The app-client
quickstart demonstrates how to code and package a client app and use the WildFly client container to start the client Main program.
The app-client
quickstart demonstrates how to use the WildFly client container to start the client Main
program and provide Dependency Injections (DI) for client applications in WildFly Application Server. It also shows you how to use Maven to package the application according to the JavaEE specification.
This example consists of the following Maven projects, each with a shared parent:
Sub-project | Description |
---|---|
|
An application that can be called by the |
|
The EAR packaging contains the server and client side. |
|
A simple client application for running in the application-client container to show the injection |
The root pom.xml
file builds each of the subprojects in the appropriate order.
The application this project produces is designed to be run on WildFly Application Server 12 or later.
All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven 3.3.1 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 WILDFLY_HOME
with the actual path to your WildFly installation. The installation path is described in detail here: Use of WILDFLY_HOME and JBOSS_HOME Variables.
If the client and server are run on different hosts, you must add the following users to the WildFly server side application. Be sure to use the names and passwords specified in the table as they are required to run this example.
UserName | Realm | Password | Roles |
---|---|---|---|
admin |
ManagementRealm |
admin-123 |
leave blank for none |
quickuser |
ApplicationRealm |
quick-123 |
leave blank for none |
To add the users, open a terminal and type the following commands:
$ WILDFLY_HOME/bin/add-user.sh -u admin -p admin-123
$ WILDFLY_HOME/bin/add-user.sh -a -u quickuser -p quick-123
Note
|
For Windows, use the WILDFLY_HOME\bin\add-user.bat script.
|
If you prefer, you can use the add-user
utility interactively. For an example of how to use the add-user utility, see the instructions located here: Add an Application User.
-
Open a terminal and navigate to the root of the WildFly directory.
-
Use the following command to start the server:
$ WILDFLY_HOME/bin/standalone.sh
NoteFor Windows, use the WILDFLY_HOME\bin\standalone.bat
script.
-
Make sure you have started the WildFly server as described above.
-
Open a terminal and navigate to the root directory of this quickstart.
-
Type this command to build the artifacts:
$ mvn clean install wildfly:deploy
This example shows how to invoke an EJB from a remote standalone application on the same machine. Both the client and server are on the same machine, so the defaults are sufficient and no authentication is necessary.
-
Be sure the quickstart deployed successfully as described above.
-
Navigate to the root directory of this quickstart and type the following command to run the application. Be sure to replace
WILDFLY_HOME
with the path to your WildFly installation.$ WILDFLY_HOME/bin/appclient.sh ear/target/app-client.ear#simpleClient.jar Hello from command line
NoteFor Windows, use the WILDFLY_HOME\bin\appclient.bat
script. -
Review the result. The client outputs the following information, which is provided by the server application:
[org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-51) Main started with arguments [org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-51) [Hello, from, command, line] [org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-##) Hello from StatelessSessionBean@myhost
-
Review the server log files to see the bean invocations on the server.
ClientContext is here = {Client =dev84, jboss.source-address=localhost/127.0.0.1:45315}
This example shows how to invoke an EJB from a remote standalone Java EE application on a different machine. In this case, the client needs to define a properties file to define properties to connect and authenticate to the server. The properties file is passed on the command line using the --ejb-client-properties
argument.
-
Install WildFly on this machine.
-
Add the application users to the WildFly server on this machine as described above.
-
Start the WildFly server with the following command. Be sure to replace
MACHINE_1_IP_ADDRESS
with the IP address of this machine. These arguments make the server accessible to the network.$ WILDFLY_HOME/bin/standalone.sh -b MACHINE_1_IP_ADDRESS -bmanagement MACHINE_1_IP_ADDRESS
NoteFor Windows, use the WILDFLY_HOME\bin\standalone.bat
script.
-
Install WildFly on this server. There is no need to add the application users to this server.
-
Download the
app-client
quickstart to this machine. -
Create a
jboss-ejb-client.properties
file. This file can be located anywhere in the file system, but for ease of demonstration, we create it in the root directory of this quickstart. Add the following content, replacingMACHINE_1_IP_ADDRESS
with the IP address ofMachine_1
.remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false remote.connections=default remote.connection.default.host=MACHINE_1_IP_ADDRESS remote.connection.default.port=8080 remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false remote.connection.default.username=quickuser remote.connection.default.password=quick-123
-
Open a terminal and navigate to the root directory of the quickstart.
-
Deploy the
app-client
quickstart to the remote machine using the following command:$ mvn clean install wildfly:deploy -Dwildfly.hostname=MACHINE_1_IP_ADDRESS [-Dwildfly.port=9099] -Dwildfly.username=admin -Dwildfly.password=admin-123
-
Be sure that the quickstart deployed successfully and the server is running on
Machine_1
as described above. -
Type this command to run the
app-client
application:$ WILDFLY_HOME/bin/appclient.sh --ejb-client-properties=ejb-client.properties ear/target/app-client.ear#simpleClient.jar Hello from command
NoteFor Windows, use the WILDFLY_HOME\bin\appclient.bat
script. -
Review the result. The client outputs the following information, which was provided by the application:
[org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-51) Main started with arguments [org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-51) [Hello, from, command, line] [org.jboss.as.quickstarts.appclient.acc.client.Main] (Thread-##) Hello from StatelessSessionBean@theOtherHOST
-
Review the server log files on the remote machine to see the bean invocations on the server.
ClientContext is here = {Client =dev84, jboss.source-address=localhost/127.0.0.1:45315}
Follow these instructions if you are testing the quickstart on the same machine.
-
Make sure you have started the WildFly server on the machine where the quickstart is deployed as described above.
-
Open a terminal on that server and navigate to the root directory of this quickstart.
-
When you are finished testing, type this command to undeploy the archive from the local machine.
$ mvn wildfly:undeploy
Follow these instructions if you are testing the quickstart on a different machine.
-
Make sure you have started the WildFly server on the remote server machine,
Machine_1
, where the quickstart is deployed as described above. -
Open a terminal on the local client machine,
Machine_2
, and navigate to the root directory of this quickstart. -
When you are finished testing, type this command to undeploy the archive from the remote server machine,
Machine_1
.$ mvn wildfly:undeploy -Dwildfly.hostname=MACHINE_1_IP_ADDRESS [-Dwildfly.port=9099] -Dwildfly.username=admin -Dwildfly.password=admin-123