2017-11-13 20 views
-1

ExceptionMapperの私の実装は以下のように見える例外を捕捉していない:私のREST APIでジャージーを

@Provider 
public class CaptureUnhandledExceptions implements ExceptionMapper<Throwable> 
{ 
    private static final Logger LOGGER = LogFactory.getLogger(CaptureUnhandledExceptions.class); 

    @Override 
    public Response toResponse(Throwable exception) 
    { 
     LOGGER.error("Unhandled exception", exception); 
     ErrorMessage em = new ErrorMessage(50099, ExceptionUtils.getRootCause(exception).getMessage(), 
       exception.getMessage()); 
     return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(em).build(); 
    } 
} 

、私は私のJSONの体のためのパス誤った値をしようとしていますが、それは次の例外に

Can not deserialize value of type com.abccompany.model.ConnectionEndpoint$Binding from String "RandomValue: value not one of declared Enum instance names: [POST, REDIRECT] 
at [Source: org.glassfish.jersey.me[email protected]3fce79f3; line: 16, column: 28] (through reference chain: com.abccompany.model.SpConnection["connection"]->com.abccompany.model.Connection["connectionendpoints"]->java.util.ArrayList[0]->com.abccompany.model.ConnectionEndpoint["endpointbinding"]) 
を投げています

私は何が欠けていますか?プロバイダをResourceConfigに登録する必要がありますか?

アプリケーション

this.register(com.abccompany.utils.CaptureUnhandledExceptions.class); 
+0

this.register(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJs‌​onProvider.class);を追加しましたあなたのログファイルに「未処理の例外」を見たことがありますか?カスタム例外ハンドラクラスを登録する必要はありません。 – zappee

+0

いいえ...私はちょうど私が何かが欠けていないことを確認するためにそれをした – yogsma

+0

何かが起こるのを見るためにあなたの残りの方法で新しいException( "何かを言う...")を故意に投げてみてください。 – zappee

答えて

0

のResourceConfigのでは修正がResourceConfig