5 Replies Latest reply on May 19, 2002 9:57 AM by frankseidinger

    Local interface between web-application and session bean

    tom.baeyens

      Hi,
      I'm using jboss-3.0.0RC2_tomcat-4.0.3
      I'm trying to create a session bean and access it from a web-application using the session bean's local interface.
      Is it impossible to do that ?
      Anybody a suggestion on how to solve the error ?
      As documentation I used the dtd's in ${JBOSS_HOME}/lib/jboss.jar, is there other documentation or examples available ?
      Thanks for your attention, Tom.

      === error shown when the web-application is deployed =========================================================================================
      18:15:16,988 INFO [MainDeployer] Starting deployment of package: file:/C:/JavaFiles/jboss-3.0.0RC2_tomcat-4.0.3/server/default/deploy/walitest.war
      18:15:17,028 INFO [EmbeddedCatalinaServiceSX] deploy, ctxPath=/walitest, warUrl=file:/C:/JavaFiles/jboss-3.0.0RC2_tomcat-4.0.3/server/default/tmp/deploy/server/default/deploy/walitest.war/96.walitest.war
      18:15:17,058 INFO [Engine] WebappLoader[/walitest]: Deploying class repositories to work directory C:\JavaFiles\jboss-3.0.0RC2_tomcat-4.0.3\catalina\work\localhost\walitest
      18:15:17,058 INFO [Engine] StandardManager[/walitest]: Seeding random number generator class java.security.SecureRandom
      18:15:17,058 INFO [Engine] StandardManager[/walitest]: Seeding of random number generator has been completed
      18:15:17,128 INFO [Engine] ContextConfig[/walitest]: Added certificates -> request attribute Valve
      18:15:17,178 INFO [EmbeddedCatalinaServiceSX] Using Java2 parent classloader delegation: true
      18:15:17,188 ERROR [EmbeddedCatalinaServiceSX] Failed to setup web application ENC
      javax.naming.NamingException: ejb-local-ref: ejb/LiTest, target not found, add valid ejb-link
      at org.jboss.web.AbstractWebContainer.linkEjbLocalRefs(AbstractWebContainer.java:758)
      at org.jboss.web.AbstractWebContainer.parseWebAppDescriptors(AbstractWebContainer.java:568)
      at org.jboss.web.AbstractWebContainer$DescriptorParser.parseWebAppDescriptors(AbstractWebContainer.java:1051)
      at org.jboss.web.catalina.EmbeddedCatalinaServiceSX.contextInit(EmbeddedCatalinaServiceSX.java:382)
      at org.jboss.web.catalina.EmbeddedCatalinaServiceSX.access$000(EmbeddedCatalinaServiceSX.java:74)
      at org.jboss.web.catalina.EmbeddedCatalinaServiceSX$1.lifecycleEvent(EmbeddedCatalinaServiceSX.java:310)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:155)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1131)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:3345)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:785)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:454)
      at org.jboss.web.catalina.EmbeddedCatalinaServiceSX.createWebContext(EmbeddedCatalinaServiceSX.java:318)
      at org.jboss.web.catalina.EmbeddedCatalinaServiceSX.performDeploy(EmbeddedCatalinaServiceSX.java:238)
      at org.jboss.web.AbstractWebContainer.start(AbstractWebContainer.java:406)
      at org.jboss.deployment.MainDeployer.start(MainDeployer.java:692)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:527)
      at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:490)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
      at $Proxy4.deploy(Unknown Source)
      at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:405)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scanDirectory(URLDeploymentScanner.java:586)
      at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:465)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:202)
      at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:191)
      18:15:17,188 INFO [Engine] StandardWrapper[/walitest:default]: Loading container servlet default
      18:15:17,188 INFO [Engine] default: init
      18:15:17,188 INFO [Engine] StandardWrapper[/walitest:invoker]: Loading container servlet invoker
      18:15:17,188 INFO [Engine] invoker: init
      18:15:17,188 INFO [Engine] jsp: init
      18:15:17,208 INFO [MainDeployer] Successfully completed deployment of package: file:/C:/JavaFiles/jboss-3.0.0RC2_tomcat-4.0.3/server/default/deploy/walitest.war
      ==============================================================================================================================================


      Session bean deployment descriptors (packed in litest.jar) :

      === ejb-jar.xml =========================================
      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar>
      litest
      <display-name>litest</display-name>
      <enterprise-beans>

      <ejb-name>LiTest</ejb-name>
      <local-home>be.sdco.litest.LiTestHome</local-home>
      be.sdco.litest.LiTestLocal
      <ejb-class>be.sdco.litest.LiTestBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Container</transaction-type>

      </enterprise-beans>
      </ejb-jar>
      =========================================================

      === jboss.xml ===========================================
      <?xml version="1.0" encoding="UTF-8"?>

      <enterprise-beans>

      <ejb-name>LiTest</ejb-name>
      <local-jndi-name>ejb/LiTest</local-jndi-name>

      </enterprise-beans>

      =========================================================


      Web app deployment descriptors (packed in walitest.war):

      === web.xml =============================================
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd">
      <web-app>
      <ejb-local-ref>
      <ejb-ref-name>ejb/LiTest</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      <local-home>be.sdco.litest.LiTestHome</local-home>
      be.sdco.litest.LiTestLocal
      <ejb-link>ejb/LiTest</ejb-link>
      </ejb-local-ref>
      </web-app>
      =========================================================

      === jboss-web.xml =======================================
      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-web>
      <ejb-ref>
      <ejb-ref-name>ejb/LiTest</ejb-ref-name>
      <jndi-name>ejb/LiTest</jndi-name>
      </ejb-ref>
      </jboss-web>
      =========================================================

        • 1. Re: Local interface between web-application and session bean
          davidjencks

          It isn't clear to me whether the ejb jar is getting deployed before the war. Is it? Can you see the local interface bound in jndi before you deploy the war?

          • 2. Re: Local interface between web-application and session bean

            Your <ejb-link> should be the <ejb-name>
            i.e. LiTest not ejb/LiTest

            Regards,
            Adrian

            • 3. Re: Local interface between web-application and session bean
              tom.baeyens

              The ejb jar (litest.jar) is deployed first.
              === output when deploying litest.jar ==================================================
              09:45:56,707 INFO [MainDeployer] Starting deployment of package: file:/C:/JavaFiles/jboss-3.0.0RC2_tomcat-4.0.3/server/default/deploy/litest.jar
              09:45:56,787 INFO [EjbModule] Creating
              09:45:56,807 INFO [EjbModule] Deploying LiTest
              09:45:57,338 INFO [EjbModule] Created
              09:45:57,338 INFO [EjbModule] Starting
              09:45:57,348 INFO [EjbModule] Started
              09:45:57,348 INFO [MainDeployer] Successfully completed deployment of package: file:/C:/JavaFiles/jboss-3.0.0RC2_tomcat-4.0.3/server/default/deploy/litest.jar
              =============================================================================

              Should there be some output about jndi-binding ?
              Regards, Tom.

              • 4. Re: Local interface between web-application and session bean
                tom.baeyens

                OK, I got it working.

                Before I posted this question, I tried also the correct ejb-name in the ejb-link but then it did not work. Just now I found in the documentation that ejb-link is for internal references (http://www.jboss.org/online-manual/HTML/ch07s22.html). If I understand correctly internal references can only be created between modules in the same deployment-unit. That was my problem. After changing the ejb-link and packing the web application and the session bean into an ear-file, it worked.

                What still seems strange to me is that in order to use local references between a web application and a bean, I have to provide 2 separate references in the deployment descriptors of the web application : the ejb-link (in web.xml) and the ejb-ref (in jboss-web.xml). If there is a simple explanation, please let me know.

                Another question still open is : Is it possible to use local interfaces between a web application and an ejb in two separate deployment units ?

                Thanks already a lot.
                I hope I can be of service for one day...
                Regards, Tom.

                • 5. Re: Local interface between web-application and session bean
                  frankseidinger

                  Hi Tom,

                  you can even use local interfaces of ejb components, that are not packaged with your ear files. It took me quite a while to realize, that local ejb components are always mapped to the jndi context 'local'.

                  Considering the following deployment descriptor would lead to an ejb component with a local interface, that can be obtained with the jndi name 'local/Person'. Where Person is the name of the ejb component. Your webapp needn't declare a <ejb-local-ref> to work.

                  == ejb-jar.xml ============================
                  <ejb-jar>
                  ...
                  <enterprise-beans>
                  ...

                  ...
                  <ejb-name>Person</ejb-name>
                  <local-home>person.PersonHome</local-home>
                  person.Person
                  ...

                  ...
                  </enterprise-beans>
                  ...
                  </ejb-jar>
                  ===========================================

                  The hint to the name mapping comes from the server logs. You should find a line for your bean similar to:

                  ...
                  2002-05-19 01:23:36,677 DEBUG [org.jboss.ejb.EntityContainer] Begin java:comp/env for EJB: Person
                  2002-05-19 01:23:36,677 DEBUG [org.jboss.ejb.EntityContainer] TCL: java.net.URLClassLoader@48ecc
                  2002-05-19 01:23:36,677 DEBUG [org.jboss.ejb.EntityContainer] End java:comp/env for EJB: Person
                  2002-05-19 01:23:36,677 DEBUG [org.jboss.ejb.plugins.local.BaseLocalContainerInvoker] Bound EJBLocalHome of Person to local/Person
                  ...

                  Best regards,

                  Frank.