hstaudacher / osgi-jax-rs-connector

An OSGi - JAX-RS 2.0 Connector, software repository available on the link below
http://hstaudacher.github.io/osgi-jax-rs-connector
Other
190 stars 98 forks source link

Exceptions thrown by REST endpoints get swallowed #170

Open tomq42 opened 7 years ago

tomq42 commented 7 years ago

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 commented 7 years ago

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

BryanHunt commented 7 years ago

I use the following:

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

@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 commented 7 years ago

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 commented 7 years ago

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.