grizzly does not log Exceptions in requests

情到浓时终转凉″ 提交于 2020-01-01 15:08:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!