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 2017/04/09 08:14:36 UTC

[1/3] camel git commit: CAMEL-11111: updated doc

Repository: camel
Updated Branches:
  refs/heads/master 693aa8a79 -> cf6a7414b


CAMEL-11111: updated doc


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

Branch: refs/heads/master
Commit: d5a3ac617b7a6644b49756cb2a9b0f2c43f2c31c
Parents: d490978
Author: Scott Cranton <sc...@cranton.com>
Authored: Sat Apr 8 18:46:17 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Apr 9 10:03:28 2017 +0200

----------------------------------------------------------------------
 components/camel-undertow/src/main/docs/undertow-component.adoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d5a3ac61/components/camel-undertow/src/main/docs/undertow-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/docs/undertow-component.adoc b/components/camel-undertow/src/main/docs/undertow-component.adoc
index 68fdea4..0ce11fc 100644
--- a/components/camel-undertow/src/main/docs/undertow-component.adoc
+++ b/components/camel-undertow/src/main/docs/undertow-component.adoc
@@ -89,7 +89,7 @@ with the following path and query parameters:
 | **options** (producer) | Sets additional channel options. The options that can be used are defined in org.xnio.Options. To configure from endpoint uri then prefix each option with option. such as option.close-abort=true&option.send-buffer=8192 |  | Map
 | **reuseAddresses** (producer) | Setting to facilitate socket multiplexing | true | Boolean
 | **tcpNoDelay** (producer) | Setting to improve TCP protocol performance | true | Boolean
-| **throwExceptionOnFailure** (producer) | 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 producer send all the fault response back. | true | Boolean
+| **throwExceptionOnFailure** (producer) | 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. | true | Boolean
 | **transferException** (producer) | 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. | false | Boolean
 | **headerFilterStrategy** (advanced) | To use a custom HeaderFilterStrategy to filter header to and from Camel message. |  | HeaderFilterStrategy
 | **synchronous** (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean


[3/3] camel git commit: CAMEL-11111: Fixes so the logic that sets the caused exception sets the result et all prior to hasFailedWith being called

Posted by da...@apache.org.
CAMEL-11111: Fixes so the logic that sets the caused exception sets the result et all prior to hasFailedWith being called


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

Branch: refs/heads/master
Commit: cf6a7414ba685785ecab767c770573847d6c5413
Parents: d5a3ac6
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Apr 9 10:13:06 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Apr 9 10:13:06 2017 +0200

----------------------------------------------------------------------
 .../undertow/UndertowClientCallback.java        | 32 ++++++++++----------
 .../component/undertow/UndertowEndpoint.java    |  4 +--
 2 files changed, 18 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cf6a7414/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java
index 9a1746d..6b48203 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java
@@ -56,7 +56,7 @@ import org.xnio.channels.StreamSinkChannel;
  * connection is ready or when the client failed to connect. It will also handle
  * writing the request and reading the response in
  * {@link #writeRequest(ClientExchange, ByteBuffer)} and
- * {@link #setupResponseListner(ClientExchange)}. The main entry point is
+ * {@link #setupResponseListener(ClientExchange)}. The main entry point is
  * {@link #completed(ClientConnection)} or {@link #failed(IOException)} in case
  * of errors, every error condition that should terminate Camel {@link Exchange}
  * should go to {@link #hasFailedWith(Exception)} and successful execution of
@@ -177,7 +177,7 @@ class UndertowClientCallback implements ClientCallback<ClientConnection> {
         callback.done(false);
     }
 
-    void hasFailedWith(final Exception e) {
+    void hasFailedWith(final Throwable e) {
         LOG.trace("Exchange has failed with", e);
         if (Boolean.TRUE.equals(throwExceptionOnFailure)) {
             exchange.setException(e);
@@ -193,13 +193,13 @@ class UndertowClientCallback implements ClientCallback<ClientConnection> {
     void performClientExchange(final ClientExchange clientExchange) {
         // add response listener to the exchange, we could receive the response
         // at any time (async)
-        setupResponseListner(clientExchange);
+        setupResponseListener(clientExchange);
 
         // write the request
         writeRequest(clientExchange, body);
     }
 
-    void setupResponseListner(final ClientExchange clientExchange) {
+    void setupResponseListener(final ClientExchange clientExchange) {
         clientExchange.setResponseListener(on((ClientExchange response) -> {
             LOG.trace("completed: {}", clientExchange);
 
@@ -221,27 +221,27 @@ class UndertowClientCallback implements ClientCallback<ClientConnection> {
                     HeaderMap headerMap = clientExchange.getResponse().getResponseHeaders();
                     Map<String, String> headers = new HashMap<>();
                     for (HttpString headerName : headerMap.getHeaderNames()) {
-                        headers.put(headerName.toString(), headerMap.get(headerName).toString());
+                        Object value = headerMap.get(headerName);
+                        if (value != null) {
+                            headers.put(headerName.toString(), value.toString());
+                        }
                     }
                     final Exception cause = new HttpOperationFailedException(uri, code, statusText, null, headers, result.getBody(String.class));
 
-                    hasFailedWith(cause);
-
-                    if (result != null) {
-                        if (ExchangeHelper.isOutCapable(exchange)) {
-                            exchange.setOut(result);
-                        } else {
-                            exchange.setIn(result);
-                        }
+                    if (ExchangeHelper.isOutCapable(exchange)) {
+                        exchange.setOut(result);
+                    } else {
+                        exchange.setIn(result);
                     }
 
-                    // true failure exception may get overwritten with connection close failure, so re-set cause
-                    exchange.setException(cause);
+                    // make sure to fail with HttpOperationFailedException
+                    hasFailedWith(cause);
+
                 } else {
                     // we end Camel exchange here
                     finish(result);
                 }
-            } catch (final Exception e) {
+            } catch (Throwable e) {
                 hasFailedWith(e);
             }
         }));

http://git-wip-us.apache.org/repos/asf/camel/blob/cf6a7414/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java
index dcd08ce..6e59caf 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowEndpoint.java
@@ -200,8 +200,8 @@ public class UndertowEndpoint extends DefaultEndpoint implements AsyncEndpoint,
     }
 
     /**
-     * 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 producer send all the fault response back.
+     * 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;


[2/3] camel git commit: CAMEL-11111: implemented throwExceptionOnFailure attribute for Producer usage

Posted by da...@apache.org.
CAMEL-11111: implemented throwExceptionOnFailure attribute for Producer usage


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

Branch: refs/heads/master
Commit: d490978eba141213c5b43cbbef13406c917132cc
Parents: 693aa8a
Author: Scott Cranton <sc...@cranton.com>
Authored: Sat Apr 8 18:42:46 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Apr 9 10:03:28 2017 +0200

----------------------------------------------------------------------
 ...HttpProducerThrowExceptionOnFailureTest.java |  4 +--
 .../undertow/UndertowClientCallback.java        | 38 ++++++++++++++++++--
 ...rtowProducerThrowExceptionOnFailureTest.java | 14 ++++----
 3 files changed, 43 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d490978e/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerThrowExceptionOnFailureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerThrowExceptionOnFailureTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerThrowExceptionOnFailureTest.java
index d5b7a60..429946d 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerThrowExceptionOnFailureTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerThrowExceptionOnFailureTest.java
@@ -39,8 +39,8 @@ public class NettyHttpProducerThrowExceptionOnFailureTest extends BaseNettyTest
             String out = template().requestBody("netty4-http:http://localhost:{{port}}/fail?throwExceptionOnFailure=true", null, String.class);
             fail("Should throw an exception");
         } catch (Throwable t) {
-            //t.printStackTrace();
-            assertNotNull(t);
+            NettyHttpOperationFailedException cause = (NettyHttpOperationFailedException) t.getCause();
+            assertEquals(404, cause.getStatusCode());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d490978e/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java
index d9c6485..9a1746d 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowClientCallback.java
@@ -40,6 +40,8 @@ import io.undertow.util.HttpString;
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.http.common.HttpHelper;
+import org.apache.camel.http.common.HttpOperationFailedException;
 import org.apache.camel.util.ExchangeHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -198,7 +200,7 @@ class UndertowClientCallback implements ClientCallback<ClientConnection> {
     }
 
     void setupResponseListner(final ClientExchange clientExchange) {
-        clientExchange.setResponseListener(on(response -> {
+        clientExchange.setResponseListener(on((ClientExchange response) -> {
             LOG.trace("completed: {}", clientExchange);
 
             try {
@@ -207,8 +209,38 @@ class UndertowClientCallback implements ClientCallback<ClientConnection> {
                 final UndertowHttpBinding binding = endpoint.getUndertowHttpBinding();
                 final Message result = binding.toCamelMessage(clientExchange, exchange);
 
-                // we end Camel exchange here
-                finish(result);
+                // if there was a http error code then check if we should throw an exception
+                final int code = clientExchange.getResponse().getResponseCode();
+                LOG.debug("Http responseCode: {}", code);
+
+                final boolean ok = HttpHelper.isStatusCodeOk(code, "200-299");
+                if (!ok && throwExceptionOnFailure) {
+                    // operation failed so populate exception to throw
+                    final String uri = endpoint.getHttpURI().toString();
+                    final String statusText = clientExchange.getResponse().getStatus();
+                    HeaderMap headerMap = clientExchange.getResponse().getResponseHeaders();
+                    Map<String, String> headers = new HashMap<>();
+                    for (HttpString headerName : headerMap.getHeaderNames()) {
+                        headers.put(headerName.toString(), headerMap.get(headerName).toString());
+                    }
+                    final Exception cause = new HttpOperationFailedException(uri, code, statusText, null, headers, result.getBody(String.class));
+
+                    hasFailedWith(cause);
+
+                    if (result != null) {
+                        if (ExchangeHelper.isOutCapable(exchange)) {
+                            exchange.setOut(result);
+                        } else {
+                            exchange.setIn(result);
+                        }
+                    }
+
+                    // true failure exception may get overwritten with connection close failure, so re-set cause
+                    exchange.setException(cause);
+                } else {
+                    // we end Camel exchange here
+                    finish(result);
+                }
             } catch (final Exception e) {
                 hasFailedWith(e);
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/d490978e/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerThrowExceptionOnFailureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerThrowExceptionOnFailureTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerThrowExceptionOnFailureTest.java
index f0d2472..b281699 100644
--- a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerThrowExceptionOnFailureTest.java
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowProducerThrowExceptionOnFailureTest.java
@@ -16,14 +16,12 @@
  */
 package org.apache.camel.component.undertow;
 
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.junit.Ignore;
+import org.apache.camel.http.common.HttpOperationFailedException;
 import org.junit.Test;
 
-import java.util.concurrent.TimeUnit;
-
-@Ignore("CAMEL-11111")
 public class UndertowProducerThrowExceptionOnFailureTest extends BaseUndertowTest {
 
     @Test
@@ -41,11 +39,11 @@ public class UndertowProducerThrowExceptionOnFailureTest extends BaseUndertowTes
     public void testFailWithException() throws Exception {
         try {
             String out = template().requestBody("undertow:http://localhost:{{port}}/fail?throwExceptionOnFailure=true", null, String.class);
-        } catch (Throwable t) {
-            //t.printStackTrace();
-            assertNotNull(t);
+            fail("Should throw an exception");
+        } catch (CamelExecutionException e) {
+            HttpOperationFailedException cause = (HttpOperationFailedException) e.getCause();
+            assertEquals(404, cause.getStatusCode());
         }
-        fail("Should throw an exception");
     }
 
     @Override