I have a Rest Get api:
@GET
@Path("myEndpoint")
public Response getSomething(@Context HttpServletResponse response) {
// do something with httpServletResponse
}
How do I return the updated HttpServletResponse
as javax.ws.rs.core.Response
?
I have a Rest Get api:
@GET
@Path("myEndpoint")
public Response getSomething(@Context HttpServletResponse response) {
// do something with httpServletResponse
}
How do I return the updated HttpServletResponse
as javax.ws.rs.core.Response
?
You can update HttpServletRequest
by adding it with @Context
in class
@Context
private HttpServletRequest request;
And check it in method
// do something with httpServletResponse
checkRequest(request);
Expanding a bit on @BlackSlash answer, a better syntax would be:
Response.status(Response.Status.OK).entity(any object here).build();
Or another example:
Response.status(Response.Status.BAD_REQUEST).entity("Error message...").build();
Just remember to set the media type correctly for example:
@Produces(MediaType.APPLICATION_JSON)