2626import org .apache .camel .component .cxf .common .message .CxfConstants ;
2727import org .apache .camel .component .http .HttpConstants ;
2828import org .apache .camel .component .http .HttpMethods ;
29+ import org .apache .camel .component .jackson .JacksonDataFormat ;
2930import org .apache .camel .http .base .HttpOperationFailedException ;
3031import org .apache .camel .model .dataformat .JsonLibrary ;
3132import org .apache .camel .util .URISupport ;
@@ -53,7 +54,7 @@ public void configure() {
5354 .when (header (HttpConstants .HTTP_METHOD ).isNotNull ())
5455 .marshal ().json (JsonLibrary .Jackson )
5556 .to ("https://api-cpe.sunat.gob.pe" )
56- .convertBodyTo ( ResponseDocumentSuccessDto .class )
57+ .unmarshal ( new JacksonDataFormat ( ResponseDocumentSuccessDto .class ) )
5758 .process (new RestSunatResponseProcessor ())
5859 .endChoice ()
5960 // Otherwise
@@ -73,12 +74,17 @@ public void configure() {
7374 HttpOperationFailedException httpException = exchange .getProperty (Exchange .EXCEPTION_CAUGHT , HttpOperationFailedException .class );
7475 String contentType = httpException .getResponseHeaders ().getOrDefault ("Content-Type" , "" );
7576
77+ boolean isResponseJson = Objects .equals (contentType , "application/json" );
78+ if (isResponseJson ) {
79+ exchange .getIn ().setBody (httpException .getResponseBody ());
80+ }
81+
7682 exchange .getIn ().setHeader ("HttpResponseHeader_ContentType" , contentType );
77- return Objects . equals ( contentType , "application/json" ) ;
83+ return isResponseJson ;
7884 })
7985 .choice ()
8086 .when (header ("HttpResponseHeader_ContentType" ).isEqualTo ("application/json" ))
81- .convertBodyTo ( ResponseDocumentErrorDto .class )
87+ .unmarshal ( new JacksonDataFormat ( ResponseDocumentErrorDto .class ) )
8288 .process (new RestSunatErrorResponseProcessor ())
8389 .endChoice ()
8490 .otherwise ()
@@ -124,7 +130,7 @@ public void configure() {
124130 }
125131 })
126132 .to ("https://api-seguridad.sunat.gob.pe" )
127- .convertBodyTo ( ResponseAccessTokenSuccessDto .class )
133+ .unmarshal ( new JacksonDataFormat ( ResponseAccessTokenSuccessDto .class ) )
128134 .process (exchange -> {
129135 ResponseAccessTokenSuccessDto response = exchange .getIn ().getBody (ResponseAccessTokenSuccessDto .class );
130136 response .setCreated_in (ZonedDateTime .now ());
0 commit comments