@Test public void shouldAddExtensionFiltersAtStartWhenNoCodec() throws Exception { AbstractIoSession session = new DummySessionEx(); final IoFilter filter1 = context.mock(IoFilter.class, "filter1"); final IoFilter filter2 = context.mock(IoFilter.class, "filter2"); final ExtensionHelper helper = context.mock(ExtensionHelper.class, "helper"); final IoFilterChain filterChain = new DefaultIoFilterChain(session); context.checking(new Expectations() { { oneOf(filter1).onPreAdd(with(filterChain), with(any(String.class)), with(any(NextFilter.class))); oneOf(filter1).onPostAdd(with(filterChain), with(any(String.class)), with(any(NextFilter.class))); oneOf(filter2).onPreAdd(with(filterChain), with(any(String.class)), with(any(NextFilter.class))); oneOf(filter2).onPostAdd(with(filterChain), with(any(String.class)), with(any(NextFilter.class))); oneOf(extension1).getFilter(); will(returnValue((null))); oneOf(extension2).getFilter(); will(returnValue((extensionFilter2))); oneOf(extension2).getExtensionHeader(); will(returnValue(extensionHeader2)); oneOf(extensionFilter2).onPreAdd(with(filterChain), with(any(String.class)), with(any(NextFilter.class))); oneOf(extensionFilter2).onPostAdd(with(filterChain), with(any(String.class)), with(any(NextFilter.class))); oneOf(extensionFilter3).onPreAdd(with(filterChain), with(any(String.class)), with(any(NextFilter.class))); oneOf(extensionFilter3).onPostAdd(with(filterChain), with(any(String.class)), with(any(NextFilter.class))); oneOf(extension3).getFilter(); will(returnValue((extensionFilter3))); oneOf(extension3).getExtensionHeader(); will(returnValue(extensionHeader3)); oneOf(extensionHeader2).getExtensionToken(); will(returnValue(("extension2"))); oneOf(extensionHeader3).getExtensionToken(); will(returnValue(("extension3"))); } }); filterChain.addLast("filter1", filter1); filterChain.addLast("filter2", filter2); WsUtils.addExtensionFilters(extensions, helper, filterChain, false); String[] expected = new String[]{"extension3", "extension2", "filter1", "filter2"}; int i = 0; for (Entry entry : filterChain.getAll()) { assertEquals(expected[i++], entry.getName()); } context.assertIsSatisfied(); }
public static void addExtensionFilters(List<WebSocketExtension> extensions, ExtensionHelper helper, IoFilterChain filterChain, boolean hasCodec) { if (hasCodec) { addExtensionFiltersAfterCodec(extensions, helper, filterChain); } else { for (WebSocketExtension extension: extensions) { IoFilter filter; if ((filter = extension.getFilter()) != null) { filterChain.addFirst(extension.getExtensionHeader().getExtensionToken(), filter); } } } }
WsUtils { public static void addExtensionFilters(List<WebSocketExtension> extensions, ExtensionHelper helper, IoFilterChain filterChain, boolean hasCodec) { if (hasCodec) { addExtensionFiltersAfterCodec(extensions, helper, filterChain); } else { for (WebSocketExtension extension: extensions) { IoFilter filter; if ((filter = extension.getFilter()) != null) { filterChain.addFirst(extension.getExtensionHeader().getExtensionToken(), filter); } } } } }
WsUtils { public static void addExtensionFilters(List<WebSocketExtension> extensions, ExtensionHelper helper, IoFilterChain filterChain, boolean hasCodec) { if (hasCodec) { addExtensionFiltersAfterCodec(extensions, helper, filterChain); } else { for (WebSocketExtension extension: extensions) { IoFilter filter; if ((filter = extension.getFilter()) != null) { filterChain.addFirst(extension.getExtensionHeader().getExtensionToken(), filter); } } } } private  WsUtils(); }
WsUtils { public static void addExtensionFilters(List<WebSocketExtension> extensions, ExtensionHelper helper, IoFilterChain filterChain, boolean hasCodec) { if (hasCodec) { addExtensionFiltersAfterCodec(extensions, helper, filterChain); } else { for (WebSocketExtension extension: extensions) { IoFilter filter; if ((filter = extension.getFilter()) != null) { filterChain.addFirst(extension.getExtensionHeader().getExtensionToken(), filter); } } } } 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 void addExtensionFilters(List<WebSocketExtension> extensions, ExtensionHelper helper, IoFilterChain filterChain, boolean hasCodec) { if (hasCodec) { addExtensionFiltersAfterCodec(extensions, helper, filterChain); } else { for (WebSocketExtension extension: extensions) { IoFilter filter; if ((filter = extension.getFilter()) != null) { filterChain.addFirst(extension.getExtensionHeader().getExtensionToken(), filter); } } } } 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; }