@Test public void testInvalidSpecificationVersionsShouldReturnNull() throws Exception { HttpRequestMessage request = new HttpRequestMessage(); request.addHeader(WsUtils.SEC_WEB_SOCKET_VERSION, String.valueOf(-10)); WebSocketWireProtocol protocol = WsUtils.guessWireProtocolVersion(request); assertNull(protocol); request = new HttpRequestMessage(); request.addHeader(WsUtils.SEC_WEB_SOCKET_VERSION, String.valueOf(500)); protocol = WsUtils.guessWireProtocolVersion(request); assertNull(protocol); }
public static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest) { String httpRequestVersionHeader = httpRequest.getHeader(SEC_WEB_SOCKET_VERSION); if ( httpRequestVersionHeader == null || httpRequestVersionHeader.length() == 0) { if ( httpRequest.getHeader(SEC_WEB_SOCKET_KEY1) != null && httpRequest.getHeader(SEC_WEB_SOCKET_KEY2) != null ) { return WebSocketWireProtocol.HIXIE_76; } else { return WebSocketWireProtocol.HIXIE_75; } } else { try { return WebSocketWireProtocol.valueOf(Integer.parseInt(httpRequestVersionHeader)); } catch (NumberFormatException e) { return null; } } }
WsUtils { public static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest) { String httpRequestVersionHeader = httpRequest.getHeader(SEC_WEB_SOCKET_VERSION); if ( httpRequestVersionHeader == null || httpRequestVersionHeader.length() == 0) { if ( httpRequest.getHeader(SEC_WEB_SOCKET_KEY1) != null && httpRequest.getHeader(SEC_WEB_SOCKET_KEY2) != null ) { return WebSocketWireProtocol.HIXIE_76; } else { return WebSocketWireProtocol.HIXIE_75; } } else { try { return WebSocketWireProtocol.valueOf(Integer.parseInt(httpRequestVersionHeader)); } catch (NumberFormatException e) { return null; } } } }
WsUtils { public static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest) { String httpRequestVersionHeader = httpRequest.getHeader(SEC_WEB_SOCKET_VERSION); if ( httpRequestVersionHeader == null || httpRequestVersionHeader.length() == 0) { if ( httpRequest.getHeader(SEC_WEB_SOCKET_KEY1) != null && httpRequest.getHeader(SEC_WEB_SOCKET_KEY2) != null ) { return WebSocketWireProtocol.HIXIE_76; } else { return WebSocketWireProtocol.HIXIE_75; } } else { try { return WebSocketWireProtocol.valueOf(Integer.parseInt(httpRequestVersionHeader)); } catch (NumberFormatException e) { return null; } } } private  WsUtils(); }
WsUtils { public static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest) { String httpRequestVersionHeader = httpRequest.getHeader(SEC_WEB_SOCKET_VERSION); if ( httpRequestVersionHeader == null || httpRequestVersionHeader.length() == 0) { if ( httpRequest.getHeader(SEC_WEB_SOCKET_KEY1) != null && httpRequest.getHeader(SEC_WEB_SOCKET_KEY2) != null ) { return WebSocketWireProtocol.HIXIE_76; } else { return WebSocketWireProtocol.HIXIE_75; } } else { try { return WebSocketWireProtocol.valueOf(Integer.parseInt(httpRequestVersionHeader)); } catch (NumberFormatException e) { return null; } } } private  WsUtils(); static void addExtensionFilters(List<WebSocketExtension> extensions,
                                           ExtensionHelper helper,
                                           IoFilterChain filterChain,
                                           boolean hasCodec); static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3); static String acceptHash(String key); static int calculateEncodedLengthSize(int lengthValue); static void encodeLength(ByteBuffer buf, int lengthValue); static void handleExtensionNegotiationException(HttpAcceptSession session, List<String> clientRequestedExtensions,
                                                            ProtocolException e, Logger logger); static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest); static List<WebSocketExtension> negotiateExtensionsAndSetResponseHeader(
                                                        WebSocketExtensionFactory factory,
                                                        WsResourceAddress address,
                                                        List<String> requestedExtensions,
                                                        HttpAcceptSession session,
                                                        String extendionsHeaderName, ExtensionHelper extensionHelper); static String negotiateWebSocketProtocol(HttpAcceptSession session, String protocolHeaderName,
                                                    List<String> clientRequestedWsProtocols,
                                                    List<String> serverWsProtocols); static void removeExtensionFilters(List<WebSocketExtension> extensions, IoFilterChain filterChain); static String secWebSocketKey(); }
WsUtils { public static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest) { String httpRequestVersionHeader = httpRequest.getHeader(SEC_WEB_SOCKET_VERSION); if ( httpRequestVersionHeader == null || httpRequestVersionHeader.length() == 0) { if ( httpRequest.getHeader(SEC_WEB_SOCKET_KEY1) != null && httpRequest.getHeader(SEC_WEB_SOCKET_KEY2) != null ) { return WebSocketWireProtocol.HIXIE_76; } else { return WebSocketWireProtocol.HIXIE_75; } } else { try { return WebSocketWireProtocol.valueOf(Integer.parseInt(httpRequestVersionHeader)); } catch (NumberFormatException e) { return null; } } } private  WsUtils(); static void addExtensionFilters(List<WebSocketExtension> extensions,
                                           ExtensionHelper helper,
                                           IoFilterChain filterChain,
                                           boolean hasCodec); static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3); static String acceptHash(String key); static int calculateEncodedLengthSize(int lengthValue); static void encodeLength(ByteBuffer buf, int lengthValue); static void handleExtensionNegotiationException(HttpAcceptSession session, List<String> clientRequestedExtensions,
                                                            ProtocolException e, Logger logger); static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest); static List<WebSocketExtension> negotiateExtensionsAndSetResponseHeader(
                                                        WebSocketExtensionFactory factory,
                                                        WsResourceAddress address,
                                                        List<String> requestedExtensions,
                                                        HttpAcceptSession session,
                                                        String extendionsHeaderName, ExtensionHelper extensionHelper); static String negotiateWebSocketProtocol(HttpAcceptSession session, String protocolHeaderName,
                                                    List<String> clientRequestedWsProtocols,
                                                    List<String> serverWsProtocols); static void removeExtensionFilters(List<WebSocketExtension> extensions, IoFilterChain filterChain); static String secWebSocketKey(); static final String SEC_WEB_SOCKET_VERSION; static final String SEC_WEB_SOCKET_KEY; static final String SEC_WEB_SOCKET_KEY1; static final String SEC_WEB_SOCKET_KEY2; static final String HEADER_X_WEBSOCKET_EXTENSIONS; static final String HEADER_WEBSOCKET_EXTENSIONS; static final String HEADER_SEC_WEBSOCKET_EXTENSIONS; static final TypedAttributeKey<List<WebSocketExtension>> ACTIVE_EXTENSIONS_KEY; }