Repository: camel
Updated Branches:
  refs/heads/master 0aba99b26 -> bfd6e49d2


CAMEL-9972: Explicitly add Connection Close HTTP header with a parameter in URI 
- camel-http4


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

Branch: refs/heads/master
Commit: d4ade0f000ca609e26115ed059c1d436ef47d72b
Parents: 0aba99b
Author: Andrea Cosentino <[email protected]>
Authored: Wed May 18 08:05:07 2016 +0200
Committer: Andrea Cosentino <[email protected]>
Committed: Wed May 18 08:05:07 2016 +0200

----------------------------------------------------------------------
 .../camel/http/common/HttpCommonEndpoint.java   |  13 +++
 components/camel-http4/src/main/docs/http4.adoc |   5 +-
 .../camel/component/http4/HttpProducer.java     |   5 +
 .../http4/HttpProducerConnectioCloseTest.java   | 103 -------------------
 .../http4/HttpProducerConnectionCloseTest.java  | 103 +++++++++++++++++++
 ...HttpProducerExplicitConnectionCloseTest.java |  86 ++++++++++++++++
 6 files changed, 211 insertions(+), 104 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d4ade0f0/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java
 
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java
index 99f03ea..0622e31 100644
--- 
a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java
+++ 
b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpCommonEndpoint.java
@@ -82,6 +82,8 @@ public abstract class HttpCommonEndpoint extends 
DefaultEndpoint implements Head
             + " This is by default turned off. If you enable this then be 
aware that Java will deserialize the incoming"
             + " data from the request to Java and that can be a potential 
security risk.")
     boolean transferException;
+    @UriParam(label = "producer", defaultValue = "false", description = 
"Specifies whether a Connection Close header must be added to HTTP Request. By 
default connectionClose is false.")
+    boolean connectionClose;
     @UriParam(label = "consumer",
             description = "Specifies whether to enable HTTP TRACE for this 
Servlet consumer. By default TRACE is turned off.")
     boolean traceEnabled;
@@ -363,6 +365,17 @@ public abstract class HttpCommonEndpoint extends 
DefaultEndpoint implements Head
     public boolean isTransferException() {
         return transferException;
     }
+    
+       public boolean isConnectionClose() {
+               return connectionClose;
+       }
+
+    /**
+     * If this option is true, the producer will add a Connection Close header 
to HTTP Request
+     */
+       public void setConnectionClose(boolean connectionClose) {
+               this.connectionClose = connectionClose;
+       }
 
     /**
      * If enabled and an Exchange failed processing on the consumer side, and 
if the caused Exception was send back serialized

http://git-wip-us.apache.org/repos/asf/camel/blob/d4ade0f0/components/camel-http4/src/main/docs/http4.adoc
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/docs/http4.adoc 
b/components/camel-http4/src/main/docs/http4.adoc
index 1e15683..7dd204e 100644
--- a/components/camel-http4/src/main/docs/http4.adoc
+++ b/components/camel-http4/src/main/docs/http4.adoc
@@ -88,8 +88,9 @@ The HTTP4 component supports 13 options which are listed 
below.
 
 
 
+
 // endpoint options: START
-The HTTP4 component supports 31 endpoint options which are listed below:
+The HTTP4 component supports 32 endpoint options which are listed below:
 
 {% raw %}
 [width="100%",cols="2s,1,1m,1m,5",options="header"]
@@ -102,6 +103,7 @@ The HTTP4 component supports 31 endpoint options which are 
listed below:
 | bridgeEndpoint | producer | false | boolean | 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.
 | chunked | producer | true | boolean | If this option is false the Servlet 
will disable the HTTP streaming and set the content-length header on the 
response
 | clearExpiredCookies | producer | true | boolean | Whether to clear expired 
cookies before sending the HTTP request. This ensures the cookies store does 
not keep growing by adding new cookies which is newer removed when they are 
expired.
+| connectionClose | producer | false | boolean | Specifies whether a 
Connection Close header must be added to HTTP Request. By default 
connectionClose is false.
 | cookieStore | producer |  | CookieStore | To use a custom 
org.apache.http.client.CookieStore. By default the 
org.apache.http.impl.client.BasicCookieStore is used which is an in-memory only 
cookie store. Notice if bridgeEndpoint=true then the cookie store is forced to 
be a noop cookie store as cookie shouldn't be stored as we are just bridging 
(eg acting as a proxy).
 | copyHeaders | producer | true | boolean | 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).
 | headerFilterStrategy | producer |  | HeaderFilterStrategy | To use a custom 
HeaderFilterStrategy to filter header to and from Camel message.
@@ -135,6 +137,7 @@ The HTTP4 component supports 31 endpoint options which are 
listed below:
 
 
 
+
 [[HTTP4-MessageHeaders]]
 Message Headers
 ^^^^^^^^^^^^^^^

http://git-wip-us.apache.org/repos/asf/camel/blob/d4ade0f0/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 3b38911..e10866d 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
@@ -65,6 +65,7 @@ import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.auth.BasicScheme;
 import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.EntityUtils;
 import org.slf4j.Logger;
@@ -163,6 +164,10 @@ public class HttpProducer extends DefaultProducer {
                 httpRequest.setHeader("Host", hostHeader);
             }
         }
+        
+        if (getEndpoint().isConnectionClose()) {
+               httpRequest.addHeader("Connection", HTTP.CONN_CLOSE);
+        }
 
         // lets store the result in the output message.
         HttpResponse httpResponse = null;

http://git-wip-us.apache.org/repos/asf/camel/blob/d4ade0f0/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerConnectioCloseTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerConnectioCloseTest.java
 
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerConnectioCloseTest.java
deleted file mode 100644
index 29b8c15..0000000
--- 
a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerConnectioCloseTest.java
+++ /dev/null
@@ -1,103 +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.EndpointInject;
-import org.apache.camel.Exchange;
-import org.apache.camel.component.http4.handler.BasicValidationHandler;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.http.common.HttpHeaderFilterStrategy;
-import org.apache.camel.impl.JndiRegistry;
-import org.apache.http.impl.bootstrap.HttpServer;
-import org.apache.http.impl.bootstrap.ServerBootstrap;
-import org.apache.http.protocol.HTTP;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Unit test that show custom header filter useful to send Connection Close 
header
- *
- * @version 
- */
-public class HttpProducerConnectioCloseTest extends BaseHttpTest {
-
-    @EndpointInject(uri = "mock:result")
-    protected MockEndpoint mockResultEndpoint;
-    
-    private HttpServer localServer;
-    
-    @Before
-    @Override
-    public void setUp() throws Exception {
-        localServer = ServerBootstrap.bootstrap().
-                setHttpProcessor(getBasicHttpProcessor()).
-                setConnectionReuseStrategy(getConnectionReuseStrategy()).
-                setResponseFactory(getHttpResponseFactory()).
-                setExpectationVerifier(getHttpExpectationVerifier()).
-                setSslContext(getSSLContext()).
-                registerHandler("/myget", new BasicValidationHandler("GET", 
null, null, getExpectedContent())).
-                create();
-        localServer.start();
-
-        super.setUp();
-    }
-
-    @After
-    @Override
-    public void tearDown() throws Exception {
-        super.tearDown();
-
-        if (localServer != null) {
-            localServer.stop();
-        }
-    }
-
-    @Test
-    public void noDataDefaultIsGet() throws Exception {
-        HttpComponent component = context.getComponent("http4", 
HttpComponent.class);
-        component.setConnectionTimeToLive(1000L);
-        HttpEndpoint endpoiont = (HttpEndpoint) 
component.createEndpoint("http4://" + 
localServer.getInetAddress().getHostName() + ":" 
-            + localServer.getLocalPort() + 
"/myget?headerFilterStrategy=#myFilter");
-        HttpProducer producer = new HttpProducer(endpoiont);
-        Exchange exchange = producer.createExchange();
-        exchange.getIn().setBody(null);
-        exchange.getIn().setHeader("connection", HTTP.CONN_CLOSE);
-        producer.start();
-        producer.process(exchange);
-        producer.stop();
-
-        assertEquals(HTTP.CONN_CLOSE, 
exchange.getOut().getHeader("connection"));
-        assertExchange(exchange);
-    }
-    
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = new JndiRegistry(createJndiContext());
-        ConnectionCloseHeaderFilter connectionCloseFilterStrategy = new 
ConnectionCloseHeaderFilter();
-        jndi.bind("myFilter", connectionCloseFilterStrategy);
-        return jndi;
-    }
-    
-    class ConnectionCloseHeaderFilter extends HttpHeaderFilterStrategy {
-        @Override
-        protected void initialize() {
-            super.initialize();
-            getOutFilter().remove("connection");
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/d4ade0f0/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerConnectionCloseTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerConnectionCloseTest.java
 
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerConnectionCloseTest.java
new file mode 100644
index 0000000..e51a927
--- /dev/null
+++ 
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerConnectionCloseTest.java
@@ -0,0 +1,103 @@
+/**
+ * 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.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.http4.handler.BasicValidationHandler;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.http.common.HttpHeaderFilterStrategy;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
+import org.apache.http.protocol.HTTP;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test that show custom header filter useful to send Connection Close 
header
+ *
+ * @version 
+ */
+public class HttpProducerConnectionCloseTest extends BaseHttpTest {
+
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint mockResultEndpoint;
+    
+    private HttpServer localServer;
+    
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        localServer = ServerBootstrap.bootstrap().
+                setHttpProcessor(getBasicHttpProcessor()).
+                setConnectionReuseStrategy(getConnectionReuseStrategy()).
+                setResponseFactory(getHttpResponseFactory()).
+                setExpectationVerifier(getHttpExpectationVerifier()).
+                setSslContext(getSSLContext()).
+                registerHandler("/myget", new BasicValidationHandler("GET", 
null, null, getExpectedContent())).
+                create();
+        localServer.start();
+
+        super.setUp();
+    }
+
+    @After
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+
+    @Test
+    public void noDataDefaultIsGet() throws Exception {
+        HttpComponent component = context.getComponent("http4", 
HttpComponent.class);
+        component.setConnectionTimeToLive(1000L);
+        HttpEndpoint endpoiont = (HttpEndpoint) 
component.createEndpoint("http4://" + 
localServer.getInetAddress().getHostName() + ":" 
+            + localServer.getLocalPort() + 
"/myget?headerFilterStrategy=#myFilter");
+        HttpProducer producer = new HttpProducer(endpoiont);
+        Exchange exchange = producer.createExchange();
+        exchange.getIn().setBody(null);
+        exchange.getIn().setHeader("connection", HTTP.CONN_CLOSE);
+        producer.start();
+        producer.process(exchange);
+        producer.stop();
+
+        assertEquals(HTTP.CONN_CLOSE, 
exchange.getOut().getHeader("connection"));
+        assertExchange(exchange);
+    }
+    
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = new JndiRegistry(createJndiContext());
+        ConnectionCloseHeaderFilter connectionCloseFilterStrategy = new 
ConnectionCloseHeaderFilter();
+        jndi.bind("myFilter", connectionCloseFilterStrategy);
+        return jndi;
+    }
+    
+    class ConnectionCloseHeaderFilter extends HttpHeaderFilterStrategy {
+        @Override
+        protected void initialize() {
+            super.initialize();
+            getOutFilter().remove("connection");
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/d4ade0f0/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerExplicitConnectionCloseTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerExplicitConnectionCloseTest.java
 
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerExplicitConnectionCloseTest.java
new file mode 100644
index 0000000..3694e4d
--- /dev/null
+++ 
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerExplicitConnectionCloseTest.java
@@ -0,0 +1,86 @@
+/**
+ * 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.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.http4.handler.BasicValidationHandler;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.http.common.HttpHeaderFilterStrategy;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.http.impl.bootstrap.HttpServer;
+import org.apache.http.impl.bootstrap.ServerBootstrap;
+import org.apache.http.protocol.HTTP;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Unit test that show custom header filter useful to send Connection Close 
header
+ *
+ * @version 
+ */
+public class HttpProducerExplicitConnectionCloseTest extends BaseHttpTest {
+
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint mockResultEndpoint;
+    
+    private HttpServer localServer;
+    
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        localServer = ServerBootstrap.bootstrap().
+                setHttpProcessor(getBasicHttpProcessor()).
+                setConnectionReuseStrategy(getConnectionReuseStrategy()).
+                setResponseFactory(getHttpResponseFactory()).
+                setExpectationVerifier(getHttpExpectationVerifier()).
+                setSslContext(getSSLContext()).
+                registerHandler("/myget", new BasicValidationHandler("GET", 
null, null, getExpectedContent())).
+                create();
+        localServer.start();
+
+        super.setUp();
+    }
+
+    @After
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        if (localServer != null) {
+            localServer.stop();
+        }
+    }
+
+    @Test
+    public void noDataDefaultIsGet() throws Exception {
+        HttpComponent component = context.getComponent("http4", 
HttpComponent.class);
+        component.setConnectionTimeToLive(1000L);
+        HttpEndpoint endpoiont = (HttpEndpoint) 
component.createEndpoint("http4://" + 
localServer.getInetAddress().getHostName() + ":" 
+            + localServer.getLocalPort() + "/myget?connectionClose=true");
+        HttpProducer producer = new HttpProducer(endpoiont);
+        Exchange exchange = producer.createExchange();
+        exchange.getIn().setBody(null);
+        producer.start();
+        producer.process(exchange);
+        producer.stop();
+
+        assertEquals(HTTP.CONN_CLOSE, 
exchange.getOut().getHeader("connection"));
+        assertExchange(exchange);
+    }
+}
\ No newline at end of file

Reply via email to