<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    How to use an application client in JBoss-5
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="http://community.jboss.org/people/WolfgangKnauf">Wolfgang Knauf</a> in <i>EJB3</i> - <a href="http://community.jboss.org/docs/DOC-12835">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>This wiki tries to explain the usage of application client container in JBoss. It consists of two parts: first an EJB is injected, the second part shows how to inject a MessageDrivenBean Queue.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h1>Injection of EJBs</h1><p>In this <span>example</span>, we are trying to inject an EJB into an application-client and then invoke a method on that EJB in the client. <em>This has been tested on JBoss-5 GA. The attached example is compiled with Java5.</em> So let's get started:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h6><strong>Step-1:Deploy th</strong><strong>e application</strong></h6><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Deploy the enterprise application which contains the EJB as well as the application-client, onto the JBoss-5 GA server. Here's what the Stateless.ear&#160;&#160; contains:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 10pt;">META-INF/MANIFEST.MF<br/>StatelessEJB.jar<br/>StatelessClient.jar</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><br/>a) The StatelessEJB.jar is the jar which contains the EJB. The EJB is simple and has a couple of methods:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 10pt;">import javax.ejb.Stateless;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 10pt;">@Stateless<br/>public class GeometricModelBean<br/>&#160; implements GeometricModelRemote, GeometricModelLocal<br/>{</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 10pt;"><br/>&#160; public double computeCuboidVolume(double a, double b, double c)<br/>&#160; {<br/>&#160;&#160;&#160;&#160;&#160; // some code here<br/>&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier; font-size: 10pt;">&#160; public double computeCuboidSurface(double a, double b, double c)<br/>&#160; {<br/>&#160;&#160;&#160; // some code here<br/>&#160; }<br/>}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>b) The StatelessClient.jar is the application client which uses the EJB (through injection). Here's the class which has the main function:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">import javax.ejb.EJB;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">public class GeometricModelApplicationClient<br/>{</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160; <strong>@EJB<br/>&#160; public static GeometricModelRemote geometricModel;</strong></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160; public static void main(String[] args)<br/>&#160; {<br/>&#160;&#160;&#160; double dblVolume;<br/>&#160;&#160;&#160; try<br/>&#160;&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160; dblVolume = geometricModel.computeCuboidVolume(10.0D, 5.0D, 7.0D);<br/>&#160;&#160;&#160;&#160;&#160; double dblSurface = geometricModel.computeCuboidSurface(10.0D, 5.0D, 7.0D);</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; System.out.println("Calculated volume: " + dblVolume + ", surface: " + dblSurface);<br/>&#160;&#160;&#160; }<br/>&#160;&#160;&#160; catch (Exception ex)<br/>&#160;&#160;&#160; {<br/>&#160;&#160;&#160;&#160;&#160; ex.printStackTrace();<br/>&#160;&#160;&#160; }<br/>&#160; }<br/>}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>As you can see, the EJB is being injected in the client and later on used to invoke a method. The&#160; StatelessClient.jar should contain a application-client.xml and a jboss-client.xml (optional) to be identified as a application client. Here are the contents of these files:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>StatelessClient.jar /META-INF/application-client.xml</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br/>&lt;application-client id="Application-client_ID" version="5"<br/><span>&#160;&#160;&#160; xmlns="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span>"</span><br/><span>&#160;&#160;&#160; xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"</span><br/><span>&#160;&#160;&#160; xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span> </span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee/application-client_5.xsd" target="_blank">http://java.sun.com/xml/ns/javaee/application-client_5.xsd</a><span>"&gt;</span><br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; &lt;display-name&gt;StatelessClient&lt;/display-name&gt;<br/>&#160;&#160;&#160; <br/>&lt;/application-client&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><br/><em>StatelessClient.jar/META-INF/jboss-client.xml</em>:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br/>&lt;!DOCTYPE jboss-client PUBLIC<br/>&#160;&#160;&#160; "-//JBoss//DTD Application Client 5.0//EN"<br/><span>&#160;&#160;&#160; "</span><a class="jive-link-external-small" href="http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd" target="_blank">http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd</a><span>"&gt;</span><br/>&lt;jboss-client&gt;<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; &lt;jndi-name&gt;StatelessClient&lt;/jndi-name&gt;<br/>&#160;&#160;&#160; <br/>&lt;/jboss-client&gt; </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>And then the StatelessClient.jar/META-INF/MANIFEST.MF should point to the application client class which has the main function.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>StatelessClient.jar/META-INF/MANIFEST.MF</em>:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">Manifest-Version: 1.0<br/>Class-Path: StatelessEJB.jar<br/>Main-Class: de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Note that this ear does not have an application.xml. But if required, you can have one.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When this EAR is successfully deployed on the JBoss-5 GA server, you will see the following log output on the console:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><br/><span style="font-family: courier new,courier;">13:55:57,734 INFO&#160; [JBossASKernel] Created KernelDeployment for: StatelessClient.jar<br/>13:55:57,734 INFO&#160; [JBossASKernel] installing bean: jboss.j2ee:ear=Stateless.ear,jar=StatelessClient.jar,name=StatelessClient,service=EJB3<br/>13:55:57,734 INFO&#160; [JBossASKernel]&#160;&#160; with dependencies:<br/>13:55:57,734 INFO&#160; [JBossASKernel]&#160;&#160; and demands:<br/>13:55:57,734 INFO&#160; [JBossASKernel]&#160;&#160; and supplies:<br/>13:55:57,734 INFO&#160; [JBossASKernel] Added bean(jboss.j2ee:ear=Stateless.ear,jar=StatelessClient.jar,name=StatelessClient,service=EJB3) to KernelDeployment of: StatelessClient.jar<br/>13:56:00,156 INFO&#160; [JBossASKernel] Created KernelDeployment for: StatelessEJB.jar<br/>13:56:00,156 INFO&#160; [JBossASKernel] installing bean: jboss.j2ee:ear=Stateless_BrokenAppClient2.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160; with dependencies:<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160; and demands:<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160;&#160;&#160;&#160; jboss.ejb:service=EJBTimerService<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160; and supplies:<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160;&#160;&#160;&#160; jndi:Stateless/GeometricModelBean/local-de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelLocal<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160;&#160;&#160;&#160; jndi:Stateless/GeometricModelBean/remote-de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160;&#160;&#160;&#160; Class:de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160;&#160;&#160;&#160; jndi:Stateless/GeometricModelBean/local<br/>13:56:00,156 INFO&#160; [JBossASKernel]&#160;&#160;&#160;&#160;&#160; Class:de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelLocal<br/>13:56:00,171 INFO&#160; [JBossASKernel]&#160;&#160;&#160;&#160;&#160; jndi:Stateless/GeometricModelBean/remote<br/>13:56:00,171 INFO&#160; [JBossASKernel] Added bean(jboss.j2ee:ear=Stateless.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3) to KernelDeployment of: StatelessEJB.jar<br/>13:56:00,437 INFO&#160; [ClientENCInjectionContainer] STARTED CLIENT ENC CONTAINER: StatelessClient<br/>13:56:01,171 INFO&#160; [SessionSpecContainer] Starting jboss.j2ee:ear=Stateless_BrokenAppClient2.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3<br/>13:56:01,187 INFO&#160; [EJBContainer] STARTED EJB: de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelBean ejbName: GeometricModelBean<br/>13:56:01,203 WARN&#160; [SessionSpecContainer] Populating JBoss-specific annotation metadata manually until done by deployers: jboss.j2ee:ear=Stateless.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3<br/><br/>....<br/>13:56:01,656 INFO&#160; [ServerImpl] JBoss (Microcontainer) [5.0.0.GA (build: SVNTag=JBoss_5_0_0_GA date=200809171046)] Started in 1m:8s:299ms</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>In your JNDIView you can now see that the application client has been bound to the JNDI:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">java:comp namespace of the component jboss.j2ee:ear=Stateless.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3 :</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160; +- EJBContext (class: javax.ejb.EJBContext)<br/>&#160; +- TransactionSynchronizationRegistry[link -&gt; java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)<br/>&#160; +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)<br/>&#160; +- env (class: org.jnp.interfaces.NamingContext)<br/>&#160; +- ORB[link -&gt; java:/JBossCorbaORB] (class: javax.naming.LinkRef)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">Global JNDI Namespace</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160; +- StatelessClient (class: org.jnp.interfaces.NamingContext)<br/>&#160; |&#160;&#160; +- UserTransaction[link -&gt; UserTransaction] (class: javax.naming.LinkRef)<br/>&#160; |&#160;&#160; +- metaData (class: org.jboss.metadata.client.jboss.JBossClientMetaData)<br/>&#160; |&#160;&#160; +- env (class: org.jnp.interfaces.NamingContext)<br/>&#160; |&#160;&#160; |&#160;&#160; +- geometricModel[link -&gt; Stateless/GeometricModelBean/remote-de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote] (class: javax.naming.LinkRef)<br/>&#160; |&#160;&#160; +- classPathEntries (class: java.util.ArrayList)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h6><strong>Step-2: Use the </strong><strong>appclient-launcher to launch the application client container.</strong></h6><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Now that the EAR containing the bean and the application client has been deployed, the next step is to launch the application client container. Note: Just running the application client class through a java command will not get the injection working. You need the launcher to provide the application server functionalities.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>From the command prompt, 'cd' to %JBOSS_HOME%\client folder. I have JBoss installed in D:\jboss-5.0.0.GA so from my command prompt, i will cd to D:\jboss-5.0.0.GA\client folder:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">D:\jboss-5.0.0.GA\client&gt;set JBOSS_HOME=d:\jboss-5.0.0.GA<br/>D:\jboss-5.0.0.GA\client&gt;set JAVA_HOME=c:\jdk1.6.0_10<br/>D:\jboss-5.0.0.GA\client&gt;set PATH=%JAVA_HOME%\bin;%PATH%</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Now use the following command to launch the application client container:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">D:\jboss-5.0.0.GA\client&gt;%JAVA_HOME%\bin\java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=jnp://localhost:1099 -classpath "%JBOSS_HOME%\client\jbossall-client.jar;%JBOSS_HOME%\client\jboss-metadata.jar;%JBOSS_HOME%\lib\jboss-classloader.jar;%JBOSS_HOME%\lib\jboss-classloading-spi.jar;%JBOSS_HOME%\lib\jboss-classloading-vfs.jar;%JBOSS_HOME%\lib\jboss-classloading.jar;%JBOSS_HOME%\lib\jboss-dependency.jar;%JBOSS_HOME%\lib\jboss-reflect.jar;%JBOSS_HOME%\lib\jboss-kernel.jar;%JBOSS_HOME%\lib\jboss-xml-binding.jar;%JBOSS_HOME%\lib\jboss-xml-binding.jar;%JBOSS_HOME%\lib\jboss-vfs.jar;%JBOSS_HOME%\lib\jboss-reflect.jar;%JBOSS_HOME%\common\lib\jboss-ejb3-core.jar" org.jboss.client.AppClientMain -jbossclient de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient -launchers org.jboss.ejb3.client.ClientLauncher -j2ee.clientName StatelessClient</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><br/>The entire command should be in one single line. The important things to note in this command (other than the classpath stuff) is that:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>a) We are passing the JNDI related properties:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">-Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=jnp://localhost:1099</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The -Djava.naming.provider.url should point to the server's Naming port.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong><em>Where is the "<span style="font-family: courier new,courier;">-Djava.naming.factory.url.pkgs" argument?</span></em></strong></p><p>This argument is required, if the client app performs a JNDI lookup itself, and it's value has to be "<a class="jive-link-anchor-small">org.jboss.naming.client".</a></p><p>But this one is not used by the Injection framework. jaikirans investigations found that the environment property Context.URL_PKG_PREFIXES does not come into picture when using injection because of the way org.jboss.ejb3.client.JNDIDependencyItem is working. It does not look into the java:comp/env namespace but just looks up and adds a dependency on StatelessClient/metaData jndiname. Later on when the actual lookup for java:comp/env namespace is done on the jndi *server*, the properties that are on the server are used.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>b) We are calling the org.jboss.client.AppClientMain which is the application client container's entry point</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>c) We are passing -jbossclient parameter and its corresponding value de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient to org.jboss.client.AppClientMain. This is your application client main class which uses the EJB</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>d) We are also passing the -j2ee.clientName which is the name of your application client to org.jboss.client.AppClientMain. In this case, its StatelessClient.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>e) We are passing the -launchers org.jboss.ejb3.client.ClientLauncher to org.jboss.client.AppClientMain. This one is important. The -launchers accepts a comma separate list of fully qualified implementations of org.jboss.client.AppClientLauncher interface. The org.jboss.ejb3.client.ClientLauncher is one such implementation (provided by JBoss) which is responsible for injecting EJB (and some other things) in the application client.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>f) Classpath: the list of included JARs was found by "try and error" and might change with every JBoss version. The file list of this sample is for <strong>JBoss 5.0 GA</strong>.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>But <strong>JBoss 6.0GA</strong> requires a different file list. To simplify this, I use wildcards to include all JAR files in "%JBOSS_HOME%\client" and "%JBOSS_HOME\lib%". A new requirement in JBoss 6 is to include also "%JBOSS_HOME%\common\lib\jboss-ejb3-vfs-spi.jar".</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here is the relevant snippet of the command:</p><p><span style="font-family: courier new,courier;">set JBOSS_HOME=d:\jboss-6.0.0.Final</span></p><p><span style="font-family: courier new,courier;">...</span></p><p><span style="font-family: courier new,courier;">"%JAVA_HOME%\bin\java" ... -classpath .;"%JBOSS_HOME%\client\*;%JBOSS_HOME%\lib\*;%JBOSS_HOME%\common\lib\jboss-ejb3-vfs-spi.jar;" ...</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h6><strong>Step-3: See th</strong><strong>e output.</strong></h6><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When you run the command mentioned in Step-2, the application client container will invoke the main method of your application client. In our example, the main method uses the injected EJB and invokes a method on the EJB and finally prints the following output on the client side:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">Calculated volume: 350.0, surface: 310.0</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Note, on the server side you might see the EJB related logs (if you have any logging messages).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>That's it!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>P.S: The application attached here is provided by Wolfgang Knauf</strong> <a class="jive-link-external-small" href="http://www.jboss.com/index.html?module=bb&amp;op=viewtopic&amp;t=143595">http://www.jboss.com/index.html?module=bb&amp;op=viewtopic&amp;t=143595</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h5>Why don't i see logs on the application client side?</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>By default, with the command used in Step-2, you will not see the log message. The log messages are really useful when debugging any issue. You have to do 2 things to see logs on the client side:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>1) Add log4j.jar to the client classpath<br/>2) Add a log4j properties or xml file to the classpath or pass -Dlog4j.configuration=[path to log4j config file] JVM option.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>On my setup, i created a log4j.properties file with the following settings:</p><p><br/><span style="font-family: courier new,courier;">log4j.rootLogger=DEBUG, stdout</span></p><p><span style="font-family: courier new,courier;">log4j.appender.stdout=org.apache.log4j.ConsoleAppender<br/>log4j.appender.stdout.layout=org.apache.log4j.PatternLayout<br/>log4j.appender.stdout.layout.ConversionPattern=%d %p [%t][%c] - &lt;%m&gt;%n</span></p><p><br/>And then placed this file under %JBOSS_HOME%\client folder. Finally i changed the java command (in Step-2) to include the log4j.jar and also pass this log4j configuration file path as a JVM option. Here's the updated command:</p><p><br/><span style="font-family: courier new,courier;">D:\jboss-5.0.0.GA\client&gt;%JAVA_HOME%\bin\java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=jnp://localhost:1099 -Dlog4j.configuration=%JBOSS_HOME%\client\log4j.properties -classpath "%JBOSS_HOME%\client\jbossall-client.jar;%JBOSS_HOME%\client\jboss-metadata.jar;%JBOSS_HOME%\client\log4j.jar;%JBOSS_HOME%\lib\jboss-classloader.jar;%JBOSS_HOME%\lib\jboss-classloading-spi.jar;%JBOSS_HOME%\lib\jboss-classloading-vfs.jar;%JBOSS_HOME%\lib\jboss-classloading.jar;%JBOSS_HOME%\lib\jboss-dependency.jar;%JBOSS_HOME%\lib\jboss-reflect.jar;%JBOSS_HOME%\lib\jboss-kernel.jar;%JBOSS_HOME%\lib\jboss-xml-binding.jar;%JBOSS_HOME%\lib\jboss-vfs.jar;</span><span style="font-family: courier new,courier;">%JBOSS_HOME%\lib\jboss-reflect.jar;%JBOSS_HOME%\common\lib\jboss-ejb3-core.jar</span><span style="font-family: courier new,courier;">" org.jboss.client.AppClientMain -jbossclient de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient -launchers org.jboss.ejb3.client.ClientLauncher -j2ee.clientName StatelessClient</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>If Log4j does not show the expected results, add "<code>-Dlog4j.debug=true"</code> to the startup parameters, which will print Log4j debugging output and hopefully point you to the reason why e.g. the config file could not be found.</p><h5></h5><h1>Injection of a Queue</h1><p>(credits for this chapter go to jaikiran, I (Wolfgang) just documented his findings here, see <a class="jive-link-external-small" href="http://www.jboss.org/index.html?module=bb&amp;op=viewtopic&amp;t=149330">http://www.jboss.org/index.html?module=bb&amp;op=viewtopic&amp;t=149330</a> ).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Assume a client that wants to send data to a queue (e.g. a Message Driven Bean).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>You need a javax.jms.QueueConnectionFactory and a javax.jms.Queue, which will be injected by the container. As they are injected, they must be static variables in the class containing the "main" method (annotations will be added later):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160; private static QueueConnectionFactory queueConnectionFactory;</span></p><p><span style="font-family: courier new,courier;">&#160; private static Queue queue;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This is the code to send the message (one more "Hello World" sample ;-) ):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();<br/>&#160;&#160;&#160;&#160;&#160; QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);<br/>&#160;&#160;&#160;&#160;&#160; QueueSender queueSender = queueSession.createSender(queue);</span></p><p><span style="font-family: courier new,courier;"><br/></span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; //Send a text message:<br/>&#160;&#160;&#160;&#160;&#160; TextMessage textMessage = queueSession.createTextMessage();<br/>&#160;&#160;&#160;&#160;&#160; textMessage.setText("Hello World");</span></p><p><span style="font-family: courier new,courier;"><br/></span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; queueSender.send(textMessage);</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>There are two possibilities to inject the Queue and QueueConnectionFactory.</p><p>We assume that our Queue (which points to a MDB) is bound to the global JNDI name "queue/MessageBeanQueue". The QueueConnectionFactory is provided by JBoss (you can find it in the JMXConsole as ObjectName "jboss.messaging.connectionfactory").</p><h5>1) From global JNDI</h5><p>This one is easy: the "mappedName" attribute of the <span style="font-family: courier new,courier;">@Resource</span> annotation points to the global JNDI names:</p><p><span style="font-family: courier new,courier;">&#160; @Resource(mappedName="ConnectionFactory")<br/>&#160; private static QueueConnectionFactory queueConnectionFactory;<br/>&#160; <br/>&#160; @Resource(mappedName="queue/MessageBeanQueue")&#160; <br/>&#160; private static Queue queue;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h5>2) From Environment Naming Context (ENC)</h5><p>The "name" attribute of the <span style="font-family: courier new,courier;">@Resource</span> annotation points to ENC names:</p><p><span style="font-family: courier new,courier;">&#160; @Resource(name="jms/MBConnectionFactory")<br/>&#160; private static QueueConnectionFactory queueConnectionFactory;<br/>&#160; <br/>&#160; @Resource(name="jms/MBQueueRef")<br/>&#160; private static Queue queue;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here you need two config files:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>application-client.xml</strong> looks like this:</p><p><span style="font-family: courier new,courier;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br/>&lt;application-client id="Application-client_ID" version="5"<br/><span>&#160;&#160;&#160; xmlns="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span>"</span><br/><span>&#160;&#160;&#160; xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"</span><br/><span>&#160;&#160;&#160; xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span> </span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee/application-client_5.xsd" target="_blank">http://java.sun.com/xml/ns/javaee/application-client_5.xsd</a><span>"&gt;</span><br/>&#160;&#160;&#160; ...<br/>&#160;&#160; &lt;resource-ref&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;res-ref-name&gt;jms/MBConnectionFactory&lt;/res-ref-name&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;res-type&gt;javax.jms.QueueConnectionFactory&lt;/res-type&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;res-auth&gt;Container&lt;/res-auth&gt;<br/>&#160;&#160; &lt;/resource-ref&gt;<br/>&#160;&#160; <br/>&#160;&#160; &lt;message-destination-ref&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;message-destination-ref-name&gt;jms/MBQueueRef&lt;/message-destination-ref-name&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;message-destination-type&gt;javax.jms.Queue&lt;/message-destination-type&gt;<br/>&#160;&#160; &lt;/message-destination-ref&gt;</span><br/>&#160;&#160; <br/>&lt;/application-client&gt;</p><p>The <span style="font-family: courier new,courier;">QueueConnectionFactory</span> as declared as a <span style="font-family: courier new,courier;">resource-ref</span>, while the Queue is declared as a <span style="font-family: courier new,courier;">message-destination-ref</span> !</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>jboss-client.xml</strong> handles the binding of the ENC entries to JBoss JNDI names:</p><p><span style="font-family: courier new,courier;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br/>&lt;!DOCTYPE jboss-client PUBLIC<br/>&#160; "-//JBoss//DTD Application Client 5.0//EN"<br/><span>&#160; "</span><a class="jive-link-external-small" href="http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd" target="_blank">http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd</a><span>"&gt;</span><br/>&lt;jboss-client&gt;<br/>&#160; &lt;jndi-name&gt;...&lt;/jndi-name&gt;<br/>&#160; &lt;resource-ref&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;res-ref-name&gt;jms/MBConnectionFactory&lt;/res-ref-name&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;jndi-name&gt;ConnectionFactory&lt;/jndi-name&gt;<br/>&#160; &lt;/resource-ref&gt;<br/>&#160; <br/>&#160; &lt;message-destination-ref&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;message-destination-ref-name&gt;jms/MBQueueRef&lt;/message-destination-ref-name&gt;<br/>&#160;&#160;&#160;&#160;&#160; &lt;jndi-name&gt;queue/MessageBeanQueue&lt;/jndi-name&gt;<br/>&#160; &lt;/message-destination-ref&gt;<br/>&lt;/jboss-client&gt;</span></p><p>Same as in application-client.xml: The Queue must be declared as a <span style="font-family: courier new,courier;">message-destination-ref</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>A full sample can be found here: <a class="jive-link-external-small" href="http://www.informatik.fh-wiesbaden.de/~knauf/KomponentenArchitekturen2008/mdb/MessageInjection.ear">http://www.informatik.fh-wiesbaden.de/~knauf/KomponentenArchitekturen2008/mdb/MessageInjection.ear</a> (compiled with Java 1.6, will not run with 1.5)</p><p>It contains an EJB module with a MDB, and an application client module (simple swing client with a JTextField whose content is sent to the server). The queue is declared in the module with a -service.xml file in the EJB module. Simply deploy it to the server. To run the client: extract "MessageClient.jar" from the EAR to some other directory, and start the client using the ClientLauncher (see step 2 above).</p><p>The code is commented in German, but hopefully you will understand it anyway ;-)</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-12835">going to Community</a></p>

        <p style="margin: 0;">Create a new document in EJB3 at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>