You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ge...@apache.org on 2009/01/19 23:16:31 UTC
svn commit: r735847 - in /camel/trunk/components/camel-jetty/src:
main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java
Author: gertv
Date: Mon Jan 19 14:16:30 2009
New Revision: 735847
URL: http://svn.apache.org/viewvc?rev=735847&view=rev
Log:
CAMEL-1274: Jetty HTTP SelectChannelConnector not closed when CamelContext shuts down
Added:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java
Modified:
camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
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=735847&r1=735846&r2=735847&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 Mon Jan 19 14:16:30 2009
@@ -106,7 +106,7 @@
public void connect(HttpConsumer consumer) throws Exception {
// Make sure that there is a connector for the requested endpoint.
JettyHttpEndpoint endpoint = (JettyHttpEndpoint)consumer.getEndpoint();
- String connectorKey = endpoint.getProtocol() + ":" + endpoint.getHttpUri().getHost() + ":" + endpoint.getPort();
+ String connectorKey = getConnectorKey(endpoint);
synchronized (connectors) {
ConnectorRef connectorRef = connectors.get(connectorKey);
@@ -163,8 +163,8 @@
public void disconnect(HttpConsumer consumer) throws Exception {
// If the connector is not needed anymore then stop it
HttpEndpoint endpoint = consumer.getEndpoint();
- String connectorKey = endpoint.getProtocol() + ":" + endpoint.getPort();
-
+ String connectorKey = getConnectorKey(endpoint);
+
synchronized (connectors) {
ConnectorRef connectorRef = connectors.get(connectorKey);
if (connectorRef != null) {
@@ -177,6 +177,10 @@
}
}
}
+
+ private String getConnectorKey(HttpEndpoint endpoint) {
+ return endpoint.getProtocol() + ":" + endpoint.getHttpUri().getHost() + ":" + endpoint.getPort();
+ }
// Properties
// -------------------------------------------------------------------------
@@ -266,7 +270,7 @@
@Override
protected void doStop() throws Exception {
for (ConnectorRef connectorRef : connectors.values()) {
- connectorRef.connector.stop();
+ connectorRef.connector.stop();
}
connectors.clear();
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java?rev=735847&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java Mon Jan 19 14:16:30 2009
@@ -0,0 +1,43 @@
+/**
+ * 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.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test to verify that the Jetty HTTP connector is correctly disconnected on shutdown
+ */
+public class JettyHttpEndpointDisconnectTest extends ContextTestSupport {
+
+ private String serverUri = "http://localhost:5432/myservice";
+
+ public void testContextShutdownRemovesHttpConnector() throws Exception {
+ context.stop();
+
+ JettyHttpComponent component = (JettyHttpComponent) context.getComponent("jetty");
+ assertEquals("Connector should have been removed", 0, component.connectors.size());
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("jetty:" + serverUri).to("mock:result");
+ }
+ };
+ }
+}