Interesting... I turned on stream caching (thank you, Doug!) and there are two differences:
- I can find the text from the response body that I was expecting, but only if I remove the first parameter to the handler method and just accept Exchange. If I leave it as was,... - I get an exception thrown because the message body can't be converted from org.apache.camel.converter.stream.InputStreamCache to javax.ws.rs.core.Response > -----Original Message----- > From: Doug Douglass [mailto:douglass.d...@gmail.com] > Sent: Tuesday, October 25, 2016 1:15 PM > To: users@camel.apache.org > Subject: Re: Trouble accessing Response body content from RESTful call > > I can't say where the response body is being consumed, but try enabling > stream caching[1] and see what you get. > > Doug > > [1] http://camel.apache.org/stream-caching.html > > On Tue, Oct 25, 2016 at 9:31 AM, Steve Huston <shus...@riverace.com> > wrote: > > > I am developing a route that calls a web service; said web service > > returns a JSON string (Not always the same type represented). I have > > this in a route as: > > > > from(myqueue) > > .bean(SetupCxfRequest.class) // This sets up parameters for > > REST API call > > .convertBodyTo(org.apache.cxf.message.MessageContentsList.class) > > .to("cxfrs:bean:ws?throwExceptionOnFailure=false") > > .bean(WebServiceResponse.class) > > > > SetupCxfRequest will: > > exchange.setPattern(ExchangePattern.InOut); > > // Indicate using Proxy API. > > in.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, > > Boolean.FALSE); > > in.setHeader(CxfConstants.OPERATION_NAME, > > VerifyEmployeeRequest); > > > > The web service interface method for the call in question is: > > @GET > > @Path(value="/authentication/{company}/employees/{id}") > > @Produces({ MediaType.APPLICATION_JSON }) > > public Response VerifyEmployeeRequest(@PathParam("company") > String > > scac, > > @PathParam("id") String id, > > @QueryParam("pin") String pin, > > @QueryParam("reason") String > > reason); > > > > The case I'm working now is that the web service is called and it > > returns a 404 status with a body of JSON-marshaled stuff I need to get at. > > From my route above, WebServiceResponse is then called as: > > > > public class WebServiceResponse { > > > > @Handler > > public Object convertWebServiceResponse(Response wsResponse, > > Exchange exchange) throws IOException { ObjectMapper unmarshaller = > > new ObjectMapper(); > > Class<?> target = null; > > Message in = exchange.getIn(); > > int opStatus = wsResponse.getStatus(); > > if (opStatus == 200) > > target = EmployeeVerificationResponseAccept.class; > > else > > target = > > EmployeeVerificationResponseDeny.class; > > > > So far, so good - opStatus is 404. I need to get the string which is > > the response body and then unmarshall it. > > wsResponse.entity is a SequenceInputStream and one of the input > > streams appears to be the string I'm expecting from the web service; > > however, it has been completely consumed (length and position are the > > same). Where did it go, and how can I get it? > > > > Thanks, > > -Steve > > > >