Skip to content

Commit

Permalink
Re-enabled test after integration with latest Jersey. Some changes to…
Browse files Browse the repository at this point in the history
… the example given that Jersey RestClient does appear to provide request scope support with async (there is no propagation). This was used by the test to get the dynamic port in which the server runs. New code uses the Helidon context for that. Test no longer blocks when using `Asynchronous` in a RestClient interface. (#7313)
  • Loading branch information
spericas authored Aug 7, 2023
1 parent fac2c3c commit c86339a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,23 +16,20 @@

package io.helidon.tests.integration.restclient;

import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;
import java.io.IOException;
import java.net.URI;

import io.helidon.common.context.Contexts;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;

/**
* A client request filter that replaces port 8080 by the ephemeral port allocated for the
* webserver in each run. This is necessary since {@link GreetResourceClient} uses an annotation
* to specify the base URI, and its value cannot be changed dynamically.
*/
public class GreetResourceFilter implements ClientRequestFilter {

@Context
UriInfo uriInfo;

@Override
public void filter(ClientRequestContext requestContext) throws IOException {
URI uri = requestContext.getUri();
Expand All @@ -41,7 +38,8 @@ public void filter(ClientRequestContext requestContext) throws IOException {
}

private String extractDynamicPort() {
String uriString = uriInfo.getBaseUri().toString();
URI uri = Contexts.globalContext().get(getClass(), URI.class).orElseThrow();
String uriString = uri.toString();
int k = uriString.lastIndexOf(":");
int j = uriString.indexOf("/", k);
return uriString.substring(k + 1, j);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import io.helidon.common.context.Contexts;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Inject;
import jakarta.json.JsonObject;
Expand Down Expand Up @@ -61,6 +62,10 @@ public void initialize() {
builderClient = RestClientBuilder.newBuilder()
.baseUri(uriInfo.getBaseUri())
.build(GreetResourceClient.class);

// Register base URI to update dynamic port in GreetResourceFilter
// given that the request scope is not provided by Jersey with async
Contexts.globalContext().register(GreetResourceFilter.class, uriInfo.getBaseUri());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.eclipse.microprofile.metrics.MetricRegistry;
import org.eclipse.microprofile.metrics.Tag;
import org.eclipse.microprofile.metrics.annotation.RegistryType;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -69,7 +68,6 @@ void testHelloWorld() {
}

@Test
@Disabled
void testHelloWorldAsync() {
JsonObject jsonObject = target
.path("proxy")
Expand Down

0 comments on commit c86339a

Please sign in to comment.