org.glassfish.tyrus.core.RequestContext Java Examples
The following examples show how to use
org.glassfish.tyrus.core.RequestContext.
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: AbstractTyrusRequestUpgradeStrategy.java From spring-analysis-note with MIT License | 5 votes |
private RequestContext createRequestContext(HttpServletRequest request, String endpointPath, HttpHeaders headers) { RequestContext context = RequestContext.Builder.create() .requestURI(URI.create(endpointPath)) .userPrincipal(request.getUserPrincipal()) .secure(request.isSecure()) .remoteAddr(request.getRemoteAddr()) .build(); headers.forEach((header, value) -> context.getHeaders().put(header, value)); return context; }
Example #2
Source File: AbstractTyrusRequestUpgradeStrategy.java From java-technology-stack with MIT License | 5 votes |
private RequestContext createRequestContext(HttpServletRequest request, String endpointPath, HttpHeaders headers) { RequestContext context = RequestContext.Builder.create() .requestURI(URI.create(endpointPath)) .userPrincipal(request.getUserPrincipal()) .secure(request.isSecure()) .remoteAddr(request.getRemoteAddr()) .build(); headers.forEach((header, value) -> context.getHeaders().put(header, value)); return context; }
Example #3
Source File: AbstractTyrusRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 5 votes |
private RequestContext createRequestContext(HttpServletRequest request, String endpointPath, HttpHeaders headers) { RequestContext context = RequestContext.Builder.create() .requestURI(URI.create(endpointPath)) .userPrincipal(request.getUserPrincipal()) .secure(request.isSecure()) // .remoteAddr(request.getRemoteAddr()) # Not available in 1.3.5 .build(); for (String header : headers.keySet()) { context.getHeaders().put(header, headers.get(header)); } return context; }
Example #4
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 #5
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 #6
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()); } }