Update 04-dec-2004:
This document has been deprecated. Check this basic example on how you can call a bean remotely through HTTP. Tested with JBoss 3.2.6. You can download it here (source).
Follow this steps:

  • modify build.properties with you jboss path and src/httpTest/remote/jndi.properties with your hostname
  • copy jboss-common.jar, jboss-transaction.jar, jnpserver.jar, jboss-j2ee.jar, jboss.jar to the lib directory
  • run ant deploy (will deploy the ear to you jboss)
  • run ant test (requires jboss running)
  • inspect the code, enjoy.

Created: 20-Nov-2003

If you plan to access you application through a firewall or to use some kind of port forwarding then the line

java.naming.provider.url=http://[external machine address]:[port]/invoker/JNDIFactory will not solve all your problems. Let’s assume the following configuration:

[client] <———–> [external machine:portE] <———-> [internal machine:portI].

(Jboss is running on internal machine, portE is forwarded to portI)

The client will indeed try to connect to external machine:portE and will be redirected to internal machine:portI but the references passed to the client will be in the form internal machine:portI/invoker/…. When the client will try to access them an error will occur. The trick is to make Jboss believe it is running on the external machine so it will send the proper references. This can be achieved by editing the server/[configuration]/deploy/http-invoker.sar/META-INF/jboss-service.xml to something similar to the following:
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE server>
<!– $Id: jboss-service.xml,v 1.1.4.6 2003/01/03 21:39:21 starksm Exp $ –>

<server>

<!– The HTTP invoker service configration
–>
<mbean code=”org.jboss.invocation.http.server.HttpInvoker”
name=”jboss:service=invoker,type=http”>
<!– Use a URL of the form http://<hostname>:8080/invoker/EJBInvokerServlet
where <hostname> is InetAddress.getHostname value on which the server
is running.
–>
<!–
<attribute name=”InvokerURLPrefix”>http://</attribute>
<attribute name=”InvokerURLSuffix”>:8080/invoker/EJBInvokerServlet</attribute>
<attribute name=”UseHostName”>true</attribute>
–>
<attribute name=”InvokerURL”>http://[external server]:[portE]/invoker/EJBInvokerServlet</attribute>
</mbean>

<mbean code=”org.jboss.invocation.http.server.HttpInvokerHA”

name=”jboss:service=invoker,type=httpHA”>

<!– Use a URL of the form http://<hostname>:8080/invoker/EJBInvokerHAServlet

where <hostname> is InetAddress.getHostname value on which the server

is running.

–>

<!–

<attribute name=”InvokerURLPrefix”>http://</attribute>

<attribute name=”InvokerURLSuffix”>:8080/invoker/EJBInvokerHAServlet</attribute>

<attribute name=”UseHostName”>true</attribute>

–>

<attribute name=”InvokerURL”>http://[external server]:[portE]/invoker/EJBInvokerHAServlet</attribute>

</mbean>

<!– Expose the Naming service interface via HTTP –>

<mbean code=”org.jboss.invocation.http.server.HttpProxyFactory”

name=”jboss:service=invoker,type=http,target=Naming”>

<!– The Naming service we are proxying –>

<attribute name=”InvokerName”>jboss:service=Naming</attribute>

<!– Compose the invoker URL from the cluster node address –>

<!–

<attribute name=”InvokerURLPrefix”>http://</attribute>

<attribute name=”InvokerURLSuffix”>:8080/invoker/JMXInvokerServlet</attribute>

<attribute name=”UseHostName”>true</attribute>

–>

<attribute name=”InvokerURL”>http://[external server]:[portE]/invoker/JMXInvokerServlet</attribute>

<attribute name=”ExportedInterface”>org.jnp.interfaces.Naming</attribute>

<attribute name=”JndiName”></attribute>

</mbean>

<!– Expose the Naming service interface via clustered HTTP. This maps

to the ReadOnlyJNDIFactory servlet URL

–>

<mbean code=”org.jboss.invocation.http.server.HttpProxyFactory”

name=”jboss:service=invoker,type=http,target=Naming,readonly=true”>

<attribute name=”InvokerName”>jboss:service=Naming</attribute>

<!–

<attribute name=”InvokerURLPrefix”>http://</attribute>

<attribute name=”InvokerURLSuffix”>:8080/invoker/readonly/JMXInvokerServlet</attribute>

<attribute name=”UseHostName”>true</attribute>

–>

<attribute name=”InvokerURL”>http://[external server]:[portE]/invoker/JMXInvokerServlet</attribute>

<attribute name=”ExportedInterface”>org.jnp.interfaces.Naming</attribute>

<attribute name=”JndiName”></attribute>

</mbean>

</server>

*. Tested with jboss 3.0.6