You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2014/05/01 17:52:07 UTC
Re: rsClient: successfully invoking REST service, but where is the
response?
Hi
This is the CxfRsproducer code I see may be related:
// set response
if (exchange.getPattern().isOutCapable()) {
LOG.trace("Response body = {}", response);
exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
exchange.getOut().setBody(binding.bindResponseToCamelBody(response,
exchange));
exchange.getOut().getHeaders().putAll(binding.bindResponseHeadersToCamelHeaders(response,
exchange));
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE,
statesCode);
}
Does it help ?
Cheers, Sergey
On 30/04/14 21:57, jarlyons wrote:
> I've been trying everything I can think of to successfully invoke a remote
> REST service and capture the response purely within a spring camel file.
>
> I've got a setup that appears to do everything I need, but for the life of
> me I can't figure out how to capture the response.
>
> On top of it all, by setting the loggingFeatureEnabled="true" in the
> rsClient, I can see the service response printed to standard out, but the
> archive file it writes to disk is empty.
>
> Does anyone have any suggestions?
>
> ------------------------------------------------------------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans
> xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:cxf="http://camel.apache.org/schema/cxf"
> xsi:schemaLocation=" http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
> http://camel.apache.org/schema/cxf
> http://camel.apache.org/schema/cxf/camel-cxf.xsd
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd">
>
>
> <cxf:rsClient id="rsClient"
> address="http://xxx.xxx.xxx:8080/foo/rest/bar/verify"
> serviceClass="Foo.Bar.TestReply"
> loggingFeatureEnabled="true" username=user" password="pwd">
> </cxf:rsClient>
>
> <camelContext id="integrationTesting"
> xmlns="http://camel.apache.org/schema/spring">
>
> <dataFormats>
> <json id="gson" library="Gson"
> unmarshalTypeName="Foo.Bar.Test"/>
> <json id="gsonResponse" library="Gson"
> unmarshalTypeName="Foo.Bar.TestReply"/>
> </dataFormats>
>
> <route>
> <from uri="direct:httpAPI"/>
> <inOut uri="cxfrs://bean://rsClient"/>
> <bean ref="debugExchange" method="process"/>
>
> </route>
>
> <route>
> <from
> uri="timer://gsonUsingHttpAPI?fixedRate=true&period=120000&repeatCount=1"/>
> <transform>
> <simple>{"param1" : 29,"param2" : 13,"param3" : "02","param4"
> : "1234"}</simple>
> </transform>
> <setHeader headerName="CamelHttpMethod">
> <constant>PUT</constant>
> </setHeader>
> <setHeader headerName="Content-Type">
> <constant>application/json</constant>
> </setHeader>
> <to uri="direct:httpAPI"/>
> </route>
>
> </camelContext>
>
> <bean id="debugExchange"
> class="Tideworks.GateVision.camel.PrintBodyProcessor"/>
>
> </beans>
>
> ---------------------------------------------------------------------------------------------------------------
>
> Here is the output ......
>
>
> invoke_junit:
> [echo] JVM arguments: -Dgms.server=172.16.66.44
> [junit] Running Tideworks.GateVision.KioskHandler.NoOpTest
> [junit] Apr 30, 2014 1:42:04 PM org.apache.cxf.jaxrs.utils.ResourceUtils
> checkMethodDispatcher
> [junit] WARNING: No resource methods have been found for resource class
> Tideworks.GateVision.VanguardTestReply
> [junit] Apr 30, 2014 1:42:06 PM
> org.apache.cxf.interceptor.LoggingOutInterceptor
> [junit] INFO: Outbound Message
> [junit] ---------------------------
> [junit] ID: 1
> [junit] Address: http://xxx.xxx.xxx:8080/foo/rest/bar/verify
> [junit] Http-Method: PUT
> [junit] Content-Type: application/json
> [junit] Headers: {firedTime=[Wed Apr 30 13:42:05 PDT 2014],
> Content-Type=[application/json],
> breadcrumbId=[ID-lyons-ubuntu-53546-1398890523707-0-1],
> org.apache.cxf.request.method=[PUT], Authorization=[Basic
> R01TVVNFUjpnbXN0ZXN0], Accept=[*/*]}
> [junit] Payload: {"param1" : 29,"param2" : 13,"param3" : "02","param4" :
> "1234"}
> [junit] --------------------------------------
> [junit] EXCHANGE IN: message: Exchange[Message:
> {"returnCode":1,"beforeData":null,"afterData":null,"messageStack":[],"tooManyRowsChoices":null,"returnMessage":null,"messageStackSize":0}]
> [junit] Apr 30, 2014 1:42:07 PM
> org.apache.cxf.interceptor.LoggingInInterceptor
> [junit] INFO: Inbound Message
> [junit] ----------------------------
> [junit] ID: 1
> [junit] Response-Code: 200
> [junit] Encoding: ISO-8859-1
> [junit] Content-Type: application/json
> [junit] Headers: {content-type=[application/json], Date=[Wed, 30 Apr
> 2014 20:41:24 GMT], Server=[Apache-Coyote/1.1],
> Set-Cookie=[JSESSIONID=97086BE1BE4A61D4819D5811492DC590; Path=/Regatta/;
> HttpOnly], transfer-encoding=[chunked]}
> [junit] Payload:
> {"returnCode":1,"beforeData":null,"afterData":null,"messageStack":[],"tooManyRowsChoices":null,"returnMessage":null,"messageStackSize":0}
> [junit] --------------------------------------
> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 6.688 sec
> [junitreport] Processing /home/jar/---------
> ---/junit_results/TESTS-TestSuites.xml to /tmp/null15503331
> [junitreport] Loading stylesheet
> jar:file:/usr/share/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
> [junitreport] Transform time: 1173ms
> [junitreport] Deleting: /tmp/null15503331
> [echo] All tests complete ... review results in ./build/junit_results
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/rsClient-successfully-invoking-REST-service-but-where-is-the-response-tp5750734.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: rsClient: successfully invoking REST service, but where is the
response?
Posted by Sergey Beryozkin <sb...@gmail.com>.
I've opened
https://issues.apache.org/jira/browse/CAMEL-7408
and will try to create a patch
Cheers, Sergey
On 02/05/14 12:01, Sergey Beryozkin wrote:
> Hi, please see comments below
> On 01/05/14 21:14, jarlyons wrote:
>> Sergey,
>>
>> Thank you for taking the time to respond.
>>
>> I'm not sure I understand your response.
>>
>> Again, my goal is to put together a series of camel routes that wire up a
>> complete RESTful interaction with a remote web service, without
>> writing any
>> additional camel application code.
>>
>> The web service is out of my control, but I have been able to
>> successfully
>> generate a request using JSON, authenticate and submit the request via
>> rsClient, and apparently receive the reply all within my standalone
>> client
>> application.
>>
>> I say apparently because I when I set the rsClient
>> loggingFeatureEnabled="true", and the endpoint as "inOut", I can see the
>> expected reply printed out in my client console.
>>
>> My expectation was that I submit a message with a JSON body (request),
>> and
>> the reply is also a message with a JSON body.
>>
>> Again, the following routes seem to generate a full and correct
>> request/response with the remote service .......
>>
>> ---------------------------------------------------------------------------------------------------------------------------------------------------
>>
>>
>> <cxf:rsClient id="rsClient"
>> address="http://xxx.xxx.xxx:8080/Regatta/rest/autoGate/verify"
>> serviceClass="Tideworks.GateVision.VanguardTest"
>> loggingFeatureEnabled="true" username="xxxxx"
>> password="xxxxx">
>> </cxf:rsClient>
>>
>> <camelContext id="integrationTesting"
>> xmlns="http://camel.apache.org/schema/spring">
>>
>> <jmxAgent id="agent" disabled="false"
>> registryPort="1098"
>> createConnector="true"/>
>>
>> <dataFormats>
>> <json id="gson" library="Gson"
>> unmarshalTypeName="Tideworks.GateVision.VanguardTest"/>
>> <json id="gsonResponse" library="Gson"
>> unmarshalTypeName="Tideworks.GateVision.VanguardTestReply"/>
>> </dataFormats>
>>
>> <route>
>> <from uri="direct:httpAPI"/>
>> <inOut uri="cxfrs://bean://rsClient"/>
>> </route>
>>
>> <route>
>> <from
>> uri="timer://gsonUsingHttpAPI?fixedRate=true&period=10000"/>
>> <transform>
>> <simple>{"ocrPrefillGkey" : 29,"gatePrefillGkey" :
>> 13,"laneId" : "02","truckRfidNbr" : "1234"}</simple>
>> </transform>
>> <setHeader headerName="CamelHttpMethod">
>> <constant>PUT</constant>
>> </setHeader>
>> <setHeader headerName="Content-Type">
>> <constant>application/json</constant>
>> </setHeader>
>> <to uri="direct:httpAPI"/>
>> </route>
>>
>> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>
>>
>> CONSOLE OUTPUT .......................... note the payload in the
>> response
>> .... that is what I was expecting .....
>>
>> May 01, 2014 1:06:01 PM org.apache.cxf.interceptor.LoggingOutInterceptor
>> INFO: Outbound Message
>> ---------------------------
>> ID: 1
>> Address: http://xxx.xxx.xxx:8080/Regatta/rest/autoGate/verify
>> Http-Method: PUT
>> Content-Type: application/json
>> Headers: {org.apache.cxf.request.method=[PUT],
>> breadcrumbId=[ID-lyons-ubuntu-53976-1398974759338-0-1],
>> Content-Type=[application/json], firedTime=[Thu May 01 13:06:01 PDT
>> 2014],
>> Authorization=[Basic xxxxxxxxxxxx], Accept=[*/*]}
>> Payload: {"ocrPrefillGkey" : 29,"gatePrefillGkey" : 13,"laneId" :
>> "02","truckRfidNbr" : "1234"}
>> --------------------------------------
>> May 01, 2014 1:06:02 PM org.apache.cxf.interceptor.LoggingInInterceptor
>> INFO: Inbound Message
>> ----------------------------
>> ID: 1
>> Response-Code: 200
>> Encoding: ISO-8859-1
>> Content-Type: application/json
>> Headers: {content-type=[application/json], Date=[Thu, 01 May 2014
>> 20:05:20
>> GMT], Server=[Apache-Coyote/1.1],
>> Set-Cookie=[JSESSIONID=81EC7C975A0E8CE4306602758A7A30F3; Path=/Regatta/;
>> HttpOnly], transfer-encoding=[chunked]}
>> Payload:
>> {"returnCode":1,"beforeData":null,"afterData":null,"messageStack":[],"tooManyRowsChoices":null,"returnMessage":null,"messageStackSize":0}
>>
>>
>> --------------------------------------
>>
>>
>> So, I simply want to be able to get that payload, run it through a camel
>> <unmarshall> into its' native Object , and hand that back to the
>> requestor.
>>
>> I was hoping my final route would look something like .....
>>
>> <route>
>> <from uri="direct:httpAPI"/>
>> <inOut uri="cxfrs://bean://rsClient"/>
>> <unmarshall ref="gsonResponse" />
>> </route>
>
> I think the reason this does not work right now is that CXF RS producer
> puts a JAX-RS Response, as opposed to the entity stream (which is
> probably what is expected by GSON unmarshaller).
>
> The following will probably do:
>
> <route>
> <from uri="direct:httpAPI"/>
> <inOut uri="cxfrs://bean://rsClient"/>
> <!--
> Convert the body from Response to Entity
> stream,
>
> Response.readEntity(InputStream.class)
> or
> Response.getEntity()
> -->
> <unmarshall ref="gsonResponse" />
> </route>
>
> Other HTTP components can probably do better right now as far the
> simplicity of converting the response is concerned.
>
> In meantime, I wonder if we can enhance a bit CXFRsProducer
> SimpleBinding only to keep the backward compatibility intact...
>
> Raul and Willem, do you agree it can make sense do update CXFRS
> SimpleBinding to put Response.getEntity() instead of Response ?
> Or may be do it optionally for the default & simple binding if the
> property is set, such as "unwrapResponse" ?
>
> Cheers, Sergey
>
>
>
>>
>> Again, thanks for taking a look at this.
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/rsClient-successfully-invoking-REST-service-but-where-is-the-response-tp5750734p5750757.html
>>
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
Re: rsClient: successfully invoking REST service, but where is the
response?
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi, please see comments below
On 01/05/14 21:14, jarlyons wrote:
> Sergey,
>
> Thank you for taking the time to respond.
>
> I'm not sure I understand your response.
>
> Again, my goal is to put together a series of camel routes that wire up a
> complete RESTful interaction with a remote web service, without writing any
> additional camel application code.
>
> The web service is out of my control, but I have been able to successfully
> generate a request using JSON, authenticate and submit the request via
> rsClient, and apparently receive the reply all within my standalone client
> application.
>
> I say apparently because I when I set the rsClient
> loggingFeatureEnabled="true", and the endpoint as "inOut", I can see the
> expected reply printed out in my client console.
>
> My expectation was that I submit a message with a JSON body (request), and
> the reply is also a message with a JSON body.
>
> Again, the following routes seem to generate a full and correct
> request/response with the remote service .......
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------
>
> <cxf:rsClient id="rsClient"
> address="http://xxx.xxx.xxx:8080/Regatta/rest/autoGate/verify"
> serviceClass="Tideworks.GateVision.VanguardTest"
> loggingFeatureEnabled="true" username="xxxxx"
> password="xxxxx">
> </cxf:rsClient>
>
> <camelContext id="integrationTesting"
> xmlns="http://camel.apache.org/schema/spring">
>
> <jmxAgent id="agent" disabled="false" registryPort="1098"
> createConnector="true"/>
>
> <dataFormats>
> <json id="gson" library="Gson"
> unmarshalTypeName="Tideworks.GateVision.VanguardTest"/>
> <json id="gsonResponse" library="Gson"
> unmarshalTypeName="Tideworks.GateVision.VanguardTestReply"/>
> </dataFormats>
>
> <route>
> <from uri="direct:httpAPI"/>
> <inOut uri="cxfrs://bean://rsClient"/>
> </route>
>
> <route>
> <from
> uri="timer://gsonUsingHttpAPI?fixedRate=true&period=10000"/>
> <transform>
> <simple>{"ocrPrefillGkey" : 29,"gatePrefillGkey" :
> 13,"laneId" : "02","truckRfidNbr" : "1234"}</simple>
> </transform>
> <setHeader headerName="CamelHttpMethod">
> <constant>PUT</constant>
> </setHeader>
> <setHeader headerName="Content-Type">
> <constant>application/json</constant>
> </setHeader>
> <to uri="direct:httpAPI"/>
> </route>
>
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> CONSOLE OUTPUT .......................... note the payload in the response
> .... that is what I was expecting .....
>
> May 01, 2014 1:06:01 PM org.apache.cxf.interceptor.LoggingOutInterceptor
> INFO: Outbound Message
> ---------------------------
> ID: 1
> Address: http://xxx.xxx.xxx:8080/Regatta/rest/autoGate/verify
> Http-Method: PUT
> Content-Type: application/json
> Headers: {org.apache.cxf.request.method=[PUT],
> breadcrumbId=[ID-lyons-ubuntu-53976-1398974759338-0-1],
> Content-Type=[application/json], firedTime=[Thu May 01 13:06:01 PDT 2014],
> Authorization=[Basic xxxxxxxxxxxx], Accept=[*/*]}
> Payload: {"ocrPrefillGkey" : 29,"gatePrefillGkey" : 13,"laneId" :
> "02","truckRfidNbr" : "1234"}
> --------------------------------------
> May 01, 2014 1:06:02 PM org.apache.cxf.interceptor.LoggingInInterceptor
> INFO: Inbound Message
> ----------------------------
> ID: 1
> Response-Code: 200
> Encoding: ISO-8859-1
> Content-Type: application/json
> Headers: {content-type=[application/json], Date=[Thu, 01 May 2014 20:05:20
> GMT], Server=[Apache-Coyote/1.1],
> Set-Cookie=[JSESSIONID=81EC7C975A0E8CE4306602758A7A30F3; Path=/Regatta/;
> HttpOnly], transfer-encoding=[chunked]}
> Payload:
> {"returnCode":1,"beforeData":null,"afterData":null,"messageStack":[],"tooManyRowsChoices":null,"returnMessage":null,"messageStackSize":0}
>
> --------------------------------------
>
>
> So, I simply want to be able to get that payload, run it through a camel
> <unmarshall> into its' native Object , and hand that back to the requestor.
>
> I was hoping my final route would look something like .....
>
> <route>
> <from uri="direct:httpAPI"/>
> <inOut uri="cxfrs://bean://rsClient"/>
> <unmarshall ref="gsonResponse" />
> </route>
I think the reason this does not work right now is that CXF RS producer
puts a JAX-RS Response, as opposed to the entity stream (which is
probably what is expected by GSON unmarshaller).
The following will probably do:
<route>
<from uri="direct:httpAPI"/>
<inOut uri="cxfrs://bean://rsClient"/>
<!--
Convert the body from Response to Entity
stream,
Response.readEntity(InputStream.class)
or
Response.getEntity()
-->
<unmarshall ref="gsonResponse" />
</route>
Other HTTP components can probably do better right now as far the
simplicity of converting the response is concerned.
In meantime, I wonder if we can enhance a bit CXFRsProducer
SimpleBinding only to keep the backward compatibility intact...
Raul and Willem, do you agree it can make sense do update CXFRS
SimpleBinding to put Response.getEntity() instead of Response ?
Or may be do it optionally for the default & simple binding if the
property is set, such as "unwrapResponse" ?
Cheers, Sergey
>
> Again, thanks for taking a look at this.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/rsClient-successfully-invoking-REST-service-but-where-is-the-response-tp5750734p5750757.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: rsClient: successfully invoking REST service, but where is the
response?
Posted by jarlyons <ja...@gmail.com>.
Sergey,
Thank you for taking the time to respond.
I'm not sure I understand your response.
Again, my goal is to put together a series of camel routes that wire up a
complete RESTful interaction with a remote web service, without writing any
additional camel application code.
The web service is out of my control, but I have been able to successfully
generate a request using JSON, authenticate and submit the request via
rsClient, and apparently receive the reply all within my standalone client
application.
I say apparently because I when I set the rsClient
loggingFeatureEnabled="true", and the endpoint as "inOut", I can see the
expected reply printed out in my client console.
My expectation was that I submit a message with a JSON body (request), and
the reply is also a message with a JSON body.
Again, the following routes seem to generate a full and correct
request/response with the remote service .......
---------------------------------------------------------------------------------------------------------------------------------------------------
<cxf:rsClient id="rsClient"
address="http://xxx.xxx.xxx:8080/Regatta/rest/autoGate/verify"
serviceClass="Tideworks.GateVision.VanguardTest"
loggingFeatureEnabled="true" username="xxxxx"
password="xxxxx">
</cxf:rsClient>
<camelContext id="integrationTesting"
xmlns="http://camel.apache.org/schema/spring">
<jmxAgent id="agent" disabled="false" registryPort="1098"
createConnector="true"/>
<dataFormats>
<json id="gson" library="Gson"
unmarshalTypeName="Tideworks.GateVision.VanguardTest"/>
<json id="gsonResponse" library="Gson"
unmarshalTypeName="Tideworks.GateVision.VanguardTestReply"/>
</dataFormats>
<route>
<from uri="direct:httpAPI"/>
<inOut uri="cxfrs://bean://rsClient"/>
</route>
<route>
<from
uri="timer://gsonUsingHttpAPI?fixedRate=true&period=10000"/>
<transform>
<simple>{"ocrPrefillGkey" : 29,"gatePrefillGkey" :
13,"laneId" : "02","truckRfidNbr" : "1234"}</simple>
</transform>
<setHeader headerName="CamelHttpMethod">
<constant>PUT</constant>
</setHeader>
<setHeader headerName="Content-Type">
<constant>application/json</constant>
</setHeader>
<to uri="direct:httpAPI"/>
</route>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONSOLE OUTPUT .......................... note the payload in the response
.... that is what I was expecting .....
May 01, 2014 1:06:01 PM org.apache.cxf.interceptor.LoggingOutInterceptor
INFO: Outbound Message
---------------------------
ID: 1
Address: http://xxx.xxx.xxx:8080/Regatta/rest/autoGate/verify
Http-Method: PUT
Content-Type: application/json
Headers: {org.apache.cxf.request.method=[PUT],
breadcrumbId=[ID-lyons-ubuntu-53976-1398974759338-0-1],
Content-Type=[application/json], firedTime=[Thu May 01 13:06:01 PDT 2014],
Authorization=[Basic xxxxxxxxxxxx], Accept=[*/*]}
Payload: {"ocrPrefillGkey" : 29,"gatePrefillGkey" : 13,"laneId" :
"02","truckRfidNbr" : "1234"}
--------------------------------------
May 01, 2014 1:06:02 PM org.apache.cxf.interceptor.LoggingInInterceptor
INFO: Inbound Message
----------------------------
ID: 1
Response-Code: 200
Encoding: ISO-8859-1
Content-Type: application/json
Headers: {content-type=[application/json], Date=[Thu, 01 May 2014 20:05:20
GMT], Server=[Apache-Coyote/1.1],
Set-Cookie=[JSESSIONID=81EC7C975A0E8CE4306602758A7A30F3; Path=/Regatta/;
HttpOnly], transfer-encoding=[chunked]}
Payload:
{"returnCode":1,"beforeData":null,"afterData":null,"messageStack":[],"tooManyRowsChoices":null,"returnMessage":null,"messageStackSize":0}
--------------------------------------
So, I simply want to be able to get that payload, run it through a camel
<unmarshall> into its' native Object , and hand that back to the requestor.
I was hoping my final route would look something like .....
<route>
<from uri="direct:httpAPI"/>
<inOut uri="cxfrs://bean://rsClient"/>
<unmarshall ref="gsonResponse" />
</route>
Again, thanks for taking a look at this.
--
View this message in context: http://camel.465427.n5.nabble.com/rsClient-successfully-invoking-REST-service-but-where-is-the-response-tp5750734p5750757.html
Sent from the Camel - Users mailing list archive at Nabble.com.