【问题标题】:WebApplicationException is not showing the error messageWebApplicationException 未显示错误消息
【发布时间】:2017-08-30 15:16:29
【问题描述】:

我通过扩展 jax-rs api 的 WebApplicationException 类创建了我的自定义异常类。我在错误的输入上抛出这个异常。

public class RestException extends WebApplicationException {

    public RestException(String message, Response.Status status) {
        super(message, status);
    }


}

当我在我的应用程序中使用上述异常时,它正确返回了状态码,但没有返回我在构造函数中设置的错误消息。

如果我使用 jersey 而不是 cxf,它会同时显示错误消息和状态代码。对此有任何帮助....

【问题讨论】:

    标签: jax-rs cxf


    【解决方案1】:

    我通过改变 RestException 构造函数的签名来解决这个问题,如下所示。

    public class RestException extends WebApplicationException {
    
        public RestException(String message, Response.Status status) {
            super(Response.status(status).entity(message).type(MediaType.TEXT_PLAIN).build());
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-29
      • 2018-10-02
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 2020-06-20
      相关资源
      最近更新 更多