Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Stardust/Knowledge Base/Integration/Camel/Camel Route to Send and Receive Email

< Stardust‎ | Knowledge Base‎ | Integration‎ | Camel
Revision as of 01:48, 25 August 2014 by Vikash.pandey.sungard.com (Talk | contribs) (Approach)

Objective

In this article we are going to explore usage of Camel route to send an email, pause process there and receive the reply to that email and continue.

For example, an employee fills in certain data and moves the process, the process in turn sends an email to given email ID for approval and pauses the process execution, once the process receives reply/approval to the same email, it resumes the process execution.

Approach

We will design a process with following activities: Enter Details - user will fill in certain details here including the email ID of the approver. Prepare Email Body - A script application activity which will create the body of the email out of data provided to it. Send And Wait Activity - which will send the email and get into hibernated mode. it will look up the email box of the configured user and once approval/reply mail arrives, it will complete itself and move the process. Show Response - A manual activity to show the received reply/approval email's body.

Create a process like shown below:

ProcessDiagram.jpg

Define 2 data types CEP Details and Employee Details as shown below:

DataTypes.jpg

Define 2 application Prepare Email Body (Script Invocation) and Send And Wait (Generic Camel Route):

PrepareMessage.jpg

SendandWait.jpg

Details of the routes:

Producer Route - <setHeader headerName="subject">

<simple>Please approve the request#${header.ippActivityInstanceOid}</simple>

</setHeader> <to uri="smtp://localhost?username=testuser&password=testuser&to={header.To}&from=testuser@localhost&mail.smtp.port=25;"/>

setting the header subject including activity instance OID from IPP which has been passed to this route by selecting "Include Process Context Headers". then using Camel's smtp endpoint configuring the email and sending it.

Since this application is configured as Send/Receive and Asynchronous, after sending email it will wait for route written in consumer to finish before the activity completes itself, hence gets into hibernated mode.

Consumer Route - <from uri="pop3://localhost:110?connectionTimeout=10000&delete=true&initialDelay=1000&password=testuser&unseen=true&username=testuser&searchTerm.subject=request#"/> <to uri="ipp:authenticate:setCurrent?user=motu&password=motu" /> <setHeader headerName="CamelLanguageScript"> <constant> function setOutHeader(key, output){ request.setHeader(key, output); } var line= request.headers.get("subject"); var part = line.split("#");

setOutHeader("ActOID", parseInt(part[1]));

</constant> </setHeader> <to uri="language:javascript"/> <to uri="ipp:activity:find?expectedResultSize=-1&activityInstanceOid=$simple{header.ActOID}&states=Application,Created,Hibernated,Interrupted,Suspended" /> <to uri="ipp:activity:complete" />

Using Camel's pop3 endpoint, it looking up to the user's email box, once the email arrives, it runs little java script to fetch the activity Instance OID from the subject and set it as header for further route to use it. It is the ipp:activit:find route that needs the activity Instance OID to search Stardust Audit trail to find the activity instance and complete it.


Deploy the model. When you run the process instance, it will ask you to input details:

Complete the activity, it will call both the application activities, prepare email body and send and wait. During execution of send and wait the process instance will hibernate and wait for an approval email. once that arrives it will complete this hibernated activity and activate Show Response Data manual activity where you can see the response email message.

ExecutionResult.jpg

Back to the top