Java GAE不尊重泽西';s WebApplicationException
我的资源:Java GAE不尊重泽西';s WebApplicationException,java,google-app-engine,jersey,Java,Google App Engine,Jersey,我的资源: public class NotAuthorizedException extends WebApplicationException { public NotAuthorizedException(String message) { super(Response.status(Response.Status.BAD_REQUEST).entity(message).type(MediaType.TEXT_PLAIN).build()); } }
public class NotAuthorizedException extends WebApplicationException {
public NotAuthorizedException(String message) {
super(Response.status(Response.Status.BAD_REQUEST).entity(message).type(MediaType.TEXT_PLAIN).build());
}
}
在GAE dev server中,我的客户端接收到我的异常
,这是我所期望的,但在生产模式下,它返回:
public class MyResource{
@GET
public Book getBook(){
...
throw new NotAuthorizedException("my exception");
}
}
400错误请求
错误:请求错误
这似乎是GAE默认的400错误响应
提前感谢。我遇到了类似的问题。您的问题可以通过将“jersey.config.server.response.setStatusOverSendError”设置为true来解决。有关详细信息,请参见。此问题已由@Takahiko Kawasaki回答,但为了完整起见,以下是设置上述Jersey属性的两种可选方法: 以编程方式:
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>400 Bad Request</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Bad Request</h1>
</body></html>
或在web.xml中:
new ResourceConfig()
.property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, true);
美国石油学会
org.glassfish.jersey.servlet.ServletContainer
....
jersey.config.server.response.setStatusOversender错误
真的
<servlet>
<servlet-name>API</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
....
<init-param>
<param-name>jersey.config.server.response.setStatusOverSendError</param-name>
<param-value>true</param-value>
</init-param>
</servlet>