-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JDF-769 - Create a JAX-RS Client API Quickstart
- Loading branch information
Showing
9 changed files
with
874 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
jaxrs-client: JAX-RS Client API example | ||
================================================================ | ||
Author: Rafael Benevides | ||
Level: Beginner | ||
Technologies: JAX-RS | ||
Summary:The `jaxrs-client` quickstart demonstrates JAX-RS Client API, which interacts with a JAX-RS Web service that runs on WildFly. | ||
Target Product: Sandbox | ||
Source: <https://github.com/jboss-developer/jboss-sandbox-quickstarts> | ||
|
||
|
||
What is it? | ||
----------- | ||
|
||
The `jaxrs-client` quickstart demonstrates the JAX-RS Client API which interacts with a JAX-RS Web service. | ||
|
||
This client "calls" many POST, GET, DELETE operations using different ways: synchronized, asynchronous, delayed and filtered invocations. | ||
|
||
|
||
System requirements | ||
------------------- | ||
|
||
|
||
The application this project produces is designed to be run on WildFly . | ||
|
||
All you need to build this project is Java 7.0 (Java SDK 1.7) or later, Maven 3.0 or later. | ||
|
||
|
||
Configure Maven | ||
--------------- | ||
|
||
If you have not yet done so, you must [Configure Maven](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN.md#configure-maven-to-build-and-deploy-the-quickstarts) before testing the quickstarts. | ||
|
||
|
||
Start the WildFly Server | ||
------------------------- | ||
|
||
1. Open a command line and navigate to the root of the WildFly directory. | ||
2. The following shows the command line to start the server with the default profile: | ||
|
||
For Linux: WILDFLY_HOME/bin/standalone.sh | ||
For Windows: WILDFLY_HOME\bin\standalone.bat | ||
|
||
|
||
Build and Deploy the Quickstart | ||
------------------------- | ||
|
||
1. Make sure you have started the WildFly server as described above. | ||
2. Open a command line and navigate to the root directory of this quickstart. | ||
3. Type this command to build and deploy the archive: | ||
|
||
mvn package wildfly:deploy | ||
4. This will deploy `target/jboss-jaxrs-client.war` to the running instance of the server. | ||
|
||
|
||
|
||
Run the Tests | ||
------------------------- | ||
|
||
|
||
This quickstart provides tests that shows the REST Client API features. By default, these tests are configured to be skipped as the tests requires that the application to be deployed first. | ||
|
||
|
||
1. Make sure you have started the WildFly server as described above. | ||
2. Open a command prompt and navigate to the root directory of this quickstart. | ||
3. Type the following command to run the test goal with the following profile activated: | ||
|
||
mvn test -Prest-client | ||
|
||
Run tests from JBDS | ||
----------------------- | ||
|
||
To be able to run the tests from JBDS, first set the active Maven profile in project properties to be either 'rest-client'. | ||
|
||
To run the tests, right click on the project or individual classes and select Run As --> JUnit Test in the context menu. | ||
|
||
|
||
Investigate the Console Output | ||
---------------------------- | ||
|
||
|
||
------------------------------------------------------- | ||
T E S T S | ||
------------------------------------------------------- | ||
Running org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest | ||
Dec 29, 2014 3:34:44 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest requestResponseFiltersTest | ||
INFO: ### Testing Request and Response Filters ### | ||
Dec 29, 2014 3:34:44 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest requestResponseFiltersTest | ||
INFO: dropping all contacts | ||
Dec 29, 2014 3:34:45 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest requestResponseFiltersTest | ||
INFO: Invoking create new contact using a ClientRequestFilter | ||
Dec 29, 2014 3:34:45 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest requestResponseFiltersTest | ||
INFO: Invoking list all contacts using a ClientResponseFilter | ||
Dec 29, 2014 3:34:45 PM org.jboss.as.quickstarts.jaxrsclient.test.LogResponseFilter filter | ||
INFO: Date: Mon Dec 29 15:34:45 BRST 2014- Status: 200 | ||
Dec 29, 2014 3:34:45 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest delayedInvocationTest | ||
INFO: ### Testing Delayed invocaton ### | ||
Dec 29, 2014 3:34:45 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest delayedInvocationTest | ||
INFO: dropping all contacts | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest delayedInvocationTest | ||
INFO: Creating a new contact invocation | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest delayedInvocationTest | ||
INFO: Creating list all contacts invocation | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest delayedInvocationTest | ||
INFO: invoking the new contact | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest delayedInvocationTest | ||
INFO: invoking list all contacts ASYNC | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest asyncCrudTest | ||
INFO: ### CRUD tests ASYNC ### | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest asyncCrudTest | ||
INFO: dropping all contacts ASYNC | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest asyncCrudTest | ||
INFO: creating a new contact ASYNC | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest asyncCrudTest | ||
INFO: delete a contact by id ASYNC | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest asyncCrudTest | ||
INFO: fetching all contacts ASYNC | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest invocationCallBackTest | ||
INFO: ### Testing invocation callback ### | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest invocationCallBackTest | ||
INFO: dropping all contacts | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest invocationCallBackTest | ||
INFO: Creating a InvocationCallback | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest invocationCallBackTest | ||
INFO: Invoking a service using the InvocationCallback | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest cruedTest | ||
INFO: ### CRUD tests ### | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest cruedTest | ||
INFO: dropping all contacts | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest cruedTest | ||
INFO: creating a new contact | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest cruedTest | ||
INFO: fetching a contact by id | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest cruedTest | ||
INFO: fetching all contacts | ||
Dec 29, 2014 3:34:46 PM org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest cruedTest | ||
INFO: delete a contact by id | ||
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.51 sec - in org.jboss.as.quickstarts.jaxrsclient.test.ContactsRestClientTest | ||
Results : | ||
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 | ||
|
||
|
||
Undeploy the Archive | ||
-------------------- | ||
|
||
1. Make sure you have started the WildFly server as described above. | ||
2. Open a command prompt and navigate to the root directory of this quickstart. | ||
3. When you are finished testing, type this command to undeploy the archive: | ||
|
||
mvn wildfly:undeploy | ||
|
||
|
||
Run the Quickstart in JBoss Developer Studio or Eclipse | ||
------------------------------------- | ||
|
||
|
||
You can also start the server and deploy the quickstarts or run the Arquillian tests from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/USE_JBDS.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts) | ||
|
||
Debug the Application | ||
------------------------------------ | ||
|
||
If you want to debug the source code of any library in the project, run the following command to pull the source into your local repository. The IDE should then detect it. | ||
|
||
mvn dependency:sources | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
JBoss, Home of Professional Open Source | ||
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual | ||
contributors by the @authors tag. See the copyright.txt in the | ||
distribution for a full listing of individual contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.jboss.quickstarts.sandbox</groupId> | ||
<artifactId>jboss-jaxrs-client</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<name> JBoss Sandbox Quickstart: jaxrs-client</name> | ||
<description>JAX-RS Client API example</description> | ||
|
||
<url>http://wildfly.org</url> | ||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<distribution>repo</distribution> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url> | ||
</license> | ||
</licenses> | ||
|
||
<properties> | ||
<!-- Explicitly declaring the source encoding eliminates the following | ||
message: --> | ||
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered | ||
resources, i.e. build is platform dependent! --> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<!-- JBoss dependency versions --> | ||
<version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin> | ||
|
||
<!-- Define the version of the JBoss BOMs we want to import to specify | ||
tested stacks. --> | ||
<version.jboss.bom>8.0.0.Final</version.jboss.bom> | ||
<version.resteasy>3.0.10.Final</version.resteasy> | ||
|
||
<!-- other plugin versions --> | ||
<version.surefire.plugin>2.16</version.surefire.plugin> | ||
<version.war.plugin>2.5</version.war.plugin> | ||
|
||
<!-- maven-compiler-plugin --> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
</properties> | ||
|
||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill | ||
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) | ||
of artifacts. We use this here so that we always get the correct versions | ||
of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can | ||
read this as the JBoss stack of the Java EE 7 APIs, with some extras tools | ||
for your project, such as Arquillian for testing) and the resteasy-bom | ||
--> | ||
<dependency> | ||
<groupId>org.wildfly.bom</groupId> | ||
<artifactId>jboss-javaee-7.0-with-tools</artifactId> | ||
<version>${version.jboss.bom}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-bom</artifactId> | ||
<version>${version.resteasy}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
|
||
<!-- First declare the APIs we depend on and need for compilation. All | ||
of them are provided by JBoss WildFly --> | ||
|
||
<!-- Import the CDI API, we use provided scope as the API is included in | ||
JBoss WildFly --> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Import the Common Annotations API (JSR-250), we use provided scope | ||
as the API is included in JBoss WildFly --> | ||
<dependency> | ||
<groupId>org.jboss.spec.javax.annotation</groupId> | ||
<artifactId>jboss-annotations-api_1.2_spec</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Import the JAX-RS API, we use provided scope as the API is included | ||
in JBoss WildFly --> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>jaxrs-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Import the RestEasy Client and Jackson provider, we use test scope as we need that for test purposes --> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-client</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-jackson-provider</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Now we declare any tools needed --> | ||
|
||
|
||
<!-- Needed for running tests (you may also use TestNG) --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<!-- Maven will append the version to the finalName (which is the name | ||
given to the generated war, and hence the context root) --> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>${version.war.plugin}</version> | ||
<configuration> | ||
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! --> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
<!-- The WildFly plugin deploys your war to a local WildFly container --> | ||
<!-- To use, run: mvn package wildfly:deploy --> | ||
<plugin> | ||
<groupId>org.wildfly.plugins</groupId> | ||
<artifactId>wildfly-maven-plugin</artifactId> | ||
<version>${version.wildfly.maven.plugin}</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<!-- The default profile skips all tests, though you can tune it to run | ||
just unit tests based on a custom pattern --> | ||
<!-- Seperate profiles are provided for running all tests, including Arquillian | ||
tests that execute in the specified container --> | ||
<id>default</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${version.surefire.plugin}</version> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<profile> | ||
|
||
<!-- An optional testing profile that executes JAX-RS Client API tests --> | ||
<!-- Run with: mvn clean test -Prest-client --> | ||
<id>rest-client</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${version.surefire.plugin}</version> | ||
<configuration> | ||
<skip>false</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
</profiles> | ||
</project> |
Oops, something went wrong.