public TomcatWebSocketClient() { this(new WsWebSocketContainer()); }
sa = new InetSocketAddress(host, port); } else { proxyConnect = createProxyRequest(host, port); Map<String, List<String>> reqHeaders = createRequestHeaders(host, port, clientEndpointConfiguration); clientEndpointConfiguration.getConfigurator().beforeRequest(reqHeaders); ByteBuffer request = createRequest(path, reqHeaders); socketChannel = AsynchronousSocketChannel.open(getAsynchronousChannelGroup()); } catch (IOException ioe) { throw new DeploymentException(sm.getString( ByteBuffer response = ByteBuffer.allocate(getDefaultMaxBinaryMessageBufferSize()); String subProtocol; boolean success = false; writeRequest(channel, proxyConnect, timeout); HttpResponse httpResponse = processResponse(response, channel, timeout); if (httpResponse.getStatus() != 200) { throw new DeploymentException(sm.getString( SSLEngine sslEngine = createSSLEngine(userProperties, host, port); channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); } else if (channel == null) { writeRequest(channel, request, timeout);
Map<String,List<String>> reqHeaders = createRequestHeaders(host, port, clientEndpointConfiguration.getPreferredSubprotocols(), clientEndpointConfiguration.getExtensions()); beforeRequest(reqHeaders); ByteBuffer request = createRequest(path, reqHeaders); SSLEngine sslEngine = createSSLEngine( clientEndpointConfiguration.getUserProperties()); channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); processResponse(response, channel, timeout); clientEndpointConfiguration.getConfigurator(). afterResponse(handshakeResponse); clientEndpointConfiguration); endpoint.onOpen(wsSession, clientEndpointConfiguration); registerSession(endpoint, wsSession);
wsKeyValues.add(generateWsKeyValue()); headers.put(Constants.WS_KEY_HEADER_NAME, wsKeyValues); generateExtensionHeaders(extensions));
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void unregisterSession(Endpoint endpoint, WsSession wsSession) { if (wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { unregisterAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } super.unregisterSession(endpoint, wsSession); log.debug("unregisterSession: {} endpoint: {}", wsSession.getId(), endpoint); }
@Override public Session connectToServer(Class<?> annotatedEndpointClass, URI path) throws DeploymentException { Object pojo; try { pojo = annotatedEndpointClass.getConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new DeploymentException(sm.getString( "wsWebSocketContainer.endpointCreateFail", annotatedEndpointClass.getName()), e); } return connectToServer(pojo, path); }
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void registerSession(Endpoint endpoint, WsSession wsSession) { super.registerSession(endpoint, wsSession); if (wsSession.isOpen() && wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { registerAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } log.debug("registerSession: {} endpoint: {}", wsSession, endpoint); }
private static ByteBuffer createRequest(URI uri, Map<String,List<String>> reqHeaders) { ByteBuffer result = ByteBuffer.allocate(4 * 1024); // Request line result.put(GET_BYTES); byte[] path = (null == uri.getPath() || "".equals(uri.getPath())) ? ROOT_URI_BYTES : uri.getRawPath().getBytes(StandardCharsets.ISO_8859_1); result.put(path); String query = uri.getRawQuery(); if (query != null) { result.put((byte) '?'); result.put(query.getBytes(StandardCharsets.ISO_8859_1)); } result.put(HTTP_VERSION_BYTES); // Headers for (Entry<String, List<String>> entry : reqHeaders.entrySet()) { result = addHeader(result, entry.getKey(), entry.getValue()); } // Terminating CRLF result.put(CRLF); result.flip(); return result; }
sa = new InetSocketAddress(host, port); } else { proxyConnect = createProxyRequest(host, port); Map<String, List<String>> reqHeaders = createRequestHeaders(host, port, clientEndpointConfiguration); clientEndpointConfiguration.getConfigurator().beforeRequest(reqHeaders); ByteBuffer request = createRequest(path, reqHeaders); socketChannel = AsynchronousSocketChannel.open(getAsynchronousChannelGroup()); } catch (IOException ioe) { throw new DeploymentException(sm.getString( ByteBuffer response = ByteBuffer.allocate(getDefaultMaxBinaryMessageBufferSize()); String subProtocol; boolean success = false; writeRequest(channel, proxyConnect, timeout); HttpResponse httpResponse = processResponse(response, channel, timeout); if (httpResponse.getStatus() != 200) { throw new DeploymentException(sm.getString( SSLEngine sslEngine = createSSLEngine(userProperties, host, port); channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); } else if (channel == null) { writeRequest(channel, request, timeout);
Map<String,List<String>> reqHeaders = createRequestHeaders(host, port, clientEndpointConfiguration.getPreferredSubprotocols(), clientEndpointConfiguration.getExtensions()); beforeRequest(reqHeaders); ByteBuffer request = createRequest(path, reqHeaders); socketChannel = AsynchronousSocketChannel.open(getAsynchronousChannelGroup()); } catch (IOException ioe) { throw new DeploymentException(MESSAGES.connectionFailed(), ioe); SSLEngine sslEngine = createSSLEngine( clientEndpointConfiguration.getUserProperties()); channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); processResponse(response, channel, timeout); clientEndpointConfiguration.getConfigurator(). afterResponse(handshakeResponse); registerSession(endpoint, wsSession);
wsKeyValues.add(generateWsKeyValue()); headers.put(Constants.WS_KEY_HEADER_NAME, wsKeyValues); generateExtensionHeaders(extensions));
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void unregisterSession(Endpoint endpoint, WsSession wsSession) { if (wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { unregisterAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } super.unregisterSession(endpoint, wsSession); }
@Override public Session connectToServer(Class<?> annotatedEndpointClass, URI path) throws DeploymentException { Object pojo; try { pojo = annotatedEndpointClass.getConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new DeploymentException(sm.getString( "wsWebSocketContainer.endpointCreateFail", annotatedEndpointClass.getName()), e); } return connectToServer(pojo, path); }
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void registerSession(Endpoint endpoint, WsSession wsSession) { super.registerSession(endpoint, wsSession); if (wsSession.isOpen() && wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { registerAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } }
private ByteBuffer createRequest(URI uri, Map<String,List<String>> reqHeaders) { ByteBuffer result = ByteBuffer.allocate(4 * 1024); // Request line result.put("GET ".getBytes(StandardCharsets.ISO_8859_1)); result.put(uri.getRawPath().getBytes(StandardCharsets.ISO_8859_1)); String query = uri.getRawQuery(); if (query != null) { result.put((byte) '?'); result.put(query.getBytes(StandardCharsets.ISO_8859_1)); } result.put(" HTTP/1.1\r\n".getBytes(StandardCharsets.ISO_8859_1)); // Headers Iterator<Entry<String,List<String>>> iter = reqHeaders.entrySet().iterator(); while (iter.hasNext()) { Entry<String,List<String>> entry = iter.next(); addHeader(result, entry.getKey(), entry.getValue()); } // Terminating CRLF result.put(crlf); result.flip(); return result; }
sa = new InetSocketAddress(host, port); } else { proxyConnect = createProxyRequest(host, port); Map<String, List<String>> reqHeaders = createRequestHeaders(host, port, clientEndpointConfiguration); clientEndpointConfiguration.getConfigurator().beforeRequest(reqHeaders); ByteBuffer request = createRequest(path, reqHeaders); socketChannel = AsynchronousSocketChannel.open(getAsynchronousChannelGroup()); } catch (IOException ioe) { throw new DeploymentException(sm.getString( ByteBuffer response = ByteBuffer.allocate(getDefaultMaxBinaryMessageBufferSize()); String subProtocol; boolean success = false; writeRequest(channel, proxyConnect, timeout); HttpResponse httpResponse = processResponse(response, channel, timeout); if (httpResponse.getStatus() != 200) { throw new DeploymentException(sm.getString( SSLEngine sslEngine = createSSLEngine(userProperties, host, port); channel = new AsyncChannelWrapperSecure(socketChannel, sslEngine); } else if (channel == null) { writeRequest(channel, request, timeout);
wsKeyValues.add(generateWsKeyValue()); headers.put(Constants.WS_KEY_HEADER_NAME, wsKeyValues); generateExtensionHeaders(extensions));
/** * {@inheritDoc} * * Overridden to make it visible to other classes in this package. */ @Override protected void unregisterSession(Endpoint endpoint, WsSession wsSession) { if (wsSession.getUserPrincipal() != null && wsSession.getHttpSessionId() != null) { unregisterAuthenticatedSession(wsSession, wsSession.getHttpSessionId()); } super.unregisterSession(endpoint, wsSession); }
@Override public Session connectToServer(Class<? extends Endpoint> clazz, ClientEndpointConfig clientEndpointConfiguration, URI path) throws DeploymentException { Endpoint endpoint; try { endpoint = clazz.getConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new DeploymentException(sm.getString( "wsWebSocketContainer.endpointCreateFail", clazz.getName()), e); } return connectToServer(endpoint, clientEndpointConfiguration, path); }
@Override protected WebSocketContainer getContainer() { return new WsWebSocketContainer(); } }