Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Exceptions thrown by REST endpoints get swallowed #170

Open
tomq42 opened this issue Jul 27, 2016 · 5 comments
Open

Exceptions thrown by REST endpoints get swallowed #170

tomq42 opened this issue Jul 27, 2016 · 5 comments

Comments

@tomq42
Copy link

tomq42 commented Jul 27, 2016

If your rest api method throws an exception, it gets swallowed and you get a bunch of other exceptions reported instead. I don't know whose fault this it, whether the cause lies in jersey, or here. I'd be surprised if "plain" jersey had this problem (though I haven't tried it).

On the console, I get:
2016-07-27 08:45:52.674:WARN:oejs.ServletHandler:qtp10883620-29: /services/test
java.lang.IllegalStateException: Committed
at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1243)
at javax.servlet.ServletResponseWrapper.resetBuffer(ServletResponseWrapper.java:195)
at org.apache.felix.http.base.internal.dispatch.ServletResponseWrapper.sendError(ServletResponseWrapper.java:67)
at org.apache.felix.http.base.internal.dispatch.ServletResponseWrapper.sendError(ServletResponseWrapper.java:61)
at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:133)
at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:61)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Unknown Source)
2016-07-27 08:45:52.674:WARN:oejs.HttpChannel:qtp10883620-29: /services/test
java.lang.IllegalStateException: Committed
at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1243)
at javax.servlet.ServletResponseWrapper.resetBuffer(ServletResponseWrapper.java:195)
at org.apache.felix.http.base.internal.dispatch.ServletResponseWrapper.sendError(ServletResponseWrapper.java:67)
at org.apache.felix.http.base.internal.dispatch.ServletResponseWrapper.sendError(ServletResponseWrapper.java:61)
at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:133)
at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:61)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Unknown Source)
2016-07-27 08:45:52.675:WARN:oejs.HttpChannel:qtp10883620-29: Could not send response error 500: java.lang.IllegalStateException: Committed

@jeromebridge
Copy link

Anyone else having this issue or have a workaround for it?

@BryanHunt
Copy link
Collaborator

I use the following:

try
{
  ...
}
catch (Exception e)
{
  log(LogService.LOG_ERROR, "Unexpected exception", e);
  throw new InternalServerErrorException(e);
}

@jeromebridge
Copy link

@BryanHunt Where did you put that? I'm not even sure where the exception is being thrown. It doesn't appear to be coming from any of my code.

@BryanHunt
Copy link
Collaborator

That's how all of my REST endpoints look ...

@POST
public Response handlePost()
{
  try
  {
    ...
  }
  catch (Exception e)
  {
    log(LogService.LOG_ERROR, "Unexpected exception", e);
    throw new InternalServerErrorException(e);
  }
}

@sdempsay
Copy link

Take a look at org.glassfish.jersey.spi.ExtendedExceptionMapper

I made an OSGi service that implements it, and then in

public Response toResponse(final Throwable throwable)

I can both log it to the OSGi logger as well as reformat the response in the web browser to something useful for debugging.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants