0 Replies Latest reply on Feb 17, 2015 3:34 AM by noboundaries

    Issues at EJB 3.x Sample Application with distributed packaging - Jboss 7.x

    noboundaries Newbie

      JBoss EAP 6.3.0.Alpha1 (AS 7.4.0.Final-redhat-4)

      jdk1.7.0_67

      Eclipse Java EE IDE for Web Developers.Version: Luna Service Release 1a (4.4.1)

       

       

      Created a sample EJB 3.x application

       

       

          // Stateless Bean

       

              package ejb3inaction.example;

              import javax.ejb.Stateless;

              @Stateless

              public class HelloUserBean implements HelloUser{

                public String sayHello(String name) { return String.format("Hello %s welcome to EJB 3.1!", name); } }

       

          //Remote class- Just a Interface for the bean

              package ejb3inaction.example;

              import javax.ejb.Remote;

              @Remote

              public interface HelloUser {String sayHello(String name);    }

       

       

      Deployed in Jboss (Eclipse - Right click on Project - Run as - Run on server) - Below is the server log

       

       

          16:26:21,770 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015876: Starting deployment of "SampleEJB_3_2.jar" (runtime-name: "SampleEJB_3_2.jar")

          16:26:21,770 INFO  [org.jboss.as.remoting] (MSC service thread 1-16) JBAS017100: Listening on 127.0.0.1:4447

          16:26:21,770 INFO  [org.jboss.as.remoting] (MSC service thread 1-14) JBAS017100: Listening on 127.0.0.1:9999

          16:26:21,926 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-5) JNDI bindings for session bean named HelloUserBean in deployment unit deployment "SampleEJB_3_2.jar" are as follows:

       

          java:global/SampleEJB_3_2/HelloUserBean!ejb3inaction.example.HelloUser

          java:app/SampleEJB_3_2/HelloUserBean!ejb3inaction.example.HelloUser

          java:module/HelloUserBean!ejb3inaction.example.HelloUser

          java:jboss/exported/SampleEJB_3_2/HelloUserBean!ejb3inaction.example.HelloUser

          java:global/SampleEJB_3_2/HelloUserBean

          java:app/SampleEJB_3_2/HelloUserBean

          java:module/HelloUserBean

       

       

       

       

      Created a SampleWebApplication and deployed at the same JBoss server where the above EJB 3.x app got deployed

       

       

      java client

       

       

          package ejb3inaction.example.utilization;

          import javax.ejb.EJB;

          import javax.naming.Context;

          import javax.naming.InitialContext;

          import javax.naming.NamingException;

          import ejb3inaction.example.HelloUser;

       

          public class HelloUserBeanClient{

       

          // EJB 3.x Client Injection

       

          @EJB

          private HelloUser helloUser;

          public String hello(){return helloUser.sayHello("Hello EJB 3.X");}

       

         //EJB Client Legacy Lookup support

       

          public String helloLegasySupport() throws NamingException{

          Context context = new InitialContext();

          HelloUser helloUser1 = (HelloUser)context.lookup("java:global/SampleEJB_3_2/HelloUserBean");

          return helloUser1.sayHello("Legacy support from EJB 3.X ");

          } }

       

       

      JSP CLient - A view that in turn calls the java client

       

       

          <jsp:useBean id="ejbClient" class="ejb3inaction.example.utilization.HelloUserBeanClient"></jsp:useBean>

          <%

          try{

          out.println(ejbClient.hello());

          }

          catch(Exception e) {

          out.println("<br > ejbTest - hello " + e.getMessage());

          }

          try{

          out.println(ejbClient.helloLegasySupport());

          }

          catch(Exception e) {

          out.println("<br > ejbTest - helloLegasySupport " + e.getMessage());

          }

       

       

      Receiving class not found Exception while accessing the JSP client. However I could see both the classes(HelloUserBean.class, HelloUser.class) got generated and  available at "jboss-eap-6.3\standalone\deployments\SampleEJB_3_2.jar\ejb3inaction\example"

       

      Note that, it is required to have them in standalone packaging ( ‘app war’ and ‘ejb jar’) for project needs.  Uses “java:global” jndi namespace to make sure the lookup spot out the jndi reference as the app and ejb are not packaged into a ear. However, the client app don’t have the visibility for the ejb classes though they are deployed in the same server(JVM),  the lookup using global jndi namespace, also the class files got generated and available inside the ejb jar.

       

       

      Error @ EJB 3.X Client Support - hello()

       

       

          JBWEB000071: root cause

       

          java.lang.ClassNotFoundException: ejb3inaction.example.HelloUserBean from [Module "deployment.SampleWebApplication.war:main" from Service Module Loader]

          org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)

          org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443)

          org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431)

          org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373)

          org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118)

          ejb3inaction.example.utilization.HelloUserBeanClient.hello(HelloUserBeanClient.java:17)

          org.apache.jsp.ejbTest_jsp._jspService(ejbTest_jsp.java:78)

          org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69)

          javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

          org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:365)

          org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309)

          org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242)

          javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

       

       

      Error @ Legacy Support - helloLegasySupport()

       

       

          JBWEB000071: root cause

       

              java.lang.ClassNotFoundException: ejb3inaction.example.HelloUser from [Module "deployment.SampleWebApplication.war:main" from Service Module Loader]

              org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)

              org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443)

              org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431)

              org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373)

              org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118)

              ejb3inaction.example.utilization.HelloUserBeanClient.helloLegasySupport(HelloUserBeanClient.java:22)

              org.apache.jsp.ejbTest_jsp._jspService(ejbTest_jsp.java:78)

              org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69)

              javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

              org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:365)

              org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309)

              org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242)

              javax.servlet.http.HttpServlet.service(HttpServlet.java:847)