You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Wayne Keenan <wa...@gmail.com> on 2010/01/20 10:02:16 UTC

passing the HTTPServletRequest from Jetty to a SEDA consumer in Spring DSL

Hi,

I have a Jetty endpoint that when recieving a message will perform the
processing asynchronously and syncronously return a correlationId so the
client can come back later to another endpoint to see how processsing is
going.

I found an example on the mailing list of how to pass the HttpSession object
using Java, but I can't seem to find out how
to reference or pass the HttpRequest using SpringDSL.  What I have at the
moment is:


        <route>
            <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
            <inOnly uri="seda:sendASync"/>
            <transform>
                <simple>${id}</simple>
            </transform>
        </route>

        <route>
            <from uri="seda:sendASync"/>
            <to uri="bean:myBean"/>
        </route>

Is there a way to say 'pass the HTTP stuff through please Mr SEDA'?
Should I really be setting a header property to that of a HTTP Object?  How
do I obtain it?
Should I architect this differently?

All the best,
Wayne

Re: passing the HTTPServletRequest from Jetty to a SEDA consumer in Spring DSL

Posted by Willem Jiang <wi...@gmail.com>.
Willem Jiang wrote:
> Wayne Keenan wrote:
>> Hi,
>>
>> Thanks for replying.
>>
>> On Wed, Jan 20, 2010 at 3:28 PM, Willem Jiang 
>> <wi...@gmail.com>wrote:
>>
>>> Hi,
>>>
>>> Can you try to set the ID into the message header instead of the message
>>> body ? In this way you can the Request object back :)
>>>
>>>
>>>>>        <route>
>>>>>             <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>>>>>             <inOnly uri="seda:sendASync"/>
>>>>>             <setHeader headerName="id">
>>>>>                  <simple>${id}</simple>
>>>>>             </setHeader>
>>>>>         </route>
>>>>>
>>>>>         <route>
>>>>>             <from uri="seda:sendASync"/>
>>>>>             <to uri="bean:myBean"/>
>>>>>         </route>
>>> You bean's method could
>>> public String controller(@Header("id")String body, Exchange exchange) ;
>>>
>>>
>>>
>> The request body contains base64 encoded POST I want.
>>
>> I can get to the body, url paramters and the ID ok without the 
>> intermediate
>> SEDA route, in the bean I have:
>>
>>
>>       HttpServletRequest req =
>> exchange.getIn().getBody(HttpServletRequest.class);
>>
>>       def corrId = exchange.getIn().getMessageId()
> 
> It looks the seda endpoint didn't copy the message body of the 
> HttpServletRequest.
> I will write a simple unit test to verify it.
> 
I did a quick test as your said, and found the HttpServletRequest and 
HttpServletResponse objects are stored in the HttpMessage which is 
extended from the DefaultMessage,
When the exchange is copy from the jetty endpoint to other endpoints, 
these HttpMessage members will not be copyed.

You need to make sure what you want is put into message header before 
pass this message to the

>>
>> I also can get to the URL (not form encoded) parameters   (e.g. the 
>> URL is:
>> http://0.0.0.0:65503/endpoint?myParam=value) by using:
>>
>>       def p1 = req?.getParameter('myParam')
>>
>>
>>
>> It's ony when I introduce the SEDA that the HttpServletRequest no longer
>> exists,  (I think), and I am unable to obtain the HTTP parameters from 
>> the
>> URL
>>
>> Perhaps I should be copying the HTTP parameters to Camel message
>> properties?  That way my bean can be less dependent on the HTTP protocol.
> Yes, that could be another solution.

You can get the Parameter from the message header like this
Exchange.getIn().getHeader("myParam");
>>
>> Is that something someone would be able to give me an example of 
>> please?  Is
>> there a built-in way to auto populate Camel message properties with HTTP
>> properties
>>
>> Alternatively, sticking with HTTP aware bean,I just get null using:
>>
>> println exchange.getProperty(Exchange.HTTP_QUERY)
>> or
>> println exchange.getIn().getProperty(Exchange.HTTP_QUERY)
>>
> The HTTP_QUERY is a message header.
> You can get it like this
>  exchange.getIn().getHeader(Exchange.HTTP_QUERY)
>>
>>
>> Regards
>> Wayne
>>
> 
> Willem
> 

BTW, seda support the Request/Response pattern in Camel 2.x.
If you are using Camel 2.x, you don't need to set the MEP to be InOnly.

Willem

Re: passing the HTTPServletRequest from Jetty to a SEDA consumer in Spring DSL

Posted by Willem Jiang <wi...@gmail.com>.
Wayne Keenan wrote:
> Hi,
> 
> Thanks for replying.
> 
> On Wed, Jan 20, 2010 at 3:28 PM, Willem Jiang <wi...@gmail.com>wrote:
> 
>> Hi,
>>
>> Can you try to set the ID into the message header instead of the message
>> body ? In this way you can the Request object back :)
>>
>>
>>>>        <route>
>>>>             <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>>>>             <inOnly uri="seda:sendASync"/>
>>>>             <setHeader headerName="id">
>>>>                  <simple>${id}</simple>
>>>>             </setHeader>
>>>>         </route>
>>>>
>>>>         <route>
>>>>             <from uri="seda:sendASync"/>
>>>>             <to uri="bean:myBean"/>
>>>>         </route>
>> You bean's method could
>> public String controller(@Header("id")String body, Exchange exchange) ;
>>
>>
>>
> The request body contains base64 encoded POST I want.
> 
> I can get to the body, url paramters and the ID ok without the intermediate
> SEDA route, in the bean I have:
> 
> 
>       HttpServletRequest req =
> exchange.getIn().getBody(HttpServletRequest.class);
> 
>       def corrId = exchange.getIn().getMessageId()

It looks the seda endpoint didn't copy the message body of the 
HttpServletRequest.
I will write a simple unit test to verify it.

> 
> I also can get to the URL (not form encoded) parameters   (e.g. the URL is:
> http://0.0.0.0:65503/endpoint?myParam=value) by using:
> 
>       def p1 = req?.getParameter('myParam')
> 
> 
> 
> It's ony when I introduce the SEDA that the HttpServletRequest no longer
> exists,  (I think), and I am unable to obtain the HTTP parameters from the
> URL
> 
> Perhaps I should be copying the HTTP parameters to Camel message
> properties?  That way my bean can be less dependent on the HTTP protocol.
Yes, that could be another solution.
> 
> Is that something someone would be able to give me an example of please?  Is
> there a built-in way to auto populate Camel message properties with HTTP
> properties
> 
> Alternatively, sticking with HTTP aware bean,I just get null using:
> 
> println exchange.getProperty(Exchange.HTTP_QUERY)
> or
> println exchange.getIn().getProperty(Exchange.HTTP_QUERY)
> 
The HTTP_QUERY is a message header.
You can get it like this
  exchange.getIn().getHeader(Exchange.HTTP_QUERY)
> 
> 
> Regards
> Wayne
> 

Willem

Re: passing the HTTPServletRequest from Jetty to a SEDA consumer in Spring DSL

Posted by Wayne Keenan <wa...@gmail.com>.
Hi,

Thanks for replying.

On Wed, Jan 20, 2010 at 3:28 PM, Willem Jiang <wi...@gmail.com>wrote:

> Hi,
>
> Can you try to set the ID into the message header instead of the message
> body ? In this way you can the Request object back :)
>
>
> >>        <route>
> >>             <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
> >>             <inOnly uri="seda:sendASync"/>
> >>             <setHeader headerName="id">
> >>                  <simple>${id}</simple>
> >>             </setHeader>
>
> >>         </route>
> >>
> >>         <route>
> >>             <from uri="seda:sendASync"/>
> >>             <to uri="bean:myBean"/>
> >>         </route>
>
> You bean's method could
> public String controller(@Header("id")String body, Exchange exchange) ;
>
>
>
The request body contains base64 encoded POST I want.

I can get to the body, url paramters and the ID ok without the intermediate
SEDA route, in the bean I have:


      HttpServletRequest req =
exchange.getIn().getBody(HttpServletRequest.class);

      def corrId = exchange.getIn().getMessageId()

I also can get to the URL (not form encoded) parameters   (e.g. the URL is:
http://0.0.0.0:65503/endpoint?myParam=value) by using:

      def p1 = req?.getParameter('myParam')



It's ony when I introduce the SEDA that the HttpServletRequest no longer
exists,  (I think), and I am unable to obtain the HTTP parameters from the
URL

Perhaps I should be copying the HTTP parameters to Camel message
properties?  That way my bean can be less dependent on the HTTP protocol.

Is that something someone would be able to give me an example of please?  Is
there a built-in way to auto populate Camel message properties with HTTP
properties

Alternatively, sticking with HTTP aware bean,I just get null using:

println exchange.getProperty(Exchange.HTTP_QUERY)
or
println exchange.getIn().getProperty(Exchange.HTTP_QUERY)



Regards
Wayne



> Willem
>
>
> Wayne Keenan wrote:
>
>> Hi,
>>
>> Apologies, I didn't word my previous email very well; what I should have
>> also mentioned for clarity is that if I do this:
>>
>>        <route>
>>            <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>>            <to uri="bean:myBean"/>
>>            <transform>
>>                <simple>${id}</simple>
>>            </transform>
>>        </route>
>>
>> The same bean is able to obtain the HTTPServletRequest to get the POST
>> data
>> (base64 encoded binary) andthe URL parameters,  however,  if I introduce
>> the
>> SEDA
>> call the same bean can't get the HTTPServletRequest. The salient bean code
>> is:
>>
>>  public String controller(String body, Exchange exchange) {
>>
>>    try {
>>      HttpServletRequest req =
>> exchange.getIn().getBody(HttpServletRequest.class);
>>
>>
>> Regards
>> Wayne
>>
>> On Wed, Jan 20, 2010 at 9:02 AM, Wayne Keenan <wayne.keenan@gmail.com
>> >wrote:
>>
>>  Hi,
>>>
>>> I have a Jetty endpoint that when recieving a message will perform the
>>> processing asynchronously and syncronously return a correlationId so the
>>> client can come back later to another endpoint to see how processsing is
>>> going.
>>>
>>> I found an example on the mailing list of how to pass the HttpSession
>>> object using Java, but I can't seem to find out how
>>> to reference or pass the HttpRequest using SpringDSL.  What I have at the
>>> moment is:
>>>
>>>
>>>        <route>
>>>            <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>>>            <inOnly uri="seda:sendASync"/>
>>>            <transform>
>>>                <simple>${id}</simple>
>>>            </transform>
>>>        </route>
>>>
>>>        <route>
>>>            <from uri="seda:sendASync"/>
>>>            <to uri="bean:myBean"/>
>>>        </route>
>>>
>>> Is there a way to say 'pass the HTTP stuff through please Mr SEDA'?
>>> Should I really be setting a header property to that of a HTTP Object?
>>>  How
>>> do I obtain it?
>>> Should I architect this differently?
>>>
>>> All the best,
>>> Wayne
>>>
>>>
>>
>

Re: passing the HTTPServletRequest from Jetty to a SEDA consumer in Spring DSL

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

Can you try to set the ID into the message header instead of the message 
body ? In this way you can the Request object back :)

 >>        <route>
 >>             <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
 >>             <inOnly uri="seda:sendASync"/>
 >>             <setHeader headerName="id">
 >>                  <simple>${id}</simple>
 >>             </setHeader>
 >>         </route>
 >>
 >>         <route>
 >>             <from uri="seda:sendASync"/>
 >>             <to uri="bean:myBean"/>
 >>         </route>

You bean's method could
public String controller(@Header("id")String body, Exchange exchange) ;


Willem

Wayne Keenan wrote:
> Hi,
> 
> Apologies, I didn't word my previous email very well; what I should have
> also mentioned for clarity is that if I do this:
> 
>         <route>
>             <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>             <to uri="bean:myBean"/>
>             <transform>
>                 <simple>${id}</simple>
>             </transform>
>         </route>
> 
> The same bean is able to obtain the HTTPServletRequest to get the POST data
> (base64 encoded binary) andthe URL parameters,  however,  if I introduce the
> SEDA
> call the same bean can't get the HTTPServletRequest. The salient bean code
> is:
> 
>  public String controller(String body, Exchange exchange) {
> 
>     try {
>       HttpServletRequest req =
> exchange.getIn().getBody(HttpServletRequest.class);
> 
> 
> Regards
> Wayne
> 
> On Wed, Jan 20, 2010 at 9:02 AM, Wayne Keenan <wa...@gmail.com>wrote:
> 
>> Hi,
>>
>> I have a Jetty endpoint that when recieving a message will perform the
>> processing asynchronously and syncronously return a correlationId so the
>> client can come back later to another endpoint to see how processsing is
>> going.
>>
>> I found an example on the mailing list of how to pass the HttpSession
>> object using Java, but I can't seem to find out how
>> to reference or pass the HttpRequest using SpringDSL.  What I have at the
>> moment is:
>>
>>
>>         <route>
>>             <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>>             <inOnly uri="seda:sendASync"/>
>>             <transform>
>>                 <simple>${id}</simple>
>>             </transform>
>>         </route>
>>
>>         <route>
>>             <from uri="seda:sendASync"/>
>>             <to uri="bean:myBean"/>
>>         </route>
>>
>> Is there a way to say 'pass the HTTP stuff through please Mr SEDA'?
>> Should I really be setting a header property to that of a HTTP Object?  How
>> do I obtain it?
>> Should I architect this differently?
>>
>> All the best,
>> Wayne
>>
> 


Re: passing the HTTPServletRequest from Jetty to a SEDA consumer in Spring DSL

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 20, 2010 at 10:40 AM, Wayne Keenan <wa...@gmail.com> wrote:
> Hi,
>
> Apologies, I didn't word my previous email very well; what I should have
> also mentioned for clarity is that if I do this:
>
>        <route>
>            <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>            <to uri="bean:myBean"/>
>            <transform>
>                <simple>${id}</simple>
>            </transform>
>        </route>
>
> The same bean is able to obtain the HTTPServletRequest to get the POST data
> (base64 encoded binary) andthe URL parameters,  however,  if I introduce the
> SEDA
> call the same bean can't get the HTTPServletRequest. The salient bean code
> is:
>
>  public String controller(String body, Exchange exchange) {
>
>    try {
>      HttpServletRequest req =
> exchange.getIn().getBody(HttpServletRequest.class);
>
>
> Regards
> Wayne
>

Well you have to be careful now if you want to access
HttpServletRequest from another thread since the original
request/response could have been terminated (HttpSession is closed)
etc.

So I would suggest that you up-front gather the stuff you need from
HttpServletRequest *before* you send back that correlation id
response.
Then you are independent of the HttpSession and you can take all the
time on the world to process the message.





> On Wed, Jan 20, 2010 at 9:02 AM, Wayne Keenan <wa...@gmail.com>wrote:
>
>> Hi,
>>
>> I have a Jetty endpoint that when recieving a message will perform the
>> processing asynchronously and syncronously return a correlationId so the
>> client can come back later to another endpoint to see how processsing is
>> going.
>>
>> I found an example on the mailing list of how to pass the HttpSession
>> object using Java, but I can't seem to find out how
>> to reference or pass the HttpRequest using SpringDSL.  What I have at the
>> moment is:
>>
>>
>>         <route>
>>             <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>>             <inOnly uri="seda:sendASync"/>
>>             <transform>
>>                 <simple>${id}</simple>
>>             </transform>
>>         </route>
>>
>>         <route>
>>             <from uri="seda:sendASync"/>
>>             <to uri="bean:myBean"/>
>>         </route>
>>
>> Is there a way to say 'pass the HTTP stuff through please Mr SEDA'?
>> Should I really be setting a header property to that of a HTTP Object?  How
>> do I obtain it?
>> Should I architect this differently?
>>
>> All the best,
>> Wayne
>>
>



-- 
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: passing the HTTPServletRequest from Jetty to a SEDA consumer in Spring DSL

Posted by Wayne Keenan <wa...@gmail.com>.
Hi,

Apologies, I didn't word my previous email very well; what I should have
also mentioned for clarity is that if I do this:

        <route>
            <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
            <to uri="bean:myBean"/>
            <transform>
                <simple>${id}</simple>
            </transform>
        </route>

The same bean is able to obtain the HTTPServletRequest to get the POST data
(base64 encoded binary) andthe URL parameters,  however,  if I introduce the
SEDA
call the same bean can't get the HTTPServletRequest. The salient bean code
is:

 public String controller(String body, Exchange exchange) {

    try {
      HttpServletRequest req =
exchange.getIn().getBody(HttpServletRequest.class);


Regards
Wayne

On Wed, Jan 20, 2010 at 9:02 AM, Wayne Keenan <wa...@gmail.com>wrote:

> Hi,
>
> I have a Jetty endpoint that when recieving a message will perform the
> processing asynchronously and syncronously return a correlationId so the
> client can come back later to another endpoint to see how processsing is
> going.
>
> I found an example on the mailing list of how to pass the HttpSession
> object using Java, but I can't seem to find out how
> to reference or pass the HttpRequest using SpringDSL.  What I have at the
> moment is:
>
>
>         <route>
>             <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>             <inOnly uri="seda:sendASync"/>
>             <transform>
>                 <simple>${id}</simple>
>             </transform>
>         </route>
>
>         <route>
>             <from uri="seda:sendASync"/>
>             <to uri="bean:myBean"/>
>         </route>
>
> Is there a way to say 'pass the HTTP stuff through please Mr SEDA'?
> Should I really be setting a header property to that of a HTTP Object?  How
> do I obtain it?
> Should I architect this differently?
>
> All the best,
> Wayne
>

Re: passing the HTTPServletRequest from Jetty to a SEDA consumer in Spring DSL

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

Please always write which version of Camel you are using.
And others listening in, do that as well. Its important for us to know!


On Wed, Jan 20, 2010 at 10:02 AM, Wayne Keenan <wa...@gmail.com> wrote:
> Hi,
>
> I have a Jetty endpoint that when recieving a message will perform the
> processing asynchronously and syncronously return a correlationId so the
> client can come back later to another endpoint to see how processsing is
> going.
>
> I found an example on the mailing list of how to pass the HttpSession object
> using Java, but I can't seem to find out how
> to reference or pass the HttpRequest using SpringDSL.  What I have at the
> moment is:
>
>
>        <route>
>            <from uri="jetty:http://0.0.0.0:8080/endpoint"/>
>            <inOnly uri="seda:sendASync"/>
>            <transform>
>                <simple>${id}</simple>
>            </transform>
>        </route>
>
>        <route>
>            <from uri="seda:sendASync"/>
>            <to uri="bean:myBean"/>
>        </route>
>
> Is there a way to say 'pass the HTTP stuff through please Mr SEDA'?
> Should I really be setting a header property to that of a HTTP Object?  How
> do I obtain it?
> Should I architect this differently?
>
> All the best,
> Wayne
>



-- 
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