camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen" ...@silverbullet.dk>
Subject RE: How to process the response in Camel
Date Fri, 07 Nov 2008 12:26:30 GMT
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.


Mime
View raw message