from http://... to file://...

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

from http://... to file://...

Patrick Shea-3
Hi all, I am trying to read from an http endpoint and save the content to a file but the to("file://...") seems to be trying to read the file and not write to it!

I've looked at all the unit tests and search for an answer but I still can't figure it out.

from("jetty:http://localhost:8888/hello").setHeader(FileComponent.HEADER_FILE_NAME, "message.txt").to("file:target/hello");

This should be simple no?

Thanks
Patrick

Reply | Threaded
Open this post in threaded view
|

RE: from http://... to file://...

Claus Ibsen
Hi

Yes it should be dead simple.
What version of Camel are you using?

You could try to enable org.apache.camel debug logging using eg. Log4j to see if FileProducer is used for writing the file.

You could also try with a simple test from("direct:xxd") instead of jetty to see if a file is produced then.

I can't crank up code at the moment as the laptop is on my legs as I watch the Holland-Italy football game.


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: Patrick Shea [mailto:[hidden email]]
Sent: 9. juni 2008 20:40
To: [hidden email]
Subject: from http://... to file://...

Hi all, I am trying to read from an http endpoint and save the content to a file but the to("file://...") seems to be trying to read the file and not write to it!

I've looked at all the unit tests and search for an answer but I still can't figure it out.

from("jetty:http://localhost:8888/hello").setHeader(FileComponent.HEADER_FILE_NAME, "message.txt").to("file:target/hello");

This should be simple no?

Thanks
Patrick

Reply | Threaded
Open this post in threaded view
|

RE: from http://... to file://...

Claus Ibsen
In reply to this post by Patrick Shea-3
Hi

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


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

-----Original Message-----
From: Patrick Shea [mailto:[hidden email]]
Sent: 9. juni 2008 20:58
To: Claus Ibsen
Subject: RE: from http://... to file://...

I'm using 1.3, I got the feeling that it has something to do with the strategy thing... In, In/Out, Out etc...

Patrick


-----Original Message-----
From: "Claus Ibsen" <[hidden email]>
Sent: Monday, June 9, 2008 1:48pm
To: [hidden email], [hidden email]
Subject: RE: from http://... to file://...

Hi

Yes it should be dead simple.
What version of Camel are you using?

You could try to enable org.apache.camel debug logging using eg. Log4j to see if FileProducer is used for writing the file.

You could also try with a simple test from("direct:xxd") instead of jetty to see if a file is produced then.

I can't crank up code at the moment as the laptop is on my legs as I watch the Holland-Italy football game.


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: Patrick Shea [mailto:[hidden email]]
Sent: 9. juni 2008 20:40
To: [hidden email]
Subject: from http://... to file://...

Hi all, I am trying to read from an http endpoint and save the content to a file but the to("file://...") seems to be trying to read the file and not write to it!

I've looked at all the unit tests and search for an answer but I still can't figure it out.

from("jetty:http://localhost:8888/hello").setHeader(FileComponent.HEADER_FILE_NAME, "message.txt").to("file:target/hello");

This should be simple no?

Thanks
Patrick



Reply | Threaded
Open this post in threaded view
|

Re: from http://... to file://...

Christian Schneider
Hi

I just checked the wiki page for the jetty component and I must confess,
I would not have understood how to use it from the documentation there.
Your example was very helpfull. I added it to the wiki page of the jetty
component.

Greetings

Christian

Claus Ibsen schrieb:

> Hi
>
> 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
>
>
> Med venlig hilsen
>  
> Claus Ibsen
>  

Reply | Threaded
Open this post in threaded view
|

Re: from http://... to file://...

Christian Schneider
In reply to this post by Claus Ibsen
What I still don´t understand. What is the difference between the jetty
and the http component and why are both needed? Normally I would have
thought the jetty component hosts a server that can be used to trigger a
camel route from the outside. But in the example you used it to extract
data from an external page. Am I missing something here?

Greetings

Christian

Claus Ibsen schrieb:

> Hi
>
> 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
>
>
> Med venlig hilsen
>  
> Claus Ibsen
>  

Reply | Threaded
Open this post in threaded view
|

Re: from http://... to file://...

jstrachan
2008/6/9 Christian Schneider <[hidden email]>:
> What I still don´t understand. What is the difference between the jetty and
> the http component and why are both needed? Normally I would have thought
> the jetty component hosts a server that can be used to trigger a camel route
> from the outside. But in the example you used it to extract data from an
> external page. Am I missing something here?

They may be badly named; but the jetty component is all about
implementing a HTTP server using a Camel route to implement it. The
http component is all about using a HTTP client (commons-httpclient)
to invoke remote web servers in a Camel route.

--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: from http://... to file://...

Christian Schneider
Ok ... That means if I want to fetch an external page
I have to use the http component.

Claus posted this example:

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");

Is it right that this should be like this:

from("timer://foo?fixedRate=true&delay=0&period=10000").to("http://www.google.com").setHeader(FileComponent.HEADER_FILE_NAME, "message.txt").to("file:target/hello");


Greetings

Christian

James Strachan schrieb:
>
> They may be badly named; but the jetty component is all about
> implementing a HTTP server using a Camel route to implement it. The
> http component is all about using a HTTP client (commons-httpclient)
> to invoke remote web servers in a Camel route.
>
>  

Reply | Threaded
Open this post in threaded view
|

RE: from http://... to file://...

lostmyoldacc
In reply to this post by Claus Ibsen
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

Reply | Threaded
Open this post in threaded view
|

RE: from http://... to file://...

Claus Ibsen
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:[hidden email]]
Sent: 22. juni 2008 22:18
To: [hidden email]
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.

Reply | Threaded
Open this post in threaded view
|

RE: from http://... to file://...

Patrick Shea-3
In reply to this post by Patrick Shea-3
Claus, I don't see a setPattern(...) on the Exchange class in 1.3?

Patrick

-----Original Message-----
From: "Claus Ibsen" <[hidden email]>
Sent: Monday, June 23, 2008 1:08am
To: [hidden email]
Subject: RE: from http://... to file://...

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:[hidden email]]
Sent: 22. juni 2008 22:18
To: [hidden email]
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.



Reply | Threaded
Open this post in threaded view
|

RE: from http://... to file://...

Claus Ibsen
Hi Patrick

Argh I do think that it's only exposed on the Exchange interface in 1.4.
In Camel 1.3 you can cast the Exchange to DefaultExchange and use the setPattern method.

BTW: I will try to investigate why the FileProducer is doing the polling when it's an InOut exchange - I can not see the reason for it.


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: Patrick Shea [mailto:[hidden email]]
Sent: 23. juni 2008 10:05
To: [hidden email]
Subject: RE: from http://... to file://...

Claus, I don't see a setPattern(...) on the Exchange class in 1.3?

Patrick

-----Original Message-----
From: "Claus Ibsen" <[hidden email]>
Sent: Monday, June 23, 2008 1:08am
To: [hidden email]
Subject: RE: from http://... to file://...

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:[hidden email]]
Sent: 22. juni 2008 22:18
To: [hidden email]
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.



Reply | Threaded
Open this post in threaded view
|

RE: from http://... to file://...

lostmyoldacc
In reply to this post by Claus Ibsen
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.
Reply | Threaded
Open this post in threaded view
|

RE: from http://... to file://...

Claus Ibsen
Hi Joe,

Yes its a correct sequence. However the seda queue divides the exchange into two processes that are async. It depends on your requirements. With the seda queue you can respond immediately to the client that you got the data. However as you haven't processed the data you don't know if its valid data that you can process.

Without the seda queue you can process and validate the data before sending a response back to the client. You can change the seda queaue to a direct queue that is synchronous and thus the response to the client is only sent after the exchange has been written to file.

If you wish to do much more complex processing your can use a .process(new MyComplexProcessor()) where you can do all the java complex processing you want. In fact in Camel there are many ways to heaven - you can also use the bean to instruct Camel to use a POJO.

From the MyComplexProcessor you can extract the in, transform, and fetch the endpoint for the persistent queue and send it there. You can inject a ProducerTemplate, or a Endpoint using annotations etc. But for start you can just get the camel context where you can get the persistent queue endpoint where you can create a exchange and a producer to send the exchange.

For example: see the spring-jms tutorial:
http://activemq.apache.org/camel/tutorial-jmsremoting.html




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:[hidden email]]
Sent: 23. juni 2008 18:56
To: [hidden email]
Subject: RE: from http://... to file://...


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:[hidden email]]
> Sent: 22. juni 2008 22:18
> To: [hidden email]
> 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.