You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Charles Moulliard <cm...@gmail.com> on 2011/01/11 12:31:18 UTC

Error with Body type (camel 2.4)

Hi,

I have created a unit test using camel-2.4 to send HTTP request to a
Jetty Server deployed on SMX4. It works fine when I create an HTTP
request from my browser but get the following error when running the
test

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.055
sec <<< FAILURE!
testHttpRouteWithMessageHeader(com.isightpartners.streaming.RouteTest)
 Time elapsed: 1.019 sec  <<< ERROR!
org.apache.camel.CamelExecutionException: Exception occurred during
execution on the exchange: Exchange[Message: [Body is instance of
java.io.InputStream]]
	at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1149)
	at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:452)
	at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:441)
	at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:169)
	at org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeader(DefaultProducerTemplate.java:287)
	at com.isightpartners.streaming.RouteTest.testHttpClient(RouteTest.java:41)
	at com.isightpartners.streaming.RouteTest.testHttpRouteWithMessageHeader(RouteTest.java:31)

Caused by: org.apache.camel.component.http.HttpOperationFailedException:
HTTP operation failed invoking http://localhost:9090/upload) with
statusCode: 404
	at org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:157)
	at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:99)
	at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
	at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
	at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:104)
	at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:272)
	at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:98)


Is it because the class used to stream the content has changed between
camel 2.4 and camel 2.5 ?

    private void testHttpClient(String uri) throws Exception {
        System.getProperties().put("HTTPClient.dontChunkRequests", "yes");

        MockEndpoint mockEndpoint = getMockEndpoint("mock:a");
        mockEndpoint.expectedBodiesReceived("<html><body>Book 123 is
Camel in Action</body></html>");

        template.requestBodyAndHeader(uri, new
ByteArrayInputStream("This is a test".getBytes()), "Content-Type",
"application/xml");

        mockEndpoint.assertIsSatisfied();
        List<Exchange> list = mockEndpoint.getReceivedExchanges();
        Exchange exchange = list.get(0);
        assertNotNull("exchange", exchange);

        Message in = exchange.getIn();
        assertNotNull("in", in);

        Map<String, Object> headers = in.getHeaders();

        log.info("Headers: " + headers);

        assertTrue("Should be more than one header but was: " +
headers, headers.size() > 0);

        // should get the Content-Length
        // assertNotNull("Should get the content-lenghth ",
headers.get("Content-Length"));
    }


    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() {

                errorHandler(noErrorHandler());

                from("direct:start")
                  .to("http://localhost:9090/upload)")
                     .convertBodyTo(String.class)
                        .to("mock:a");
            }
        };
    }

Regards,


Charles Moulliard

Sr. Principal Solution Architect - FuseSource
Apache Committer

Blog : http://cmoulliard.blogspot.com
Twitter : http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard
Skype: cmoulliard

Re: Error with Body type (camel 2.4)

Posted by Claus Ibsen <cl...@gmail.com>.
Yeah ah 4xx error code is on the client side :)


On Tue, Jan 11, 2011 at 1:08 PM, Charles Moulliard <cm...@gmail.com> wrote:
> FORGET MY EMAIL. THERE WAS AN ERROR IN MY SYNTAX
>
> from("direct:start")
>  .to("http://localhost:9090/upload)")
>
> SHOULD BE
>
> from("direct:start")
> .to("http://localhost:9090/upload")
>
> ) parenthesis was added
>
>
> On Tue, Jan 11, 2011 at 12:31 PM, Charles Moulliard
> <cm...@gmail.com> wrote:
>> Hi,
>>
>> I have created a unit test using camel-2.4 to send HTTP request to a
>> Jetty Server deployed on SMX4. It works fine when I create an HTTP
>> request from my browser but get the following error when running the
>> test
>>
>> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.055
>> sec <<< FAILURE!
>> testHttpRouteWithMessageHeader(com.isightpartners.streaming.RouteTest)
>>  Time elapsed: 1.019 sec  <<< ERROR!
>> org.apache.camel.CamelExecutionException: Exception occurred during
>> execution on the exchange: Exchange[Message: [Body is instance of
>> java.io.InputStream]]
>>        at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1149)
>>        at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:452)
>>        at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:441)
>>        at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:169)
>>        at org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeader(DefaultProducerTemplate.java:287)
>>        at com.isightpartners.streaming.RouteTest.testHttpClient(RouteTest.java:41)
>>        at com.isightpartners.streaming.RouteTest.testHttpRouteWithMessageHeader(RouteTest.java:31)
>>
>> Caused by: org.apache.camel.component.http.HttpOperationFailedException:
>> HTTP operation failed invoking http://localhost:9090/upload) with
>> statusCode: 404
>>        at org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:157)
>>        at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:99)
>>        at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
>>        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
>>        at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:104)
>>        at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:272)
>>        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:98)
>>
>>
>> Is it because the class used to stream the content has changed between
>> camel 2.4 and camel 2.5 ?
>>
>>    private void testHttpClient(String uri) throws Exception {
>>        System.getProperties().put("HTTPClient.dontChunkRequests", "yes");
>>
>>        MockEndpoint mockEndpoint = getMockEndpoint("mock:a");
>>        mockEndpoint.expectedBodiesReceived("<html><body>Book 123 is
>> Camel in Action</body></html>");
>>
>>        template.requestBodyAndHeader(uri, new
>> ByteArrayInputStream("This is a test".getBytes()), "Content-Type",
>> "application/xml");
>>
>>        mockEndpoint.assertIsSatisfied();
>>        List<Exchange> list = mockEndpoint.getReceivedExchanges();
>>        Exchange exchange = list.get(0);
>>        assertNotNull("exchange", exchange);
>>
>>        Message in = exchange.getIn();
>>        assertNotNull("in", in);
>>
>>        Map<String, Object> headers = in.getHeaders();
>>
>>        log.info("Headers: " + headers);
>>
>>        assertTrue("Should be more than one header but was: " +
>> headers, headers.size() > 0);
>>
>>        // should get the Content-Length
>>        // assertNotNull("Should get the content-lenghth ",
>> headers.get("Content-Length"));
>>    }
>>
>>
>>    protected RouteBuilder createRouteBuilder() throws Exception {
>>        return new RouteBuilder() {
>>            public void configure() {
>>
>>                errorHandler(noErrorHandler());
>>
>>                from("direct:start")
>>                  .to("http://localhost:9090/upload)")
>>                     .convertBodyTo(String.class)
>>                        .to("mock:a");
>>            }
>>        };
>>    }
>>
>> Regards,
>>
>>
>> Charles Moulliard
>>
>> Sr. Principal Solution Architect - FuseSource
>> Apache Committer
>>
>> Blog : http://cmoulliard.blogspot.com
>> Twitter : http://twitter.com/cmoulliard
>> Linkedin : http://www.linkedin.com/in/charlesmoulliard
>> Skype: cmoulliard
>>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Error with Body type (camel 2.4)

Posted by Charles Moulliard <cm...@gmail.com>.
FORGET MY EMAIL. THERE WAS AN ERROR IN MY SYNTAX

from("direct:start")
 .to("http://localhost:9090/upload)")

SHOULD BE

from("direct:start")
.to("http://localhost:9090/upload")

) parenthesis was added


On Tue, Jan 11, 2011 at 12:31 PM, Charles Moulliard
<cm...@gmail.com> wrote:
> Hi,
>
> I have created a unit test using camel-2.4 to send HTTP request to a
> Jetty Server deployed on SMX4. It works fine when I create an HTTP
> request from my browser but get the following error when running the
> test
>
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.055
> sec <<< FAILURE!
> testHttpRouteWithMessageHeader(com.isightpartners.streaming.RouteTest)
>  Time elapsed: 1.019 sec  <<< ERROR!
> org.apache.camel.CamelExecutionException: Exception occurred during
> execution on the exchange: Exchange[Message: [Body is instance of
> java.io.InputStream]]
>        at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1149)
>        at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:452)
>        at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:441)
>        at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:169)
>        at org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeader(DefaultProducerTemplate.java:287)
>        at com.isightpartners.streaming.RouteTest.testHttpClient(RouteTest.java:41)
>        at com.isightpartners.streaming.RouteTest.testHttpRouteWithMessageHeader(RouteTest.java:31)
>
> Caused by: org.apache.camel.component.http.HttpOperationFailedException:
> HTTP operation failed invoking http://localhost:9090/upload) with
> statusCode: 404
>        at org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:157)
>        at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:99)
>        at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
>        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
>        at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:104)
>        at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:272)
>        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:98)
>
>
> Is it because the class used to stream the content has changed between
> camel 2.4 and camel 2.5 ?
>
>    private void testHttpClient(String uri) throws Exception {
>        System.getProperties().put("HTTPClient.dontChunkRequests", "yes");
>
>        MockEndpoint mockEndpoint = getMockEndpoint("mock:a");
>        mockEndpoint.expectedBodiesReceived("<html><body>Book 123 is
> Camel in Action</body></html>");
>
>        template.requestBodyAndHeader(uri, new
> ByteArrayInputStream("This is a test".getBytes()), "Content-Type",
> "application/xml");
>
>        mockEndpoint.assertIsSatisfied();
>        List<Exchange> list = mockEndpoint.getReceivedExchanges();
>        Exchange exchange = list.get(0);
>        assertNotNull("exchange", exchange);
>
>        Message in = exchange.getIn();
>        assertNotNull("in", in);
>
>        Map<String, Object> headers = in.getHeaders();
>
>        log.info("Headers: " + headers);
>
>        assertTrue("Should be more than one header but was: " +
> headers, headers.size() > 0);
>
>        // should get the Content-Length
>        // assertNotNull("Should get the content-lenghth ",
> headers.get("Content-Length"));
>    }
>
>
>    protected RouteBuilder createRouteBuilder() throws Exception {
>        return new RouteBuilder() {
>            public void configure() {
>
>                errorHandler(noErrorHandler());
>
>                from("direct:start")
>                  .to("http://localhost:9090/upload)")
>                     .convertBodyTo(String.class)
>                        .to("mock:a");
>            }
>        };
>    }
>
> Regards,
>
>
> Charles Moulliard
>
> Sr. Principal Solution Architect - FuseSource
> Apache Committer
>
> Blog : http://cmoulliard.blogspot.com
> Twitter : http://twitter.com/cmoulliard
> Linkedin : http://www.linkedin.com/in/charlesmoulliard
> Skype: cmoulliard
>