Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAX-RS @Provider autodiscovery #1880

Merged
merged 6 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ void initInContext() {
private HelidonContainerImpl init() {
LOGGER.fine(() -> "Initializing CDI container " + id);

addHelidonBeanDefiningAnnotations("javax.ws.rs.Path", "javax.websocket.server.ServerEndpoint");
addHelidonBeanDefiningAnnotations("javax.ws.rs.Path",
"javax.ws.rs.ext.Provider",
"javax.websocket.server.ServerEndpoint");

ResourceLoader resourceLoader = new WeldResourceLoader() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import io.helidon.common.HelidonFeatures;
import io.helidon.common.HelidonFlavor;
Expand All @@ -66,6 +67,7 @@ public class JaxRsCdiExtension implements Extension {

private final Set<Class<? extends Application>> applications = new LinkedHashSet<>();
private final Set<Class<?>> resources = new HashSet<>();
private final Set<Class<?>> providers = new HashSet<>();
private final AtomicBoolean setInStone = new AtomicBoolean(false);

private void collectApplications(@Observes ProcessAnnotatedType<? extends Application> applicationType) {
Expand All @@ -82,6 +84,18 @@ private void collectResourceClasses(@Observes @WithAnnotations(Path.class) Proce
resources.add(resourceClass);
}

private void collectProviderClasses(@Observes @WithAnnotations(Provider.class) ProcessAnnotatedType<?> providerType) {
Class<?> providerClass = providerType.getAnnotatedType().getJavaClass();
if (providerClass.isInterface()) {
// we are only interested in classes
LOGGER.finest(() -> "Discovered @Provider interface " + providerClass
.getName() + ", ignored as we only support classes");
return;
}
LOGGER.finest(() -> "Discovered @Provider class " + providerClass.getName());
providers.add(providerClass);
}

// once application scoped starts, we do not allow modification of applications
void fixApps(@Observes @Priority(PLATFORM_BEFORE) @Initialized(ApplicationScoped.class) Object event) {
this.setInStone.set(true);
Expand All @@ -102,10 +116,16 @@ public List<JaxRsApplication> applicationsToRun() throws IllegalStateException {
throw new IllegalStateException("Applications are not yet fixed. This method is only available in "
+ "@Initialized(ApplicationScoped.class) event, before server is started");
}

// set of resource and provider classes that were discovered
Set<Class<?>> allClasses = new HashSet<>();
allClasses.addAll(resources);
allClasses.addAll(providers);

if (applications.isEmpty() && applicationMetas.isEmpty()) {
// create a synthetic application from all resource classes
if (!resources.isEmpty()) {
addSyntheticApp(resources);
addSyntheticApp(allClasses);
}
}

Expand All @@ -114,7 +134,7 @@ public List<JaxRsApplication> applicationsToRun() throws IllegalStateException {
.stream()
.map(appClass -> JaxRsApplication.builder()
.applicationClass(appClass)
.config(ResourceConfig.forApplicationClass(appClass, resources))
.config(ResourceConfig.forApplicationClass(appClass, allClasses))
.build())
.collect(Collectors.toList()));

Expand Down Expand Up @@ -238,7 +258,7 @@ public void addSyntheticApplication(List<Class<?>> resourceClasses) throws Illeg
// set-up synthetic application from resource classes
private void addSyntheticApp(Collection<Class<?>> resourceClasses) {
// the classes set must be created before the lambda, as the incoming collection may be mutable
Set<Class<?>> classes = new HashSet<>(resourceClasses);
Set<Class<?>> classes = Set.copyOf(resourceClasses);
this.applicationMetas.add(JaxRsApplication.builder()
.synthetic(true)
.applicationClass(Application.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020 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 Down Expand Up @@ -29,7 +29,6 @@
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;

import io.helidon.common.HelidonFeatures;
import io.helidon.common.context.Contexts;
Expand All @@ -48,7 +47,6 @@
* Only works as part of integration with Security component.
* This class is public to allow unit testing from providers (without invoking an HTTP request)
*/
@Provider
@ConstrainedTo(RuntimeType.CLIENT)
@Priority(Priorities.AUTHENTICATION)
public class ClientSecurityFilter implements ClientRequestFilter {
Expand Down

This file was deleted.

This file was deleted.

Loading