在Jersey发生500台服务器错误时,如何获取堆栈跟踪? [英] How can I get the stack trace when 500 server error happens in Jersey?

查看:173
本文介绍了在Jersey发生500台服务器错误时,如何获取堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jersey服务器中,我遇到服务器500错误:

When in jersey server I have server 500 error:

  • 服务器响应中没有堆栈跟踪或某些信息.

  • In server response don´t have stack trace or some info.

在Eclipse控制台中没有异常堆栈跟踪

In Eclipse console don´t have exception stack trace

我尝试在服务器中捕获异常并在控制台中打印跟踪,但是什么也没发生

I try to catch exception in server and print trace in console, but nothing happens

发生500台服务器错误时如何获取堆栈跟踪?

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

推荐答案

在大多数情况下,通用ExceptionMapper可以解决问题.

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();
    }
}

然后只需注册

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

有时,如果未映射该异常,则该异常将被Jersey吞噬,并且您将看不到发生了什么.当问题在泽西岛级别时,通常可以使用.

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.

这篇关于在Jersey发生500台服务器错误时,如何获取堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆