camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hekon...@apache.org
Subject git commit: Fixed: [CAMEL-7423] Netty HTTP producer ignores requestTimeout option.
Date Thu, 08 May 2014 07:20:02 GMT
Repository: camel
Updated Branches:
  refs/heads/master c43f8e400 -> 5c8b2e953


Fixed: [CAMEL-7423] Netty HTTP producer ignores requestTimeout option.


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

Branch: refs/heads/master
Commit: 5c8b2e953a7e7b23f849849a14ff8a018faa586c
Parents: c43f8e4
Author: Henryk Konsek <hekonsek@gmail.com>
Authored: Thu May 8 09:19:38 2014 +0200
Committer: Henryk Konsek <hekonsek@gmail.com>
Committed: Thu May 8 09:19:38 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/5c8b2e95/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/5c8b2e95/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");
+
+            }
+        };
+    }
+}


Mime
View raw message