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:23 UTC
[21/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/be77f1a0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/be77f1a0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/be77f1a0
Branch: refs/heads/master
Commit: be77f1a08acee401b62686bc6db3109cfaa4263e
Parents: f899941
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 23 13:30:52 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 23 15:04:35 2015 +0200
----------------------------------------------------------------------
.../apache/camel/http/common/HttpHelper.java | 34 ++
components/camel-http4/pom.xml | 147 +++---
.../camel/component/http4/CamelServlet.java | 116 -----
.../component/http4/DefaultHttpBinding.java | 461 -----------------
.../camel/component/http4/HttpBinding.java | 162 ------
.../camel/component/http4/HttpComponent.java | 49 +-
.../camel/component/http4/HttpConsumer.java | 69 ---
.../camel/component/http4/HttpConverter.java | 101 ----
.../camel/component/http4/HttpEndpoint.java | 279 +----------
.../http4/HttpHeaderFilterStrategy.java | 52 --
.../camel/component/http4/HttpMessage.java | 82 ---
.../http4/HttpOperationFailedException.java | 75 ---
.../component/http4/HttpPollingConsumer.java | 2 +-
.../camel/component/http4/HttpProducer.java | 12 +-
.../http4/HttpProtocolHeaderFilterStrategy.java | 88 ----
.../component/http4/HttpServletUrlRewrite.java | 45 --
.../camel/component/http4/UrlRewrite.java | 41 --
.../http4/helper/CamelFileDataSource.java | 53 --
.../component/http4/helper/HttpHelper.java | 498 -------------------
.../http4/helper/HttpMethodHelper.java | 82 +++
.../UrlRewriteHttpServletRequestAdapter.java | 50 --
.../services/org/apache/camel/TypeConverter | 1 -
.../camel/component/http4/GoogleUrlRewrite.java | 1 +
...tpEndpointOptionsNotChangeComponentTest.java | 8 +-
.../http4/HttpHeaderFilterStrategyTest.java | 1 +
.../camel/component/http4/HttpRedirectTest.java | 1 +
.../http4/HttpReferenceParameterTest.java | 5 +-
.../http4/HttpThrowExceptionOnFailureTest.java | 1 +
.../component/http4/helper/HttpHelperTest.java | 11 +-
29 files changed, 252 insertions(+), 2275 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
index e7311b0..2a7189a 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHelper.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
+import java.net.ProtocolException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
@@ -52,6 +53,39 @@ public final class HttpHelper {
// Helper class
}
+ public static boolean isSecureConnection(String uri) {
+ return uri.startsWith("https");
+ }
+
+ public static int[] parserHttpVersion(String s) throws ProtocolException {
+ int major;
+ int minor;
+ if (s == null) {
+ throw new IllegalArgumentException("String may not be null");
+ }
+ if (!s.startsWith("HTTP/")) {
+ throw new ProtocolException("Invalid HTTP version string: " + s);
+ }
+ int i1 = "HTTP/".length();
+ int i2 = s.indexOf(".", i1);
+ if (i2 == -1) {
+ throw new ProtocolException("Invalid HTTP version number: " + s);
+ }
+ try {
+ major = Integer.parseInt(s.substring(i1, i2));
+ } catch (NumberFormatException e) {
+ throw new ProtocolException("Invalid HTTP major version number: " + s);
+ }
+ i1 = i2 + 1;
+ i2 = s.length();
+ try {
+ minor = Integer.parseInt(s.substring(i1, i2));
+ } catch (NumberFormatException e) {
+ throw new ProtocolException("Invalid HTTP minor version number: " + s);
+ }
+ return new int[]{major, minor};
+ }
+
@SuppressWarnings("deprecation")
public static void setCharsetFromContentType(String contentType, Exchange exchange) {
if (contentType != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-http4/pom.xml b/components/camel-http4/pom.xml
index 4ce95aa..e1f4edf 100644
--- a/components/camel-http4/pom.xml
+++ b/components/camel-http4/pom.xml
@@ -15,85 +15,86 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.16-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.16-SNAPSHOT</version>
+ </parent>
- <artifactId>camel-http4</artifactId>
- <packaging>bundle</packaging>
- <name>Camel :: HTTP4</name>
- <description>Camel HTTP (Apache HttpClient 4.x) support</description>
+ <artifactId>camel-http4</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: HTTP4</name>
+ <description>Camel HTTP (Apache HttpClient 4.x) support</description>
- <properties>
- <!-- CAMEL-7010 Now we move to HttpClient 4.3 API -->
- <camel.osgi.import.before.defaults>
- javax.servlet.*;version="${servlet-version-range}",
- org.apache.http.*;version="[4.3,5)"
- </camel.osgi.import.before.defaults>
- <camel.osgi.export.pkg>org.apache.camel.component.http4.*</camel.osgi.export.pkg>
- <camel.osgi.export.service>
- org.apache.camel.spi.ComponentResolver;component=http4,
- org.apache.camel.spi.ComponentResolver;component=https4
- </camel.osgi.export.service>
- </properties>
+ <properties>
+ <!-- CAMEL-7010 Now we move to HttpClient 4.3 API -->
+ <camel.osgi.import.before.defaults>
+ javax.servlet.*;version="${servlet-version-range}",
+ org.apache.http.*;version="[4.3,5)"
+ </camel.osgi.import.before.defaults>
+ <camel.osgi.export.pkg>org.apache.camel.component.http4.*</camel.osgi.export.pkg>
+ <camel.osgi.export.service>
+ org.apache.camel.spi.ComponentResolver;component=http4,
+ org.apache.camel.spi.ComponentResolver;component=https4
+ </camel.osgi.export.service>
+ </properties>
- <dependencies>
+ <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-servlet_3.0_spec</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${httpclient4-version}</version>
- </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-http-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${httpclient4-version}</version>
+ </dependency>
- <!-- testing -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${httpclient4-version}</version>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${httpclient4-version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <!-- use per test fork mode to avoid side effects -->
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <forkCount>1</forkCount>
- <reuseForks>false</reuseForks>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <!-- use per test fork mode to avoid side effects -->
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkCount>1</forkCount>
+ <reuseForks>false</reuseForks>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/CamelServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/CamelServlet.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/CamelServlet.java
deleted file mode 100644
index ca5de47..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/CamelServlet.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import java.io.IOException;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.component.http4.helper.HttpHelper;
-import org.apache.camel.impl.DefaultExchange;
-
-/**
- * @version
- */
-@Deprecated
-public class CamelServlet extends HttpServlet {
-
- private static final long serialVersionUID = -7061982839117697829L;
-
- private ConcurrentMap<String, HttpConsumer> consumers = new ConcurrentHashMap<String, HttpConsumer>();
-
- @Override
- protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- try {
-
- // Is there a consumer registered for the request.
- HttpConsumer consumer = resolve(request);
- if (consumer == null) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- if (consumer.getEndpoint().getHttpMethodRestrict() != null
- && !consumer.getEndpoint().getHttpMethodRestrict().equals(request.getMethod())) {
- response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- return;
- }
-
- if ("TRACE".equals(request.getMethod()) && !consumer.isTraceEnabled()) {
- response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- return;
- }
-
- // Have the camel process the HTTP exchange.
- DefaultExchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut);
- if (consumer.getEndpoint().isBridgeEndpoint()) {
- exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
- exchange.setProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE);
- }
- if (consumer.getEndpoint().isDisableStreamCache()) {
- exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE);
- }
- HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
- exchange.setIn(new HttpMessage(exchange, request, response));
- // set context path as header
- String contextPath = consumer.getEndpoint().getPath();
- exchange.getIn().setHeader("CamelServletContextPath", contextPath);
-
- consumer.getProcessor().process(exchange);
-
- // now lets output to the response
- consumer.getBinding().writeResponse(exchange, response);
-
- } catch (Exception e) {
- throw new ServletException(e);
- }
- }
-
- protected HttpConsumer resolve(HttpServletRequest request) {
- String path = request.getPathInfo();
- if (path == null) {
- return null;
- }
- HttpConsumer answer = consumers.get(path);
-
- if (answer == null) {
- for (String key : consumers.keySet()) {
- if (consumers.get(key).getEndpoint().isMatchOnUriPrefix() && path.startsWith(key)) {
- answer = consumers.get(key);
- break;
- }
- }
- }
- return answer;
- }
-
- public void connect(HttpConsumer consumer) {
- consumers.put(consumer.getPath(), consumer);
- }
-
- public void disconnect(HttpConsumer consumer) {
- consumers.remove(consumer.getPath());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
deleted file mode 100644
index 4420c69..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/DefaultHttpBinding.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.Serializable;
-import java.net.URLDecoder;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.activation.DataHandler;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.Message;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.StreamCache;
-import org.apache.camel.component.http4.helper.CamelFileDataSource;
-import org.apache.camel.component.http4.helper.HttpHelper;
-import org.apache.camel.converter.stream.CachedOutputStream;
-import org.apache.camel.spi.HeaderFilterStrategy;
-import org.apache.camel.util.GZIPHelper;
-import org.apache.camel.util.IOHelper;
-import org.apache.camel.util.MessageHelper;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Binding between {@link HttpMessage} and {@link HttpServletResponse}.
- * <p/>
- * Uses by default the {@link org.apache.camel.component.http4.HttpHeaderFilterStrategy}
- *
- * @version
- */
-public class DefaultHttpBinding implements HttpBinding {
-
- private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpBinding.class);
- private boolean useReaderForPayload;
- private boolean transferException;
- private boolean eagerCheckContentAvailable;
- private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
-
- public DefaultHttpBinding() {
- }
-
- @Deprecated
- public DefaultHttpBinding(HeaderFilterStrategy headerFilterStrategy) {
- this.headerFilterStrategy = headerFilterStrategy;
- }
-
- @Deprecated
- public DefaultHttpBinding(HttpEndpoint endpoint) {
- this.headerFilterStrategy = endpoint.getHeaderFilterStrategy();
- this.transferException = endpoint.isTransferException();
- }
-
- public void readRequest(HttpServletRequest request, HttpMessage message) {
- // lets force a parse of the body and headers
- message.getBody();
- // populate the headers from the request
- Map<String, Object> headers = message.getHeaders();
-
- //apply the headerFilterStrategy
- Enumeration<?> names = request.getHeaderNames();
- while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
- Object value = request.getHeader(name);
- // mapping the content-type
- if (name.toLowerCase().equals("content-type")) {
- name = Exchange.CONTENT_TYPE;
- }
- if (headerFilterStrategy != null
- && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) {
- HttpHelper.appendHeader(headers, name, value);
- }
- }
-
- if (request.getCharacterEncoding() != null) {
- headers.put(Exchange.HTTP_CHARACTER_ENCODING, request.getCharacterEncoding());
- message.getExchange().setProperty(Exchange.CHARSET_NAME, request.getCharacterEncoding());
- }
-
- try {
- populateRequestParameters(request, message);
- } catch (Exception e) {
- throw new RuntimeCamelException("Cannot read request parameters due " + e.getMessage(), e);
- }
-
- Object body = message.getBody();
- // reset the stream cache if the body is the instance of StreamCache
- if (body instanceof StreamCache) {
- ((StreamCache) body).reset();
- }
-
- // store the method and query and other info in headers
- headers.put(Exchange.HTTP_METHOD, request.getMethod());
- headers.put(Exchange.HTTP_QUERY, request.getQueryString());
- headers.put(Exchange.HTTP_URL, request.getRequestURL());
- headers.put(Exchange.HTTP_URI, request.getRequestURI());
- headers.put(Exchange.HTTP_PATH, request.getPathInfo());
- headers.put(Exchange.CONTENT_TYPE, request.getContentType());
-
- // if content type is serialized java object, then de-serialize it to a Java object
- if (request.getContentType() != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(request.getContentType())) {
- try {
- InputStream is = message.getExchange().getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, body);
- Object object = HttpHelper.deserializeJavaObjectFromStream(is, message.getExchange().getContext());
- if (object != null) {
- message.setBody(object);
- }
- } catch (Exception e) {
- throw new RuntimeCamelException("Cannot deserialize body to Java object", e);
- }
- }
-
- populateAttachments(request, message);
- }
-
- protected void populateRequestParameters(HttpServletRequest request, HttpMessage message) throws Exception {
- //we populate the http request parameters without checking the request method
- Map<String, Object> headers = message.getHeaders();
- Enumeration<?> names = request.getParameterNames();
- while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
- // there may be multiple values for the same name
- String[] values = request.getParameterValues(name);
- LOG.trace("HTTP parameter {} = {}", name, values);
-
- if (values != null) {
- for (String value : values) {
- if (headerFilterStrategy != null
- && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) {
- HttpHelper.appendHeader(headers, name, value);
- }
- }
- }
- }
- Boolean flag = message.getHeader(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.class);
- boolean skipWwwFormUrlEncoding = flag != null ? flag : false;
- if (request.getMethod().equals("POST") && request.getContentType() != null
- && request.getContentType().startsWith(HttpConstants.CONTENT_TYPE_WWW_FORM_URLENCODED)
- && !skipWwwFormUrlEncoding) {
- String charset = request.getCharacterEncoding();
- if (charset == null) {
- charset = "UTF-8";
- }
- // Push POST form params into the headers to retain compatibility with DefaultHttpBinding
- String body = message.getBody(String.class);
- if (ObjectHelper.isNotEmpty(body)) {
- for (String param : body.split("&")) {
- String[] pair = param.split("=", 2);
- if (pair.length == 2) {
- String name = URLDecoder.decode(pair[0], charset);
- String value = URLDecoder.decode(pair[1], charset);
- if (headerFilterStrategy != null
- && !headerFilterStrategy.applyFilterToExternalHeaders(name, value, message.getExchange())) {
- headers.put(name, value);
- }
- } else {
- throw new IllegalArgumentException("Invalid parameter, expected to be a pair but was " + param);
- }
- }
- }
- }
- }
-
- protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
- // check if there is multipart files, if so will put it into DataHandler
- Enumeration<?> names = request.getAttributeNames();
- while (names.hasMoreElements()) {
- String name = (String) names.nextElement();
- Object object = request.getAttribute(name);
- if (object instanceof File) {
- String fileName = request.getParameter(name);
- message.addAttachment(fileName, new DataHandler(new CamelFileDataSource((File) object, fileName)));
- }
- }
- }
-
- public void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException {
- if (exchange.isFailed()) {
- if (exchange.getException() != null) {
- doWriteExceptionResponse(exchange.getException(), response);
- } else {
- // it must be a fault, no need to check for the fault flag on the message
- doWriteFaultResponse(exchange.getOut(), response, exchange);
- }
- } else {
- // just copy the protocol relates header
- copyProtocolHeaders(exchange.getIn(), exchange.getOut());
- Message out = exchange.getOut();
- if (out != null) {
- doWriteResponse(out, response, exchange);
- }
- }
- }
-
- private void copyProtocolHeaders(Message request, Message response) {
- if (request.getHeader(Exchange.CONTENT_ENCODING) != null) {
- String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING, String.class);
- response.setHeader(Exchange.CONTENT_ENCODING, contentEncoding);
- }
- if (checkChunked(response, response.getExchange())) {
- response.setHeader(Exchange.TRANSFER_ENCODING, "chunked");
- }
- }
-
- public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException {
- // 500 for internal server error
- response.setStatus(500);
- if (isTransferException()) {
- // transfer the exception as a serialized java object
- HttpHelper.writeObjectToServletResponse(response, exception);
- } else {
- // write stacktrace as plain text
- response.setContentType("text/plain");
- PrintWriter pw = response.getWriter();
- exception.printStackTrace(pw);
- pw.flush();
- }
- }
-
- public void doWriteFaultResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
- message.setHeader(Exchange.HTTP_RESPONSE_CODE, 500);
- doWriteResponse(message, response, exchange);
- }
-
- public void doWriteResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
- // set the status code in the response. Default is 200.
- if (message.getHeader(Exchange.HTTP_RESPONSE_CODE) != null) {
- int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
- response.setStatus(code);
- }
- // set the content type in the response.
- String contentType = MessageHelper.getContentType(message);
- if (MessageHelper.getContentType(message) != null) {
- response.setContentType(contentType);
- }
-
- // append headers
- // must use entrySet to ensure case of keys is preserved
- for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
- String key = entry.getKey();
- Object value = entry.getValue();
- // use an iterator as there can be multiple values. (must not use a delimiter)
- final Iterator<?> it = ObjectHelper.createIterator(value, null);
- while (it.hasNext()) {
- String headerValue = exchange.getContext().getTypeConverter().convertTo(String.class, it.next());
- if (headerValue != null && headerFilterStrategy != null
- && !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue, exchange)) {
- response.addHeader(key, headerValue);
- }
- }
- }
-
- // write the body.
- if (message.getBody() != null) {
- if (GZIPHelper.isGzip(message)) {
- doWriteGZIPResponse(message, response, exchange);
- } else {
- doWriteDirectResponse(message, response, exchange);
- }
- }
- }
-
- protected boolean isText(String contentType) {
- if (contentType != null) {
- String temp = contentType.toLowerCase();
- if (temp.indexOf("text") >= 0 || temp.indexOf("html") >= 0) {
- return true;
- }
- }
- return false;
- }
-
- protected void copyStream(InputStream is, OutputStream os) throws IOException {
- try {
- // copy directly from input stream to output stream
- IOHelper.copy(is, os);
- } finally {
- IOHelper.close(os, is);
- }
- }
-
- protected void doWriteDirectResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
- // if content type is serialized Java object, then serialize and write it to the response
- String contentType = message.getHeader(Exchange.CONTENT_TYPE, String.class);
- if (contentType != null && HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT.equals(contentType)) {
- try {
- Object object = message.getMandatoryBody(Serializable.class);
- HttpHelper.writeObjectToServletResponse(response, object);
- // object is written so return
- return;
- } catch (InvalidPayloadException e) {
- throw new IOException(e);
- }
- }
-
- // prefer streaming
- InputStream is = null;
- if (checkChunked(message, exchange)) {
- is = message.getBody(InputStream.class);
- } else {
- // try to use input stream first, so we can copy directly
- if (!isText(contentType)) {
- is = exchange.getContext().getTypeConverter().tryConvertTo(InputStream.class, message.getBody());
- }
- }
-
- if (is != null) {
- ServletOutputStream os = response.getOutputStream();
- LOG.trace("Writing direct response from source input stream to servlet output stream");
- if (!checkChunked(message, exchange)) {
- CachedOutputStream stream = new CachedOutputStream(exchange);
- try {
- // copy directly from input stream to the cached output stream to get the content length
- int len = IOHelper.copy(is, stream);
- // we need to setup the length if message is not chucked
- response.setContentLength(len);
- copyStream(stream.getInputStream(), os);
- } finally {
- IOHelper.close(is, stream);
- }
- } else {
- copyStream(is, os);
- }
- } else {
- // not convertable as a stream so try as a String
- String data = message.getBody(String.class);
- if (data != null) {
- LOG.debug("Cannot write from source input stream, falling back to using String content. For binary content this can be a problem.");
- // set content length before we write data
- String charset = IOHelper.getCharsetName(exchange, true);
- final int dataByteLength = data.getBytes(charset).length;
- response.setCharacterEncoding(charset);
- response.setContentLength(dataByteLength);
- try {
- response.getWriter().print(data);
- } finally {
- response.getWriter().flush();
- }
- }
- }
- }
-
- protected boolean checkChunked(Message message, Exchange exchange) {
- boolean answer = true;
- if (message.getHeader(Exchange.HTTP_CHUNKED) == null) {
- // check the endpoint option
- Endpoint endpoint = exchange.getFromEndpoint();
- if (endpoint instanceof HttpEndpoint) {
- answer = ((HttpEndpoint) endpoint).isChunked();
- }
- } else {
- answer = message.getHeader(Exchange.HTTP_CHUNKED, boolean.class);
- }
- return answer;
- }
-
- protected void doWriteGZIPResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException {
- byte[] bytes;
- try {
- bytes = message.getMandatoryBody(byte[].class);
- } catch (InvalidPayloadException e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
-
- byte[] data = GZIPHelper.compressGZIP(bytes);
- ServletOutputStream os = response.getOutputStream();
- try {
- response.setContentLength(data.length);
- os.write(data);
- os.flush();
- } finally {
- IOHelper.close(os);
- }
- }
-
- public Object parseBody(HttpMessage httpMessage) throws IOException {
- // lets assume the body is a reader
- HttpServletRequest request = httpMessage.getRequest();
- // there is only a body if we have a content length, or its -1 to indicate unknown length
- int len = request.getContentLength();
- LOG.trace("HttpServletRequest content-length: {}", len);
- if (len == 0) {
- return null;
- }
- if (isUseReaderForPayload()) {
- // use reader to read the response body
- return request.getReader();
- } else {
- // if we do not know if there is any data at all, then make sure to check the stream first
- if (len < 0 && isEagerCheckContentAvailable()) {
- InputStream is = request.getInputStream();
- if (is.available() == 0) {
- // no data so return null
- return null;
- }
- }
- // read the response body from servlet request
- return HttpHelper.readRequestBodyFromServletRequest(request, httpMessage.getExchange());
- }
- }
-
- public boolean isUseReaderForPayload() {
- return useReaderForPayload;
- }
-
- public void setUseReaderForPayload(boolean useReaderForPayload) {
- this.useReaderForPayload = useReaderForPayload;
- }
-
- public boolean isEagerCheckContentAvailable() {
- return eagerCheckContentAvailable;
- }
-
- public void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) {
- this.eagerCheckContentAvailable = eagerCheckContentAvailable;
- }
-
- public boolean isTransferException() {
- return transferException;
- }
-
- public void setTransferException(boolean transferException) {
- this.transferException = transferException;
- }
-
- public HeaderFilterStrategy getHeaderFilterStrategy() {
- return headerFilterStrategy;
- }
-
- public void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy) {
- this.headerFilterStrategy = headerFilterStrategy;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java
deleted file mode 100644
index 3c8b87d..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpBinding.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import java.io.IOException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.spi.HeaderFilterStrategy;
-
-/**
- * A pluggable strategy for configuring the http binding so reading request and writing response
- * can be customized using the Java Servlet API.
- * <p/>
- * This is also used by the <tt>camel-jetty</tt> component in the <tt>JettyHttpConsumer</tt> class.
- *
- * @version
- */
-public interface HttpBinding {
-
- /**
- * Strategy to read the given request and bindings it to the given message.
- *
- * @param request the request
- * @param message the message to populate with data from request
- */
- void readRequest(HttpServletRequest request, HttpMessage message);
-
- /**
- * Parses the body from a {@link org.apache.camel.component.http4.HttpMessage}
- *
- * @param httpMessage the http message
- * @return the parsed body returned as either a {@link java.io.InputStream} or a {@link java.io.Reader}
- * depending on the {@link #setUseReaderForPayload(boolean)} property.
- * @throws java.io.IOException can be thrown
- */
- Object parseBody(HttpMessage httpMessage) throws IOException;
-
- /**
- * Writes the exchange to the servlet response.
- * <p/>
- * Default implementation will delegate to the following methods depending on the status of the exchange
- * <ul>
- * <li>doWriteResponse - processing returns a OUT message </li>
- * <li>doWriteFaultResponse - processing returns a fault message</li>
- * <li>doWriteResponse - processing returns an exception and status code 500</li>
- * </ul>
- *
- * @param exchange the exchange
- * @param response the http response
- * @throws java.io.IOException can be thrown from http response
- */
- void writeResponse(Exchange exchange, HttpServletResponse response) throws IOException;
-
- /**
- * Strategy method that writes the response to the http response stream when an exception occurred
- *
- * @param exception the exception occurred
- * @param response the http response
- * @throws java.io.IOException can be thrown from http response
- */
- void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException;
-
- /**
- * Strategy method that writes the response to the http response stream for a fault message
- *
- * @param message the fault message
- * @param response the http response
- * @param exchange the exchange to provide context for header filtering
- * @throws java.io.IOException can be thrown from http response
- */
- void doWriteFaultResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException;
-
- /**
- * Strategy method that writes the response to the http response stream for an OUT message
- *
- * @param message the OUT message
- * @param response the http response
- * @param exchange the exchange to provide context for header filtering
- * @throws java.io.IOException can be thrown from http response
- */
- void doWriteResponse(Message message, HttpServletResponse response, Exchange exchange) throws IOException;
-
- /**
- * Should reader by used instead of input stream.
- *
- * @see #setUseReaderForPayload(boolean) for more details
- * @return <tt>true</tt> if reader should be used
- */
- boolean isUseReaderForPayload();
-
- /**
- * Should the {@link javax.servlet.http.HttpServletRequest#getReader()} be exposed as the payload of input messages in the Camel
- * {@link org.apache.camel.Message#getBody()} or not. If false then the {@link javax.servlet.http.HttpServletRequest#getInputStream()} will be exposed.
- * <p/>
- * Is default <tt>false</tt>.
- *
- * @param useReaderForPayload whether to use reader or not
- */
- void setUseReaderForPayload(boolean useReaderForPayload);
-
- /**
- * 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.
- */
- boolean isEagerCheckContentAvailable();
-
- /**
- * 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.
- */
- void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable);
-
- /**
- * If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back
- * serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or
- * Servlet Camel components). On the producer side the exception will be deserialized and thrown as is,
- * instead of the HttpOperationFailedException. The caused exception is required to be serialized.
- */
- boolean isTransferException();
-
- /**
- * If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back
- * serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or
- * Servlet Camel components). On the producer side the exception will be deserialized and thrown as is,
- * instead of the HttpOperationFailedException. The caused exception is required to be serialized.
- */
- void setTransferException(boolean transferException);
-
- /**
- * Gets the header filter strategy
- *
- * @return the strategy
- */
- HeaderFilterStrategy getHeaderFilterStrategy();
-
- /**
- * Sets the header filter strategy to use.
- * <p/>
- * Will default use {@link org.apache.camel.component.http4.HttpHeaderFilterStrategy}
- *
- * @param headerFilterStrategy the custom strategy
- */
- void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy);
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/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 9fc700d..a2be672 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
@@ -25,8 +25,11 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.Endpoint;
import org.apache.camel.ResolveEndpointFailedException;
-import org.apache.camel.component.http4.helper.HttpHelper;
-import org.apache.camel.impl.HeaderFilterStrategyComponent;
+import org.apache.camel.http.common.HttpBinding;
+import org.apache.camel.http.common.HttpCommonComponent;
+import org.apache.camel.http.common.HttpConfiguration;
+import org.apache.camel.http.common.HttpHelper;
+import org.apache.camel.http.common.UrlRewrite;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.ObjectHelper;
@@ -56,12 +59,12 @@ import org.slf4j.LoggerFactory;
*
* @version
*/
-public class HttpComponent extends HeaderFilterStrategyComponent {
+public class HttpComponent extends HttpCommonComponent {
+
private static final Logger LOG = LoggerFactory.getLogger(HttpComponent.class);
protected HttpClientConfigurer httpClientConfigurer;
protected HttpClientConnectionManager clientConnectionManager;
- protected HttpBinding httpBinding;
protected HttpContext httpContext;
protected SSLContextParameters sslContextParameters;
protected X509HostnameVerifier x509HostnameVerifier = new BrowserCompatHostnameVerifier();
@@ -77,22 +80,8 @@ public class HttpComponent extends HeaderFilterStrategyComponent {
super(HttpEndpoint.class);
}
- /**
- * Connects the URL specified on the endpoint to the specified processor.
- *
- * @param consumer the consumer
- * @throws Exception can be thrown
- */
- public void connect(HttpConsumer consumer) throws Exception {
- }
-
- /**
- * Disconnects the URL specified on the endpoint from the specified processor.
- *
- * @param consumer the consumer
- * @throws Exception can be thrown
- */
- public void disconnect(HttpConsumer consumer) throws Exception {
+ public HttpComponent(Class<? extends HttpEndpoint> endpointClass) {
+ super(endpointClass);
}
/**
@@ -286,9 +275,9 @@ public class HttpComponent extends HeaderFilterStrategyComponent {
} else {
setEndpointHeaderFilterStrategy(endpoint);
}
- endpoint.setHttpBinding(getHttpBinding());
+ endpoint.setBinding(getHttpBinding());
if (httpBinding != null) {
- endpoint.setHttpBinding(httpBinding);
+ endpoint.setBinding(httpBinding);
}
if (httpMethodRestrict != null) {
endpoint.setHttpMethodRestrict(httpMethodRestrict);
@@ -375,15 +364,21 @@ public class HttpComponent extends HeaderFilterStrategyComponent {
this.clientConnectionManager = clientConnectionManager;
}
- public HttpBinding getHttpBinding() {
- return httpBinding;
- }
-
/**
* To use a custom HttpBinding to control the mapping between Camel message and HttpClient.
*/
public void setHttpBinding(HttpBinding httpBinding) {
- this.httpBinding = httpBinding;
+ // need to override and call super for component docs
+ super.setHttpBinding(httpBinding);
+ }
+
+ /**
+ * To use the shared HttpConfiguration as base configuration.
+ */
+ @Override
+ public void setHttpConfiguration(HttpConfiguration httpConfiguration) {
+ // need to override and call super for component docs
+ super.setHttpConfiguration(httpConfiguration);
}
public HttpContext getHttpContext() {
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/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
deleted file mode 100644
index 1ddf687..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConsumer.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import org.apache.camel.Processor;
-import org.apache.camel.impl.DefaultConsumer;
-
-/**
- * @version
- */
-@Deprecated
-public class HttpConsumer extends DefaultConsumer {
-
- private boolean traceEnabled;
-
- public HttpConsumer(HttpEndpoint endpoint, Processor processor) {
- super(endpoint, processor);
- if (endpoint.isTraceEnabled()) {
- setTraceEnabled(true);
- }
- }
-
- @Override
- public HttpEndpoint getEndpoint() {
- return (HttpEndpoint)super.getEndpoint();
- }
-
- public HttpBinding getBinding() {
- return getEndpoint().getHttpBinding();
- }
-
- public String getPath() {
- return getEndpoint().getPath();
- }
-
- @Override
- protected void doStart() throws Exception {
- super.doStart();
- getEndpoint().connect(this);
- }
-
- @Override
- protected void doStop() throws Exception {
- getEndpoint().disconnect(this);
- super.doStop();
- }
-
- public boolean isTraceEnabled() {
- return traceEnabled;
- }
-
- public void setTraceEnabled(boolean traceEnabled) {
- this.traceEnabled = traceEnabled;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java
deleted file mode 100644
index dead494..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpConverter.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.camel.Converter;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.util.GZIPHelper;
-
-/**
- * Some converter methods making it easy to convert the body of a message to servlet types or to switch between
- * the underlying {@link ServletInputStream} or {@link BufferedReader} payloads etc.
- *
- * @version
- */
-@Converter
-public final class HttpConverter {
-
- private HttpConverter() {
- }
-
- @Converter
- public static HttpServletRequest toServletRequest(Message message) {
- if (message == null) {
- return null;
- }
- return message.getHeader(Exchange.HTTP_SERVLET_REQUEST, HttpServletRequest.class);
- }
-
- @Converter
- public static HttpServletResponse toServletResponse(Message message) {
- if (message == null) {
- return null;
- }
- return message.getHeader(Exchange.HTTP_SERVLET_RESPONSE, HttpServletResponse.class);
- }
-
- @Converter
- public static ServletInputStream toServletInputStream(HttpMessage message) throws IOException {
- HttpServletRequest request = toServletRequest(message);
- if (request != null) {
- return request.getInputStream();
- }
- return null;
- }
-
- @Converter
- public static InputStream toInputStream(HttpMessage message, Exchange exchange) throws Exception {
- return toInputStream(toServletRequest(message), exchange);
- }
-
- @Converter
- public static BufferedReader toReader(HttpMessage message) throws IOException {
- HttpServletRequest request = toServletRequest(message);
- if (request != null) {
- return request.getReader();
- }
- return null;
- }
-
- @Converter
- public static InputStream toInputStream(HttpServletRequest request, Exchange exchange) throws IOException {
- if (request == null) {
- return null;
- }
- InputStream is = request.getInputStream();
- if (is != null && is.available() <= 0) {
- // there is no data, so we cannot uncompress etc.
- return is;
- }
- if (exchange == null || !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) {
- String contentEncoding = request.getHeader(Exchange.CONTENT_ENCODING);
- return GZIPHelper.uncompressGzip(contentEncoding, is);
- } else {
- return is;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/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 c2c2c57..57e9795 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
@@ -23,14 +23,10 @@ import org.apache.camel.Consumer;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.component.http4.helper.HttpHelper;
-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.http.common.HttpCommonEndpoint;
+import org.apache.camel.http.common.HttpHelper;
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.http.HttpHost;
import org.apache.http.client.CookieStore;
@@ -49,50 +45,24 @@ import org.slf4j.LoggerFactory;
* @version
*/
@UriEndpoint(scheme = "http4,http4s", title = "HTTP4,HTTP4S", syntax = "http4:httpUri", producerOnly = true, label = "http")
-public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware {
+public class HttpEndpoint extends HttpCommonEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(HttpEndpoint.class);
+
+ // Note: all options must be documented with description in annotations so extended components can access the documentation
+
private HttpContext httpContext;
- private HttpComponent component;
private HttpClientConfigurer httpClientConfigurer;
private HttpClientConnectionManager clientConnectionManager;
private HttpClientBuilder clientBuilder;
- private HttpClient httpClient;
- private UrlRewrite urlRewrite;
- private CookieStore cookieStore = new BasicCookieStore();
+ private HttpClient httpClient;
- @UriPath @Metadata(required = "true", label = "producer")
- private URI httpUri;
- @UriParam
- private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
- @UriParam
- private HttpBinding httpBinding;
- @UriParam(label = "producer", defaultValue = "true")
- private boolean throwExceptionOnFailure = true;
@UriParam(label = "producer")
- private boolean bridgeEndpoint;
- @UriParam(label = "consumer")
- private boolean matchOnUriPrefix;
- @UriParam(defaultValue = "true")
- private boolean chunked = true;
- @UriParam(label = "consumer")
- private boolean disableStreamCache;
- @UriParam
- private boolean transferException;
- @UriParam(label = "consumer")
- private boolean traceEnabled;
+ private CookieStore cookieStore = new BasicCookieStore();
@UriParam(label = "producer")
private boolean authenticationPreemptive;
- @UriParam(label = "consumer")
- private String httpMethodRestrict;
@UriParam(label = "producer", defaultValue = "true")
private boolean clearExpiredCookies = true;
- @UriParam(label = "producer")
- private boolean ignoreResponseBody;
- @UriParam(label = "producer", defaultValue = "true")
- private boolean copyHeaders = true;
- @UriParam(label = "consumer")
- private boolean eagerCheckContentAvailable;
public HttpEndpoint() {
}
@@ -112,9 +82,7 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
public HttpEndpoint(String endPointURI, HttpComponent component, URI httpURI, HttpClientBuilder clientBuilder,
HttpClientConnectionManager clientConnectionManager, HttpClientConfigurer clientConfigurer) throws URISyntaxException {
- super(endPointURI, component);
- this.component = component;
- this.httpUri = httpURI;
+ super(endPointURI, component, httpURI);
this.clientBuilder = clientBuilder;
this.httpClientConfigurer = clientConfigurer;
this.clientConnectionManager = clientConnectionManager;
@@ -196,32 +164,19 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
return clientBuilder.build();
}
- 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;
+ @Override
+ public HttpComponent getComponent() {
+ return (HttpComponent) super.getComponent();
}
- public boolean isSingleton() {
- return true;
- }
-
@Override
protected void doStop() throws Exception {
- if (component != null && component.getClientConnectionManager() != clientConnectionManager) {
+ if (getComponent() != null && getComponent().getClientConnectionManager() != clientConnectionManager) {
// need to shutdown the ConnectionManager
clientConnectionManager.shutdown();
}
}
-
// Properties
//-------------------------------------------------------------------------
@@ -257,59 +212,10 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
this.httpClientConfigurer = httpClientConfigurer;
}
- public HttpBinding getHttpBinding() {
- if (httpBinding == null) {
- // create a new binding and use the options from this endpoint
- httpBinding = new DefaultHttpBinding();
- httpBinding.setHeaderFilterStrategy(getHeaderFilterStrategy());
- httpBinding.setTransferException(isTransferException());
- httpBinding.setEagerCheckContentAvailable(isEagerCheckContentAvailable());
- }
- return httpBinding;
- }
-
- /**
- * 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) {
this.httpContext = httpContext;
}
- 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()) || "https4".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 HttpClientConnectionManager getClientConnectionManager() {
return clientConnectionManager;
}
@@ -321,131 +227,6 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
this.clientConnectionManager = clientConnectionManager;
}
- 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 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;
- }
-
- 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 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 boolean isClearExpiredCookies() {
return clearExpiredCookies;
}
@@ -483,38 +264,4 @@ public class HttpEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
this.authenticationPreemptive = authenticationPreemptive;
}
- public boolean isIgnoreResponseBody() {
- return ignoreResponseBody;
- }
-
- /**
- * If this option is true, The http producer won't read response body and cached the input stream.
- */
- public void setIgnoreResponseBody(boolean ignoreResponseBody) {
- this.ignoreResponseBody = ignoreResponseBody;
- }
-
- 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;
- }
-
- /**
- * 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;
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpHeaderFilterStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpHeaderFilterStrategy.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpHeaderFilterStrategy.java
deleted file mode 100644
index 906bf29..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpHeaderFilterStrategy.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import org.apache.camel.impl.DefaultHeaderFilterStrategy;
-
-/**
- * @version
- */
-public class HttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
-
- public HttpHeaderFilterStrategy() {
- initialize();
- }
-
- protected void initialize() {
- getOutFilter().add("content-length");
- getOutFilter().add("content-type");
- getOutFilter().add("host");
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getOutFilter().add("cache-control");
- getOutFilter().add("connection");
- getOutFilter().add("date");
- getOutFilter().add("pragma");
- getOutFilter().add("trailer");
- getOutFilter().add("transfer-encoding");
- getOutFilter().add("upgrade");
- getOutFilter().add("via");
- getOutFilter().add("warning");
-
- setLowerCase(true);
-
- // filter headers begin with "Camel" or "org.apache.camel"
- // must ignore case for Http based transports
- setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/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
deleted file mode 100644
index 69df1d6..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpMessage.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.impl.DefaultMessage;
-import org.apache.camel.util.ObjectHelper;
-
-/**
- * @version
- */
-public class HttpMessage extends DefaultMessage {
-
- private HttpServletRequest request;
- private HttpServletResponse response;
-
- public HttpMessage(Exchange exchange, HttpServletRequest request, HttpServletResponse response) {
- setExchange(exchange);
- this.request = request;
- this.response = response;
- // Put the request and response into the message header
- this.setHeader(Exchange.HTTP_SERVLET_REQUEST, request);
- this.setHeader(Exchange.HTTP_SERVLET_RESPONSE, response);
-
- // Check the setting of exchange
- Boolean flag = exchange.getProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.class);
- if (flag != null && flag) {
- this.setHeader(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE);
- }
- // use binding to read the request allowing end users to use their
- // implementation of the binding
- getEndpoint().getHttpBinding().readRequest(request, this);
- }
-
- public HttpServletRequest getRequest() {
- return request;
- }
-
- public HttpServletResponse getResponse() {
- return response;
- }
-
- @Override
- protected Object createBody() {
- try {
- return getEndpoint().getHttpBinding().parseBody(this);
- } catch (IOException e) {
- throw new RuntimeCamelException(e);
- }
- }
-
- private HttpEndpoint getEndpoint() {
- return (HttpEndpoint) getExchange().getFromEndpoint();
- }
-
- @Override
- public String toString() {
- // do not use toString on HTTP message
- return "HttpMessage@" + ObjectHelper.getIdentityHashCode(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpOperationFailedException.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpOperationFailedException.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpOperationFailedException.java
deleted file mode 100644
index 2c3f354..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpOperationFailedException.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import java.util.Map;
-
-import org.apache.camel.CamelException;
-import org.apache.camel.util.ObjectHelper;
-
-public class HttpOperationFailedException extends CamelException {
- private static final long serialVersionUID = -8721487434390572634L;
- private final String uri;
- private final String redirectLocation;
- private final int statusCode;
- private final String statusText;
- private final Map<String, String> responseHeaders;
- private final String responseBody;
-
- public HttpOperationFailedException(String uri, int statusCode, String statusText, String location, Map<String, String> responseHeaders, String responseBody) {
- super("HTTP operation failed invoking " + uri + " with statusCode: " + statusCode + (location != null ? ", redirectLocation: " + location : ""));
- this.uri = uri;
- this.statusCode = statusCode;
- this.statusText = statusText;
- this.redirectLocation = location;
- this.responseHeaders = responseHeaders;
- this.responseBody = responseBody;
- }
-
- public String getUri() {
- return uri;
- }
-
- public boolean isRedirectError() {
- return statusCode >= 300 && statusCode < 400;
- }
-
- public boolean hasRedirectLocation() {
- return ObjectHelper.isNotEmpty(redirectLocation);
- }
-
- public String getRedirectLocation() {
- return redirectLocation;
- }
-
- public int getStatusCode() {
- return statusCode;
- }
-
- public String getStatusText() {
- return statusText;
- }
-
- public Map<String, String> getResponseHeaders() {
- return responseHeaders;
- }
-
- public String getResponseBody() {
- return responseBody;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java
index ff74cee..0020094 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpPollingConsumer.java
@@ -22,7 +22,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.ServicePoolAware;
-import org.apache.camel.component.http4.helper.HttpHelper;
+import org.apache.camel.http.common.HttpHelper;
import org.apache.camel.impl.PollingConsumerSupport;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.http.Header;
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index 258c6a4..026754c 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -36,9 +36,11 @@ import org.apache.camel.CamelExchangeException;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.file.GenericFile;
-import org.apache.camel.component.http4.helper.HttpHelper;
-
+import org.apache.camel.component.http4.helper.HttpMethodHelper;
import org.apache.camel.converter.stream.CachedOutputStream;
+import org.apache.camel.http.common.HttpHelper;
+import org.apache.camel.http.common.HttpOperationFailedException;
+import org.apache.camel.http.common.HttpProtocolHeaderFilterStrategy;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.ExchangeHelper;
@@ -50,6 +52,7 @@ import org.apache.camel.util.URISupport;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpRequestBase;
@@ -110,7 +113,8 @@ public class HttpProducer extends DefaultProducer {
String httpProtocolVersion = in.getHeader(Exchange.HTTP_PROTOCOL_VERSION, String.class);
if (httpProtocolVersion != null) {
// set the HTTP protocol version
- httpRequest.setProtocolVersion(HttpHelper.parserHttpVersion(httpProtocolVersion));
+ int[] version = HttpHelper.parserHttpVersion(httpProtocolVersion);
+ httpRequest.setProtocolVersion(new HttpVersion(version[0], version[1]));
}
HeaderFilterStrategy strategy = getEndpoint().getHeaderFilterStrategy();
@@ -377,7 +381,7 @@ public class HttpProducer extends DefaultProducer {
// create http holder objects for the request
HttpEntity requestEntity = createRequestEntity(exchange);
- HttpMethods methodToUse = HttpHelper.createMethod(exchange, getEndpoint(), requestEntity != null);
+ HttpMethods methodToUse = HttpMethodHelper.createMethod(exchange, getEndpoint(), requestEntity != null);
HttpRequestBase method = methodToUse.createMethod(url);
LOG.trace("Using URL: {} with method: {}", url, method);
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProtocolHeaderFilterStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProtocolHeaderFilterStrategy.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProtocolHeaderFilterStrategy.java
deleted file mode 100644
index e7ae36d..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProtocolHeaderFilterStrategy.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import org.apache.camel.impl.DefaultHeaderFilterStrategy;
-
-
-public class HttpProtocolHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
-
- public HttpProtocolHeaderFilterStrategy() {
- initialize();
- }
-
- // Just add the http headers here
- protected void initialize() {
- getInFilter().add("host");
-
- getInFilter().add("content-encoding");
- getInFilter().add("content-language");
- getInFilter().add("content-location");
- getInFilter().add("content-md5");
- getInFilter().add("content-length");
- getInFilter().add("content-type");
- getInFilter().add("content-range");
-
- getInFilter().add("dav");
- getInFilter().add("depth");
- getInFilter().add("destination");
- getInFilter().add("etag");
- getInFilter().add("expect");
- getInFilter().add("expires");
- getInFilter().add("from");
- getInFilter().add("if");
- getInFilter().add("if-match");
- getInFilter().add("if-modified-since");
- getInFilter().add("if-none-match");
- getInFilter().add("if-range");
- getInFilter().add("if-unmodified-since");
- getInFilter().add("last-modified");
- getInFilter().add("location");
- getInFilter().add("lock-token");
- getInFilter().add("max-forwards");
- getInFilter().add("overwrite");
- getInFilter().add("pragma");
- getInFilter().add("proxy-authenticate");
- getInFilter().add("proxy-authorization");
- getInFilter().add("range");
- getInFilter().add("referer");
- getInFilter().add("retry-after");
- getInFilter().add("server");
- getInFilter().add("status-uri");
- getInFilter().add("te");
- getInFilter().add("timeout");
-
- getInFilter().add("user-agent");
- getInFilter().add("vary");
-
- getInFilter().add("www-authenticate");
-
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getInFilter().add("cache-control");
- getInFilter().add("connection");
- getInFilter().add("date");
- getInFilter().add("pragma");
- getInFilter().add("trailer");
- getInFilter().add("transfer-encoding");
- getInFilter().add("upgrade");
- getInFilter().add("via");
- getInFilter().add("warning");
-
- setLowerCase(true);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/be77f1a0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpServletUrlRewrite.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpServletUrlRewrite.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpServletUrlRewrite.java
deleted file mode 100644
index 4d132dd..0000000
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpServletUrlRewrite.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http4;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.camel.Producer;
-
-/**
- * Extended {@link UrlRewrite} which leverages {@link HttpServletRequest}
- * during the rewrite process.
- * <p/>
- * For example the camel-urlrewrite component supports
- * {@link HttpServletUrlRewrite} implementations.
- */
-public interface HttpServletUrlRewrite extends UrlRewrite {
-
- /**
- * Rewrite the url.
- *
- * @param url the absolute url (eg with scheme://host:port/path?query)
- * @param relativeUrl optional relative url, if bridging endpoints, which then would be without the base path from the
- * endpoint from the given producer.
- * @param producer the producer to use the rewritten url
- * @param request the http servlet request
- * @return the rewritten url, or <tt>null</tt> to use the original url
- * @throws Exception is thrown if error rewriting the url
- */
- String rewrite(String url, String relativeUrl, Producer producer, HttpServletRequest request) throws Exception;
-
-}