You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by GLD <gu...@orange-ftgroup.com> on 2008/11/07 11:27:38 UTC

How to process the response in Camel

Hi all, 

I want to make a  Camel base engine that adapts web services requests and
replies
For example : 
- convert currencies from dollars to euro in both requests and responses
- The client understands Dollars
- The server understands euros.
  
I have the following route
<endpoint id="httpEndpointBackend"
uri="http://myEuropeanServer.com/myservice"/>
<route>
  <from uri="direct:myServletServiceUri" />   <!-- called by a servlet doGt
and doPost methods-->
  <process ref="myProcessor" />
  <to ref="httpEndpointBackend" />
</route>
 
In my servlet, I extract http  headers and body, send them to by endpoint
using
        result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
httpBodyString, exchangeMapHeaders);

With this configuration, I can successfully process the request but I cannot
process the response.
I think it because processors are asynchonous  but my  process is
synchronous.

Is there a way to  either
 - use processors in a synchronous way (like servlet filters chain) 
or
 - define a processor that will be called once the http endpoint receives
its http response


Thanks
Guillaume


-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378039.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How to process the response in Camel

Posted by Willem Jiang <wi...@gmail.com>.
You could use the camel-jetty component to handle the request and send
the response back. Here is a unit test[1] of camel-jetty component to
show that.

[1]
https://svn.apache.org/repos/asf/activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyRouteTest.java

Willem

GLD wrote:
> Hi all, 
> 
> I want to make a  Camel base engine that adapts web services requests and
> replies
> For example : 
> - convert currencies from dollars to euro in both requests and responses
> - The client understands Dollars
> - The server understands euros.
>   
> I have the following route
> <endpoint id="httpEndpointBackend"
> uri="http://myEuropeanServer.com/myservice"/>
> <route>
>   <from uri="direct:myServletServiceUri" />   <!-- called by a servlet doGt
> and doPost methods-->
>   <process ref="myProcessor" />
>   <to ref="httpEndpointBackend" />
> </route>
>  
> In my servlet, I extract http  headers and body, send them to by endpoint
> using
>         result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
> httpBodyString, exchangeMapHeaders);
> 
> With this configuration, I can successfully process the request but I cannot
> process the response.
> I think it because processors are asynchonous  but my  process is
> synchronous.
> 
> Is there a way to  either
>  - use processors in a synchronous way (like servlet filters chain) 
> or
>  - define a processor that will be called once the http endpoint receives
> its http response
> 
> 
> Thanks
> Guillaume
> 
> 


RE: How to process the response in Camel

Posted by GLD <gu...@orange-ftgroup.com>.
Hi, 

Thanks for your fast and helpful support Claus. It really helped me.

This is the solution you give me by mail... and may help someone else :




Claus Ibsen wrote:
> 
> You route looks like something like this
> 
> from("direct:acServletServiceBusinessUri?exchangePattern=InOut")
> .to("xslt:transformPricingService.xsl")
> .to("http://localhost:8088/mockPricingSOAP")
> .to("xslt:transformPricingService.xsl")
> 
> Where the .xsl file is located on the classpath. You can use Spring
> scheme to locate it on the file system instead
> 
> .to("xslt:file://transformPricingService.xsl")
> 
> 
> Where the 2nd xslt transformation might need another file to transform
> the reponse as you want it. However XSLT tends to get complex and hard
> to try and debug. Definitely not a favorite of mine.
> 
> BTW: Camel 1.5.0 has been released. You should consider if possible to
> upgrade.
> 
> 
> So you are nearly there in your route in your spring XML file. You
> need the last xslt processing step. So you need to add a <process
> ref="acXsltProcessor"/> after the HTTP call to SoapUI
> 
> 
> 		<route>
> 			<from uri="direct:acServletServiceBusinessUri?exchangePattern=InOut" />
> 
> 			<process ref="acXsltProcessor" />
> 
>       <!--  preprocessor that specify the POST method in Exchange
> header-->
>       <process ref="acHttpPreProcessor" />
>       <to ref="httpEndpointBackend" />
> 
> <!-- INSERT HERE THE LAST XSLT TRANSFORMATION -->
> <process ref="acXsltProcessor"/>
> <!-- Maybe you need another xsl file to convert it back but you could
> then just ref another processor: myOtherXsltProcessor
> 
> 		</route>
> 
> /Claus
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20476717.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: How to process the response in Camel

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

You can not add the exchange pattern in the URI. (only in the JBI component)

I think we need a clean mail. Could you post the entire route and relevant code. It should really be possible to extract the OUT and return it to the original caller.

PS: In your processor you could also replace the original IN body with the response from the webservice call. Then you can still use a In-Only pattern. 




Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 13:31
To: camel-user@activemq.apache.org
Subject: RE: How to process the response in Camel


Please have a look at my previous reply, I've updated it : I added the
exchange format in the endpoint uri.
There are no changes.
  
May be the method ProducerCache.sendExchange() should be modified  : 
    protected E sendExchange(Endpoint<E> endpoint, Producer<E> producer,
Processor processor, E exchange) throws Exception {
        processor.process(exchange);

        // now lets dispatch
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>>> " + endpoint + " " + exchange);
        }

        >>> GLD : <<< GLD : call defined processor chain in the route up to
the <to>  endpoint
        producer.process(exchange);     

       >>> GLD : reply route processing to insert here??????
        return exchange;
   }   


Guillaume


Claus Ibsen wrote:
> 
> Hi
> 
> Ah there might miss a method for the multiple headers, 
> 
> Do you mind creating a ticket in the bug tracker for this issue. Then I
> will make sure it's added.
> 
> There is a link to the tracker from here:
> http://activemq.apache.org/camel/support.html
> 
> 
> 
> 
I'm off this afternoon.
I will do it next week.

-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20379735.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: How to process the response in Camel

Posted by GLD <gu...@orange-ftgroup.com>.
Please have a look at my previous reply, I've updated it : I added the
exchange format in the endpoint uri.
There are no changes.
  
May be the method ProducerCache.sendExchange() should be modified  : 
    protected E sendExchange(Endpoint<E> endpoint, Producer<E> producer,
Processor processor, E exchange) throws Exception {
        processor.process(exchange);

        // now lets dispatch
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>>> " + endpoint + " " + exchange);
        }

        >>> GLD : <<< GLD : call defined processor chain in the route up to
the <to>  endpoint
        producer.process(exchange);     

       >>> GLD : reply route processing to insert here??????
        return exchange;
   }   


Guillaume


Claus Ibsen wrote:
> 
> Hi
> 
> Ah there might miss a method for the multiple headers, 
> 
> Do you mind creating a ticket in the bug tracker for this issue. Then I
> will make sure it's added.
> 
> There is a link to the tracker from here:
> http://activemq.apache.org/camel/support.html
> 
> 
> 
> 
I'm off this afternoon.
I will do it next week.

-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20379735.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: How to process the response in Camel

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

You can change the MEP pattern at runtime by using this workaround

You can cast to DefaultExchange where there is a setter to set the pattern

DefaultExchange ex = (DefaultExchange) exchange
Ex.setPattern(ExchangePattern.InOut);


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: Claus Ibsen [mailto:ci@silverbullet.dk] 
Sent: 7. november 2008 13:10
To: camel-user@activemq.apache.org
Subject: RE: How to process the response in Camel

Hi

Ah there might miss a method for the multiple headers, 

Do you mind creating a ticket in the bug tracker for this issue. Then I will make sure it's added.

There is a link to the tracker from here:
http://activemq.apache.org/camel/support.html


Is there a sendXXX method that accepts an exchange pattern and also the headers? If there is you can use that on.

Otherwise you can use the generic send(Exchange) where you can create the exchange and set all the stuff manually.

Check out the source code in DefaultProducerTemplate.java that can give you hints as well.




Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 12:35
To: camel-user@activemq.apache.org
Subject: RE: How to process the response in Camel


hi,


Claus Ibsen wrote:
> 
> Hi
> 
> Ah that is a little pitfall with the producerTemplate as it has many
> methods.
> http://activemq.apache.org/camel/producertemplate.html
> 
> You should use sendXXX for IN only message exchange patterns
> You should use requestXXX for IN-OUT message exchange patterns
> 
> So you should use requestBody:
> 
>         result = camelProducerTemplate.requestBodyAndHeaders(endPointUri,
> httpBodyString, exchangeMapHeaders);
> 
> 


The only method requestXXX that exist is with a single hearder (no s at the
end of the method)
   Object requestBodyAndHeader(String endpointUri, Object body, String
header, Object headerValue);

And I want to add all http headers in order to rebuild the same http request
to my "european server".

requestBodyAndHeader calls sendBodyAndHeader. For sendXXX, there are 
   Object sendBodyAndHeader(String endpoint, 
                                         ExchangePattern pattern, 
                                         final Object body, 
                                         final String header,
  and 
    Object sendBodyAndHeaders(String endpointUri, 
                                           final Object body, 
                                           final Map<String, Object>
headers)
   
Using the problem using sendBodyAndHeaders is I cannot set  the
ExchangePattern to InOut.
Your are right, running in debug mode, I see that the exchange pattern
associated to the endpoint is InOnly.
  ==> Is there a way to specify the Exchange pattern in another way (via the
endpoint uri like dataformat?,  pring property)

But I don't know if the problem is here. In my servlet, I am able to process
the Exchange;
getOut() and put it in the httpResponse.getOutputStream() 

            result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
                                                          buff.toString(),
                                                         
exchangeMapHeaders);
            InputStream isResult = (InputStream)result;
            final OutputStream respOs;
            respOs = httpResponse.getOutputStream();  

            while (isResult.available() != 0) {
                final int readByte = isResult.read();
                respOs.write(readByte);
            }


My Problem is that, in that case, I cannot process the response stream. In
my example, the client will receive prices in euros instead of in dollars.

So, I think my problem is to insert a processor to process the reply.!!!




Claus Ibsen wrote:
> 
> 
> What is the content on endPointUri? Do you send it the direct or the http
> endpoint?
> 
endPointUri is tha string that contains "direct:myServletServiceUri"

Guilaume Lundy


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 11:28
To: camel-user@activemq.apache.org
Subject: How to process the response in Camel


Hi all, 

I want to make a  Camel base engine that adapts web services requests and
replies
For example : 
- convert currencies from dollars to euro in both requests and responses
- The client understands Dollars
- The server understands euros.
  
I have the following route
<endpoint id="httpEndpointBackend"
uri="http://myEuropeanServer.com/myservice"/>
<route>
  <from uri="direct:myServletServiceUri" />   <!-- called by a servlet doGt
and doPost methods-->
  <process ref="myProcessor" />
  <to ref="httpEndpointBackend" />
</route>
 
In my servlet, I extract http  headers and body, send them to by endpoint
using
        result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
httpBodyString, exchangeMapHeaders);

With this configuration, I can successfully process the request but I cannot
process the response.
I think it because processors are asynchonous  but my  process is
synchronous.

Is there a way to  either
 - use processors in a synchronous way (like servlet filters chain) 
or
 - define a processor that will be called once the http endpoint receives
its http response


Thanks
Guillaume


-- 
View this message in context:
http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378039.html
Sent from the Camel - Users mailing list archive at Nabble.com.




-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378945.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: How to process the response in Camel

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

If there is still an issue and you don't mind then you could create a .zip of your sample project to let me look into.

Or post the full snippets of the configuration and code so I will be able better to see the "full picture".

The exchange pattern stuff is on the roadmap for Camel 2.0 to be improved. 


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: Claus Ibsen [mailto:ci@silverbullet.dk] 
Sent: 7. november 2008 13:10
To: camel-user@activemq.apache.org
Subject: RE: How to process the response in Camel

Hi

Ah there might miss a method for the multiple headers, 

Do you mind creating a ticket in the bug tracker for this issue. Then I will make sure it's added.

There is a link to the tracker from here:
http://activemq.apache.org/camel/support.html


Is there a sendXXX method that accepts an exchange pattern and also the headers? If there is you can use that on.

Otherwise you can use the generic send(Exchange) where you can create the exchange and set all the stuff manually.

Check out the source code in DefaultProducerTemplate.java that can give you hints as well.




Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 12:35
To: camel-user@activemq.apache.org
Subject: RE: How to process the response in Camel


hi,


Claus Ibsen wrote:
> 
> Hi
> 
> Ah that is a little pitfall with the producerTemplate as it has many
> methods.
> http://activemq.apache.org/camel/producertemplate.html
> 
> You should use sendXXX for IN only message exchange patterns
> You should use requestXXX for IN-OUT message exchange patterns
> 
> So you should use requestBody:
> 
>         result = camelProducerTemplate.requestBodyAndHeaders(endPointUri,
> httpBodyString, exchangeMapHeaders);
> 
> 


The only method requestXXX that exist is with a single hearder (no s at the
end of the method)
   Object requestBodyAndHeader(String endpointUri, Object body, String
header, Object headerValue);

And I want to add all http headers in order to rebuild the same http request
to my "european server".

requestBodyAndHeader calls sendBodyAndHeader. For sendXXX, there are 
   Object sendBodyAndHeader(String endpoint, 
                                         ExchangePattern pattern, 
                                         final Object body, 
                                         final String header,
  and 
    Object sendBodyAndHeaders(String endpointUri, 
                                           final Object body, 
                                           final Map<String, Object>
headers)
   
Using the problem using sendBodyAndHeaders is I cannot set  the
ExchangePattern to InOut.
Your are right, running in debug mode, I see that the exchange pattern
associated to the endpoint is InOnly.
  ==> Is there a way to specify the Exchange pattern in another way (via the
endpoint uri like dataformat?,  pring property)

But I don't know if the problem is here. In my servlet, I am able to process
the Exchange;
getOut() and put it in the httpResponse.getOutputStream() 

            result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
                                                          buff.toString(),
                                                         
exchangeMapHeaders);
            InputStream isResult = (InputStream)result;
            final OutputStream respOs;
            respOs = httpResponse.getOutputStream();  

            while (isResult.available() != 0) {
                final int readByte = isResult.read();
                respOs.write(readByte);
            }


My Problem is that, in that case, I cannot process the response stream. In
my example, the client will receive prices in euros instead of in dollars.

So, I think my problem is to insert a processor to process the reply.!!!




Claus Ibsen wrote:
> 
> 
> What is the content on endPointUri? Do you send it the direct or the http
> endpoint?
> 
endPointUri is tha string that contains "direct:myServletServiceUri"

Guilaume Lundy


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 11:28
To: camel-user@activemq.apache.org
Subject: How to process the response in Camel


Hi all, 

I want to make a  Camel base engine that adapts web services requests and
replies
For example : 
- convert currencies from dollars to euro in both requests and responses
- The client understands Dollars
- The server understands euros.
  
I have the following route
<endpoint id="httpEndpointBackend"
uri="http://myEuropeanServer.com/myservice"/>
<route>
  <from uri="direct:myServletServiceUri" />   <!-- called by a servlet doGt
and doPost methods-->
  <process ref="myProcessor" />
  <to ref="httpEndpointBackend" />
</route>
 
In my servlet, I extract http  headers and body, send them to by endpoint
using
        result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
httpBodyString, exchangeMapHeaders);

With this configuration, I can successfully process the request but I cannot
process the response.
I think it because processors are asynchonous  but my  process is
synchronous.

Is there a way to  either
 - use processors in a synchronous way (like servlet filters chain) 
or
 - define a processor that will be called once the http endpoint receives
its http response


Thanks
Guillaume


-- 
View this message in context:
http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378039.html
Sent from the Camel - Users mailing list archive at Nabble.com.




-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378945.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: How to process the response in Camel

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

Ah there might miss a method for the multiple headers, 

Do you mind creating a ticket in the bug tracker for this issue. Then I will make sure it's added.

There is a link to the tracker from here:
http://activemq.apache.org/camel/support.html


Is there a sendXXX method that accepts an exchange pattern and also the headers? If there is you can use that on.

Otherwise you can use the generic send(Exchange) where you can create the exchange and set all the stuff manually.

Check out the source code in DefaultProducerTemplate.java that can give you hints as well.




Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 12:35
To: camel-user@activemq.apache.org
Subject: RE: How to process the response in Camel


hi,


Claus Ibsen wrote:
> 
> Hi
> 
> Ah that is a little pitfall with the producerTemplate as it has many
> methods.
> http://activemq.apache.org/camel/producertemplate.html
> 
> You should use sendXXX for IN only message exchange patterns
> You should use requestXXX for IN-OUT message exchange patterns
> 
> So you should use requestBody:
> 
>         result = camelProducerTemplate.requestBodyAndHeaders(endPointUri,
> httpBodyString, exchangeMapHeaders);
> 
> 


The only method requestXXX that exist is with a single hearder (no s at the
end of the method)
   Object requestBodyAndHeader(String endpointUri, Object body, String
header, Object headerValue);

And I want to add all http headers in order to rebuild the same http request
to my "european server".

requestBodyAndHeader calls sendBodyAndHeader. For sendXXX, there are 
   Object sendBodyAndHeader(String endpoint, 
                                         ExchangePattern pattern, 
                                         final Object body, 
                                         final String header,
  and 
    Object sendBodyAndHeaders(String endpointUri, 
                                           final Object body, 
                                           final Map<String, Object>
headers)
   
Using the problem using sendBodyAndHeaders is I cannot set  the
ExchangePattern to InOut.
Your are right, running in debug mode, I see that the exchange pattern
associated to the endpoint is InOnly.
  ==> Is there a way to specify the Exchange pattern in another way (via the
endpoint uri like dataformat?,  pring property)

But I don't know if the problem is here. In my servlet, I am able to process
the Exchange;
getOut() and put it in the httpResponse.getOutputStream() 

            result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
                                                          buff.toString(),
                                                         
exchangeMapHeaders);
            InputStream isResult = (InputStream)result;
            final OutputStream respOs;
            respOs = httpResponse.getOutputStream();  

            while (isResult.available() != 0) {
                final int readByte = isResult.read();
                respOs.write(readByte);
            }


My Problem is that, in that case, I cannot process the response stream. In
my example, the client will receive prices in euros instead of in dollars.

So, I think my problem is to insert a processor to process the reply.!!!




Claus Ibsen wrote:
> 
> 
> What is the content on endPointUri? Do you send it the direct or the http
> endpoint?
> 
endPointUri is tha string that contains "direct:myServletServiceUri"

Guilaume Lundy


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 11:28
To: camel-user@activemq.apache.org
Subject: How to process the response in Camel


Hi all, 

I want to make a  Camel base engine that adapts web services requests and
replies
For example : 
- convert currencies from dollars to euro in both requests and responses
- The client understands Dollars
- The server understands euros.
  
I have the following route
<endpoint id="httpEndpointBackend"
uri="http://myEuropeanServer.com/myservice"/>
<route>
  <from uri="direct:myServletServiceUri" />   <!-- called by a servlet doGt
and doPost methods-->
  <process ref="myProcessor" />
  <to ref="httpEndpointBackend" />
</route>
 
In my servlet, I extract http  headers and body, send them to by endpoint
using
        result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
httpBodyString, exchangeMapHeaders);

With this configuration, I can successfully process the request but I cannot
process the response.
I think it because processors are asynchonous  but my  process is
synchronous.

Is there a way to  either
 - use processors in a synchronous way (like servlet filters chain) 
or
 - define a processor that will be called once the http endpoint receives
its http response


Thanks
Guillaume


-- 
View this message in context:
http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378039.html
Sent from the Camel - Users mailing list archive at Nabble.com.




-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378945.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: How to process the response in Camel

Posted by GLD <gu...@orange-ftgroup.com>.
hi,


Claus Ibsen wrote:
> 
> Hi
> 
> Ah that is a little pitfall with the producerTemplate as it has many
> methods.
> http://activemq.apache.org/camel/producertemplate.html
> 
> You should use sendXXX for IN only message exchange patterns
> You should use requestXXX for IN-OUT message exchange patterns
> 
> So you should use requestBody:
> 
>         result = camelProducerTemplate.requestBodyAndHeaders(endPointUri,
> httpBodyString, exchangeMapHeaders);
> 
> 


The only method requestXXX that exist is with a single hearder (no s at the
end of the method)
   Object requestBodyAndHeader(String endpointUri, Object body, String
header, Object headerValue);

And I want to add all http headers in order to rebuild the same http request
to my "european server".

requestBodyAndHeader calls sendBodyAndHeader. For sendXXX, there are 
   Object sendBodyAndHeader(String endpoint, 
                                         ExchangePattern pattern, 
                                         final Object body, 
                                         final String header,
  and 
    Object sendBodyAndHeaders(String endpointUri, 
                                           final Object body, 
                                           final Map<String, Object>
headers)
   
Using the problem using sendBodyAndHeaders is I cannot set  the
ExchangePattern to InOut.
Your are right, running in debug mode, I see that the exchange pattern
associated to the endpoint is InOnly.
  ==> Is there a way to specify the Exchange pattern in another way (via the
endpoint uri like dataformat?,  pring property)

But I don't know if the problem is here. In my servlet, I am able to process
the Exchange;
getOut() and put it in the httpResponse.getOutputStream() 

            result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
                                                          buff.toString(),
                                                         
exchangeMapHeaders);
            InputStream isResult = (InputStream)result;
            final OutputStream respOs;
            respOs = httpResponse.getOutputStream();  

            while (isResult.available() != 0) {
                final int readByte = isResult.read();
                respOs.write(readByte);
            }


My Problem is that, in that case, I cannot process the response stream. In
my example, the client will receive prices in euros instead of in dollars.

So, I think my problem is to insert a processor to process the reply.!!!




Claus Ibsen wrote:
> 
> 
> What is the content on endPointUri? Do you send it the direct or the http
> endpoint?
> 
endPointUri is tha string that contains "direct:myServletServiceUri"

Guilaume Lundy


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 11:28
To: camel-user@activemq.apache.org
Subject: How to process the response in Camel


Hi all, 

I want to make a  Camel base engine that adapts web services requests and
replies
For example : 
- convert currencies from dollars to euro in both requests and responses
- The client understands Dollars
- The server understands euros.
  
I have the following route
<endpoint id="httpEndpointBackend"
uri="http://myEuropeanServer.com/myservice"/>
<route>
  <from uri="direct:myServletServiceUri" />   <!-- called by a servlet doGt
and doPost methods-->
  <process ref="myProcessor" />
  <to ref="httpEndpointBackend" />
</route>
 
In my servlet, I extract http  headers and body, send them to by endpoint
using
        result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
httpBodyString, exchangeMapHeaders);

With this configuration, I can successfully process the request but I cannot
process the response.
I think it because processors are asynchonous  but my  process is
synchronous.

Is there a way to  either
 - use processors in a synchronous way (like servlet filters chain) 
or
 - define a processor that will be called once the http endpoint receives
its http response


Thanks
Guillaume


-- 
View this message in context:
http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378039.html
Sent from the Camel - Users mailing list archive at Nabble.com.




-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378945.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: How to process the response in Camel

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

Ah that is a little pitfall with the producerTemplate as it has many methods.
http://activemq.apache.org/camel/producertemplate.html

You should use sendXXX for IN only message exchange patterns
You should use requestXXX for IN-OUT message exchange patterns

So you should use requestBody:

        result = camelProducerTemplate.requestBodyAndHeaders(endPointUri,
httpBodyString, exchangeMapHeaders);

What is the content on endPointUri? Do you send it the direct or the http endpoint?


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: GLD [mailto:guillaume.lundy@orange-ftgroup.com] 
Sent: 7. november 2008 11:28
To: camel-user@activemq.apache.org
Subject: How to process the response in Camel


Hi all, 

I want to make a  Camel base engine that adapts web services requests and
replies
For example : 
- convert currencies from dollars to euro in both requests and responses
- The client understands Dollars
- The server understands euros.
  
I have the following route
<endpoint id="httpEndpointBackend"
uri="http://myEuropeanServer.com/myservice"/>
<route>
  <from uri="direct:myServletServiceUri" />   <!-- called by a servlet doGt
and doPost methods-->
  <process ref="myProcessor" />
  <to ref="httpEndpointBackend" />
</route>
 
In my servlet, I extract http  headers and body, send them to by endpoint
using
        result = camelProducerTemplate.sendBodyAndHeaders(endPointUri,
httpBodyString, exchangeMapHeaders);

With this configuration, I can successfully process the request but I cannot
process the response.
I think it because processors are asynchonous  but my  process is
synchronous.

Is there a way to  either
 - use processors in a synchronous way (like servlet filters chain) 
or
 - define a processor that will be called once the http endpoint receives
its http response


Thanks
Guillaume


-- 
View this message in context: http://www.nabble.com/How-to-process-the-response-in-Camel-tp20378039s22882p20378039.html
Sent from the Camel - Users mailing list archive at Nabble.com.