【发布时间】:2012-07-28 01:41:51
【问题描述】:
我想在 CXF (2.6.1) 中添加一个 ExceptionMapper,它不仅可以传达响应代码,还可以以有效负载格式发送异常(我现在使用的是 JSON)。
@Provider
public class CustomExceptionMapper
implements
ExceptionMapper<MyException>
{
...
@Override
public Response toResponse(MyException mex)
{
//I need something here which can convert mex object to JSON and ship it in response
// I want this to be de-serialized on client
//the following returns the status code
return Response.status(Response.Status.BAD_REQUEST).build();
}
...
}
有没有办法做到这一点?
【问题讨论】: