Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This repository contains a set of examples about the Shamrock framework.
* [Using Web Sockets](./using-websockets): Demonstrate how to use web sockets and serve static assets
* [Startup and Shutdown actions](./application-lifecycle-events): Explains how to execute code when the application starts and stops
* [Validation and JSON](./input-validation): How to consume and produce JSON payloads and how to validate the user input with Bean Validation
* [REST Client](./rest-client): How to use MicroProfile's REST Client

There is documentation published at <http://10.0.144.40/nfs/protean/index.html> (docs' [sources are here](https://github.com/jbossas/protean-shamrock/tree/master/docs/src/main/asciidoc)).

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
<module>using-websockets</module>
<module>using-opentracing</module>
<module>using-spring-di</module>
<module>rest-client</module>
</modules>
</project>
181 changes: 181 additions & 0 deletions rest-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?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>

<groupId>org.acme</groupId>
<artifactId>rest-client</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<shamrock.version>1.0.0.Alpha1-SNAPSHOT</shamrock.version>
<surefire.version>2.22.0</surefire.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shamrock</groupId>
<artifactId>shamrock-bom</artifactId>
<version>${shamrock.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jboss.shamrock</groupId>
<artifactId>shamrock-jaxrs-json-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shamrock</groupId>
<artifactId>shamrock-rest-client-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shamrock</groupId>
<artifactId>shamrock-junit5</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
<plugin>
<groupId>org.jboss.shamrock</groupId>
<artifactId>shamrock-maven-plugin</artifactId>
<version>${shamrock.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<build>
<plugins>
<plugin>
<groupId>org.jboss.shamrock</groupId>
<artifactId>shamrock-maven-plugin</artifactId>
<version>${shamrock.version}</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<!-- This should go away as soon as we publish the artifacts publicly. -->
<repositories>
<repository>
<id>central</id>
<name>Maven Central</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
<!-- Forgot the password? see https://github.com/protean-project/hibernate-protean/wiki/Protean-Nexus-credentials -->
<repository>
<id>protean-nexus-release</id>
<name>Protean AWS Nexus - Releases</name>
<url>http://ec2-18-234-117-118.compute-1.amazonaws.com:8081/nexus/content/repositories/releases/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- Forgot the password? see https://github.com/protean-project/hibernate-protean/wiki/Protean-Nexus-credentials -->
<repository>
<id>protean-nexus-snapshot</id>
<name>Protean AWS Nexus - Snapshots</name>
<url>http://ec2-18-234-117-118.compute-1.amazonaws.com:8081/nexus/content/repositories/snapshots/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<!-- 10 minutes. Or enforce refresh by using -U option to Maven -->
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Central</name>
<url>http://repo.maven.apache.org/maven2</url>
</pluginRepository>
<pluginRepository>
<id>protean-nexus-release</id>
<name>Protean AWS Nexus - Releases</name>
<url>http://ec2-18-234-117-118.compute-1.amazonaws.com:8081/nexus/content/repositories/releases/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<!-- Forgot the password? see https://github.com/protean-project/hibernate-protean/wiki/Protean-Nexus-credentials -->
<pluginRepository>
<id>protean-nexus-snapshot</id>
<name>Protean AWS Nexus - Snapshots</name>
<url>http://ec2-18-234-117-118.compute-1.amazonaws.com:8081/nexus/content/repositories/snapshots/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<!-- 10 minutes. Or enforce refresh by using -U option to Maven -->
<updatePolicy>daily</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.restclient;

import org.eclipse.microprofile.rest.client.inject.RestClient;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Set;

@Path("/country")
public class CountriesResource {

@Inject
@RestClient
private CountriesService countriesService;


@GET
@Path("/name/{name}")
@Produces(MediaType.APPLICATION_JSON)
public Set<Country> name(@PathParam("name") String name) {
return countriesService.getByName(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.acme.restclient;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import java.util.Set;

@Path("/v2")
@RegisterRestClient
public interface CountriesService {

@GET
@Path("/name/{name}")
@Produces("application/json")
Set<Country> getByName(@PathParam("name") String name);
}
74 changes: 74 additions & 0 deletions rest-client/src/main/java/org/acme/restclient/Country.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.acme.restclient;

import java.util.List;

public class Country {

private String name;
private String alpha2Code;
private String capital;
private List<Currency> currencies;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAlpha2Code() {
return alpha2Code;
}

public void setAlpha2Code(String alpha2Code) {
this.alpha2Code = alpha2Code;
}

public String getCapital() {
return capital;
}

public void setCapital(String capital) {
this.capital = capital;
}

public List<Currency> getCurrencies() {
return currencies;
}

public void setCurrencies(List<Currency> currencies) {
this.currencies = currencies;
}

public static class Currency {
private String code;
private String name;
private String symbol;

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSymbol() {
return symbol;
}

public void setSymbol(String symbol) {
this.symbol = symbol;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.acme.restclient.CountriesService/mp-rest/url=https://restcountries.eu/rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.acme.restclient;

import org.jboss.shamrock.test.junit.ShamrockTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@ShamrockTest
public class CountriesResourceTest {

@Test
public void testCountryNameEndpoint() {
given()
.when().get("/country/name/greece")
.then()
.statusCode(200)
.body("$.size()", is(1),
"[0].alpha2Code", is("GR"),
"[0].capital", is("Athens"),
"[0].currencies.size()", is(1),
"[0].currencies[0].name", is("Euro")
);
}

}