Java Code Examples for org.springframework.http.server.ServerHttpRequest#getURI()
The following examples show how to use
org.springframework.http.server.ServerHttpRequest#getURI() .
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: JettyRequestUpgradeStrategy.java From spring-analysis-note with MIT License | 5 votes |
@Override public void upgrade(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user, WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException { Assert.isInstanceOf(ServletServerHttpRequest.class, request, "ServletServerHttpRequest required"); HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest(); Assert.isInstanceOf(ServletServerHttpResponse.class, response, "ServletServerHttpResponse required"); HttpServletResponse servletResponse = ((ServletServerHttpResponse) response).getServletResponse(); Assert.isTrue(this.factory.isUpgradeRequest(servletRequest, servletResponse), "Not a WebSocket handshake"); JettyWebSocketSession session = new JettyWebSocketSession(attributes, user); JettyWebSocketHandlerAdapter handlerAdapter = new JettyWebSocketHandlerAdapter(wsHandler, session); WebSocketHandlerContainer container = new WebSocketHandlerContainer(handlerAdapter, selectedProtocol, selectedExtensions); try { containerHolder.set(container); this.factory.acceptWebSocket(servletRequest, servletResponse); } catch (IOException ex) { throw new HandshakeFailureException( "Response update failed during upgrade to WebSocket: " + request.getURI(), ex); } finally { containerHolder.remove(); } }
Example 2
Source File: SockJsHttpRequestHandler.java From spring-analysis-note with MIT License | 5 votes |
@Override public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { ServerHttpRequest request = new ServletServerHttpRequest(servletRequest); ServerHttpResponse response = new ServletServerHttpResponse(servletResponse); try { this.sockJsService.handleRequest(request, response, getSockJsPath(servletRequest), this.webSocketHandler); } catch (Throwable ex) { throw new SockJsException("Uncaught failure in SockJS request, uri=" + request.getURI(), ex); } }
Example 3
Source File: JettyRequestUpgradeStrategy.java From java-technology-stack with MIT License | 5 votes |
@Override public void upgrade(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user, WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException { Assert.isInstanceOf(ServletServerHttpRequest.class, request, "ServletServerHttpRequest required"); HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest(); Assert.isInstanceOf(ServletServerHttpResponse.class, response, "ServletServerHttpResponse required"); HttpServletResponse servletResponse = ((ServletServerHttpResponse) response).getServletResponse(); Assert.isTrue(this.factory.isUpgradeRequest(servletRequest, servletResponse), "Not a WebSocket handshake"); JettyWebSocketSession session = new JettyWebSocketSession(attributes, user); JettyWebSocketHandlerAdapter handlerAdapter = new JettyWebSocketHandlerAdapter(wsHandler, session); WebSocketHandlerContainer container = new WebSocketHandlerContainer(handlerAdapter, selectedProtocol, selectedExtensions); try { containerHolder.set(container); this.factory.acceptWebSocket(servletRequest, servletResponse); } catch (IOException ex) { throw new HandshakeFailureException( "Response update failed during upgrade to WebSocket: " + request.getURI(), ex); } finally { containerHolder.remove(); } }
Example 4
Source File: SockJsHttpRequestHandler.java From java-technology-stack with MIT License | 5 votes |
@Override public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { ServerHttpRequest request = new ServletServerHttpRequest(servletRequest); ServerHttpResponse response = new ServletServerHttpResponse(servletResponse); try { this.sockJsService.handleRequest(request, response, getSockJsPath(servletRequest), this.webSocketHandler); } catch (Throwable ex) { throw new SockJsException("Uncaught failure in SockJS request, uri=" + request.getURI(), ex); } }
Example 5
Source File: JettyRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void upgrade(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user, WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException { Assert.isInstanceOf(ServletServerHttpRequest.class, request); HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest(); Assert.isInstanceOf(ServletServerHttpResponse.class, response); HttpServletResponse servletResponse = ((ServletServerHttpResponse) response).getServletResponse(); Assert.isTrue(this.factory.isUpgradeRequest(servletRequest, servletResponse), "Not a WebSocket handshake"); JettyWebSocketSession session = new JettyWebSocketSession(attributes, user); JettyWebSocketHandlerAdapter handlerAdapter = new JettyWebSocketHandlerAdapter(wsHandler, session); WebSocketHandlerContainer container = new WebSocketHandlerContainer(handlerAdapter, selectedProtocol, selectedExtensions); try { wsContainerHolder.set(container); this.factory.acceptWebSocket(servletRequest, servletResponse); } catch (IOException ex) { throw new HandshakeFailureException( "Response update failed during upgrade to WebSocket: " + request.getURI(), ex); } finally { wsContainerHolder.remove(); } }
Example 6
Source File: SockJsHttpRequestHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { ServerHttpRequest request = new ServletServerHttpRequest(servletRequest); ServerHttpResponse response = new ServletServerHttpResponse(servletResponse); try { this.sockJsService.handleRequest(request, response, getSockJsPath(servletRequest), this.webSocketHandler); } catch (Throwable ex) { throw new SockJsException("Uncaught failure in SockJS request, uri=" + request.getURI(), ex); } }
Example 7
Source File: AbstractHttpSockJsSession.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Handle the first request for receiving messages on a SockJS HTTP transport * based session. * <p>Long polling-based transports (e.g. "xhr", "jsonp") complete the request * after writing the open frame. Streaming-based transports ("xhr_streaming", * "eventsource", and "htmlfile") leave the response open longer for further * streaming of message frames but will also close it eventually after some * amount of data has been sent. * @param request the current request * @param response the current response * @param frameFormat the transport-specific SocksJS frame format to use */ public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException { this.uri = request.getURI(); this.handshakeHeaders = request.getHeaders(); this.principal = request.getPrincipal(); this.localAddress = request.getLocalAddress(); this.remoteAddress = request.getRemoteAddress(); synchronized (this.responseLock) { try { this.response = response; this.frameFormat = frameFormat; this.asyncRequestControl = request.getAsyncRequestControl(response); this.asyncRequestControl.start(-1); disableShallowEtagHeaderFilter(request); // Let "our" handler know before sending the open frame to the remote handler delegateConnectionEstablished(); handleRequestInternal(request, response, true); // Request might have been reset (e.g. polling sessions do after writing) this.readyToSend = isActive(); } catch (Throwable ex) { tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR); throw new SockJsTransportFailureException("Failed to open session", getId(), ex); } } }
Example 8
Source File: AbstractTyrusRequestUpgradeStrategy.java From spring-analysis-note with MIT License | 4 votes |
@Override public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol, List<Extension> extensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest servletRequest = getHttpServletRequest(request); HttpServletResponse servletResponse = getHttpServletResponse(response); TyrusServerContainer serverContainer = (TyrusServerContainer) getContainer(servletRequest); TyrusWebSocketEngine engine = (TyrusWebSocketEngine) serverContainer.getWebSocketEngine(); Object tyrusEndpoint = null; boolean success; try { // Shouldn't matter for processing but must be unique String path = "/" + random.nextLong(); tyrusEndpoint = createTyrusEndpoint(endpoint, path, selectedProtocol, extensions, serverContainer, engine); register(engine, tyrusEndpoint); HttpHeaders headers = request.getHeaders(); RequestContext requestContext = createRequestContext(servletRequest, path, headers); TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse(); UpgradeInfo upgradeInfo = engine.upgrade(requestContext, upgradeResponse); success = SUCCESS.equals(upgradeInfo.getStatus()); if (success) { if (logger.isTraceEnabled()) { logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders()); } handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse); } } catch (Exception ex) { unregisterTyrusEndpoint(engine, tyrusEndpoint); throw new HandshakeFailureException("Error during handshake: " + request.getURI(), ex); } unregisterTyrusEndpoint(engine, tyrusEndpoint); if (!success) { throw new HandshakeFailureException("Unexpected handshake failure: " + request.getURI()); } }
Example 9
Source File: AbstractHandshakeHandler.java From spring-analysis-note with MIT License | 4 votes |
@Override public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException { WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHeaders()); if (logger.isTraceEnabled()) { logger.trace("Processing request " + request.getURI() + " with headers=" + headers); } try { if (HttpMethod.GET != request.getMethod()) { response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED); response.getHeaders().setAllow(Collections.singleton(HttpMethod.GET)); if (logger.isErrorEnabled()) { logger.error("Handshake failed due to unexpected HTTP method: " + request.getMethod()); } return false; } if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) { handleInvalidUpgradeHeader(request, response); return false; } if (!headers.getConnection().contains("Upgrade") && !headers.getConnection().contains("upgrade")) { handleInvalidConnectHeader(request, response); return false; } if (!isWebSocketVersionSupported(headers)) { handleWebSocketVersionNotSupported(request, response); return false; } if (!isValidOrigin(request)) { response.setStatusCode(HttpStatus.FORBIDDEN); return false; } String wsKey = headers.getSecWebSocketKey(); if (wsKey == null) { if (logger.isErrorEnabled()) { logger.error("Missing \"Sec-WebSocket-Key\" header"); } response.setStatusCode(HttpStatus.BAD_REQUEST); return false; } } catch (IOException ex) { throw new HandshakeFailureException( "Response update failed during upgrade to WebSocket: " + request.getURI(), ex); } String subProtocol = selectProtocol(headers.getSecWebSocketProtocol(), wsHandler); List<WebSocketExtension> requested = headers.getSecWebSocketExtensions(); List<WebSocketExtension> supported = this.requestUpgradeStrategy.getSupportedExtensions(request); List<WebSocketExtension> extensions = filterRequestedExtensions(request, requested, supported); Principal user = determineUser(request, wsHandler, attributes); if (logger.isTraceEnabled()) { logger.trace("Upgrading to WebSocket, subProtocol=" + subProtocol + ", extensions=" + extensions); } this.requestUpgradeStrategy.upgrade(request, response, subProtocol, extensions, user, wsHandler, attributes); return true; }
Example 10
Source File: AbstractTyrusRequestUpgradeStrategy.java From java-technology-stack with MIT License | 4 votes |
@Override public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol, List<Extension> extensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest servletRequest = getHttpServletRequest(request); HttpServletResponse servletResponse = getHttpServletResponse(response); TyrusServerContainer serverContainer = (TyrusServerContainer) getContainer(servletRequest); TyrusWebSocketEngine engine = (TyrusWebSocketEngine) serverContainer.getWebSocketEngine(); Object tyrusEndpoint = null; boolean success; try { // Shouldn't matter for processing but must be unique String path = "/" + random.nextLong(); tyrusEndpoint = createTyrusEndpoint(endpoint, path, selectedProtocol, extensions, serverContainer, engine); register(engine, tyrusEndpoint); HttpHeaders headers = request.getHeaders(); RequestContext requestContext = createRequestContext(servletRequest, path, headers); TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse(); UpgradeInfo upgradeInfo = engine.upgrade(requestContext, upgradeResponse); success = SUCCESS.equals(upgradeInfo.getStatus()); if (success) { if (logger.isTraceEnabled()) { logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders()); } handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse); } } catch (Exception ex) { unregisterTyrusEndpoint(engine, tyrusEndpoint); throw new HandshakeFailureException("Error during handshake: " + request.getURI(), ex); } unregisterTyrusEndpoint(engine, tyrusEndpoint); if (!success) { throw new HandshakeFailureException("Unexpected handshake failure: " + request.getURI()); } }
Example 11
Source File: AbstractHandshakeHandler.java From java-technology-stack with MIT License | 4 votes |
@Override public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException { WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHeaders()); if (logger.isTraceEnabled()) { logger.trace("Processing request " + request.getURI() + " with headers=" + headers); } try { if (HttpMethod.GET != request.getMethod()) { response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED); response.getHeaders().setAllow(Collections.singleton(HttpMethod.GET)); if (logger.isErrorEnabled()) { logger.error("Handshake failed due to unexpected HTTP method: " + request.getMethod()); } return false; } if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) { handleInvalidUpgradeHeader(request, response); return false; } if (!headers.getConnection().contains("Upgrade") && !headers.getConnection().contains("upgrade")) { handleInvalidConnectHeader(request, response); return false; } if (!isWebSocketVersionSupported(headers)) { handleWebSocketVersionNotSupported(request, response); return false; } if (!isValidOrigin(request)) { response.setStatusCode(HttpStatus.FORBIDDEN); return false; } String wsKey = headers.getSecWebSocketKey(); if (wsKey == null) { if (logger.isErrorEnabled()) { logger.error("Missing \"Sec-WebSocket-Key\" header"); } response.setStatusCode(HttpStatus.BAD_REQUEST); return false; } } catch (IOException ex) { throw new HandshakeFailureException( "Response update failed during upgrade to WebSocket: " + request.getURI(), ex); } String subProtocol = selectProtocol(headers.getSecWebSocketProtocol(), wsHandler); List<WebSocketExtension> requested = headers.getSecWebSocketExtensions(); List<WebSocketExtension> supported = this.requestUpgradeStrategy.getSupportedExtensions(request); List<WebSocketExtension> extensions = filterRequestedExtensions(request, requested, supported); Principal user = determineUser(request, wsHandler, attributes); if (logger.isTraceEnabled()) { logger.trace("Upgrading to WebSocket, subProtocol=" + subProtocol + ", extensions=" + extensions); } this.requestUpgradeStrategy.upgrade(request, response, subProtocol, extensions, user, wsHandler, attributes); return true; }
Example 12
Source File: AbstractTyrusRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<Extension> extensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest servletRequest = getHttpServletRequest(request); HttpServletResponse servletResponse = getHttpServletResponse(response); TyrusServerContainer serverContainer = (TyrusServerContainer) getContainer(servletRequest); TyrusWebSocketEngine engine = (TyrusWebSocketEngine) serverContainer.getWebSocketEngine(); Object tyrusEndpoint = null; boolean success; try { // Shouldn't matter for processing but must be unique String path = "/" + random.nextLong(); tyrusEndpoint = createTyrusEndpoint(endpoint, path, selectedProtocol, extensions, serverContainer, engine); getEndpointHelper().register(engine, tyrusEndpoint); HttpHeaders headers = request.getHeaders(); RequestContext requestContext = createRequestContext(servletRequest, path, headers); TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse(); UpgradeInfo upgradeInfo = engine.upgrade(requestContext, upgradeResponse); success = SUCCESS.equals(upgradeInfo.getStatus()); if (success) { if (logger.isTraceEnabled()) { logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders()); } handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse); } } catch (Exception ex) { unregisterTyrusEndpoint(engine, tyrusEndpoint); throw new HandshakeFailureException("Error during handshake: " + request.getURI(), ex); } unregisterTyrusEndpoint(engine, tyrusEndpoint); if (!success) { throw new HandshakeFailureException("Unexpected handshake failure: " + request.getURI()); } }
Example 13
Source File: AbstractHandshakeHandler.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException { WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHeaders()); if (logger.isTraceEnabled()) { logger.trace("Processing request " + request.getURI() + " with headers=" + headers); } try { if (HttpMethod.GET != request.getMethod()) { response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED); response.getHeaders().setAllow(Collections.singleton(HttpMethod.GET)); if (logger.isErrorEnabled()) { logger.error("Handshake failed due to unexpected HTTP method: " + request.getMethod()); } return false; } if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) { handleInvalidUpgradeHeader(request, response); return false; } if (!headers.getConnection().contains("Upgrade") && !headers.getConnection().contains("upgrade")) { handleInvalidConnectHeader(request, response); return false; } if (!isWebSocketVersionSupported(headers)) { handleWebSocketVersionNotSupported(request, response); return false; } if (!isValidOrigin(request)) { response.setStatusCode(HttpStatus.FORBIDDEN); return false; } String wsKey = headers.getSecWebSocketKey(); if (wsKey == null) { if (logger.isErrorEnabled()) { logger.error("Missing \"Sec-WebSocket-Key\" header"); } response.setStatusCode(HttpStatus.BAD_REQUEST); return false; } } catch (IOException ex) { throw new HandshakeFailureException( "Response update failed during upgrade to WebSocket: " + request.getURI(), ex); } String subProtocol = selectProtocol(headers.getSecWebSocketProtocol(), wsHandler); List<WebSocketExtension> requested = headers.getSecWebSocketExtensions(); List<WebSocketExtension> supported = this.requestUpgradeStrategy.getSupportedExtensions(request); List<WebSocketExtension> extensions = filterRequestedExtensions(request, requested, supported); Principal user = determineUser(request, wsHandler, attributes); if (logger.isTraceEnabled()) { logger.trace("Upgrading to WebSocket, subProtocol=" + subProtocol + ", extensions=" + extensions); } this.requestUpgradeStrategy.upgrade(request, response, subProtocol, extensions, user, wsHandler, attributes); return true; }