Hi,
I can't understand why the following code produces different outputs for two
trivial Jetty routes.
The first route uses an anonymous processor to set the HTTP response code to
200, but the output actually displays 500 (and the body contains an HTML
error from Jetty). The second route uses '.setHeader()' directly on the
route and correctly displays 200 (and has no error in the body).
But shouldn't these two routes be functionally identical...? I don't
understand why the first one is failing, nor why these two routes are in any
way 'different'.
public class TestApp {
public static class TestRoutes extends RouteBuilder {
public final static String DEMO_ENDPOINT_1 =
"http4://localhost:8099/demo_1";
public final static String DEMO_ENDPOINT_2 =
"http4://localhost:8099/demo_2";
@Override
public void configure() {
from("jetty:" + DEMO_ENDPOINT_1)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE,
constant(200));
} });
from("jetty:" + DEMO_ENDPOINT_2)
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200));
public static void main( String[] args ) throws Exception {
final CamelContext context = new DefaultCamelContext();
context.addRoutes(new TestRoutes());
context.start();
ProducerTemplate producerTemplate = context.createProducerTemplate();
Exchange request1 = new DefaultExchange(context);
Exchange response1 = producerTemplate.send(TestRoutes.DEMO_ENDPOINT_1 +
"?throwExceptionOnFailure=false", request1);
System.out.println("Output 1: [" +
response1.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE) + "]");
Exchange request2 = new DefaultExchange(context);
Exchange response2 = producerTemplate.send(TestRoutes.DEMO_ENDPOINT_2 +
"?throwExceptionOnFailure=false", request2);
System.out.println("Output 2: [" +
response2.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE) + "]");
I can't understand why the following code produces different outputs for two
trivial Jetty routes.
The first route uses an anonymous processor to set the HTTP response code to
200, but the output actually displays 500 (and the body contains an HTML
error from Jetty). The second route uses '.setHeader()' directly on the
route and correctly displays 200 (and has no error in the body).
But shouldn't these two routes be functionally identical...? I don't
understand why the first one is failing, nor why these two routes are in any
way 'different'.
public class TestApp {
public static class TestRoutes extends RouteBuilder {
public final static String DEMO_ENDPOINT_1 =
"http4://localhost:8099/demo_1";
public final static String DEMO_ENDPOINT_2 =
"http4://localhost:8099/demo_2";
@Override
public void configure() {
from("jetty:" + DEMO_ENDPOINT_1)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE,
constant(200));
} });
from("jetty:" + DEMO_ENDPOINT_2)
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200));
public static void main( String[] args ) throws Exception {
final CamelContext context = new DefaultCamelContext();
context.addRoutes(new TestRoutes());
context.start();
ProducerTemplate producerTemplate = context.createProducerTemplate();
Exchange request1 = new DefaultExchange(context);
Exchange response1 = producerTemplate.send(TestRoutes.DEMO_ENDPOINT_1 +
"?throwExceptionOnFailure=false", request1);
System.out.println("Output 1: [" +
response1.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE) + "]");
Exchange request2 = new DefaultExchange(context);
Exchange response2 = producerTemplate.send(TestRoutes.DEMO_ENDPOINT_2 +
"?throwExceptionOnFailure=false", request2);
System.out.println("Output 2: [" +
response2.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE) + "]");