Skip to content

Commit

Permalink
Improve reactive rest client "process paths before sub resources" sce…
Browse files Browse the repository at this point in the history
…nario

There is an issue in upstream (quarkusio/quarkus#29821) that
only happens under some RestClient definition hierarchy.

This commit reproduces the problem in Quarkus 2.12 and earlier versions
  • Loading branch information
pablo gonzalez granados committed Jan 16, 2023
1 parent 2fad57f commit 0f64b62
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 125 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.quarkus.ts.http.restclient.reactive;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
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;

@RegisterRestClient
@RegisterClientHeaders
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public interface ResourceAndSubResourcesClient {
@Path("clients")
ClientsResource clients();

interface ClientsResource {
@Path("{id}")
ClientResource get(@PathParam("id") String id);
}

interface ClientResource {
@Path("/resource-server")
SubResource sub();
}

// interface PermissionsResource {
// @Path("resource")
// ResourcePermissionsResource resource();
// }

interface leafResource {
@DELETE
String remove();
}

interface SubResource {
@Path("{id}")
leafResource findById(@PathParam("id") String id);
}

// interface AuthorizationResource {
// @Path("/permission")
// PermissionsResource permissions();
// }
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.ts.http.restclient.reactive;
package io.quarkus.ts.http.restclient.reactive.resources;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.quarkus.ts.http.restclient.reactive.resources;

import java.net.URI;
import java.net.URISyntaxException;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.quarkus.ts.http.restclient.reactive.ResourceAndSubResourcesClient;

@Path("clients/{clientId}/clientResource")
@Consumes("text/plain")
@Produces("text/plain")
public class PlainComplexClientResource {
@Inject
@RestClient
ResourceAndSubResourcesClient resourceAndSubResourcesClient;

@DELETE
@Path("/{id}")
@Produces(MediaType.TEXT_PLAIN)
public String deleteClientResource(@PathParam("clientId") String rootParam,
@PathParam("id") String id,
@QueryParam("baseUri") String baseUri) throws URISyntaxException {
if (!StringUtils.isEmpty(baseUri)) {
ResourceAndSubResourcesClient rClient = RestClientBuilder.newBuilder().baseUri(new URI(baseUri))
.build(ResourceAndSubResourcesClient.class);
return rClient.clients().get(rootParam).sub().findById(id).remove();
}

return resourceAndSubResourcesClient.clients().get(rootParam).sub().findById(id).remove();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.ts.http.restclient.reactive;
package io.quarkus.ts.http.restclient.reactive.resources;

import java.util.List;
import java.util.Map;
Expand All @@ -14,6 +14,7 @@

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

import io.quarkus.ts.http.restclient.reactive.BookClient;
import io.quarkus.ts.http.restclient.reactive.json.Book;
import io.quarkus.ts.http.restclient.reactive.json.BookIdWrapper;
import io.quarkus.ts.http.restclient.reactive.json.IdBeanParam;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.ts.http.restclient.reactive.resources;

import javax.ws.rs.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("/clients/{rootPath}/resource-server")
public class ReactivecomplexClientResource {
@Path("/{id}")
@DELETE
public String deleteById(@PathParam("rootPath") String rootPath, @PathParam("id") String id) {
return "/clients/" + rootPath + "/resource-server/" + id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.json.JsonRestInterfa
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.files.FileClient".url=http://localhost:${quarkus.http.port}
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.BookClient".url=http://localhost:${quarkus.http.port}
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.BookClient.AuthorClient".url=http://localhost:${quarkus.http.port}
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.SubResourcesClient".url=http://localhost:${quarkus.http.port}
quarkus.rest-client."io.quarkus.ts.http.restclient.reactive.ResourceAndSubResourcesClient".url=http://localhost:${quarkus.http.port}

quarkus.rest-client.logging.scope=request-response
quarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=DEBUG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package io.quarkus.ts.http.restclient.reactive;

import static io.quarkus.ts.http.restclient.reactive.PlainBookResource.SEARCH_TERM_VAL;
import static io.quarkus.ts.http.restclient.reactive.resources.PlainBookResource.SEARCH_TERM_VAL;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.UUID;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;

import io.quarkus.test.bootstrap.Protocol;
import io.quarkus.test.bootstrap.RestService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.scenarios.annotations.DisabledOnQuarkusVersion;
Expand Down Expand Up @@ -201,23 +204,24 @@ public void checkSuffixPriority() {
@Tag("QUARKUS-2741")
@Test
public void checkProcessPathBeforeSubResources() {
// should result in sending GET root/method/sub/sub/subsub
String result = app.given().get("/plain-root/root/method/sub/subsub").then()
final String randomId = UUID.randomUUID().toString();
String result = app.given().delete("clients/myRealm/clientResource/" + randomId).then()
.statusCode(HttpStatus.SC_OK)
.extract().asString();

assertEquals("root/method/sub/sub/subsub", result);
assertEquals("/clients/myRealm/resource-server/" + randomId, result);
}

@Tag("QUARKUS-2741")
@Test
public void checkProcessPathBeforeSubResourcesManualRestClientBuild() {
String baseUri = String.format("http://%s:%s", app.getURI().getHost(), "" + app.getURI().getPort());
// should result in sending GET root/method/sub/sub/subsub
String result = app.given().get("/plain-root/root/manualClient/method/sub/subsub?baseUri=" + baseUri).then()
final String randomId = UUID.randomUUID().toString();
String baseUri = String.format("%s:%s", app.getURI(Protocol.HTTP).getRestAssuredStyleUri(),
"" + app.getURI().getPort());
String result = app.given().delete("clients/myRealm/clientResource/" + randomId + "/?baseUri=" + baseUri).then()
.statusCode(HttpStatus.SC_OK)
.extract().asString();

assertEquals("root/method/sub/sub/subsub", result);
assertEquals("/clients/myRealm/resource-server/" + randomId, result);
}
}

0 comments on commit 0f64b62

Please sign in to comment.