有谁知道如何从请求中获取原始标头字段?我想验证客户端是否会收到 html 或只是纯/文本响应。我可以在异常映射器的“toResponse”方法中获取此字段吗?
我像这篇文章中一样创建了异常映射器:http://gary-rowe.com/agilestack/2012/10/23/how-to-implement-a-runtimeexceptionmapper-for-dropwizard/ 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());
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)