Skip to content

Commit

Permalink
Merge pull request #472 from gastaldi/FORGE-1833
Browse files Browse the repository at this point in the history
FORGE-1833: Added Resteasy's JAX-RS 2.0 Client implementation
  • Loading branch information
lincolnthree committed Jun 10, 2014
2 parents aca0f2b + fb01493 commit 72afbc6
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 2 deletions.
6 changes: 6 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@
<version>${project.version}</version>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>rest-client</artifactId>
<version>${project.version}</version>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>projects-api</artifactId>
Expand Down
15 changes: 13 additions & 2 deletions javaee/addon/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?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">
<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>
Expand Down Expand Up @@ -57,12 +58,22 @@
<artifactId>text</artifactId>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>bean-validation</artifactId>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>rest-client</artifactId>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>javaee-spi</artifactId>
<classifier>forge-addon</classifier>
</dependency>

<!-- Furnace Container -->
<dependency>
<groupId>org.jboss.forge.furnace.container</groupId>
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<module>parser-json</module>
<module>parser-xml</module>
<module>resources</module>
<module>rest-client</module>
<module>ui</module>
<module>scaffold</module>
<module>shell</module>
Expand All @@ -115,6 +116,7 @@
<module>addon-manager/api</module>
<module>addon-manager/spi</module>
<module>addons/api</module>
<module>bean-validation/api</module>
<module>convert/api</module>
<module>configuration/api</module>
<module>dependencies/api</module>
Expand All @@ -128,6 +130,7 @@
<module>parser-json/api</module>
<module>parser-xml/api</module>
<module>resources/api</module>
<module>rest-client</module>
<module>ui/api</module>
<module>ui/spi</module>
<module>ui/test-harness</module>
Expand Down
63 changes: 63 additions & 0 deletions rest-client/README.asciidoc
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();
----
====
88 changes: 88 additions & 0 deletions rest-client/addon/pom.xml
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>
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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.jboss.forge.addon.rest.ClientFactory
21 changes: 21 additions & 0 deletions rest-client/pom.xml
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>
35 changes: 35 additions & 0 deletions rest-client/tests/pom.xml
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>

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());

}
}

0 comments on commit 72afbc6

Please sign in to comment.