You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Martin Stiborský <ma...@gmail.com> on 2013/01/04 14:23:35 UTC

Fetching webpages with CXF on the producer endpoint side

Hi,
I have a simple case - CXF as producer and based on the HTTP request
parameters, I need fetch some web page - with help of Camel HTTP component,
I guess.

For start, simple code:

from("cxfrs:bean:jenkinsServer")
.choice()
.when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
.to("http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false
")

I'd expect, that after I hit a "localhost:1234/test" in my browser, I'll
see a google.com source code, wrong :( Actually, I've got an exception:

org.apache.camel.InvalidPayloadException: No body available of type:
java.io.InputStream but has value: [] of type:
org.apache.cxf.message.MessageContentsList on: Message: []. Caused by: No
type converter available to convert from type:
org.apache.cxf.message.MessageContentsList to the required type:
java.io.InputStream with value []. Exchange[Message: []]. Caused by:
[org.apache.camel.NoTypeConversionAvailableException - No type converter
available to convert from type: org.apache.cxf.message.MessageContentsList
to the required type: java.io.InputStream with value []]

Now, after so many tries and googling, I'm not sure why and where it's
wrong...

Is there a way how to make it work? Sure I can write my own bean to
fetching data with HTTP requests, but I was thinking that Camel HTTP
component could be capable of that.

-- 
S pozdravem / Best regards
Martin Stiborský

Jabber: stibi@njs.netlab.cz
Twitter: http://www.twitter.com/stibi

Re: Fetching webpages with CXF on the producer endpoint side

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

Because when the camel-cxfrs endpoint get the request it will try to turn the request invocation into to method call, so you can get the operation name from the message header and parameters array from the the message body.

If you just want to access the google with a http get request, you don't need to set the message body.
Otherwise the camel-http producer will try to turn the message body into a output stream for you.

These could explain that when you set the message body to be a empty string, the route works for you.  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On Saturday, January 5, 2013 at 5:36 AM, Martin Stiborský wrote:

> Finally solved. About time, it was out of options anyway, it was inevitable
> to stumble over correct solution :D
> Two things, erase exchange body passed from CXF (it works but why it's like
> that?), then gzip unmarshalling (that was hard for me to find out, stupid
> me).
>  
> from("cxfrs:bean:jenkinsServer")
> .choice()
> .when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
> .setBody(constant(""))
> .to("http://www.google.com?bridgeEndpoint=true")
> .unmarshal().gzip().convertBodyTo(String.class)
>  
> Woooohoooo :)
>  
>  
> On Fri, Jan 4, 2013 at 3:07 PM, Martin Stiborský <martin.stiborsky@gmail.com (mailto:martin.stiborsky@gmail.com)
> > wrote:
>  
>  
>  
> > Maybe, it's really a CXF problem?
> > Because, it seems to me that the Camel HTTP component just does its job as
> > expected...
> > I wrote a simple test and voila - google is there :)
> > It's failing of course, I was maily curious about the body content, that's
> > why the asserting with "".
> >  
> > public class FetchWebTest extends CamelTestSupport {
> >  
> > @EndpointInject(uri = "mock:fetchWebpage")
> > protected MockEndpoint resultEndpoint;
> >  
> > @Produce(uri = "direct:start")
> > protected ProducerTemplate template;
> >  
> > @Test
> > public void testDatFetch() throws InterruptedException {
> > String expectedBody = "";
> >  
> > resultEndpoint.expectedBodiesReceived(expectedBody);
> >  
> > template.sendBodyAndHeader("", Exchange.HTTP_METHOD, "GET");
> >  
> > resultEndpoint.assertIsSatisfied();
> > }
> >  
> > @Override
> > protected RouteBuilder createRouteBuilder() {
> > return new RouteBuilder() {
> > @Override
> > public void configure() throws Exception {
> > from("direct:start").to("http://www.google.com
> > ").to("mock:fetchWebpage");
> > }
> > };
> > }
> > }
> >  
> >  
> >  
> > On Fri, Jan 4, 2013 at 1:23 PM, Martin Stiborský <
> > martin.stiborsky@gmail.com (mailto:martin.stiborsky@gmail.com)> wrote:
> >  
> > > Hi,
> > > I have a simple case - CXF as producer and based on the HTTP request
> > > parameters, I need fetch some web page - with help of Camel HTTP component,
> > > I guess.
> > >  
> > > For start, simple code:
> > >  
> > > from("cxfrs:bean:jenkinsServer")
> > > .choice()
> > > .when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
> > > .to("
> > > http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false")
> > >  
> > > I'd expect, that after I hit a "localhost:1234/test" in my browser, I'll
> > > see a google.com (http://google.com) source code, wrong :( Actually, I've got an exception:
> > >  
> > > org.apache.camel.InvalidPayloadException: No body available of type:
> > > java.io.InputStream but has value: [] of type:
> > > org.apache.cxf.message.MessageContentsList on: Message: []. Caused by: No
> > > type converter available to convert from type:
> > > org.apache.cxf.message.MessageContentsList to the required type:
> > > java.io.InputStream with value []. Exchange[Message: []]. Caused by:
> > > [org.apache.camel.NoTypeConversionAvailableException - No type converter
> > > available to convert from type: org.apache.cxf.message.MessageContentsList
> > > to the required type: java.io.InputStream with value []]
> > >  
> > > Now, after so many tries and googling, I'm not sure why and where it's
> > > wrong...
> > >  
> > > Is there a way how to make it work? Sure I can write my own bean to
> > > fetching data with HTTP requests, but I was thinking that Camel HTTP
> > > component could be capable of that.
> > >  
> > > --
> > > S pozdravem / Best regards
> > > Martin Stiborský
> > >  
> > > Jabber: stibi@njs.netlab.cz (mailto:stibi@njs.netlab.cz)
> > > Twitter: http://www.twitter.com/stibi
> >  
> >  
> >  
> >  
> >  
> > --
> > S pozdravem / Best regards
> > Martin Stiborský
> >  
> > Jabber: stibi@njs.netlab.cz (mailto:stibi@njs.netlab.cz)
> > Twitter: http://www.twitter.com/stibi
>  
>  
>  
>  
>  
> --  
> S pozdravem / Best regards
> Martin Stiborský
>  
> Jabber: stibi@njs.netlab.cz (mailto:stibi@njs.netlab.cz)
> Twitter: http://www.twitter.com/stibi




Re: Fetching webpages with CXF on the producer endpoint side

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 06/01/13 03:05, Martin Stiborský wrote:
> Hi again :)
>
> One more (last one hopefully) problem I've had is related to this:
> http://camel.465427.n5.nabble.com/Bridging-between-HTTP-endpoints-td476103.html
> Any plans/news to this? At least I can clean the headers, so it works…I'm
> just curious about current situation.

IMHO Camel 2.x is correct in getting HTTP request properties set by the 
consumer that received the initial request, those are then supposed to 
be used somehow by the follow-up consumer components, those which can 
make sense of those HTTP properties.

It does seem the Camel HTTP transport should not append the HTTP request 
bits to the outgoing URI, may be it can be configured not to at least to 
preserve BC ?

Cheers, Sergey

>
> Please guys, talk to me, I feel really alone here :)
>
>
> On Fri, Jan 4, 2013 at 10:36 PM, Martin Stiborský<
> martin.stiborsky@gmail.com>  wrote:
>
>> Finally solved. About time, it was out of options anyway, it was
>> inevitable to stumble over correct solution :D
>> Two things, erase exchange body passed from CXF (it works but why it's
>> like that?), then gzip unmarshalling (that was hard for me to find out,
>> stupid me).
>>
>> from("cxfrs:bean:jenkinsServer")
>> .choice()
>> .when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
>> .setBody(constant(""))
>> .to("http://www.google.com?bridgeEndpoint=true")
>> .unmarshal().gzip().convertBodyTo(String.class)
>>
>> Woooohoooo :)
>>
>>
>> On Fri, Jan 4, 2013 at 3:07 PM, Martin Stiborský<
>> martin.stiborsky@gmail.com>  wrote:
>>
>>> Maybe, it's really a CXF problem?
>>> Because, it seems to me that the Camel HTTP component just does its job
>>> as expected...
>>> I wrote a simple test and voila - google is there :)
>>> It's failing of course, I was maily curious about the body content,
>>> that's why the asserting with "".
>>>
>>> public class FetchWebTest extends CamelTestSupport {
>>>
>>>      @EndpointInject(uri = "mock:fetchWebpage")
>>>      protected MockEndpoint resultEndpoint;
>>>
>>>      @Produce(uri = "direct:start")
>>>      protected ProducerTemplate template;
>>>
>>>      @Test
>>>      public void testDatFetch() throws InterruptedException {
>>>          String expectedBody = "";
>>>
>>>          resultEndpoint.expectedBodiesReceived(expectedBody);
>>>
>>>          template.sendBodyAndHeader("", Exchange.HTTP_METHOD, "GET");
>>>
>>>          resultEndpoint.assertIsSatisfied();
>>>      }
>>>
>>>      @Override
>>>      protected RouteBuilder createRouteBuilder() {
>>>          return new RouteBuilder() {
>>>              @Override
>>>              public void configure() throws Exception {
>>>                  from("direct:start").to("http://www.google.com
>>> ").to("mock:fetchWebpage");
>>>              }
>>>          };
>>>      }
>>> }
>>>
>>>
>>>
>>> On Fri, Jan 4, 2013 at 1:23 PM, Martin Stiborský<
>>> martin.stiborsky@gmail.com>  wrote:
>>>
>>>> Hi,
>>>> I have a simple case - CXF as producer and based on the HTTP request
>>>> parameters, I need fetch some web page - with help of Camel HTTP component,
>>>> I guess.
>>>>
>>>> For start, simple code:
>>>>
>>>> from("cxfrs:bean:jenkinsServer")
>>>> .choice()
>>>> .when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
>>>> .to("
>>>> http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false
>>>> ")
>>>>
>>>> I'd expect, that after I hit a "localhost:1234/test" in my browser, I'll
>>>> see a google.com source code, wrong :( Actually, I've got an exception:
>>>>
>>>> org.apache.camel.InvalidPayloadException: No body available of type:
>>>> java.io.InputStream but has value: [] of type:
>>>> org.apache.cxf.message.MessageContentsList on: Message: []. Caused by: No
>>>> type converter available to convert from type:
>>>> org.apache.cxf.message.MessageContentsList to the required type:
>>>> java.io.InputStream with value []. Exchange[Message: []]. Caused by:
>>>> [org.apache.camel.NoTypeConversionAvailableException - No type converter
>>>> available to convert from type: org.apache.cxf.message.MessageContentsList
>>>> to the required type: java.io.InputStream with value []]
>>>>
>>>> Now, after so many tries and googling, I'm not sure why and where it's
>>>> wrong...
>>>>
>>>> Is there a way how to make it work? Sure I can write my own bean to
>>>> fetching data with HTTP requests, but I was thinking that Camel HTTP
>>>> component could be capable of that.
>>>>
>>>> --
>>>> S pozdravem / Best regards
>>>> Martin Stiborský
>>>>
>>>> Jabber: stibi@njs.netlab.cz
>>>> Twitter: http://www.twitter.com/stibi
>>>>
>>>
>>>
>>>
>>> --
>>> S pozdravem / Best regards
>>> Martin Stiborský
>>>
>>> Jabber: stibi@njs.netlab.cz
>>> Twitter: http://www.twitter.com/stibi
>>>
>>
>>
>>
>> --
>> S pozdravem / Best regards
>> Martin Stiborský
>>
>> Jabber: stibi@njs.netlab.cz
>> Twitter: http://www.twitter.com/stibi
>>
>
>
>


Re: Fetching webpages with CXF on the producer endpoint side

Posted by Martin Stiborský <ma...@gmail.com>.
Hi again :)

One more (last one hopefully) problem I've had is related to this:
http://camel.465427.n5.nabble.com/Bridging-between-HTTP-endpoints-td476103.html
Any plans/news to this? At least I can clean the headers, so it works…I'm
just curious about current situation.

Please guys, talk to me, I feel really alone here :)


On Fri, Jan 4, 2013 at 10:36 PM, Martin Stiborský <
martin.stiborsky@gmail.com> wrote:

> Finally solved. About time, it was out of options anyway, it was
> inevitable to stumble over correct solution :D
> Two things, erase exchange body passed from CXF (it works but why it's
> like that?), then gzip unmarshalling (that was hard for me to find out,
> stupid me).
>
> from("cxfrs:bean:jenkinsServer")
> .choice()
> .when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
> .setBody(constant(""))
> .to("http://www.google.com?bridgeEndpoint=true")
> .unmarshal().gzip().convertBodyTo(String.class)
>
> Woooohoooo :)
>
>
> On Fri, Jan 4, 2013 at 3:07 PM, Martin Stiborský <
> martin.stiborsky@gmail.com> wrote:
>
>> Maybe, it's really a CXF problem?
>> Because, it seems to me that the Camel HTTP component just does its job
>> as expected...
>> I wrote a simple test and voila - google is there :)
>> It's failing of course, I was maily curious about the body content,
>> that's why the asserting with "".
>>
>> public class FetchWebTest extends CamelTestSupport {
>>
>>     @EndpointInject(uri = "mock:fetchWebpage")
>>     protected MockEndpoint resultEndpoint;
>>
>>     @Produce(uri = "direct:start")
>>     protected ProducerTemplate template;
>>
>>     @Test
>>     public void testDatFetch() throws InterruptedException {
>>         String expectedBody = "";
>>
>>         resultEndpoint.expectedBodiesReceived(expectedBody);
>>
>>         template.sendBodyAndHeader("", Exchange.HTTP_METHOD, "GET");
>>
>>         resultEndpoint.assertIsSatisfied();
>>     }
>>
>>     @Override
>>     protected RouteBuilder createRouteBuilder() {
>>         return new RouteBuilder() {
>>             @Override
>>             public void configure() throws Exception {
>>                 from("direct:start").to("http://www.google.com
>> ").to("mock:fetchWebpage");
>>             }
>>         };
>>     }
>> }
>>
>>
>>
>> On Fri, Jan 4, 2013 at 1:23 PM, Martin Stiborský <
>> martin.stiborsky@gmail.com> wrote:
>>
>>> Hi,
>>> I have a simple case - CXF as producer and based on the HTTP request
>>> parameters, I need fetch some web page - with help of Camel HTTP component,
>>> I guess.
>>>
>>> For start, simple code:
>>>
>>> from("cxfrs:bean:jenkinsServer")
>>> .choice()
>>> .when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
>>> .to("
>>> http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false
>>> ")
>>>
>>> I'd expect, that after I hit a "localhost:1234/test" in my browser, I'll
>>> see a google.com source code, wrong :( Actually, I've got an exception:
>>>
>>> org.apache.camel.InvalidPayloadException: No body available of type:
>>> java.io.InputStream but has value: [] of type:
>>> org.apache.cxf.message.MessageContentsList on: Message: []. Caused by: No
>>> type converter available to convert from type:
>>> org.apache.cxf.message.MessageContentsList to the required type:
>>> java.io.InputStream with value []. Exchange[Message: []]. Caused by:
>>> [org.apache.camel.NoTypeConversionAvailableException - No type converter
>>> available to convert from type: org.apache.cxf.message.MessageContentsList
>>> to the required type: java.io.InputStream with value []]
>>>
>>> Now, after so many tries and googling, I'm not sure why and where it's
>>> wrong...
>>>
>>> Is there a way how to make it work? Sure I can write my own bean to
>>> fetching data with HTTP requests, but I was thinking that Camel HTTP
>>> component could be capable of that.
>>>
>>> --
>>> S pozdravem / Best regards
>>> Martin Stiborský
>>>
>>> Jabber: stibi@njs.netlab.cz
>>> Twitter: http://www.twitter.com/stibi
>>>
>>
>>
>>
>> --
>> S pozdravem / Best regards
>> Martin Stiborský
>>
>> Jabber: stibi@njs.netlab.cz
>> Twitter: http://www.twitter.com/stibi
>>
>
>
>
> --
> S pozdravem / Best regards
> Martin Stiborský
>
> Jabber: stibi@njs.netlab.cz
> Twitter: http://www.twitter.com/stibi
>



-- 
S pozdravem / Best regards
Martin Stiborský

Jabber: stibi@njs.netlab.cz
Twitter: http://www.twitter.com/stibi

Re: Fetching webpages with CXF on the producer endpoint side

Posted by Martin Stiborský <ma...@gmail.com>.
Finally solved. About time, it was out of options anyway, it was inevitable
to stumble over correct solution :D
Two things, erase exchange body passed from CXF (it works but why it's like
that?), then gzip unmarshalling (that was hard for me to find out, stupid
me).

from("cxfrs:bean:jenkinsServer")
.choice()
.when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
.setBody(constant(""))
.to("http://www.google.com?bridgeEndpoint=true")
.unmarshal().gzip().convertBodyTo(String.class)

Woooohoooo :)


On Fri, Jan 4, 2013 at 3:07 PM, Martin Stiborský <martin.stiborsky@gmail.com
> wrote:

> Maybe, it's really a CXF problem?
> Because, it seems to me that the Camel HTTP component just does its job as
> expected...
> I wrote a simple test and voila - google is there :)
> It's failing of course, I was maily curious about the body content, that's
> why the asserting with "".
>
> public class FetchWebTest extends CamelTestSupport {
>
>     @EndpointInject(uri = "mock:fetchWebpage")
>     protected MockEndpoint resultEndpoint;
>
>     @Produce(uri = "direct:start")
>     protected ProducerTemplate template;
>
>     @Test
>     public void testDatFetch() throws InterruptedException {
>         String expectedBody = "";
>
>         resultEndpoint.expectedBodiesReceived(expectedBody);
>
>         template.sendBodyAndHeader("", Exchange.HTTP_METHOD, "GET");
>
>         resultEndpoint.assertIsSatisfied();
>     }
>
>     @Override
>     protected RouteBuilder createRouteBuilder() {
>         return new RouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 from("direct:start").to("http://www.google.com
> ").to("mock:fetchWebpage");
>             }
>         };
>     }
> }
>
>
>
> On Fri, Jan 4, 2013 at 1:23 PM, Martin Stiborský <
> martin.stiborsky@gmail.com> wrote:
>
>> Hi,
>> I have a simple case - CXF as producer and based on the HTTP request
>> parameters, I need fetch some web page - with help of Camel HTTP component,
>> I guess.
>>
>> For start, simple code:
>>
>> from("cxfrs:bean:jenkinsServer")
>> .choice()
>> .when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
>> .to("
>> http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false")
>>
>> I'd expect, that after I hit a "localhost:1234/test" in my browser, I'll
>> see a google.com source code, wrong :( Actually, I've got an exception:
>>
>> org.apache.camel.InvalidPayloadException: No body available of type:
>> java.io.InputStream but has value: [] of type:
>> org.apache.cxf.message.MessageContentsList on: Message: []. Caused by: No
>> type converter available to convert from type:
>> org.apache.cxf.message.MessageContentsList to the required type:
>> java.io.InputStream with value []. Exchange[Message: []]. Caused by:
>> [org.apache.camel.NoTypeConversionAvailableException - No type converter
>> available to convert from type: org.apache.cxf.message.MessageContentsList
>> to the required type: java.io.InputStream with value []]
>>
>> Now, after so many tries and googling, I'm not sure why and where it's
>> wrong...
>>
>> Is there a way how to make it work? Sure I can write my own bean to
>> fetching data with HTTP requests, but I was thinking that Camel HTTP
>> component could be capable of that.
>>
>> --
>> S pozdravem / Best regards
>> Martin Stiborský
>>
>> Jabber: stibi@njs.netlab.cz
>> Twitter: http://www.twitter.com/stibi
>>
>
>
>
> --
> S pozdravem / Best regards
> Martin Stiborský
>
> Jabber: stibi@njs.netlab.cz
> Twitter: http://www.twitter.com/stibi
>



-- 
S pozdravem / Best regards
Martin Stiborský

Jabber: stibi@njs.netlab.cz
Twitter: http://www.twitter.com/stibi

Re: Fetching webpages with CXF on the producer endpoint side

Posted by Martin Stiborský <ma...@gmail.com>.
Maybe, it's really a CXF problem?
Because, it seems to me that the Camel HTTP component just does its job as
expected...
I wrote a simple test and voila - google is there :)
It's failing of course, I was maily curious about the body content, that's
why the asserting with "".

public class FetchWebTest extends CamelTestSupport {

    @EndpointInject(uri = "mock:fetchWebpage")
    protected MockEndpoint resultEndpoint;

    @Produce(uri = "direct:start")
    protected ProducerTemplate template;

    @Test
    public void testDatFetch() throws InterruptedException {
        String expectedBody = "";

        resultEndpoint.expectedBodiesReceived(expectedBody);

        template.sendBodyAndHeader("", Exchange.HTTP_METHOD, "GET");

        resultEndpoint.assertIsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start").to("http://www.google.com
").to("mock:fetchWebpage");
            }
        };
    }
}



On Fri, Jan 4, 2013 at 1:23 PM, Martin Stiborský <martin.stiborsky@gmail.com
> wrote:

> Hi,
> I have a simple case - CXF as producer and based on the HTTP request
> parameters, I need fetch some web page - with help of Camel HTTP component,
> I guess.
>
> For start, simple code:
>
> from("cxfrs:bean:jenkinsServer")
> .choice()
> .when(header(CxfConstants.OPERATION_NAME).isEqualTo("test"))
> .to("
> http://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false")
>
> I'd expect, that after I hit a "localhost:1234/test" in my browser, I'll
> see a google.com source code, wrong :( Actually, I've got an exception:
>
> org.apache.camel.InvalidPayloadException: No body available of type:
> java.io.InputStream but has value: [] of type:
> org.apache.cxf.message.MessageContentsList on: Message: []. Caused by: No
> type converter available to convert from type:
> org.apache.cxf.message.MessageContentsList to the required type:
> java.io.InputStream with value []. Exchange[Message: []]. Caused by:
> [org.apache.camel.NoTypeConversionAvailableException - No type converter
> available to convert from type: org.apache.cxf.message.MessageContentsList
> to the required type: java.io.InputStream with value []]
>
> Now, after so many tries and googling, I'm not sure why and where it's
> wrong...
>
> Is there a way how to make it work? Sure I can write my own bean to
> fetching data with HTTP requests, but I was thinking that Camel HTTP
> component could be capable of that.
>
> --
> S pozdravem / Best regards
> Martin Stiborský
>
> Jabber: stibi@njs.netlab.cz
> Twitter: http://www.twitter.com/stibi
>



-- 
S pozdravem / Best regards
Martin Stiborský

Jabber: stibi@njs.netlab.cz
Twitter: http://www.twitter.com/stibi