You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by SyedBhai <sy...@hotmail.com> on 2013/07/29 12:38:58 UTC

Invoking Servlet from Camel

Hi guys,
  I am having a servlet.  It expects one parameter, say 'message'.
  I want to invoke it using camel.
  I am able to invoke it successfully as a HTTP GET method as follows:
   
from("direct:start").to("http://192.168.221.109:8080/DSP1/ServletDsp?message=HelloCamel");
    String response=template.requestBody("direct:start", null,
String.class);

  What I want is instead of passing the parameter in the query string, can I
pass it as a message body?
    String response=template.requestBody("direct:start", "HelloCamel",
String.class);

  Is there a way to accomplish this?
 
  I have already visited Camel Servlet Component webpage.

  It doesn't help.

Thanks,
Syed.



--
View this message in context: http://camel.465427.n5.nabble.com/Invoking-Servlet-from-Camel-tp5736417.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Invoking Servlet from Camel

Posted by James Carman <ja...@carmanconsulting.com>.
If you just set the query string using the header Exchange.HTTP_QUERY,
then it will use GET automatically.  Also, if you just use an
expression (as Claus was suggesting) to bind the body of the message
to the query parameter, it will use GET automatically also.

On Mon, Jul 29, 2013 at 6:58 AM, Bilgin Ibryam <bi...@gmail.com> wrote:
> Hi Syed,
>
> what you have done should work.
> If you set a message body http4 component will use POST method to do
> the http call and sent the message body as post body.
>
> Have a look here http://camel.apache.org/http4.html
>
> You can also set the http method manually if you prefer, like this:
>  .setHeader(Exchange.HTTP_METHOD,
> constant(org.apache.camel.component.http4.HttpMethods.POST))
>
> But notice that in this case, in your servlet you will get the call
> from doPost method and not from doGet
>
> HTH
> Bilgin
>
> On 29 July 2013 11:38, SyedBhai <sy...@hotmail.com> wrote:
>> Hi guys,
>>   I am having a servlet.  It expects one parameter, say 'message'.
>>   I want to invoke it using camel.
>>   I am able to invoke it successfully as a HTTP GET method as follows:
>>
>> from("direct:start").to("http://192.168.221.109:8080/DSP1/ServletDsp?message=HelloCamel");
>>     String response=template.requestBody("direct:start", null,
>> String.class);
>>
>>   What I want is instead of passing the parameter in the query string, can I
>> pass it as a message body?
>>     String response=template.requestBody("direct:start", "HelloCamel",
>> String.class);
>>
>>   Is there a way to accomplish this?
>>
>>   I have already visited Camel Servlet Component webpage.
>>
>>   It doesn't help.
>>
>> Thanks,
>> Syed.
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Invoking-Servlet-from-Camel-tp5736417.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Invoking Servlet from Camel

Posted by SyedBhai <sy...@hotmail.com>.
Hello.
  But how can I ensure that the body I am passing is connected to the
parameter 'message'?

Thanks,
Syed.



--
View this message in context: http://camel.465427.n5.nabble.com/Invoking-Servlet-from-Camel-tp5736417p5736426.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Invoking Servlet from Camel

Posted by Bilgin Ibryam <bi...@gmail.com>.
Hi Syed,

what you have done should work.
If you set a message body http4 component will use POST method to do
the http call and sent the message body as post body.

Have a look here http://camel.apache.org/http4.html

You can also set the http method manually if you prefer, like this:
 .setHeader(Exchange.HTTP_METHOD,
constant(org.apache.camel.component.http4.HttpMethods.POST))

But notice that in this case, in your servlet you will get the call
from doPost method and not from doGet

HTH
Bilgin

On 29 July 2013 11:38, SyedBhai <sy...@hotmail.com> wrote:
> Hi guys,
>   I am having a servlet.  It expects one parameter, say 'message'.
>   I want to invoke it using camel.
>   I am able to invoke it successfully as a HTTP GET method as follows:
>
> from("direct:start").to("http://192.168.221.109:8080/DSP1/ServletDsp?message=HelloCamel");
>     String response=template.requestBody("direct:start", null,
> String.class);
>
>   What I want is instead of passing the parameter in the query string, can I
> pass it as a message body?
>     String response=template.requestBody("direct:start", "HelloCamel",
> String.class);
>
>   Is there a way to accomplish this?
>
>   I have already visited Camel Servlet Component webpage.
>
>   It doesn't help.
>
> Thanks,
> Syed.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Invoking-Servlet-from-Camel-tp5736417.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Invoking Servlet from Camel

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See this page
http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html

On Mon, Jul 29, 2013 at 12:38 PM, SyedBhai <sy...@hotmail.com> wrote:
> Hi guys,
>   I am having a servlet.  It expects one parameter, say 'message'.
>   I want to invoke it using camel.
>   I am able to invoke it successfully as a HTTP GET method as follows:
>
> from("direct:start").to("http://192.168.221.109:8080/DSP1/ServletDsp?message=HelloCamel");
>     String response=template.requestBody("direct:start", null,
> String.class);
>
>   What I want is instead of passing the parameter in the query string, can I
> pass it as a message body?
>     String response=template.requestBody("direct:start", "HelloCamel",
> String.class);
>
>   Is there a way to accomplish this?
>
>   I have already visited Camel Servlet Component webpage.
>
>   It doesn't help.
>
> Thanks,
> Syed.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Invoking-Servlet-from-Camel-tp5736417.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen