Wednesday, December 19, 2007

WSIF with EJB 2.0, 2.1 and 3.0

Although WSIF seems to be hack to plug-in native protocol in web services framework, I absolutely love WSIF.

My understanding of WSIF is standard way of representing service contract (which is WSDL) for any type of service. E.g. if you have servlet, java program, .Net code or JCA operation, you can represent all of them as standard WSDL. Now for WSDL consumer (e.g. BPEL) it is just any other WSDL operation and WSIF provider will know how to interact with this service. My belief is Oracle BPEL uses open source Apache WSIF provider in BPEL engine. I did play with HTTP WSIF Binding and Java Binding. I probably will post on HTTP binding once I figure out how to pass dynamic URL (e.g. calling servlet with dynamic parameters) but now it is time to play with some EJB WSIF.

I created sample EJB 2.0, EJB 2.1 and EJB 3.0 Session Façade using Jdeveloper and deployed to my SOASuite oc4j. I deployed in different container than OC4J_SOA just to make sure Remote interface are being used. I will start with EJB 2.1 because that is the easiest one, EJB 3.0 and EJB 2.0 WSIF binding needs lot of hack and/or custom coding.

Technology Used: JDeveloper 10.1.3.3, Oracle SOASuite 10.1.3.3


EJB 2.1 WSIF: Created a sample EJB 2.1 Session Façade, one business method called demoHelloMethod as shown below:

Once you right click your EJB icon, it let’s you create stand-alone Java client for EJB pointing to Remote Application Server as shown below:

We can see that the client uses opmn URL to connect with remote EJB: “opmn:ormi://localhost:6003:home/demosessionejb21”. I found WSIF doesn’t like this URL so I tested my client with ormi url “ormi://localhost:12402/demosessionejb21”. We probably want to note down some information from this client, e.g.

Provider URL: ormi://localhost:12402/demosessionejb21

Initial Context Factory: oracle.j2ee.rmi.RMIInitialContextFactory

EJB name: DemoSessionEJB21

Now it is time to create WSDL, which can represent this EJB operation. We can Jdeveloper wizard to create such such wsdl. Once we right click on EJB we can see “create J2EE web service” option, it lets you create web-service for your EJB. Remember we are just going to use this to create WSDL but not web-service. I took backup of my project, created web-service, took wsdl and then restored my old project, as I am not interested in web-service. I just followed the wizard as shown below.

In Step 2. Please remember to select RPC Lit otherwise some extra effort will be required on XSD side.
In Step 6, this values I took from EJB Client code which was generated using JDeveloper.
Just click on Finish and Look at generated WSDL file:
We can take this wsif and restore the project from earlier backup. We can see both WSIF and HTTP binding in this WSDL. Now as this is not deployed as web-service, I commented out the http part and also put the partner-link so that BPEL doesn’t create extra ref file. The final WSDL file look something like this:
EJB 2.1 WSIF Testing through BPEL Project
I created sample BPEL project and copied this wsdl file in bpel directory. I created partnerlink and selected the binding wsdl. I am almost done, I just need to pass extra information required by EJB RMI client. Seems like these extra information (e.g. username, password) are not part of WSIF spec, but BPEL supports it very well. I provided these entries in bpel.xml:

Because it is native call, BPEL engine will need all classes for EJB client. I copied the classes from EJB session facade project to bpel/system/classes directory.

Deployed the project … and hulala… things working great.



EJB 2.0 WSIF: It is very well supported by Oracle BPEL PM, but not through JDeveloer. Overuse of Wizards and drag-drop kinda makes us handicapped!! Anyways, time to get hand dirty. Created EJB 2.0 session façade, a sample business method and deployed to Application Server. I also created EJB 2.0 Java Client the same way as described in EJB 2.1.

We can see the “Create J2EE Web Service option”. Upon clicking this option it just create web service code and wsdl file with name called “MyWebService1” without showing any prompt… I double click on MyWebService1 so I could at least change the name of WS to DemoSessionEJB20. The initial WSDL looks something like:

There is no WSIF information at all. I hand coded the part of WSDL as shown below. I copied most of the part from EJB 2.1 WSIF wsdl and just changed the stuff as required.

I created sample BPEL project and imported WSIF WSDL. I also put username and password in bpel.xml as described in EJB 2.1 and copied required EJB classes in bpel/system/classes directory. Deployed the project and things went pretty smooth…




EJB 3.0: Personally I believe EJB 3.0 made life much easier in J2EE development. It is really very nice concept eliminating need of EJB 2.x crap, lot of XMLs (like Spring) and extensive use of annotations. Ok, let’s get back to WSIF part.

I created sample EJB 3.0 Session Façade, Java Client, as EJB 2.x. JDeveloper doesn’t display “Create J2EE webservice” option for EJB 3.0 Session Façade, but there is Annotation to create WSIF bindings.

During the creation of EJB 3.0, please expose them to WebService interfacce as well as shown in above figure. That creates Doc-Lit service without any WSIF binding. I believe we need to do schemac if we stick with Doc-Lit. I changed webservice interface (DemoSessionEJB30WebService.java) as shown below to create RPC Lit service with WSIF bindings using annotations.

Now when I deploy this service using deployment profile, Oracle AS creates very nice WSDL:

I created BPEL project, imported this WSDL. After importing this WSDL file I still had to make couple of changes. I had to add partner link to avoid Ref file, remove soap bindings for safety and I also had to add more parameter in ejb:address e.g. className, jndiName and providerURL. The final WSDL with changes looks something like:

As usual, I provided username and password in bpel.xml and copied required classes in bpel/system/classes directory, and things started rocking!!!


Source code can be downloaded at this link.

I will try to update my log when JDeveloper has support for creating wsif WSDL through wizard for EJB 2.0 and EJB 3.0.

1 comment:

Anonymous said...

Thanks Chintan for this very useful blog! I have created a sample application based on your EJB3.0 example, but i am having trouble when the "helloDemoMethod" takes a complex type as argument, for example a very basic Person object, i.e. helloDemoMethod(Person person). Will you please provide an example for this kind of situation? I tried both Java-to-XML facade classes and JAXB through orajaxb.bat to no avail. Thanks in advance!