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 2014/04/07 11:15:06 UTC

[2/3] git commit: CAMEL-7347: camel-netty-http should return 404 instead 503 if resource not found.

CAMEL-7347: camel-netty-http should return 404 instead 503 if resource not found.


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

Branch: refs/heads/camel-2.13.x
Commit: 38391554e80bf2582e9804f89d3fccccca6f1cc0
Parents: e177e41
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Apr 7 11:18:06 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Apr 7 11:18:23 2014 +0200

----------------------------------------------------------------------
 .../http/handlers/HttpServerMultiplexChannelHandler.java |  6 +++---
 .../http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java     | 11 ++++++++++-
 .../netty/http/NettyHttpTwoRoutesStopOneRouteTest.java   |  4 ++--
 3 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/38391554/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
index 3351fd8..e00abd4 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -38,7 +38,7 @@ import org.jboss.netty.handler.codec.http.HttpResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.jboss.netty.handler.codec.http.HttpResponseStatus.SERVICE_UNAVAILABLE;
+import static org.jboss.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND;
 import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
 
 /**
@@ -102,8 +102,8 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
             ctx.setAttachment(handler);
             handler.messageReceived(ctx, messageEvent);
         } else {
-            // this service is not available, so send empty response back
-            HttpResponse response = new DefaultHttpResponse(HTTP_1_1, SERVICE_UNAVAILABLE);
+            // this resource is not found, so send empty response back
+            HttpResponse response = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
             response.setHeader(Exchange.CONTENT_TYPE, "text/plain");
             response.setHeader(Exchange.CONTENT_LENGTH, 0);
             response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));

http://git-wip-us.apache.org/repos/asf/camel/blob/38391554/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
index 382e2c9..370753f 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesMatchOnUriPrefixTest.java
@@ -36,7 +36,16 @@ public class NettyHttpTwoRoutesMatchOnUriPrefixTest extends BaseNettyTest {
             fail("Should have thrown exception");
         } catch (CamelExecutionException e) {
             NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
-            assertEquals(503, cause.getStatusCode());
+            assertEquals(404, cause.getStatusCode());
+        }
+
+        // .. and likewise baz is not a context-path we have mapped as input
+        try {
+            template.requestBody("netty-http:http://localhost:{{port}}/baz", "Hello World", String.class);
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+            assertEquals(404, cause.getStatusCode());
         }
 
         out = template.requestBody("netty-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/38391554/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesStopOneRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesStopOneRouteTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesStopOneRouteTest.java
index 7563511..9e9dc53 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesStopOneRouteTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesStopOneRouteTest.java
@@ -43,13 +43,13 @@ public class NettyHttpTwoRoutesStopOneRouteTest extends BaseNettyTest {
         getMockEndpoint("mock:foo").expectedMessageCount(0);
         getMockEndpoint("mock:bar").expectedBodiesReceived("Hello Camel");
 
-        // the foo route is stopped so this service is not available
+        // the foo route is stopped so this service is no longer there
         try {
             template.requestBody("netty-http:http://localhost:{{port}}/foo", "Hello World", String.class);
             fail("Should have thrown exception");
         } catch (CamelExecutionException e) {
             NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
-            assertEquals(503, cause.getStatusCode());
+            assertEquals(404, cause.getStatusCode());
         }
 
         out = template.requestBody("netty-http:http://localhost:{{port}}/bar", "Hello Camel", String.class);