Hi, I just went through the unit test, I just found there is some miss understand between the URI that http4 endpoint use and the URI that the http4 producer use.
As you know there are more than one component which can send the request to the HTTP server, such as camel-http, camel-http4 and camel-ahc even camel-jetty. In came we use URI to specify the endpoint information, so we use different scheme to let camel pick up right component to use. But for the http4 producer, it just understand the URI which is start with http://xxx, so you need to set the URI in the message header like http://xxx instead of http4:xxx. And we don't support the change the http request uri for the bridge endpoint, as the message which is routed form the first endpoint could have the header with Exchange.HTTP_URI and we don't want this header confuse the producer. BTW, I past the Unit test file which I modified here, please check it out. package org.apache.camel.component.http4; import java.io.IOException; import java.io.InputStream; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; public class HttpUriOverrideTest extends CamelTestSupport { private String direct = "direct:abc"; private String oldUri = "http4:stackoverflow.com:80"; private String oldUriBridge = "http4:stackoverflow.com:80?bridgeEndpoint=true"; private String newUri = "http://www.website.com:80"; private String newHttp4Uri = "http4:www.website.com:80"; private String mock = "mock:mock1"; private String oldUriBody = "stackoverflow"; private String newUriBody = "www.website.com"; /** * This test success * @throws Exception */ @Test public void testValidOldUri() throws Exception { doTestValidWebsite(oldUri); } /** * This test success * @throws Exception */ @Test public void testValidNewUri() throws Exception { doTestValidWebsite(newHttp4Uri); } /** * This test success * @throws Exception */ @Test public void testSimpleTest() throws Exception { doTestWithSetHeaderHttpUri(oldUri, false); } /** * This test will give the following exception : * Caused by: java.lang.IllegalArgumentException: Invalid uri: http4:www.website.com:80. * If you are forwarding/bridging http endpoints, * then enable the bridgeEndpoint option on the endpoint: Endpoint[http4://stackoverflow.com:80] * @throws Exception */ @Test public void testOverride() throws Exception { doTestWithSetHeaderHttpUri(oldUri, true); } /** * This test will fails on the Asserts, the body contains the body of the oldUri (oldUriBody instead of newUriBody) * @throws Exception */ @Test @Ignore("This test will failed as we don't support to override the http uri within the bridge endpoint") public void testOverrideWithBridgeParameter() throws Exception { doTestWithSetHeaderHttpUri(oldUriBridge, true); } public void doTestWithSetHeaderHttpUri(final String oldURI, final boolean override) throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { if (override) { from(direct).setHeader(Exchange.HTTP_URI, constant(newUri)).to(oldURI).to(mock); } else { from(direct).to(oldURI).to(mock); } } }); context.start(); getMockEndpoint(mock).expectedMessageCount(1); context.createProducerTemplate().sendBody(direct, "body"); assertMockEndpointsSatisfied(); String body = getMessage((InputStream) getMockEndpoint(mock).getExchanges().get(0).getIn().getBody()); if (override) { // Should contain newUriBody Assert.assertFalse(body.contains(oldUriBody)); Assert.assertTrue(body.contains(newUriBody)); } else { // Should contain oldUriBody Assert.assertTrue(body.contains(oldUriBody)); Assert.assertFalse(body.contains(newUriBody)); } } public void doTestValidWebsite(final String uri) throws Exception { context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from(direct).to(uri).to(mock); } }); context.start(); getMockEndpoint(mock).expectedMessageCount(1); context.createProducerTemplate().sendBody(direct, "body"); assertMockEndpointsSatisfied(); String body = getMessage((InputStream) getMockEndpoint(mock).getExchanges().get(0).getIn().getBody()); if (uri.equals(newHttp4Uri)) { // Should contain newUriBody Assert.assertFalse(body.contains(oldUriBody)); Assert.assertTrue(body.contains(newUriBody)); } else { // Should contain oldUriBody Assert.assertTrue(body.contains(oldUriBody)); Assert.assertFalse(body.contains(newUriBody)); } } private String getMessage(InputStream is) throws IOException { StringBuilder var = new StringBuilder(); int read = is.read(); while (read != -1) { var.append((char) read); read = is.read(); } return var.toString(); } @Override public boolean isUseAdviceWith() { return true; } } -- View this message in context: http://camel.465427.n5.nabble.com/Found-a-bug-in-overriding-URI-using-camel-http4-documentation-problem-tp5726005p5726048.html Sent from the Camel - Users mailing list archive at Nabble.com.