Skip to content

Commit

Permalink
fix servlet type controller method binding (#504)
Browse files Browse the repository at this point in the history
Servlet types shouldn't be interpreted as the body
  • Loading branch information
graemerocher authored Nov 19, 2024
1 parent 7ccb6c1 commit 8739f81
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ public class JaxRsTypeElementVisitor implements TypeElementVisitor<Object, Objec

// Backwards compatibility
@NextMajorVersion("Allow only inject values annotated with @Context")
private final List<String> JAX_RS_BINDING_TYPES = Stream.of(
HttpHeaders.class,
Cookie.class,
SecurityContext.class,
UriInfo.class
).map(Class::getName).toList();
private final List<String> JAX_RS_BINDING_TYPES = List.of(
HttpHeaders.class.getName(),
Cookie.class.getName(),
SecurityContext.class.getName(),
UriInfo.class.getName(),
"jakarta.servlet.ServletContext",
"jakarta.servlet.ServletRequest",
"jakarta.servlet.http.HttpServletRequest",
"jakarta.servlet.ServletResponse",
"jakarta.servlet.http.HttpServletResponse",
"jakarta.servlet.ServletConfig"
);

@Override
public int getOrder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import io.micronaut.http.client.HttpClient;
import io.micronaut.http.client.annotation.Client;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
Expand All @@ -28,8 +32,16 @@ public static class TestResource {

@GET
@Produces("text/plain")
public String get(HttpHeaders httpHeaders) {
public String get(HttpHeaders httpHeaders,
HttpServletRequest request,
HttpServletResponse response,
ServletConfig config,
ServletContext servletContext) throws IOException {
String header = httpHeaders.getHeaderString("foo");
Assertions.assertNotNull(response);
Assertions.assertNotNull(request);
Assertions.assertNotNull(config);
Assertions.assertNotNull(servletContext);
return header != null ? header : "Unknown";
}
}
Expand Down

0 comments on commit 8739f81

Please # to comment.