I need to recover the whole payload of a form POST request, to send it back to the receiver (PayPal requires this as a verification procedure). I tried several ways but I always get the same warning, with no payload:
Warning: A servlet request to the URI http://localhost:8080/ipnlistener contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.
Here's the code of the listener
@POST
@Path("/ipnlistener")
public Response testIpn(String t) {
System.out.println(t);
return Response.ok().build();
}
I tried to add different Consumes
annotations but nothing changes. Of course with FormParam
annotations I'm able to retrieve single fields, but I really need the whole body of the request.
I also tried with the following
public Response testIpn(@Context HttpServletRequest req) throws IOException {
BufferedReader reader= req.getReader();
String sCurrentLine;
while ((sCurrentLine = reader.readLine()) != null) {
System.out.println(sCurrentLine);
}
return Response.ok().build();
}
but I get the error
getInputStream() has already been called for this request
i think you can add the following code to your file:
@Context
private HttpServletRequest request;
The HttpServletRequest
contains the whole body of the request!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.