@Test public void shouldNegotiateOnlyExistingxtensions() throws ProtocolException { List<String> clientRequestedExtensions = new ArrayList<>(); clientRequestedExtensions.add("not-there"); clientRequestedExtensions.add("mock"); clientRequestedExtensions.add("not-there2"); context.checking(new Expectations() { { oneOf(mockNegotiate).negotiate(with(new ExtensionHeaderTokenMatcher("mock")), with(address)); will(returnValue(webSocketExtensionSpi)); } }); List<WebSocketExtension> ActiveWebSocketExtensions = wsExtFactory.negotiateWebSocketExtensions(address, clientRequestedExtensions, extensionHelper); assertSame(webSocketExtensionSpi, ActiveWebSocketExtensions.get(0)); assertEquals(1, ActiveWebSocketExtensions.size()); }
public List<WebSocketExtension> negotiateWebSocketExtensions(WsResourceAddress address, List<String> clientRequestedExtensions, ExtensionHelper extensionHelper) throws ProtocolException { List<WebSocketExtension> result = Collections.emptyList(); if (clientRequestedExtensions != null) { List<ExtensionHeader> requestedExtensions = toWsExtensions(clientRequestedExtensions); LinkedList<WebSocketExtension> acceptedExtensions = new LinkedList<>(); for(Set<ExtensionHeader> extensionHeaders: extensionHeadersByCategory.values()){ for (ExtensionHeader candidate : requestedExtensions) { if(extensionHeaders.contains(candidate)){ WebSocketExtensionFactorySpi extension = factoriesRO.get(candidate.getExtensionToken()); WebSocketExtension acceptedExtension = extension.negotiate(candidate, extensionHelper, address); if (acceptedExtension != null) { acceptedExtensions.add(acceptedExtension); } } } } result = Collections.unmodifiableList(acceptedExtensions); } return result; }
WebSocketExtensionFactory { public List<WebSocketExtension> negotiateWebSocketExtensions(WsResourceAddress address, List<String> clientRequestedExtensions, ExtensionHelper extensionHelper) throws ProtocolException { List<WebSocketExtension> result = Collections.emptyList(); if (clientRequestedExtensions != null) { List<ExtensionHeader> requestedExtensions = toWsExtensions(clientRequestedExtensions); LinkedList<WebSocketExtension> acceptedExtensions = new LinkedList<>(); for(Set<ExtensionHeader> extensionHeaders: extensionHeadersByCategory.values()){ for (ExtensionHeader candidate : requestedExtensions) { if(extensionHeaders.contains(candidate)){ WebSocketExtensionFactorySpi extension = factoriesRO.get(candidate.getExtensionToken()); WebSocketExtension acceptedExtension = extension.negotiate(candidate, extensionHelper, address); if (acceptedExtension != null) { acceptedExtensions.add(acceptedExtension); } } } } result = Collections.unmodifiableList(acceptedExtensions); } return result; } }
WebSocketExtensionFactory { public List<WebSocketExtension> negotiateWebSocketExtensions(WsResourceAddress address, List<String> clientRequestedExtensions, ExtensionHelper extensionHelper) throws ProtocolException { List<WebSocketExtension> result = Collections.emptyList(); if (clientRequestedExtensions != null) { List<ExtensionHeader> requestedExtensions = toWsExtensions(clientRequestedExtensions); LinkedList<WebSocketExtension> acceptedExtensions = new LinkedList<>(); for(Set<ExtensionHeader> extensionHeaders: extensionHeadersByCategory.values()){ for (ExtensionHeader candidate : requestedExtensions) { if(extensionHeaders.contains(candidate)){ WebSocketExtensionFactorySpi extension = factoriesRO.get(candidate.getExtensionToken()); WebSocketExtension acceptedExtension = extension.negotiate(candidate, extensionHelper, address); if (acceptedExtension != null) { acceptedExtensions.add(acceptedExtension); } } } } result = Collections.unmodifiableList(acceptedExtensions); } return result; } private  WebSocketExtensionFactory(Map<String, WebSocketExtensionFactorySpi> factoriesRO); }
WebSocketExtensionFactory { public List<WebSocketExtension> negotiateWebSocketExtensions(WsResourceAddress address, List<String> clientRequestedExtensions, ExtensionHelper extensionHelper) throws ProtocolException { List<WebSocketExtension> result = Collections.emptyList(); if (clientRequestedExtensions != null) { List<ExtensionHeader> requestedExtensions = toWsExtensions(clientRequestedExtensions); LinkedList<WebSocketExtension> acceptedExtensions = new LinkedList<>(); for(Set<ExtensionHeader> extensionHeaders: extensionHeadersByCategory.values()){ for (ExtensionHeader candidate : requestedExtensions) { if(extensionHeaders.contains(candidate)){ WebSocketExtensionFactorySpi extension = factoriesRO.get(candidate.getExtensionToken()); WebSocketExtension acceptedExtension = extension.negotiate(candidate, extensionHelper, address); if (acceptedExtension != null) { acceptedExtensions.add(acceptedExtension); } } } } result = Collections.unmodifiableList(acceptedExtensions); } return result; } private  WebSocketExtensionFactory(Map<String, WebSocketExtensionFactorySpi> factoriesRO); Collection<WebSocketExtensionFactorySpi> availableExtensions(); List<WebSocketExtension> negotiateWebSocketExtensions(WsResourceAddress address,
                                                                 List<String> clientRequestedExtensions,
                                                                 ExtensionHelper extensionHelper); List<WebSocketExtension> offerWebSocketExtensions(WsResourceAddress address,
                                                             ExtensionHelper extensionHelper); static WebSocketExtensionFactory newInstance(); static WebSocketExtensionFactory newInstance(ClassLoader cl); }
WebSocketExtensionFactory { public List<WebSocketExtension> negotiateWebSocketExtensions(WsResourceAddress address, List<String> clientRequestedExtensions, ExtensionHelper extensionHelper) throws ProtocolException { List<WebSocketExtension> result = Collections.emptyList(); if (clientRequestedExtensions != null) { List<ExtensionHeader> requestedExtensions = toWsExtensions(clientRequestedExtensions); LinkedList<WebSocketExtension> acceptedExtensions = new LinkedList<>(); for(Set<ExtensionHeader> extensionHeaders: extensionHeadersByCategory.values()){ for (ExtensionHeader candidate : requestedExtensions) { if(extensionHeaders.contains(candidate)){ WebSocketExtensionFactorySpi extension = factoriesRO.get(candidate.getExtensionToken()); WebSocketExtension acceptedExtension = extension.negotiate(candidate, extensionHelper, address); if (acceptedExtension != null) { acceptedExtensions.add(acceptedExtension); } } } } result = Collections.unmodifiableList(acceptedExtensions); } return result; } private  WebSocketExtensionFactory(Map<String, WebSocketExtensionFactorySpi> factoriesRO); Collection<WebSocketExtensionFactorySpi> availableExtensions(); List<WebSocketExtension> negotiateWebSocketExtensions(WsResourceAddress address,
                                                                 List<String> clientRequestedExtensions,
                                                                 ExtensionHelper extensionHelper); List<WebSocketExtension> offerWebSocketExtensions(WsResourceAddress address,
                                                             ExtensionHelper extensionHelper); static WebSocketExtensionFactory newInstance(); static WebSocketExtensionFactory newInstance(ClassLoader cl);  }