Discussion:
EJB3 remote interface injection/lookup problems
(too old to reply)
i***@epam.com
2008-02-20 14:16:15 UTC
Permalink
Hi,<br />
<br />
I have 2 applications (EAR with ejb3 module and WAR with ejb3-client module) which located on different application servers. Every AS have ejb3 feature pack installed. I want to lookup/inject ejb remote interface to jsf managed bean/servlet but I can't do it :( <br />
<br />
1) When I try manually lookup ejb via initial context in my JSF managed bean I get<br /> <br /> <code>java.lang.ClassCastException: org.omg.stub.java.rmi._Remote_Stub incompatible with &lt;RemoteInterfaceName&gt;</code> <br />
<br />
excepttion error. <br />
<br />
I have ejb-ref element declared in the application's web.xml and use it's ejb-ref-name in lookup method (<code>initialContext.lookup("java:comp/env/&lt;ejb-ref-name&gt;")</code>). This ejb-ref during deployment phase I bind to the actual ejb, which deployed on another app server. Since AS with WAR application has ejb3 feature pack installed I don't create any stubs for my ejb-client. Is it right? Or in spite of ejb3fp I must create stubs via createEJBStubs bat?<br />
<br />
2) In case of servlet I have an <code>"exception while injecting resource"</code> error message. <br />
<br />
Because of injection support in servlets I use @EJB annotation with name attribute. This name corresponds to the ejb-ref-name attribute of ejb-ref element in my web.xml descriptor. Naming URL and provider I specified in <code>jndi.properties</code> file which located in the classpath of application.<br />
<p />
Thus, in every case I can't lookup my remote ejb on different app server. Anybody can help me in these problems?<br />
Thanks in advance.
Jacek Laskowski
2008-02-21 00:45:47 UTC
Permalink
Hi,<br />
<br />
Ad 1) You have to include stubs for remote intfs created by createEJBStubs in the client application which is a web app in this case.<br />
<br />
Ad 2) Could you post the stack trace? It might shed some light on the issue.<br />
<br />
Jacek<br />
<br />
---<br />
Jacek Laskowski<br />
<a href="http://www.JacekLaskowski.pl">http://www.JacekLaskowski.pl</a>
Randy Schnier
2008-02-24 00:54:00 UTC
Permalink
The InfoCenter documentation explains that the EJB 3.0 feature pack does not support injection into JSF managed beans. (JSF injection support is beyond the scope of what is provided by the EJB 3.0 feature pack, as JSF is a Java EE specification outside the domain of EJB 3.0.)

There's an example of looking up an EJB 3.0 bean via JNDI from a servlet 2.4 module in the InfoCenter. Basically, setting up the ejb-ref in your web.xml is similar to if you were pointing at an EJB 2.1 bean, except since EJB 3.0 beans don't have homes you put nothing in for the home entry in the ejb-ref. (But I definitely recommend you look at the example.)

For question 2, you may want to check out the EJB 3.0 feature pack InfoCenter documentation. If your client is a Web container, EJB container, or application client container that has the EJB 3.0 feature pack applied, you don't need to generate the stub classes with createEJBStubs.bat (assuming that your WAR module at least includes the .class file for the EJB remote business interface, the stub will be generated in-memory by the container you're calling from).
Post by i***@epam.com
Hi,<br />
<br />
I have 2 applications (EAR with ejb3 module and WAR with ejb3-client module) which located on different application servers. Every AS have ejb3 feature pack installed. I want to lookup/inject ejb remote interface to jsf managed bean/servlet but I can't do it :( <br />
<br />
<br />
excepttion error. <br />
<br />
<br />
2) In case of servlet I have an <code>"exception while injecting resource"</code> error message. <br />
<br />
<p />
Thus, in every case I can't lookup my remote ejb on different app server. Anybody can help me in these problems?<br />
Thanks in advance.
a***@eg.ibm.com
2008-02-25 07:50:02 UTC
Permalink
Hey Randy, im having the same problem. im trying to lookup the ejb i deployed on was6.1 with ejb3.0 feature pack installed.<br />
Here's my code for the client:<br />
<br />
public static void main(String[] args) {<br />
// TODO Auto-generated method stub<br />
try {<br />
Hashtable env = new Hashtable();<br />
env.put(Context.INITIAL_CONTEXT_FACTORY,<br />
"com.ibm.websphere.naming.WsnInitialContextFactory");<br />
env.put(Context.PROVIDER_URL, "corbaloc::localhost:2812/NameService");<br />
Context initialContext = new InitialContext(env);<br />
PortableRemoteObject remoteObject = new PortableRemoteObject();<br />
TaskImpl task =(TaskImpl)remoteObject.narrow(initialContext.lookup("com.ibm.ejb3.poc.session.Task"),TaskImpl.class);<br />
<br />
} catch (Exception e) {<br />
// TODO Auto-generated catch block<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
I get the following exception:<br />
<br />
Feb 25, 2008 9:18:35 AM com.ibm.ws.util.ImplFactory<br />
WARNING: WSVR0073W<br />
java.lang.ClassCastException: cannot cast class org.omg.stub.java.rmi._Remote_Stub to class com.ibm.ejb3.poc.session.TaskImpl<br />
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:396)<br />
at tst.TestClient.main(TestClient.java:28)<br />
<br />
any ideas?<br />
<br />
Thanks, Salem
Randy Schnier
2008-02-25 19:33:56 UTC
Permalink
I don't think it's the same problem. Your code looks like you're attempting a lookup from a "bare" JVM client. It's documented in the InfoCenter that there are three cases where you need to generate the client-side stubs with the createEJBStubs command and copy the resulting stubs into your client's classpath. A bare JVM client is one of those cases. (The other two are WebSphere environments without the EJB 3.0 feature pack applied, and non-WebSphere environments.)
Post by a***@eg.ibm.com
Hey Randy, im having the same problem. im trying to lookup the ejb i deployed on was6.1 with ejb3.0 feature pack installed.<br />
Here's my code for the client:<br />
<br />
public static void main(String[] args) {<br />
// TODO Auto-generated method stub<br />
try {<br />
Hashtable env = new Hashtable();<br />
env.put(Context.INITIAL_CONTEXT_FACTORY,<br />
"com.ibm.websphere.naming.WsnInitialContextFactory");<br />
env.put(Context.PROVIDER_URL, "corbaloc::localhost:2812/NameService");<br />
Context initialContext = new InitialContext(env);<br />
PortableRemoteObject remoteObject = new PortableRemoteObject();<br />
TaskImpl task =(TaskImpl)remoteObject.narrow(initialContext.lookup("com.ibm.ejb3.poc.session.Task"),TaskImpl.class);<br />
<br />
} catch (Exception e) {<br />
// TODO Auto-generated catch block<br />
e.printStackTrace();<br />
}<br />
}<br />
<br />
I get the following exception:<br />
<br />
Feb 25, 2008 9:18:35 AM com.ibm.ws.util.ImplFactory<br />
WARNING: WSVR0073W<br />
java.lang.ClassCastException: cannot cast class org.omg.stub.java.rmi._Remote_Stub to class com.ibm.ejb3.poc.session.TaskImpl<br />
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:396)<br />
at tst.TestClient.main(TestClient.java:28)<br />
<br />
any ideas?<br />
<br />
Thanks, Salem
a***@eg.ibm.com
2008-02-26 08:01:04 UTC
Permalink
Thanks for your help Randy, i created the stubs manually and it worked.
Randy Schnier
2008-02-26 14:36:29 UTC
Permalink
Glad to hear that.
Post by a***@eg.ibm.com
Thanks for your help Randy, i created the stubs manually and it worked.
Loading...