Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 833AF101D0 for ; Fri, 30 May 2014 13:15:33 +0000 (UTC) Received: (qmail 3312 invoked by uid 500); 30 May 2014 13:15:33 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 3262 invoked by uid 500); 30 May 2014 13:15:33 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 3255 invoked by uid 99); 30 May 2014 13:15:33 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 May 2014 13:15:33 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 358899F4A; Fri, 30 May 2014 13:15:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hekonsek@apache.org To: commits@camel.apache.org Message-Id: <13e78497e5e64e1fa06d67303e2f7ff5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: Fixed: [CAMEL-7423] Netty HTTP producer ignores requestTimeout option. (cherry picked from commit 5c8b2e9) Date: Fri, 30 May 2014 13:15:33 +0000 (UTC) Repository: camel Updated Branches: refs/heads/camel-2.12.x 01f591d1f -> b44e54f59 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/b44e54f5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b44e54f5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b44e54f5 Branch: refs/heads/camel-2.12.x Commit: b44e54f59abe4904647e13f8af8a5f04763cd67e Parents: 01f591d Author: Henryk Konsek Authored: Thu May 8 09:19:38 2014 +0200 Committer: Henryk Konsek Committed: Fri May 30 15:14:21 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/b44e54f5/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/b44e54f5/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"); + + } + }; + } +}