2 Replies Latest reply on Jun 18, 2012 3:38 AM by thomas.diesler

    jboss-ejb-client.xml in OSGi bundle is ignored

    steffenwollscheid

      Hi,

       

      in Jboss 7.1.1.Final (Brontes), i would like to call a remote EJB in a different server instance from within an OSGi bundle deployed into JBoss7, using standard remote EJB call, as described in https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance.

       

      This works perfectly EXCEPT FOR OSGi bundles.

       

      During deployment of the OSGi bundle no information on the console shows any processing of the jboss-ejb-client.xml at all, and when trying to call the remote EJB, the following Exception will occur:

       

      10:09:46,963 ERROR [stderr] (RMI TCP Connection(1)-10.0.103.124) java.lang.IllegalStateException: No EJB receiver available for handling [appName:application-ear-0.0.1-SNAPSHOT,modulename:ejb-definition-0.0.1-SNAPSHOT,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@3c826ab6

      10:09:46,966 ERROR [stderr] (RMI TCP Connection(1)-10.0.103.124)        at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)

      10:09:46,967 ERROR [stderr] (RMI TCP Connection(1)-10.0.103.124)        at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)

      10:09:46,968 ERROR [stderr] (RMI TCP Connection(1)-10.0.103.124)        at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)

      10:09:46,969 ERROR [stderr] (RMI TCP Connection(1)-10.0.103.124)        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)

      10:09:46,969 ERROR [stderr] (RMI TCP Connection(1)-10.0.103.124)        at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)

      10:09:46,970 ERROR [stderr] (RMI TCP Connection(1)-10.0.103.124)        at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

      10:09:46,971 ERROR [stderr] (RMI TCP Connection(1)-10.0.103.124)        at $Proxy15.add(Unknown Source)

       

       

      We tried to to create our own EJBClientContextSelector as described by Jaikiran Pai in https://community.jboss.org/thread/177302?start=0&tstart=0 - on the console the creation of the connection can be seen -  but of course, since we are within the AS we cannot replace the EJBClientContextSelector, due to the SELECTOR_LOCKED attribute in, which of course is set to true, so this approach does not work.

       

      10:20:35,001 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "ejb-accessor-osgi-0.0.1-SNAPSHOT.jar"

      10:20:35,033 INFO  [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-7) Install bundle: demo.experimental.ejb-accessor-osgi:0.0.1.SNAPSHOT

      10:20:35,100 INFO  [org.jboss.as.server] (management-handler-thread - 14) JBAS018559: Deployed "ejb-accessor-osgi-0.0.1-SNAPSHOT.jar"

      10:20:35,362 INFO  [org.jboss.ejb.client.remoting.VersionReceiver] (Remoting "client-endpoint" task-4) Received server version 1 and marshalling strategies [river]

      10:20:35,364 INFO  [org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver] (MSC service thread 1-7) Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@455ab929, receiver=Remoting connection EJB receiver [connection=Remoting connection <735f182>,channel=jboss.ejb,nodename=master:server-one]} on channel Channel ID c0978def (outbound) of Remoting connection 7a26dccc to /127.0.0.1:4447

      10:20:36,673 WARN  [org.jboss.ejb.client.remoting.ChannelAssociation] (Remoting "client-endpoint" task-2) Unsupported message received with header 0xffffffff

      10:20:36,674 ERROR [org.jboss.as.osgi] (MSC service thread 1-7) JBAS011900: Cannot start bundle: demo.experimental.ejb-accessor-osgi:0.0.1.SNAPSHOT: org.osgi.framework.BundleException: Cannot start bundle: demo.experimental.ejb-accessor-osgi:0.0.1.SNAPSHOT

              at org.jboss.osgi.framework.internal.HostBundleState.transitionToActive(HostBundleState.java:328) [jbosgi-framework-core-1.1.8.Final.jar:1.1.8.Final]

              at org.jboss.osgi.framework.internal.HostBundleState.startInternal(HostBundleState.java:223) [jbosgi-framework-core-1.1.8.Final.jar:1.1.8.Final]

              at org.jboss.osgi.framework.internal.AbstractBundleState.start(AbstractBundleState.java:494) [jbosgi-framework-core-1.1.8.Final.jar:1.1.8.Final]

              at org.jboss.as.osgi.deployment.BundleStartTracker$1.processService(BundleStartTracker.java:144) [jboss-as-osgi-service-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.osgi.deployment.BundleStartTracker$1.transition(BundleStartTracker.java:119) [jboss-as-osgi-service-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.msc.service.ServiceControllerImpl.invokeListener(ServiceControllerImpl.java:1416) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at org.jboss.msc.service.ServiceControllerImpl.access$2700(ServiceControllerImpl.java:49) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at org.jboss.msc.service.ServiceControllerImpl$ListenerTask.run(ServiceControllerImpl.java:1954) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_30]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_30]

              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_30]

      Caused by: java.lang.ExceptionInInitializerError

              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_30]

              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_30]

              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_30]

              at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_30]

              at java.lang.Class.newInstance0(Class.java:355) [rt.jar:1.6.0_30]

              at java.lang.Class.newInstance(Class.java:308) [rt.jar:1.6.0_30]

              at org.jboss.osgi.framework.internal.HostBundleState.transitionToActive(HostBundleState.java:294) [jbosgi-framework-core-1.1.8.Final.jar:1.1.8.Final]

              ... 10 more

      Caused by: java.lang.SecurityException: EJB client context selector may not be changed

              at org.jboss.ejb.client.EJBClientContext.setSelector(EJBClientContext.java:181)

              at demo.experimental.osgi.AccessorActivator.<clinit>(AccessorActivator.java:53)

              ... 17 more

       

      When trying to coerce the JBoss deplyoment mechanism to process jboss-ejb-client.xml by adding a stateless EJB (because of the annotations) to the OSGi bundle, deployment will result in the following NPE:

       

      09:11:46,845 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "ejb-accessor-osgi-0.0.1-SNAPSHOT.jar"

      09:11:46,877 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-10) MSC00001: Failed to start service jboss.deployment.unit."ejb-accessor-osgi-0.0.1-SNAPSHOT.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."ejb-accessor-osgi-0.0.1-SNAPSHOT.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "ejb-accessor-osgi-0.0.1-SNAPSHOT.jar"

              at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_30]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_30]

              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_30]

      Caused by: java.lang.NullPointerException

              at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:53) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:63)

              at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55)

              at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              ... 5 more

       

      09:11:46,890 INFO  [org.jboss.as.server] (management-handler-thread - 7) JBAS015870: Deploy of deployment "ejb-accessor-osgi-0.0.1-SNAPSHOT.jar" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"ejb-accessor-osgi-0.0.1-SNAPSHOT.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"ejb-accessor-osgi-0.0.1-SNAPSHOT.jar\".POST_MODULE: Failed to process phase POST_MODULE of deployment \"ejb-accessor-osgi-0.0.1-SNAPSHOT.jar\""}}

      09:11:46,894 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment ejb-accessor-osgi-0.0.1-SNAPSHOT.jar in 4ms

      09:11:46,898 INFO  [org.jboss.as.controller] (management-handler-thread - 7) JBAS014774: Service status report JBAS014777:   Services which failed to start:    

          service jboss.deployment.unit."ejb-accessor-osgi-0.0.1-SNAPSHOT.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."ejb-accessor-osgi-0.0.1-SNAPSHOT.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "ejb-accessor-osgi-0.0.1-SNAPSHOT.jar"

       

      So this (desperate) approach does not work either, then.

       

      As the EJBClientContextSelector cannot be replaced, and the deployment mechanism ignores the jboss-ejb-client.xml, thus resulting in an EJBClientContext not associated with a functional EJBReceiver, how can a remote EJB be called from within an OSGi bundle running in JBoss7 ?

       

      Thanks in advance!

      Steffen

        • 1. Re: jboss-ejb-client.xml in OSGi bundle is ignored
          steffenwollscheid

          Hi all,

           

          just found a little hack, that you can use to call remote EJBs from OSGi bundles running in a JBoss7 instance, if you don't mind to deactivate the org.jboss.as.ejb3 and org.jboss.as.jsr77 subsytems.

           

          1. in your configuration xml, remove or comment the extensions org.jboss.as.ejb3 and org.jboss.as.jsr77, also remove the corresponding subsystems from the configuration xml.

           

          2. To your osgi-subsystem add the following subsystems

           

          capability name="org.jboss.ejb-client" startlevel="1"

          capability name="org.jboss.xnio" startlevel="1"

          capability name="org.jboss.as.naming" startlevel="1"

           

          3. define your ejb client properties file and put it whereever you like, e.g. to META-INF/jboss-ejb-client.properties (how to do this, is described in https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI)

           

          4. in a single place and only once execute the following code - this sets up the EJBReceiver and the JNDI

           

          // this is copied from https://github.com/jbossas/jboss-as/pull/365/files

          org.jboss.as.naming.InitialContext.addUrlContextFactory("ejb", new ejbURLContextFactory());

           

          final Properties clientConfigProps = new Properties();

          try

          {

              clientConfigProps.load(AccessorActivator.class.getClassLoader().getResourceAsStream("META-INF/jboss-ejb-client.properties"));

          }

          catch (IOException e)

          {

              throw new RuntimeException(e);

          }

           

          // Create a EJB client configuration from the properties

          final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(clientConfigProps);

           

          // EJB client context selection is based on selectors. So let's create a

          // ConfigBasedEJBClientContextSelector which uses our EJBClientConfiguration created in previous step

          final ContextSelector<EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration);

           

          // Now let's setup the EJBClientContext to use this selector

          final ContextSelector<EJBClientContext> previousSelector = EJBClientContext.setSelector(ejbClientContextSelector);

           

          These steps basically convert the JBoss to a 'normal' ejb3 remote client. The first line of code registers the ejbURLContextFactory (which resolves the "ejb" scheme) with the naming subsytem of jboss (perhaps there is also a configurative way to do this), which is necessary, because nobody else does it anymore, since we deactivated the ejb3 subsystem in step 1.

           

          Now looking up a remote EJB is done as always:

           

          Properties props = new Properties();

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

          try

          {

              InitialContext ctx = new InitialContext(props);

              return doLookup(ctx);

          }

          catch (NamingException e)

          {

              e.printStackTrace();

              return e.getMessage();

          }

           

          As mentioned before this is quite a hack, and tested only under 'lab conditions', and requires that the 'client server' has no need of JBoss's EJB3 facilities.

           

          I sure hope that there are better ways than this, to lookup remote EJBs from OSGi bundles. If you find one, post it here!

          1 of 1 people found this helpful
          • 2. Re: jboss-ejb-client.xml in OSGi bundle is ignored
            thomas.diesler

            Yes, this is a bug/missing feature. Please monitor https://issues.jboss.org/browse/AS7-5009