I have an integer multiplication web service exposed over HTTP, and want to make it accessible via email, where emails containing the input data sent to a predefined address are processed and replied to with the multiplication results.
UltraESB-X can be configured to proxy messages between the email service and the web service in order to enable the acceptance of data from and propagation of results to email senders.
UltraStudio Configuration
UltraESB-X Configuration
In order to implement above use case you must first select following dependencies when you are creating a new Ultra project.
Mail Connector from the connector list
NIO HTTP Connector from the connector list
Transport Header Manager from processor list
If you have already created a project, you can add above dependencies via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list and Processors list, select above dependencies. |
To implement above use case, first create an integration flow named “web-service-via-email-flow”, and then add required components by going through following steps in order.
Add a Mail Ingress Connector from the Connectors → Ingress Connectors list, to accept incoming multiplication request emails, with the configuration shown below (assuming a Gmail account)
Add an Add Variable processing element from the Processors → Generic list, to extract the value of the retained From
header (sender’s email address)
into a recipient
variable
Add a NIO HTTP Egress Connector from the Connectors → Ingress Connectors list, to forward the received request to the multiplication web service
Add an Add New Transport Header processing element from the Processors → Header Manipulation list, to set the subject of the response email
Restore the previously saved sender’s email address from recipient
variable into the mail.to
transport header,
using another Add New Transport Header processing element
Add a Mail Egress Connector to send the response back to the sender (assuming a Gmail account)
Finally add a Successful Flow End processing element to complete the flow
The completed integration flow should look like below.
Configuration for each element is as below. The numbering corresponds to the numbers shown in above diagram.
Design View
Text View
1. Mail Ingress Connector (Basic Tab)
For other settings, specify below Map entries
1. Mail Ingress Connector (Processing Tab)
1. Mail Ingress Connector (Scheduling Tab)
2. Add Variable
3. NIO HTTP Egress Connector
4. Add New Transport Header
5. Add New Transport Header
6. Mail Egress Connector
For other settings, specify below Map entries
1. Mail Ingress Connector (Basic Tab)
|
imap |
|
imap.gmail.com |
|
993 |
|
|
|
your-password |
|
INBOX |
|
|
1. Mail Ingress Connector (Processing Tab)
|
From |
|
Off |
|
On |
1. Mail Ingress Connector (Scheduling Tab)
|
2000 |
|
10000 |
2. Add Variable
|
recipient |
|
HEADER |
|
From |
|
String |
3. NIO HTTP Egress Connector
|
URL |
|
localhost |
|
9000 |
|
/service/JsonServlet |
4. Add New Transport Header
|
mail.subject |
|
Off |
|
Multiplication Result |
|
String |
5. Add New Transport Header
|
mail.to |
|
On |
|
recipient |
|
String |
6. Mail Egress Connector
|
smtp |
|
smtp.gmail.com |
|
25 |
|
|
|
your-password |
|
|
Now you can run the Ultra Project and check the functionality of the integration flow. Create an UltraESB Server run configuration and start it.
When running the sample in the UltraESB-X distribution, you need to override the following properties in-order for the sample to work. The properties file is located at $ULTRA_HOME/conf/projects/web-service-via-email/default.properties
Refer to Managing Project Properties documentation on how to override properties. |
|
Email account of the user who accepts input data |
|
Email password of the user who accepts input data |
|
Email account of the user who sends back computed data |
|
Email password of the user who sends back computed data |
After that navigate to $ULTRA_HOME/bin directory. Next you can run the UltraESB-X distribution with following command to start the engine with this sample project deployed.
./ultraesbx.sh -sample web-service-via-email
A multiplication service that accepts JSON payloads in the format {"v1":first_number,"v2":second_number}
is
available in the Jetty Server plugin shipped with Ultra Studio.
Click View → Tool Windows → Jetty Server and click the green start button to start a Jetty server at port 9000.
(If you have run a server instance previously, it will be listed in the Jetty Servers list, in which case you
should start the corresponding (port 9000) server from the list.)
Send an email to your-email@gmail.com
containing a multiplication request in the message body, such as the following:
{"v1":7,"v2":6}
A response email will be delivered to the account from which you sent the multiplication request, resembling:
{"result":42,"v1":7,"v2":6}
Depnding on the email provider which hosts the emails that you have mentioned above, you may have to enable insecure application access in account settings |