1 Reply Latest reply on Oct 14, 2014 6:47 AM by Wolf-Dieter Fink

    remote ejb lookup from servlet doesn't work (no ejb receiver available)

    Alessandro Gelormini Newbie

      hi, i have two running jboss eap 6.1. One is back end with session bean and db query, the other is the front end with a simple servlet.

      I have configured  both jboss to support remote connection (i'm using also in other project so i know how to do it), but i have problems doing lookup from servlet.

      The client project is a dynamic web project with a servlet and a web service. Running same lookup code form a web method in web service and doPost in servlet results in different output: web method runs well and calls the remote bean,doPost throws no ejb receiver available for handling exception. I don't know why servlet doesn't like remote lookups.

       

      FRONT END standalone.xml

       

      <remote-outbound-connection name="remote-ejb-connection3" outbound-socket-binding-ref="remote-ejb" username="remoteUser" security-realm="ejb-security-realm">
                          <properties>
                              <property name="SASL_POLICY_NOANONYMOUS" value="false"/>
                              <property name="SSL_ENABLED" value="false"/>
                          </properties>
                      </remote-outbound-connection>
      

       

      <outbound-socket-binding name="remote-ejb">
                  <remote-destination host="192.168.30.78" port="4445"/>
              </outbound-socket-binding>
      

       

      FRONT END jboss-ejb-client.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-ejb-client xmlns="urn:jboss:ejb-client:1.0">
          <client-context>
              <ejb-receivers>
                  <remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection3"/>
              </ejb-receivers>
          </client-context>
      </jboss-ejb-client>
      

       

      WEB METHOD CODE (IT WORKS)

       

      @WebService(name = "ProvaService")
      public class ProvaService {
      
      
        @WebMethod
        @WebResult(name = "prova")
        public String prova() {
        String ret = "OK";
        try {
        Utility.getInstance().initContext();
        } catch (Exception e1) {
        ret = "KO 1";
        e1.printStackTrace();
        }
      
      
        try {
      
      
        Utility.getInstance().getBean().insertDevice(new ArrayList<Device>());
        } catch (Exception e) {
        ret = "KO 2";
        e.printStackTrace();
        }
        return ret;
      
      
        }
      
      
      }
      
      
      
      
      
      
      
      
      
      
      
      
      

       

      SERVLET CODE (FAILS)

       

       

      @WebServlet("/ProvaServlet")
      public class ProvaServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
      
      
      
        /**
        * @see HttpServlet#HttpServlet()
        */
        public ProvaServlet() {
        super();
        // TODO Auto-generated constructor stub
        }
      
      
      
      
      
      
      
      
      
      
        /**
        * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
        *      response)
        */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("CHIAMATA SERVLET GET");
        PrintWriter out = response.getWriter();
        out.write("Hi GET");
        }
      
      
        /**
        * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
        *      response)
        */
        @SuppressWarnings("unchecked")
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("CHIAMATA SERVLET POST");
        PrintWriter out = response.getWriter();
      
      
      
        try {
        Utility.getInstance().initContext();
        } catch (Exception e1) {
        ret = "KO 1";
        e1.printStackTrace();
        }
      
      
        try {
      
      
        Utility.getInstance().getBean().insertDevice(new ArrayList<Device>());
        } catch (Exception e) {
        ret = "KO 2";
        e.printStackTrace();
        }
      
      
      
        out.write("Hi POST");
        }
      
      
      
      
      
      }
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

       

       

      STACK TRACE

       

      11:17:10,426 INFO  [stdout] (http-/192.168.30.78:8080-1) CHIAMATA SERVLET POST
      11:17:10,450 ERROR [stderr] (http-/192.168.30.78:8080-1) java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:ProvaTelecomBackEnd, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@7af859ab
      11:17:10,451 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:727)
      11:17:10,452 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
      11:17:10,475 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:183)
      11:17:10,476 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
      11:17:10,541 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
      11:17:10,541 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
      11:17:10,542 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
      11:17:10,542 ERROR [stderr] (http-/192.168.30.78:8080-1)        at com.sun.proxy.$Proxy75.insertDevice(Unknown Source)
      11:17:10,542 ERROR [stderr] (http-/192.168.30.78:8080-1)        at main.ProvaServlet.doPost(ProvaServlet.java:207)
      11:17:10,543 ERROR [stderr] (http-/192.168.30.78:8080-1)        at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
      11:17:10,543 ERROR [stderr] (http-/192.168.30.78:8080-1)        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
      11:17:10,543 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
      11:17:10,565 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
      11:17:10,581 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      11:17:10,636 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
      11:17:10,667 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
      11:17:10,702 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)
      11:17:10,706 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
      11:17:10,733 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
      11:17:10,738 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)
      11:17:10,766 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      11:17:10,776 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)
      11:17:10,781 ERROR [stderr] (http-/192.168.30.78:8080-1)        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920)
      11:17:10,803 ERROR [stderr] (http-/192.168.30.78:8080-1)        at java.lang.Thread.run(Thread.java:724)
      
      

       

      BACK END DEPLOY

       

      09:58:54,253 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named Bean in deployment unit deployment "ProvaTelecomBackEnd.jar" are as follows:
      
      
              java:global/ProvaTelecomBackEnd/Bean!bean.RemoteBean
              java:app/ProvaTelecomBackEnd/Bean!bean.RemoteBean
              java:module/Bean!bean.RemoteBean
              java:jboss/exported/ProvaTelecomBackEnd/Bean!bean.RemoteBean
              java:global/ProvaTelecomBackEnd/Bean
              java:app/ProvaTelecomBackEnd/Bean
              java:module/Bean
      
      
      
      

       

      UTILITY.JAVA

       

      public class Utility {
      
      
        private Context context = null;
        private static Utility instance = null;
        private RemoteBean gestore = null;
      
      
        public static Utility getInstance() {
        if (instance == null)
        instance = new Utility();
        return instance;
        }
      
      
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public void initContext() throws Exception {
        final Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        if (context == null)
        context = new InitialContext(jndiProperties);
      
      
        }
      
      
        public void closeContext() {
        try {
        this.context.close();
        } catch (NamingException e) {
      
      
        e.printStackTrace();
        }
        }
      
      
        public RemoteBean getBean() throws Exception {
        if (gestore == null)
        gestore = (RemoteBean) context.lookup("ejb:/ProvaTelecomBackEnd//Bean!bean.RemoteBean");
      
      
        return gestore;
        }
      
      
      }
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

       

       

      I tried some modifications of lookup but nothing changed. Strange thing is that errors came up when i call the remote method insertDevice, initcontext and getBean seems to works.

       

      any solution??