Reputation: 1
in camel route I am accessing a rest service. For invalid input I am getting below json response with 400 response code. But I cannot access the payload. Even it is not reflecting in camel body. Please help to give a solution that how to access the rest payload when response code is other than 200.
This below chunk is the route containing cxfrs:bean. I am trying to handle the exception in dotry block and then try to retrieve the response payload in processor. But payload is not accessible.
<route id="_route3" streamCache="true">
<from id="_from2" uri="direct:togetcustomercategorybackend"/>
<doTry id="_doTry1">
<to id="_to3" uri="cxfrs:bean:DsGetCustomerCategoryBackEndUrl"/>
<doCatch id="_doCatch1">
<exception>java.lang.Exception</exception>
<process ref="ResponseHandler" />
</doCatch>
</doTry>
</route>
This is response from rest client. Please note the payload from backend with response code 400
ID: 923
Response-Code: 400
Encoding: UTF-8
Content-Type: application/json; charset=utf-8
Headers: {connection=[keep-alive], Content-Length=[98],
content-type=[application/json; charset=utf-8],Date=[Mon, 16 Dec 2019 17:19:04 GMT],
Server=[Kestrel]}
Payload: {"error":{"errorcode":"inv.offertype","errormessage":"Invalid offertype
provided","errorinfo":""}}
Passing the request parameters using query params:
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
public interface DSGetCustomerCategoryApi {
@GET
@Produces(MediaType.APPLICATION_JSON)
public String DSGetCustomerCategory(
@QueryParam("OfferType") String OfferType,
@QueryParam("MSISDN") String MSISDN ,
@QueryParam("IdType") String IdType ,
@QueryParam("IdNumber") String IdNumber ,
@QueryParam("BillAverage") Double BillAverage );
}
Upvotes: 0
Views: 577
Reputation: 21
when response code is other than 200 this means you got an exception and to get the exception body in your payload below example may help:
public String getException(Exception exception) {
return exception.getMessage();
}
Upvotes: 1