You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Paul Lowry <pl...@newbay.com> on 2011/03/29 11:20:37 UTC
restlet consumer overrides http producer's endpoint
Hi all,
I think there is a bug in camel-restlet, but I'd like to pass it by you
first and see what you think...
I define a route with a restlet consumer and http producer:
<route>
<from uri="restlet:http://localhost:9090/proxy?restletMethod=POST"/>
...
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<setHeader headerName="Content-Type">
<constant>text/xml</constant>
</setHeader>
<to uri="http://localhost:8080/server"/>
</route>
I deploy this route in Tomcat, and the logs indicate that it has
connected to both endpoints:
HttpClient DEBUG Java version: 1.6.0_23
....
HttpProducer DEBUG Starting producer:
Producer[http://localhost:8080/server]
....
RestletConsumer DEBUG Starting consumer:
Consumer[http://localhost:9090/proxy]
RestletComponent DEBUG Added server: localhost:9090
....
DefaultCamelContext INFO Apache Camel 2.4.0 started in 1.001 seconds
The restlet consumer accepts a message on port 8080:
MethodBasedRouter DEBUG MethodRouter (/proxy) received request method:
POST
RestletConsumer DEBUG Consumer restlet handle request method: POST
....
The send processor opens a connection to port 9090 (or so it says):
SendProcessor DEBUG >>>> Endpoint[http://localhost:9090/server]
....
But then things go a bit funny - the http producer opens a connection to
port 8080, and sends the message back into the restlet consumer!
HttpProducer DEBUG Executing http POST method:
http://localhost:8080/proxy
iThreadedHttpConnectionManager DEBUG
HttpConnectionManager.getConnection: config =
HostConfiguration[host=http://localhost:9090], timeout = 0
iThreadedHttpConnectionManager DEBUG Allocating new connection,
hostConfig=HostConfiguration[host=http://localhost:9090]
HttpConnection DEBUG Open connection to localhost:9090
....
The message is now stuck, having been fed from the route's http producer
back into its restlet consumer.
My guess is that the camel-restlet component configures a http
producer's connection URI, and the same http producer is recycled for
use in the camel-http component.
If this is correct, then I would suggest one of these solutions:
(1) the camel-restlet and camel-http components should each create their
own unique instance of HttpProducer and HttpConsumer
(2) the camel-restlet and camel-http components should continue to share
HttpProducer and HttpConsumer instances, but only after checking that
the endpoint URI is correct
(3) HttpProducer and HttpConsumer should be made 'smart', i.e. they
should ask their parent for an endpoint URI when invoked, compare this
URI to the current connection, and if a mismatch is found, update the
current connection by calling HttpConnectionManager.getConnection()
Opinions? Thoughts? Questions?
As for workarounds, my http producer is actually invoking a RESTful
service, so I was able to fix the problem simply by using a restlet
producer instead. But the restlet-consumer-to-http-producer is a valid
routing scenario, so the problem still needs fixing ... doesn't it?
Kind Regards,
Paul
STRICTLY PRIVATE, CONFIDENTIAL AND PRIVILEGED COMMUNICATION.
This message (including attachments) may contain information that is
privileged, confidential or protected from disclosure. They are intended
solely for the use of the intended recipient. If you are not the
intended recipient, you are hereby notified that dissemination,
disclosure, copying, distribution, printing, transmission or use of this
message or any information contained in it is strictly prohibited. If
you have received this message from NewBay Software in error, please
immediately notify the sender by reply email and delete this message
from your computer. The content of this e-mail, and any files
transmitted with it, may have been changed or altered without the
consent of the author. Although we have taken steps to ensure that this
email and attachments are free from any virus, we advise that in keeping
with good computing practice the recipient should ensure they are
actually virus free.
Re: restlet consumer overrides http producer's endpoint
Posted by Paul Lowry <pl...@newbay.com>.
Thanks Willem :)
On Fri, 2011-04-01 at 04:07 -0700, Willem Jiang wrote:
> Hi Paul,
>
> Cool. It's good to see you find a way to resolve this issue.
>
> Just one more note for the InputStreamCache, if you want to read the
> body again, you just need to call the method reset() of
> InputStreamCache.
>
> Willem
>
> On 4/1/11 5:49 PM, Paul Lowry wrote:
> > Hi Willem,
> >
> > My route looks like this:
> >
> > <route id="MyRoute">
> > <from
> uri="restlet:http://localhost:9090/client?restletMethod=POST"/>
> > <setHeader headerName="CamelHttpMethod">
> > <constant>POST</constant>
> > </setHeader>
> > <setHeader headerName="Content-Type">
> > <constant>text/xml</constant>
> > </setHeader>
> > <removeHeader headerName="CamelHttpUri"/>
> > <to uri="http://localhost:8080/server"/>
> > <process ref="MyResponseProcessor"/>
> > </route>
> >
> > The processor at the end is defined as follows:
> >
> > public class MyResponseProcessor implements Processor
> > {
> > public void process(Exchange exchange) throws Exception {
> > Message message = exchange.getIn();
> > MyJaxbType response = message.getBody(MyJaxbType.class);
> > ...
> > }
> > }
> >
> > The problem was, the http response is an InputStream, so calling
> > Message.getBody() reads the stream and thus deletes it.
> >
> > I fixed it by adding the following line to the end of the processor:
> >
> > message.setBody(response, MyJaxbType.class);
> >
> > So now all is good!
> >
> > Thanks,
> > Paul
> >
> >
>
>
> --
> Willem
> ----------------------------------
> FuseSource
> Web: http://www.fusesource.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
>
> Connect at CamelOne May 24-26
> The Open Source Integration Conference
> http://camelone.com
>
>
>
STRICTLY PRIVATE, CONFIDENTIAL AND PRIVILEGED COMMUNICATION.
This message (including attachments) may contain information that is
privileged, confidential or protected from disclosure. They are intended
solely for the use of the intended recipient. If you are not the
intended recipient, you are hereby notified that dissemination,
disclosure, copying, distribution, printing, transmission or use of this
message or any information contained in it is strictly prohibited. If
you have received this message from NewBay Software in error, please
immediately notify the sender by reply email and delete this message
from your computer. The content of this e-mail, and any files
transmitted with it, may have been changed or altered without the
consent of the author. Although we have taken steps to ensure that this
email and attachments are free from any virus, we advise that in keeping
with good computing practice the recipient should ensure they are
actually virus free.
Re: restlet consumer overrides http producer's endpoint
Posted by Willem Jiang <wi...@gmail.com>.
Hi Paul,
Cool. It's good to see you find a way to resolve this issue.
Just one more note for the InputStreamCache, if you want to read the
body again, you just need to call the method reset() of InputStreamCache.
Willem
On 4/1/11 5:49 PM, Paul Lowry wrote:
> Hi Willem,
>
> My route looks like this:
>
> <route id="MyRoute">
> <from uri="restlet:http://localhost:9090/client?restletMethod=POST"/>
> <setHeader headerName="CamelHttpMethod">
> <constant>POST</constant>
> </setHeader>
> <setHeader headerName="Content-Type">
> <constant>text/xml</constant>
> </setHeader>
> <removeHeader headerName="CamelHttpUri"/>
> <to uri="http://localhost:8080/server"/>
> <process ref="MyResponseProcessor"/>
> </route>
>
> The processor at the end is defined as follows:
>
> public class MyResponseProcessor implements Processor
> {
> public void process(Exchange exchange) throws Exception {
> Message message = exchange.getIn();
> MyJaxbType response = message.getBody(MyJaxbType.class);
> ...
> }
> }
>
> The problem was, the http response is an InputStream, so calling
> Message.getBody() reads the stream and thus deletes it.
>
> I fixed it by adding the following line to the end of the processor:
>
> message.setBody(response, MyJaxbType.class);
>
> So now all is good!
>
> Thanks,
> Paul
>
>
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Connect at CamelOne May 24-26
The Open Source Integration Conference
http://camelone.com
Re: restlet consumer overrides http producer's endpoint
Posted by Paul Lowry <pl...@newbay.com>.
Hi Willem,
My route looks like this:
<route id="MyRoute">
<from uri="restlet:http://localhost:9090/client?restletMethod=POST"/>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<setHeader headerName="Content-Type">
<constant>text/xml</constant>
</setHeader>
<removeHeader headerName="CamelHttpUri"/>
<to uri="http://localhost:8080/server"/>
<process ref="MyResponseProcessor"/>
</route>
The processor at the end is defined as follows:
public class MyResponseProcessor implements Processor
{
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
MyJaxbType response = message.getBody(MyJaxbType.class);
...
}
}
The problem was, the http response is an InputStream, so calling
Message.getBody() reads the stream and thus deletes it.
I fixed it by adding the following line to the end of the processor:
message.setBody(response, MyJaxbType.class);
So now all is good!
Thanks,
Paul
On Fri, 2011-04-01 at 01:42 -0700, Willem Jiang wrote:
> Hi Paul,
>
> Can you check the response from the outside server is right.
> I guess the issue of converting the InputStreamCache object to
> Document
> could be caused by the server didn't send the reply message rightly.
>
> Willem
>
> On 4/1/11 4:10 PM, Paul Lowry wrote:
> > Hi Willem,
> >
> > I did what you suggested and got another error...
> >
> > DefaultTypeConverter DEBUG No type converter available to convert
> from
> > type: org.apache.camel.converter.stream.InputStreamCache to the
> required
> > type: org.w3c.dom.Document with value
> > org.apache.camel.converter.stream.InputStreamCache@1cb4cae Caused
> by:
> > org.xml.sax.SAXParseException: Premature end of file.. Will ignore
> this
> > and continue.
> >
> > DefaultErrorHandler DEBUG Failed delivery for exchangeId:
> > 04ff6403-4294-4152-b81e-6c3da8849a26. On delivery attempt: 0 caught:
> > java.lang.ClassCastException:
> > org.apache.camel.converter.stream.InputStreamCache cannot be cast to
> > org.w3c.dom.Node
> >
> > DefaultErrorHandler ERROR Failed delivery for exchangeId:
> > 04ff6403-4294-4152-b81e-6c3da8849a26. Exhausted after delivery
> attempt:
> > 1 caught: java.lang.ClassCastException:
> > org.apache.camel.converter.stream.InputStreamCache cannot be cast to
> > org.w3c.dom.Node
> >
> > But this is OK, because I understand it; I just need to (a) convert
> the
> > body in a processor, or (b) add a new type converter to the http
> > component - right?
> >
> > Regard,
> > Paul
> >
> >
> > On Tue, 2011-03-29 at 22:56 -0700, Willem Jiang wrote:
> >> <removeHeader headerName="CamelHttpUri"/>
> >> > <to uri="http://localhost:8080/server"/>
> >
> > STRICTLY PRIVATE, CONFIDENTIAL AND PRIVILEGED COMMUNICATION.
> >
> > This message (including attachments) may contain information that is
> > privileged, confidential or protected from disclosure. They are
> intended
> > solely for the use of the intended recipient. If you are not the
> > intended recipient, you are hereby notified that dissemination,
> > disclosure, copying, distribution, printing, transmission or use of
> this
> > message or any information contained in it is strictly prohibited.
> If
> > you have received this message from NewBay Software in error, please
> > immediately notify the sender by reply email and delete this message
> > from your computer. The content of this e-mail, and any files
> > transmitted with it, may have been changed or altered without the
> > consent of the author. Although we have taken steps to ensure that
> this
> > email and attachments are free from any virus, we advise that in
> keeping
> > with good computing practice the recipient should ensure they are
> > actually virus free.
>
>
> --
> Willem
> ----------------------------------
> FuseSource
> Web: http://www.fusesource.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
>
> Connect at CamelOne May 24-26
> The Open Source Integration Conference
> http://camelone.com
>
>
>
STRICTLY PRIVATE, CONFIDENTIAL AND PRIVILEGED COMMUNICATION.
This message (including attachments) may contain information that is
privileged, confidential or protected from disclosure. They are intended
solely for the use of the intended recipient. If you are not the
intended recipient, you are hereby notified that dissemination,
disclosure, copying, distribution, printing, transmission or use of this
message or any information contained in it is strictly prohibited. If
you have received this message from NewBay Software in error, please
immediately notify the sender by reply email and delete this message
from your computer. The content of this e-mail, and any files
transmitted with it, may have been changed or altered without the
consent of the author. Although we have taken steps to ensure that this
email and attachments are free from any virus, we advise that in keeping
with good computing practice the recipient should ensure they are
actually virus free.
Re: restlet consumer overrides http producer's endpoint
Posted by Willem Jiang <wi...@gmail.com>.
Hi Paul,
Can you check the response from the outside server is right.
I guess the issue of converting the InputStreamCache object to Document
could be caused by the server didn't send the reply message rightly.
Willem
On 4/1/11 4:10 PM, Paul Lowry wrote:
> Hi Willem,
>
> I did what you suggested and got another error...
>
> DefaultTypeConverter DEBUG No type converter available to convert from
> type: org.apache.camel.converter.stream.InputStreamCache to the required
> type: org.w3c.dom.Document with value
> org.apache.camel.converter.stream.InputStreamCache@1cb4cae Caused by:
> org.xml.sax.SAXParseException: Premature end of file.. Will ignore this
> and continue.
>
> DefaultErrorHandler DEBUG Failed delivery for exchangeId:
> 04ff6403-4294-4152-b81e-6c3da8849a26. On delivery attempt: 0 caught:
> java.lang.ClassCastException:
> org.apache.camel.converter.stream.InputStreamCache cannot be cast to
> org.w3c.dom.Node
>
> DefaultErrorHandler ERROR Failed delivery for exchangeId:
> 04ff6403-4294-4152-b81e-6c3da8849a26. Exhausted after delivery attempt:
> 1 caught: java.lang.ClassCastException:
> org.apache.camel.converter.stream.InputStreamCache cannot be cast to
> org.w3c.dom.Node
>
> But this is OK, because I understand it; I just need to (a) convert the
> body in a processor, or (b) add a new type converter to the http
> component - right?
>
> Regard,
> Paul
>
>
> On Tue, 2011-03-29 at 22:56 -0700, Willem Jiang wrote:
>> <removeHeader headerName="CamelHttpUri"/>
>> > <to uri="http://localhost:8080/server"/>
>
> STRICTLY PRIVATE, CONFIDENTIAL AND PRIVILEGED COMMUNICATION.
>
> This message (including attachments) may contain information that is
> privileged, confidential or protected from disclosure. They are intended
> solely for the use of the intended recipient. If you are not the
> intended recipient, you are hereby notified that dissemination,
> disclosure, copying, distribution, printing, transmission or use of this
> message or any information contained in it is strictly prohibited. If
> you have received this message from NewBay Software in error, please
> immediately notify the sender by reply email and delete this message
> from your computer. The content of this e-mail, and any files
> transmitted with it, may have been changed or altered without the
> consent of the author. Although we have taken steps to ensure that this
> email and attachments are free from any virus, we advise that in keeping
> with good computing practice the recipient should ensure they are
> actually virus free.
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Connect at CamelOne May 24-26
The Open Source Integration Conference
http://camelone.com
Re: restlet consumer overrides http producer's endpoint
Posted by Paul Lowry <pl...@newbay.com>.
Hi Willem,
I did what you suggested and got another error...
DefaultTypeConverter DEBUG No type converter available to convert from
type: org.apache.camel.converter.stream.InputStreamCache to the required
type: org.w3c.dom.Document with value
org.apache.camel.converter.stream.InputStreamCache@1cb4cae Caused by:
org.xml.sax.SAXParseException: Premature end of file.. Will ignore this
and continue.
DefaultErrorHandler DEBUG Failed delivery for exchangeId:
04ff6403-4294-4152-b81e-6c3da8849a26. On delivery attempt: 0 caught:
java.lang.ClassCastException:
org.apache.camel.converter.stream.InputStreamCache cannot be cast to
org.w3c.dom.Node
DefaultErrorHandler ERROR Failed delivery for exchangeId:
04ff6403-4294-4152-b81e-6c3da8849a26. Exhausted after delivery attempt:
1 caught: java.lang.ClassCastException:
org.apache.camel.converter.stream.InputStreamCache cannot be cast to
org.w3c.dom.Node
But this is OK, because I understand it; I just need to (a) convert the
body in a processor, or (b) add a new type converter to the http
component - right?
Regard,
Paul
On Tue, 2011-03-29 at 22:56 -0700, Willem Jiang wrote:
> <removeHeader headerName="CamelHttpUri"/>
> > <to uri="http://localhost:8080/server"/>
STRICTLY PRIVATE, CONFIDENTIAL AND PRIVILEGED COMMUNICATION.
This message (including attachments) may contain information that is
privileged, confidential or protected from disclosure. They are intended
solely for the use of the intended recipient. If you are not the
intended recipient, you are hereby notified that dissemination,
disclosure, copying, distribution, printing, transmission or use of this
message or any information contained in it is strictly prohibited. If
you have received this message from NewBay Software in error, please
immediately notify the sender by reply email and delete this message
from your computer. The content of this e-mail, and any files
transmitted with it, may have been changed or altered without the
consent of the author. Although we have taken steps to ensure that this
email and attachments are free from any virus, we advise that in keeping
with good computing practice the recipient should ensure they are
actually virus free.
Re: restlet consumer overrides http producer's endpoint
Posted by Willem Jiang <wi...@gmail.com>.
Hi,
I think you just need to filter the message header of Exchange.HTTP_URI,
which will be used by the HttpProducer to override the configuration on
the Http endpoint. And the RestLetProducer doesn't take that header into
consideration.
Your route could be like below to workaround such kind of issue.
> <route>
> <from uri="restlet:http://localhost:9090/proxy?restletMethod=POST"/>
> ...
> <setHeader headerName="CamelHttpMethod">
> <constant>POST</constant>
> </setHeader>
> <setHeader headerName="Content-Type">
> <constant>text/xml</constant>
> </setHeader>
// please add this line into your route
<removeHeader headerName="CamelHttpUri"/>
> <to uri="http://localhost:8080/server"/>
> </route>
Willem
On 3/29/11 5:20 PM, Paul Lowry wrote:
> Hi all,
>
> I think there is a bug in camel-restlet, but I'd like to pass it by you
> first and see what you think...
>
>
> I define a route with a restlet consumer and http producer:
> <route>
> <from uri="restlet:http://localhost:9090/proxy?restletMethod=POST"/>
> ...
> <setHeader headerName="CamelHttpMethod">
> <constant>POST</constant>
> </setHeader>
> <setHeader headerName="Content-Type">
> <constant>text/xml</constant>
> </setHeader>
> <to uri="http://localhost:8080/server"/>
> </route>
>
>
> I deploy this route in Tomcat, and the logs indicate that it has
> connected to both endpoints:
> HttpClient DEBUG Java version: 1.6.0_23
> ....
> HttpProducer DEBUG Starting producer:
> Producer[http://localhost:8080/server]
> ....
> RestletConsumer DEBUG Starting consumer:
> Consumer[http://localhost:9090/proxy]
> RestletComponent DEBUG Added server: localhost:9090
> ....
> DefaultCamelContext INFO Apache Camel 2.4.0 started in 1.001 seconds
>
>
> The restlet consumer accepts a message on port 8080:
> MethodBasedRouter DEBUG MethodRouter (/proxy) received request method:
> POST
> RestletConsumer DEBUG Consumer restlet handle request method: POST
> ....
>
>
> The send processor opens a connection to port 9090 (or so it says):
> SendProcessor DEBUG>>>> Endpoint[http://localhost:9090/server]
> ....
>
>
> But then things go a bit funny - the http producer opens a connection to
> port 8080, and sends the message back into the restlet consumer!
> HttpProducer DEBUG Executing http POST method:
> http://localhost:8080/proxy
> iThreadedHttpConnectionManager DEBUG
> HttpConnectionManager.getConnection: config =
> HostConfiguration[host=http://localhost:9090], timeout = 0
> iThreadedHttpConnectionManager DEBUG Allocating new connection,
> hostConfig=HostConfiguration[host=http://localhost:9090]
> HttpConnection DEBUG Open connection to localhost:9090
> ....
>
>
> The message is now stuck, having been fed from the route's http producer
> back into its restlet consumer.
>
> My guess is that the camel-restlet component configures a http
> producer's connection URI, and the same http producer is recycled for
> use in the camel-http component.
>
> If this is correct, then I would suggest one of these solutions:
> (1) the camel-restlet and camel-http components should each create their
> own unique instance of HttpProducer and HttpConsumer
> (2) the camel-restlet and camel-http components should continue to share
> HttpProducer and HttpConsumer instances, but only after checking that
> the endpoint URI is correct
> (3) HttpProducer and HttpConsumer should be made 'smart', i.e. they
> should ask their parent for an endpoint URI when invoked, compare this
> URI to the current connection, and if a mismatch is found, update the
> current connection by calling HttpConnectionManager.getConnection()
>
> Opinions? Thoughts? Questions?
>
> As for workarounds, my http producer is actually invoking a RESTful
> service, so I was able to fix the problem simply by using a restlet
> producer instead. But the restlet-consumer-to-http-producer is a valid
> routing scenario, so the problem still needs fixing ... doesn't it?
>
> Kind Regards,
>
> Paul
>
>
> STRICTLY PRIVATE, CONFIDENTIAL AND PRIVILEGED COMMUNICATION.
>
> This message (including attachments) may contain information that is
> privileged, confidential or protected from disclosure. They are intended
> solely for the use of the intended recipient. If you are not the
> intended recipient, you are hereby notified that dissemination,
> disclosure, copying, distribution, printing, transmission or use of this
> message or any information contained in it is strictly prohibited. If
> you have received this message from NewBay Software in error, please
> immediately notify the sender by reply email and delete this message
> from your computer. The content of this e-mail, and any files
> transmitted with it, may have been changed or altered without the
> consent of the author. Although we have taken steps to ensure that this
> email and attachments are free from any virus, we advise that in keeping
> with good computing practice the recipient should ensure they are
> actually virus free.
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang