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:38 UTC

[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

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;