Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Invalid
-
2.20.1
-
None
-
None
-
Unknown
Description
According to https://github.com/apache/camel/blob/master/components/camel-http4/src/main/docs/http4-component.adoc it is possible to provided a custom HttpClient with the query parameter _httpClient _.
When I try to use parameter the route can not be created because the httpClient does not see to be looked up in the registry:
org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> To[https4://localhost:8443?httpClient=allTrustingHttpClient] <<< in route: Route(route1)[[From[seda:in]] -> [To[https4://localhost:8443... because of Failed to resolve endpoint: https4://localhost:8443?httpClient=allTrustingHttpClient due to: Could not find a suitable setter for property: httpClient as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.http.client.HttpClient with value allTrustingHttpClient at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1298) at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204) at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1148) at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3727) at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3441) at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:208) at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3249) at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3245) at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3268) at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3245) at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3168) at org.apache.camel.test.junit4.CamelTestSupport.startCamelContext(CamelTestSupport.java:678) at org.apache.camel.test.junit4.CamelTestSupport.doSetUp(CamelTestSupport.java:361) at org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:262) Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: https4://localhost:8443?httpClient=allTrustingHttpClient due to: Could not find a suitable setter for property: httpClient as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.http.client.HttpClient with value allTrustingHttpClient at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:763) at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80) at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:219) at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:115) at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:121) at org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:62) at org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:56) at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:549) at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:510) at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:226) at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1295) ... 42 more Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: httpClient as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.http.client.HttpClient with value allTrustingHttpClient at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:614) at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:645) at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:497) at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:507) at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:254) at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:309) at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:297) at org.apache.camel.component.http4.HttpComponent.createEndpoint(HttpComponent.java:258) at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:126) at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:716) ... 52 more
A test case to replicated this behavior:
import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLContext; import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.http.client.HttpClient; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContextBuilder; import org.junit.Test; public class Https4CustomHttpClientTest extends CamelTestSupport { private static final String IN_URI = "seda:in"; @Produce(uri = "seda:in") private ProducerTemplate in; @Test public void test() throws Exception { CompletableFuture<Object> out = in.asyncRequestBody(IN_URI, ""); out.get(10, TimeUnit.SECONDS); } @Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override public void configure() throws Exception { from(IN_URI).to("https4://localhost:8443?httpClient=allTrustingHttpClient"); } }; } @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry jndi = super.createRegistry(); jndi.bind("allTrustingHttpClient", createAllTrustingHttpClient()); return jndi; } public static HttpClient createAllTrustingHttpClient() throws Exception { SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build(); return HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); } }