Skip to content

Commit

Permalink
Fix CDI scope for classes that declare @ServerRequestFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand authored and pedroh-pereira committed Nov 14, 2022
1 parent 85020f3 commit 34d1854
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.function.Supplier;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Priorities;
Expand Down Expand Up @@ -151,6 +152,7 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
}
}

@ApplicationScoped
public static class CustomFilters {

@ServerRequestFilter(nonBlocking = true, priority = Priorities.USER + 20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Priorities;
Expand Down Expand Up @@ -134,6 +135,7 @@ public Uni<Void> uniResponseFilter(ContainerResponseContext ctx) {
}
}

@Singleton
public static class AlwaysEnabledFilter {

@ServerRequestFilter(priority = Priorities.USER + 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,10 @@ private FieldDescriptor generateConstructorAndDelegateField(ClassCreator cc, Cla
*/
private ScopeInspectionResult inspectScope(ClassInfo classInfo) {
if (classInfo.hasDeclaredAnnotation(ApplicationScoped.class) || classInfo.hasDeclaredAnnotation(RequestScoped.class)) {
return new ScopeInspectionResult(null, true);
return new ScopeInspectionResult(ApplicationScoped.class, true);
}
if (classInfo.hasDeclaredAnnotation(Singleton.class)) {
return new ScopeInspectionResult(null, false);
return new ScopeInspectionResult(Singleton.class, false);
}
List<FieldInfo> fields = classInfo.fields();
if (fields.isEmpty()) {
Expand Down

0 comments on commit 34d1854

Please sign in to comment.