Skip to main content

[tyrus~code:e0505652] TYRUS-234: Removed support for deprecated protocol versions.

  • From:
  • To:
  • Subject: [tyrus~code:e0505652] TYRUS-234: Removed support for deprecated protocol versions.
  • Date: Mon, 12 Aug 2013 15:41:28 +0000

Project:    tyrus
Repository: code
Revision:   e0505652a25768228c8e3b502bce6daacee48c48
Author:     jerseyrobot
Date:       2013-08-12 14:25:30 UTC
Link:       

Log Message:
------------
TYRUS-234: Removed support for deprecated protocol versions.

- lots of related refactorings, some renames
- removed big part of unused code
- tested on standalone Grizzly and integrated into Glassfish trunk



Revisions:
----------
e0505652a25768228c8e3b502bce6daacee48c48


Modified Paths:
---------------
containers/grizzly/src/main/java/org/glassfish/tyrus/container/grizzly/GrizzlyClientSocket.java
containers/grizzly/src/main/java/org/glassfish/tyrus/container/grizzly/WebSocketFilter.java
containers/servlet/src/main/java/org/glassfish/tyrus/servlet/ConnectionImpl.java
containers/servlet/src/main/java/org/glassfish/tyrus/servlet/TyrusHttpUpgradeHandler.java
core/src/main/java/org/glassfish/tyrus/core/TyrusEndpoint.java
core/src/main/java/org/glassfish/tyrus/core/TyrusWebSocket.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Connection.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/DataFrame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Extension.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/FramingException.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/HandShake.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Masker.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ParseResult.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ProtocolError.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ProtocolHandler.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/SecKey.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/StrictUtf8.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Utf8DecodingError.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Version.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocket.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocketApplication.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocketEngine.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocketException.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocketListener.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WriteFuture.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/AbstractMultivaluedMap.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/CharacterIterator.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/MultivaluedHashMap.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/MultivaluedStringMap.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/PathPattern.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/PathSegment.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/PathTemplate.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/PatternWithGroups.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/UriComponent.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/UriTemplate.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/UriTemplateParser.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/uri/internal/l10n/Localizable.java
protocol/websocket/src/test/java/org/glassfish/tyrus/websockets/uri/TestBestMatch.java
tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/MockWebSocketClient.java


Added Paths:
------------
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ClosingFrame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/frame/BaseFrame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/frame/BinaryFrame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/frame/ClosingFrame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/frame/ContinuationFrame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/frame/Frame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/frame/PingFrame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/frame/PongFrame.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/frame/TextFrame.java


Diffs:
------
--- 
a/containers/grizzly/src/main/java/org/glassfish/tyrus/container/grizzly/GrizzlyClientSocket.java
+++ 
b/containers/grizzly/src/main/java/org/glassfish/tyrus/container/grizzly/GrizzlyClientSocket.java
@@ -78,9 +78,9 @@ import org.glassfish.tyrus.websockets.ProtocolHandler;
 import org.glassfish.tyrus.websockets.WebSocket;
 import org.glassfish.tyrus.websockets.WebSocketEngine;
 import org.glassfish.tyrus.websockets.WebSocketListener;
-import org.glassfish.tyrus.websockets.draft06.ClosingFrame;
-import org.glassfish.tyrus.websockets.frametypes.PingFrameType;
-import org.glassfish.tyrus.websockets.frametypes.PongFrameType;
+import org.glassfish.tyrus.websockets.ClosingFrame;
+import org.glassfish.tyrus.websockets.frame.PingFrame;
+import org.glassfish.tyrus.websockets.frame.PongFrame;
 
 import org.glassfish.grizzly.Connection;
 import org.glassfish.grizzly.GrizzlyFuture;
@@ -361,13 +361,13 @@ public class GrizzlyClientSocket implements WebSocket, 
TyrusClientSocket {
 
     @Override
     public Future<DataFrame> sendPing(byte[] bytes) {
-        DataFrame df = new DataFrame(new PingFrameType(), bytes);
+        DataFrame df = new DataFrame(new PingFrame(), bytes);
         return this.protocolHandler.send(df, false);
     }
 
     @Override
     public Future<DataFrame> sendPong(byte[] bytes) {
-        DataFrame df = new DataFrame(new PongFrameType(), bytes);
+        DataFrame df = new DataFrame(new PongFrame(), bytes);
         return this.protocolHandler.send(df, false);
     }
 
@@ -402,11 +402,6 @@ public class GrizzlyClientSocket implements WebSocket, 
TyrusClientSocket {
     }
 
     @Override
-    public void close(int i) {
-        close(i, null);
-    }
-
-    @Override
     public void close(int i, String s) {
         if (state.compareAndSet(State.CONNECTED, State.CLOSING)) {
             protocolHandler.close(i, s);
@@ -492,11 +487,6 @@ public class GrizzlyClientSocket implements WebSocket, 
TyrusClientSocket {
     }
 
     @Override
-    public boolean remove(WebSocketListener webSocketListener) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
     public void setWriteTimeout(long timeoutMs) {
         protocolHandler.setWriteTimeout(timeoutMs);
     }
--- 
a/containers/grizzly/src/main/java/org/glassfish/tyrus/container/grizzly/WebSocketFilter.java
+++ 
b/containers/grizzly/src/main/java/org/glassfish/tyrus/container/grizzly/WebSocketFilter.java
@@ -59,7 +59,7 @@ import org.glassfish.tyrus.websockets.WebSocketEngine;
 import org.glassfish.tyrus.websockets.WebSocketEngine.WebSocketHolder;
 import org.glassfish.tyrus.websockets.WebSocketRequest;
 import org.glassfish.tyrus.websockets.WebSocketResponse;
-import org.glassfish.tyrus.websockets.draft06.ClosingFrame;
+import org.glassfish.tyrus.websockets.ClosingFrame;
 
 import org.glassfish.grizzly.Buffer;
 import org.glassfish.grizzly.Connection;
@@ -195,7 +195,7 @@ class WebSocketFilter extends BaseFilter {
     /**
      * Method handles Grizzly {@link Connection} close phase. Check if the 
{@link Connection} is a {@link org.glassfish.tyrus.websockets.WebSocket}, if
      * yes - tries to close the websocket gracefully (sending close frame) 
and calls {@link
-     * 
org.glassfish.tyrus.websockets.WebSocket#onClose(org.glassfish.tyrus.websockets.draft06.ClosingFrame)}.
 If the Grizzly {@link Connection} is not websocket - passes processing to 
the next
+     * 
org.glassfish.tyrus.websockets.WebSocket#onClose(org.glassfish.tyrus.websockets.ClosingFrame)}.
 If the Grizzly {@link Connection} is not websocket - passes processing to 
the next
      * filter in the chain.
      *
      * @param ctx {@link FilterChainContext}--- 
a/containers/servlet/src/main/java/org/glassfish/tyrus/servlet/ConnectionImpl.java
+++ 
b/containers/servlet/src/main/java/org/glassfish/tyrus/servlet/ConnectionImpl.java
@@ -54,7 +54,7 @@ import org.glassfish.tyrus.websockets.Connection;
 import org.glassfish.tyrus.websockets.DataFrame;
 import org.glassfish.tyrus.websockets.WebSocketEngine;
 import org.glassfish.tyrus.websockets.WebSocketResponse;
-import org.glassfish.tyrus.websockets.frametypes.ClosingFrameType;
+import org.glassfish.tyrus.websockets.frame.ClosingFrame;
 
 /**
  * {@link Connection} implementation used in Servlet integration.
@@ -158,7 +158,7 @@ class ConnectionImpl extends Connection implements 
WriteListener {
                 completionHandler.completed(frame);
             }
 
-            if (frame.getType() instanceof ClosingFrameType) {
+            if (frame.getType() instanceof ClosingFrame) {
                 tyrusHttpUpgradeHandler.getWebConnection().close();
             }
         } catch (Exception e) {--- 
a/containers/servlet/src/main/java/org/glassfish/tyrus/servlet/TyrusHttpUpgradeHandler.java
+++ 
b/containers/servlet/src/main/java/org/glassfish/tyrus/servlet/TyrusHttpUpgradeHandler.java
@@ -58,7 +58,7 @@ import org.glassfish.tyrus.websockets.DataFrame;
 import org.glassfish.tyrus.websockets.FramingException;
 import org.glassfish.tyrus.websockets.WebSocket;
 import org.glassfish.tyrus.websockets.WebSocketEngine;
-import org.glassfish.tyrus.websockets.draft06.ClosingFrame;
+import org.glassfish.tyrus.websockets.ClosingFrame;
 
 /**
  * {@link HttpUpgradeHandler} and {@link ReadListener} implementation.--- 
a/core/src/main/java/org/glassfish/tyrus/core/TyrusEndpoint.java
+++ b/core/src/main/java/org/glassfish/tyrus/core/TyrusEndpoint.java
@@ -68,7 +68,7 @@ import org.glassfish.tyrus.websockets.WebSocketEngine;
 import org.glassfish.tyrus.websockets.WebSocketListener;
 import org.glassfish.tyrus.websockets.WebSocketRequest;
 import org.glassfish.tyrus.websockets.WebSocketResponse;
-import org.glassfish.tyrus.websockets.draft06.ClosingFrame;
+import org.glassfish.tyrus.websockets.ClosingFrame;
 
 /**
  * Implementation of {@link SPIRegisteredEndpoint}.--- 
a/core/src/main/java/org/glassfish/tyrus/core/TyrusWebSocket.java
+++ b/core/src/main/java/org/glassfish/tyrus/core/TyrusWebSocket.java
@@ -51,13 +51,13 @@ import org.glassfish.tyrus.websockets.DataFrame;
 import org.glassfish.tyrus.websockets.ProtocolHandler;
 import org.glassfish.tyrus.websockets.WebSocket;
 import org.glassfish.tyrus.websockets.WebSocketListener;
-import org.glassfish.tyrus.websockets.draft06.ClosingFrame;
-import org.glassfish.tyrus.websockets.frametypes.PingFrameType;
-import org.glassfish.tyrus.websockets.frametypes.PongFrameType;
+import org.glassfish.tyrus.websockets.ClosingFrame;
+import org.glassfish.tyrus.websockets.frame.PingFrame;
+import org.glassfish.tyrus.websockets.frame.PongFrame;
 
 /**
  * Tyrus implementation of {@link WebSocket}.
- *
+ * <p/>
  * Instance of this class represents one bi-directional websocket connection.
  */
 public class TyrusWebSocket implements WebSocket {
@@ -77,7 +77,7 @@ public class TyrusWebSocket implements WebSocket {
      * Create new instance, set {@link ProtocolHandler} and register {@link 
WebSocketListener WebSocketListeners}.
      *
      * @param protocolHandler used for writing data (sending).
-     * @param listeners notifies registered endpoints about incoming events.
+     * @param listeners       notifies registered endpoints about incoming 
events.
      */
     public TyrusWebSocket(final ProtocolHandler protocolHandler,
                           final WebSocketListener... listeners) {
@@ -88,19 +88,17 @@ public class TyrusWebSocket implements WebSocket {
         protocolHandler.setWebSocket(this);
     }
 
+    @Override
     public final boolean add(WebSocketListener listener) {
         return listeners.add(listener);
     }
 
-    public final boolean remove(WebSocketListener listener) {
-        return listeners.remove(listener);
-    }
-
     @Override
     public void setWriteTimeout(long timeoutMs) {
         protocolHandler.setWriteTimeout(timeoutMs);
     }
 
+    @Override
     public boolean isConnected() {
         return connected.contains(state.get());
     }
@@ -109,6 +107,7 @@ public class TyrusWebSocket implements WebSocket {
         state.set(State.CLOSED);
     }
 
+    @Override
     public void onClose(final ClosingFrame frame) {
         WebSocketListener listener;
         while ((listener = listeners.poll()) != null) {
@@ -123,6 +122,7 @@ public class TyrusWebSocket implements WebSocket {
         }
     }
 
+    @Override
     public void onConnect() {
         state.set(State.CONNECTED);
 
@@ -165,6 +165,7 @@ public class TyrusWebSocket implements WebSocket {
         }
     }
 
+    @Override
     public void onPing(DataFrame frame) {
         awaitOnConnect();
         for (WebSocketListener listener : listeners) {
@@ -180,14 +181,12 @@ public class TyrusWebSocket implements WebSocket {
         }
     }
 
+    @Override
     public void close() {
         close(NORMAL_CLOSURE, null);
     }
 
-    public void close(int code) {
-        close(code, null);
-    }
-
+    @Override
     public void close(int code, String reason) {
         if (state.compareAndSet(State.CONNECTED, State.CLOSING)) {
             protocolHandler.close(code, reason);
@@ -214,12 +213,12 @@ public class TyrusWebSocket implements WebSocket {
 
     @Override
     public Future<DataFrame> sendPing(byte[] data) {
-        return send(new DataFrame(new PingFrameType(), data));
+        return send(new DataFrame(new PingFrame(), data));
     }
 
     @Override
     public Future<DataFrame> sendPong(byte[] data) {
-        return send(new DataFrame(new PongFrameType(), data));
+        return send(new DataFrame(new PongFrame(), data));
     }
 
     // return boolean, check return value
@@ -239,6 +238,7 @@ public class TyrusWebSocket implements WebSocket {
         }
     }
 
+    @Override
     public Future<DataFrame> stream(boolean last, String fragment) {
         if (isConnected()) {
             return protocolHandler.stream(last, fragment);
@@ -247,6 +247,7 @@ public class TyrusWebSocket implements WebSocket {
         }
     }
 
+    @Override
     public Future<DataFrame> stream(boolean last, byte[] bytes, int off, int 
len) {
         if (isConnected()) {
             return protocolHandler.stream(last, bytes, off, len);--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ArrayDecoder.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * http://glassfish.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
- *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the 
License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or 
GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-
-package org.glassfish.tyrus.websockets;
-
-/*
- * FastPath byte[]->char[] decoder, REPLACE on malformed or
- * unmappable input.
- */
-interface ArrayDecoder {
-
-    int decode(byte[] src, int off, int len, char[] dst);
-
-}--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ArrayEncoder.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License").  You
- * may not use this file except in compliance with the License.  You can
- * obtain a copy of the License at
- * http://glassfish.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
- *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the 
License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or 
GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-
-package org.glassfish.tyrus.websockets;
-
-/*
- * FastPath char[]->byte[] encoder, REPLACE on malformed input or
- * unmappable input.
- */
-interface ArrayEncoder {
-
-    int encode(char[] src, int off, int len, byte[] dst);
-
-}--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/draft06/ClosingFrame.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ClosingFrame.java
@@ -38,7 +38,7 @@
  * holder.
  */
 
-package org.glassfish.tyrus.websockets.draft06;
+package org.glassfish.tyrus.websockets;
 
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
@@ -46,25 +46,14 @@ import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 
-import org.glassfish.tyrus.websockets.DataFrame;
-import org.glassfish.tyrus.websockets.ProtocolError;
-import org.glassfish.tyrus.websockets.StrictUtf8;
-import org.glassfish.tyrus.websockets.Utf8DecodingError;
-import org.glassfish.tyrus.websockets.WebSocket;
-import org.glassfish.tyrus.websockets.WebSocketEngine;
-import org.glassfish.tyrus.websockets.frametypes.ClosingFrameType;
-
 public class ClosingFrame extends DataFrame {
+
     private static final byte[] EMPTY_BYTES = new byte[0];
     private int code = WebSocket.NORMAL_CLOSURE;
     private String reason;
 
-    public ClosingFrame() {
-        super(new ClosingFrameType());
-    }
-
     public ClosingFrame(int code, String reason) {
-        super(new ClosingFrameType());
+        super(new org.glassfish.tyrus.websockets.frame.ClosingFrame());
         if (code > 0) {
             this.code = code;
         }
@@ -72,7 +61,7 @@ public class ClosingFrame extends DataFrame {
     }
 
     public ClosingFrame(byte[] data) {
-        super(new ClosingFrameType());
+        super(new org.glassfish.tyrus.websockets.frame.ClosingFrame());
         setPayload(data);
     }
 
@@ -153,6 +142,5 @@ public class ClosingFrame extends DataFrame {
                 throw new Utf8DecodingError("Illegal UTF-8 Sequence");
             }
         }
-
     }
 }--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Connection.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Connection.java
@@ -40,8 +40,6 @@
 
 package org.glassfish.tyrus.websockets;
 
-import java.io.IOException;
-
 /**
  * @author Pavel Bucek (pavel.bucek at oracle.com)
  */
@@ -49,7 +47,7 @@ public abstract class Connection {
 
     public interface CloseListener {
         // add param for remote/local close indication?
-        void onClose(Connection connection) throws IOException;
+        void onClose(Connection connection);
     }
 
     /**--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/DataFrame.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/DataFrame.java
@@ -42,42 +42,46 @@ package org.glassfish.tyrus.websockets;
 
 import java.util.Arrays;
 
+import org.glassfish.tyrus.websockets.frame.Frame;
+
 /**
  * In memory representation of a websocket frame.
  *
  * @see <a 
href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-05#section-4.3";>Frame
 Definition</a>
  */
 public class DataFrame {
+
     private String payload;
     private byte[] bytes;
-    private final FrameType type;
-    private boolean last = true;
+    private final Frame type;
+    private final boolean last;
 
-    public DataFrame(FrameType type) {
+    DataFrame(Frame type) {
         this.type = type;
+        last = true;
     }
 
-    public DataFrame(FrameType type, String data) {
+    public DataFrame(Frame type, String data) {
         this(type, data, true);
     }
 
-    public DataFrame(FrameType type, String data, boolean fin) {
+    public DataFrame(Frame type, String data, boolean fin) {
         this.type = type;
         setPayload(data);
         last = fin;
     }
 
-    public DataFrame(FrameType type, byte[] data) {
+    public DataFrame(Frame type, byte[] data) {
         this(type, data, true);
     }
 
-    public DataFrame(FrameType type, byte[] data, boolean fin) {
+    public DataFrame(Frame type, byte[] data, boolean fin) {
         this.type = type;
         type.setPayload(this, data);
         last = fin;
     }
 
-    public FrameType getType() {
+    public Frame getType() {
         return type;
     }
 
@@ -97,7 +101,7 @@ public class DataFrame {
         if (payload != null) {
             bytes = Utf8Utils.encode(new StrictUtf8(), payload);
         }
-        return bytes;
+        return Arrays.copyOf(bytes, bytes.length);
     }
 
     public void respond(WebSocket socket) {
@@ -119,8 +123,4 @@ public class DataFrame {
     public boolean isLast() {
         return last;
     }
-
-    public void setLast(boolean last) {
-        this.last = last;
-    }
 }--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Extension.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Extension.java
@@ -56,7 +56,6 @@ public final class Extension {
 
     // ------------------------------------------------------------ 
Constructors
 
-
     /**
      * Constructs a new Extension with the specified name.
      *
@@ -69,7 +68,6 @@ public final class Extension {
 
     // ---------------------------------------------------------- Public 
Methods
 
-
     /**
      * @return the extension name.
      */
@@ -118,14 +116,13 @@ public final class Extension {
 
     // ---------------------------------------------------------- Nested 
Classes
 
-
     /**
      * Representation of extension parameters.
      */
     public static final class Parameter {
 
         private final String name;
-        private String value;
+        private final String value;
 
 
         // -------------------------------------------------------- 
Constructors
@@ -146,32 +143,6 @@ public final class Extension {
             this.value = value;
         }
 
-
-        // ------------------------------------------------------ Public 
Methods
-
-        /**
-         * @return the parameter name.
-         */
-        public String getName() {
-            return name;
-        }
-
-        /**
-         * @return the parameter value; may be <code>null</code>.
-         */
-        public String getValue() {
-            return value;
-        }
-
-        /**
-         * Set the value of this parameter.
-         *
-         * @param value the value of this parameter.
-         */
-        public void setValue(String value) {
-            this.value = value;
-        }
-
         @Override
         public boolean equals(Object o) {
             if (this == o) return true;
@@ -203,5 +174,4 @@ public final class Extension {
             return sb.toString();
         }
     } // END Parameter
-
 }--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/FramingException.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/FramingException.java
@@ -42,17 +42,9 @@ package org.glassfish.tyrus.websockets;
 
 public abstract class FramingException extends WebSocketException {
 
-    public FramingException(String s) {
+    FramingException(String s) {
         super(s);
     }
 
-    public FramingException(String s, Throwable throwable) {
-        super(s, throwable);
-    }
-
-    public FramingException(Throwable throwable) {
-        super(throwable);
-    }
-
     public abstract int getClosingCode();
 }--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/HandShake.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/HandShake.java
@@ -53,18 +53,16 @@ import java.util.logging.Logger;
  * @author Justin Lee
  * @author Pavel Bucek (pavel.bucek at oracle.com)
  */
-public abstract class HandShake {
+public final class HandShake {
 
     private static final String HEADER_SEPARATOR = ", ";
-
     private static final Logger LOGGER = 
Logger.getLogger(HandShake.class.getName());
-
+    private final List<String> enabledExtensions = Collections.emptyList();
     private boolean secure;
     private String origin;
     private String serverHostName;
     private int port = 80;
     private String resourcePath;
-    private String location;
     //private final Map<String, String[]> queryParams = new TreeMap<String, 
String[]>();
     private List<String> subProtocols = new ArrayList<String>();
     private List<Extension> extensions = new ArrayList<Extension>(); // 
client extensions
@@ -72,49 +70,59 @@ public abstract class HandShake {
     private WebSocketRequest request;
     private HandShakeResponseListener responseListener;
     private WebSocketRequest incomingRequest;
+    private SecKey secKey;
+
 
-    protected HandShake(WebSocketRequest webSocketRequest, boolean client) {
-        this.request = webSocketRequest;
+    private HandShake() {
+    }
+
+    static HandShake createClientHandShake(WebSocketRequest 
webSocketRequest) {
+        final HandShake handShake = new HandShake();
+        handShake.request = webSocketRequest;
 
         final URI uri = webSocketRequest.getRequestURI();
-        resourcePath = uri.getPath();
-        if ("".equals(resourcePath)) {
-            resourcePath = "/";
+        handShake.resourcePath = uri.getPath();
+        if ("".equals(handShake.resourcePath)) {
+            handShake.resourcePath = "/";
         }
         if (uri.getQuery() != null) {
-            resourcePath += "?" + uri.getQuery();
+            handShake.resourcePath += "?" + uri.getQuery();
         }
-        serverHostName = uri.getHost();
-        secure = request.isSecure();
-        port = uri.getPort();
-        origin = appendPort(new StringBuilder(uri.getHost())).toString();
-        buildLocation();
+        handShake.serverHostName = uri.getHost();
+        handShake.secure = webSocketRequest.isSecure();
+        handShake.port = uri.getPort();
+        handShake.origin = appendPort(new StringBuilder(uri.getHost()), 
handShake.port, handShake.secure).toString();
+        handShake.secKey = new SecKey();
+
+        return handShake;
     }
 
-    protected HandShake(WebSocketRequest request) {
-        this.incomingRequest = request;
+    static HandShake createServerHandShake(WebSocketRequest request) {
+        final HandShake handShake = new HandShake();
+
+        handShake.incomingRequest = request;
         checkForHeader(request.getFirstHeaderValue(WebSocketEngine.UPGRADE), 
WebSocketEngine.UPGRADE, "WebSocket");
         checkForHeader(request.getHeader(WebSocketEngine.CONNECTION), 
WebSocketEngine.CONNECTION, WebSocketEngine.UPGRADE);
 
-        origin = 
request.getFirstHeaderValue(WebSocketEngine.SEC_WS_ORIGIN_HEADER);
+        handShake.origin = 
request.getFirstHeaderValue(WebSocketEngine.SEC_WS_ORIGIN_HEADER);
 
-        if (origin == null) {
-            origin = 
request.getFirstHeaderValue(WebSocketEngine.ORIGIN_HEADER);
+        if (handShake.origin == null) {
+            handShake.origin = 
request.getFirstHeaderValue(WebSocketEngine.ORIGIN_HEADER);
         }
-        determineHostAndPort(request);
+        HandShake.determineHostAndPort(handShake, request);
 
         // TODO - trim?
         final String protocolHeader = 
request.getFirstHeaderValue(WebSocketEngine.SEC_WS_PROTOCOL_HEADER);
-        subProtocols = (protocolHeader == null ? 
Collections.<String>emptyList() : Arrays.asList(protocolHeader.split(",")));
+        handShake.subProtocols = (protocolHeader == null ? 
Collections.<String>emptyList() : Arrays.asList(protocolHeader.split(",")));
 
-        if (serverHostName == null) {
+        if (handShake.serverHostName == null) {
             throw new HandshakeException("Missing required headers for 
WebSocket negotiation");
         }
-        resourcePath = request.getRequestURI().toString();
+        handShake.resourcePath = request.getRequestURI().toString();
         final String queryString = request.getQueryString();
         if (queryString != null) {
             if (!queryString.isEmpty()) {
-                resourcePath += "?" + queryString;
+                handShake.resourcePath += "?" + queryString;
             }
 //            Parameters queryParameters = new Parameters();
 //            queryParameters.processParameters(queryString);
@@ -123,130 +131,21 @@ public abstract class HandShake {
 //                queryParams.put(name, 
queryParameters.getParameterValues(name));
 //            }
         }
-        buildLocation();
-    }
 
-    final void buildLocation() {
-        StringBuilder builder = new StringBuilder((isSecure() ? "wss" : 
"ws") + "://" + serverHostName);
-        appendPort(builder);
-        if (resourcePath == null || !resourcePath.startsWith("/") && 
!"".equals(resourcePath)) {
-            builder.append("/");
+        List<String> value = 
request.getHeaders().get(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER);
+        if (value != null) {
+            handShake.extensions = HandShake.fromHeaders(value);
         }
-        builder.append(resourcePath);
-        location = builder.toString();
-    }
-
-    public String getLocation() {
-        return location;
-    }
-
-    public void setLocation(String location) {
-        this.location = location;
-    }
-
-    protected String getOrigin() {
-        return origin;
-    }
-
-    public void setOrigin(String origin) {
-        this.origin = origin;
-    }
+        handShake.secKey = SecKey.generateServerKey(new 
SecKey(request.getFirstHeaderValue(WebSocketEngine.SEC_WS_KEY_HEADER)));
 
-    int getPort() {
-        return port;
-    }
-
-    void setPort(int port) {
-        this.port = port;
+        return handShake;
     }
 
-    public void setResourcePath(String resourcePath) {
-        this.resourcePath = resourcePath;
-    }
-
-    String getResourcePath() {
-        return resourcePath;
-    }
-
-    boolean isSecure() {
-        return secure;
-    }
-
-    public void setSecure(boolean secure) {
-        this.secure = secure;
-    }
-
-    String getServerHostName() {
-        return serverHostName;
-    }
-
-    void setServerHostName(String serverHostName) {
-        this.serverHostName = serverHostName;
-    }
-
-    protected List<String> getSubProtocols() {
-        return subProtocols;
-    }
-
-    protected <T> String getHeaderFromList(List<T> list) {
-        StringBuilder sb = new StringBuilder();
-        Iterator<T> it = list.iterator();
-        while (it.hasNext()) {
-            sb.append(it.next());
-            if (it.hasNext()) {
-                sb.append(", ");
-            }
-        }
-        return sb.toString();
-    }
-
-    public void setSubProtocols(List<String> subProtocols) {
-        this.subProtocols = subProtocols;
-    }
-
-    private void sanitize(List<String> strings) {
-        if (strings != null) {
-            for (int i = 0; i < strings.size(); i++) {
-                strings.set(i, strings.get(i) == null ? null : 
strings.get(i).trim());
-            }
-        }
-    }
-
-    protected List<Extension> getExtensions() {
-        return extensions;
-    }
-
-    public void setExtensions(List<Extension> extensions) {
-        this.extensions = extensions;
-    }
-
-    protected final String joinExtensions(List<Extension> extensions) {
-        StringBuilder sb = new StringBuilder();
-        for (Extension e : extensions) {
-            if (sb.length() != 0) {
-                sb.append(HEADER_SEPARATOR);
-            }
-            sb.append(e.toString());
-        }
-        return sb.toString();
-    }
-
-    protected String join(List<String> values) {
-        StringBuilder builder = new StringBuilder();
-        for (String s : values) {
-            if (builder.length() != 0) {
-                builder.append(HEADER_SEPARATOR);
-            }
-            builder.append(s);
-        }
-        return builder.toString();
-    }
-
-    private void checkForHeader(String currentValue, String header, String 
validValue) {
+    private static void checkForHeader(String currentValue, String header, 
String validValue) {
         validate(header, validValue, currentValue);
     }
 
-    private void validate(String header, String validValue, String value) {
+    private static void validate(String header, String validValue, String 
value) {
         // http://java.net/jira/browse/TYRUS-55
         // Firefox workaround (it sends "Connections: keep-alive, upgrade").
         if (header.equalsIgnoreCase(WebSocketEngine.CONNECTION)) {
@@ -260,153 +159,26 @@ public abstract class HandShake {
         }
     }
 
-    private void determineHostAndPort(WebSocketRequest request) {
+    private static void determineHostAndPort(HandShake handShake, 
WebSocketRequest request) {
         String header = request.getFirstHeaderValue(WebSocketEngine.HOST);
 
         final int i = header == null ? -1 : header.indexOf(":");
         if (i == -1) {
-            setServerHostName(header);
-            setPort(80);
-        } else {
-            setServerHostName(header.substring(0, i));
-            setPort(Integer.valueOf(header.substring(i + 1)));
-        }
-    }
-
-    /**
-     * Gets the {@link WebSocketRequest}.
-     *
-     * @return {@link WebSocketRequest} created on this HandShake.
-     */
-    public WebSocketRequest getRequest() {
-        return request;
-    }
-
-    /**
-     * Compose the {@link WebSocketRequest} and store it for further use.
-     *
-     * @return composed {@link WebSocketRequest}.
-     */
-    public WebSocketRequest prepareRequest() {
-        String host = getServerHostName();
-        if (port != -1 && port != 80 && port != 443) {
-            host += ":" + getPort();
-        }
-
-        request.setRequestPath(getResourcePath());
-        request.putSingleHeader(WebSocketEngine.HOST, host);
-        request.putSingleHeader(WebSocketEngine.CONNECTION, 
WebSocketEngine.UPGRADE);
-        request.putSingleHeader(WebSocketEngine.UPGRADE, 
WebSocketEngine.WEBSOCKET);
-
-        if (!getSubProtocols().isEmpty()) {
-            request.putSingleHeader(WebSocketEngine.SEC_WS_PROTOCOL_HEADER, 
getHeaderFromList(subProtocols));
-        }
-
-        if (!getExtensions().isEmpty()) {
-            
request.putSingleHeader(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER, 
getHeaderFromList(extensions));
-        }
-
-        return request;
-    }
-
-    public void validateServerResponse(WebSocketResponse response) {
-        if (WebSocketEngine.RESPONSE_CODE_VALUE != response.getStatus()) {
-            throw new HandshakeException(String.format("Response code was 
not %s: %s",
-                    WebSocketEngine.RESPONSE_CODE_VALUE, 
response.getStatus()));
-        }
-
-        checkForHeader(response.getHeaders().get(WebSocketEngine.UPGRADE), 
WebSocketEngine.UPGRADE, WebSocketEngine.WEBSOCKET);
-        
checkForHeader(response.getHeaders().get(WebSocketEngine.CONNECTION), 
WebSocketEngine.CONNECTION, WebSocketEngine.UPGRADE);
-
-//        if (!getSubProtocols().isEmpty()) {
-//            checkForHeader(response.getHeaders(), 
WebSocketEngine.SEC_WS_PROTOCOL_HEADER, 
WebSocketEngine.SEC_WS_PROTOCOL_HEADER);
-//        }
-    }
-
-    void respond(Connection connection, WebSocketApplication application/*, 
WebSocketResponse response*/) {
-        WebSocketResponse response = new WebSocketResponse();
-        response.setStatus(101);
-
-        response.getHeaders().put(WebSocketEngine.UPGRADE, 
WebSocketEngine.WEBSOCKET);
-        response.getHeaders().put(WebSocketEngine.CONNECTION, 
WebSocketEngine.UPGRADE);
-        setHeaders(response);
-
-        if (subProtocols != null && !subProtocols.isEmpty()) {
-            List<String> appProtocols = 
application.getSupportedProtocols(subProtocols);
-            if (!appProtocols.isEmpty()) {
-                
response.getHeaders().put(WebSocketEngine.SEC_WS_PROTOCOL_HEADER, 
getHeaderFromList(appProtocols));
-            }
-        }
-        if (!application.getSupportedExtensions().isEmpty() && 
!getExtensions().isEmpty()) {
-            List<Extension> intersection =
-                    intersection(getExtensions(),
-                            application.getSupportedExtensions());
-            if (!intersection.isEmpty()) {
-                application.onExtensionNegotiation(intersection);
-                
response.getHeaders().put(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER, 
getHeaderFromList(intersection));
-            }
-        }
-
-        application.onHandShakeResponse(incomingRequest, response);
-
-        connection.write(response);
-    }
-
-
-    protected abstract void setHeaders(WebSocketResponse response);
-
-    protected final List<String> split(final String header) {
-        if (header == null) {
-            return Collections.emptyList();
+            handShake.serverHostName = header;
+            handShake.port = 80;
         } else {
-            final List<String> list = Arrays.asList(header.split(","));
-            sanitize(list);
-            return list;
+            handShake.serverHostName = header.substring(0, i);
+            handShake.port = Integer.valueOf(header.substring(i + 1));
         }
     }
 
-    List<Extension> intersection(List<Extension> requested, List<Extension> 
supported) {
-        List<Extension> intersection = new 
ArrayList<Extension>(supported.size());
-        for (Extension e : requested) {
-            for (Extension s : supported) {
-                if (e.getName().equals(s.getName())) {
-                    intersection.add(e);
-                    break;
-                }
-            }
-        }
-        return intersection;
-    }
-
-    /**
-     * Parsing of one {@link Extension}.
-     *
-     * @param s {@link String} containing {@link Extension}.
-     * @return extension represented as {@link Extension}.
-     */
-    public static List<Extension> fromString(String s) {
-        return fromHeaders(Arrays.asList(s));
-    }
-
-    private enum ParserState {
-        NAME_START,
-        NAME,
-        PARAM_NAME,
-        PARAM_VALUE,
-        PARAM_VALUE_QUOTED,
-        PARAM_VALUE_QUOTED_POST,
-        // quoted-pair - '\' escaped character
-        PARAM_VALUE_QUOTED_QP,
-        ERROR
-    }
-
     /**
      * Parse {@link Extension} from headers (represented as {@link List} of 
strings).
      *
      * @param extensionHeaders Http Extension headers.
      * @return list of parsed {@link Extension Extensions}.
      */
-    protected static List<Extension> fromHeaders(List<String> 
extensionHeaders) {
+    private static List<Extension> fromHeaders(List<String> 
extensionHeaders) {
         List<Extension> extensions = new ArrayList<Extension>();
 
         for (String singleHeader : extensionHeaders) {
@@ -586,13 +358,8 @@ public abstract class HandShake {
         return extensions;
     }
 
-
-    public WebSocketRequest initiate(/*FilterChainContext ctx*/) {
-        return request;
-    }
-
-    private StringBuilder appendPort(StringBuilder builder) {
-        if (isSecure()) {
+    private static StringBuilder appendPort(StringBuilder builder, int port, 
boolean secure) {
+        if (secure) {
             if (port != 443 && port != -1) {
                 builder.append(':').append(port);
             }
@@ -604,14 +371,167 @@ public abstract class HandShake {
         return builder;
     }
 
+    String getOrigin() {
+        return origin;
+    }
+
+    int getPort() {
+        return port;
+    }
+
+    void setPort(int port) {
+        this.port = port;
+    }
+
+    String getResourcePath() {
+        return resourcePath;
+    }
+
+    String getServerHostName() {
+        return serverHostName;
+    }
+
+    List<String> getSubProtocols() {
+        return subProtocols;
+    }
+
+    public void setSubProtocols(List<String> subProtocols) {
+        this.subProtocols = subProtocols;
+    }
+
+    <T> String getHeaderFromList(List<T> list) {
+        StringBuilder sb = new StringBuilder();
+        Iterator<T> it = list.iterator();
+        while (it.hasNext()) {
+            sb.append(it.next());
+            if (it.hasNext()) {
+                sb.append(", ");
+            }
+        }
+        return sb.toString();
+    }
+
+    List<Extension> getExtensions() {
+        return extensions;
+    }
+
+    public void setExtensions(List<Extension> extensions) {
+        this.extensions = extensions;
+    }
+
     /**
-     * Set response listener.
+     * Gets the {@link WebSocketRequest}.
      *
-     * @param responseListener {@link 
HandShakeResponseListener#onResponseHeaders(java.util.Map)} will be called 
when
-     *                         response is ready and validated.
+     * @return {@link WebSocketRequest} created on this HandShake.
      */
-    public void setResponseListener(HandShakeResponseListener 
responseListener) {
-        this.responseListener = responseListener;
+    public WebSocketRequest getRequest() {
+        return request;
+    }
+
+    /**
+     * Compose the {@link WebSocketRequest} and store it for further use.
+     *
+     * @return composed {@link WebSocketRequest}.
+     */
+    public WebSocketRequest prepareRequest() {
+        String host = getServerHostName();
+        if (port != -1 && port != 80 && port != 443) {
+            host += ":" + getPort();
+        }
+
+        request.setRequestPath(getResourcePath());
+        request.putSingleHeader(WebSocketEngine.HOST, host);
+        request.putSingleHeader(WebSocketEngine.CONNECTION, 
WebSocketEngine.UPGRADE);
+        request.putSingleHeader(WebSocketEngine.UPGRADE, 
WebSocketEngine.WEBSOCKET);
+
+        if (!getSubProtocols().isEmpty()) {
+            request.putSingleHeader(WebSocketEngine.SEC_WS_PROTOCOL_HEADER, 
getHeaderFromList(subProtocols));
+        }
+
+        if (!getExtensions().isEmpty()) {
+            
request.putSingleHeader(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER, 
getHeaderFromList(extensions));
+        }
+
+        request.putSingleHeader(WebSocketEngine.SEC_WS_KEY_HEADER, 
secKey.toString());
+        request.putSingleHeader(WebSocketEngine.SEC_WS_ORIGIN_HEADER, 
getOrigin());
+        request.putSingleHeader(WebSocketEngine.SEC_WS_VERSION, getVersion() 
+ "");
+        if (!getExtensions().isEmpty()) {
+            
request.putSingleHeader(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER, 
getHeaderFromList(getExtensions()));
+        }
+        final String headerValue = 
request.getFirstHeaderValue(WebSocketEngine.SEC_WS_ORIGIN_HEADER);
+        request.getHeaders().remove(WebSocketEngine.SEC_WS_ORIGIN_HEADER);
+        request.putSingleHeader(WebSocketEngine.ORIGIN_HEADER, headerValue);
+        return request;
+    }
+
+    public void validateServerResponse(WebSocketResponse response) {
+        if (WebSocketEngine.RESPONSE_CODE_VALUE != response.getStatus()) {
+            throw new HandshakeException(String.format("Response code was 
not %s: %s",
+                    WebSocketEngine.RESPONSE_CODE_VALUE, 
response.getStatus()));
+        }
+
+        checkForHeader(response.getHeaders().get(WebSocketEngine.UPGRADE), 
WebSocketEngine.UPGRADE, WebSocketEngine.WEBSOCKET);
+        
checkForHeader(response.getHeaders().get(WebSocketEngine.CONNECTION), 
WebSocketEngine.CONNECTION, WebSocketEngine.UPGRADE);
+
+//        if (!getSubProtocols().isEmpty()) {
+//            checkForHeader(response.getHeaders(), 
WebSocketEngine.SEC_WS_PROTOCOL_HEADER, 
WebSocketEngine.SEC_WS_PROTOCOL_HEADER);
+//        }
+
+        
secKey.validateServerKey(response.getHeaders().get(WebSocketEngine.SEC_WS_ACCEPT));
+    }
+
+    void respond(Connection connection, WebSocketApplication application/*, 
WebSocketResponse response*/) {
+        WebSocketResponse response = new WebSocketResponse();
+        response.setStatus(101);
+
+        response.getHeaders().put(WebSocketEngine.UPGRADE, 
WebSocketEngine.WEBSOCKET);
+        response.getHeaders().put(WebSocketEngine.CONNECTION, 
WebSocketEngine.UPGRADE);
+        setHeaders(response);
+
+        if (subProtocols != null && !subProtocols.isEmpty()) {
+            List<String> appProtocols = 
application.getSupportedProtocols(subProtocols);
+            if (!appProtocols.isEmpty()) {
+                
response.getHeaders().put(WebSocketEngine.SEC_WS_PROTOCOL_HEADER, 
getHeaderFromList(appProtocols));
+            }
+        }
+        if (!application.getSupportedExtensions().isEmpty() && 
!getExtensions().isEmpty()) {
+            List<Extension> intersection =
+                    intersection(getExtensions(),
+                            application.getSupportedExtensions());
+            if (!intersection.isEmpty()) {
+                application.onExtensionNegotiation(intersection);
+                
response.getHeaders().put(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER, 
getHeaderFromList(intersection));
+            }
+        }
+
+        application.onHandShakeResponse(incomingRequest, response);
+
+        connection.write(response);
+    }
+
+    void setHeaders(WebSocketResponse response) {
+        response.setReasonPhrase(WebSocketEngine.RESPONSE_CODE_MESSAGE);
+        response.getHeaders().put(WebSocketEngine.SEC_WS_ACCEPT, 
secKey.getSecKey());
+        if (!getEnabledExtensions().isEmpty()) {
+            
response.getHeaders().put(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER, 
getHeaderFromList(getSubProtocols()));
+        }
+    }
+
+    List<Extension> intersection(List<Extension> requested, List<Extension> 
supported) {
+        List<Extension> intersection = new 
ArrayList<Extension>(supported.size());
+        for (Extension e : requested) {
+            for (Extension s : supported) {
+                if (e.getName().equals(s.getName())) {
+                    intersection.add(e);
+                    break;
+                }
+            }
+        }
+        return intersection;
+    }
+
+    public WebSocketRequest initiate(/*FilterChainContext ctx*/) {
+        return request;
     }
 
     /**
@@ -624,6 +544,36 @@ public abstract class HandShake {
     }
 
     /**
+     * Set response listener.
+     *
+     * @param responseListener {@link 
HandShakeResponseListener#onResponseHeaders(java.util.Map)} will be called 
when
+     *                         response is ready and validated.
+     */
+    public void setResponseListener(HandShakeResponseListener 
responseListener) {
+        this.responseListener = responseListener;
+    }
+
+    List<String> getEnabledExtensions() {
+        return enabledExtensions;
+    }
+
+    int getVersion() {
+        return 13;
+    }
+
+    private enum ParserState {
+        NAME_START,
+        NAME,
+        PARAM_NAME,
+        PARAM_VALUE,
+        PARAM_VALUE_QUOTED,
+        PARAM_VALUE_QUOTED_POST,
+        // quoted-pair - '\' escaped character
+        PARAM_VALUE_QUOTED_QP,
+        ERROR
+    }
+
+    /**
      * Used to register with {@link HandShake}. If the handshake response is 
received, this listener is called.
      *
      * @author Stepan Kopriva (stepan.kopriva at oracle.com)
@@ -637,7 +587,6 @@ public abstract class HandShake {
          */
         public void onResponseHeaders(Map<String, String> headers);
 
-
         /**
          * Called when an error is found in handshake response.
          *--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Masker.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/Masker.java
@@ -43,7 +43,7 @@ package org.glassfish.tyrus.websockets;
 import java.nio.ByteBuffer;
 import java.security.SecureRandom;
 
-public class Masker {
+class Masker {
     private volatile ByteBuffer buffer;
     private byte[] mask;
     private int index = 0;
@@ -56,21 +56,16 @@ public class Masker {
         generateMask();
     }
 
-    public byte get() {
+    byte get() {
         return buffer.get();
     }
 
-    public byte[] get(final int size) {
+    byte[] get(final int size) {
         byte[] bytes = new byte[size];
         buffer.get(bytes);
         return bytes;
     }
 
-    public byte unmask() {
-        final byte b = get();
-        return mask == null ? b : (byte) (b ^ mask[index++ % 
WebSocketEngine.MASK_SIZE]);
-    }
-
     public byte[] unmask(int count) {
         byte[] bytes = get(count);
         if (mask != null) {
@@ -82,15 +77,11 @@ public class Masker {
         return bytes;
     }
 
-    public void generateMask() {
+    void generateMask() {
         mask = new byte[WebSocketEngine.MASK_SIZE];
         new SecureRandom().nextBytes(mask);
     }
 
-    public void mask(byte[] bytes, int location, byte b) {
-        bytes[location] = mask == null ? b : (byte) (b ^ mask[index++ % 
WebSocketEngine.MASK_SIZE]);
-    }
-
     public void mask(byte[] target, int location, byte[] bytes) {
         if (bytes != null && target != null) {
             for (int i = 0; i < bytes.length; i++) {
@@ -101,18 +92,10 @@ public class Masker {
         }
     }
 
-    public byte[] maskAndPrepend(byte[] packet) {
-        byte[] masked = new byte[packet.length + WebSocketEngine.MASK_SIZE];
-        System.arraycopy(getMask(), 0, masked, 0, WebSocketEngine.MASK_SIZE);
-        mask(masked, WebSocketEngine.MASK_SIZE, packet);
-        return masked;
-    }
-
     public void setBuffer(ByteBuffer buffer) {
         this.buffer = buffer;
     }
 
-
     public byte[] getMask() {
         return mask;
     }--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ParseResult.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ParseResult.java
@@ -44,12 +44,13 @@ import java.nio.ByteBuffer;
 
 /**
  * {@link DataFrame} parse result.
- *
+ * <p/>
  * TODO: cache (see original grizzly impl)?
  *
  * @author Alexey Stashok
  */
 public class ParseResult /*implements Cacheable*/ {
+
     private boolean isComplete;
     // remainder buffer (might not be null only if parsing was completed).
     private ByteBuffer remainder;--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ProtocolError.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ProtocolError.java
@@ -42,7 +42,6 @@ package org.glassfish.tyrus.websockets;
 
 /**
  * TODO
- *
  */
 public class ProtocolError extends FramingException {
 
@@ -50,14 +49,6 @@ public class ProtocolError extends FramingException {
         super(s);
     }
 
-    public ProtocolError(String s, Throwable throwable) {
-        super(s, throwable);
-    }
-
-    public ProtocolError(Throwable throwable) {
-        super(throwable);
-    }
-
     @Override
     public int getClosingCode() {
         return WebSocket.PROTOCOL_ERROR;--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ProtocolHandler.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/ProtocolHandler.java
@@ -46,6 +46,7 @@ import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.util.Arrays;
+import java.util.Locale;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
@@ -55,27 +56,31 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.websocket.WebSocketContainer;
 
-import org.glassfish.tyrus.websockets.draft06.ClosingFrame;
-import org.glassfish.tyrus.websockets.frametypes.BinaryFrameType;
-import org.glassfish.tyrus.websockets.frametypes.TextFrameType;
+import org.glassfish.tyrus.websockets.frame.BinaryFrame;
+import org.glassfish.tyrus.websockets.frame.ClosingFrame;
+import org.glassfish.tyrus.websockets.frame.ContinuationFrame;
+import org.glassfish.tyrus.websockets.frame.Frame;
+import org.glassfish.tyrus.websockets.frame.PingFrame;
+import org.glassfish.tyrus.websockets.frame.PongFrame;
+import org.glassfish.tyrus.websockets.frame.TextFrame;
 
-public abstract class ProtocolHandler {
+public final class ProtocolHandler {
 
     private final Charset utf8 = new StrictUtf8();
     private final CharsetDecoder currentDecoder = utf8.newDecoder();
-    private WebSocket webSocket;
     private final AtomicBoolean onClosedCalled = new AtomicBoolean(false);
+    private final boolean maskData;
+    private final ParsingState state = new ParsingState();
+    private WebSocket webSocket;
     private byte outFragmentedType;
     private ByteBuffer remainder;
     private long writeTimeoutMs = -1;
     private WebSocketContainer container;
+    private Connection connection;
+    private byte inFragmentedType;
+    private boolean processingFragment;
 
-    protected final boolean maskData;
-    protected Connection connection;
-    protected byte inFragmentedType;
-    protected boole
[truncated due to length]



[tyrus~code:e0505652] TYRUS-234: Removed support for deprecated protocol versions.

jerseyrobot 08/12/2013
 
 
Close
loading
Please Confirm
Close