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 2010/03/04 09:22:43 UTC

svn commit: r918888 - /camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java

Author: davsclaus
Date: Thu Mar  4 08:22:43 2010
New Revision: 918888

URL: http://svn.apache.org/viewvc?rev=918888&view=rev
Log:
CAMEL-2519: Added unit test that demonstrates the issue with http status code

Added:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java
      - copied, changed from r918881, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyOnExceptionHandledTest.java

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java (from r918881, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyOnExceptionHandledTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyOnExceptionHandledTest.java&r1=918881&r2=918888&rev=918888&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyOnExceptionHandledTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java Thu Mar  4 08:22:43 2010
@@ -17,21 +17,33 @@
 package org.apache.camel.component.jetty;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
  * @version $Revision$
  */
-public class JettyOnExceptionHandledTest extends CamelTestSupport {
+public class JettyCallHttpThenExceptionTest extends CamelTestSupport {
 
     @Test
-    public void testJettyOnException() throws Exception {
-        Exchange reply = template.request("http://localhost:8234/myserver?throwExceptionOnFailure=false", null);
+    @Ignore
+    public void testJettyCallHttpThenException() throws Exception {
+        getMockEndpoint("mock:foo").expectedBodiesReceived("World");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
+
+        Exchange reply = template.request("http://localhost:8234/myserver?throwExceptionOnFailure=false", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("World");
+            }
+        });
+
+        assertMockEndpointsSatisfied();
 
         assertNotNull(reply);
-        assertEquals("Dude something went wrong", reply.getOut().getBody(String.class));
+        assertTrue(reply.getOut().getBody(String.class).startsWith("java.lang.IllegalArgumentException: I cannot do this"));
         assertEquals(500, reply.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
     }
 
@@ -40,21 +52,36 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                // START SNIPPET: e1
                 from("jetty://http://localhost:8234/myserver")
-                    // use onException to catch all exceptions and return a custom reply message
-                    .onException(Exception.class)
-                        .handled(true)
-                        // create a custom failure response
-                        .transform(constant("Dude something went wrong"))
-                        // we must remember to set error code 500 as handled(true)
-                        // otherwise would let Camel thing its a OK response (200)
-                        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500))
-                    .end()
+                    .to("log:A")
+                    .convertBodyTo(String.class)
+                    .removeHeader(Exchange.HTTP_PATH)
+                    .removeHeader(Exchange.HTTP_BASE_URI)
+                    .removeHeader(Exchange.HTTP_RESPONSE_CODE)
+                    .removeHeader(Exchange.HTTP_CHARACTER_ENCODING)
+                    .removeHeader(Exchange.HTTP_CHUNKED)
+                    .removeHeader(Exchange.HTTP_METHOD)
+                    .removeHeader(Exchange.HTTP_QUERY)
+                    .removeHeader(Exchange.HTTP_RESPONSE_CODE)
+                    .removeHeader(Exchange.HTTP_SERVLET_REQUEST)
+                    .removeHeader(Exchange.HTTP_SERVLET_RESPONSE)
+                    .removeHeader(Exchange.HTTP_URI)
+                    .removeHeader(Exchange.HTTP_URL)
+                    .removeHeader("Content-Length")
+                    .to("http://localhost:8234/other")
+                    .convertBodyTo(String.class)
+                    .to("log:B")
+                    .to("mock:bar")
                     // now just force an exception immediately
                     .throwException(new IllegalArgumentException("I cannot do this"));
-                // END SNIPPET: e1
+
+                from("jetty://http://localhost:8234/other")
+                    .convertBodyTo(String.class)
+                    .to("log:C")
+                    .to("mock:foo")
+                    .transform().simple("Bye ${body}");
             }
         };
     }
-}
+    
+}
\ No newline at end of file