如何在Jersey服务器中映射Null Pointer Exception

时间:2014-08-19 20:01:18

标签: java rest java-ee jersey jersey-client

我有泽西客户端和球衣服务器。 对于自定义异常,我创建了一个实现的提供程序类 avax.ws.rs.ext.ExceptionMapper,我回复了

ErrorResponse errorResponse = new ErrorResponse();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).type(
            MediaType.APPLICATION_XML).build();

现在在客户端我正在做如下

if (response.getStatus() == Status.OK.getStatusCode()) {

    CustomeResponse cresponse = response
                    .getEntity(CustomeResponse.class);
}else{
ErrorResponse errorResponse = response
                    .getEntity(ErrorResponse.class);
throw new CustomException(errorResponse.getErrorMessage(),
                    errorResponse.getErrorCode());

}

但是每当我的服务器有空指针异常时,我在客户端

中得到以下异常
Aug 19, 2014 12:03:37 PM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: A message body reader for Java class com.custom.exception.ErrorResponse, and Java type class com.custom.exception.ErrorResponse, and MIME media type text/html; charset=utf-8 was not found
Aug 19, 2014 12:03:37 PM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: The registered message body readers compatible with the MIME media type are:
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider

Aug 19, 2014 12:03:37 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException

我可以映射空指针和其他运行时异常,以便在客户端抛出有用的错误代码。 请帮忙并提出建议。

0 个答案:

没有答案