Dropwizard ExceptionMapper: checking source header fields

Does anyone know how I can get the original header fields from a request? I would like to confirm if the client receives html or just a text response. Can I get these fields inside the toResponse method of exceptionMapper method?

I created exceptionMapper, as in this post: http://gary-rowe.com/agilestack/2012/10/23/how-to-implement-a-runtimeexceptionmapper-for-dropwizard/

+4
source share
1 answer

If you want to get information from the original request object, you can add the following to the controller.

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;

@Path("/my")
@Produces(["application/json", "application/hal+json"])
class MyController {

  @Context
  protected HttpServletRequest httpRequest

  @Timed
  @GET
  public Response getOne(){
    httpRequest.getHeaders(); 
    ... //do something with headers
    return Response.ok(new Person(id:1), httpRequest.getContentType());
  }
+4
source

All Articles