Repository: wicket Updated Branches: refs/heads/master 5a4a6a7d8 -> d9bfc96e6
WICKET-6304 Remove Tomcat7 support in Native WebSockets Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d9bfc96e Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d9bfc96e Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d9bfc96e Branch: refs/heads/master Commit: d9bfc96e6cb67a382ed1800d9900ff6f30b8b218 Parents: 5a4a6a7 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Fri Jan 13 18:57:33 2017 +0100 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Fri Jan 13 18:57:33 2017 +0100 ---------------------------------------------------------------------- wicket-native-websocket/pom.xml | 1 - .../wicket-native-websocket-tomcat/pom.xml | 63 ----------- .../ws/tomcat7/Tomcat7WebSocketFilter.java | 113 ------------------- .../ws/tomcat7/TomcatWebSocketConnection.java | 101 ----------------- .../ws/tomcat7/TomcatWebSocketProcessor.java | 83 -------------- .../util/license/ApacheLicenceHeaderTest.java | 34 ------ 6 files changed, 395 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/d9bfc96e/wicket-native-websocket/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-native-websocket/pom.xml b/wicket-native-websocket/pom.xml index 233d99b..b81fe33 100644 --- a/wicket-native-websocket/pom.xml +++ b/wicket-native-websocket/pom.xml @@ -29,7 +29,6 @@ <description>Wicket Native WebSocket provides native integration for WebSocket support with Servlet web containers.</description> <modules> <module>wicket-native-websocket-core</module> - <module>wicket-native-websocket-tomcat</module> <module>wicket-native-websocket-javax</module> <module>wicket-native-websocket-example</module> </modules> http://git-wip-us.apache.org/repos/asf/wicket/blob/d9bfc96e/wicket-native-websocket/wicket-native-websocket-tomcat/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-native-websocket/wicket-native-websocket-tomcat/pom.xml b/wicket-native-websocket/wicket-native-websocket-tomcat/pom.xml deleted file mode 100644 index 02f0ae5..0000000 --- a/wicket-native-websocket/wicket-native-websocket-tomcat/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ -<?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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket-native-websocket</artifactId> - <version>8.0.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>wicket-native-websocket-tomcat</artifactId> - <packaging>jar</packaging> - <name>Wicket Native WebSocket Tomcat 7.x</name> - <description>Provides the code specific to integrate with Tomcat web container</description> - <properties> - <tomcat.version>7.0.70</tomcat.version> - </properties> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.apache.tomcat</groupId> - <artifactId>tomcat-catalina</artifactId> - <version>${tomcat.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.tomcat</groupId> - <artifactId>tomcat-coyote</artifactId> - <version>${tomcat.version}</version> - <scope>provided</scope> - </dependency> - </dependencies> - </dependencyManagement> - <dependencies> - <dependency> - <groupId>org.apache.tomcat</groupId> - <artifactId>tomcat-catalina</artifactId> - </dependency> - <dependency> - <groupId>org.apache.tomcat</groupId> - <artifactId>tomcat-coyote</artifactId> - </dependency> - <dependency> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket-native-websocket-core</artifactId> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/wicket/blob/d9bfc96e/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java ---------------------------------------------------------------------- diff --git a/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java b/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java deleted file mode 100644 index 8dc6582..0000000 --- a/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java +++ /dev/null @@ -1,113 +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.wicket.protocol.ws.tomcat7; - -import org.apache.catalina.connector.RequestFacade; -import org.apache.catalina.util.Base64; -import org.apache.tomcat.util.buf.B2CConverter; -import org.apache.wicket.protocol.http.WebApplication; -import org.apache.wicket.protocol.ws.AbstractUpgradeFilter; - -import java.io.IOException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; -import javax.servlet.http.HttpServletResponse; - -/** - * An upgrade filter that uses code borrowed from Tomcat's WebSocketServlet - * to decide whether to upgrade the request protocol to websocket or not. - * - * @since 6.0 - */ -public class Tomcat7WebSocketFilter extends AbstractUpgradeFilter -{ - private static final byte[] WS_ACCEPT = - "258EAFA5-E914-47DA-95CA-C5AB0DC85B11".getBytes( - B2CConverter.ISO_8859_1); - - private MessageDigest sha1Helper; - - - public Tomcat7WebSocketFilter() - { - super(); - } - - public Tomcat7WebSocketFilter(WebApplication application) - { - super(application); - } - - @Override - public void init(final boolean isServlet, final FilterConfig filterConfig) - throws ServletException - { - super.init(isServlet, filterConfig); - - try { - sha1Helper = MessageDigest.getInstance("SHA1"); - } catch (NoSuchAlgorithmException e) { - throw new ServletException(e); - } - } - - @Override - protected boolean acceptWebSocket(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException - { - if (!super.acceptWebSocket(req, resp)) - { - return false; - } - else - { - resp.setHeader("upgrade", "websocket"); - resp.setHeader("connection", "upgrade"); - } - - String key = req.getHeader("Sec-WebSocket-Key"); - resp.setHeader("Sec-WebSocket-Accept", getWebSocketAccept(key)); - - WebApplication application = getApplication(); - // Small hack until the Servlet API provides a way to do this. - TomcatWebSocketProcessor webSocketHandler = new TomcatWebSocketProcessor(req, application); - TomcatWebSocketProcessor.TomcatWebSocket tomcatWebSocket = webSocketHandler.new TomcatWebSocket(); - - // the request can be a wrapper from application servlet filters - while (req instanceof HttpServletRequestWrapper) - { - req = (HttpServletRequest) ((HttpServletRequestWrapper) req).getRequest(); - } - ((RequestFacade) req).doUpgrade(tomcatWebSocket); - return true; - } - - private String getWebSocketAccept(String key) { - synchronized (sha1Helper) { - sha1Helper.reset(); - sha1Helper.update(key.getBytes(B2CConverter.ISO_8859_1)); - return Base64.encode(sha1Helper.digest(WS_ACCEPT)); - } - } - - -} http://git-wip-us.apache.org/repos/asf/wicket/blob/d9bfc96e/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketConnection.java ---------------------------------------------------------------------- diff --git a/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketConnection.java b/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketConnection.java deleted file mode 100644 index 01ddfb0..0000000 --- a/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketConnection.java +++ /dev/null @@ -1,101 +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.wicket.protocol.ws.tomcat7; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; - -import org.apache.catalina.websocket.WsOutbound; -import org.apache.wicket.protocol.ws.api.AbstractWebSocketConnection; -import org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor; -import org.apache.wicket.protocol.ws.api.IWebSocketConnection; -import org.apache.wicket.util.lang.Args; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * * A wrapper around Tomcat's native WsOutbound - * - * @since 6.0 - */ -public class TomcatWebSocketConnection extends AbstractWebSocketConnection -{ - private static final Logger LOG = LoggerFactory.getLogger(TomcatWebSocketConnection.class); - - private final WsOutbound connection; - - private boolean closed = false; - - public TomcatWebSocketConnection(final WsOutbound connection, final AbstractWebSocketProcessor webSocketProcessor) - { - super(webSocketProcessor); - this.connection = Args.notNull(connection, "connection"); - } - - @Override - public boolean isOpen() - { - return !closed; - } - - @Override - public void close(int code, String reason) - { - if (isOpen()) - { - try - { - ByteBuffer byteBuffer = ByteBuffer.wrap(reason.getBytes("UTF-8")); - connection.close(0, byteBuffer); - } - catch (IOException iox) - { - LOG.error("An error occurred while closing WebSocket connection with initial reason: " + reason, iox); - } - closed = true; - } - } - - @Override - public IWebSocketConnection sendMessage(String message) throws IOException - { - checkClosed(); - - CharBuffer buffer = CharBuffer.wrap(message); - connection.writeTextMessage(buffer); - return this; - } - - @Override - public TomcatWebSocketConnection sendMessage(byte[] message, int offset, int length) throws IOException - { - checkClosed(); - - ByteBuffer buffer = ByteBuffer.wrap(message, offset, length); - connection.writeBinaryMessage(buffer); - return this; - } - - private void checkClosed() - { - if (!isOpen()) - { - throw new IllegalStateException("The connection is closed."); - } - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/d9bfc96e/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java ---------------------------------------------------------------------- diff --git a/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java b/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java deleted file mode 100644 index b89a608..0000000 --- a/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/TomcatWebSocketProcessor.java +++ /dev/null @@ -1,83 +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.wicket.protocol.ws.tomcat7; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.catalina.websocket.MessageInbound; -import org.apache.catalina.websocket.WsOutbound; -import org.apache.wicket.protocol.http.WebApplication; -import org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor; - -/** - * An {@link org.apache.wicket.protocol.ws.api.IWebSocketProcessor processor} that integrates - * with Tomcat 7.x {@link WsOutbound web socket} implementation. - * - * @since 6.0 - */ -public class TomcatWebSocketProcessor extends AbstractWebSocketProcessor -{ - public class TomcatWebSocket extends MessageInbound - { - @Override - protected void onBinaryMessage(ByteBuffer byteBuffer) throws IOException - { - byte[] bytes = byteBuffer.array(); - int offset = byteBuffer.position(); - int length = byteBuffer.limit() - offset; - TomcatWebSocketProcessor.this.onMessage(bytes, offset, length); - } - - @Override - protected void onTextMessage(CharBuffer charBuffer) throws IOException - { - TomcatWebSocketProcessor.this.onMessage(charBuffer.toString()); - } - - @Override - protected void onOpen(WsOutbound outbound) - { - TomcatWebSocketProcessor.this.onOpen(outbound); - } - - @Override - protected void onClose(int status) - { - TomcatWebSocketProcessor.this.onClose(status, "Connection closed by client"); - } - } - public TomcatWebSocketProcessor(final HttpServletRequest request, final WebApplication application) - { - super(request, application); - } - - @Override - public void onOpen(Object containerConnection) - { - if (!(containerConnection instanceof WsOutbound)) - { - throw new IllegalArgumentException(TomcatWebSocketProcessor.class.getName() + - " can work only with " + WsOutbound.class.getName()); - } - onConnect(new TomcatWebSocketConnection((WsOutbound) containerConnection, this)); - } - -} http://git-wip-us.apache.org/repos/asf/wicket/blob/d9bfc96e/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java ---------------------------------------------------------------------- diff --git a/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java b/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java deleted file mode 100644 index 9e3759d..0000000 --- a/wicket-native-websocket/wicket-native-websocket-tomcat/src/test/java/org/apache/wicket/protocol/ws/util/license/ApacheLicenceHeaderTest.java +++ /dev/null @@ -1,34 +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.wicket.protocol.ws.util.license; - -import org.apache.wicket.util.license.ApacheLicenseHeaderTestCase; - -/** - * Test that the license headers are in place in this project. The tests are run from - * {@link org.apache.wicket.util.license.ApacheLicenseHeaderTestCase}, but you can add project specific tests here if needed. - */ -public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase -{ - /** - * Construct. - */ - public ApacheLicenceHeaderTest() - { - // addHeaders = true; - } -}
