protected URI getWebSocketLocation(HttpAcceptSession session, WebSocketWireProtocol wireProtocol) throws URISyntaxException { URI uri = session.getRequestURL(); String scheme = session.isSecure() ? "wss" : "ws"; // Note: According to specification, WebSocket location MUST CONTAIN // query string and fragment "resource name" as defined by the // middle token of the first line of the WebSocket handshake // Note: Chrome 4.0.249.78 closes WebSocket after specification-compliant // handshake if WebSocket location contains a query string. // Workaround to avoid echoing back the query string in that case. String query = uri.getQuery(); if ("nq".equals(session.getParameter(".kl"))) { query = null; } int port = uri.getPort(); if (wireProtocol == WebSocketWireProtocol.HIXIE_76) { if (session.isSecure() && port == 443) { port = -1; } else if (!session.isSecure() && port == 80) { port = -1; } } URI location = new URI(scheme, uri.getUserInfo(), uri.getHost(), port, uri.getPath(), query, uri .getFragment()); return location; }
public static void handleExtensionNegotiationException(HttpAcceptSession session, List<String> clientRequestedExtensions, ProtocolException e, Logger logger) { // This happens when the extension negotiation leads to // a fatal failure; the session should be closed because // the service REQUIRED some extension that the client // did not request. if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) { // KG-10384: make sure port is explicitly included in the request URI we use for lookup since it is always // included when the service registry is created since we force use of explicit port in accepts. // TODO: consider doing this "at the edge" when the HTTP request object (or http session) is created. URI requestURI = HttpUtils.getRequestURI(session.getRequestURL(), session.getReadHeader("Host"), session); logger.debug(format( "Rejected %s request for URI \"%s\" on session '%s': failed to negotiate client requested extensions '%s'" + " due to exception %s", session.getMethod(), requestURI, session, clientRequestedExtensions, e.toString())); } } session.setStatus(HttpStatus.CLIENT_NOT_FOUND); session.setReason("WebSocket Extensions not found or invalid"); session.close(false); }
@Override public void initializeSession(IoSession wsSession, IoFuture future) { wsSession.setAttribute(HttpAcceptor.SERVICE_REGISTRATION_KEY, session.getAttribute(HttpAcceptor.SERVICE_REGISTRATION_KEY)); wsSession.setAttribute(HTTP_REQUEST_URI_KEY, session.getRequestURL()); ((AbstractWsBridgeSession)wsSession).setSubject(session.getSubject()); wsSession.setAttribute(BridgeSession.NEXT_PROTOCOL_KEY, wsProtocol0); // TODO: add websocket extension filters from negotiated or set an attribute // and do in addBridgeFilters } }, new Callable<WsrSession>() {
@Override public void initializeSession(IoSession wsSession, IoFuture future) { wsSession.setAttribute(HttpAcceptor.SERVICE_REGISTRATION_KEY, session .getAttribute(HttpAcceptor.SERVICE_REGISTRATION_KEY)); wsSession.setAttribute(HTTP_REQUEST_URI_KEY, session.getRequestURL()); WsebSession wsebSession = (WsebSession)wsSession; wsSession.setAttribute(BridgeSession.NEXT_PROTOCOL_KEY, wsProtocol0); wsebSession.setLoginContext(session.getLoginContext()); wsebSession.setPingEnabled(pingEnabled); IoSessionEx extensionsSession = wsebSession.getTransportSession(); IoFilterChain extensionsFilterChain = extensionsSession.getFilterChain(); // we don't want IdleTimeoutFilter in the filter chain. It sends 0x8A (PONG) // and some clients don't understand it. WSEB anyway sends NOOP command when // writer is idle. List<WebSocketExtension> negotiatedCopy = new ArrayList<>(negotiated); negotiatedCopy.removeIf(e -> e.getExtensionHeader().getExtensionToken().equals("x-kaazing-idle-timeout")); WsUtils.addExtensionFilters(negotiatedCopy, extensionHelper, extensionsFilterChain, false); extensionsFilterChain.fireSessionCreated(); extensionsFilterChain.fireSessionOpened(); } }, new Callable<WsebSession>() {
URI request = session.getRequestURL(); URI httpCreateURI = httpCreateAddress.getResource(); final URI httpUri = session.getRequestURL(); if ( !httpUri.getPath().contains(CREATE_SUFFIX)) { throw new IllegalStateException("Session created with unexpected URL: "+httpUri.toASCIIString());
final URI httpUri = session.getRequestURL(); if (!httpUri.getPath().contains(createSuffix)) { throw new IllegalStateException("Session created with unexpected URL: "+httpUri.toASCIIString());