Not able to get request body from request context
See original GitHub issueDescription
I’m trying to get the body from request context
- what I’ve tried
inject CurrentVertxRequest
context and then get body from there
@Path("/map_event")
public class MapEventApi {
@Inject
CurrentVertxRequest reqContext;
@POST
@Consumes({ "application/json" })
@Produces({ "application/json" })
Response create(@Valid MapEvent mapEvent, @Context SecurityContext securityContext) throws Exception {
String body = reqContext.getCurrent().getBodyAsString();
...
}
}
but the getBodyAsString()
gives null value, with a warning:
2022-01-25 18:22:08,854 WARN [null:-1] (executor-thread-0) BodyHandler in not enabled on this route: RoutingContext.getBodyAsString(...) in always be NULL
- another try:
inject standard JaxRS HttpServletRequest
context
@Context HttpServletRequest
will get this error:
org.jboss.resteasy.spi.LoggableFailure: RESTEASY003880: Unable to find contextual data of type: javax.servlet.http.HttpServletRequest
at org.jboss.resteasy.core.ContextParameterInjector$GenericDelegatingProxy.invoke(ContextParameterInjector.java:155)
at com.sun.proxy.$Proxy97.getInputStream(Unknown Source)
I guess it’s because quarkus uses vertx under the hood so injecting regular JAX-RS context won’t work since it’s not the same thread.
Can not find a proper way to get the request body, anyone can help?
Implementation ideas
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Get request body of my request - java - Stack Overflow
You could try to wrap the Outputstream for the Entity. First, by using a javax.ws.rs.client.ClientRequestFilter to add a custom Outputstream ...
Read more >Unable to read HttpContext Body - Microsoft Q&A
Unable to read HttpContext Body. Hi, I am trying to read request information from request body but always getting as empty string.
Read more >Request and response objects - Django documentation
It's possible that a request can come in via POST with an empty POST dictionary – if, say, a form is requested via...
Read more >RequestContext (Spring Framework 6.0.2 API)
Suitable for exposition to views, and usage within JSP's "useBean" tag, JSP scriptlets, JSTL EL, etc. Necessary for views that do not have...
Read more >net/http - Go Packages
Package http provides HTTP client and server implementations. ... New("http: request method or response status code does not allow body") // ErrHijacked is ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks. We’ll do as you suggested
If I needed to read the body many times in filter, what I would do is setup a
ContainerRequestFilter
with a very low@Priority
(thus it would be executed very early) that read the body and saved in a property ofContainerRequestContext
. Then my other filters would read the body from there