July
July

Reputation: 913

GAE does not honor Jersey's WebApplicationException

public class NotAuthorizedException extends WebApplicationException {
    public NotAuthorizedException(String message) {
           super(Response.status(Response.Status.BAD_REQUEST).entity(message).type(MediaType.TEXT_PLAIN).build());
    }
}

My resource:

public class MyResource{
@GET
public Book getBook(){
   ...
   throw new NotAuthorizedException("my exception");
}
}

In GAE dev server, my client side receive my exception, which is what I expect, but in production mode, it returns:

<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>

which seems like the GAE default 400 error response.

Thanks in advance.

Upvotes: 3

Views: 244

Answers (2)

G. Demecki
G. Demecki

Reputation: 10586

This question is already answered by @Takahiko Kawasaki but just for completness below are two alternative ways to set mentioned Jersey property:

Programmatically:

new ResourceConfig()
       .property(ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, true);

Or inside web.xml:

<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>

Upvotes: 0

Takahiko Kawasaki
Takahiko Kawasaki

Reputation: 18991

I encountered a similar issue. Your problem may be solved by setting "jersey.config.server.response.setStatusOverSendError" to true. See https://stackoverflow.com/a/25894138/1174054 for details.

Upvotes: 4

Related Questions