http://git-wip-us.apache.org/repos/asf/wicket/blob/6540f025/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
new file mode 100644
index 0000000..fbb7625
--- /dev/null
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-jetty9/src/main/java/org/apache/wicket/protocol/ws/jetty9/Jetty9WebSocketProcessor.java
@@ -0,0 +1,102 @@
+/*
+ * 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.jetty9;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor;
+import org.eclipse.jetty.websocket.core.annotations.WebSocket;
+import org.eclipse.jetty.websocket.core.api.UpgradeRequest;
+import org.eclipse.jetty.websocket.core.api.UpgradeResponse;
+import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
+import org.eclipse.jetty.websocket.core.api.WebSocketException;
+import org.eclipse.jetty.websocket.core.api.WebSocketListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An {@link org.apache.wicket.protocol.ws.api.IWebSocketProcessor processor} 
that integrates with
+ * Jetty 9.x {@link WebSocket web socket} implementation.
+ *
+ * @since 6.2
+ */
+public class Jetty9WebSocketProcessor extends AbstractWebSocketProcessor
+       implements
+               WebSocketListener
+{
+       private static final Logger LOG = 
LoggerFactory.getLogger(Jetty9WebSocketProcessor.class);
+
+       /**
+        * Constructor.
+        *
+        * @param upgradeRequest
+        *            the jetty upgrade request
+        * @param upgradeResponse
+        *            the jetty upgrade response
+        * @param application
+        *            the current Wicket Application
+        */
+       public Jetty9WebSocketProcessor(final UpgradeRequest upgradeRequest,
+               final UpgradeResponse upgradeResponse, final Application 
application)
+       {
+               
super((HttpServletRequest)((HttpServletRequestWrapper)upgradeRequest).getRequest(),
+                       application);
+       }
+
+       @Override
+       public void onWebSocketConnect(WebSocketConnection connection)
+       {
+               onConnect(new Jetty9WebSocketConnection(connection, this));
+       }
+
+       @Override
+       public void onWebSocketText(String message)
+       {
+               onMessage(message);
+       }
+
+       @Override
+       public void onWebSocketBinary(byte[] payload, int offset, int len)
+       {
+               onMessage(payload, offset, len);
+       }
+
+       @Override
+       public void onWebSocketClose(int statusCode, String reason)
+       {
+               onClose(statusCode, reason);
+       }
+
+       @Override
+       public void onWebSocketException(WebSocketException error)
+       {
+               LOG.error("An error occurred when using WebSocket.", error);
+       }
+
+       @Override
+       public void onOpen(Object connection)
+       {
+               if (!(connection instanceof WebSocketConnection))
+               {
+                       throw new 
IllegalArgumentException(WebSocketConnection.class.getName() +
+                               " can work only with " + 
WebSocketConnection.class.getName());
+               }
+               onWebSocketConnect((WebSocketConnection)connection);
+       }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/6540f025/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/http/Tomcat7WebSocketFilter.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/http/Tomcat7WebSocketFilter.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/http/Tomcat7WebSocketFilter.java
deleted file mode 100644
index 8f3ea55..0000000
--- 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/http/Tomcat7WebSocketFilter.java
+++ /dev/null
@@ -1,90 +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.http;
-
-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.HttpServletResponse;
-
-import org.apache.catalina.connector.RequestFacade;
-import org.apache.catalina.util.Base64;
-import org.apache.tomcat.util.buf.B2CConverter;
-import org.apache.wicket.Application;
-import org.apache.wicket.protocol.ws.tomcat7.TomcatWebSocketProcessor;
-
-/**
- * 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;
-
-
-       @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, Application application)
-                       throws ServletException, IOException
-       {
-               if (!super.acceptWebSocket(req, resp, application))
-               {
-                       return false;
-               }
-
-               String key = req.getHeader("Sec-WebSocket-Key");
-               resp.setHeader("Sec-WebSocket-Accept", getWebSocketAccept(key));
-
-               // Small hack until the Servlet API provides a way to do this.
-               TomcatWebSocketProcessor webSocketHandler = new 
TomcatWebSocketProcessor(req, application);
-               TomcatWebSocketProcessor.TomcatWebSocket tomcatWebSocket = 
webSocketHandler.new TomcatWebSocket();
-               ((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/6540f025/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
----------------------------------------------------------------------
diff --git 
a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
new file mode 100644
index 0000000..fbb4d0b
--- /dev/null
+++ 
b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-tomcat/src/main/java/org/apache/wicket/protocol/ws/tomcat7/Tomcat7WebSocketFilter.java
@@ -0,0 +1,91 @@
+/*
+ * 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.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.catalina.connector.RequestFacade;
+import org.apache.catalina.util.Base64;
+import org.apache.tomcat.util.buf.B2CConverter;
+import org.apache.wicket.Application;
+import org.apache.wicket.protocol.ws.AbstractUpgradeFilter;
+
+/**
+ * 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;
+
+
+       @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;
+               }
+
+               String key = req.getHeader("Sec-WebSocket-Key");
+               resp.setHeader("Sec-WebSocket-Accept", getWebSocketAccept(key));
+
+               Application 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();
+               ((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));
+               }
+       }
+
+
+}

Reply via email to