Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E2E30C7CC for ; Fri, 14 Jun 2013 12:09:22 +0000 (UTC) Received: (qmail 32576 invoked by uid 500); 14 Jun 2013 12:09:22 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 31722 invoked by uid 500); 14 Jun 2013 12:09:20 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 31714 invoked by uid 99); 14 Jun 2013 12:09:20 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jun 2013 12:09:20 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A277B816DAF; Fri, 14 Jun 2013 12:09:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Message-Id: <4930ad1c49c64b688aabe0e16f6eace4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: CAMEL-6327: More work on new camel-netty-http component. Date: Fri, 14 Jun 2013 12:09:19 +0000 (UTC) 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 Authored: Fri Jun 14 14:09:10 2013 +0200 Committer: Claus Ibsen 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();