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 2013/06/14 14:09:19 UTC

git commit: CAMEL-6327: More work on new camel-netty-http component.

Updated Branches:
  refs/heads/master cd7714207 -> d5183ff3b


CAMEL-6327: More work on new camel-netty-http component.


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

Branch: refs/heads/master
Commit: d5183ff3b5cf0be2a03de3b4e134752e07f79c75
Parents: cd77142
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jun 14 14:09:10 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jun 14 14:09:10 2013 +0200

----------------------------------------------------------------------
 .../component/netty/http/NettyHttpComponent.java |  2 +-
 .../component/netty/http/NettyHttpHelper.java    |  5 ++---
 .../component/netty/http/NettyHttpProducer.java  | 15 +++++++++------
 ...tyHttp500ErrorThrowExceptionOnServerTest.java |  1 +
 .../component/netty/http/NettyHttpSSLTest.java   | 19 +++++++++----------
 5 files changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d5183ff3/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index eb8a56d..6e5c00e 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -35,10 +35,10 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
     // - bridgeEndpoint
     // - matchOnUriPrefix
     // - urlrewrite
+    // - various CamelHttpUri headers with details about the url in use
 
     // TODO: producer
     // - add support for HTTP_URI / HTTP_QUERY overrides
-    // - add actual url to state so we know exactly which url we called also for done callback
 
     private NettyHttpBinding nettyHttpBinding;
     private HeaderFilterStrategy headerFilterStrategy;

http://git-wip-us.apache.org/repos/asf/camel/blob/d5183ff3/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
index d23a67f..4f0ce98 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
@@ -112,9 +112,8 @@ public final class NettyHttpHelper {
         }
     }
 
-    public static Exception populateNettyHttpOperationFailedException(Exchange exchange, HttpResponse response, int responseCode, boolean transferException) {
-        // TODO: we need to have the uri of the http server we called
-        String uri = "TODO";
+    public static Exception populateNettyHttpOperationFailedException(Exchange exchange, String url, HttpResponse response, int responseCode, boolean transferException) {
+        String uri = url;
         String statusText = response.getStatus().getReasonPhrase();
 
         if (responseCode >= 300 && responseCode < 400) {

http://git-wip-us.apache.org/repos/asf/camel/blob/d5183ff3/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
index 112c843..2e5772e 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
@@ -20,6 +20,7 @@ import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
 import org.apache.camel.component.netty.NettyConfiguration;
 import org.apache.camel.component.netty.NettyProducer;
+import org.jboss.netty.handler.codec.http.HttpRequest;
 import org.jboss.netty.handler.codec.http.HttpResponse;
 
 /**
@@ -57,11 +58,11 @@ public class NettyHttpProducer extends NettyProducer {
             uri += "?" + uriParameters;
         }
 
-        if (exchange.hasOut()) {
-            return getEndpoint().getNettyHttpBinding().toNettyRequest(exchange.getOut(), uri, getConfiguration());
-        } else {
-            return getEndpoint().getNettyHttpBinding().toNettyRequest(exchange.getIn(), uri, getConfiguration());
-        }
+        HttpRequest request = getEndpoint().getNettyHttpBinding().toNettyRequest(exchange.getIn(), uri, getConfiguration());
+        String actualUri = request.getUri();
+        exchange.getIn().setHeader(Exchange.HTTP_URL, actualUri);
+
+        return request;
     }
 
     /**
@@ -84,13 +85,15 @@ public class NettyHttpProducer extends NettyProducer {
                 if (nettyMessage != null) {
                     HttpResponse response = nettyMessage.getHttpResponse();
                     if (response != null) {
+                        // the actual url is stored on the IN message in the getRequestBody method as its accessed on-demand
+                        String actualUrl = exchange.getIn().getHeader(Exchange.HTTP_URL, String.class);
                         int code = response.getStatus() != null ? response.getStatus().getCode() : -1;
                         log.debug("Http responseCode: {}", code);
 
                         // if there was a http error code (300 or higher) then check if we should throw an exception
                         if (code >= 300 && getConfiguration().isThrowExceptionOnFailure()) {
                             // operation failed so populate exception to throw
-                            Exception cause = NettyHttpHelper.populateNettyHttpOperationFailedException(exchange, response, code, getConfiguration().isTransferException());
+                            Exception cause = NettyHttpHelper.populateNettyHttpOperationFailedException(exchange, actualUrl, response, code, getConfiguration().isTransferException());
                             exchange.setException(cause);
                         }
                     }

http://git-wip-us.apache.org/repos/asf/camel/blob/d5183ff3/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java
index 5b7206e..fbc2155 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java
@@ -35,6 +35,7 @@ public class NettyHttp500ErrorThrowExceptionOnServerTest extends BaseNettyTest {
             String trace = context.getTypeConverter().convertTo(String.class, cause.getResponse().getContent());
             assertNotNull(trace);
             assertTrue(trace.startsWith("java.lang.IllegalArgumentException: Camel cannot do this"));
+            assertEquals("http://localhost:" + getPort() + "/foo", cause.getUri());
         }
 
         assertMockEndpointsSatisfied();

http://git-wip-us.apache.org/repos/asf/camel/blob/d5183ff3/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java
index 28345c4..ab8d1ad 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLTest.java
@@ -18,7 +18,6 @@ package org.apache.camel.component.netty.http;
 
 import java.net.URL;
 import java.util.Properties;
-
 import javax.net.ssl.SSLSession;
 
 import org.apache.camel.Exchange;
@@ -63,7 +62,7 @@ public class NettyHttpSSLTest extends BaseNettyTest {
             if (NULL_VALUE_MARKER.equals(value)) {
                 System.getProperties().remove(key);
             } else {
-                System.setProperty((String)key, (String)value);
+                System.setProperty((String) key, (String) value);
             }
         }
     }
@@ -87,15 +86,15 @@ public class NettyHttpSSLTest extends BaseNettyTest {
                 from("netty-http:https://localhost:{{port}}?ssl=true&passphrase=changeit&keyStoreResource=jsse/localhost.ks&trustStoreResource=jsse/localhost.ks")
                         .to("mock:input")
                         .process(new Processor() {
-                        public void process(Exchange exchange) throws Exception {
-                            SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class);
-                            if (session != null) {
-                                exchange.getOut().setBody("Bye World");  
-                            } else {
-                                exchange.getOut().setBody("Cannot start conversion without SSLSession");
+                            public void process(Exchange exchange) throws Exception {
+                                SSLSession session = exchange.getIn().getHeader(NettyConstants.NETTY_SSL_SESSION, SSLSession.class);
+                                if (session != null) {
+                                    exchange.getOut().setBody("Bye World");
+                                } else {
+                                    exchange.getOut().setBody("Cannot start conversion without SSLSession");
+                                }
                             }
-                        }
-                    });
+                        });
             }
         });
         context.start();