camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-10916: Add option to turn on body on HTTP delete in http4 component
Date Mon, 06 Mar 2017 15:27:36 GMT
Repository: camel
Updated Branches:
  refs/heads/master 9bd6d31bb -> dfa2456cc


CAMEL-10916: Add option to turn on body on HTTP delete in http4 component


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

Branch: refs/heads/master
Commit: 7657d7718b328c1f676e2574f8678b8dd99379e0
Parents: 9bd6d31
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Mar 6 16:05:02 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Mar 6 16:05:02 2017 +0100

----------------------------------------------------------------------
 .../src/main/docs/http4-component.adoc          |  3 +-
 .../http4/HttpDeleteWithBodyMethod.java         | 36 ++++++++++++++++++++
 .../camel/component/http4/HttpEndpoint.java     | 16 +++++++++
 .../camel/component/http4/HttpProducer.java     |  5 +++
 .../camel/component/http4/HttpMethodsTest.java  | 19 ++++++++++-
 5 files changed, 77 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7657d771/components/camel-http4/src/main/docs/http4-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/docs/http4-component.adoc b/components/camel-http4/src/main/docs/http4-component.adoc
index cda92ee..e23d7f7 100644
--- a/components/camel-http4/src/main/docs/http4-component.adoc
+++ b/components/camel-http4/src/main/docs/http4-component.adoc
@@ -97,7 +97,7 @@ The HTTP4 component is configured using the URI syntax with the following
path a
 | httpUri |  | URI | *Required* The url of the HTTP endpoint to call.
 |=======================================================================
 
-#### Query Parameters (47 parameters):
+#### Query Parameters (48 parameters):
 
 [width="100%",cols="2,1,1m,1m,5",options="header"]
 |=======================================================================
@@ -112,6 +112,7 @@ The HTTP4 component is configured using the URI syntax with the following
path a
 | 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).
If a cookieHandler is set then the cookie store is also forced to be a noop cookie store as
cookie handling is then performed by the cookieHandler.
 | 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).
+| deleteWithBody | producer | false | boolean | Whether the HTTP DELETE should include the
message body or not. By default HTTP DELETE do not include any HTTP message. However in some
rare cases users may need to be able to include the message body.
 | httpMethod | producer |  | HttpMethods | Configure the HTTP method to use. The HttpMethod
header cannot override this option if set.
 | ignoreResponseBody | producer | false | boolean | If this option is true The http producer
won't read response body and cache the input stream
 | preserveHostHeader | producer | false | boolean | If the option is true HttpProducer will
set the Host header to the value contained in the current exchange Host header useful in reverse
proxy applications where you want the Host header received by the downstream server to reflect
the URL called by the upstream client this allows applications which use the Host header to
generate accurate URL's for a proxied service

http://git-wip-us.apache.org/repos/asf/camel/blob/7657d771/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpDeleteWithBodyMethod.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpDeleteWithBodyMethod.java
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpDeleteWithBodyMethod.java
new file mode 100644
index 0000000..1fee560
--- /dev/null
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpDeleteWithBodyMethod.java
@@ -0,0 +1,36 @@
+/**
+ * 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.net.URI;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+
+public class HttpDeleteWithBodyMethod extends HttpEntityEnclosingRequestBase {
+
+    public static final String METHOD_NAME = "DELETE";
+
+    public HttpDeleteWithBodyMethod(String uri, HttpEntity entity) {
+        setURI(URI.create(uri));
+        setEntity(entity);
+    }
+
+    public String getMethod() {
+        return METHOD_NAME;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7657d771/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 aa7843b..6e3315b 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
@@ -75,6 +75,8 @@ public class HttpEndpoint extends HttpCommonEndpoint {
     private boolean authenticationPreemptive;
     @UriParam(label = "producer", defaultValue = "true")
     private boolean clearExpiredCookies = true;
+    @UriParam(label = "producer")
+    private boolean deleteWithBody;
 
     @UriParam(label = "advanced", defaultValue = "200")
     private int maxTotalConnections;
@@ -271,6 +273,20 @@ public class HttpEndpoint extends HttpCommonEndpoint {
         this.clearExpiredCookies = clearExpiredCookies;
     }
 
+    public boolean isDeleteWithBody() {
+        return deleteWithBody;
+    }
+
+    /**
+     * Whether the HTTP DELETE should include the message body or not.
+     * <p/>
+     * By default HTTP DELETE do not include any HTTP message. However in some rare cases
users may need to be able to include the
+     * message body.
+     */
+    public void setDeleteWithBody(boolean deleteWithBody) {
+        this.deleteWithBody = deleteWithBody;
+    }
+
     public CookieStore getCookieStore() {
         return cookieStore;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7657d771/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 085d3d7..4c6154c 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
@@ -456,6 +456,11 @@ public class HttpProducer extends DefaultProducer {
         HttpMethods methodToUse = HttpMethodHelper.createMethod(exchange, getEndpoint(),
requestEntity != null);
         HttpRequestBase method = methodToUse.createMethod(url);
 
+        // special for HTTP DELETE if the message body should be included
+        if (getEndpoint().isDeleteWithBody() && "DELETE".equals(method.getMethod()))
{
+            method = new HttpDeleteWithBodyMethod(url, requestEntity);
+        }
+
         LOG.trace("Using URL: {} with method: {}", url, method);
 
         if (methodToUse.isEntityEnclosing()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/7657d771/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
index 397618f..0e552ac 100644
--- a/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
+++ b/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpMethodsTest.java
@@ -50,11 +50,12 @@ public class HttpMethodsTest extends BaseHttpTest {
                 registerHandler("/patch", new BasicValidationHandler("PATCH", null, null,
getExpectedContent())).
                 registerHandler("/patch1", new BasicValidationHandler("PATCH", null, "rocks
camel?", getExpectedContent())).
                 registerHandler("/post", new BasicValidationHandler("POST", null, null, getExpectedContent())).
-                registerHandler("/post1", new BasicValidationHandler("POST", null, null,
getExpectedContent())).
+                registerHandler("/post1", new BasicValidationHandler("POST", null, "rocks
camel?", getExpectedContent())).
                 registerHandler("/put", new BasicValidationHandler("PUT", null, null, getExpectedContent())).
                 registerHandler("/trace", new BasicValidationHandler("TRACE", null, null,
getExpectedContent())).
                 registerHandler("/options", new BasicValidationHandler("OPTIONS", null, null,
getExpectedContent())).
                 registerHandler("/delete", new BasicValidationHandler("DELETE", null, null,
getExpectedContent())).
+                registerHandler("/delete1", new BasicValidationHandler("DELETE", null, null,
getExpectedContent())).
                 registerHandler("/head", new BasicValidationHandler("HEAD", null, null, getExpectedContent())).create();
         localServer.start();
 
@@ -207,6 +208,21 @@ public class HttpMethodsTest extends BaseHttpTest {
     }
 
     @Test
+    public void httpDeleteWithBody() throws Exception {
+
+        Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName()
+ ":" + localServer.getLocalPort() + "/delete1?deleteWithBody=true", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(Exchange.HTTP_METHOD, "DELETE");
+                exchange.getIn().setBody("rocks camel?");
+            }
+        });
+
+        assertExchange(exchange);
+
+        // the http4 server will not provide body on HTTP DELETE so we cannot test the server
side
+    }
+
+    @Test
     public void httpHead() throws Exception {
 
         Exchange exchange = template.request("http4://" + localServer.getInetAddress().getHostName()
+ ":" + localServer.getLocalPort() + "/head", new Processor() {
@@ -222,4 +238,5 @@ public class HttpMethodsTest extends BaseHttpTest {
         assertHeaders(out.getHeaders());
         assertNull(out.getBody(String.class));
     }
+
 }
\ No newline at end of file


Mime
View raw message