Repository: camel Updated Branches: refs/heads/master 9d17405ad -> 80ff59200
Component docs Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/80ff5920 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/80ff5920 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/80ff5920 Branch: refs/heads/master Commit: 80ff59200d1c2cce4c10df28247117afd9915852 Parents: 9d17405 Author: Claus Ibsen <[email protected]> Authored: Tue May 26 18:18:06 2015 +0200 Committer: Claus Ibsen <[email protected]> Committed: Tue May 26 18:26:06 2015 +0200 ---------------------------------------------------------------------- .../camel/component/http4/HttpComponent.java | 40 ++++++- .../camel/component/http4/HttpConsumer.java | 2 +- .../camel/component/http4/HttpEndpoint.java | 115 ++++++++++++++----- .../camel/component/http4/HttpMessage.java | 4 +- ...tpEndpointOptionsNotChangeComponentTest.java | 6 +- .../http4/HttpReferenceParameterTest.java | 4 +- 6 files changed, 132 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/80ff5920/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java index b5fc46e..9fc700d 100644 --- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java +++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java @@ -286,7 +286,7 @@ public class HttpComponent extends HeaderFilterStrategyComponent { } else { setEndpointHeaderFilterStrategy(endpoint); } - endpoint.setBinding(getHttpBinding()); + endpoint.setHttpBinding(getHttpBinding()); if (httpBinding != null) { endpoint.setHttpBinding(httpBinding); } @@ -357,6 +357,9 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return httpClientConfigurer; } + /** + * To use the custom HttpClientConfigurer to perform configuration of the HttpClient that will be used. + */ public void setHttpClientConfigurer(HttpClientConfigurer httpClientConfigurer) { this.httpClientConfigurer = httpClientConfigurer; } @@ -365,6 +368,9 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return clientConnectionManager; } + /** + * To use a custom HttpClientConnectionManager to manage connections + */ public void setClientConnectionManager(HttpClientConnectionManager clientConnectionManager) { this.clientConnectionManager = clientConnectionManager; } @@ -373,6 +379,9 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return httpBinding; } + /** + * To use a custom HttpBinding to control the mapping between Camel message and HttpClient. + */ public void setHttpBinding(HttpBinding httpBinding) { this.httpBinding = httpBinding; } @@ -381,6 +390,9 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return httpContext; } + /** + * To use a custom org.apache.http.protocol.HttpContext when executing requests. + */ public void setHttpContext(HttpContext httpContext) { this.httpContext = httpContext; } @@ -389,6 +401,11 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return sslContextParameters; } + /** + * To configure security using SSLContextParameters. + * Important: Only one instance of org.apache.camel.util.jsse.SSLContextParameters is supported per HttpComponent. + * If you need to use 2 or more different instances, you need to define a new HttpComponent per instance you need. + */ public void setSslContextParameters(SSLContextParameters sslContextParameters) { this.sslContextParameters = sslContextParameters; } @@ -397,6 +414,10 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return x509HostnameVerifier; } + /** + * To use a custom X509HostnameVerifier such as org.apache.http.conn.ssl.StrictHostnameVerifier + * or org.apache.http.conn.ssl.AllowAllHostnameVerifier. + */ public void setX509HostnameVerifier(X509HostnameVerifier x509HostnameVerifier) { this.x509HostnameVerifier = x509HostnameVerifier; } @@ -405,6 +426,9 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return maxTotalConnections; } + /** + * The maximum number of connections. + */ public void setMaxTotalConnections(int maxTotalConnections) { this.maxTotalConnections = maxTotalConnections; } @@ -413,6 +437,9 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return connectionsPerRoute; } + /** + * The maximum number of connections per route. + */ public void setConnectionsPerRoute(int connectionsPerRoute) { this.connectionsPerRoute = connectionsPerRoute; } @@ -420,7 +447,10 @@ public class HttpComponent extends HeaderFilterStrategyComponent { public long getConnectionTimeToLive() { return connectionTimeToLive; } - + + /** + * The time for connection to live, the time unit is millisecond, the default value is always keep alive. + */ public void setConnectionTimeToLive(long connectionTimeToLive) { this.connectionTimeToLive = connectionTimeToLive; } @@ -429,6 +459,12 @@ public class HttpComponent extends HeaderFilterStrategyComponent { return cookieStore; } + /** + * To use a custom org.apache.http.client.CookieStore. + * By default the org.apache.http.impl.client.BasicCookieStore is used which is an in-memory only cookie store. + * Notice if bridgeEndpoint=true then the cookie store is forced to be a noop cookie store as cookie + * shouldn't be stored as we are just bridging (eg acting as a proxy). + */ public void setCookieStore(CookieStore cookieStore) { this.cookieStore = cookieStore; } http://git-wip-us.apache.org/repos/asf/camel/blob/80ff5920/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConsumer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConsumer.java index 37d0cb0..1ddf687 100644 --- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConsumer.java +++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConsumer.java @@ -40,7 +40,7 @@ public class HttpConsumer extends DefaultConsumer { } public HttpBinding getBinding() { - return getEndpoint().getBinding(); + return getEndpoint().getHttpBinding(); } public String getPath() { http://git-wip-us.apache.org/repos/asf/camel/blob/80ff5920/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java index 03724b5..c22f9ac 100644 --- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java +++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpEndpoint.java @@ -61,31 +61,31 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg private UrlRewrite urlRewrite; private CookieStore cookieStore = new BasicCookieStore(); - @UriPath @Metadata(required = "true") + @UriPath @Metadata(required = "true", label = "producer") private URI httpUri; @UriParam private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy(); @UriParam - private HttpBinding binding; - @UriParam(defaultValue = "true") + private HttpBinding httpBinding; + @UriParam(label = "producer", defaultValue = "true") private boolean throwExceptionOnFailure = true; - @UriParam + @UriParam(label = "producer") private boolean bridgeEndpoint; - @UriParam + @UriParam(label = "consumer") private boolean matchOnUriPrefix; @UriParam(defaultValue = "true") private boolean chunked = true; - @UriParam + @UriParam(label = "consumer") private boolean disableStreamCache; @UriParam private boolean transferException; - @UriParam + @UriParam(label = "consumer") private boolean traceEnabled; - @UriParam + @UriParam(label = "producer") private boolean authenticationPreemptive; - @UriParam + @UriParam(label = "consumer") private String httpMethodRestrict; - @UriParam(defaultValue = "true") + @UriParam(label = "producer", defaultValue = "true") private boolean clearExpiredCookies = true; public HttpEndpoint() { @@ -246,33 +246,26 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg /** * Register a custom configuration strategy for new {@link HttpClient} instances * created by producers or consumers such as to configure authentication mechanisms etc - * - * @param httpClientConfigurer the strategy for configuring new {@link HttpClient} instances */ public void setHttpClientConfigurer(HttpClientConfigurer httpClientConfigurer) { this.httpClientConfigurer = httpClientConfigurer; } - public HttpBinding getBinding() { - if (binding == null) { + public HttpBinding getHttpBinding() { + if (httpBinding == null) { // create a new binding and use the options from this endpoint - binding = new DefaultHttpBinding(); - binding.setHeaderFilterStrategy(getHeaderFilterStrategy()); - binding.setTransferException(isTransferException()); + httpBinding = new DefaultHttpBinding(); + httpBinding.setHeaderFilterStrategy(getHeaderFilterStrategy()); + httpBinding.setTransferException(isTransferException()); } - return binding; - } - - public void setBinding(HttpBinding binding) { - this.binding = binding; - } - - public void setHttpBinding(HttpBinding binding) { - this.binding = binding; + return httpBinding; } - public void setHttpBindingRef(HttpBinding binding) { - this.binding = binding; + /** + * To use a custom HttpBinding to control the mapping between Camel message and HttpClient. + */ + public void setHttpBinding(HttpBinding httpBinding) { + this.httpBinding = httpBinding; } public void setHttpContext(HttpContext httpContext) { @@ -303,6 +296,9 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return httpUri; } + /** + * The url of the HTTP endpoint to call. + */ public void setHttpUri(URI httpUri) { this.httpUri = httpUri; } @@ -311,6 +307,9 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return clientConnectionManager; } + /** + * To use a custom HttpClientConnectionManager to manage connections + */ public void setClientConnectionManager(HttpClientConnectionManager clientConnectionManager) { this.clientConnectionManager = clientConnectionManager; } @@ -319,6 +318,9 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return headerFilterStrategy; } + /** + * To use a custom HeaderFilterStrategy to filter header to and from Camel message. + */ public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) { this.headerFilterStrategy = headerFilterStrategy; } @@ -327,6 +329,10 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return throwExceptionOnFailure; } + /** + * Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. + * This allows you to get all responses regardless of the HTTP status code. + */ public void setThrowExceptionOnFailure(boolean throwExceptionOnFailure) { this.throwExceptionOnFailure = throwExceptionOnFailure; } @@ -335,6 +341,10 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return bridgeEndpoint; } + /** + * If the option is true, HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint's URI for request. + * You may also set the option throwExceptionOnFailure to be false to let the HttpProducer send all the fault response back. + */ public void setBridgeEndpoint(boolean bridge) { this.bridgeEndpoint = bridge; } @@ -343,6 +353,11 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return matchOnUriPrefix; } + /** + * Whether or not the consumer should try to find a target consumer by matching the URI prefix if no exact match is found. + * <p/> + * See more details at: http://camel.apache.org/how-do-i-let-jetty-match-wildcards.html + */ public void setMatchOnUriPrefix(boolean match) { this.matchOnUriPrefix = match; } @@ -350,7 +365,18 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg public boolean isDisableStreamCache() { return this.disableStreamCache; } - + + /** + * Determines whether or not the raw input stream from Jetty is cached or not + * (Camel will read the stream into a in memory/overflow to file, Stream caching) cache. + * By default Camel will cache the Jetty input stream to support reading it multiple times to ensure it Camel + * can retrieve all data from the stream. However you can set this option to true when you for example need + * to access the raw stream, such as streaming it directly to a file or other persistent store. + * DefaultHttpBinding will copy the request input stream into a stream cache and put it into message bod + * if this option is false to support reading the stream multiple times. + * If you use Jetty to bridge/proxy an endpoint then consider enabling this option to improve performance, + * in case you do not need to read the message payload multiple times. + */ public void setDisableStreamCache(boolean disable) { this.disableStreamCache = disable; } @@ -359,6 +385,9 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return this.chunked; } + /** + * If this option is false Jetty servlet will disable the HTTP streaming and set the content-length header on the response + */ public void setChunked(boolean chunked) { this.chunked = chunked; } @@ -367,6 +396,10 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return transferException; } + /** + * Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. + * This allows you to get all responses regardless of the HTTP status code. + */ public void setTransferException(boolean transferException) { this.transferException = transferException; } @@ -375,6 +408,9 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return this.traceEnabled; } + /** + * Specifies whether to enable HTTP TRACE for this Jetty consumer. By default TRACE is turned off. + */ public void setTraceEnabled(boolean traceEnabled) { this.traceEnabled = traceEnabled; } @@ -383,6 +419,10 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return httpMethodRestrict; } + /** + * Used to only allow consuming if the HttpMethod matches, such as GET/POST/PUT etc. + * Multiple methods can be specified separated by comma. + */ public void setHttpMethodRestrict(String httpMethodRestrict) { this.httpMethodRestrict = httpMethodRestrict; } @@ -391,6 +431,10 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return urlRewrite; } + /** + * Refers to a custom org.apache.camel.component.http.UrlRewrite which allows you to rewrite urls when you bridge/proxy endpoints. + * See more details at http://camel.apache.org/urlrewrite.html + */ public void setUrlRewrite(UrlRewrite urlRewrite) { this.urlRewrite = urlRewrite; } @@ -399,6 +443,10 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return clearExpiredCookies; } + /** + * Whether to clear expired cookies before sending the HTTP request. + * This ensures the cookies store does not keep growing by adding new cookies which is newer removed when they are expired. + */ public void setClearExpiredCookies(boolean clearExpiredCookies) { this.clearExpiredCookies = clearExpiredCookies; } @@ -407,6 +455,12 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return cookieStore; } + /** + * To use a custom org.apache.http.client.CookieStore. + * By default the org.apache.http.impl.client.BasicCookieStore is used which is an in-memory only cookie store. + * Notice if bridgeEndpoint=true then the cookie store is forced to be a noop cookie store as cookie + * shouldn't be stored as we are just bridging (eg acting as a proxy). + */ public void setCookieStore(CookieStore cookieStore) { this.cookieStore = cookieStore; } @@ -415,6 +469,9 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg return authenticationPreemptive; } + /** + * If this option is true, camel-http4 sends preemptive basic authentication to the server. + */ public void setAuthenticationPreemptive(boolean authenticationPreemptive) { this.authenticationPreemptive = authenticationPreemptive; } http://git-wip-us.apache.org/repos/asf/camel/blob/80ff5920/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpMessage.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpMessage.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpMessage.java index 30c8af0..69df1d6 100644 --- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpMessage.java +++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpMessage.java @@ -49,7 +49,7 @@ public class HttpMessage extends DefaultMessage { } // use binding to read the request allowing end users to use their // implementation of the binding - getEndpoint().getBinding().readRequest(request, this); + getEndpoint().getHttpBinding().readRequest(request, this); } public HttpServletRequest getRequest() { @@ -63,7 +63,7 @@ public class HttpMessage extends DefaultMessage { @Override protected Object createBody() { try { - return getEndpoint().getBinding().parseBody(this); + return getEndpoint().getHttpBinding().parseBody(this); } catch (IOException e) { throw new RuntimeCamelException(e); } http://git-wip-us.apache.org/repos/asf/camel/blob/80ff5920/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java index e2a385f..7ddf4b1 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpEndpointOptionsNotChangeComponentTest.java @@ -57,15 +57,15 @@ public class HttpEndpointOptionsNotChangeComponentTest extends CamelTestSupport public void testDoNotMessWithComponent() throws Exception { // get default HttpEndpoint end = context.getEndpoint("http4://www.google.com", HttpEndpoint.class); - assertIsInstanceOf(MyBinding.class, end.getBinding()); + assertIsInstanceOf(MyBinding.class, end.getHttpBinding()); // use a endpoint specific binding HttpEndpoint end2 = context.getEndpoint("http4://www.google.com?httpBinding=#other", HttpEndpoint.class); - assertIsInstanceOf(MyOtherBinding.class, end2.getBinding()); + assertIsInstanceOf(MyOtherBinding.class, end2.getHttpBinding()); // and the default option has not been messed with HttpEndpoint end3 = context.getEndpoint("http4://www.google.com", HttpEndpoint.class); - assertIsInstanceOf(MyBinding.class, end3.getBinding()); + assertIsInstanceOf(MyBinding.class, end3.getHttpBinding()); // test the headerFilterStrategy HttpEndpoint end4 = context.getEndpoint("http4://www.google.com?headerFilterStrategy=#myStrategy", HttpEndpoint.class); http://git-wip-us.apache.org/repos/asf/camel/blob/80ff5920/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java index 10781f1..8b323b9 100644 --- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java +++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpReferenceParameterTest.java @@ -53,8 +53,8 @@ public class HttpReferenceParameterTest extends CamelTestSupport { @Test public void testHttpBindingRef() { - assertSame(testBinding, endpoint1.getBinding()); - assertSame(testBinding, endpoint2.getBinding()); + assertSame(testBinding, endpoint1.getHttpBinding()); + assertSame(testBinding, endpoint2.getHttpBinding()); } @Test
