Skip to content

Commit

Permalink
Properly create REST Client template path when @url is used
Browse files Browse the repository at this point in the history
Fixes: quarkusio#44974
(cherry picked from commit e4a3279)
  • Loading branch information
geoand authored and gsmet committed Dec 17, 2024
1 parent fadd689 commit 53c8759
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,7 @@ A more full example of generated client (with sub-resource) can is at the bottom
classContext.constructor.getThis(),
baseTarget));
if (observabilityIntegrationNeeded) {
String templatePath = MULTIPLE_SLASH_PATTERN.matcher(restClientInterface.getPath() + method.getPath())
.replaceAll("/");
String templatePath = templatePath(restClientInterface, method);
classContext.constructor.invokeVirtualMethod(
MethodDescriptor.ofMethod(WebTargetImpl.class, "setPreClientSendHandler", void.class,
ClientRestHandler.class),
Expand Down Expand Up @@ -1012,11 +1011,25 @@ A more full example of generated client (with sub-resource) can is at the bottom
+ jandexMethod.name());
}

ResultHandle newInputTarget = methodParamNotNull.invokeVirtualMethod(
MethodDescriptor.ofMethod(WebTargetImpl.class, "withNewUri", WebTargetImpl.class,
java.net.URI.class),
methodParamNotNull.readInstanceField(inputTargetField, methodParamNotNull.getThis()),
newUri);
ResultHandle newInputTarget;
if (observabilityIntegrationNeeded) {
// we need to apply the ClientObservabilityHandler to the inputTarget field without altering it
newInputTarget = methodParamNotNull.invokeVirtualMethod(
MethodDescriptor.ofMethod(WebTargetImpl.class, "withNewUri", WebTargetImpl.class,
java.net.URI.class, ClientRestHandler.class),
methodParamNotNull.readInstanceField(inputTargetField, methodParamNotNull.getThis()),
newUri,
methodParamNotNull.newInstance(
MethodDescriptor.ofConstructor(ClientObservabilityHandler.class, String.class),
methodParamNotNull.load(templatePath(restClientInterface, method))));
} else {
// just read the inputTarget field and call withNewUri on it
newInputTarget = methodParamNotNull.invokeVirtualMethod(
MethodDescriptor.ofMethod(WebTargetImpl.class, "withNewUri", WebTargetImpl.class,
java.net.URI.class),
methodParamNotNull.readInstanceField(inputTargetField, methodParamNotNull.getThis()),
newUri);
}
ResultHandle newBaseTarget = methodParamNotNull.invokeVirtualMethod(
baseTargetProducer.getMethodDescriptor(),
methodParamNotNull.getThis(), newInputTarget);
Expand Down Expand Up @@ -1247,6 +1260,11 @@ A more full example of generated client (with sub-resource) can is at the bottom

}

private String templatePath(RestClientInterface restClientInterface, ResourceMethod method) {
return MULTIPLE_SLASH_PATTERN.matcher(restClientInterface.getPath() + method.getPath())
.replaceAll("/");
}

/**
* The @Encoded annotation is only supported in path/query/matrix/form params.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ public WebTargetImpl withNewUri(URI uri) {
return newInstance(client, UriBuilder.fromUri(uri), configuration);
}

@SuppressWarnings("unused") // this is used in the REST Client to support @BaseUrl and observability is enabled
public WebTargetImpl withNewUri(URI uri, ClientRestHandler preClientSendHandler) {
return newInstance(client, UriBuilder.fromUri(uri), configuration, preClientSendHandler);
}

@SuppressWarnings("unused")
public WebTargetImpl queryParams(MultivaluedMap<String, Object> parameters)
throws IllegalArgumentException, NullPointerException {
Expand Down Expand Up @@ -297,6 +302,12 @@ public WebTargetImpl queryParamNoTemplate(String name, Object... values) throws

protected WebTargetImpl newInstance(HttpClient client, UriBuilder uriBuilder,
ConfigurationImpl configuration) {
return newInstance(client, uriBuilder, configuration, preClientSendHandler);
}

protected WebTargetImpl newInstance(HttpClient client, UriBuilder uriBuilder,
ConfigurationImpl configuration,
ClientRestHandler preClientSendHandler) {
WebTargetImpl result = new WebTargetImpl(restClient, client, uriBuilder, configuration,
handlerChain.setPreClientSendHandler(preClientSendHandler),
requestContext);
Expand Down

0 comments on commit 53c8759

Please sign in to comment.