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.
The following connectors and processing elements should be selected when creating an Ultra project for our requirement (or added to the project later via Tools → Ultra Studio → Component Registry):
Mail Connector (for both ingress (listener) and egress (sender))
NIO HTTP Connector (for sending HTTP requests to the web service)
Transport Header Manager (for some header manipulations)
Add the following Map
for use in enabling SSL for IMAP (email polling) as well as SMTP (email sending), in project.xpml
:
Type |
|
Name |
|
|
|
|
|
Add a Mail Ingress Connector to accept incoming multiplication request emails, with the following configuration (assuming a Gmail account):
Basic |
|
Protocol |
|
Host |
|
Port |
|
User |
|
Password |
|
Folder |
|
Other Settings |
|
Processing |
|
Preserve Headers (1) |
|
Lazy-fetch Payload (2) |
|
Lazy-fetch Attachments (3) |
|
Scheduling |
|
Polling Start Delay |
|
Polling Repeat Interval |
|
(1) avoids fetching of unnecessary email headers, as we would be submitting the message to an HTTP endpoint later on
(2) we want the payload, so fetch it eagerly
(3) we don’t expect attachments, and will not be accessing them even if they are present
Add an Add Variable processing element to extract the value of the retained From
header (sender’s email address)
into a recipient
variable:
Variable Name |
|
Extraction Type |
|
Value |
|
Variable Type |
|
Add a NIO HTTP Egress Connector to forward the received request to the multiplication web service:
Basic |
|
Destination Address type |
|
Destination Host |
|
Destination Port |
|
Service Path |
|
Add an Add New Transport Header processing element to set the subject of the response email:
Transport Header Name |
|
Use Variable |
|
Value |
|
Header Variable Type |
|
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:
Transport Header Name |
|
Use Variable |
|
Value |
|
Header Variable Type |
|
Finally, add a Mail Egress Connector to send the response back to the sender (assuming a Gmail account):
Basic |
|
Protocol |
|
Host |
|
Port |
|
User |
|
Password |
|
Other Settings |
|
The final flow would resemble the following:
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.)
Create a new UltraESB Server runtime configuration, and start the project.
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}
When running the sample in the UltraESB-X distribution, you need to override the following properties in-order for the sample to work.
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 |
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 |