Repository: cxf Updated Branches: refs/heads/master 994d43eff -> fae074f22
[CXF-5900] websocket destination in osgi fails to start after being stopped Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fae074f2 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fae074f2 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fae074f2 Branch: refs/heads/master Commit: fae074f2246897b80488406bb80d46237e95271e Parents: 994d43e Author: Akitoshi Yoshida <[email protected]> Authored: Wed Jul 23 23:48:31 2014 +0200 Committer: Akitoshi Yoshida <[email protected]> Committed: Thu Jul 24 11:37:30 2014 +0200 ---------------------------------------------------------------------- .../AtmosphereWebSocketServletDestination.java | 2 +- .../jetty/JettyWebSocketServletDestination.java | 2 +- ...mosphereWebSocketServletDestinationTest.java | 80 +++++++++++++++++ .../jetty/JettyWebSocketDestinationTest.java | 94 ++++++++++++++++++++ .../JettyWebSocketServletDestinationTest.java | 79 ++++++++++++++++ ...RSClientServerWebSocketSpringWebAppTest.java | 11 ++- 6 files changed, 265 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/fae074f2/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java index 1885924..c8e5fae 100644 --- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java +++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java @@ -52,7 +52,7 @@ public class AtmosphereWebSocketServletDestination extends ServletDestination im public AtmosphereWebSocketServletDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei, String path) throws IOException { - super(bus, registry, ei, ei.toString()); + super(bus, registry, ei, path); this.framework = new AtmosphereFramework(false, true); framework.setUseNativeImplementation(false); http://git-wip-us.apache.org/repos/asf/cxf/blob/fae074f2/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestination.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestination.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestination.java index 53bc640..296410b 100644 --- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestination.java +++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestination.java @@ -43,7 +43,7 @@ public class JettyWebSocketServletDestination extends ServletDestination impleme public JettyWebSocketServletDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei, String path) throws IOException { - super(bus, registry, ei, ei.toString()); + super(bus, registry, ei, path); webSocketManager = new JettyWebSocketManager(); webSocketManager.init(this); } http://git-wip-us.apache.org/repos/asf/cxf/blob/fae074f2/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java new file mode 100644 index 0000000..f56c51c --- /dev/null +++ b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java @@ -0,0 +1,80 @@ +/** + * 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.cxf.transport.websocket.atmosphere; + +import java.io.IOException; + +import javax.xml.namespace.QName; + +import org.apache.cxf.Bus; +import org.apache.cxf.bus.extension.ExtensionManagerBus; +import org.apache.cxf.service.model.EndpointInfo; +import org.apache.cxf.transport.http.DestinationRegistry; +import org.apache.cxf.transport.http.HTTPTransportFactory; + +import org.junit.Assert; +import org.junit.Test; + +/** + * + */ +public class AtmosphereWebSocketServletDestinationTest extends Assert { + private static final String ENDPOINT_ADDRESS = "/websocket/nada"; + private static final QName ENDPOINT_NAME = new QName("urn:websocket:probe", "nada"); + + @Test + public void testRegisteration() throws Exception { + Bus bus = new ExtensionManagerBus(); + DestinationRegistry registry = new HTTPTransportFactory().getRegistry(); + EndpointInfo endpoint = new EndpointInfo(); + endpoint.setAddress(ENDPOINT_ADDRESS); + endpoint.setName(ENDPOINT_NAME); + + TestAtmosphereWebSocketServletDestination dest = + new TestAtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS); + + dest.activate(); + + assertNotNull(registry.getDestinationForPath(ENDPOINT_ADDRESS)); + + dest.deactivate(); + + assertNull(registry.getDestinationForPath(ENDPOINT_ADDRESS)); + } + + private static class TestAtmosphereWebSocketServletDestination extends AtmosphereWebSocketServletDestination { + + + public TestAtmosphereWebSocketServletDestination(Bus bus, DestinationRegistry registry, + EndpointInfo ei, String path) throws IOException { + super(bus, registry, ei, path); + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/fae074f2/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketDestinationTest.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketDestinationTest.java b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketDestinationTest.java new file mode 100644 index 0000000..3c3efb3 --- /dev/null +++ b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketDestinationTest.java @@ -0,0 +1,94 @@ +/** + * 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.cxf.transport.websocket.jetty; + +import java.io.IOException; + +import javax.xml.namespace.QName; + +import org.apache.cxf.Bus; +import org.apache.cxf.bus.extension.ExtensionManagerBus; +import org.apache.cxf.service.model.EndpointInfo; +import org.apache.cxf.transport.http.DestinationRegistry; +import org.apache.cxf.transport.http.HTTPTransportFactory; +import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine; +import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * + */ +public class JettyWebSocketDestinationTest extends Assert { + private static final String ENDPOINT_ADDRESS = "ws://localhost:9001/websocket/nada"; + private static final QName ENDPOINT_NAME = new QName("urn:websocket:probe", "nada"); + + private IMocksControl control; + + @Before + public void setUp() { + control = EasyMock.createNiceControl(); + } + + @Test + public void testRegisteration() throws Exception { + Bus bus = new ExtensionManagerBus(); + DestinationRegistry registry = new HTTPTransportFactory().getRegistry(); + EndpointInfo endpoint = new EndpointInfo(); + endpoint.setAddress(ENDPOINT_ADDRESS); + endpoint.setName(ENDPOINT_NAME); + JettyHTTPServerEngine engine = EasyMock.createMock(JettyHTTPServerEngine.class); + + control.replay(); + + TestJettyWebSocketDestination dest = new TestJettyWebSocketDestination(bus, registry, endpoint, null, engine); + + dest.activate(); + + assertNotNull(registry.getDestinationForPath(ENDPOINT_ADDRESS)); + + dest.deactivate(); + + assertNull(registry.getDestinationForPath(ENDPOINT_ADDRESS)); + } + + private static class TestJettyWebSocketDestination extends JettyWebSocketDestination { + public TestJettyWebSocketDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei, + JettyHTTPServerEngineFactory serverEngineFactory, + JettyHTTPServerEngine engine) throws IOException { + super(bus, registry, ei, serverEngineFactory); + this.engine = engine; + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/fae074f2/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestinationTest.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestinationTest.java b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestinationTest.java new file mode 100644 index 0000000..9e88d64 --- /dev/null +++ b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocketServletDestinationTest.java @@ -0,0 +1,79 @@ +/** + * 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.cxf.transport.websocket.jetty; + +import java.io.IOException; + +import javax.xml.namespace.QName; + +import org.apache.cxf.Bus; +import org.apache.cxf.bus.extension.ExtensionManagerBus; +import org.apache.cxf.service.model.EndpointInfo; +import org.apache.cxf.transport.http.DestinationRegistry; +import org.apache.cxf.transport.http.HTTPTransportFactory; + +import org.junit.Assert; +import org.junit.Test; + +/** + * + */ +public class JettyWebSocketServletDestinationTest extends Assert { + private static final String ENDPOINT_ADDRESS = "/websocket/nada"; + private static final QName ENDPOINT_NAME = new QName("urn:websocket:probe", "nada"); + + @Test + public void testRegisteration() throws Exception { + Bus bus = new ExtensionManagerBus(); + DestinationRegistry registry = new HTTPTransportFactory().getRegistry(); + EndpointInfo endpoint = new EndpointInfo(); + endpoint.setAddress(ENDPOINT_ADDRESS); + endpoint.setName(ENDPOINT_NAME); + + TestJettyWebSocketServletDestination dest = + new TestJettyWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS); + + dest.activate(); + + assertNotNull(registry.getDestinationForPath(ENDPOINT_ADDRESS)); + + dest.deactivate(); + + assertNull(registry.getDestinationForPath(ENDPOINT_ADDRESS)); + } + + private static class TestJettyWebSocketServletDestination extends JettyWebSocketServletDestination { + + public TestJettyWebSocketServletDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei, + String path) throws IOException { + super(bus, registry, ei, path); + } + + @Override + public void activate() { + super.activate(); + } + + @Override + public void deactivate() { + super.deactivate(); + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/fae074f2/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java index cf0bbab..4b9ce4f 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java @@ -30,6 +30,7 @@ import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.webapp.WebAppContext; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -38,9 +39,11 @@ import org.junit.Test; */ public class JAXRSClientServerWebSocketSpringWebAppTest extends JAXRSClientServerWebSocketTest { private static final String PORT = BookServerWebSocket.PORT_WAR; + private static org.eclipse.jetty.server.Server server; + @BeforeClass public static void startServers() throws Exception { - org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(); + server = new org.eclipse.jetty.server.Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(Integer.parseInt(BookServerWebSocket.PORT_WAR)); @@ -64,6 +67,12 @@ public class JAXRSClientServerWebSocketSpringWebAppTest extends JAXRSClientServe } + @AfterClass + public static void stopServers() throws Exception { + server.stop(); + server.destroy(); + } + @Test public void testGetBookHTTP() throws Exception { String address = "http://localhost:" + getPort() + getContext() + "/http/web/bookstore/books/1";
