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 2009/10/20 13:06:54 UTC
svn commit: r827033 - in /camel/trunk/components:
camel-http/src/main/java/org/apache/camel/component/http/
camel-jetty/src/test/java/org/apache/camel/component/jetty/
Author: davsclaus
Date: Tue Oct 20 11:06:54 2009
New Revision: 827033
URL: http://svn.apache.org/viewvc?rev=827033&view=rev
Log:
CAMEL-2084: Fixed HttpPollingConsumer not supporting timeout value.
Added:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java (with props)
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=827033&r1=827032&r2=827033&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java Tue Oct 20 11:06:54 2009
@@ -180,8 +180,16 @@
// copy directly from input stream to output stream
IOHelper.copy(is, os);
} finally {
- os.close();
- is.close();
+ try {
+ os.close();
+ } catch (Exception e) {
+ // ignore, maybe client have disconnected or timed out
+ }
+ try {
+ is.close();
+ } catch (Exception e) {
+ // ignore, maybe client have disconnected or timed out
+ }
}
} else {
// not convertable as a stream so try as a String
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java?rev=827033&r1=827032&r2=827033&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpPollingConsumer.java Tue Oct 20 11:06:54 2009
@@ -48,17 +48,26 @@
}
public Exchange receive() {
- return receiveNoWait();
+ return doReceive(-1);
}
public Exchange receive(long timeout) {
- return receiveNoWait();
+ return doReceive((int) timeout);
}
public Exchange receiveNoWait() {
+ return doReceive(-1);
+ }
+
+ protected Exchange doReceive(int timeout) {
Exchange exchange = endpoint.createExchange();
HttpMethod method = createMethod();
+ // set optional timeout in millis
+ if (timeout > 0) {
+ method.getParams().setSoTimeout(timeout);
+ }
+
try {
int responseCode = httpClient.executeMethod(method);
// lets store the result in the output message.
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java?rev=827033&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java Tue Oct 20 11:06:54 2009
@@ -0,0 +1,64 @@
+/**
+ * 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 java.net.SocketTimeoutException;
+
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpPollingConsumerTest extends CamelTestSupport {
+
+ @Test
+ public void testReceive() throws Exception {
+ String body = consumer.receiveBody("http://localhost:9080/test", String.class);
+ assertEquals("Bye World", body);
+ }
+
+ @Test
+ public void testReceiveTimeout() throws Exception {
+ String body = consumer.receiveBody("http://localhost:9080/test", 5000, String.class);
+ assertEquals("Bye World", body);
+ }
+
+ @Test
+ public void testReceiveTimeoutTriggered() throws Exception {
+ try {
+ consumer.receiveBody("http://localhost:9080/test", 250, String.class);
+ fail("Should have thrown an exception");
+ } catch (RuntimeCamelException e) {
+ assertIsInstanceOf(SocketTimeoutException.class, e.getCause());
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("jetty://http://localhost:9080/test")
+ .delay(2000).transform(constant("Bye World"));
+ }
+ };
+ }
+
+}
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date