Skip to content

Commit

Permalink
Take @namebinding in the class hierarchy into account
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand authored and igorregis committed Oct 17, 2022
1 parent 14375dd commit 1015135
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public MaybeRestClientInterface createClientProxy(ClassInfo classInfo,
}
clazz.setPath(path);
}
List<ResourceMethod> methods = createEndpoints(classInfo, classInfo, new HashSet<>(),
List<ResourceMethod> methods = createEndpoints(classInfo, classInfo, new HashSet<>(), new HashSet<>(),
clazz.getPathParameters(), clazz.getPath(), false);
clazz.getMethods().addAll(methods);

Expand Down Expand Up @@ -99,7 +99,8 @@ protected void handleClientSubResource(ResourceMethod resourceMethod, MethodInfo
throw new IllegalStateException("Subresource method returns an invalid type: " + method.returnType().name());
}

List<ResourceMethod> endpoints = createEndpoints(subResourceClass, subResourceClass, new HashSet<>(), new HashSet<>(),
List<ResourceMethod> endpoints = createEndpoints(subResourceClass, subResourceClass,
new HashSet<>(), new HashSet<>(), new HashSet<>(),
"", false);
resourceMethod.setSubResourceMethods(endpoints);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public Optional<ResourceClass> createEndpoints(ClassInfo classInfo, boolean cons
if (classLevelExceptionMappers != null) {
clazz.setClassLevelExceptionMappers(classLevelExceptionMappers);
}
List<ResourceMethod> methods = createEndpoints(classInfo, classInfo, new HashSet<>(),
List<ResourceMethod> methods = createEndpoints(classInfo, classInfo, new HashSet<>(), new HashSet<>(),
clazz.getPathParameters(), clazz.getPath(), considerApplication);
clazz.getMethods().addAll(methods);

Expand Down Expand Up @@ -349,7 +349,7 @@ protected abstract METHOD createResourceMethod(MethodInfo info, ClassInfo actual
Map<String, Object> methodContext);

protected List<ResourceMethod> createEndpoints(ClassInfo currentClassInfo,
ClassInfo actualEndpointInfo, Set<String> seenMethods,
ClassInfo actualEndpointInfo, Set<String> seenMethods, Set<String> existingClassNameBindings,
Set<String> pathParameters, String resourceClassPath, boolean considerApplication) {
if (considerApplication && applicationScanningResult != null
&& !applicationScanningResult.keepClass(actualEndpointInfo.name().toString())) {
Expand All @@ -371,6 +371,9 @@ protected List<ResourceMethod> createEndpoints(ClassInfo currentClassInfo,
classConsumes, pathParameters, classStreamElementType);

Set<String> classNameBindings = NameBindingUtil.nameBindingNames(index, currentClassInfo);
if (classNameBindings.isEmpty()) {
classNameBindings = existingClassNameBindings;
}

for (DotName httpMethod : httpAnnotationToMethod.keySet()) {
List<MethodInfo> methods = currentClassInfo.methods();
Expand Down Expand Up @@ -436,15 +439,15 @@ protected List<ResourceMethod> createEndpoints(ClassInfo currentClassInfo,
if (superClassName != null && !superClassName.equals(OBJECT)) {
ClassInfo superClass = index.getClassByName(superClassName);
if (superClass != null) {
ret.addAll(createEndpoints(superClass, actualEndpointInfo, seenMethods,
ret.addAll(createEndpoints(superClass, actualEndpointInfo, seenMethods, classNameBindings,
pathParameters, resourceClassPath, considerApplication));
}
}
List<DotName> interfaces = currentClassInfo.interfaceNames();
for (DotName i : interfaces) {
ClassInfo superClass = index.getClassByName(i);
if (superClass != null) {
ret.addAll(createEndpoints(superClass, actualEndpointInfo, seenMethods,
ret.addAll(createEndpoints(superClass, actualEndpointInfo, seenMethods, classNameBindings,
pathParameters, resourceClassPath, considerApplication));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package org.jboss.resteasy.reactive.server.vertx.test.simple;

import static io.restassured.RestAssured.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import io.smallrye.mutiny.Uni;
import java.io.IOException;
import java.lang.annotation.Retention;
import javax.ws.rs.GET;
import javax.ws.rs.NameBinding;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;
import org.hamcrest.Matchers;
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class NameBindingWithInterfaceTest {

@RegisterExtension
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(BlockingHelloResource.class, ReactiveHelloResource.class, BlockingHelloApi.class,
ReactiveHelloApi.class, AddTestHeaderContainerRequestFilter.class));

@Test
public void blockingHello() {
get("/blocking-hello")
.then()
.statusCode(200)
.body(Matchers.equalTo("hello"))
.header("test", "some-value");
}

@Test
public void reactiveHello() {
get("/reactive-hello")
.then()
.statusCode(200)
.body(Matchers.equalTo("hello"))
.header("test", "some-value");
}

@SomeFilter
public static class BlockingHelloResource implements BlockingHelloApi {

@Override
public String sayHello() {
return "hello";
}
}

@SomeFilter
public static class ReactiveHelloResource implements ReactiveHelloApi {

@Override
public Uni<String> sayHello() {
return Uni.createFrom().item("hello");
}
}

@Path("blocking-hello")
public interface BlockingHelloApi {

@GET
@Produces(MediaType.TEXT_PLAIN)
String sayHello();
}

@Path("reactive-hello")
public interface ReactiveHelloApi {

@GET
@Produces(MediaType.TEXT_PLAIN)
Uni<String> sayHello();
}

@NameBinding
@Retention(RUNTIME)
@interface SomeFilter {
}

@Provider
@SomeFilter
public static class AddTestHeaderContainerRequestFilter implements ContainerResponseFilter {

@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
responseContext.getHeaders().putSingle("test", "some-value");

}
}
}

0 comments on commit 1015135

Please sign in to comment.