camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Satch <upadhya...@gmail.com>
Subject RE: from http://... to file://...
Date Mon, 23 Jun 2008 16:56:02 GMT

Hi Claus,

Thanks for the reply!

Yeah, it worked. I am still thinking abt the correct sequence here. Is this
a correct sequence:
1. Jetty gets an Inout MEP
2. A copy of exchange goes to the seda and out content in the original
exchange is set to ("We got your request")
3. MyJettyProcessor picks it up from the SEDA and wirtes to the fille.

Also, if I wish to do more complex processing with the message after it
comes out from jetty, this is what i tried to do, but i got stuck at one
place.
I coded a POJO which which was the target of jetty component. I wanted to
grab the inout mep, make its out content as "recieved", extract the "in"
payload, transform it into something, create an inonly MEP and write it to a
persistent queue. The problem is that I am not able to figure out how to
return the Inout exchange back to the jetty component and then
simultaneously persist the Inonly MEP to the JMS queue. 

thanks






Claus Ibsen wrote:
> 
> Hi Joe
> 
> By all means please post any questions you have to this user forum. 
> 
> Ad 1)
> Yes your observations is correct. If the file component gets an out
> capable exchange then its trying to poll the file. So you need to change
> the mep pattern to inonly.
> 
> The HTTP protocol is by nature request-response based so that is why Camel
> will send back a response if you use camel-jetty. You should probably send
> back a response with HTTP STATUS 200 to indicate to the client that you
> have accepted/consume his request.
> 
> Ad 2)
> Send a response back to the client.
> 
> Ad 3)
> You can use a processor to change/handle the exchange programmatically.
> from("xxx").process(new MyProcessor()).to("yyy")
> 
> 
> Here is some help for your route to do what you want:
> 
>     protected RouteBuilder createRouteBuilder() throws Exception {
>         return new RouteBuilder() {
>             public void configure() throws Exception {
>                
> from("jetty:http://localhost:8080/myworld").to("seda:in").setBody(constant("We
> got your request"));
> 
>                 from("seda:in").process(new MyJettyProcessor()).
>                     setHeader(FileComponent.HEADER_FILE_NAME,
> "hello.txt").to("file://target/myworld");
>             }
>         };
>     }
> 
>     private class MyJettyProcessor implements Processor {
>         public void process(Exchange exchange) throws Exception {
>             // must convert to in only as file producer will try to load
> the file if the exchange pattner
>             // is out capable.
>             exchange.setPattern(ExchangePattern.InOnly);
>         }
>     }
> 
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> 
> -----Original Message-----
> From: Joe Satch [mailto:upadhyay.k@gmail.com] 
> Sent: 22. juni 2008 22:18
> To: camel-user@activemq.apache.org
> Subject: RE: from http://... to file://...
> 
> 
> Hi,
> 
> I am quite new to camel, so plz excuse me if i say something fundamentally
> wrong. 
> What i am not able to understand here is that if I wish to open an http
> serversocket to listen to requests and persist them to a file, how do i go
> for it. I could open a serversocket using jetty component, and then I
> routed
> the incoming messages to a file URI. It threw me exception.
> 
> My analysis of the problem was that the jetty server component makes an
> Inout exchange and forwards the content to file URI and waits for the
> response to come as it instantiated an Inout MEP. And it never gets the
> response back as the file component probably expects an Inonly MEP or
> something of that sort. 
> 
> My questions
> 
> 1. Is my analysis wrong.
> 2. If I wish to do what i am trying to, how do I go abt it ?
> 3. How do I trap an exchange programtically and then do something with it
> ?
> thanks
> 
> 
>>Ah the issue is that the Jetty component is an EventDrivenConsumer and not
> Scheduled. So you have to >trigger the event yourself to start the event
> in
> jetty.
>>Eg:
>>from("timer://foo?fixedRate=true&delay=0&period=10000").to("jetty:http://www.google.com").setHeader>(FileComponent.HEADER_FILE_NAME,
> "message.txt").to("file:target/hello");
> 
>>This will invoke the google homepage every 10th second and store it as a
> file.
>>http://activemq.apache.org/camel/event-driven-consumer.html
> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/from-http%3A--...-to-file%3A--...-tp17739149s22882p18058624.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/from-http%3A--...-to-file%3A--...-tp17739149s22882p18073429.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message