Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:3500:0400:0410:0411 [2023/04/05 06:25] – removed - external edit (Unknown date) 127.0.0.1 | docs:3500:0400:0410:0411 [2025/06/12 02:36] (current) – Rename to AwareIM aware_support3 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | {{tag> | ||
| + | [< | ||
| + | ==== Writing a Sink ==== | ||
| + | |||
| + | To write a custom Sink follow the steps below: | ||
| + | |||
| + | - Inherit the Sink from the '' | ||
| + | - If necessary override init method to provide the Sink-specific initialization (if there’s any) – this method is called once when the Sink is initialized. The Sink-specific properties would have been entered by the user in the Configuration Tool (see also section 4.3) | ||
| + | - You must override the following method to provide your own handling of messages sent from // | ||
| + | throws PipelineException;</ | ||
| + | - get the array of DataObject’s from the message:< | ||
| + | - use MessageInterpreter class to interpret the message (see also 4.1.3):< | ||
| + | INotification notif = mi.getNotification (); /**or**/ | ||
| + | String serviceName | ||
| + | |||
| + | As an example you can see the code snippet below that implements the Sink that sends outgoing e-mails from // | ||
| + | |||
| + | <code java> public | ||
| + | { | ||
| + | private Stringm_mailHost= null ; | ||
| + | private Sessionm_session= null ; | ||
| + | private Stringm_fromAddress= null ; | ||
| + | /** Initializethesink. Mail host and 'from address' | ||
| + | public | ||
| + | Controllercontroller) | ||
| + | throws IbafException | ||
| + | { | ||
| + | try | ||
| + | { | ||
| + | super .init(name, | ||
| + | m_mailHost=props.getProperty(prefix+" | ||
| + | if (m_mailHost== null ) | ||
| + | throw new IbafException(" | ||
| + | PropertiessessionProps=System.getProperties(); | ||
| + | sessionProps.put(" | ||
| + | m_fromAddress=props.getProperty(prefix+" | ||
| + | m_session=Session.getDefaultInstance(sessionProps, | ||
| + | } | ||
| + | catch (Exceptione) | ||
| + | { | ||
| + | e.printStackTrace(); | ||
| + | throw new IbafException(e.toString()); | ||
| + | } | ||
| + | } | ||
| + | /** Message handling method – must be provided */ | ||
| + | public | ||
| + | throws PipelineException | ||
| + | { | ||
| + | Stringsubject= null ,toAddress= null ; | ||
| + | StringsentDateStr= null ; | ||
| + | try | ||
| + | { | ||
| + | DataObject[]dobs=msg.peekDataObjects(); | ||
| + | // get all message parameters from data objects | ||
| + | MessageInterpretermi= new MessageInterpreter(dobs); | ||
| + | // get e-mail address from channel values | ||
| + | DataObjectchvDob=mis.getChannelValues(); | ||
| + | if (chvDob== null ) | ||
| + | return ; // ignore the message | ||
| + | try | ||
| + | { | ||
| + | toAddress=(String)chvDob.getAttributeValue(EMAIL_ADDRESS); | ||
| + | } | ||
| + | catch (InvalidParameterExceptionipe) | ||
| + | { | ||
| + | |||
| + | } | ||
| + | if (toAddress== null ) return ;//** ignore the message | ||
| + | INotificationnotif=mis.getNotification(); | ||
| + | if (notif== null ) return ; // ignore the message | ||
| + | // we expect notification of a certain structure – it must have " | ||
| + | Stringbody= null ; | ||
| + | try | ||
| + | { | ||
| + | body=(String)notif.getAttributeValue (EMAIL_BODY_ATTR); | ||
| + | } | ||
| + | catch (InvalidParameterExceptionipe) | ||
| + | { | ||
| + | |||
| + | } | ||
| + | if (body== null ) | ||
| + | return ; // ignore the message// subject is optional | ||
| + | try | ||
| + | { | ||
| + | subject=(String)notif.getAttributeValue (EMAIL_SUBJECT_ATTR); | ||
| + | } | ||
| + | catch (Exceptione) | ||
| + | { | ||
| + | } | ||
| + | if (subject== null ) subject=""; | ||
| + | // create MAPI e-mail message | ||
| + | MimeMessageemail=createEmail(body, | ||
| + | if (email!= null ) | ||
| + | { | ||
| + | // send e-mail using MAPI | ||
| + | sendEmail(email, | ||
| + | } | ||
| + | } | ||
| + | catch (Exceptione) | ||
| + | { | ||
| + | } | ||
| + | } | ||
| + | |||
| + | /** Send the e-mail using MAPI. A lot of details are omitted | ||
| + | private | ||
| + | { | ||
| + | try | ||
| + | { | ||
| + | Transport.send(email); | ||
| + | } | ||
| + | catch (Exceptione) | ||
| + | { | ||
| + | } | ||
| + | return true; | ||
| + | } | ||
| + | |||
| + | /** Create e-mailmessage using MAPI. Details are omitted */ | ||
| + | private MimeMessagecreateEmail(Stringbody, | ||
| + | throws Exception | ||
| + | { | ||
| + | MimeMessagemailMessage= new MimeMessage(m_session); | ||
| + | if (m_fromAddress!= null ) mailMessage.setFrom(InternetAddress.parse mailMessage.setRecipients(javax.mail.Message.RecipientType.TO, | ||
| + | mailMessage.setSubject (subject); | ||
| + | mailMessage.setSentDate(sentDate); | ||
| + | return mailMessage; | ||
| + | }</ | ||