Tuesday, November 26, 2013

Invoking EJB service from SOA and OSB


Recently I came across a requirement where I had to invoke a EJB code from SOA and OSB 11g, I have done it in past but it took me a while to get it working and thats when this post happened , so to avoid that extra time in future .

Here are the steps on creating a simple EJB in Jdeveloper , Invoking it using Bpel and Invoking it using Business service in OSB.

Create a EJB in Jdeveloper
1. Create a Generic Application  - RSEJBApp
2. Create a Project OSBUtilityEJB
3. Create a session Bean :
  Name : GetSumEJB
  Mapped Name : RSEJBApp-OSBUtilityEJB-GetSumEJB (This is the name used to refer the EJB)
  Just create the RemoteInterface
  Interface Name : GetSumEJB
  Java class : GetSumEJBBean

4. Create method "public int getSum" and implement in Java class.
5. Create EJB Jar file deployment profile for project
 Project -> Properties -> Deployment -> New -> EJB Jar File -> RSEJBJar

6. Deploy the project using the  deployment profile created in previous step, I deployed this on SOA domain.
7. Login to console to see if its deployed properly in WLS
It will be deployed as : Enterprise Application and Name= RSEJBJar

Create a SOA project to invoke EJB :
1. Create a Mediator/Bpel process to invoke the EJB in Jdeveloper SOA project
2. Copy the remote interface to the SCA-INF/src ,i.e copy GetSumEJB.java, Remove the import and Remote annotation.This will appear in Application Sources folder in Jdeveloper project.

3. Create an EJB service by dragging on the composite reference
Name : InvokeSumEJBSvc
JNDI Name : Mapped Name of the EJB#Remoteinterface
ie : RSEJBApp-OSBUtilityEJB-GetSumEJB#pc.common.rs.GetSumEJB

Java Interface : pc.common.rs.GetSumEJB

4. Go to composite source
Cick on reference -> binding.ejb tag and on the property inspector add "pc.common.rs.GetSumEJB" for javaInterface, This should have added automatically by doesnt work in Jdev as of now.

5. If you still see error while creating invoke or wiring the EJB service , compile the SOA project, so that it loads the EJB interface to memory
6. Deploy the SOA project to SOA domain.
7. Test in EM console.

Create OSB Business service to invoke the EJB:
1. Create Client jar depoyment profile for the EJB project in Jdeveloper : RSEJBClientJar
2. Deploy to client jar deployment profile to Jar file : RSEJBClientJar.jar

3. Add client jar to OSB project like any other jar file

4. Create business service for EJB
Name : SumEJBS
Type : Transport Typed Service
Protocol : EJB
Endpoint URI : ejb::RSEJBApp-OSBUtilityEJB-GetSumEJB#pc.common.rs.GetSumEJB

EJB Transport Configuration-
EJB 3.0  : selected
Client Jar  : RSEJBClientJar, select interface and method.
IMP : Rename arguments if you like from arg0 -> Input 1 , this will help generating the WSDL with more appropriate name.


5. Test , it will fail with below error as the JNDI is not from the same server and is remotely hosted.
The invocation resulted in an error: Failed to invoke end component com.bea.wli.sb.transports.ejb.Jws (POJO), operation=getSum
-> Failed to invoke method
-> While trying to lookup 'RSEJBApp-OSBUtilityEJB-GetSumEJB#pc.common.rs.GetSumEJB' didn't find subcontext 'RSEJBApp-OSBUtilityEJB-GetSumEJB#pc'. Resolved ''

6. Create JNDI provider for server where EJB is deployed
System Administration -> JNDI Providers -> add
Name : EJBServJNDI
Provider URL : t3://server:9501 (Admin server port)
User Name : weblogic
password: welcome1

7. update the Endpoint URI in BS
Endpoint URI = ejb:EJBServJNDI:RSEJBApp-OSBUtilityEJB-GetSumEJB#pc.common.rs.GetSumEJB

8. Test and it will work fine.


Keep coding!!

3 comments:

  1. how would it look for external server? don't we need to specify server host-name ?

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hi, I'm trying consume a EJB with dependencies the 3rd JARs but this generated an exception Classnotfoundexception despite that dependencies be found in the classpath.
    I need you help please :)

    * is for OSB 12c

    ReplyDelete