Dropwizard ExceptionMapper:验证原始标头字段 [英] Dropwizard ExceptionMapper: Validate original header fields

查看:70
本文介绍了Dropwizard ExceptionMapper:验证原始标头字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道我如何从请求中获取原始标头字段吗?我想验证,如果客户端将收到html或只是纯文本/文本响应。我可以在exceptionMapper的 toResponse方法中获取此字段吗?

Does anyone know how I can get the original header fields from request? I would like to validate, if client will receive html or just plain/text response. Can I get this fields inside 'toResponse' method of exceptionMapper?

我创建了exceptionMapper,如下所示:
http://gary-rowe.com/agilestack/2012/10/ 23 / how-to-implementation-a-runtimeexceptionmapper-for-dropwizard /

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

推荐答案

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());
  }

这篇关于Dropwizard ExceptionMapper:验证原始标头字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆