4

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

grizzly 500 error

As this answer states, grizzly should be using the default logging API. What am I doing wrong?

Community
  • 1
  • 1
Yogu
  • 9,165
  • 5
  • 37
  • 58

2 Answers2

3

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.")

alexey
  • 1,959
  • 10
  • 9
  • 1
    Thank you, that confirms what I guessed from looking at the code. I now registered an exception mapper which logs the exception – Yogu Jul 10 '14 at 07:32
-1

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"));
Yogu
  • 9,165
  • 5
  • 37
  • 58