Avoid java.util.Optional signatures for simple field access
Issue: SPR-15576
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.web.reactive.config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -37,13 +36,8 @@ import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.BDDMockito.any;
|
||||
import static org.mockito.BDDMockito.doAnswer;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.verify;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link DelegatingWebFluxConfiguration} tests.
|
||||
@@ -72,8 +66,8 @@ public class DelegatingWebFluxConfigurationTests {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
delegatingConfig = new DelegatingWebFluxConfiguration();
|
||||
delegatingConfig.setApplicationContext(new StaticApplicationContext());
|
||||
given(webFluxConfigurer.getValidator()).willReturn(Optional.empty());
|
||||
given(webFluxConfigurer.getMessageCodesResolver()).willReturn(Optional.empty());
|
||||
given(webFluxConfigurer.getValidator()).willReturn(null);
|
||||
given(webFluxConfigurer.getMessageCodesResolver()).willReturn(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -98,18 +98,18 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
|
||||
|
||||
StepVerifier.create(result)
|
||||
.consumeNextWith( event -> {
|
||||
assertEquals("0", event.id().get());
|
||||
assertEquals("foo", event.data().get());
|
||||
assertEquals("bar", event.comment().get());
|
||||
assertFalse(event.event().isPresent());
|
||||
assertFalse(event.retry().isPresent());
|
||||
assertEquals("0", event.id());
|
||||
assertEquals("foo", event.data());
|
||||
assertEquals("bar", event.comment());
|
||||
assertNull(event.event());
|
||||
assertNull(event.retry());
|
||||
})
|
||||
.consumeNextWith( event -> {
|
||||
assertEquals("1", event.id().get());
|
||||
assertEquals("foo", event.data().get());
|
||||
assertEquals("bar", event.comment().get());
|
||||
assertFalse(event.event().isPresent());
|
||||
assertFalse(event.retry().isPresent());
|
||||
assertEquals("1", event.id());
|
||||
assertEquals("foo", event.data());
|
||||
assertEquals("bar", event.comment());
|
||||
assertNull(event.event());
|
||||
assertNull(event.retry());
|
||||
})
|
||||
.expectComplete()
|
||||
.verify(Duration.ofSeconds(5L));
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.web.reactive.result.method;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -59,7 +58,6 @@ public class InvocableHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void invokeMethodWithNoValue() throws Exception {
|
||||
|
||||
Mono<Object> resolvedValue = Mono.empty();
|
||||
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
|
||||
@@ -69,7 +67,6 @@ public class InvocableHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void invokeMethodWithValue() throws Exception {
|
||||
|
||||
Mono<Object> resolvedValue = Mono.just("value1");
|
||||
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
|
||||
@@ -79,7 +76,6 @@ public class InvocableHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void noMatchingResolver() throws Exception {
|
||||
|
||||
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||
|
||||
@@ -95,7 +91,6 @@ public class InvocableHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void resolverThrowsException() throws Exception {
|
||||
|
||||
Mono<Object> resolvedValue = Mono.error(new UnsupportedMediaTypeStatusException("boo"));
|
||||
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
|
||||
@@ -111,7 +106,6 @@ public class InvocableHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void illegalArgumentExceptionIsWrappedWithInvocationDetails() throws Exception {
|
||||
|
||||
Mono<Object> resolvedValue = Mono.just(1);
|
||||
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
|
||||
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
|
||||
@@ -129,7 +123,6 @@ public class InvocableHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void invocationTargetExceptionIsUnwrapped() throws Exception {
|
||||
|
||||
Method method = on(TestController.class).mockCall(TestController::exceptionMethod).method();
|
||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||
|
||||
@@ -144,7 +137,6 @@ public class InvocableHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void invokeMethodWithResponseStatus() throws Exception {
|
||||
|
||||
Method method = on(TestController.class).annotPresent(ResponseStatus.class).resolveMethod();
|
||||
Mono<HandlerResult> mono = invoke(new TestController(), method);
|
||||
|
||||
@@ -175,9 +167,7 @@ public class InvocableHandlerMethodTests {
|
||||
private void assertHandlerResultValue(Mono<HandlerResult> mono, String expected) {
|
||||
StepVerifier.create(mono)
|
||||
.consumeNextWith(result -> {
|
||||
Optional<?> optional = result.getReturnValue();
|
||||
assertTrue(optional.isPresent());
|
||||
assertEquals(expected, optional.get());
|
||||
assertEquals(expected, result.getReturnValue());
|
||||
})
|
||||
.expectComplete()
|
||||
.verify();
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -353,10 +352,10 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
HandlerResult result = mono.block();
|
||||
assertNotNull(result);
|
||||
|
||||
Optional<Object> value = result.getReturnValue();
|
||||
assertTrue(value.isPresent());
|
||||
assertEquals(HttpHeaders.class, value.get().getClass());
|
||||
assertEquals(allowedMethods, ((HttpHeaders) value.get()).getAllow());
|
||||
Object value = result.getReturnValue();
|
||||
assertNotNull(value);
|
||||
assertEquals(HttpHeaders.class, value.getClass());
|
||||
assertEquals(allowedMethods, ((HttpHeaders) value).getAllow());
|
||||
}
|
||||
|
||||
private void testMediaTypeNotAcceptable(String url) throws Exception {
|
||||
@@ -490,4 +489,4 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ControllerAdviceTests {
|
||||
TestController controller = context.getBean(TestController.class);
|
||||
controller.setException(exception);
|
||||
|
||||
Object actual = handle(adapter, controller, "handle").getReturnValue().orElse(null);
|
||||
Object actual = handle(adapter, controller, "handle").getReturnValue();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,12 +37,10 @@ import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||
import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.toFlux;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.*;
|
||||
|
||||
/**
|
||||
* @author Sebastien Deleuze
|
||||
@@ -112,18 +110,18 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
|
||||
StepVerifier.create(result)
|
||||
.consumeNextWith( event -> {
|
||||
assertEquals("0", event.id().get());
|
||||
assertEquals("foo", event.data().get());
|
||||
assertEquals("bar", event.comment().get());
|
||||
assertFalse(event.event().isPresent());
|
||||
assertFalse(event.retry().isPresent());
|
||||
assertEquals("0", event.id());
|
||||
assertEquals("foo", event.data());
|
||||
assertEquals("bar", event.comment());
|
||||
assertNull(event.event());
|
||||
assertNull(event.retry());
|
||||
})
|
||||
.consumeNextWith( event -> {
|
||||
assertEquals("1", event.id().get());
|
||||
assertEquals("foo", event.data().get());
|
||||
assertEquals("bar", event.comment().get());
|
||||
assertFalse(event.event().isPresent());
|
||||
assertFalse(event.retry().isPresent());
|
||||
assertEquals("1", event.id());
|
||||
assertEquals("foo", event.data());
|
||||
assertEquals("bar", event.comment());
|
||||
assertNull(event.event());
|
||||
assertNull(event.retry());
|
||||
})
|
||||
.thenCancel()
|
||||
.verify(Duration.ofSeconds(5L));
|
||||
@@ -140,18 +138,18 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||
|
||||
StepVerifier.create(result)
|
||||
.consumeNextWith( event -> {
|
||||
assertEquals("0", event.id().get());
|
||||
assertEquals("foo", event.data().get());
|
||||
assertEquals("bar", event.comment().get());
|
||||
assertFalse(event.event().isPresent());
|
||||
assertFalse(event.retry().isPresent());
|
||||
assertEquals("0", event.id());
|
||||
assertEquals("foo", event.data());
|
||||
assertEquals("bar", event.comment());
|
||||
assertNull(event.event());
|
||||
assertNull(event.retry());
|
||||
})
|
||||
.consumeNextWith( event -> {
|
||||
assertEquals("1", event.id().get());
|
||||
assertEquals("foo", event.data().get());
|
||||
assertEquals("bar", event.comment().get());
|
||||
assertFalse(event.event().isPresent());
|
||||
assertFalse(event.retry().isPresent());
|
||||
assertEquals("1", event.id());
|
||||
assertEquals("foo", event.data());
|
||||
assertEquals("bar", event.comment());
|
||||
assertNull(event.event());
|
||||
assertNull(event.retry());
|
||||
})
|
||||
.thenCancel()
|
||||
.verify(Duration.ofSeconds(5L));
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.result.view;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -23,29 +23,23 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.ui.ExtendedModelMap;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultRenderingBuilder}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class DefaultRenderingBuilderTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void defaultValues() {
|
||||
Rendering rendering = Rendering.view("abc").build();
|
||||
|
||||
assertEquals("abc", rendering.view().orElse(null));
|
||||
assertEquals("abc", rendering.view());
|
||||
assertEquals(Collections.emptyMap(), rendering.modelAttributes());
|
||||
assertNull(rendering.status().orElse(null));
|
||||
assertNull(rendering.status());
|
||||
assertEquals(0, rendering.headers().size());
|
||||
}
|
||||
|
||||
@@ -53,7 +47,7 @@ public class DefaultRenderingBuilderTests {
|
||||
public void defaultValuesForRedirect() throws Exception {
|
||||
Rendering rendering = Rendering.redirectTo("abc").build();
|
||||
|
||||
Object view = rendering.view().orElse(null);
|
||||
Object view = rendering.view();
|
||||
assertEquals(RedirectView.class, view.getClass());
|
||||
assertEquals("abc", ((RedirectView) view).getUrl());
|
||||
assertTrue(((RedirectView) view).isContextRelative());
|
||||
@@ -64,7 +58,7 @@ public class DefaultRenderingBuilderTests {
|
||||
@Test
|
||||
public void viewName() {
|
||||
Rendering rendering = Rendering.view("foo").build();
|
||||
assertEquals("foo", rendering.view().orElse(null));
|
||||
assertEquals("foo", rendering.view());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +112,7 @@ public class DefaultRenderingBuilderTests {
|
||||
public void redirectWithAbsoluteUrl() throws Exception {
|
||||
Rendering rendering = Rendering.redirectTo("foo").contextRelative(false).build();
|
||||
|
||||
Object view = rendering.view().orElse(null);
|
||||
Object view = rendering.view();
|
||||
assertEquals(RedirectView.class, view.getClass());
|
||||
assertFalse(((RedirectView) view).isContextRelative());
|
||||
}
|
||||
@@ -127,7 +121,7 @@ public class DefaultRenderingBuilderTests {
|
||||
public void redirectWithPropagateQuery() throws Exception {
|
||||
Rendering rendering = Rendering.redirectTo("foo").propagateQuery(true).build();
|
||||
|
||||
Object view = rendering.view().orElse(null);
|
||||
Object view = rendering.view();
|
||||
assertEquals(RedirectView.class, view.getClass());
|
||||
assertTrue(((RedirectView) view).isPropagateQuery());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.springframework.web.reactive.socket;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -69,19 +71,16 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests
|
||||
|
||||
@Test
|
||||
public void subProtocol() throws Exception {
|
||||
|
||||
String protocol = "echo-v1";
|
||||
AtomicReference<HandshakeInfo> infoRef = new AtomicReference<>();
|
||||
MonoProcessor<Object> output = MonoProcessor.create();
|
||||
|
||||
client.execute(getUrl("/sub-protocol"),
|
||||
new WebSocketHandler() {
|
||||
|
||||
@Override
|
||||
public String[] getSubProtocols() {
|
||||
return new String[] {protocol};
|
||||
public List<String> getSubProtocols() {
|
||||
return Collections.singletonList(protocol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(WebSocketSession session) {
|
||||
infoRef.set(session.getHandshakeInfo());
|
||||
@@ -96,7 +95,7 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests
|
||||
HandshakeInfo info = infoRef.get();
|
||||
assertThat(info.getHeaders().getFirst("Upgrade"), Matchers.equalToIgnoringCase("websocket"));
|
||||
assertEquals(protocol, info.getHeaders().getFirst("Sec-WebSocket-Protocol"));
|
||||
assertEquals("Wrong protocol accepted", protocol, info.getSubProtocol().orElse("none"));
|
||||
assertEquals("Wrong protocol accepted", protocol, info.getSubProtocol());
|
||||
assertEquals("Wrong protocol detected on the server side", protocol, output.block(Duration.ofMillis(5000)));
|
||||
}
|
||||
|
||||
@@ -122,7 +121,6 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests
|
||||
|
||||
@Bean
|
||||
public HandlerMapping handlerMapping() {
|
||||
|
||||
Map<String, WebSocketHandler> map = new HashMap<>();
|
||||
map.put("/echo", new EchoWebSocketHandler());
|
||||
map.put("/sub-protocol", new SubProtocolWebSocketHandler());
|
||||
@@ -149,13 +147,13 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests
|
||||
private static class SubProtocolWebSocketHandler implements WebSocketHandler {
|
||||
|
||||
@Override
|
||||
public String[] getSubProtocols() {
|
||||
return new String[] {"echo-v1"};
|
||||
public List<String> getSubProtocols() {
|
||||
return Collections.singletonList("echo-v1");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(WebSocketSession session) {
|
||||
String protocol = session.getHandshakeInfo().getSubProtocol().orElse("none");
|
||||
String protocol = session.getHandshakeInfo().getSubProtocol();
|
||||
WebSocketMessage message = session.textMessage(protocol);
|
||||
return doSend(session, Mono.just(message));
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.socket.client;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -24,6 +25,7 @@ import java.util.function.Function;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.reactivex.netty.protocol.http.HttpHandlerNames;
|
||||
import io.reactivex.netty.protocol.http.client.HttpClient;
|
||||
import io.reactivex.netty.protocol.http.client.HttpClientRequest;
|
||||
import io.reactivex.netty.protocol.http.ws.WebSocketConnection;
|
||||
@@ -39,12 +41,11 @@ import rx.RxReactiveStreams;
|
||||
import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.reactive.socket.HandshakeInfo;
|
||||
import org.springframework.web.reactive.socket.WebSocketHandler;
|
||||
import org.springframework.web.reactive.socket.adapter.RxNettyWebSocketSession;
|
||||
|
||||
import static io.reactivex.netty.protocol.http.HttpHandlerNames.WsClientDecoder;
|
||||
|
||||
/**
|
||||
* {@link WebSocketClient} implementation for use with RxNetty.
|
||||
* For internal use within the framework.
|
||||
@@ -125,7 +126,7 @@ public class RxNettyWebSocketClient extends WebSocketClientSupport implements We
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
private Observable<Void> executeInternal(URI url, HttpHeaders headers, WebSocketHandler handler) {
|
||||
String[] protocols = beforeHandshake(url, headers, handler);
|
||||
List<String> protocols = beforeHandshake(url, headers, handler);
|
||||
return createRequest(url, headers, protocols)
|
||||
.flatMap(response -> {
|
||||
Observable<WebSocketConnection> conn = response.getWebSocketConnection();
|
||||
@@ -141,13 +142,13 @@ public class RxNettyWebSocketClient extends WebSocketClientSupport implements We
|
||||
ByteBufAllocator allocator = response.unsafeNettyChannel().alloc();
|
||||
NettyDataBufferFactory factory = new NettyDataBufferFactory(allocator);
|
||||
RxNettyWebSocketSession session = new RxNettyWebSocketSession(conn, info, factory);
|
||||
session.aggregateFrames(response.unsafeNettyChannel(), WsClientDecoder.getName());
|
||||
session.aggregateFrames(response.unsafeNettyChannel(), HttpHandlerNames.WsClientDecoder.getName());
|
||||
|
||||
return RxReactiveStreams.toObservable(handler.handle(session));
|
||||
});
|
||||
}
|
||||
|
||||
private WebSocketRequest<ByteBuf> createRequest(URI url, HttpHeaders headers, String[] protocols) {
|
||||
private WebSocketRequest<ByteBuf> createRequest(URI url, HttpHeaders headers, List<String> protocols) {
|
||||
String query = url.getRawQuery();
|
||||
String requestUrl = url.getRawPath() + (query != null ? "?" + query : "");
|
||||
HttpClientRequest<ByteBuf, ByteBuf> request = getHttpClient(url).createGet(requestUrl);
|
||||
@@ -158,9 +159,8 @@ public class RxNettyWebSocketClient extends WebSocketClientSupport implements We
|
||||
request = request.setHeaders(map);
|
||||
}
|
||||
|
||||
return (ObjectUtils.isEmpty(protocols) ?
|
||||
request.requestWebSocketUpgrade() :
|
||||
request.requestWebSocketUpgrade().requestSubProtocols(protocols));
|
||||
return (ObjectUtils.isEmpty(protocols) ? request.requestWebSocketUpgrade() :
|
||||
request.requestWebSocketUpgrade().requestSubProtocols(StringUtils.toStringArray(protocols)));
|
||||
}
|
||||
|
||||
private HttpHeaders toHttpHeaders(WebSocketResponse<ByteBuf> response) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.socket.server.upgrade;
|
||||
|
||||
import java.security.Principal;
|
||||
@@ -40,14 +41,10 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
*/
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
public class RxNettyRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
|
||||
Optional<String> subProtocol) {
|
||||
|
||||
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, String subProtocol) {
|
||||
RxNettyServerHttpResponse response = (RxNettyServerHttpResponse) exchange.getResponse();
|
||||
HttpServerResponse<?> rxNettyResponse = response.getRxNettyResponse();
|
||||
|
||||
@@ -62,18 +59,18 @@ public class RxNettyRequestUpgradeStrategy implements RequestUpgradeStrategy {
|
||||
return RxReactiveStreams.toObservable(handler.handle(session));
|
||||
});
|
||||
|
||||
if (subProtocol.isPresent()) {
|
||||
handshaker = handshaker.subprotocol(subProtocol.get());
|
||||
if (subProtocol != null) {
|
||||
handshaker = handshaker.subprotocol(subProtocol);
|
||||
}
|
||||
else {
|
||||
// TODO: https://github.com/reactor/reactor-netty/issues/20
|
||||
handshaker = handshaker.subprotocol(new String[0]);
|
||||
handshaker = handshaker.subprotocol();
|
||||
}
|
||||
|
||||
return Mono.from(RxReactiveStreams.toPublisher(handshaker));
|
||||
}
|
||||
|
||||
private HandshakeInfo getHandshakeInfo(ServerWebExchange exchange, Optional<String> protocol) {
|
||||
private HandshakeInfo getHandshakeInfo(ServerWebExchange exchange, String protocol) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
Mono<Principal> principal = exchange.getPrincipal();
|
||||
return new HandshakeInfo(request.getURI(), request.getHeaders(), principal, protocol);
|
||||
|
||||
Reference in New Issue
Block a user