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&amp;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.


Reply via email to