问题
I've set up a simple jersey server like this:
ResourceConfig rc = new ResourceConfig().packages("com.example.jersey_test/services");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(API_URI), rc);
And I have a bean that simply throws an exception:
@Path("persons")
public class PersonService {
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getPersons() {
java.util.logging.Logger.getGlobal().log(Level.INFO, "test");
throw new RuntimeException("test");
}
}
The log output is the following (so logging works, but the exception is not logged):
Jul 01, 2014 10:19:33 PM com.example.jersey_test.services.PersonService getPersons
INFO: test
The response is a 500 with looks like the following (so the stacktrace is not included):
As this answer states, grizzly should be using the default logging API. What am I doing wrong?
回答1:
The exception doesn't come to Grizzly, it's getting processed by Jersey. Grizzly has no information about the error other than provided by Jersey via:
Response.sendError(int code, String description)
where Jersey passes (500, "Request failed.")
回答2:
There is a way to start a grizzly server that both logs and prints out exceptions in the response:
HttpServer server =
GrizzlyWebContainerFactory.create(getBaseURI(),
Collections.singletonMap("javax.ws.rs.Application",
"class.that.extends.ResourceConfig"));
来源:https://stackoverflow.com/questions/24518607/grizzly-does-not-log-exceptions-in-requests