Skip to content

Commit

Permalink
Fixes for packaging tests. Review fix (metrics)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-langer committed Oct 14, 2022
1 parent 1faac59 commit 378c04e
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public boolean test(Http.Method t) {
public Set<Method> acceptedMethods() {
return Set.of();
}

@Override
public String toString() {
return "(any method)";
}
}

static class SingleMethodEnumPredicate implements MethodPredicate {
Expand Down
8 changes: 4 additions & 4 deletions etc/scripts/test-packaging-jar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ java -Dexit.on.started=! -jar target/helidon-tests-native-image-se-1.jar
#
cd ${WS_DIR}/tests/integration/native-image/mp-1
# Classpath
java -jar target/helidon-tests-native-image-mp-1.jar
java --enable-preview -jar target/helidon-tests-native-image-mp-1.jar

# Module Path
java --module-path target/helidon-tests-native-image-mp-1.jar:target/libs \
java --enable-preview --module-path target/helidon-tests-native-image-mp-1.jar:target/libs \
--module helidon.tests.nimage.mp/io.helidon.tests.integration.nativeimage.mp1.Mp1Main

#
# Run MP-3 (just start and stop)
#
cd ${WS_DIR}/tests/integration/native-image/mp-3
# Classpath
java -Dexit.on.started=! -jar target/helidon-tests-native-image-mp-3.jar
java --enable-preview -Dexit.on.started=! -jar target/helidon-tests-native-image-mp-3.jar

# Module Path
java -Dexit.on.started=! \
java --enable-preview -Dexit.on.started=! \
--module-path target/helidon-tests-native-image-mp-3.jar:target/libs \
--add-modules helidon.tests.nimage.quickstartmp \
--module io.helidon.microprofile.cdi/io.helidon.microprofile.cdi.Main
8 changes: 5 additions & 3 deletions etc/scripts/test-packaging-jlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ cd ${WS_DIR}/tests/integration/native-image/se-1
jri_dir=${WS_DIR}/tests/integration/native-image/se-1/target/helidon-tests-native-image-se-1-jri

# Classpath
${jri_dir}/bin/start --test
${jri_dir}/bin/start --test --jvm --enable-preview

# Run MP-1
cd ${WS_DIR}/tests/integration/native-image/mp-1
jri_dir=${WS_DIR}/tests/integration/native-image/mp-1/target/helidon-tests-native-image-mp-1-jri

# Classpath
${jri_dir}/bin/start
${jri_dir}/bin/start --jvm --enable-preview

# Module Path
${jri_dir}/bin/java \
--enable-preview \
--module-path ${jri_dir}/app/helidon-tests-native-image-mp-1.jar:${jri_dir}/app/libs \
--module helidon.tests.nimage.mp/io.helidon.tests.integration.nativeimage.mp1.Mp1Main

Expand All @@ -64,10 +65,11 @@ cd ${WS_DIR}/tests/integration/native-image/mp-3
jri_dir=${WS_DIR}/tests/integration/native-image/mp-3/target/helidon-tests-native-image-mp-3-jri

# Classpath
${jri_dir}/bin/start --test
${jri_dir}/bin/start --test --jvm --enable-preview

# Module Path
${jri_dir}/bin/java -Dexit.on.started=! \
--enable-preview \
--module-path ${jri_dir}/app/helidon-tests-native-image-mp-3.jar:${jri_dir}/app/libs \
--add-modules helidon.tests.nimage.quickstartmp \
--module io.helidon.microprofile.cdi/io.helidon.microprofile.cdi.Main
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ static BuiltInRegistryType valueByName(String name) throws UnrecognizedBuiltInRe
Handler matchingHandler(ServerRequest serverRequest, ServerResponse serverResponse) {
return registryEnrollments.stream()
.map(e -> e.handlerFn().apply(serverRequest))
.findFirst()
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElse((req, res) -> res
.status(Http.Status.NOT_ACCEPTABLE_406)
.send(NO_MATCHING_REGISTRY_ERROR_MESSAGE));
Expand All @@ -244,9 +244,9 @@ io.helidon.nima.webserver.http.Handler matchingHandler(io.helidon.nima.webserver
io.helidon.nima.webserver.http.ServerResponse serverResponse) {
return nimaRegistryEnrollments.stream()
.map(e -> e.handlerFn().apply(serverRequest))
.findFirst()
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElse((req, res) -> res
.status(Http.Status.NOT_ACCEPTABLE_406)
.send(NO_MATCHING_REGISTRY_ERROR_MESSAGE));
Expand Down
2 changes: 2 additions & 0 deletions metrics/metrics/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

exports io.helidon.metrics;

uses io.helidon.metrics.api.spi.ExemplarService;

provides io.helidon.metrics.api.spi.RegistryFactoryProvider with io.helidon.metrics.RegistryFactoryProviderImpl;
provides io.helidon.common.configurable.spi.ExecutorServiceSupplierObserver
with io.helidon.metrics.ExecutorServiceMetricsObserver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ public Set<Class<?>> getClasses() {
.build());
}

JaxRsHandler toJerseySupport(JaxRsApplication jaxRsApplication,
JaxRsService toJerseySupport(JaxRsApplication jaxRsApplication,
InjectionManager injectionManager) {

ResourceConfig resourceConfig = jaxRsApplication.resourceConfig();
resourceConfig.register(new CatchAllExceptionMapper());

return JaxRsHandler.create(resourceConfig,
return JaxRsService.create(resourceConfig,
injectionManager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
import io.helidon.common.uri.UriPath;
import io.helidon.microprofile.server.HelidonHK2InjectionManagerFactory.InjectionManagerWrapper;
import io.helidon.nima.webserver.KeyPerformanceIndicatorSupport;
import io.helidon.nima.webserver.http.Handler;
import io.helidon.nima.webserver.http.HttpRules;
import io.helidon.nima.webserver.http.HttpService;
import io.helidon.nima.webserver.http.ServerRequest;
import io.helidon.nima.webserver.http.ServerResponse;

Expand All @@ -67,13 +68,13 @@
import static org.glassfish.jersey.CommonProperties.PROVIDER_DEFAULT_DISABLE;
import static org.glassfish.jersey.server.ServerProperties.WADL_FEATURE_DISABLE;

class JaxRsHandler implements Handler {
class JaxRsService implements HttpService {
/**
* If set to {@code "true"}, Jersey will ignore responses in exceptions.
*/
static final String IGNORE_EXCEPTION_RESPONSE = "jersey.config.client.ignoreExceptionResponse";

private static final System.Logger LOGGER = System.getLogger(JaxRsHandler.class.getName());
private static final System.Logger LOGGER = System.getLogger(JaxRsService.class.getName());
private static final Type REQUEST_TYPE = (new GenericType<Ref<ServerRequest>>() { }).getType();
private static final Type RESPONSE_TYPE = (new GenericType<Ref<ServerResponse>>() { }).getType();
private static final Set<InjectionManager> INJECTION_MANAGERS = Collections.newSetFromMap(new WeakHashMap<>());
Expand All @@ -83,7 +84,7 @@ class JaxRsHandler implements Handler {
private final Container container;
private final Application application;

private JaxRsHandler(ResourceConfig resourceConfig,
private JaxRsService(ResourceConfig resourceConfig,
ApplicationHandler appHandler,
Container container) {
this.resourceConfig = resourceConfig;
Expand All @@ -92,7 +93,7 @@ private JaxRsHandler(ResourceConfig resourceConfig,
this.application = getApplication(resourceConfig);
}

static JaxRsHandler create(ResourceConfig resourceConfig, InjectionManager injectionManager) {
static JaxRsService create(ResourceConfig resourceConfig, InjectionManager injectionManager) {
resourceConfig.property(PROVIDER_DEFAULT_DISABLE, "ALL");
resourceConfig.property(WADL_FEATURE_DISABLE, "true");

Expand All @@ -113,7 +114,7 @@ static JaxRsHandler create(ResourceConfig resourceConfig, InjectionManager injec
System.setProperty(IGNORE_EXCEPTION_RESPONSE, ignore);
}

return new JaxRsHandler(resourceConfig, appHandler, container);
return new JaxRsService(resourceConfig, appHandler, container);
}

static String basePath(UriPath path) {
Expand All @@ -131,7 +132,11 @@ static String basePath(UriPath path) {
}

@Override
public void handle(ServerRequest req, ServerResponse res) {
public void routing(HttpRules rules) {
rules.any(this::handle);
}

private void handle(ServerRequest req, ServerResponse res) {
Contexts.runInContext(req.context(), () -> doHandle(req.context(), req, res));
}

Expand Down Expand Up @@ -184,10 +189,16 @@ private static URI baseUri(ServerRequest req) {

private void doHandle(Context ctx, ServerRequest req, ServerResponse res) {
URI baseUri = baseUri(req);
URI requestUri;

if (req.query().isEmpty()) {
requestUri = baseUri.resolve(req.path().rawPath());
} else {
requestUri = baseUri.resolve(req.path().rawPath() + "?" + req.query().rawValue());
}

ContainerRequest requestContext = new ContainerRequest(baseUri,
baseUri.resolve(req.path().rawPath() + "?" + req.query()
.rawValue()),
requestUri,
req.prologue().method().text(),
new HelidonMpSecurityContext(), new MapPropertiesDelegate(),
resourceConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,19 @@ private void addApplication(JaxRsCdiExtension jaxRs, JaxRsApplication applicatio

HttpRouting.Builder routing = routingBuilder(namedRouting, routingNameRequired, applicationMeta.appName());

JaxRsHandler jerseySupport = jaxRs.toJerseySupport(applicationMeta, injectionManager);
JaxRsService jerseyHandler = jaxRs.toJerseySupport(applicationMeta, injectionManager);
if (contextRoot.isPresent()) {
String contextRootString = contextRoot.get();
LOGGER.fine(() -> "JAX-RS application " + applicationMeta.appName() + " registered on '" + contextRootString + "'");
if (contextRootString.endsWith("/")) {
routing.any(contextRootString + "*", jerseySupport);
routing.register(contextRootString.substring(0, contextRootString.length() - 1), jerseyHandler);
} else {
routing.any(contextRootString + "/*", jerseySupport);
routing.register(contextRootString, jerseyHandler);
}

} else {
LOGGER.fine(() -> "JAX-RS application " + applicationMeta.appName() + " registered on '/'");
routing.any("/*", jerseySupport);
routing.register(jerseyHandler);
}
}

Expand Down
4 changes: 2 additions & 2 deletions microprofile/server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@

provides InjectionManagerFactory with io.helidon.microprofile.server.HelidonHK2InjectionManagerFactory;

// needed when running with modules - to make private methods accessible
opens io.helidon.microprofile.server to weld.core.impl, org.glassfish.hk2.utilities, io.helidon.microprofile.cdi;
// needed when running with modules - to make private methods and types accessible
opens io.helidon.microprofile.server;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/**
* Test that it is possible to override {@code IGNORE_EXCEPTION_RESPONSE} in
* Jersey using config. See {@link io.helidon.microprofile.server.JaxRsHandler}
* Jersey using config. See {@link JaxRsService}
* for more information.
*/
@HelidonTest
Expand All @@ -45,7 +45,7 @@
class JerseyPropertiesTest {
@Test
void testIgnoreExceptionResponseOverride() {
JaxRsHandler jerseySupport = JaxRsHandler.create(new ResourceConfig().property(IGNORE_EXCEPTION_RESPONSE, "false"),
JaxRsService jerseySupport = JaxRsService.create(new ResourceConfig().property(IGNORE_EXCEPTION_RESPONSE, "false"),
null);
assertNotNull(jerseySupport);
assertThat(System.getProperty(IGNORE_EXCEPTION_RESPONSE), is("false"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@
@Priority(Integer.MIN_VALUE)
@ApplicationScoped
public class MpTracingContextFilter implements ContainerRequestFilter {
@Context
private Provider<ServerRequest> request;
private final Provider<ServerRequest> request;

private final Config config = ConfigProvider.getConfig();

/**
* Constructor to be used by JAX-RS implementation.
*
* @param request injected by JAX-RS
*/
public MpTracingContextFilter(@Context Provider<ServerRequest> request) {
this.request = request;
}

@Override
public void filter(ContainerRequestContext requestContext) {
ServerRequest serverRequest = this.request.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@
public class MpTracingFilter extends AbstractTracingFilter {
private static final Pattern LOCALHOST_PATTERN = Pattern.compile("127.0.0.1", Pattern.LITERAL);

@Context
private ResourceInfo resourceInfo;
private final ResourceInfo resourceInfo;

private MpTracingHelper utils;
private Function<String, Boolean> skipPatternFunction;

/**
* Create a new instance by JAX-RS.
*
* @param resourceInfo injected by JAX-RS implementation
*/
public MpTracingFilter(@Context ResourceInfo resourceInfo) {
this.resourceInfo = resourceInfo;
}

/**
* Post construct method, initialization procedures.
*/
Expand Down
4 changes: 2 additions & 2 deletions microprofile/tracing/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

exports io.helidon.microprofile.tracing;

// this is needed for CDI extensions that use non-public observer methods
opens io.helidon.microprofile.tracing to weld.core.impl,org.glassfish.hk2.utilities, io.helidon.microprofile.cdi;
// this is needed for CDI extensions that use non-public observer methods, and for constructor injection
opens io.helidon.microprofile.tracing;

provides jakarta.enterprise.inject.spi.Extension
with io.helidon.microprofile.tracing.TracingCdiExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,29 @@ private Map<String, SecurityDefinition> subResourceMethodSecurity(Class<?> appCl
return appClassCacheEntry(appClass).subResourceMethodSecurity;
}

@Context
private ServerConfig serverConfig;
private final ServerConfig serverConfig;

@Context
private SecurityContext securityContext;
private final SecurityContext securityContext;

private final List<AnnotationAnalyzer> analyzers = new LinkedList<>();

/**
* Default constructor to be used by Jersey when creating an instance of this class.
* Constructor to be used by Jersey when creating an instance, injects all parameters.
*
* @param security security instance
* @param featureConfig feature config
* @param serverConfig server config
* @param securityContext security context
*/
public SecurityFilter() {
public SecurityFilter(@Context Security security,
@Context FeatureConfig featureConfig,
@Context ServerConfig serverConfig,
@Context SecurityContext securityContext) {
super(security, featureConfig);

this.serverConfig = serverConfig;
this.securityContext = securityContext;

loadAnalyzers();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,13 @@ abstract class SecurityFilterCommon {
private static final List<SecurityResponseMapper> RESPONSE_MAPPERS = HelidonServiceLoader
.builder(ServiceLoader.load(SecurityResponseMapper.class)).build().asList();

@Context
private Security security;
private final Security security;

@Context
private FeatureConfig featureConfig;

SecurityFilterCommon() {
}
private final FeatureConfig featureConfig;

// due to a bug in Jersey @Context in constructor injection is failing
// this method is needed for unit tests
SecurityFilterCommon(Security security, FeatureConfig featureConfig) {
SecurityFilterCommon(@Context Security security, @Context FeatureConfig featureConfig) {
this.security = security;
this.featureConfig = featureConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.logging.Logger;

import io.helidon.common.context.Contexts;
import io.helidon.security.Security;
import io.helidon.security.SecurityContext;
import io.helidon.security.integration.common.SecurityTracing;

Expand Down Expand Up @@ -47,11 +48,18 @@ class SecurityPreMatchingFilter extends SecurityFilterCommon implements Containe

private static final AtomicInteger CONTEXT_COUNTER = new AtomicInteger();

@Context
private InjectionManager injectionManager;
private final InjectionManager injectionManager;
private final UriInfo uriInfo;

@Context
private UriInfo uriInfo;
SecurityPreMatchingFilter(@Context Security security,
@Context FeatureConfig featureConfig,
@Context InjectionManager injectionManager,
@Context UriInfo uriInfo) {
super(security, featureConfig);

this.injectionManager = injectionManager;
this.uriInfo = uriInfo;
}

@Override
public void filter(ContainerRequestContext request) {
Expand Down
Loading

0 comments on commit 378c04e

Please sign in to comment.