Discussions

EJB programming & troubleshooting: Urgent Pl: How to make use of EJB which was written by someone?

  1. Hello,
    I am new to EJB world, any help is greatly appreciated.

    Versions: JDK 1.3.1, EJB 2.0, WebLogic 7.1

    Let me explain the problem:
    1) I have developed an EJB1 under WEBAPP1,
    2) EJB2 developed under WEBAPP2.
    3) I have deployed both EJB's (jar files) under
       \applications on same server.
    4) I have a client program Test.jsp (under WEBAPP1) which access EJB1 using JNDI lookup, it works fine.
    5) If try to access EJB2 methods for Testtwo.jsp (under WEBAPP2), client program (JSP) works fine.

    6) Buit, When I try to access EJB2 methods from Test.jsp it complains.
    Am I doing any thing wrong? Any problem with stub/skelton?

    FYI: I didn't do java weblogic.ejbc, instead from WebLogic console, I have deployed the EJB using Configure a new EJB option.

    Error:
    <Jun 12, 2003 3:16:33 PM CDT> <Error> <HTTP> <101046> <[ServletContext(id=758109
    ,name=WEBAPP2,context-path=/WEBAPP2)] Compilation of /dvl/lwc/wls/lwc01/lwc01_admi
    n/.wlnotdelete/WEBAPP2_WEBAPP2_758109/jsp_servlet/__hello_45_ejb.java failed:
    /dvl/lwc/wls/lwc01/lwc01_admin/.wlnotdelete/WEBAPP2_WEBAPP2_758109/jsp_servlet/__h
    ello_45_ejb.java:128: cannot resolve symbol
    symbol : class EJB2Home
    location: class jsp_servlet.__hello_45_ejb
                EJB2Home home1 = (EJB2Home)PortableRemoteObject.narrow(h1, EJB2Home.
    class); //[ /hello-ejb.jsp; Line: 38]
                ^
    /dvl/lwc/wls/lwc01/lwc01_admin/.wlnotdelete/WEBAPP2_WEBAPP2_758109/jsp_servlet/__h
    ello_45_ejb.java:128: cannot resolve symbol
    symbol : class EJB2Home
    location: class jsp_servlet.__hello_45_ejb
                EJB2Home home1 = (EJB2Home)PortableRemoteObject.narrow(h1, EJB2Home.
    class); //[ /hello-ejb.jsp; Line: 38]
                                  ^
    /dvl/lwc/wls/lwc01/lwc01_admin/.wlnotdelete/WEBAPP2_WEBAPP2_758109/jsp_servlet/__h
    ello_45_ejb.java:128: cannot resolve symbol
    symbol : class EJB2Home
    location: class jsp_servlet.__hello_45_ejb
                EJB2Home home1 = (EJB2Home)PortableRemoteObject.narrow(h1, EJB2Home.
    class); //[ /hello-ejb.jsp; Line: 38]
                                                                           ^
    /dvl/lwc/wls/lwc01/lwc01_admin/.wlnotdelete/WEBAPP2_WEBAPP2_758109/jsp_servlet/__h
    ello_45_ejb.java:131: cannot resolve symbol
    symbol : class EJB2
    location: class jsp_servlet.__hello_45_ejb
                EJB2 hw1 = home1.create(); //[ /hello-ejb.jsp; Line: 41]
                ^
    4 errors
  2. Ramu:

       As you have mentioned you are new to EJBs. I will like to confirm if you have done these two webapps coz you donno or is it a requirement. Thing is you can deploy multiple EJBs in one webapp. so if you dont have specific need to call a EJB from other application then go ahead and move your ejb2 from webapp2 to one and it will be all smooth and easy for you.

       One way to use other webapp ejbs is to use servlets and make a call. This is well accepted pattern, that way you dont have to worry about getting the stub for the bean from the ejb supplied.

       To make your jndi call work, you will have to add a entry in your dd giving class path for the bean with url. secondly u will need bean stubb to operate on it.

    Regards
    Chetan
  3. Thanks Chetan,
    In our organization, we are going to have an enterprise group, they will provide some EJB services to application groups. Thats why I have created multiple webapps and EJBs and figuring out how to use them.

    This is how my EJB2 dd looks like:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    <enterprise-beans>
    <session>
    <ejb-name>Test</ejb-name>
    <home>com.nwa.lwc.ejb.TestHome</home>
    <remote>com.nwa.lwc.ejb.Test</remote>
    <ejb-class>com.nwa.lwc.ejb.TestBean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
    </session>
    </enterprise-beans>
    </ejb-jar>

    How do I prefix the classpath to bean class?
    Do I need to prefix webapp2 to <ejb-class>, because both webapps are hosted on same server. Will it look like webapp2.com.nwa.lwc.ejb.TestBean ???

    I will give a try.

    Can you please throw some light and share your experience.
    I believe weblogic already created stub/skelton.

    Thanks, Ramu
  4. Ramu:

    J2EE app servers use a heirarchial class loader. The child classloader can access parent classloaders classes, but not vice-versa. The "weblogic server classloader" loads "ejb classloader", in turn "ejb classloader" loads "Webcontainer classloader". Since, ejb1 class is visible to Webapp webcontainer classloader, the jspcompiler has no problem compiling this page. However, Test2.jsp is being compiled in webapp2 which is in a totally different hierarchy, the classloader doesn't find the home interface and hence not able to compile Test 2.

    Solution, you need to publish your home/remote/local/key interface to other webapplication. In your environment you generate a bundle (ejb_client.jar) for all each ejb and give it to the "applications" group. The following link tells you how to generate that bundle.

    http://edocs.bea.com/wls/docs70/ejb/EJB_packaging.html#1078958

    The application group can include that bundle in their webapplication or the J2ee application assmbler might stick this bundle in some hihger level classloader.

    Anshuman