Quickstarts

jax-rs-client: External JAX-RS Client

What is it?

This example demonstrates an external JAX-RS RestEasy client which interacts with a JAX-RS Web service that uses CDI 1.0 and JAX-RS in JBoss Enterprise Application Platform 6 or JBoss AS 7.

This client "calls" the HelloWorld JAX-RS Web Service that was created in the helloworld-rs quickstart. See the Prerequisite section below for details on how to build and deploy the helloworld-rs quickstart.

System requirements

All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.

The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7.

Configure Maven

If you have not yet done so, you must Configure Maven before testing the quickstarts.

Prerequisites

IMPORTANT: This quickstart depends on the deployment of the 'helloworld-rs' quickstart for its test. Before running this quickstart, see the helloworld-rs README file for details on how to deploy it.

You can verify the deployment of the helloworld-rs quickstart by accessing the following content:

Run the Arquillian Tests

This quickstart provides Arquillian tests.

NOTE: The following commands assume you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See Run the Arquillian Tests for complete instructions and additional options.

  1. Make sure you have started the JBoss Server as described above.
  2. Make sure the helloworld-rs quickstart has been deployed on the server as noted in the Prerequisites section above.
  3. Open a command line and navigate to the root directory of this quickstart.
  4. Type the following command to run the test goal with the following profile activated:

     mvn clean test 
    

Investigate the Console Output

This command will compile the example and execute a test to make two separate requests to the Web Service. Towards the end of the Maven build output, you should see the following if the execution is successful:

=============================================== URL: http://localhost:8080/jboss-as-helloworld-rs/rest/xml MediaType: application/xml

Response from Server

Hello World!

===============================================

URL: http://localhost:8080/jboss-as-helloworld-rs/rest/json MediaType: application/json

Response from Server

{"result":"Hello World!"}

===============================================

OpenShift

To make this quickstart more interesting, deploy the RESTful service to OpenShift. The following instructions will guide you as to the modifications that must be made to successfully execute the jax-rs-client against a service deployed to OpenShift.

Build and Deploy the Quickstart - to OpenShift

IMPORTANT: This quickstart depends on the deployment of the helloworld-rs quickstart to OpenShift for its test. Follow the instructions Build and Deploy the Quickstart - to OpenShift in the helloworld-rs README to deploy that application to OpenShift. Do NOT yet follow the step "Destroy the OpenShift Application".

As it says in the helloworld-rs instructions, you can verify the deployment of the helloworld-rs quickstart by accessing the following content. Be sure to replace the quickstart in the URL with your domain name.

Modify the jax-rs-client quickstart pom.xml

Now that you have deployed the application, it is time to make changes to the jax-rs-client quickstart Arquillian tests.

  1. Open a shell command prompt and navigate to the QUICKSTART_HOME/jax-rs-client/ directory.
  2. Make a backup copy of the pom.xml file.
  3. Open the pom.xml file in an editor and modify the xmlUrl and jsonUrl property values as follows. Be sure to replace the quickstart in the URL with your domain name.

     <property>
         <name>xmlUrl</name>
         <value>http://helloworldrs-quickstart.rhcloud.com/rest/xml</value>
     </property>
     <property>
         <name>jsonUrl</name>
         <value>http://helloworldrs-quickstart.rhcloud.com/rest/json</value>
     </property>
    

Run the Maven test

Type the following command to run the jax-rs-client:

    mvn test

This command will compile the example and execute a test to make two separate requests to the Web Service. Towards the end of the Maven build output, you should see the following if the execution is successful:

=============================================== URL: http://helloworldrs-quickstart.rhcloud.com/rest/xml MediaType: application/xml

Response from Server

Hello World!

===============================================

URL: http://helloworldrs-quickstart.rhcloud.com/rest/json MediaType: application/json

Response from Server

{"result":"Hello World!"}

===============================================

When you are finished testing, restore the pom.xml file to the previous version if you want to test locally.

Destroy the OpenShift Application

When you are finished with the application you can destroy it as follows:

    rhc app destroy -a helloworldrs

Note: There is a limit to the number of applications you can deploy concurrently to OpenShift. If the rhc app create command returns an error indicating you have reached that limit, you must destroy an existing application before you continue.

  • To view the list of your OpenShift applications, type: rhc domain show
  • To destroy an existing application, type the following, substituting the application name you want to destroy: rhc app destroy -a APPLICATION_NAME_TO_DESTROY

Share the Knowledge

Find this guide useful?

Feedback

Find a bug in the guide? Something missing? You can fix it by forking the repository, making the correction and sending a pull request. If you're just plain stuck, feel free to ask a question in the user discussion forum.

Recent Changelog

  • Feb 12, 2013: Add quickstart source repository of record to the readme files Sande Gilda
  • Sep 11, 2012: Add target product (https://issues.jboss.org/browse/jdf-108) Sande Gilda
  • Jul 30, 2012: Fix openshift instructions, issue #291, developer and doc links Sande Gilda
  • Jul 19, 2012: Fix issue #301 and issue #302 : remove openshift warning, make template readme instructions clearer Sande Gilda
  • May 18, 2012: Move metadata to quickstarts Pete Muir
  • May 03, 2012: Clarify that the domain portion of the openshift url will be your own domain Sande Gilda
  • May 02, 2012: Switch to new version of rhc commands Pete Muir
  • May 03, 2012: Add caveat that only the as7 quickstarts currently run on openshift Sande Gilda
  • May 03, 2012: Fix readme problems found in qe testing of eap 6 quickstarts Sande Gilda
  • Apr 11, 2012: Made modifications to include instructions on how to run this on the helloworld-rs application deployed to openshift Blaine Mincey
  • Apr 11, 2012: Remove odd trailing slashes Pete Muir
  • Apr 11, 2012: Fix test instructions Pete Muir
  • Apr 10, 2012: Solve issue #194 :-) auto transform links from readme.md -> readme.html Pete Muir
  • Apr 05, 2012: Missed adding the arquillian instructions, fixed indentations, modified jta-crash-rec and jts-distributed-crash-rec, add missing authors Sande Gilda
  • Mar 26, 2012: Attempt to standardize readme.md files Sande Gilda

See full history »