camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmcb55 <>
Subject Http4 component throws useless NPE if request body is String (instead of InputStream)
Date Mon, 13 Aug 2012 19:47:56 GMT
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....???


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 {
    public void testReport() throws Exception {
        Exchange exchange = new DefaultExchange(context());
        Exchange response = context.createProducerTemplate().send(
                "http4://", exchange);

        exchange = new DefaultExchange(context());
        exchange.getIn().setBody("Some input string...");
        response = context.createProducerTemplate().send(
                "http4://", exchange);
        Throwable exception = response.getException();
        System.out.println("Exception: " + exception.getLocalizedMessage() +
"\nCause: " + exception.getCause());

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message