Skip to content

Commit

Permalink
Merge pull request quarkus-qe#459 from pjgg/backport_1e7c244
Browse files Browse the repository at this point in the history
[2.2] Add reactive counterpart of http/rest-client module
  • Loading branch information
Pablo Gonzalez Granados authored Jan 10, 2022
2 parents b86df92 + 3e5e9b7 commit 6d61088
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ Verifies Rest Client configuration using `quarkus-rest-client-jaxb` (XML support
This module will setup a very minimal configuration (only `quarkus-resteasy`) and have four endpoints:
- Two endpoints to get a book in JSON and XML formats.

### `http/rest-client-reactive`
Reactive equivalent of the http/rest-client module.
Exclusions: XML test. Reason: https://quarkus.io/blog/resteasy-reactive/#what-jax-rs-features-are-missing

#### Additions
* *@Deprecated* annotation has been added for test regression purposes to ensure `java.lang` annotations are allowed for resources
* Resource with multipart body support, provided parts are text, image and binary data, charset checked with `us-ascii` and `utf-8`
Expand Down
27 changes: 27 additions & 0 deletions http/rest-client-reactive/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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>io.quarkus.ts.qe</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>http-rest-client-reactive</artifactId>
<packaging>jar</packaging>
<name>Quarkus QE TS: HTTP: Rest Client Reactive</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxb</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.quarkus.ts.http.restclient.reactive;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

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

import io.quarkus.ts.http.restclient.reactive.json.Book;
import io.smallrye.mutiny.Uni;

@Path("/client/book")
public class ReactiveClientBookResource {

@Inject
@RestClient
ReactiveRestInterface restInterface;

@GET
@Path("/json")
@Produces(MediaType.APPLICATION_JSON)
public Uni<Book> getAsJson() {
return restInterface.getAsJson();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.ts.http.restclient.reactive;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

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

import io.quarkus.ts.http.restclient.reactive.json.Book;
import io.smallrye.mutiny.Uni;

@RegisterRestClient
@Path("/book")
@RegisterClientHeaders
public interface ReactiveRestInterface {

@GET
@Path("/json")
@Produces(MediaType.APPLICATION_JSON)
Uni<Book> getAsJson();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.ts.http.restclient.reactive.json;

public class Book {

private String title;

public Book() {
}

public Book(String title) {
this.title = title;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.ts.http.restclient.reactive.json;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import io.smallrye.mutiny.Uni;

@Produces(MediaType.APPLICATION_JSON)
@Path("/book/json")
public class BookAsJsonResource {

@GET
public Uni<String> get() {
return Uni.createFrom().item("{\"title\":\"Title in Json\"}");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.ts.http.restclient.reactive.ReactiveRestInterface/mp-rest/url=http://localhost:${quarkus.http.port}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.ts.http.restclient.reactive;

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

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;

import io.quarkus.test.scenarios.QuarkusScenario;

@QuarkusScenario
public class ClientBookResourceIT {

@Test
public void shouldGetBookFromRestClientJson() {
given().get("/client/book/json").then().statusCode(HttpStatus.SC_OK)
.body(is("{\"title\":\"Title in Json\"}"));
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
<module>http/jaxrs-reactive</module>
<module>http/reactive-routes</module>
<module>http/rest-client</module>
<module>http/rest-client-reactive</module>
<module>http/servlet-undertow</module>
<module>http/vertx-web-client</module>
</modules>
Expand Down

0 comments on commit 6d61088

Please sign in to comment.