Kabir Khan [
http://community.jboss.org/people/kabirkhan] created the document:
"Remote EJB lookup and invocation in JBoss AS 7.0.0"
To view the document, visit:
http://community.jboss.org/docs/DOC-16994
--------------------------------------------------------------
Since JBoss AS 7.0.0 targets the Java EE6 Web Profile, no support is available for remote
connectivity beyond http (and the management functionality). That means that out of the
box you can't do things like look up things in JNDI and invoke upon them from outside
the server. This will be added later this year in JBoss AS 7.1.0, which will support the
full Java EE6 stack.
In the meantime, if you want to invoke upon EJBs remotely, I have created a hack which
lives here:
https://github.com/kabir/as7-remote https://github.com/kabir/as7-remote. Use
JDK 6 and maven 3+ to build it.
It is still a bit rough around the edges since I don't want to spend too much time on
it until someone says if they are interested in this or not. Ideally if it is useful to
someone, they can get involved in this. *DISCLAIMER:* This is a temporary stop-gap until
we support proper remote invocations :-)
Instead of doing JNDI lookups on the client, I am forwarding lookup requests to an MBean
that is deployed as part of an ear. So instead of
InitialContext ctx = new InitialContext();
TestStateless bean = ctx.lookup("java:global/test/test-ejb/TestStatelessBean");
You need to do
Client client = ClientFactory.INSTANCE.getOrCreateClient(new
ObjectName("jboss:name=test,type=remote"), "localhost", 1090); //This
only needs doing once to initialize the client
TestStateless bean = client.lookup(TestStateless.class,
"java:global/test/test-ejb/TestStatelessBean");
https://github.com/kabir/as7-remote/blob/master/src/test/java/org/jboss/a...
https://github.com/kabir/as7-remote/blob/master/src/test/java/org/jboss/a...
deploys an ear containing the sar and an ejb jar.
The sar's META-INF/jboss-service.xml lets you explicitly declare the jndi names of
EJBs that should be exposed via this mechanism:
<server xmlns="urn:jboss:service:7.0"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
<mbean name="jboss:name=test,type=remote"
code="org.jboss.as.remote.jmx.mbean.RemoteEjb">
<!-- A comma separated list of jndi names of stateless session beans -->
<attribute
name="statelessBeanNames">java:global/test/test-ejb/TestStatelessBean</attribute>
<!-- A comma separated list of jndi names of stateful session beans -->
<attribute
name="statefulBeanNames">java:global/test/test-ejb/TestStatefulBean</attribute>
</mbean>
</server>
The EJBs are then looked up on the server by the MBean which then returns a proxy allowing
the remote client to invoke upon the EJBs by invoking via the MBean again. EJBs not
declared are not accessible via this mechanism.
It works fine for simple cases but has the following limitations. Most of these are very
simple to fix if there is enough interest:
* If an EJB method were to return a reference interface to another EJB that will not work
at the moment.
* Only EJBs exposing interfaces are supported, in other words the no-interface views are
not handled.
* For stateful session beans you need to put the @Remove annotation on the interface
method as well as the bean class method.
* Asynchronous invocations are not handled
* I think the MBean needs to be deployed as part of the EAR containing the EJBs. Making it
possible to load things from other deployments should be simple if someone wants that.
* No attempt is made to propagate security and transactional context from the client to
the server
* Probably a load of other stuff I haven't thought of :-)
I obviously have all the AS 7 stuff in my local maven repository so if someone is having
problems building it due to missing maven artifacts please let me know and I'll fix.
Also, the test included relies on a AS 7 CR 1 instance being up and running.
--------------------------------------------------------------
Comment by going to Community
[
http://community.jboss.org/docs/DOC-16994]
Create a new document in JBoss AS7 Development at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=102&am...]