Skip to content

Commit fb5b21c

Browse files
authored
Merge pull request #49221 from mposolda/49172-resteasy-head-bug
Fix Quarkus REST issue where HEAD returned 405
2 parents 4544e85 + 0702c4a commit fb5b21c

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-10
lines changed

independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ResourceLocatorHandler.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,22 @@ public void onComplete(Throwable throwable) {
7979
}
8080

8181
RequestMapper<RuntimeResource> mapper = target.get(requestContext.getMethod());
82-
boolean hadNullMethodMapper = false;
83-
if (mapper == null) {
84-
mapper = target.get(null); //another layer of resource locators maybe
82+
RequestMapper.RequestMatch<RuntimeResource> res;
83+
boolean hadNullMethodMapper;
84+
if (mapper != null) {
85+
res = findRequestMatch(mapper, requestContext);
86+
hadNullMethodMapper = false;
87+
} else {
88+
res = findRequestMatch(target.get(null), requestContext); //another layer of resource locators maybe
8589
// we set this without checking if we matched, but we only use it after
8690
// we check for a null mapper, so by the time we use it, it must have meant that
8791
// we had a matcher for a null method
8892
hadNullMethodMapper = true;
8993

90-
if (mapper == null) {
94+
if (res == null) {
9195
String requestMethod = requestContext.getMethod();
9296
if (requestMethod.equals(HttpMethod.HEAD)) {
93-
mapper = target.get(HttpMethod.GET);
97+
res = findRequestMatch(target.get(HttpMethod.GET), requestContext);
9498
} else if (requestMethod.equals(HttpMethod.OPTIONS)) {
9599
Set<String> allowedMethods = new HashSet<>();
96100
for (String method : target.keySet()) {
@@ -106,11 +110,6 @@ public void onComplete(Throwable throwable) {
106110
}
107111
}
108112
}
109-
if (mapper == null) {
110-
throw new WebApplicationException(Response.status(Response.Status.METHOD_NOT_ALLOWED.getStatusCode()).build());
111-
}
112-
RequestMapper.RequestMatch<RuntimeResource> res = mapper
113-
.map(requestContext.getRemaining().isEmpty() ? "/" : requestContext.getRemaining());
114113
if (res == null) {
115114
// the TCK checks for both these return statuses
116115
if (hadNullMethodMapper)
@@ -133,6 +132,12 @@ public void onComplete(Throwable throwable) {
133132

134133
}
135134

135+
private RequestMapper.RequestMatch<RuntimeResource> findRequestMatch(RequestMapper<RuntimeResource> mapper,
136+
ResteasyReactiveRequestContext requestContext) {
137+
return mapper == null ? null
138+
: mapper.map(requestContext.getRemaining().isEmpty() ? "/" : requestContext.getRemaining());
139+
}
140+
136141
private Map<String, RequestMapper<RuntimeResource>> findTarget(Class<?> locatorClass) {
137142
if (locatorClass == Object.class || locatorClass == null) {
138143
return null;

independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/resource/basic/ParameterSubResTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.jboss.resteasy.reactive.server.vertx.test.resource.basic.resource.ParameterSubResRootImpl;
2323
import org.jboss.resteasy.reactive.server.vertx.test.resource.basic.resource.ParameterSubResSub;
2424
import org.jboss.resteasy.reactive.server.vertx.test.resource.basic.resource.ParameterSubResSubImpl;
25+
import org.jboss.resteasy.reactive.server.vertx.test.resource.basic.resource.ParameterSubResSubImpl2;
2526
import org.jboss.resteasy.reactive.server.vertx.test.resource.basic.resource.RequestScopedObject;
2627
import org.jboss.resteasy.reactive.server.vertx.test.simple.PortProviderUtil;
2728
import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -65,6 +66,7 @@ public JavaArchive get() {
6566
war.addClass(RequestScopedObject.class);
6667
war.addClass(ParameterSubResSub.class);
6768
war.addClass(ParameterSubResSubImpl.class);
69+
war.addClass(ParameterSubResSubImpl2.class);
6870
war.addClasses(ParameterSubResRootImpl.class, ParameterSubResGenericSub.class);
6971
return war;
7072
}
@@ -110,6 +112,30 @@ public void testSubResourceOptions() throws Exception {
110112
Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
111113
}
112114

115+
@Test
116+
@DisplayName("Test Sub Resource with null path handler")
117+
public void testSubResourceWithNullPathHandler() throws Exception {
118+
Response response = client.target(generateURL("/path/sub2")).request().get();
119+
Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
120+
Assertions.assertEquals("Boo2", response.readEntity(String.class), "Wrong content of response");
121+
}
122+
123+
@Test
124+
@DisplayName("Test Sub Resource with null path handler - HEAD")
125+
public void testSubResourceWithNullPathHandlerHead() throws Exception {
126+
try (Response response = client.target(generateURL("/path/sub2")).request().head()) {
127+
Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
128+
}
129+
}
130+
131+
@Test
132+
@DisplayName("Test Sub Resource with null path handler - OPTIONS")
133+
public void testSubResourceWithNullPathHandlerOptions() throws Exception {
134+
try (Response response = client.target(generateURL("/path/sub2")).request().options()) {
135+
Assertions.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
136+
}
137+
}
138+
113139
@Test
114140
@DisplayName("Test Return Sub Resource As Class")
115141
public void testReturnSubResourceAsClass() throws Exception {

independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/resource/basic/resource/ParameterSubResRoot.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ public interface ParameterSubResRoot {
99

1010
@Path("subclass")
1111
Class<ParameterSubResClassSub> getSubClass();
12+
13+
@Path("sub2")
14+
ParameterSubResSubImpl2 getAnotherSubresource();
1215
}

independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/resource/basic/resource/ParameterSubResRootImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ public Class<ParameterSubResClassSub> getSubClass() {
1515
return ParameterSubResClassSub.class;
1616
}
1717

18+
@Override
19+
public ParameterSubResSubImpl2 getAnotherSubresource() {
20+
return new ParameterSubResSubImpl2();
21+
}
1822
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.jboss.resteasy.reactive.server.vertx.test.resource.basic.resource;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.Produces;
6+
7+
public class ParameterSubResSubImpl2 {
8+
9+
@GET
10+
@Produces("text/plain")
11+
public String get() {
12+
return "Boo2";
13+
}
14+
15+
@Path("/unrelated")
16+
@Produces("text/plain")
17+
public String noHttpMethod() {
18+
return "Whatever - this method exists just to simulate 49172";
19+
}
20+
}

0 commit comments

Comments
 (0)