Jersey中的ExceptionMapper抛出mapMappableContainerException

时间:2016-01-27 14:02:14

标签: java rest exception-handling jersey

我创建了一个Rest服务,并希望实现异常处理,但在尝试运行服务时会抛出mapMappableContainerException。你可以在这里找到我的代码。

我的服务:

@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("add")
public Response addJobSeeker() throws MyCustomException{

    throw new MyCustomException("My Exception");    

}

My Exception class。

@Provider
public class MyExceptionMapper extends Exception implements ExceptionMapper<MyCustomException>{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    public MyExceptionMapper(String str){
        super(str);
    }
    @Override
    public Response toResponse(MyCustomException exception) {
        System.out.println("In my exception mapper -- "+exception.getMessage());
        Success sc = new Success(404, "Hello", "I am mukesh");
        return Response.status(404).entity(sc).type(MediaType.APPLICATION_JSON).build();        
    }

}

MyCustomClass

public class MyCustomException extends Exception {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    public MyCustomException(String str){
        super(str);
    }

0 个答案:

没有答案