javax.websocket.Extension Java Examples
The following examples show how to use
javax.websocket.Extension.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUtil.java From tomcatsrc with Apache License 2.0 | 6 votes |
private void doTestParseExtensionHeaderSimple(String header) { // Simple test List<Extension> result = new ArrayList<Extension>(); Util.parseExtensionHeader(result, header); Assert.assertEquals(1, result.size()); Extension ext = result.get(0); Assert.assertEquals("ext", ext.getName()); List<Parameter> params = ext.getParameters(); Assert.assertEquals(2, params.size()); Parameter paramA = params.get(0); Assert.assertEquals("a", paramA.getName()); Assert.assertEquals("1", paramA.getValue()); Parameter paramB = params.get(1); Assert.assertEquals("b", paramB.getName()); Assert.assertEquals("2", paramB.getValue()); }
Example #2
Source File: WebSphereRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void upgradeInternal(ServerHttpRequest httpRequest, ServerHttpResponse httpResponse, String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest request = getHttpServletRequest(httpRequest); HttpServletResponse response = getHttpServletResponse(httpResponse); StringBuffer requestUrl = request.getRequestURL(); String path = request.getRequestURI(); // shouldn't matter Map<String, String> pathParams = Collections.<String, String> emptyMap(); ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol)); endpointConfig.setExtensions(selectedExtensions); try { ServerContainer container = getContainer(request); upgradeMethod.invoke(container, request, response, endpointConfig, pathParams); } catch (Exception ex) { throw new HandshakeFailureException( "Servlet request failed to upgrade to WebSocket for " + requestUrl, ex); } }
Example #3
Source File: WebSphereRequestUpgradeStrategy.java From spring-analysis-note with MIT License | 6 votes |
@Override public void upgradeInternal(ServerHttpRequest httpRequest, ServerHttpResponse httpResponse, @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest request = getHttpServletRequest(httpRequest); HttpServletResponse response = getHttpServletResponse(httpResponse); StringBuffer requestUrl = request.getRequestURL(); String path = request.getRequestURI(); // shouldn't matter Map<String, String> pathParams = Collections.<String, String> emptyMap(); ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol)); endpointConfig.setExtensions(selectedExtensions); try { ServerContainer container = getContainer(request); upgradeMethod.invoke(container, request, response, endpointConfig, pathParams); } catch (Exception ex) { throw new HandshakeFailureException( "Servlet request failed to upgrade to WebSocket for " + requestUrl, ex); } }
Example #4
Source File: DefaultServerEndpointConfig.java From lams with GNU General Public License v2.0 | 6 votes |
DefaultServerEndpointConfig(Class<?> endpointClass, String path, List<String> subprotocols, List<Extension> extensions, List<Class<? extends Encoder>> encoders, List<Class<? extends Decoder>> decoders, ServerEndpointConfig.Configurator serverEndpointConfigurator) { this.path = path; this.endpointClass = endpointClass; this.subprotocols = Collections.unmodifiableList(subprotocols); this.extensions = Collections.unmodifiableList(extensions); this.encoders = Collections.unmodifiableList(encoders); this.decoders = Collections.unmodifiableList(decoders); if (serverEndpointConfigurator == null) { this.serverEndpointConfigurator = ServerEndpointConfig.Configurator.fetchContainerDefaultConfigurator(); } else{ this.serverEndpointConfigurator = serverEndpointConfigurator; } }
Example #5
Source File: StandardWebSocketSession.java From spring-analysis-note with MIT License | 6 votes |
@Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); this.uri = session.getRequestURI(); this.acceptedProtocol = session.getNegotiatedSubprotocol(); List<Extension> standardExtensions = getNativeSession().getNegotiatedExtensions(); if (!CollectionUtils.isEmpty(standardExtensions)) { this.extensions = new ArrayList<>(standardExtensions.size()); for (Extension standardExtension : standardExtensions) { this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension)); } this.extensions = Collections.unmodifiableList(this.extensions); } else { this.extensions = Collections.emptyList(); } if (this.user == null) { this.user = session.getUserPrincipal(); } }
Example #6
Source File: UpgradeUtil.java From Tomcat8-Source-Read with MIT License | 6 votes |
private static void append(StringBuilder sb, Extension extension) { if (extension == null || extension.getName() == null || extension.getName().length() == 0) { return; } sb.append(extension.getName()); for (Extension.Parameter p : extension.getParameters()) { sb.append(';'); sb.append(p.getName()); if (p.getValue() != null) { sb.append('='); sb.append(p.getValue()); } } }
Example #7
Source File: WebSphereRequestUpgradeStrategy.java From java-technology-stack with MIT License | 6 votes |
@Override public void upgradeInternal(ServerHttpRequest httpRequest, ServerHttpResponse httpResponse, @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest request = getHttpServletRequest(httpRequest); HttpServletResponse response = getHttpServletResponse(httpResponse); StringBuffer requestUrl = request.getRequestURL(); String path = request.getRequestURI(); // shouldn't matter Map<String, String> pathParams = Collections.<String, String> emptyMap(); ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol)); endpointConfig.setExtensions(selectedExtensions); try { ServerContainer container = getContainer(request); upgradeMethod.invoke(container, request, response, endpointConfig, pathParams); } catch (Exception ex) { throw new HandshakeFailureException( "Servlet request failed to upgrade to WebSocket for " + requestUrl, ex); } }
Example #8
Source File: WsWebSocketContainer.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
private static List<String> generateExtensionHeaders(List<Extension> extensions) { List<String> result = new ArrayList<String>(extensions.size()); for (Extension extension : extensions) { StringBuilder header = new StringBuilder(); header.append(extension.getName()); for (Extension.Parameter param : extension.getParameters()) { header.append(';'); header.append(param.getName()); String value = param.getValue(); if (value != null && value.length() > 0) { header.append('='); header.append(value); } } result.add(header.toString()); } return result; }
Example #9
Source File: UpgradeUtil.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
private static void append(StringBuilder sb, Extension extension) { if (extension == null || extension.getName() == null || extension.getName().length() == 0) { return; } sb.append(extension.getName()); for (Extension.Parameter p : extension.getParameters()) { sb.append(';'); sb.append(p.getName()); if (p.getValue() != null) { sb.append('='); sb.append(p.getValue()); } } }
Example #10
Source File: PerMessageDeflate.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public Extension getExtensionResponse() { Extension result = new WsExtension(NAME); List<Extension.Parameter> params = result.getParameters(); if (!serverContextTakeover) { params.add(new WsExtensionParameter(SERVER_NO_CONTEXT_TAKEOVER, null)); } if (serverMaxWindowBits != -1) { params.add(new WsExtensionParameter(SERVER_MAX_WINDOW_BITS, Integer.toString(serverMaxWindowBits))); } if (!clientContextTakeover) { params.add(new WsExtensionParameter(CLIENT_NO_CONTEXT_TAKEOVER, null)); } if (clientMaxWindowBits != -1) { params.add(new WsExtensionParameter(CLIENT_MAX_WINDOW_BITS, Integer.toString(clientMaxWindowBits))); } return result; }
Example #11
Source File: PerMessageDeflate.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public Extension getExtensionResponse() { Extension result = new WsExtension(NAME); List<Extension.Parameter> params = result.getParameters(); if (!serverContextTakeover) { params.add(new WsExtensionParameter(SERVER_NO_CONTEXT_TAKEOVER, null)); } if (serverMaxWindowBits != -1) { params.add(new WsExtensionParameter(SERVER_MAX_WINDOW_BITS, Integer.toString(serverMaxWindowBits))); } if (!clientContextTakeover) { params.add(new WsExtensionParameter(CLIENT_NO_CONTEXT_TAKEOVER, null)); } if (clientMaxWindowBits != -1) { params.add(new WsExtensionParameter(CLIENT_MAX_WINDOW_BITS, Integer.toString(clientMaxWindowBits))); } return result; }
Example #12
Source File: UpgradeUtil.java From tomcatsrc with Apache License 2.0 | 6 votes |
private static void append(StringBuilder sb, Extension extension) { if (extension == null || extension.getName() == null || extension.getName().length() == 0) { return; } sb.append(extension.getName()); for (Extension.Parameter p : extension.getParameters()) { sb.append(';'); sb.append(p.getName()); if (p.getValue() != null) { sb.append('='); sb.append(p.getValue()); } } }
Example #13
Source File: DefaultServerEndpointConfig.java From Tomcat8-Source-Read with MIT License | 5 votes |
DefaultServerEndpointConfig( Class<?> endpointClass, String path, List<String> subprotocols, List<Extension> extensions, List<Class<? extends Encoder>> encoders, List<Class<? extends Decoder>> decoders, Configurator serverEndpointConfigurator) { this.endpointClass = endpointClass; this.path = path; this.subprotocols = subprotocols; this.extensions = extensions; this.encoders = encoders; this.decoders = decoders; this.serverEndpointConfigurator = serverEndpointConfigurator; }
Example #14
Source File: DefaultServerEndpointConfigurator.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) { Set<String> installedNames = new HashSet<String>(); for (Extension e : installed) { installedNames.add(e.getName()); } List<Extension> result = new ArrayList<Extension>(); for (Extension request : requested) { if (installedNames.contains(request.getName())) { result.add(request); } } return result; }
Example #15
Source File: AbstractStandardUpgradeStrategy.java From java-technology-stack with MIT License | 5 votes |
protected List<WebSocketExtension> getInstalledExtensions(WebSocketContainer container) { List<WebSocketExtension> result = new ArrayList<>(); for (Extension extension : container.getInstalledExtensions()) { result.add(new StandardToWebSocketExtensionAdapter(extension)); } return result; }
Example #16
Source File: WsHttpUpgradeHandler.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public void preInit(Endpoint ep, EndpointConfig endpointConfig, WsServerContainer wsc, WsHandshakeRequest handshakeRequest, List<Extension> negotiatedExtensionsPhase2, String subProtocol, Transformation transformation, Map<String,String> pathParameters, boolean secure) { this.ep = ep; this.endpointConfig = endpointConfig; this.webSocketContainer = wsc; this.handshakeRequest = handshakeRequest; this.negotiatedExtensions = negotiatedExtensionsPhase2; this.subProtocol = subProtocol; this.transformation = transformation; this.pathParameters = pathParameters; this.secure = secure; }
Example #17
Source File: TransformationFactory.java From Tomcat8-Source-Read with MIT License | 5 votes |
public Transformation create(String name, List<List<Extension.Parameter>> preferences, boolean isServer) { if (PerMessageDeflate.NAME.equals(name)) { return PerMessageDeflate.negotiate(preferences, isServer); } if (Constants.ALLOW_UNSUPPORTED_EXTENSIONS) { return null; } else { throw new IllegalArgumentException( sm.getString("transformerFactory.unsupportedExtension", name)); } }
Example #18
Source File: StandardWebSocketClient.java From spring-analysis-note with MIT License | 5 votes |
private static List<Extension> adaptExtensions(List<WebSocketExtension> extensions) { List<Extension> result = new ArrayList<>(); for (WebSocketExtension extension : extensions) { result.add(new WebSocketToStandardExtensionAdapter(extension)); } return result; }
Example #19
Source File: DefaultServerEndpointConfig.java From tomcatsrc with Apache License 2.0 | 5 votes |
DefaultServerEndpointConfig( Class<?> endpointClass, String path, List<String> subprotocols, List<Extension> extensions, List<Class<? extends Encoder>> encoders, List<Class<? extends Decoder>> decoders, Configurator serverEndpointConfigurator) { this.endpointClass = endpointClass; this.path = path; this.subprotocols = subprotocols; this.extensions = extensions; this.encoders = encoders; this.decoders = decoders; this.serverEndpointConfigurator = serverEndpointConfigurator; }
Example #20
Source File: AbstractTyrusRequestUpgradeStrategy.java From java-technology-stack with MIT License | 5 votes |
private Object createTyrusEndpoint(Endpoint endpoint, String endpointPath, @Nullable String protocol, List<Extension> extensions, WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException { ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(endpointPath, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(protocol)); endpointConfig.setExtensions(extensions); return createEndpoint(endpointConfig, this.componentProvider, container, engine); }
Example #21
Source File: TestWsWebSocketContainer.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private void doTestPerMessageDefalteClient(String msg, int count) throws Exception { Tomcat tomcat = getTomcatInstance(); // Must have a real docBase - just use temp Context ctx = tomcat.addContext("", System.getProperty("java.io.tmpdir")); ctx.addApplicationListener(TesterEchoServer.Config.class.getName()); Tomcat.addServlet(ctx, "default", new DefaultServlet()); ctx.addServletMapping("/", "default"); tomcat.start(); Extension perMessageDeflate = new WsExtension(PerMessageDeflate.NAME); List<Extension> extensions = new ArrayList<Extension>(1); extensions.add(perMessageDeflate); ClientEndpointConfig clientConfig = ClientEndpointConfig.Builder.create().extensions(extensions).build(); WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); Session wsSession = wsContainer.connectToServer( TesterProgrammaticEndpoint.class, clientConfig, new URI("ws://" + getHostName() + ":" + getPort() + TesterEchoServer.Config.PATH_ASYNC)); CountDownLatch latch = new CountDownLatch(count); BasicText handler = new BasicText(latch, msg); wsSession.addMessageHandler(handler); for (int i = 0; i < count; i++) { wsSession.getBasicRemote().sendText(msg); } boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS); Assert.assertTrue(latchResult); ((WsWebSocketContainer) wsContainer).destroy(); }
Example #22
Source File: AbstractStandardUpgradeStrategy.java From spring-analysis-note with MIT License | 5 votes |
protected List<WebSocketExtension> getInstalledExtensions(WebSocketContainer container) { List<WebSocketExtension> result = new ArrayList<>(); for (Extension extension : container.getInstalledExtensions()) { result.add(new StandardToWebSocketExtensionAdapter(extension)); } return result; }
Example #23
Source File: StandardWebSocketClient.java From java-technology-stack with MIT License | 5 votes |
private static List<Extension> adaptExtensions(List<WebSocketExtension> extensions) { List<Extension> result = new ArrayList<>(); for (WebSocketExtension extension : extensions) { result.add(new WebSocketToStandardExtensionAdapter(extension)); } return result; }
Example #24
Source File: StandardToWebSocketExtensionAdapter.java From java-technology-stack with MIT License | 5 votes |
private static Map<String, String> initParameters(Extension extension) { List<Extension.Parameter> parameters = extension.getParameters(); Map<String, String> result = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH); for (Extension.Parameter parameter : parameters) { result.put(parameter.getName(), parameter.getValue()); } return result; }
Example #25
Source File: DefaultServerEndpointConfig.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
DefaultServerEndpointConfig( Class<?> endpointClass, String path, List<String> subprotocols, List<Extension> extensions, List<Class<? extends Encoder>> encoders, List<Class<? extends Decoder>> decoders, Configurator serverEndpointConfigurator) { this.endpointClass = endpointClass; this.path = path; this.subprotocols = subprotocols; this.extensions = extensions; this.encoders = encoders; this.decoders = decoders; this.serverEndpointConfigurator = serverEndpointConfigurator; }
Example #26
Source File: ServerWebSocketContainer.java From quarkus-http with Apache License 2.0 | 5 votes |
public ServerWebSocketContainer(final ClassIntrospecter classIntrospecter, final ClassLoader classLoader, Supplier<EventLoopGroup> eventLoopSupplier, List<ThreadSetupHandler> threadSetupHandlers, boolean dispatchToWorker, InetSocketAddress clientBindAddress, WebSocketReconnectHandler reconnectHandler, Supplier<Executor> executorSupplier, List<Extension> installedExtensions, int maxFrameSize) { this.classIntrospecter = classIntrospecter; this.eventLoopSupplier = eventLoopSupplier; this.dispatchToWorker = dispatchToWorker; this.clientBindAddress = clientBindAddress; this.executorSupplier = executorSupplier; this.installedExtensions = new ArrayList<>(installedExtensions); this.webSocketReconnectHandler = reconnectHandler; this.maxFrameSize = maxFrameSize; ThreadSetupHandler.Action<Void, Runnable> task = new ThreadSetupHandler.Action<Void, Runnable>() { @Override public Void call(HttpServerExchange exchange, Runnable context) throws Exception { context.run(); return null; } }; List<WebsocketClientSslProvider> clientSslProviders = new ArrayList<>(); for (WebsocketClientSslProvider provider : ServiceLoader.load(WebsocketClientSslProvider.class, classLoader)) { clientSslProviders.add(provider); } this.clientSslProviders = Collections.unmodifiableList(clientSslProviders); for (ThreadSetupHandler handler : threadSetupHandlers) { task = handler.create(task); } this.invokeEndpointTask = task; }
Example #27
Source File: AbstractTyrusRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 5 votes |
private Object createTyrusEndpoint(Endpoint endpoint, String endpointPath, String protocol, List<Extension> extensions, WebSocketContainer container, TyrusWebSocketEngine engine) throws DeploymentException { ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(endpointPath, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(protocol)); endpointConfig.setExtensions(extensions); return getEndpointHelper().createdEndpoint(endpointConfig, this.componentProvider, container, engine); }
Example #28
Source File: UpgradeUtil.java From tomcatsrc with Apache License 2.0 | 5 votes |
private static List<Transformation> createTransformations( List<Extension> negotiatedExtensions) { TransformationFactory factory = TransformationFactory.getInstance(); LinkedHashMap<String,List<List<Extension.Parameter>>> extensionPreferences = new LinkedHashMap<String,List<List<Extension.Parameter>>>(); // Result will likely be smaller than this List<Transformation> result = new ArrayList<Transformation>(negotiatedExtensions.size()); for (Extension extension : negotiatedExtensions) { List<List<Extension.Parameter>> preferences = extensionPreferences.get(extension.getName()); if (preferences == null) { preferences = new ArrayList<List<Extension.Parameter>>(); extensionPreferences.put(extension.getName(), preferences); } preferences.add(extension.getParameters()); } for (Map.Entry<String,List<List<Extension.Parameter>>> entry : extensionPreferences.entrySet()) { Transformation transformation = factory.create(entry.getKey(), entry.getValue(), true); if (transformation != null) { result.add(transformation); } } return result; }
Example #29
Source File: UndertowSession.java From quarkus-http with Apache License 2.0 | 5 votes |
public UndertowSession(Channel channel, URI requestUri, Map<String, String> pathParameters, Map<String, List<String>> requestParameterMap, EndpointSessionHandler handler, Principal user, InstanceHandle<Endpoint> endpoint, EndpointConfig config, final String queryString, final Encoding encoding, final SessionContainer openSessions, final String subProtocol, final List<Extension> extensions, WebsocketConnectionBuilder clientConnectionBuilder, Executor executor) { channel.closeFuture().addListener(new GenericFutureListener<Future<? super Void>>() { @Override public void operationComplete(Future<? super Void> future) throws Exception { closeInternal(new CloseReason(CloseReason.CloseCodes.GOING_AWAY, null)); } }); this.clientConnectionBuilder = clientConnectionBuilder; assert openSessions != null; this.channel = channel; this.queryString = queryString; this.encoding = encoding; this.openSessions = openSessions; container = handler.getContainer(); this.user = user; this.requestUri = requestUri; this.requestParameterMap = Collections.unmodifiableMap(requestParameterMap); this.pathParameters = Collections.unmodifiableMap(pathParameters); this.config = config; remote = new WebSocketSessionRemoteEndpoint(this, encoding); this.endpoint = endpoint; this.sessionId = new SecureRandomSessionIdGenerator().createSessionId(); this.attrs = Collections.synchronizedMap(new HashMap<>(config.getUserProperties())); this.extensions = extensions; this.subProtocol = subProtocol; this.executor = executor; setupWebSocketChannel(channel); }
Example #30
Source File: ConfiguredServerEndpoint.java From quarkus-http with Apache License 2.0 | 5 votes |
public ConfiguredServerEndpoint(final ServerEndpointConfig endpointConfiguration, final InstanceFactory<?> endpointFactory, final PathTemplate pathTemplate, final EncodingFactory encodingFactory, AnnotatedEndpointFactory annotatedEndpointFactory, List<Extension> installed) { this.endpointConfiguration = endpointConfiguration; this.endpointFactory = endpointFactory; this.pathTemplate = pathTemplate; this.encodingFactory = encodingFactory; this.annotatedEndpointFactory = annotatedEndpointFactory; this.extensions = installed; }