-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #472 from gastaldi/FORGE-1833
FORGE-1833: Added Resteasy's JAX-RS 2.0 Client implementation
- Loading branch information
Showing
10 changed files
with
340 additions
and
2 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
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
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
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,63 @@ | ||
== rest-client | ||
:idprefix: id_ | ||
|
||
|
||
This addon *exports services* for use in other addons. The rest-client addon allows to . | ||
|
||
=== Depends on | ||
|
||
[options="header"] | ||
|=== | ||
|Addon |Exported |Optional | ||
|
||
|javaee-spi | ||
|yes | ||
|no | ||
|
||
|org.jboss.forge.furnace.container:simple | ||
|no | ||
|no | ||
|
||
|=== | ||
== Setup | ||
|
||
This Addon requires the following installation steps. | ||
|
||
=== Add configuration to pom.xml | ||
|
||
To use this addon, you must add it as a dependency in the *pom.xml* of your `forge-addon` classified artifact: | ||
|
||
[source,xml] | ||
---- | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>rest-client</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<version>${version}</version> | ||
</dependency> | ||
---- | ||
== Features | ||
|
||
ClientFactory service for JAX-RS 2.0 Client creation:: | ||
The ClientFactory provides a single API to create a javax.ws.rs.client.Client or a javax.ws.rs.client.ClientBuilder object. | ||
+ | ||
[source,java] | ||
---- | ||
@Inject | ||
private ClientFactory factory; | ||
... | ||
Client client = factory.createClient(); | ||
String response = client.target("http://www.iheartquotes.com/api/v1/random").request(MediaType.TEXT_PLAIN_TYPE).get(String.class); | ||
---- | ||
+ | ||
[TIP] | ||
==== | ||
If your addon uses a container that does not support "@Inject" annotations, services such as the `ClientFactory` may also be | ||
accessed via the `AddonRegistry`: | ||
---- | ||
AddonRegistry registry = ... | ||
Imported<ClientFactory> imported = registry.getServices(ClientFactory.class); | ||
ClientFactory factory = imported.get(); | ||
---- | ||
==== |
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,88 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>rest-client-parent</artifactId> | ||
<version>2.6.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>rest-client</artifactId> | ||
<name>Forge - Core Addon</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>javaee-spi</artifactId> | ||
<classifier>forge-addon</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>configuration</artifactId> | ||
<classifier>forge-addon</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-client</artifactId> | ||
<version>3.0.8.Final</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>javax.activation</groupId> | ||
<artifactId>activation</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.jboss.spec.javax.annotation</groupId> | ||
<artifactId>jboss-annotations-api_1.1_spec</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>jaxrs-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.container</groupId> | ||
<artifactId>simple</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jboss.forge.furnace</groupId> | ||
<artifactId>furnace-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>generate-dot</id> | ||
<phase>prepare-package</phase> | ||
<goals> | ||
<goal>generate-dot</goal> | ||
</goals> | ||
<configuration> | ||
<attach>true</attach> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>create-forge-addon</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classifier>forge-addon</classifier> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
rest-client/addon/src/main/java/org/jboss/forge/addon/rest/ClientFactory.java
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,36 @@ | ||
/** | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.rest; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
|
||
/** | ||
* Service to create REST clients | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class ClientFactory | ||
{ | ||
/** | ||
* Creates a {@link ClientBuilder} | ||
*/ | ||
public ClientBuilder createClientBuilder() | ||
{ | ||
return ClientBuilder.newBuilder(); | ||
} | ||
|
||
/** | ||
* Creates a {@link Client} | ||
*/ | ||
public Client createClient() | ||
{ | ||
return createClientBuilder().build(); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...don/src/main/resources/META-INF/services/org.jboss.forge.furnace.container.simple.Service
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 @@ | ||
org.jboss.forge.addon.rest.ClientFactory |
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,21 @@ | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>forge-parent</artifactId> | ||
<version>2.6.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>rest-client-parent</artifactId> | ||
|
||
<packaging>pom</packaging> | ||
<name>Forge - Rest Client Addon Parent</name> | ||
|
||
<modules> | ||
<module>addon</module> | ||
<module>tests</module> | ||
</modules> | ||
</project> |
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,35 @@ | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>rest-client-parent</artifactId> | ||
<version>2.6.1-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>rest-client-tests</artifactId> | ||
<name>Forge - Rest Client Addon Integration Tests</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.forge.addon</groupId> | ||
<artifactId>rest-client</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.container</groupId> | ||
<artifactId>cdi</artifactId> | ||
<classifier>forge-addon</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.test</groupId> | ||
<artifactId>furnace-test-harness</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge.furnace.test</groupId> | ||
<artifactId>arquillian-furnace-classpath</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
|
74 changes: 74 additions & 0 deletions
74
rest-client/tests/src/test/java/org/jboss/forge/addon/rest/ClientTest.java
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,74 @@ | ||
/** | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.rest; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.not; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.arquillian.AddonDependency; | ||
import org.jboss.forge.arquillian.Dependencies; | ||
import org.jboss.forge.arquillian.archive.ForgeArchive; | ||
import org.jboss.forge.furnace.repositories.AddonDependencyEntry; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class ClientTest | ||
{ | ||
@Deployment | ||
@Dependencies({ | ||
@AddonDependency(name = "org.jboss.forge.addon:rest-client"), | ||
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi") }) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class) | ||
.addBeansXML() | ||
.addAsAddonDependencies( | ||
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"), | ||
AddonDependencyEntry.create("org.jboss.forge.addon:rest-client") | ||
); | ||
|
||
return archive; | ||
} | ||
|
||
@Inject | ||
ClientFactory clientFactory; | ||
|
||
@Test | ||
public void testClientImplementationAvailable() throws Exception | ||
{ | ||
Assert.assertNotNull(clientFactory); | ||
Assert.assertNotNull(clientFactory.createClientBuilder()); | ||
Client client = clientFactory.createClient(); | ||
Assert.assertNotNull(client); | ||
Assert.assertThat(client, is(not(clientFactory.createClient()))); | ||
} | ||
|
||
@Test | ||
public void testGetRequest() | ||
{ | ||
Client client = clientFactory.createClient(); | ||
String response = client.target("http://www.iheartquotes.com/api/v1/random").request(MediaType.TEXT_PLAIN_TYPE) | ||
.get(String.class); | ||
Assert.assertNotNull(response); | ||
Assert.assertFalse(response.isEmpty()); | ||
|
||
} | ||
} |