Using SMTP BC to send Email in JBI Environment

What is SMTP BC?

Java Business Integration (JBI) is a standard for integrating business sytems. It defines a platform for different components to interact each other in a standard way. A binding component in a JBI environment is a piece of software written to interact with external systems which typically involves communicating through a specific protocol. Thus SMTP Binding component provides communication to SMTP servers for other JBI components.

How do you send e-mail using SMTP BC?

The SMTP BC currently provides mechanism for sending emails to SMTP servers and it also acts as a SMTP server to receive emails. Here we will see how it helps us to send emails. Here we use NetBeans 5.5.1 IDE to develop a composite application which uses SMTP BC, BPEL SE and HTTP BC to send a mail.

Sample Application:

The sample application we create here involes a http request triggering an email to be sent to a particular email destination. The steps to create are:


  1. Create a BPEL Module project

  2. Create 2 WSDLs. one with Http/SOAP Binding and another with SMTP Binding.

  3. Edit the WSDL with SMTP Binding to specify the destination email address, SMTP Server to use and the message part for content of the email.

  4. Create a BPEL Process.

  5. Build the module to create a Service Unit.

  6. Create a Composite Application.

  7. Add the above BPEL Module to the composite application.

  8. Build the Composite Application to a Service Assembly.

  9. Start the App.Server and deploy the composite application.

  10. Test the application.

How to Create the WSDL With SMTP Binding:

Here we will use the WSDL Wizard for creating the WSDLs:

1. In the BPEL Module Project, Right Click on Process Files folder and select New - > File/Folder. Select the Folder XML and then WSDL Document from Right pane.

2. Provide a Name for WSDL. In this sample, we are not going to use any Schemas, so leave it as blank. Click Next.

3. Select the Operation type as One-Way Operation. And leave the other values to default. Click Next.

4. Select SMTP Binding in the "Concrete Configuration" Screen. Click Finish.

Providing values for smtp:address :

1. Open the SMTPWSDL using WSDL Editor
2. Expand the folder: Services -> SMTPWSDLService -> SMTPWSDLPort -> smtp:address
3. Provide the values in property editor for location and smtpserver attributes.

Providing values for smtp:input :

1. Open the SMTPWSDL using WSDL Editor.
2. Expand the folder : Bindings -> SMTPWSDLBinding -> SMTPWSDLOperation -> input1 -> smtp:input.
3. Provide the value in property editor for message. eg: part1.

Creating the WSDL With Http Binding:

You can use the WSDL Wizard for creating the WSDL same as SMTP Binding except these changes:

    - Select Request-Response Operation in 3rd Step.
    - Select Binding Type to SOAP and Binding SubType to RPC Literal.

Creating the BPEL process:

1. Right Click on Process Files folder and select New -> BPEL Process.
2. Provide Name for the bpel process and click on Finish
3. Using the BPEl Editor / BPEL Mapper, create the bpel with these activities:
    - Receive Operation on HTTP
    - Assign the request received to the request for SMTP Invoke.
    - Invoke operation on SMTP
    - Assign a static String "Email Sent Successfully"
    - Reply Operation on HTTP.

The completed BPEL module will look like this:

Creating the Composite Application:

1. Create a new Project. Select Service Oriented Architecture -> Composite Application.

2. Provide a name for the project and click finish

3. Under the Jbi project. Right click on JBI Modules and select Add JBI Module. Find the above created BPEl project and add it.

Building and deploying the SA:

1. Right click the Comp. App. project and select Build.

2. In the Runtime tab, make sure the Application Server is started.

3. Right click the Comp. App. project and select Deploy.

Testing the application.
To Create a TestCase:

In the Comp. App. project,

1. Right Click on the Test Folder and select New Test Case
2. Provide a TestCase name and go to next screen.
3. Choose the WSDL implementing HTTP/SOAP Binding and click next.

4. Select the Operation you want to test and Click Finish

A test case would have got created with an Input.xml and output.xml. Edit the input.xml to provide the data.

Running the Test Case:

Run the Testcase by Right click on the testcase and select Run.

The First time it fails, because the output.xml is empty and it does not matches with the output returned. To make the output returned as a valid output, right click on the output returned (marked as Failed) and select "Use as Output"

Comments:

Thia is a very good example.

I was able to implement it but I am getting
com.sun.jbi.smtpbc.extensions.InvalidMailboxException
in a server log.

The mailto: field is correct and so is the smtphost and port. Any suggestions?

cheers
mark

Posted by mark on December 13, 2007 at 06:40 PM IST #

this is very good tutorial but how to make it cater for message attachment?

Posted by eric on February 29, 2008 at 11:07 AM IST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

vishblog

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today