add UndertowWebSocketDestination when Atmosphere isn't available with more tests
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ebd1c24d Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ebd1c24d Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ebd1c24d Branch: refs/heads/websocket-undertow Commit: ebd1c24df1b405bf0478f191ba055d96e8ccea41 Parents: a07135b Author: Freeman Fang <freeman.f...@gmail.com> Authored: Wed Apr 19 14:28:37 2017 +0800 Committer: Freeman Fang <freeman.f...@gmail.com> Committed: Wed Apr 19 14:28:37 2017 +0800 ---------------------------------------------------------------------- .../websocket/WebSocketDestinationFactory.java | 19 +- .../AtmosphereWebSocketUndertowDestination.java | 22 +- .../undertow/UndertowWebSocketDestination.java | 232 +++++ .../WebSocketUndertowServletRequest.java | 6 +- ...RSClientServerWebSocketNoAtmosphereTest.java | 51 + ...ntServerWebSocketSpringNoAtmosphereTest.java | 52 ++ .../JAXRSClientServerWebSocketSpringTest.java | 48 + .../resources/jaxrs_websocket/WEB-INF/beans.xml | 54 ++ .../resources/jaxrs_websocket/WEB-INF/web.xml | 41 + .../jaxrs_websocket/beans-embedded.xml | 48 + .../jaxrs_websocket/beans-embedded2.xml | 48 + .../systest/ws/rm/WSRMPolicyResolveTest.java | 52 -- .../systest/ws/policy/RM10PolicyWsdlTest.java | 148 --- .../tools/wadlto/jaxrs/JAXRSContainerTest.java | 921 ------------------- 14 files changed, 601 insertions(+), 1141 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/WebSocketDestinationFactory.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/WebSocketDestinationFactory.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/WebSocketDestinationFactory.java index bbd6f5a..40fd02e 100644 --- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/WebSocketDestinationFactory.java +++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/WebSocketDestinationFactory.java @@ -43,6 +43,8 @@ public class WebSocketDestinationFactory implements HttpDestinationFactory { private static final boolean UNDERTOW_AVAILABLE = probeClass("io.undertow.websockets.core.WebSockets"); private static final Constructor<?> JETTY9_WEBSOCKET_DESTINATION_CTR = probeConstructor("org.apache.cxf.transport.websocket.jetty9.Jetty9WebSocketDestination"); + private static final Constructor<?> UNDERTOW_WEBSOCKET_DESTINATION_CTR = + probeUndertowConstructor("org.apache.cxf.transport.websocket.undertow.UndertowWebSocketDestination"); private static final Constructor<?> ATMOSPHERE_WEBSOCKET_JETTY_DESTINATION_CTR = probeConstructor("org.apache.cxf.transport.websocket.atmosphere.AtmosphereWebSocketJettyDestination"); private static final Constructor<?> ATMOSPHERE_WEBSOCKET_UNDERTOW_DESTINATION_CTR = @@ -102,11 +104,20 @@ public class WebSocketDestinationFactory implements HttpDestinationFactory { } return null; } else { - // for the embedded mode, we stick to jetty - JettyHTTPServerEngineFactory serverEngineFactory = bus - .getExtension(JettyHTTPServerEngineFactory.class); - return createJettyHTTPDestination(JETTY9_WEBSOCKET_DESTINATION_CTR, bus, registry, + if (JETTY_AVAILABLE) { + // for the embedded mode, we stick to jetty if jetty is available + JettyHTTPServerEngineFactory serverEngineFactory = bus + .getExtension(JettyHTTPServerEngineFactory.class); + return createJettyHTTPDestination(JETTY9_WEBSOCKET_DESTINATION_CTR, bus, registry, endpointInfo, serverEngineFactory); + } else if (UNDERTOW_AVAILABLE) { + // use UndertowWebSocketDestination + UndertowHTTPServerEngineFactory undertowServerEngineFactory = bus + .getExtension(UndertowHTTPServerEngineFactory.class); + return createUndertowHTTPDestination(UNDERTOW_WEBSOCKET_DESTINATION_CTR, bus, + registry, endpointInfo, undertowServerEngineFactory); + } + return null; } } else { // REVISIT other way of getting the registry of http so that the plain cxf servlet finds the http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketUndertowDestination.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketUndertowDestination.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketUndertowDestination.java index 4d1f427..d894482 100644 --- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketUndertowDestination.java +++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketUndertowDestination.java @@ -194,7 +194,7 @@ public class AtmosphereWebSocketUndertowDestination extends UndertowHTTPDestinat @Override protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) { - handleReceivedMessage(channel, message); + handleReceivedMessage(channel, message, exchange); } @@ -202,14 +202,12 @@ public class AtmosphereWebSocketUndertowDestination extends UndertowHTTPDestinat BufferedBinaryMessage message) throws IOException { - handleReceivedMessage(channel, message); + handleReceivedMessage(channel, message, exchange); } }); channel.resumeReceives(); - // handleNormalRequest(undertowExchange); } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -228,12 +226,7 @@ public class AtmosphereWebSocketUndertowDestination extends UndertowHTTPDestinat .getDeployment(), request, response, null); undertowExchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext); - /* - * if (AtmosphereUtils.useAtmosphere(request)) { try { - * framework.doCometSupport(AtmosphereRequestImpl.wrap(request), - * AtmosphereResponseImpl.wrap(response)); } catch (ServletException e) { throw new - * IOException(e); } return; } else { super.handleRequest(undertowExchange); } - */ + try { framework.doCometSupport(AtmosphereRequestImpl.wrap(request), AtmosphereResponseImpl.wrap(response)); @@ -246,7 +239,6 @@ public class AtmosphereWebSocketUndertowDestination extends UndertowHTTPDestinat public void handleNormalRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { - // if (AtmosphereUtils.useAtmosphere(request)) { try { framework.doCometSupport(AtmosphereRequestImpl.wrap(request), AtmosphereResponseImpl.wrap(response)); @@ -254,16 +246,16 @@ public class AtmosphereWebSocketUndertowDestination extends UndertowHTTPDestinat } catch (ServletException e) { throw new IOException(e); } - // } + } - private void handleReceivedMessage(WebSocketChannel channel, Object message) { + private void handleReceivedMessage(WebSocketChannel channel, Object message, HttpServerExchange exchange) { executor.execute(new Runnable() { @Override public void run() { try { - HttpServletRequest request = new WebSocketUndertowServletRequest(channel, message); + HttpServletRequest request = new WebSocketUndertowServletRequest(channel, message, exchange); HttpServletResponse response = new WebSocketUndertowServletResponse(channel); if (request.getHeader(WebSocketConstants.DEFAULT_REQUEST_ID_KEY) != null) { response.setHeader(WebSocketConstants.DEFAULT_RESPONSE_ID_KEY, @@ -271,7 +263,7 @@ public class AtmosphereWebSocketUndertowDestination extends UndertowHTTPDestinat } handleNormalRequest(request, response); } catch (Exception ex) { - ex.printStackTrace(); + LOG.log(Level.WARNING, "Failed to invoke service", ex); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/UndertowWebSocketDestination.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/UndertowWebSocketDestination.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/UndertowWebSocketDestination.java new file mode 100644 index 0000000..1d34169 --- /dev/null +++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/UndertowWebSocketDestination.java @@ -0,0 +1,232 @@ +/** + * 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.undertow; + +import java.io.IOException; +import java.net.URL; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.cxf.Bus; +import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.common.util.StringUtils; +import org.apache.cxf.service.model.EndpointInfo; +import org.apache.cxf.transport.http.DestinationRegistry; +import org.apache.cxf.transport.http_undertow.UndertowHTTPDestination; +import org.apache.cxf.transport.http_undertow.UndertowHTTPHandler; +import org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngineFactory; +import org.apache.cxf.transport.websocket.WebSocketConstants; +import org.apache.cxf.transport.websocket.WebSocketDestinationService; +import org.apache.cxf.workqueue.WorkQueueManager; +import org.xnio.StreamConnection; + +import io.undertow.server.HttpServerExchange; +import io.undertow.server.HttpUpgradeListener; +import io.undertow.servlet.handlers.ServletRequestContext; +import io.undertow.servlet.spec.HttpServletRequestImpl; +import io.undertow.servlet.spec.HttpServletResponseImpl; +import io.undertow.servlet.spec.ServletContextImpl; +import io.undertow.util.Methods; +import io.undertow.websockets.core.AbstractReceiveListener; +import io.undertow.websockets.core.BufferedBinaryMessage; +import io.undertow.websockets.core.BufferedTextMessage; +import io.undertow.websockets.core.WebSocketChannel; +import io.undertow.websockets.core.protocol.Handshake; +import io.undertow.websockets.core.protocol.version07.Hybi07Handshake; +import io.undertow.websockets.core.protocol.version08.Hybi08Handshake; +import io.undertow.websockets.core.protocol.version13.Hybi13Handshake; +import io.undertow.websockets.spi.AsyncWebSocketHttpServerExchange; + +/** + * + */ +public class UndertowWebSocketDestination extends UndertowHTTPDestination + implements WebSocketDestinationService { + private static final Logger LOG = LogUtils.getL7dLogger(UndertowWebSocketDestination.class); + private final Executor executor; + + public UndertowWebSocketDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei, + UndertowHTTPServerEngineFactory serverEngineFactory) + throws IOException { + super(bus, registry, ei, serverEngineFactory); + executor = bus.getExtension(WorkQueueManager.class).getAutomaticWorkQueue(); + } + + @Override + public void invokeInternal(ServletConfig config, ServletContext context, HttpServletRequest req, + HttpServletResponse resp) throws IOException { + super.invoke(config, context, req, resp); + } + + private static String getNonWSAddress(EndpointInfo endpointInfo) { + String address = endpointInfo.getAddress(); + if (address.startsWith("ws")) { + address = "http" + address.substring(2); + } + return address; + } + + @Override + protected String getAddress(EndpointInfo endpointInfo) { + return getNonWSAddress(endpointInfo); + } + + @Override + protected String getBasePath(String contextPath) throws IOException { + if (StringUtils.isEmpty(endpointInfo.getAddress())) { + return ""; + } + return new URL(getAddress(endpointInfo)).getPath(); + } + + @Override + protected UndertowHTTPHandler createUndertowHTTPHandler(UndertowHTTPDestination jhd, boolean cmExact) { + return new AtmosphereUndertowWebSocketHandler(jhd, cmExact); + } + + + + private class AtmosphereUndertowWebSocketHandler extends UndertowHTTPHandler { + private final Set<Handshake> handshakes; + private final Set<WebSocketChannel> peerConnections = Collections + .newSetFromMap(new ConcurrentHashMap<WebSocketChannel, Boolean>()); + + AtmosphereUndertowWebSocketHandler(UndertowHTTPDestination jhd, boolean cmExact) { + super(jhd, cmExact); + handshakes = new HashSet<>(); + handshakes.add(new Hybi13Handshake()); + handshakes.add(new Hybi08Handshake()); + handshakes.add(new Hybi07Handshake()); + } + + @Override + public void handleRequest(HttpServerExchange undertowExchange) throws Exception { + if (undertowExchange.isInIoThread()) { + undertowExchange.dispatch(this); + return; + } + if (!undertowExchange.getRequestMethod().equals(Methods.GET)) { + // Only GET is supported to start the handshake + handleNormalRequest(undertowExchange); + return; + } + final AsyncWebSocketHttpServerExchange facade = new AsyncWebSocketHttpServerExchange(undertowExchange, + peerConnections); + Handshake handshaker = null; + for (Handshake method : handshakes) { + if (method.matches(facade)) { + handshaker = method; + break; + } + } + + if (handshaker == null) { + handleNormalRequest(undertowExchange); + } else { + final Handshake selected = handshaker; + undertowExchange.upgradeChannel(new HttpUpgradeListener() { + @Override + public void handleUpgrade(StreamConnection streamConnection, + HttpServerExchange exchange) { + try { + + WebSocketChannel channel = selected.createChannel(facade, streamConnection, + facade.getBufferPool()); + peerConnections.add(channel); + channel.getReceiveSetter().set(new AbstractReceiveListener() { + @Override + protected void onFullTextMessage(WebSocketChannel channel, + BufferedTextMessage message) { + handleReceivedMessage(channel, message, exchange); + + } + + protected void onFullBinaryMessage(WebSocketChannel channel, + BufferedBinaryMessage message) + throws IOException { + + handleReceivedMessage(channel, message, exchange); + + } + }); + channel.resumeReceives(); + + } catch (Exception e) { + LOG.log(Level.WARNING, "Failed to invoke service", e); + } + } + }); + handshaker.handshake(facade); + } + + } + + public void handleNormalRequest(HttpServerExchange undertowExchange) throws Exception { + HttpServletResponseImpl response = new HttpServletResponseImpl(undertowExchange, + (ServletContextImpl)servletContext); + HttpServletRequestImpl request = new HttpServletRequestImpl(undertowExchange, + (ServletContextImpl)servletContext); + ServletRequestContext servletRequestContext = new ServletRequestContext(((ServletContextImpl)servletContext) + .getDeployment(), request, response, null); + + undertowExchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext); + doService(request, response); + } + + public void handleNormalRequest(HttpServletRequest request, HttpServletResponse response) + throws Exception { + + doService(request, response); + } + + private void handleReceivedMessage(WebSocketChannel channel, Object message, HttpServerExchange exchange) { + executor.execute(new Runnable() { + + @Override + public void run() { + try { + HttpServletRequest request = new WebSocketUndertowServletRequest(channel, message, exchange); + HttpServletResponse response = new WebSocketUndertowServletResponse(channel); + if (request.getHeader(WebSocketConstants.DEFAULT_REQUEST_ID_KEY) != null) { + response.setHeader(WebSocketConstants.DEFAULT_RESPONSE_ID_KEY, + request.getHeader(WebSocketConstants.DEFAULT_REQUEST_ID_KEY)); + } + handleNormalRequest(request, response); + } catch (Exception ex) { + ex.printStackTrace(); + } + + } + + }); + + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java ---------------------------------------------------------------------- diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java index 0b1d884..27aa6d2 100644 --- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java +++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java @@ -57,6 +57,7 @@ import javax.servlet.http.Part; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.transport.websocket.WebSocketUtils; +import io.undertow.server.HttpServerExchange; import io.undertow.websockets.core.BufferedBinaryMessage; import io.undertow.websockets.core.BufferedTextMessage; import io.undertow.websockets.core.WebSocketChannel; @@ -71,8 +72,9 @@ public class WebSocketUndertowServletRequest implements HttpServletRequest { private Map<String, String> requestHeaders; private Map<String, Object> attributes; private InputStream in; + //private HttpServerExchange exchange; - public WebSocketUndertowServletRequest(WebSocketChannel channel, Object message) + public WebSocketUndertowServletRequest(WebSocketChannel channel, Object message, HttpServerExchange exchange) throws IOException { this.channel = channel; if (message instanceof BufferedBinaryMessage) { @@ -469,7 +471,9 @@ public class WebSocketUndertowServletRequest implements HttpServletRequest { @Override public String getPathInfo() { + return null; + } @Override http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketNoAtmosphereTest.java ---------------------------------------------------------------------- diff --git a/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketNoAtmosphereTest.java b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketNoAtmosphereTest.java new file mode 100644 index 0000000..fcb4b0b --- /dev/null +++ b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketNoAtmosphereTest.java @@ -0,0 +1,51 @@ +/** + * 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.systest.http_undertow.websocket; + +import org.apache.cxf.jaxrs.model.AbstractResourceInfo; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + + + +/** + * JAXRSClientServerWebSocketTest without atmosphere + */ +public class JAXRSClientServerWebSocketNoAtmosphereTest extends JAXRSClientServerWebSocketTest { + private static final String PORT = BookServerWebSocket.PORT2; + + @BeforeClass + public static void startServers() throws Exception { + System.setProperty("org.apache.cxf.transport.websocket.atmosphere.disabled", "true"); + AbstractResourceInfo.clearAllMaps(); + assertTrue("server did not launch correctly", launchServer(new BookServerWebSocket(PORT))); + createStaticBus(); + } + + @AfterClass + public static void cleanup() { + System.clearProperty("org.apache.cxf.transport.websocket.atmosphere.disabled"); + } + + protected String getPort() { + return PORT; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketSpringNoAtmosphereTest.java ---------------------------------------------------------------------- diff --git a/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketSpringNoAtmosphereTest.java b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketSpringNoAtmosphereTest.java new file mode 100644 index 0000000..4f64875 --- /dev/null +++ b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketSpringNoAtmosphereTest.java @@ -0,0 +1,52 @@ +/** + * 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.systest.http_undertow.websocket; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * JAXRSClientServerWebSocketSpringTest without atmosphere + */ +public class JAXRSClientServerWebSocketSpringNoAtmosphereTest extends JAXRSClientServerWebSocketSpringTest { + private static final String PORT = BookServerWebSocket.PORT2_SPRING; + + @BeforeClass + public static void startServers() throws Exception { + System.setProperty("org.apache.cxf.transport.websocket.atmosphere.disabled", "true"); + @SuppressWarnings({ "unused", "resource" }) + ApplicationContext appctxt = + new ClassPathXmlApplicationContext( + JAXRSClientServerWebSocketSpringTest.class.getResource( + "/jaxrs_websocket/beans-embedded2.xml").toString()); + } + + @AfterClass + public static void cleanup() { + System.clearProperty("org.apache.cxf.transport.websocket.atmosphere.disabled"); + } + + protected String getPort() { + return PORT; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketSpringTest.java ---------------------------------------------------------------------- diff --git a/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketSpringTest.java b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketSpringTest.java new file mode 100644 index 0000000..6689060 --- /dev/null +++ b/systests/transport-undertow/src/test/java/org/apache/cxf/systest/http_undertow/websocket/JAXRSClientServerWebSocketSpringTest.java @@ -0,0 +1,48 @@ +/** + * 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.systest.http_undertow.websocket; + +import org.junit.BeforeClass; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + + +/** + * JAXRSClientServerWebSocket test with jaxrs:server using the embedded undertow server. + */ +public class JAXRSClientServerWebSocketSpringTest extends JAXRSClientServerWebSocketTest { + private static final String PORT = BookServerWebSocket.PORT_SPRING; + @BeforeClass + public static void startServers() throws Exception { + + @SuppressWarnings({ "unused", "resource" }) + ApplicationContext appctxt = + new ClassPathXmlApplicationContext( + JAXRSClientServerWebSocketSpringTest.class.getResource( + "/jaxrs_websocket/beans-embedded.xml").toString()); + + } + + protected String getPort() { + return PORT; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/transport-undertow/src/test/resources/jaxrs_websocket/WEB-INF/beans.xml ---------------------------------------------------------------------- diff --git a/systests/transport-undertow/src/test/resources/jaxrs_websocket/WEB-INF/beans.xml b/systests/transport-undertow/src/test/resources/jaxrs_websocket/WEB-INF/beans.xml new file mode 100644 index 0000000..2bdced4 --- /dev/null +++ b/systests/transport-undertow/src/test/resources/jaxrs_websocket/WEB-INF/beans.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!-- START SNIPPET: beans --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:http="http://cxf.apache.org/transports/http/configuration" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" + xmlns:jaxrs="http://cxf.apache.org/jaxrs" + xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration" + xmlns:cxf="http://cxf.apache.org/core" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd + http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd + http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd + http://cxf.apache.org/transports/http-jetty/configuration http://cxf.apache.org/schemas/configuration/http-jetty.xsd + http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> + <import resource="classpath:META-INF/cxf/cxf.xml"/> + <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> + + <bean class="org.apache.cxf.systest.http_undertow.websocket.BookStoreWebSocket" id="serviceBean"/> + + <jaxrs:server id="bookserviceWS" address="/websocket" transportId="http://cxf.apache.org/transports/websocket"> + <jaxrs:serviceBeans> + <ref bean="serviceBean"/> + </jaxrs:serviceBeans> + <jaxrs:providers> + <bean class="org.apache.cxf.jaxrs.provider.StreamingResponseProvider"/> + </jaxrs:providers> + </jaxrs:server> + <jaxrs:server id="bookserviceHTTP" address="/http"> + <jaxrs:serviceBeans> + <ref bean="serviceBean"/> + </jaxrs:serviceBeans> + </jaxrs:server> + +</beans> +<!-- END SNIPPET: beans --> http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/transport-undertow/src/test/resources/jaxrs_websocket/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/systests/transport-undertow/src/test/resources/jaxrs_websocket/WEB-INF/web.xml b/systests/transport-undertow/src/test/resources/jaxrs_websocket/WEB-INF/web.xml new file mode 100644 index 0000000..76d7687 --- /dev/null +++ b/systests/transport-undertow/src/test/resources/jaxrs_websocket/WEB-INF/web.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> +<!-- + 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. +--> +<!-- START SNIPPET: webxml --> +<web-app> + <context-param> + <param-name>contextConfigLocation</param-name> + <param-value>WEB-INF/beans.xml</param-value> + </context-param> + <listener> + <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> + </listener> + <servlet> + <servlet-name>CXFServlet</servlet-name> + <display-name>CXF Servlet</display-name> + <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CXFServlet</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> +</web-app> +<!-- END SNIPPET: webxml --> http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/transport-undertow/src/test/resources/jaxrs_websocket/beans-embedded.xml ---------------------------------------------------------------------- diff --git a/systests/transport-undertow/src/test/resources/jaxrs_websocket/beans-embedded.xml b/systests/transport-undertow/src/test/resources/jaxrs_websocket/beans-embedded.xml new file mode 100644 index 0000000..d05429b --- /dev/null +++ b/systests/transport-undertow/src/test/resources/jaxrs_websocket/beans-embedded.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!-- START SNIPPET: beans --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:http="http://cxf.apache.org/transports/http/configuration" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" + xmlns:jaxrs="http://cxf.apache.org/jaxrs" + xmlns:cxf="http://cxf.apache.org/core" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd + http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd + http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd + http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> + <import resource="classpath:META-INF/cxf/cxf.xml"/> + <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> + + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> + + <bean class="org.apache.cxf.systest.http_undertow.websocket.BookStoreWebSocket" id="serviceBean"/> + + <jaxrs:server id="bookservice" address="ws://localhost:${testutil.ports.org.apache.cxf.systest.http_undertow.websocket.BookServerWebSocket.2}/websocket"> + <jaxrs:serviceBeans> + <ref bean="serviceBean"/> + </jaxrs:serviceBeans> + <jaxrs:providers> + <bean class="org.apache.cxf.jaxrs.provider.StreamingResponseProvider"/> + </jaxrs:providers> + </jaxrs:server> +</beans> +<!-- END SNIPPET: beans --> http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/transport-undertow/src/test/resources/jaxrs_websocket/beans-embedded2.xml ---------------------------------------------------------------------- diff --git a/systests/transport-undertow/src/test/resources/jaxrs_websocket/beans-embedded2.xml b/systests/transport-undertow/src/test/resources/jaxrs_websocket/beans-embedded2.xml new file mode 100644 index 0000000..08d381f --- /dev/null +++ b/systests/transport-undertow/src/test/resources/jaxrs_websocket/beans-embedded2.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!-- START SNIPPET: beans --> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:http="http://cxf.apache.org/transports/http/configuration" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" + xmlns:jaxrs="http://cxf.apache.org/jaxrs" + xmlns:cxf="http://cxf.apache.org/core" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd + http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd + http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd + http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> + <import resource="classpath:META-INF/cxf/cxf.xml"/> + <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> + + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> + + <bean class="org.apache.cxf.systest.http_undertow.websocket.BookStoreWebSocket" id="serviceBean"/> + + <jaxrs:server id="bookservice" address="ws://localhost:${testutil.ports.org.apache.cxf.systest.http_undertow.websocket.BookServerWebSocket.5}/websocket"> + <jaxrs:serviceBeans> + <ref bean="serviceBean"/> + </jaxrs:serviceBeans> + <jaxrs:providers> + <bean class="org.apache.cxf.jaxrs.provider.StreamingResponseProvider"/> + </jaxrs:providers> + </jaxrs:server> +</beans> +<!-- END SNIPPET: beans --> http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/WSRMPolicyResolveTest.java ---------------------------------------------------------------------- diff --git a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/WSRMPolicyResolveTest.java b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/WSRMPolicyResolveTest.java deleted file mode 100644 index 75129bf..0000000 --- a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/WSRMPolicyResolveTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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.systest.ws.rm; - - -import org.apache.cxf.test.AbstractCXFSpringTest; -import org.apache.cxf.testutil.common.TestUtil; - -import org.junit.Test; - -import org.springframework.context.support.GenericApplicationContext; - - - -//CXF-4875 -public class WSRMPolicyResolveTest extends AbstractCXFSpringTest { - public static final String PORT = TestUtil.getPortNumber(WSRMPolicyResolveTest.class); - /** {@inheritDoc}*/ - @Override - protected void additionalSpringConfiguration(GenericApplicationContext context) throws Exception { - } - - @Test - public void testHello() throws Exception { - BasicDocEndpoint port = getApplicationContext().getBean("TestClient", - BasicDocEndpoint.class); - Object retObj = port.echo("Hello"); - assertEquals("Hello", retObj); - } - - /** {@inheritDoc}*/ - @Override - protected String[] getConfigLocations() { - return new String[] {"classpath:/org/apache/cxf/systest/ws/rm/wsrm-policy-resolve.xml" }; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/ebd1c24d/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/RM10PolicyWsdlTest.java ---------------------------------------------------------------------- diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/RM10PolicyWsdlTest.java b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/RM10PolicyWsdlTest.java deleted file mode 100644 index 0157759..0000000 --- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/RM10PolicyWsdlTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * 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.systest.ws.policy; - -import java.io.Closeable; -import java.util.logging.Logger; - -import org.apache.cxf.common.logging.LogUtils; -import org.apache.cxf.greeter_control.Greeter; -import org.apache.cxf.greeter_control.PingMeFault; -import org.apache.cxf.greeter_control.ReliableGreeterService; -import org.apache.cxf.systest.ws.util.ConnectionHelper; -import org.apache.cxf.systest.ws.util.MessageFlow; -import org.apache.cxf.testutil.common.TestUtil; -import org.apache.cxf.testutil.recorders.MessageRecorder; -import org.apache.cxf.ws.rm.RM10Constants; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Tests the use of the WS-Policy Framework to automatically engage WS-RM 1.0 in response to Policies defined for the - * endpoint via an direct attachment to the wsdl. - */ -public class RM10PolicyWsdlTest extends RMPolicyWsdlTestBase { - - public static final String PORT = allocatePort(Server.class); - - private static final Logger LOG = LogUtils.getLogger(RM10PolicyWsdlTest.class); - - public static class Server extends ServerBase { - - public static void main(String[] args) { - try { - Server s = new Server(); - s.start(); - } catch (Exception ex) { - ex.printStackTrace(); - System.exit(-1); - } finally { - System.out.println("done!"); - } - } - - @Override - protected String getConfigPath() { - return "org/apache/cxf/systest/ws/policy/rm10wsdl_server.xml"; - } - } - - - @BeforeClass - public static void startServers() throws Exception { - TestUtil.getNewPortNumber("decoupled"); - assertTrue("server did not launch correctly", launchServer(Server.class, true)); - } - - @Test - public void testUsingRM() throws Exception { - setUpBus(PORT); - ReliableGreeterService gs = new ReliableGreeterService(); - Greeter greeter = gs.getGreeterPort(); - updateAddressPort(greeter, PORT); - LOG.fine("Created greeter client."); - - ConnectionHelper.setKeepAliveConnection(greeter, true); - - - // two-way - - assertEquals("CXF", greeter.greetMe("cxf")); - - // oneway - - greeter.greetMeOneWay("CXF"); - - // exception - - try { - greeter.pingMe(); - } catch (PingMeFault ex) { - fail("First invocation should have succeeded."); - } - - try { - greeter.pingMe(); - fail("Expected PingMeFault not thrown."); - } catch (PingMeFault ex) { - assertEquals(2, ex.getFaultInfo().getMajor()); - assertEquals(1, ex.getFaultInfo().getMinor()); - } - - MessageRecorder mr = new MessageRecorder(outRecorder, inRecorder); - mr.awaitMessages(5, 4, 5000); -// mr.awaitMessages(5, 9, 5000); - - MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(), - inRecorder.getInboundMessages(), - "http://schemas.xmlsoap.org/ws/2004/08/addressing", - "http://schemas.xmlsoap.org/ws/2005/02/rm"); - - - mf.verifyMessages(5, true); - String[] expectedActions = new String[] {RM10Constants.INSTANCE.getCreateSequenceAction(), - GREETME_ACTION, - GREETMEONEWAY_ACTION, - PINGME_ACTION, - PINGME_ACTION}; - mf.verifyActions(expectedActions, true); - mf.verifyMessageNumbers(new String[] {null, "1", "2", "3", "4"}, true); - mf.verifyLastMessage(new boolean[] {false, false, false, false, false}, true); - mf.verifyAcknowledgements(new boolean[] {false, false, true, false, true}, true); - - mf.verifyMessages(4, false); -// mf.verifyMessages(9, false); -// mf.verifyPartialResponses(5); -// mf.purgePartialResponses(); - - expectedActions = new String[] { - RM10Constants.INSTANCE.getCreateSequenceResponseAction(), - GREETME_RESPONSE_ACTION, - PINGME_RESPONSE_ACTION, - GREETER_FAULT_ACTION - }; - mf.verifyActions(expectedActions, false); - mf.verifyMessageNumbers(new String[] {null, "1", "2", "3"}, false); - mf.verifyLastMessage(new boolean[] {false, false, false, false}, false); - mf.verifyAcknowledgements(new boolean[] {false, true, true, true}, false); - ((Closeable)greeter).close(); - } -}