You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/07/23 14:58:05 UTC

[03/24] camel git commit: camel-http-common - as a common module

camel-http-common - as a common module


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/600063ab
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/600063ab
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/600063ab

Branch: refs/heads/master
Commit: 600063abdeb2d3030a414b3215625f009770dd58
Parents: b48be21
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 23 09:09:34 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 23 15:04:30 2015 +0200

----------------------------------------------------------------------
 .../component/http/HttpCommonComponent.java     |   4 +-
 .../component/http/HttpCommonEndpoint.java      |  42 +--
 .../camel/component/http/HttpEndpoint.java      | 343 +------------------
 3 files changed, 24 insertions(+), 365 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/600063ab/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java
index 8443963..23b4455 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonComponent.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.http;
 
-import org.apache.camel.Endpoint;
 import org.apache.camel.impl.HeaderFilterStrategyComponent;
 
 public abstract class HttpCommonComponent extends HeaderFilterStrategyComponent {
@@ -24,8 +23,7 @@ public abstract class HttpCommonComponent extends HeaderFilterStrategyComponent
     protected HttpBinding httpBinding;
     protected HttpConfiguration httpConfiguration;
 
-    // TODO: HttpCommonEndpoint
-    public HttpCommonComponent(Class<? extends Endpoint> endpointClass) {
+    public HttpCommonComponent(Class<? extends HttpCommonEndpoint> endpointClass) {
         super(endpointClass);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/600063ab/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java
index 1c40e38..ae2e39e 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpCommonEndpoint.java
@@ -32,30 +32,30 @@ public abstract class HttpCommonEndpoint extends DefaultEndpoint implements Head
 
     // Note: all options must be documented with description in annotations so extended components can access the documentation
 
-    private static final Logger LOG = LoggerFactory.getLogger(HttpEndpoint.class);
+    private static final Logger LOG = LoggerFactory.getLogger(HttpCommonEndpoint.class);
 
-    private HttpCommonComponent component;
-    private UrlRewrite urlRewrite;
+    HttpCommonComponent component;
+    UrlRewrite urlRewrite;
 
     @UriPath(label = "producer", description = "The url of the HTTP endpoint to call.") @Metadata(required = "true")
-    private URI httpUri;
+    URI httpUri;
     @UriParam(description = "To use a custom HeaderFilterStrategy to filter header to and from Camel message.")
-    private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
+    HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
     @UriParam(description = "To use a custom HttpBinding to control the mapping between Camel message and HttpClient.")
-    private HttpBinding binding;
+    HttpBinding binding;
     @UriParam(label = "producer", defaultValue = "true",
             description = "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.")
-    private boolean throwExceptionOnFailure = true;
+    boolean throwExceptionOnFailure = true;
     @UriParam(label = "producer",
             description = "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.")
-    private boolean bridgeEndpoint;
+    boolean bridgeEndpoint;
     @UriParam(label = "consumer",
             description = "Whether or not the consumer should try to find a target consumer by matching the URI prefix if no exact match is found.")
-    private boolean matchOnUriPrefix;
+    boolean matchOnUriPrefix;
     @UriParam(defaultValue = "true", description = "If this option is false Jetty servlet will disable the HTTP streaming and set the content-length header on the response")
-    private boolean chunked = true;
+    boolean chunked = true;
     @UriParam(label = "consumer",
             description = "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."
@@ -66,36 +66,36 @@ public abstract class HttpCommonEndpoint extends DefaultEndpoint implements Head
                     + " 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.")
-    private boolean disableStreamCache;
+    boolean disableStreamCache;
     @UriParam(label = "producer", description = "The proxy host name")
-    private String proxyHost;
+    String proxyHost;
     @UriParam(label = "producer", description = "The proxy port number")
-    private int proxyPort;
+    int proxyPort;
     @UriParam(label = "producer", enums = "Basic,Digest,NTLM", description = "Authentication method for proxy, either as Basic, Digest or NTLM.")
-    private String authMethodPriority;
+    String authMethodPriority;
     @UriParam(description = "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.")
-    private boolean transferException;
+    boolean transferException;
     @UriParam(label = "consumer",
             description = "Specifies whether to enable HTTP TRACE for this Jetty consumer. By default TRACE is turned off.")
-    private boolean traceEnabled;
+    boolean traceEnabled;
     @UriParam(label = "consumer",
             description = "Used to only allow consuming if the HttpMethod matches, such as GET/POST/PUT etc. Multiple methods can be specified separated by comma.")
-    private String httpMethodRestrict;
+    String httpMethodRestrict;
     @UriParam(label = "consumer",
             description = "To use a custom buffer size on the javax.servlet.ServletResponse.")
-    private Integer responseBufferSize;
+    Integer responseBufferSize;
     @UriParam(label = "producer",
             description = "If this option is true, The http producer won't read response body and cache the input stream")
-    private boolean ignoreResponseBody;
+    boolean ignoreResponseBody;
     @UriParam(label = "producer", defaultValue = "true",
             description = "If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy."
                     + " Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers).")
-    private boolean copyHeaders = true;
+    boolean copyHeaders = true;
     @UriParam(label = "consumer",
             description = "Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present."
                     + " This can be turned on in case HTTP clients do not send streamed data.")
-    private boolean eagerCheckContentAvailable;
+    boolean eagerCheckContentAvailable;
 
     public HttpCommonEndpoint() {
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/600063ab/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
index a31ec23..23b1a20 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
@@ -26,13 +26,7 @@ import org.apache.camel.Consumer;
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
-import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.camel.spi.HeaderFilterStrategyAware;
-import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
-import org.apache.camel.spi.UriPath;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpConnectionManager;
@@ -47,77 +41,15 @@ import org.slf4j.LoggerFactory;
  * @version 
  */
 @UriEndpoint(scheme = "http,https", title = "HTTP,HTTPS", syntax = "http:httpUri", producerOnly = true, label = "http")
-public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware {
+public class HttpEndpoint extends HttpCommonEndpoint {
 
     // Note: all options must be documented with description in annotations so extended components can access the documentation
 
     private static final Logger LOG = LoggerFactory.getLogger(HttpEndpoint.class);
 
-    private HttpComponent component;
     private HttpClientParams clientParams;
     private HttpClientConfigurer httpClientConfigurer;
     private HttpConnectionManager httpConnectionManager;
-    private UrlRewrite urlRewrite;
-
-    @UriPath(label = "producer", description = "The url of the HTTP endpoint to call.") @Metadata(required = "true")
-    private URI httpUri;
-    @UriParam(description = "To use a custom HeaderFilterStrategy to filter header to and from Camel message.")
-    private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
-    @UriParam(description = "To use a custom HttpBinding to control the mapping between Camel message and HttpClient.")
-    private HttpBinding binding;
-    @UriParam(label = "producer", defaultValue = "true",
-            description = "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.")
-    private boolean throwExceptionOnFailure = true;
-    @UriParam(label = "producer",
-            description = "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.")
-    private boolean bridgeEndpoint;
-    @UriParam(label = "consumer",
-            description = "Whether or not the consumer should try to find a target consumer by matching the URI prefix if no exact match is found.")
-    private boolean matchOnUriPrefix;
-    @UriParam(defaultValue = "true", description = "If this option is false Jetty servlet will disable the HTTP streaming and set the content-length header on the response")
-    private boolean chunked = true;
-    @UriParam(label = "consumer",
-            description = "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 body"
-                    + " 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.")
-    private boolean disableStreamCache;
-    @UriParam(label = "producer", description = "The proxy host name")
-    private String proxyHost;
-    @UriParam(label = "producer", description = "The proxy port number")
-    private int proxyPort;
-    @UriParam(label = "producer", enums = "Basic,Digest,NTLM", description = "Authentication method for proxy, either as Basic, Digest or NTLM.")
-    private String authMethodPriority;
-    @UriParam(description = "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.")
-    private boolean transferException;
-    @UriParam(label = "consumer",
-            description = "Specifies whether to enable HTTP TRACE for this Jetty consumer. By default TRACE is turned off.")
-    private boolean traceEnabled;
-    @UriParam(label = "consumer",
-            description = "Used to only allow consuming if the HttpMethod matches, such as GET/POST/PUT etc. Multiple methods can be specified separated by comma.")
-    private String httpMethodRestrict;
-    @UriParam(label = "consumer",
-            description = "To use a custom buffer size on the javax.servlet.ServletResponse.")
-    private Integer responseBufferSize;
-    @UriParam(label = "producer",
-            description = "If this option is true, The http producer won't read response body and cache the input stream")
-    private boolean ignoreResponseBody;
-    @UriParam(label = "producer", defaultValue = "true",
-            description = "If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy."
-                    + " Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers).")
-    private boolean copyHeaders = true;
-    @UriParam(label = "consumer",
-            description = "Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present."
-                    + " This can be turned on in case HTTP clients do not send streamed data.")
-    private boolean eagerCheckContentAvailable;
 
     public HttpEndpoint() {
     }
@@ -137,9 +69,8 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
 
     public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpClientParams clientParams,
                         HttpConnectionManager httpConnectionManager, HttpClientConfigurer clientConfigurer) throws URISyntaxException {
-        super(endPointURI, component);
+        super(endPointURI, component, httpURI);
         this.component = component;
-        this.httpUri = httpURI;
         this.clientParams = clientParams;
         this.httpClientConfigurer = clientConfigurer;
         this.httpConnectionManager = httpConnectionManager;
@@ -209,24 +140,6 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
         return answer;
     }
 
-    public void connect(HttpConsumer consumer) throws Exception {
-        component.connect(consumer);
-    }
-
-    public void disconnect(HttpConsumer consumer) throws Exception {
-        component.disconnect(consumer);
-    }
-
-    public boolean isLenientProperties() {
-        // true to allow dynamic URI options to be configured and passed to external system for eg. the HttpProducer
-        return true;
-    }
-
-    public boolean isSingleton() {
-        return true;
-    }
-
-
     // Properties
     //-------------------------------------------------------------------------
 
@@ -260,55 +173,6 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
         this.httpClientConfigurer = httpClientConfigurer;
     }
 
-    public HttpBinding getBinding() {
-        if (binding == null) {
-            // create a new binding and use the options from this endpoint
-            binding = new DefaultHttpBinding();
-            binding.setHeaderFilterStrategy(getHeaderFilterStrategy());
-            binding.setTransferException(isTransferException());
-            binding.setEagerCheckContentAvailable(isEagerCheckContentAvailable());
-        }
-        return binding;
-    }
-
-    /**
-     * To use a custom HttpBinding to control the mapping between Camel message and HttpClient.
-     */
-    public void setBinding(HttpBinding binding) {
-        this.binding = binding;
-    }
-
-    public String getPath() {
-        //if the path is empty, we just return the default path here
-        return httpUri.getPath().length() == 0 ? "/" : httpUri.getPath();
-    }
-
-    public int getPort() {
-        if (httpUri.getPort() == -1) {
-            if ("https".equals(getProtocol())) {
-                return 443;
-            } else {
-                return 80;
-            }
-        }
-        return httpUri.getPort();
-    }
-
-    public String getProtocol() {
-        return httpUri.getScheme();
-    }
-
-    public URI getHttpUri() {
-        return httpUri;
-    }
-
-    /**
-     * The url of the HTTP endpoint to call.
-     */
-    public void setHttpUri(URI httpUri) {
-        this.httpUri = httpUri;
-    }
-
     public HttpConnectionManager getHttpConnectionManager() {
         return httpConnectionManager;
     }
@@ -320,207 +184,4 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
         this.httpConnectionManager = httpConnectionManager;
     }
 
-    public HeaderFilterStrategy getHeaderFilterStrategy() {
-        return headerFilterStrategy;
-    }
-
-    /**
-     * To use a custom HeaderFilterStrategy to filter header to and from Camel message.
-     */
-    public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
-        this.headerFilterStrategy = headerFilterStrategy;
-    }
-
-    public boolean isThrowExceptionOnFailure() {
-        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;
-    }
-
-    public boolean isBridgeEndpoint() {
-        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;
-    }
-
-    public boolean isMatchOnUriPrefix() {
-        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;
-    }
-
-    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 body
-     * 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;
-    }
-
-    public boolean isChunked() {
-        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;
-    }
-
-    public String getProxyHost() {
-        return proxyHost;
-    }
-
-    /**
-     * The proxy host name
-     */
-    public void setProxyHost(String proxyHost) {
-        this.proxyHost = proxyHost;
-    }
-
-    public int getProxyPort() {
-        return proxyPort;
-    }
-
-    /**
-     * The proxy port number
-     */
-    public void setProxyPort(int proxyPort) {
-        this.proxyPort = proxyPort;
-    }
-
-    public String getAuthMethodPriority() {
-        return authMethodPriority;
-    }
-
-    /**
-     * Authentication method for proxy, either as Basic, Digest or NTLM.
-     */
-    public void setAuthMethodPriority(String authMethodPriority) {
-        this.authMethodPriority = authMethodPriority;
-    }
-
-    public boolean isTransferException() {
-        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;
-    }
-
-    public boolean isTraceEnabled() {
-        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;
-    }
-
-    public String getHttpMethodRestrict() {
-        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;
-    }
-
-    public UrlRewrite getUrlRewrite() {
-        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;
-    }
-
-    public Integer getResponseBufferSize() {
-        return responseBufferSize;
-    }
-
-    /**
-     * To use a custom buffer size on the javax.servlet.ServletResponse.
-     */
-    public void setResponseBufferSize(Integer responseBufferSize) {
-        this.responseBufferSize = responseBufferSize;
-    }
-
-    public boolean isIgnoreResponseBody() {
-        return ignoreResponseBody;
-    }
-
-    /**
-     * If this option is true, The http producer won't read response body and cache the input stream.
-     */
-    public void setIgnoreResponseBody(boolean ignoreResponseBody) {
-        this.ignoreResponseBody = ignoreResponseBody;
-    }
-
-    /**
-     * If this option is true then IN exchange headers will be copied to OUT exchange headers according to copy strategy.
-     * Setting this to false, allows to only include the headers from the HTTP response (not propagating IN headers).
-     */
-    public boolean isCopyHeaders() {
-        return copyHeaders;
-    }
-
-    public void setCopyHeaders(boolean copyHeaders) {
-        this.copyHeaders = copyHeaders;
-    }
-
-    public boolean isEagerCheckContentAvailable() {
-        return eagerCheckContentAvailable;
-    }
-
-    /**
-     * Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present.
-     * This can be turned on in case HTTP clients do not send streamed data.
-     */
-    public void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) {
-        this.eagerCheckContentAvailable = eagerCheckContentAvailable;
-    }
 }