Pages

Wednesday, January 7, 2009

Using remote / local ejb in JDeveloper 11g and WLS

If you want to use EJB as model in your 11G ADF JSF application then you can follow this guide on otn. Using the local interface to an ejb session bean is not so difficult. Just select the ejb session bean and create an datacontrol on this. Then You will get the option to use the Local or Remote interface.

After this you can select and use the ejb methods from the viewcontroller datacontrol window. When you use this local ejb, JDeveloper will add a reference to this ejb in the web.xml. It will use ejb-local-ref element

<ejb-local-ref>
<ejb-ref-name>ejb/local/HRSessionEJB2</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>nl.whitehorses.model2.HRSessionEJB2Local</local>
<ejb-link>HRSessionEJB2</ejb-link>
</ejb-local-ref>

When you start your application then JDeveloper automatically add this ejb module in the weblogic deployment and the web application will use the ejb-link element to resolve the ejb.

Now let's make it a bit more difficult by using remote interface EJB. We have now two options. You can add this remote ejb to the application workspace then JDeveloper will deploy this ejb too with the web application deployment. The only thing what is different with a local interface ejb is the reference element in the web.xml. It will now use the ejb-ref element.

<ejb-ref>
<ejb-ref-name>ejb/HRSessionEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>nl.whitehorses.model.HRSessionEJB</remote>
<ejb-link>HRSessionEJB</ejb-link>
</ejb-ref>

I think when you choose to use remote ejb then it is wise to deploy this on a different wls then the wls where you web application is running. For this we need to create a new workspace where we will create the remote ejb's. Deploy this ejb to a WLS server other then the WLS of the web application .
When we want to use this ejb with ADF in the web application then we need to create a new datacontrol on this ejb session bean. Now we use the remote interface option. If we want see this datacontrol in the data control window of the web application then we need to make an ADF library deployment.

Deploy this to a jar and add this jar to the viewcontroller project.
There are two ways to do a jndi lookup from the web application to the remote EJB. The first way is to open datacontrols.dcx in the remote ejb wproject and fill the correct jndi properties fields.

<Source>
<ejb-definition ejb-version="3.0" ejb-name="HRSessionEJB"
ejb-type="Session"
ejb-business-interface="nl.whitehorses.model.HRSessionEJB"
ejb-interface-type="remote"
jndi-name="ADF_EJB-SessionEJB#nl.whitehorses.model.HRSessionEJB"
provider-url="t3://127.0.0.1:7001"
initial-context-factory="weblogic.jndi.WLInitialContextFactory"
xmlns="http://xmlns.oracle.com/adfm/adapter/ejb"/>
</Source>
</AdapterDataControl>
</DataControlConfigs>

The other way is to make a reference element in the web.xml and weblogic.xml in the viewcontroller project. here is the remote ejb reference in the web.xml

<ejb-ref>
<ejb-ref-name>ejb/HRSessionEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>nl.whitehorses.model.HRSessionEJB</remote>
</ejb-ref>

and here the weblogic.xml located in the web-inf folder

<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<ejb-reference-description>
<ejb-ref-name>ejb/HRSessionEJB</ejb-ref-name>
<jndi-name>ADF_EJB-SessionEJB#nl.whitehorses.model.HRSessionEJB</jndi-name>
</ejb-reference-description>
</weblogic-web-app>

Now we only have to make an library for the WebLogic server and add this library to weblogic-application.xml of the viewcontroller project. This library contains the remote ejb classes else we can get a class loading problem and our application can't find the ejb classes. To do this we first have to make a folder where we will add an APP-INF and a META-INF folder and we use an empty dummy jar.

Under the APP-INF folder I created a new folder lib and add the ejb jar to this folder.

In the meta-inf folder we need to create two files MANIFEST.MF and application.xml these files will we used to determine the WLS library name.
We can go the weblogic server console and go to deployment menu where we press the install button and follow the wizards.


When this is successfull we can change the weblogic-application.xml.

<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-application.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-application">
<listener>
<listener-class>oracle.adf.share.weblogic.listeners.ADFApplicationLifecycleListener</listener-class>
</listener>
<library-ref>
<library-name>adf.oracle.domain</library-name>
</library-ref>
<library-ref>
<library-name>ejb.whitehorses.model</library-name>
</library-ref>
</weblogic-application>

If you deployed the remote ejb to the same WebLogic server as the web application then everything should work now when you deploy the application.
When you have deployed the remote ejb on a different WLS then we need to create an foreign jndi provider first. Go to the wls console of the web application and create a foreign jndi provider and foreign jndi link. So the web appplication can find the remote ejb on the other Weblogic server.


It can be that you still got errors where you use the remote ejb on a different WLS server. Then you could try to generate ejb client.jar. Use this to add the Welblogic stub classes to the deployment jar of the remote ejb and add jar as a library to the adf wls.

set JAVA_HOME=C:\oracle\MiddlewareJdev11g\jdk160_05
set PATH=C:\oracle\MiddlewareJdev11g\jdk160_05\bin
set CLASSPATH=C:\oracle\MiddlewareJdev11g/wlserver_10.3/server/lib/weblogic.jar

java weblogic.appc C:\projecten\workspace\11g_prod\ADF_EJB_REMOTE\model\deploy\EjbWebServices.jar


here are my example projects.

6 comments:

  1. Is there a way to make ejb calls from 11g WLS to 10g OAS running on jdk 1.5 ?

    ReplyDelete
  2. Hi

    That should be possible but we tried to call the soa suite task ejb but we need to put a ws on it and call this ws from wls.

    you can get some serial id errors but they got osb also working with soa suite.

    thanks Edwin

    ReplyDelete
  3. Hi Edwin,

    Thanks for the post. I am trying to configure the XMPP driver and send a IM Message. After I send the message from my client, when I checked the status of my message at UMS, I saw the below error. Can you please help me out here?

    Status Code: DELIVERY_TO_DRIVER_FAILURE
    Status Message: No matching drivers found for delivery type = IM

    Thanks,
    Sudan

    ReplyDelete
  4. Hi,

    Did you select the im application driver in the web logic console and target this to the web logic SOA managed server and then reboot

    Thanks

    ReplyDelete
  5. Hi Edwin,
    I have same problem as previous comment has. I didn't understand what do you mean by "select the im application driver in the web logic console and target this to the web logic SOA managed server ". I do everything written here http://technology.amis.nl/blog/6029/chatting-from-soa-suite-11g-how-bpel-processes-can-use-the-xmpp-protocol-to-notify-the-world (I think)

    ReplyDelete
  6. Hi,

    What I mean, default these drivers are disabled. These drivers are a EAR application and you can see then in the weblogic console application / deployment.

    select the driver you want to use and open it , here you see a target tab where you can assign it to a soa managed server.

    thanks

    ReplyDelete