You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by kitplummer <ki...@gmail.com> on 2010/01/26 06:25:10 UTC

Grails/Camel - pass queue message to HTTP POST?

Ok, just thinking at this point...and I don't yet understand Camel well
enough.  So, I need some insight.

What I want to do is use Camel to facilitate some back-end business logic in
my Grails app.  Here's the general idea.  From my Grails app I send a block
of text to a Route.  I want this route to be configured to take in a block
of raw text (seda:my.queue) and send my.queue as the body of an HTTP POST to
an external service - and consume the returned body, sending it back to a
Grails service.  I have the last part figured, but missing the Camel guts.

Here's where I'm starting:

class JobRoute {
    def configure = {
        println "Setting JobRoute Camel Router..."
        from("seda:my.queue") {
            Exchange exchange =
template.send("http://localhost:4567/jodmock", 
                new Processor() {
                    process(exchange) {
                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
constant(org.apache.camel.component.http.HttpMethods.POST));
                    }
                }
            );
            Message out = exchange.getOut();
            int responseCode =
out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
        }
    }
}

The "new Processor() instantiation barfs during compile with:

[groovyc] /Users/kplummer/Development/ts/grails-app/routes/JobRoute.groovy:
9: You cannot create an instance from the abstract interface
'org.apache.camel.Processor'.
  [groovyc]  @ line 9, column 17.
  [groovyc]                    new Processor() {
  [groovyc] 

And, I haven't figured out to get the my.queue to the contents of the In.  

Help!

Thanks.
Kit
-- 
View this message in context: http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27318113.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Grails/Camel - pass queue message to HTTP POST?

Posted by kitplummer <ki...@gmail.com>.
Here's what I was able to get working.  Keep in mind this is Groovy, within a
Grails' Camel Plugin Route.  Process is a simple closure, with "it" being
the Exchange.

class JobRoute { 
    def configure = { 
        println "Setting JobRoute Camel Router..." 
        from("seda:job.contents").process{
                Object body = it.getIn().getBody()
                // do some business logic with the input body
                println "Body ${body}"
            }.
        setHeader("Accept", "text/plain").
        to("http://localhost:4567/converter/service").
        to("bean:rawTextService?methodName=handleText")
    } 
}


Ashwin Karpe wrote:
> 
> Hi,
> 
> You can do the following
> from(seda)
>    .to(http)
>    .process(new Processor() {
>        public void process(Exchange exchange) throws Exception {
>              // do something...
>        }
>    });
> 
> This should do the trick.
> 
> Cheers,
> 
> Ashwin...
> 
> 

-- 
View this message in context: http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27343479.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Grails/Camel - pass queue message to HTTP POST?

Posted by Ashwin Karpe <as...@progress.com>.
Hi,

You can do the following
from(seda)
   .to(http)
   .process(new Processor() {
       public void process(Exchange exchange) throws Exception {
             // do something...
       }
   });

This should do the trick.

Cheers,

Ashwin...


kitplummer wrote:
> 
> Thanks Claus, that works.  But, I need to handle the returned contents
> from my Route.  Just figured I needed the Exchange to get at the contents
> as a String.
> 
> Kit
> 
> 
> Claus Ibsen-2 wrote:
>> 
>> Can you not just do a
>> 
>> from(seda).to(http);
>> 
>> The camel http component will automatic use POST if no uri parameters.
>> You should also be able to configure in the uri for the http endpoint
>> that it should use POST
>> 
>> 
>> On Tue, Jan 26, 2010 at 2:37 PM, kitplummer <ki...@gmail.com> wrote:
>>>
>>> Getting closer:
>>>
>>> import org.apache.camel.Exchange
>>> import org.apache.camel.Processor
>>> import org.apache.camel.Message
>>>
>>> class JobRoute {
>>>   def configure = {
>>>       println "Setting JobRoute Camel Router..."
>>>       from("seda:my.queue") {
>>>           Exchange exchange =
>>> template.send("http://localhost:4567/jodmock",
>>>               [
>>>                   process: { exchange ->
>>>                       exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>>> constant(POST));
>>>                   }
>>>               ] as Processor
>>>           );
>>>           Message out = exchange.getOut();
>>>           int responseCode =
>>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>>       }
>>>   }
>>> }
>>>
>>> Produces:
>>>
>>> Caused by: groovy.lang.MissingMethodException: No signature of method:
>>> org.ix.grails.plugins.camel.GrailsRouteBuilder.from() is applicable for
>>> argument types: (java.lang.String, JobRoute$_closure1_closure2) values:
>>> [seda:my.queue, JobRoute$_closure1_closure2@55661f7b]
>>>
>>> Run-time error, so we're past the compilation problem.  I guess it
>>> doesn't
>>> like the second closure.  :)
>>>
>>> Thanks for the help.  Still curious about how to the get the my.queue
>>> message into the body of the In's POST.
>>>
>>> Kit
>>>
>>> wkeenan wrote:
>>>>
>>>> On Tue, Jan 26, 2010 at 5:25 AM, kitplummer <ki...@gmail.com>
>>>> wrote:
>>>>
>>>>>
>>>>> Ok, just thinking at this point...and I don't yet understand Camel
>>>>> well
>>>>> enough.  So, I need some insight.
>>>>>
>>>>> What I want to do is use Camel to facilitate some back-end business
>>>>> logic
>>>>> in
>>>>> my Grails app.  Here's the general idea.  From my Grails app I send a
>>>>> block
>>>>> of text to a Route.  I want this route to be configured to take in a
>>>>> block
>>>>> of raw text (seda:my.queue) and send my.queue as the body of an HTTP
>>>>> POST
>>>>> to
>>>>> an external service - and consume the returned body, sending it back
>>>>> to a
>>>>> Grails service.  I have the last part figured, but missing the Camel
>>>>> guts.
>>>>>
>>>>> Here's where I'm starting:
>>>>>
>>>>> class JobRoute {
>>>>>    def configure = {
>>>>>        println "Setting JobRoute Camel Router..."
>>>>>        from("seda:my.queue") {
>>>>>            Exchange exchange =
>>>>> template.send("http://localhost:4567/jodmock",
>>>>>                new Processor() {
>>>>>                    process(exchange) {
>>>>>                      
>>>>>  exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>>>>> constant(org.apache.camel.component.http.HttpMethods.POST));
>>>>>                    }
>>>>>                }
>>>>>            );
>>>>>            Message out = exchange.getOut();
>>>>>            int responseCode =
>>>>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>>>>        }
>>>>>    }
>>>>> }
>>>>>
>>>>> The "new Processor() instantiation barfs during compile with:
>>>>>
>>>>> [groovyc]
>>>>> /Users/kplummer/Development/ts/grails-app/routes/JobRoute.groovy:
>>>>> 9: You cannot create an instance from the abstract interface
>>>>> 'org.apache.camel.Processor'.
>>>>>  [groovyc]  @ line 9, column 17.
>>>>>  [groovyc]                    new Processor() {
>>>>>  [groovyc]
>>>>>
>>>>>
>>>> try this:
>>>>
>>>> class JobRoute extends RouteBuilder {
>>>>    void configure  {
>>>>        println "Setting JobRoute Camel Router..."
>>>>        from("seda:my.queue") {
>>>>            Exchange exchange =
>>>> template.send("http://localhost:4567/jodmock
>>>> ",
>>>>                [
>>>>                    process: { exchange ->
>>>>                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>>>> constant(org.apache.camel.component.http.HttpMethods.POST));
>>>>                    }
>>>>                ] as Processor
>>>>            );
>>>>            Message out = exchange.getOut();
>>>>            int responseCode =
>>>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>>>        }
>>>>    }
>>>> }
>>>>
>>>>
>>>>
>>>>> And, I haven't figured out to get the my.queue to the contents of the
>>>>> In.
>>>>>
>>>>> Help!
>>>>>
>>>>> Thanks.
>>>>> Kit
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27318113.html
>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27322707.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
>> 
>> -- 
>> Claus Ibsen
>> Apache Camel Committer
>> 
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>> 
>> 
> 
> 


-----
--- 
Ashwin Karpe, Principal Consultant, PS - Opensource Center of Competence 
Progress Software Corporation
14 Oak Park Drive
Bedford, MA 01730
--- 
+1-972-304-9084 (Office) 
+1-972-971-1700 (Mobile) 
---- 
Blog: http://opensourceknowledge.blogspot.com/


-- 
View this message in context: http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27338409.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Grails/Camel - pass queue message to HTTP POST?

Posted by kitplummer <ki...@gmail.com>.
Thanks Claus, that works.  But, I need to handle the returned contents from
my Route.  Just figured I needed the Exchange to get at the contents as a
String.

Kit


Claus Ibsen-2 wrote:
> 
> Can you not just do a
> 
> from(seda).to(http);
> 
> The camel http component will automatic use POST if no uri parameters.
> You should also be able to configure in the uri for the http endpoint
> that it should use POST
> 
> 
> On Tue, Jan 26, 2010 at 2:37 PM, kitplummer <ki...@gmail.com> wrote:
>>
>> Getting closer:
>>
>> import org.apache.camel.Exchange
>> import org.apache.camel.Processor
>> import org.apache.camel.Message
>>
>> class JobRoute {
>>   def configure = {
>>       println "Setting JobRoute Camel Router..."
>>       from("seda:my.queue") {
>>           Exchange exchange =
>> template.send("http://localhost:4567/jodmock",
>>               [
>>                   process: { exchange ->
>>                       exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>> constant(POST));
>>                   }
>>               ] as Processor
>>           );
>>           Message out = exchange.getOut();
>>           int responseCode =
>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>       }
>>   }
>> }
>>
>> Produces:
>>
>> Caused by: groovy.lang.MissingMethodException: No signature of method:
>> org.ix.grails.plugins.camel.GrailsRouteBuilder.from() is applicable for
>> argument types: (java.lang.String, JobRoute$_closure1_closure2) values:
>> [seda:my.queue, JobRoute$_closure1_closure2@55661f7b]
>>
>> Run-time error, so we're past the compilation problem.  I guess it
>> doesn't
>> like the second closure.  :)
>>
>> Thanks for the help.  Still curious about how to the get the my.queue
>> message into the body of the In's POST.
>>
>> Kit
>>
>> wkeenan wrote:
>>>
>>> On Tue, Jan 26, 2010 at 5:25 AM, kitplummer <ki...@gmail.com>
>>> wrote:
>>>
>>>>
>>>> Ok, just thinking at this point...and I don't yet understand Camel well
>>>> enough.  So, I need some insight.
>>>>
>>>> What I want to do is use Camel to facilitate some back-end business
>>>> logic
>>>> in
>>>> my Grails app.  Here's the general idea.  From my Grails app I send a
>>>> block
>>>> of text to a Route.  I want this route to be configured to take in a
>>>> block
>>>> of raw text (seda:my.queue) and send my.queue as the body of an HTTP
>>>> POST
>>>> to
>>>> an external service - and consume the returned body, sending it back to
>>>> a
>>>> Grails service.  I have the last part figured, but missing the Camel
>>>> guts.
>>>>
>>>> Here's where I'm starting:
>>>>
>>>> class JobRoute {
>>>>    def configure = {
>>>>        println "Setting JobRoute Camel Router..."
>>>>        from("seda:my.queue") {
>>>>            Exchange exchange =
>>>> template.send("http://localhost:4567/jodmock",
>>>>                new Processor() {
>>>>                    process(exchange) {
>>>>                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>>>> constant(org.apache.camel.component.http.HttpMethods.POST));
>>>>                    }
>>>>                }
>>>>            );
>>>>            Message out = exchange.getOut();
>>>>            int responseCode =
>>>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>>>        }
>>>>    }
>>>> }
>>>>
>>>> The "new Processor() instantiation barfs during compile with:
>>>>
>>>> [groovyc]
>>>> /Users/kplummer/Development/ts/grails-app/routes/JobRoute.groovy:
>>>> 9: You cannot create an instance from the abstract interface
>>>> 'org.apache.camel.Processor'.
>>>>  [groovyc]  @ line 9, column 17.
>>>>  [groovyc]                    new Processor() {
>>>>  [groovyc]
>>>>
>>>>
>>> try this:
>>>
>>> class JobRoute extends RouteBuilder {
>>>    void configure  {
>>>        println "Setting JobRoute Camel Router..."
>>>        from("seda:my.queue") {
>>>            Exchange exchange =
>>> template.send("http://localhost:4567/jodmock
>>> ",
>>>                [
>>>                    process: { exchange ->
>>>                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>>> constant(org.apache.camel.component.http.HttpMethods.POST));
>>>                    }
>>>                ] as Processor
>>>            );
>>>            Message out = exchange.getOut();
>>>            int responseCode =
>>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>>        }
>>>    }
>>> }
>>>
>>>
>>>
>>>> And, I haven't figured out to get the my.queue to the contents of the
>>>> In.
>>>>
>>>> Help!
>>>>
>>>> Thanks.
>>>> Kit
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27318113.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27322707.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27331778.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Grails/Camel - pass queue message to HTTP POST?

Posted by Claus Ibsen <cl...@gmail.com>.
Can you not just do a

from(seda).to(http);

The camel http component will automatic use POST if no uri parameters.
You should also be able to configure in the uri for the http endpoint
that it should use POST


On Tue, Jan 26, 2010 at 2:37 PM, kitplummer <ki...@gmail.com> wrote:
>
> Getting closer:
>
> import org.apache.camel.Exchange
> import org.apache.camel.Processor
> import org.apache.camel.Message
>
> class JobRoute {
>   def configure = {
>       println "Setting JobRoute Camel Router..."
>       from("seda:my.queue") {
>           Exchange exchange =
> template.send("http://localhost:4567/jodmock",
>               [
>                   process: { exchange ->
>                       exchange.getIn().setHeader(Exchange.HTTP_METHOD,
> constant(POST));
>                   }
>               ] as Processor
>           );
>           Message out = exchange.getOut();
>           int responseCode =
> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>       }
>   }
> }
>
> Produces:
>
> Caused by: groovy.lang.MissingMethodException: No signature of method:
> org.ix.grails.plugins.camel.GrailsRouteBuilder.from() is applicable for
> argument types: (java.lang.String, JobRoute$_closure1_closure2) values:
> [seda:my.queue, JobRoute$_closure1_closure2@55661f7b]
>
> Run-time error, so we're past the compilation problem.  I guess it doesn't
> like the second closure.  :)
>
> Thanks for the help.  Still curious about how to the get the my.queue
> message into the body of the In's POST.
>
> Kit
>
> wkeenan wrote:
>>
>> On Tue, Jan 26, 2010 at 5:25 AM, kitplummer <ki...@gmail.com> wrote:
>>
>>>
>>> Ok, just thinking at this point...and I don't yet understand Camel well
>>> enough.  So, I need some insight.
>>>
>>> What I want to do is use Camel to facilitate some back-end business logic
>>> in
>>> my Grails app.  Here's the general idea.  From my Grails app I send a
>>> block
>>> of text to a Route.  I want this route to be configured to take in a
>>> block
>>> of raw text (seda:my.queue) and send my.queue as the body of an HTTP POST
>>> to
>>> an external service - and consume the returned body, sending it back to a
>>> Grails service.  I have the last part figured, but missing the Camel
>>> guts.
>>>
>>> Here's where I'm starting:
>>>
>>> class JobRoute {
>>>    def configure = {
>>>        println "Setting JobRoute Camel Router..."
>>>        from("seda:my.queue") {
>>>            Exchange exchange =
>>> template.send("http://localhost:4567/jodmock",
>>>                new Processor() {
>>>                    process(exchange) {
>>>                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>>> constant(org.apache.camel.component.http.HttpMethods.POST));
>>>                    }
>>>                }
>>>            );
>>>            Message out = exchange.getOut();
>>>            int responseCode =
>>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>>        }
>>>    }
>>> }
>>>
>>> The "new Processor() instantiation barfs during compile with:
>>>
>>> [groovyc]
>>> /Users/kplummer/Development/ts/grails-app/routes/JobRoute.groovy:
>>> 9: You cannot create an instance from the abstract interface
>>> 'org.apache.camel.Processor'.
>>>  [groovyc]  @ line 9, column 17.
>>>  [groovyc]                    new Processor() {
>>>  [groovyc]
>>>
>>>
>> try this:
>>
>> class JobRoute extends RouteBuilder {
>>    void configure  {
>>        println "Setting JobRoute Camel Router..."
>>        from("seda:my.queue") {
>>            Exchange exchange =
>> template.send("http://localhost:4567/jodmock
>> ",
>>                [
>>                    process: { exchange ->
>>                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>> constant(org.apache.camel.component.http.HttpMethods.POST));
>>                    }
>>                ] as Processor
>>            );
>>            Message out = exchange.getOut();
>>            int responseCode =
>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>        }
>>    }
>> }
>>
>>
>>
>>> And, I haven't figured out to get the my.queue to the contents of the In.
>>>
>>> Help!
>>>
>>> Thanks.
>>> Kit
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27318113.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27322707.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Grails/Camel - pass queue message to HTTP POST?

Posted by kitplummer <ki...@gmail.com>.
Getting closer:

import org.apache.camel.Exchange
import org.apache.camel.Processor
import org.apache.camel.Message

class JobRoute { 
   def configure = { 
       println "Setting JobRoute Camel Router..." 
       from("seda:my.queue") { 
           Exchange exchange =
template.send("http://localhost:4567/jodmock", 
               [ 
                   process: { exchange -> 
                       exchange.getIn().setHeader(Exchange.HTTP_METHOD, 
constant(POST)); 
                   } 
               ] as Processor 
           ); 
           Message out = exchange.getOut(); 
           int responseCode = 
out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class); 
       } 
   } 
}

Produces:

Caused by: groovy.lang.MissingMethodException: No signature of method:
org.ix.grails.plugins.camel.GrailsRouteBuilder.from() is applicable for
argument types: (java.lang.String, JobRoute$_closure1_closure2) values:
[seda:my.queue, JobRoute$_closure1_closure2@55661f7b]

Run-time error, so we're past the compilation problem.  I guess it doesn't
like the second closure.  :)

Thanks for the help.  Still curious about how to the get the my.queue
message into the body of the In's POST.

Kit

wkeenan wrote:
> 
> On Tue, Jan 26, 2010 at 5:25 AM, kitplummer <ki...@gmail.com> wrote:
> 
>>
>> Ok, just thinking at this point...and I don't yet understand Camel well
>> enough.  So, I need some insight.
>>
>> What I want to do is use Camel to facilitate some back-end business logic
>> in
>> my Grails app.  Here's the general idea.  From my Grails app I send a
>> block
>> of text to a Route.  I want this route to be configured to take in a
>> block
>> of raw text (seda:my.queue) and send my.queue as the body of an HTTP POST
>> to
>> an external service - and consume the returned body, sending it back to a
>> Grails service.  I have the last part figured, but missing the Camel
>> guts.
>>
>> Here's where I'm starting:
>>
>> class JobRoute {
>>    def configure = {
>>        println "Setting JobRoute Camel Router..."
>>        from("seda:my.queue") {
>>            Exchange exchange =
>> template.send("http://localhost:4567/jodmock",
>>                new Processor() {
>>                    process(exchange) {
>>                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
>> constant(org.apache.camel.component.http.HttpMethods.POST));
>>                    }
>>                }
>>            );
>>            Message out = exchange.getOut();
>>            int responseCode =
>> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>>        }
>>    }
>> }
>>
>> The "new Processor() instantiation barfs during compile with:
>>
>> [groovyc]
>> /Users/kplummer/Development/ts/grails-app/routes/JobRoute.groovy:
>> 9: You cannot create an instance from the abstract interface
>> 'org.apache.camel.Processor'.
>>  [groovyc]  @ line 9, column 17.
>>  [groovyc]                    new Processor() {
>>  [groovyc]
>>
>>
> try this:
> 
> class JobRoute extends RouteBuilder {
>    void configure  {
>        println "Setting JobRoute Camel Router..."
>        from("seda:my.queue") {
>            Exchange exchange =
> template.send("http://localhost:4567/jodmock
> ",
>                [
>                    process: { exchange ->
>                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
> constant(org.apache.camel.component.http.HttpMethods.POST));
>                    }
>                ] as Processor
>            );
>            Message out = exchange.getOut();
>            int responseCode =
> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>        }
>    }
> }
> 
> 
> 
>> And, I haven't figured out to get the my.queue to the contents of the In.
>>
>> Help!
>>
>> Thanks.
>> Kit
>> --
>> View this message in context:
>> http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27318113.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27322707.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Grails/Camel - pass queue message to HTTP POST?

Posted by Wayne Keenan <wa...@gmail.com>.
On Tue, Jan 26, 2010 at 5:25 AM, kitplummer <ki...@gmail.com> wrote:

>
> Ok, just thinking at this point...and I don't yet understand Camel well
> enough.  So, I need some insight.
>
> What I want to do is use Camel to facilitate some back-end business logic
> in
> my Grails app.  Here's the general idea.  From my Grails app I send a block
> of text to a Route.  I want this route to be configured to take in a block
> of raw text (seda:my.queue) and send my.queue as the body of an HTTP POST
> to
> an external service - and consume the returned body, sending it back to a
> Grails service.  I have the last part figured, but missing the Camel guts.
>
> Here's where I'm starting:
>
> class JobRoute {
>    def configure = {
>        println "Setting JobRoute Camel Router..."
>        from("seda:my.queue") {
>            Exchange exchange =
> template.send("http://localhost:4567/jodmock",
>                new Processor() {
>                    process(exchange) {
>                        exchange.getIn().setHeader(Exchange.HTTP_METHOD,
> constant(org.apache.camel.component.http.HttpMethods.POST));
>                    }
>                }
>            );
>            Message out = exchange.getOut();
>            int responseCode =
> out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
>        }
>    }
> }
>
> The "new Processor() instantiation barfs during compile with:
>
> [groovyc] /Users/kplummer/Development/ts/grails-app/routes/JobRoute.groovy:
> 9: You cannot create an instance from the abstract interface
> 'org.apache.camel.Processor'.
>  [groovyc]  @ line 9, column 17.
>  [groovyc]                    new Processor() {
>  [groovyc]
>
>
try this:

class JobRoute extends RouteBuilder {
   void configure  {
       println "Setting JobRoute Camel Router..."
       from("seda:my.queue") {
           Exchange exchange = template.send("http://localhost:4567/jodmock
",
               [
                   process: { exchange ->
                       exchange.getIn().setHeader(Exchange.HTTP_METHOD,
constant(org.apache.camel.component.http.HttpMethods.POST));
                   }
               ] as Processor
           );
           Message out = exchange.getOut();
           int responseCode =
out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);
       }
   }
}



> And, I haven't figured out to get the my.queue to the contents of the In.
>
> Help!
>
> Thanks.
> Kit
> --
> View this message in context:
> http://old.nabble.com/Grails-Camel---pass-queue-message-to-HTTP-POST--tp27318113p27318113.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>