Repository: camel
Updated Branches:
  refs/heads/camel-2.13.x 70826d8b4 -> 3827064b3


Fixed: [CAMEL-7423] Netty HTTP producer ignores requestTimeout option.
(cherry picked from commit 5c8b2e9)


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

Branch: refs/heads/camel-2.13.x
Commit: 3827064b39137aa8134cc8359bc849c27477c7b7
Parents: 70826d8
Author: Henryk Konsek <hekon...@gmail.com>
Authored: Thu May 8 09:19:38 2014 +0200
Committer: Henryk Konsek <hekon...@gmail.com>
Committed: Thu May 8 12:25:09 2014 +0200

----------------------------------------------------------------------
 .../netty/http/HttpClientPipelineFactory.java   | 13 +++++
 .../netty/http/NettyHttpRequestTimeoutTest.java | 60 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3827064b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
index fd20f89..b5d2d4d 100644
--- 
a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
+++ 
b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientPipelineFactory.java
@@ -16,19 +16,24 @@
  */
 package org.apache.camel.component.netty.http;
 
+import java.util.concurrent.TimeUnit;
+
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
 
 import org.apache.camel.component.netty.ClientPipelineFactory;
+import org.apache.camel.component.netty.NettyComponent;
 import org.apache.camel.component.netty.NettyConfiguration;
 import org.apache.camel.component.netty.NettyProducer;
 import org.apache.camel.component.netty.http.handlers.HttpClientChannelHandler;
 import org.apache.camel.component.netty.ssl.SSLEngineFactory;
 import org.apache.camel.util.ObjectHelper;
+import org.jboss.netty.channel.ChannelHandler;
 import org.jboss.netty.channel.ChannelPipeline;
 import org.jboss.netty.channel.Channels;
 import org.jboss.netty.handler.codec.http.HttpClientCodec;
 import org.jboss.netty.handler.ssl.SslHandler;
+import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -77,6 +82,14 @@ public class HttpClientPipelineFactory extends 
ClientPipelineFactory {
 
         pipeline.addLast("http", new HttpClientCodec());
 
+        if (producer.getConfiguration().getRequestTimeout() > 0) {
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Using request timeout {} millis", 
producer.getConfiguration().getRequestTimeout());
+            }
+            ChannelHandler timeout = new 
ReadTimeoutHandler(NettyComponent.getTimer(), 
producer.getConfiguration().getRequestTimeout(), TimeUnit.MILLISECONDS);
+            pipeline.addLast("timeout", timeout);
+        }
+
         // handler to route Camel messages
         pipeline.addLast("handler", new HttpClientChannelHandler(producer));
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3827064b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRequestTimeoutTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRequestTimeoutTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRequestTimeoutTest.java
new file mode 100644
index 0000000..cae94a3
--- /dev/null
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRequestTimeoutTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.netty.http;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.jboss.netty.handler.timeout.ReadTimeoutException;
+import org.junit.Test;
+
+public class NettyHttpRequestTimeoutTest extends BaseNettyTest {
+
+    @Test
+    public void testRequestTimeout() throws Exception {
+        try {
+            
template.requestBody("netty-http:http://localhost:{{port}}/timeout?requestTimeout=1000";,
 "Hello Camel", String.class);
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            ReadTimeoutException cause = 
assertIsInstanceOf(ReadTimeoutException.class, e.getCause());
+            assertNotNull(cause);
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("netty-http:http://localhost:{{port}}/timeout";)
+                    .process(new Processor() {
+                        @Override
+                        public void process(Exchange exchange) throws 
Exception {
+                            String body = 
exchange.getIn().getBody(String.class);
+
+                            if (body.contains("Camel")) {
+                                Thread.sleep(3000);
+                            }
+                        }
+                    })
+                    .transform().constant("Bye World");
+
+            }
+        };
+    }
+}

Reply via email to