org.springframework.http.server.reactive.AbstractServerHttpRequest Java Examples

The following examples show how to use org.springframework.http.server.reactive.AbstractServerHttpRequest. 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: UndertowRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
		@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {

	ServerHttpRequest request = exchange.getRequest();
	Assert.isInstanceOf(AbstractServerHttpRequest.class, request);
	HttpServerExchange httpExchange = ((AbstractServerHttpRequest) request).getNativeRequest();

	Set<String> protocols = (subProtocol != null ? Collections.singleton(subProtocol) : Collections.emptySet());
	Hybi13Handshake handshake = new Hybi13Handshake(protocols, false);
	List<Handshake> handshakes = Collections.singletonList(handshake);

	HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
	DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();

	try {
		DefaultCallback callback = new DefaultCallback(handshakeInfo, handler, bufferFactory);
		new WebSocketProtocolHandshakeHandler(handshakes, callback).handleRequest(httpExchange);
	}
	catch (Exception ex) {
		return Mono.error(ex);
	}

	return Mono.empty();
}
 
Example #2
Source File: UndertowRequestUpgradeStrategy.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
		@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {

	ServerHttpRequest request = exchange.getRequest();
	Assert.isInstanceOf(AbstractServerHttpRequest.class, request);
	HttpServerExchange httpExchange = ((AbstractServerHttpRequest) request).getNativeRequest();

	Set<String> protocols = (subProtocol != null ? Collections.singleton(subProtocol) : Collections.emptySet());
	Hybi13Handshake handshake = new Hybi13Handshake(protocols, false);
	List<Handshake> handshakes = Collections.singletonList(handshake);

	HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
	DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();

	try {
		DefaultCallback callback = new DefaultCallback(handshakeInfo, handler, bufferFactory);
		new WebSocketProtocolHandshakeHandler(handshakes, callback).handleRequest(httpExchange);
	}
	catch (Exception ex) {
		return Mono.error(ex);
	}

	return Mono.empty();
}
 
Example #3
Source File: VertxRequestUpgradeStrategy.java    From vertx-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
    @Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {

    LOGGER.debug("Upgrading request to web socket");

    ServerHttpRequest request = exchange.getRequest();
    HttpServerRequest vertxRequest = ((AbstractServerHttpRequest) request).getNativeRequest();

    ServerWebSocket webSocket = vertxRequest.upgrade();
    VertxWebSocketSession session =
        new VertxWebSocketSession(webSocket, handshakeInfoFactory.get(), bufferConverter);

    return handler.handle(session);
}
 
Example #4
Source File: JettyRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private HttpServletRequest getHttpServletRequest(ServerHttpRequest request) {
	Assert.isInstanceOf(AbstractServerHttpRequest.class, request);
	return ((AbstractServerHttpRequest) request).getNativeRequest();
}
 
Example #5
Source File: TomcatRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private HttpServletRequest getHttpServletRequest(ServerHttpRequest request) {
	Assert.isInstanceOf(AbstractServerHttpRequest.class, request, "ServletServerHttpRequest required");
	return ((AbstractServerHttpRequest) request).getNativeRequest();
}
 
Example #6
Source File: JettyRequestUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
private HttpServletRequest getHttpServletRequest(ServerHttpRequest request) {
	Assert.isInstanceOf(AbstractServerHttpRequest.class, request);
	return ((AbstractServerHttpRequest) request).getNativeRequest();
}
 
Example #7
Source File: TomcatRequestUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
private HttpServletRequest getHttpServletRequest(ServerHttpRequest request) {
	Assert.isInstanceOf(AbstractServerHttpRequest.class, request, "ServletServerHttpRequest required");
	return ((AbstractServerHttpRequest) request).getNativeRequest();
}