How can I get the stack trace when 500 server error happens in Jersey?

◇◆丶佛笑我妖孽 提交于 2019-11-29 17:45:54

Most of the time, a generic ExceptionMapper will do the trick.

@Provider
public class DebugMapper implements ExceptionMapper<Throwable> {
    @Override
    public Response toResponse(Throwable t) {
        t.printStackTrace()
        return Response.serverError()
            .entity(t.getMessage())
            .build();
    }
}

Then just register it

ResourceConfig config = new ResourceConfig()
        .register(DebugMapper.class);

Sometime the exception will get swallowed by Jersey when the exception is not mapped, and you will not see what happened. This usually works, when the problem is at the Jersey level.

See also:

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