5 Replies Latest reply on Aug 24, 2012 2:57 AM by Oliver Katzer

    [JBoss7] Remote EJB3 calls from spawned thread

    dario novakovic Newbie

      I have simple remote ejb client that calls remote stateless beans. There is security enabled on the server.


      All is well for single threrad, authentication and authorization and remote call works:


      final Properties jndiProperties = new Properties();

      jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

      jndiProperties.put(Context.SECURITY_PRINCIPAL, "XXX");

      jndiProperties.put(Context.SECURITY_CREDENTIALS, "XXX");

      jndiProperties.put("jboss.naming.client.ejb.context", true);

      jndiProperties.put(Context.PROVIDER_URL, "remote://serverIP:4447");

      jndiProperties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

      jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());


      Context context = new InitialContext(jndiProperties);


      RemoteService rs = (RemoteService)context.lookup("ejb:app/app-ejb-1.0-SNAPSHOT/RemoteBean!com.app.services.remoting.RemoteService");



      So far so good, authentication is OK and remote call works.


      However, If i make remote call from another thread, like from event handler in GUI application, I get:


      java.lang.IllegalStateException: No EJB receiver available for handling [appName:app,modulename:app-ejb-1.0-SNAPSHOT,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@12a55aa


      I realised that this is security-related problem and reason for this is that "EJB security context" is thread-local-var and it is missing in all spawned threads. It is present in the main thread and remoting works. Am I right?


      What am I supposed to do to make secured EJB remote calls from event handlers?