5 Replies Latest reply on Jul 7, 2009 5:12 PM by redguard

    remote ejb call and backing bean constructor

    redguard

      hi , i have deployed a jar a machine aunder jboss 5 , configure it it run just fine, now i exported my ejb project as jar to use it in my web project , i added a test class in my web project like :


      package com.vox.utils;
      
      
      import java.util.List;
      import java.util.Properties;
      
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      import com.vox.core.services.VoxManager;
      import com.vox.core.persistence.model.Cdr;
      
      
      public class voxClientTest {
       public static void main(String [] args) {
      
       try {
      
      
       Properties props = new Properties();
       props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       props.setProperty("java.naming.provider.url", "jnp://192.168.1.201:1099");
       props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
       props.setProperty("jnp.socket.Factory", "org.jnp.interfaces.TimedSocketFactory");
      
       Context context = new InitialContext(props);
      
       try {
       VoxManager VoxManager = (VoxManager) context.lookup("VoxService/remote");
      
       List<Cdr> cdr = (List<Cdr>) VoxManager.findAllCdr();
       for(Cdr o:cdr)
       {
       System.out.println("***"+o.getClid());
      
       }
      
       } catch (NamingException e) {
       e.printStackTrace();
       }
      
       int e=23;
       } catch (Exception ex) {
       ex.printStackTrace();
       }
      
      }
       private static Context getInitialContext() throws NamingException {
       return new InitialContext();
       }
      
      }
      


      in my backend bean who is used to display a datatable in a jsp , backend bean code:



      package com.vox.bean.view;
      
      import java.util.ArrayList;
      import java.util.List;
      import java.util.Properties;
      
      import javax.annotation.PostConstruct;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      
      import javax.naming.NamingException;
      
      import com.vox.core.persistence.model.Cdr;
      import com.vox.core.services.VoxManager;
      
      
      
      public class ShowCdrsView {
      
       List cdrs = new ArrayList();
      
       public ShowCdrsView() {
      
       Properties props = new Properties();
       props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       props.setProperty("java.naming.provider.url", "jnp://192.168.1.201:1099");
       props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
       props.setProperty("jnp.socket.Factory", "org.jnp.interfaces.TimedSocketFactory");
      
      
       try {
       System.out.println("111");
       Context context = new InitialContext(props);
       System.out.println("22");
       VoxManager VoxManager = (VoxManager) context.lookup("VoxService/remote");
      
       List<Cdr> cdr = (List<Cdr>) VoxManager.findAllCdr();
       for(Cdr o:cdr)
       {
       System.out.println("***"+o.getClid());
       }
      
       } catch (NamingException e) {
       e.printStackTrace();
       }
      
       }
      
       public List getCdrs() {
       return cdrs;
       }
      
       public void setCdrs(List cdrs) {
       this.cdrs = cdrs;
       }
      
       private static Context getInitialContext() throws NamingException {
      
       return new InitialContext();
       }
      
      
      }
      
      


      but it was giving me the error :

      111
      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
       at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
       at javax.naming.InitialContext.init(InitialContext.java:223)
       at javax.naming.InitialContext.<init>(InitialContext.java:197)
       at com.vox.bean.view.ShowCdrsView.init(ShowCdrsView.java:38)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.apache.catalina.util.DefaultAnnotationProcessor.postConstruct(DefaultAnnotationProcessor.java:79)
       at com.sun.faces.vendor.Tomcat6InjectionProvider.invokePostConstruct(Tomcat6InjectionProvider.java:82)
       at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:327)
       at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:551)
       at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
       at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
       at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
       at com.sun.faces.config.ManagedBeanFactoryImpl.evaluateValueExpressionGet(ManagedBeanFactoryImpl.java:1003)
       at com.sun.faces.config.ManagedBeanFactoryImpl.setPropertiesIntoBean(ManagedBeanFactoryImpl.java:636)
       at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:317)
       at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:551)
       at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
       at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
       at org.apache.el.parser.AstValue.getValue(AstValue.java:86)
       at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
       at javax.faces.component.UIData.getValue(UIData.java:582)
       at org.ajax4jsf.component.UIDataAdaptor.getValue(UIDataAdaptor.java:1640)
       at org.ajax4jsf.component.SequenceDataAdaptor.getDataModel(SequenceDataAdaptor.java:48)
       at org.ajax4jsf.component.SequenceDataAdaptor.createDataModel(SequenceDataAdaptor.java:42)
       at org.richfaces.component.UIDataTable.createDataModel(UIDataTable.java:122)
       at org.ajax4jsf.component.UIDataAdaptor.getExtendedDataModel(UIDataAdaptor.java:621)
       at org.ajax4jsf.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:339)
       at org.richfaces.renderkit.AbstractTableRenderer.encodeTableStructure(AbstractTableRenderer.java:121)
       at org.richfaces.renderkit.html.DataTableRenderer.doEncodeBegin(DataTableRenderer.java:206)
       at org.richfaces.renderkit.html.DataTableRenderer.doEncodeBegin(DataTableRenderer.java:194)
       at org.ajax4jsf.renderkit.RendererBase.encodeBegin(RendererBase.java:101)
       at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:785)
       at javax.faces.component.UIData.encodeBegin(UIData.java:879)
       at org.ajax4jsf.component.UIDataAdaptor.encodeBegin(UIDataAdaptor.java:1220)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:884)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
       at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
       at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
       at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Class.java:247)
       at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
       at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
       ... 70 more
      


      which primarly suggest , that i don;t have jbossclient.jar !! , but the test client class is in the same project and she is working just fine,

      after a little googling i add PostContruct to my backing bean:

      
      import java.util.ArrayList;
      import java.util.List;
      import java.util.Properties;
      
      import javax.annotation.PostConstruct;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      
      import javax.naming.NamingException;
      
      import com.vox.core.persistence.model.Cdr;
      import com.vox.core.services.VoxManager;
      
      
      
      public class ShowCdrsView {
      
       List cdrs = new ArrayList();
      
      
       @PostConstruct
       public void init() {
      
       Properties props = new Properties();
       props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       props.setProperty("java.naming.provider.url", "jnp://192.168.1.201:1099");
       props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
       props.setProperty("jnp.socket.Factory", "org.jnp.interfaces.TimedSocketFactory");
      
      
       try {
       System.out.println("111");
       Context context = new InitialContext(props);
       System.out.println("22");
       VoxManager VoxManager = (VoxManager) context.lookup("VoxService/remote");
      
       List<Cdr> cdr = (List<Cdr>) VoxManager.findAllCdr();
       for(Cdr o:cdr)
       {
       System.out.println("***"+o.getClid());
      
       }
      
      
      
       } catch (NamingException e) {
       e.printStackTrace();
       }
       }
      
       public ShowCdrsView() {
      
       }
      
       public List getCdrs() {
       return cdrs;
       }
      
       public void setCdrs(List cdrs) {
       //init();
       this.cdrs = cdrs;
       }
      
       private static Context getInitialContext() throws NamingException {
      
       return new InitialContext();
       }
      
      
      }
      
      


      but still same issue .
      any idea how to call my ejb remotly in my backing bean constructor?

      and thanks a lot

        • 1. Re: remote ejb call and backing bean constructor
          jaikiran

          Is this backing bean running in the same server where you have your EJB? Also which exact version of JBoss do you use? And do you package any JBoss specific jar files within your application? And is any IDE involved? If yes, try reproducing this without the IDE in picture.

          • 2. Re: remote ejb call and backing bean constructor
            redguard

            Hi jaikiran,

            well ;
            i'm using jboss 5.0.1 GA ; on the server side , i'm deploying my ejb project using eclipse and jboss tools ; the test there work normally.

            on my application i use myeclipse 7.5 ; so in my web app add the ejbJar(that i exported from my other machine) and jbossallClient.jar from the same jboss5.0.1 , it's the only jar i added a part frommy regular jar needed(richfaces/commons/and the rest ....).

            reproducing all this stuff without myeclipse/eclipse is a LOT of work :d , i tried before but didn't succed :d....

            • 3. Re: remote ejb call and backing bean constructor
              jaikiran

              Along with the jbossall-client.jar you also have to include all the jars files that are listed in the MANIFEST.MF of the jbossall-client.jar, in the client classpath.

              • 4. Re: remote ejb call and backing bean constructor
                redguard

                hi,
                MANIFEST.MF is empty in my project ; the problem is not a missing jar because if i call in my web project a test client class with the same code ; it will work ; the problem :( is the injection of the code in the constructor of the backing bean

                and thanks

                • 5. Re: remote ejb call and backing bean constructor
                  redguard

                  Hi , jaikiran ,

                  thanks mate yu were right ( i missread yu answer...) , adding all the jar listed in the file fixed the issue.