Say normally I have a REST method in Java
@POST @Path("/test") @Produces(MediaType.APPLICATION_JSON) public String showTime(@FormParam("username") String userName) { : : : }
which is fine. However, I'm wondering is there a way I can access the full HTTP request with Jersey such as
@POST @Path("/test") @Produces(MediaType.APPLICATION_JSON) public String showTime(@FormParam("username") String userName,@XXXXXX String httpRequest) { : : : }
where some annotation would give me the full HTTP request to store in a variable. I have tried using @POST but it doesn't seem to work. Any suggestions?
To view the request or response HTTP headers in Google Chrome, take the following steps : In Chrome, visit a URL, right click , select Inspect to open the developer tools. Select Network tab. Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.
An HTTP request is made by a client, to a named host, which is located on a server. The aim of the request is to access a resource on the server. To make the request, the client uses components of a URL (Uniform Resource Locator), which includes the information needed to access the resource.
An HTTP request is an action to be performed on a resource identified by a given Request-URL. Request methods are case-sensitive, and should always be noted in upper case. There are various HTTP request methods, but each one is assigned a specific purpose.
You can use the @Context annotation:
@POST @Path("/test") @Produces(MediaType.APPLICATION_JSON) public String showTime( @FormParam("username") String userName, @Context HttpServletRequest httpRequest ) { // The method body }
If you want to get the request body, you could use the tip lined out in this post: How to get full REST request body using Jersey?
If you need to know more about the request itself, you could try the @Context annotation as mentioned by sdorra.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With