What version of Camel do you use?
On Mon, Aug 13, 2012 at 9:47 PM, pmcb55 <mcbenne...@dnb.com> wrote: > We've been using the Camel HTTP4 component for a while now, but today we > wanted to call a HTTP endpoint and pass some text as input to the endpoint. > But when we use 'exchange.getIn().setBody("Some input string...");' we got a > very unhelpful NullPointerException (i.e. no detail information, no stack > trace). The very simple code below illustrates the problem. > > To work out what was going on we had to debug into the Camel source code. We > found that the problem was the fact we passed a String as the message body > instead of an InputStream, so simply wrapping our String in a stream worked > fine. So my question is simply, why doesn't Camel provide a more helpful > error message to indicate the problem (surely it's a common newbie mistake > to provide the text body of a HTTP request as a simple String?!)? Also I > would have thought the automatic type conversions in Camel would have kicked > in to convert our String to an InputStream....??? > > > package com.cameltesting.services.httptest; > > import org.apache.camel.Exchange; > import org.apache.camel.impl.DefaultExchange; > import org.apache.camel.test.junit4.CamelTestSupport; > import org.junit.Assert; > import org.junit.Test; > > public class HttpTest extends CamelTestSupport { > @Test > public void testReport() throws Exception { > > Exchange exchange = new DefaultExchange(context()); > Exchange response = context.createProducerTemplate().send( > "http4://www.google.com?q=HelloWorld", exchange); > Assert.assertFalse(response.isFailed()); > > exchange = new DefaultExchange(context()); > exchange.getIn().setBody("Some input string..."); > response = context.createProducerTemplate().send( > "http4://www.google.com?q=HelloWorld", exchange); > Assert.assertTrue(response.isFailed()); > Throwable exception = response.getException(); > System.out.println("Exception: " + exception.getLocalizedMessage() + > "\nCause: " + exception.getCause()); > } > } > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Http4-component-throws-useless-NPE-if-request-body-is-String-instead-of-InputStream-tp5717268.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen