Routing with EJBs in OpenESB

A common myth about OpenESB is that you can only route msgs using a full orchestration language such as BPEL.

It is possible to route msgs using a number of mechanisms in OpenESB. These include:

This article looks at how to route msgs between two EJBs that are deployed to the JavaEE Service Engine. I picked JavaEE SE because it is a production quality, supported component as part of the GlassfishESB release of OpenESB. Hopefully POJO SE will also be a supported option soon.


The JavaEE Service Engine (JavaEE SE) is used to allow EJBs to act as Service Units in a JBI-compliant infrastructure. For this example, there are 2 important points to remember about JavaEE SE and JBI.

  • Service Units must be described using abstract WSDL definitions
  • The JavaEE provides a "wrapper" or "bridge". It allows EJBs which are implemented as WebService providers and consumers to act as JBI Service Units. The important point is that although you implement JavaEE SUs as WebServices, they do not necessarily send msgs as SOAP over HTTP requests over-the-wire. If an EJB is acting as a JBI Service Unit, then JaveEE SE intercepts the call and passes the msg internally. This article provides more detail on how JavaEE SE does this. 
This article creates a simple example with two EJBs. One is a simple HelloWorld Service. The other is a RouterService which accepts requests and passes them to the HelloWorld Service.

There are two primary ways to create an EJB WebService.

  • Create a WSDL file, the generate a Webservice from WSDL.
  • Create the EJB and use Webservice annotations to expose it as a webservice

Because all JBI Service Units must be described using a WSDL description, it is easiest to use the "Webservice from WSDL" approach as that will make sure a WSDL exists for our SUs. It is also possible route between EJB Service Units that are created by adding webservice annotations to the EJB, but the approach is slightly different. I might show how to do that in a subsequent article.

The screencast is recorded using Jing, which has a 5min limit on videos, so its split into 4 parts.

Part 1

Note: Normally you should only need to create an Abstract WSDL to repsenent the EJB Service. However, in Part 3 we will create a client for this service, and the client generation tooling currently requires a Concrete WSDL to work. So in this example I´ve created a Concrete WSDL for the HelloWorld service. Hopefully this bug in Netbeans will be fixed soon.

Part 2

  • fill in ejb HelloWorld java code
  • create an EJB project for the Router service
  • import the same XSD files to the project
  • create a WSDL file based on those two XSDs. 
  • create new "Webservice from WSDL"
  • this creates a service stub
  • Screencast

Part 3

  • edit the ejb Routing java code.
  • create a "Webservice Client" and use the wsdl for the ejb HelloWorld service.
  • this creates a Webservice reference. Drop the webservice reference into the Routing code.
  • edit the java to copy the parameter from the Routing request to the HelloWorld request
  • copy the return values
  • create a Composite Application project (JBI Service Assembly)
  • drag´n´drop both EJB projects into the compapp project. Build.
  • add a SOAP connector to act as an external binding for the ejb Routing Service.
  • Screencast
Note: you will notice that the Routing SU consumes an endpoint called javaee_HelloWorld_Port and the HelloWorld SU provides an endpoint called javaee_HelloWorld_Port. Although these two endpoints are not connected in the CASA diagram, the msg will pass between them.

Part 4

  • before deploying, disable the soap binding that connects to the HelloWorld service. This SOAP binding was included because we needed a concrete WSDL for the workaround discussed in Part 1. Disabling the SOAP endpoint is discussed in more detail in this article
  • deploy.
  • create a unit test
  • test. The test msg is sent to the Router. It will then send the msg on to the HelloWorld service which returns "Hello " + requestMsg
  • Screencast

Comments:

Hello Jason,

I have been using EJB based routing in OpenESB for quite some time.

Is there any way to call Binding components from witin EJB? I would like to use BC from EJB as Sun is coming out with more BC as compared to JCA. But most of the BC can be called from BPEL only. The reason for not using BPEL instead of EJB is because we are more comfortable with EJB, we can do complex programming but kindaa difficult to write comple programs in BPEL.

I know we can build a warpper in BPEL to recieve msg, invoke BC and reply back with response and call the WSDL of this wrapper inside the EJB module.

But do you recommend any other way of calling Binding component from EJB?

Thanks,
Rajan

Posted by Rajan Jain on March 01, 2009 at 10:25 PM CET #

Calling a BC from an EJB works for me. I just made a quick example. In your EJB Project:
- Make a "New Binding", which generates the BC service unit information in a WSDL file.
- In the EJB project, create a new "WebService Client", and use the wsdl generated above. It creates a "WebService Reference" in your EJB project
- expand the "Webservice Reference" and drop the operation into your code. You call the EJB "like a webservice". But the call moves internally to the BC service unit.
Let me know if you want me to create a quick screencast for this

Jason

Posted by Jason on March 02, 2009 at 04:07 AM CET #

A Screencast would be very helpful. I don't understand how to use the WebService Client within a webservice.

André

Posted by André on April 28, 2009 at 04:08 AM CEST #

It would be nice if you demonstrate the following scenario:
1. Poll the file system to get a file.
2. Get the filename into a webservice.
3. Send the file to another location in the file system.

Posted by André on April 28, 2009 at 04:22 AM CEST #

Andre,

Part 3 of this tutorial shows how to make a webservice client and call it from the EJB.

I´m not sure what you mean by 2. in your scenario.

It is quite simple to:
- use File BC to poll for a file and read in its contents
- use File BC to write those contents to another file in a new location.

Is this what you would like to see?

Jason

Posted by Jason on April 30, 2009 at 02:59 AM CEST #

Hi Jason,

thanks for your fast answer.

Yes, that's nearly what i try to do. It looks very simple but I'm completely new to OpenESB and only tried out the file example of Sun's web site.

The concrete scenario:
1. Poll the file system with backup functionality.
2. On an incoming file I want to build a checksum (SHA256) and write the filename and the checksum to the database (DBJava).
3. Then I want to move the file further to another directory.

These are the steps I've done:
1. I created a BPELModule. Within the Module I created and configured a file binding. This I pointed to a "Receive" unit. I created an abstract WSDL file and configured it with parameter filename and dirname.
2. I created an EJB from the abstract WSDL file of the BPELModule by using the given net beans functionality "Create web service from WSDL". I now tried to access the file using a filestream but this does not work because it is moved to the backup path.
(How can I access the file? Reading the content and then move it further would also help.)
3.Now I dragged the defined function of the web service to the BPELModule (right side). I used the invoke unit to call the web service. Then I concatenated the filename and the filedir from Properties -> File BC -> Inbound and mapped it to filename.

Info:
To not slow down the system I don't want to use the attachement functionality.

I would be glad if you can send me a short tutorial perhaps with screenshots based on the tutorial on http://wiki.open-esb.java.net/Wiki.jsp?page=WorkingWithFileBindingComponent.

You may even mail to aboegge@gmail.com.

Many thanks,
André

Posted by Andre on May 01, 2009 at 02:14 PM CEST #

Hi jason!
I have the problem that i can't call a bpel-process from within an Ejb! I tried it with the synchronoussample from netbeans! But after deploying the CA and making a webservice reference of the bpel's wsdl in ejb, the ejb couldn't call the process! Please, can you help me?! I don't know why this don't work...
Greetz, ben

Posted by Ben on June 20, 2009 at 10:05 AM CEST #

Hi Ben,

I've been able to implement a similar scenario so I don't see why it shouldn't work. Can you send a message to user@openesb mailing list with the relevant error message and log file?

rgds
Jason

Posted by jason on June 22, 2009 at 12:38 PM CEST #

Hi Jason,thanks for sharing

Posted by gucci shoes on February 10, 2010 at 02:41 AM CET #

Post a Comment:
Comments are closed for this entry.
About

jason

Search

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