The ejb-remote quickstart uses EJB and JNDI to demonstrate how to access an EJB, deployed to JBoss EAP, from a remote Java client application.
The ejb-remote quickstart shows how to access an EJB from a remote Java client application. It demonstrates the use of EJB and JNDI in Red Hat JBoss Enterprise Application Platform.
There are two components to this example:
-
A server side component:
The server component is comprised of a stateful EJB and a stateless EJB. It provides both an EJB JAR that is deployed to the server and a JAR file containing the remote business interfaces required by the remote client application.
-
A remote client application that accesses the server component.
The remote client application depends on the remote business interfaces from the server component. This application looks up the stateless and stateful beans via JNDI and invokes a number of methods on them.
The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 8.1 or later.
All you need to build this project is Java SE 17.0 or later, and Maven 3.6.0 or later. See Configure Maven to Build and Deploy the Quickstarts to make sure you are configured correctly for testing the quickstarts.
In the following instructions, replace EAP_HOME with the actual path to your JBoss EAP installation. The installation path is described in detail here: Use of EAP_HOME and JBOSS_HOME Variables.
When you see the replaceable variable QUICKSTART_HOME, replace it with the path to the root directory of all of the quickstarts.
This quickstart uses secured application interfaces and requires that you create the following application user to access the running application.
| UserName | Realm | Password | Roles |
|---|---|---|---|
quickstartUser |
ApplicationRealm |
quickstartPwd1! |
To add the application user, open a terminal and type the following command:
$ EAP_HOME/bin/add-user.sh -a -u 'quickstartUser' -p 'quickstartPwd1!' |
Note
|
For Windows, use the EAP_HOME\bin\add-user.bat script.
|
-
Open a terminal and navigate to the root of the JBoss EAP directory.
-
Start the JBoss EAP server with the default profile by typing the following command.
$ EAP_HOME/bin/standalone.shNoteFor Windows, use the EAP_HOME\bin\standalone.batscript.
-
Make sure JBoss EAP server is started.
-
Open a terminal and navigate to the root directory of this quickstart.
-
Type the following command to build the quickstart.
$ mvn clean package -
Type the following command to deploy the quickstart.
$ mvn wildfly:deploy
This deploys the ejb-remote/target/ejb-remote.war to the running instance of the server.
You should see a message in the server log indicating that the archive deployed successfully.
This quickstart includes integration tests, which are located under the src/test/ directory. The integration tests verify that the quickstart runs correctly when deployed on the server.
Follow these steps to run the integration tests.
-
Make sure JBoss EAP server is started.
-
Make sure the quickstart is deployed.
-
Type the following command to run the
verifygoal with theintegration-testingprofile activated.$ mvn verify -Pintegration-testing
When the client application is run by the EJBRemoteIT tests, it performs the following steps:
-
Obtains a stateless session bean instance.
-
Sends method invocations to the stateless bean to add two numbers, and then displays the result.
-
Sends a second invocation to the stateless bean subtract two numbers, and then displays the result.
-
Obtains a stateful session bean instance.
-
Sends several method invocations to the stateful bean to increment a field in the bean, displaying the result each time.
-
Sends several method invocations to the stateful bean to decrement a field in the bean, displaying the result each time.
The following output is displayed in the terminal window:
Obtained a remote stateless calculator for invocation
Adding 204 and 340 via the remote stateless calculator deployed on the server
Remote calculator returned sum = 544
Subtracting 2332 from 3434 via the remote stateless calculator deployed on the server
Remote calculator returned difference = 1102
Obtained a remote stateful counter for invocation
Counter will now be incremented 5 times
Incrementing counter
Count after increment is 1
Incrementing counter
Count after increment is 2
Incrementing counter
Count after increment is 3
Incrementing counter
Count after increment is 4
Incrementing counter
Count after increment is 5
Counter will now be decremented 5 times
Decrementing counter
Count after decrement is 4
Decrementing counter
Count after decrement is 3
Decrementing counter
Count after decrement is 2
Decrementing counter
Count after decrement is 1
Decrementing counter
Count after decrement is 0Logging statements have been removed from this output here to make it clearer.
Instead of using a standard JBoss EAP server distribution, you can alternatively provision a JBoss EAP server to deploy and run the quickstart. The functionality is provided by the WildFly Maven Plugin, and you may find its configuration in the quickstart pom.xml:
<profile>
<id>provisioned-server</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jboss.eap.plugins</groupId>
<artifactId>eap-maven-plugin</artifactId>
<configuration>
...
<feature-packs>
<feature-pack>
<location>org.jboss.eap:wildfly-ee-galleon-pack</location>
</feature-pack>
...
</feature-packs>
<layers>...</layers>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
</profile>|
Note
|
When built, the provisioned JBoss EAP server can be found in the |
Follow these steps to run the quickstart using the provisioned server.
-
Make sure the server is provisioned.
$ mvn clean package -
Add the quickstart user:
$ target/server/bin/add-user.sh -a -u 'quickstartUser' -p 'quickstartPwd1!' -
Start the JBoss EAP provisioned server, using the WildFly Maven Plugin
startgoal.$ mvn wildfly:start -
Type the following command to run the integration tests.
$ mvn verify -Pintegration-testing -
Shut down the JBoss EAP provisioned server.
$ mvn wildfly:shutdown