Author: davsclaus
Date: Tue Jan 11 12:25:26 2011
New Revision: 1057603

URL: http://svn.apache.org/viewvc?rev=1057603&view=rev
Log:
CAMEL-3527: Added option to disable using Jetty continuation.

Added:
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContinuationDisabledTest.java
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEndpointContinuationDisabledTest.java
    
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java
      - copied, changed from r1057518, 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
Modified:
    
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
    
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
    
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
    
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
    camel/trunk/components/camel-jetty/src/test/resources/log4j.properties

Modified: 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java?rev=1057603&r1=1057602&r2=1057603&view=diff
==============================================================================
--- 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
 (original)
+++ 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
 Tue Jan 11 12:25:26 2011
@@ -43,39 +43,55 @@ public class CamelServlet extends HttpSe
    
     @Override
     protected void service(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
-        try {
+        if (log.isTraceEnabled()) {
+            log.trace("Service: " + request);
+        }
 
-            // Is there a consumer registered for the request.
-            HttpConsumer consumer = resolve(request);
-            if (consumer == null) {
-                response.sendError(HttpServletResponse.SC_NOT_FOUND);
-                return;
-            }
+        // Is there a consumer registered for the request.
+        HttpConsumer consumer = resolve(request);
+        if (consumer == null) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
 
-            // are we suspended?
-            if (consumer.isSuspended()) {
-                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
-                return;
-            }
+        // are we suspended?
+        if (consumer.isSuspended()) {
+            response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+            return;
+        }
 
-            // create exchange and set data on it
-            Exchange exchange = new DefaultExchange(consumer.getEndpoint(), 
ExchangePattern.InOut);
-            if (consumer.getEndpoint().isBridgeEndpoint()) {
-                exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, 
Boolean.TRUE);
-            }
-            if (consumer.getEndpoint().isDisableStreamCache()) {
-                exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, 
Boolean.TRUE);
-            }
-            
-            HttpHelper.setCharsetFromContentType(request.getContentType(), 
exchange);
-            exchange.setIn(new HttpMessage(exchange, request, response));
+        // create exchange and set data on it
+        Exchange exchange = new DefaultExchange(consumer.getEndpoint(), 
ExchangePattern.InOut);
+        if (consumer.getEndpoint().isBridgeEndpoint()) {
+            exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
+        }
+        if (consumer.getEndpoint().isDisableStreamCache()) {
+            exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, 
Boolean.TRUE);
+        }
 
-            // Have the camel process the HTTP exchange.
+        HttpHelper.setCharsetFromContentType(request.getContentType(), 
exchange);
+        exchange.setIn(new HttpMessage(exchange, request, response));
+
+        try {
+            if (log.isTraceEnabled()) {
+                log.trace("Processing request for exchangeId: " + 
exchange.getExchangeId());
+            }
+            // process the exchange
             consumer.getProcessor().process(exchange);
+        } catch (Exception e) {
+            exchange.setException(e);
+        }
+
+        try {
+            if (log.isTraceEnabled()) {
+                log.trace("Writing response for exchangeId: " + 
exchange.getExchangeId());
+            }
 
             // now lets output to the response
             consumer.getBinding().writeResponse(exchange, response);
-
+        } catch (IOException e) {
+            log.error("Error processing request", e);
+            throw e;
         } catch (Exception e) {
             log.error("Error processing request", e);
             throw new ServletException(e);

Modified: 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java?rev=1057603&r1=1057602&r2=1057603&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
 (original)
+++ 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/CamelContinuationServlet.java
 Tue Jan 11 12:25:26 2011
@@ -96,6 +96,9 @@ public class CamelContinuationServlet ex
             // must suspend before we process the exchange
             continuation.suspend();
 
+            if (log.isTraceEnabled()) {
+                log.trace("Processing request for exchangeId: " + 
exchange.getExchangeId());
+            }
             // use the asynchronous API to process the exchange
             consumer.getAsyncProcessor().process(exchange, new AsyncCallback() 
{
                 public void done(boolean doneSync) {
@@ -122,6 +125,9 @@ public class CamelContinuationServlet ex
         } catch (IOException e) {
             log.error("Error processing request", e);
             throw e;
+        } catch (Exception e) {
+            log.error("Error processing request", e);
+            throw new ServletException(e);
         }
     }
 

Modified: 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=1057603&r1=1057602&r2=1057603&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
 (original)
+++ 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
 Tue Jan 11 12:25:26 2011
@@ -95,6 +95,7 @@ public class JettyHttpComponent extends 
     protected boolean enableJmx;
     protected JettyHttpBinding jettyHttpBinding;
     protected Long continuationTimeout;
+    protected boolean useContinuation = true;
 
     class ConnectorRef {
         Server server;
@@ -140,6 +141,7 @@ public class JettyHttpComponent extends 
                                                               Boolean.class, 
true);
         Filter multipartFilter = 
resolveAndRemoveReferenceParameter(parameters, "multipartFilterRef", 
Filter.class);
         Long continuationTimeout = getAndRemoveParameter(parameters, 
"continuationTimeout", Long.class);
+        Boolean useContinuation = getAndRemoveParameter(parameters, 
"useContinuation", Boolean.class);
 
         // configure http client if we have url configuration for it
         // http client is only used for jetty http producer (hence not very 
commonly used)
@@ -219,6 +221,9 @@ public class JettyHttpComponent extends 
         if (continuationTimeout != null) {
             endpoint.setContinuationTimeout(continuationTimeout);
         }
+        if (useContinuation != null) {
+            endpoint.setUseContinuation(useContinuation);
+        }
 
         setProperties(endpoint, parameters);
         return endpoint;
@@ -653,6 +658,14 @@ public class JettyHttpComponent extends 
         this.continuationTimeout = continuationTimeout;
     }
 
+    public boolean isUseContinuation() {
+        return useContinuation;
+    }
+
+    public void setUseContinuation(boolean useContinuation) {
+        this.useContinuation = useContinuation;
+    }
+
     // Implementation methods
     // 
-------------------------------------------------------------------------
     protected CamelServlet createServletForConnector(Server server, Connector 
connector,
@@ -674,15 +687,26 @@ public class JettyHttpComponent extends 
             }
         }
 
-        // use Jetty continuations
-        CamelContinuationServlet camelServlet = new CamelContinuationServlet();
-        // configure timeout and log it so end user know what we are using
-        Long timeout = endpoint.getContinuationTimeout() != null ? 
endpoint.getContinuationTimeout() : getContinuationTimeout();
-        if (timeout != null) {
-            LOG.info("Using Jetty continuation timeout: " + timeout + " millis 
for: " + endpoint);
-            camelServlet.setContinuationTimeout(timeout);
+        CamelServlet camelServlet;
+        boolean jetty = endpoint.getUseContinuation() != null ? 
endpoint.getUseContinuation() : isUseContinuation();
+        if (jetty) {
+            // use Jetty continuations
+            CamelContinuationServlet jettyServlet = new 
CamelContinuationServlet();
+            // configure timeout and log it so end user know what we are using
+            Long timeout = endpoint.getContinuationTimeout() != null ? 
endpoint.getContinuationTimeout() : getContinuationTimeout();
+            if (timeout != null) {
+                LOG.info("Using Jetty continuation timeout: " + timeout + " 
millis for: " + endpoint);
+                jettyServlet.setContinuationTimeout(timeout);
+            } else {
+                LOG.info("Using default Jetty continuation timeout for: " + 
endpoint);
+            }
+
+            // use the jetty servlet
+            camelServlet = jettyServlet;
         } else {
-            LOG.info("Using default Jetty continuation timeout for: " + 
endpoint);
+            // do not use jetty so use a plain servlet
+            camelServlet = new CamelServlet();
+            LOG.info("Jetty continuation is disabled for: " + endpoint);
         }
 
         ServletHolder holder = new ServletHolder();

Modified: 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java?rev=1057603&r1=1057602&r2=1057603&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
 (original)
+++ 
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
 Tue Jan 11 12:25:26 2011
@@ -44,6 +44,7 @@ public class JettyHttpEndpoint extends H
     private boolean enableMultipartFilter;
     private Filter multipartFilter;
     private Long continuationTimeout;
+    private Boolean useContinuation;
 
     public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI 
httpURL) throws URISyntaxException {
         super(uri, component, httpURL);
@@ -142,4 +143,12 @@ public class JettyHttpEndpoint extends H
     public void setContinuationTimeout(Long continuationTimeout) {
         this.continuationTimeout = continuationTimeout;
     }
+
+    public Boolean getUseContinuation() {
+        return useContinuation;
+    }
+
+    public void setUseContinuation(Boolean useContinuation) {
+        this.useContinuation = useContinuation;
+    }
 }

Added: 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContinuationDisabledTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContinuationDisabledTest.java?rev=1057603&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContinuationDisabledTest.java
 (added)
+++ 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContinuationDisabledTest.java
 Tue Jan 11 12:25:26 2011
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 1027376 $
+ */
+public class JettyContinuationDisabledTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyContinuationDisabled() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String out = 
template.requestBody("http://localhost:{{port}}/myservice";, null, String.class);
+        assertEquals("Bye World", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // disable continuation
+                JettyHttpComponent jetty = context.getComponent("jetty", 
JettyHttpComponent.class);
+                jetty.setUseContinuation(false);
+
+                from("jetty:http://localhost:{{port}}/myservice";)
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws 
Exception {
+                            Thread.sleep(1000);
+                            exchange.getOut().setBody("Bye World");
+                        }
+                    })
+                    .to("mock:result");
+            }
+        };
+    }
+}

Added: 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEndpointContinuationDisabledTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEndpointContinuationDisabledTest.java?rev=1057603&view=auto
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEndpointContinuationDisabledTest.java
 (added)
+++ 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEndpointContinuationDisabledTest.java
 Tue Jan 11 12:25:26 2011
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jetty;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 1027376 $
+ */
+public class JettyEndpointContinuationDisabledTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyContinuationDisabled() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        String out = 
template.requestBody("http://localhost:{{port}}/myservice";, null, String.class);
+        assertEquals("Bye World", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
from("jetty:http://localhost:{{port}}/myservice?useContinuation=false";)
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws 
Exception {
+                            Thread.sleep(1000);
+                            exchange.getOut().setBody("Bye World");
+                        }
+                    })
+                    .to("mock:result");
+            }
+        };
+    }
+}

Copied: 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java
 (from r1057518, 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java&r1=1057518&r2=1057603&rev=1057603&view=diff
==============================================================================
--- 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationTimeoutTest.java
 (original)
+++ 
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/async/JettyAsyncContinuationDisabledTest.java
 Tue Jan 11 12:25:26 2011
@@ -16,37 +16,21 @@
  */
 package org.apache.camel.component.jetty.async;
 
-import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.http.HttpOperationFailedException;
 import org.apache.camel.component.jetty.BaseJettyTest;
-import org.apache.camel.util.StopWatch;
 import org.junit.Test;
 
 /**
  * @version $Revision: 1027376 $
  */
-public class JettyAsyncContinuationTimeoutTest extends BaseJettyTest {
+public class JettyAsyncContinuationDisabledTest extends BaseJettyTest {
 
     @Test
-    public void testJettyAsyncTimeout() throws Exception {
+    public void testJettyAsyncContinuationDisabled() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
 
-        StopWatch watch = new StopWatch();
-        try {
-            template.requestBody("http://localhost:{{port}}/myservice";, null, 
String.class);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            log.info("Timeout hit and client got reply with failure status 
code");
-
-            long taken = watch.stop();
-
-            HttpOperationFailedException cause = 
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
-            assertEquals(503, cause.getStatusCode());
-
-            // should be approx 3-4 sec.
-            assertTrue("Timeout should occur faster than " + taken, taken < 
4500);
-        }
+        String out = 
template.requestBody("http://localhost:{{port}}/myservice";, null, String.class);
+        assertEquals("Bye World", out);
 
         assertMockEndpointsSatisfied();
     }
@@ -58,8 +42,8 @@ public class JettyAsyncContinuationTimeo
             public void configure() throws Exception {
                 context.addComponent("async", new MyAsyncComponent());
 
-                
from("jetty:http://localhost:{{port}}/myservice?continuationTimeout=3000";)
-                    .to("async:Bye World?delay=6000")
+                
from("jetty:http://localhost:{{port}}/myservice?useContinuation=false";)
+                    .to("async:Bye World")
                     .to("mock:result");
             }
         };

Modified: camel/trunk/components/camel-jetty/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/resources/log4j.properties?rev=1057603&r1=1057602&r2=1057603&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/resources/log4j.properties 
(original)
+++ camel/trunk/components/camel-jetty/src/test/resources/log4j.properties Tue 
Jan 11 12:25:26 2011
@@ -26,6 +26,7 @@ log4j.rootLogger=INFO, file
 # uncomment the following to enable camel debugging
 #log4j.logger.org.apache.camel.component.jetty=TRACE
 #log4j.logger.org.apache.camel.component.jetty.CamelContinuationServlet=TRACE
+#log4j.logger.org.apache.camel.component.http.CamelServlet=TRACE
 #log4j.logger.org.apache.camel.component.http=TRACE
 #log4j.logger.org.apache.camel=DEBUG
 #log4j.logger.org.apache.camel.impl.converter.PropertyEditorTypeConverter=TRACE


Reply via email to