Apply "instanceof pattern matching" in spring-webflux
This commit also applies additional clean-up tasks such as the following. - final fields - diamond operator (<>) for anonymous inner classes - multi-catch This has only been applied to `src/main/java`.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,7 +66,7 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
|
||||
};
|
||||
|
||||
|
||||
private ExchangeStrategies strategies;
|
||||
private final ExchangeStrategies strategies;
|
||||
|
||||
private int statusCode = 200;
|
||||
|
||||
@@ -104,8 +104,8 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
|
||||
this.headers.addAll(other.headers().asHttpHeaders());
|
||||
}
|
||||
this.originalResponse = other;
|
||||
this.request = (other instanceof DefaultClientResponse ?
|
||||
((DefaultClientResponse) other).request() : EMPTY_REQUEST);
|
||||
this.request = (other instanceof DefaultClientResponse defaultClientResponse ?
|
||||
defaultClientResponse.request() : EMPTY_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -116,8 +116,7 @@ public abstract class ExchangeFilterFunctions {
|
||||
public static ExchangeFilterFunction basicAuthentication() {
|
||||
return (request, next) -> {
|
||||
Object attr = request.attributes().get(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE);
|
||||
if (attr instanceof Credentials) {
|
||||
Credentials cred = (Credentials) attr;
|
||||
if (attr instanceof Credentials cred) {
|
||||
return next.exchange(ClientRequest.from(request)
|
||||
.headers(headers -> headers.setBasicAuth(cred.username, cred.password))
|
||||
.build());
|
||||
@@ -174,10 +173,9 @@ public abstract class ExchangeFilterFunctions {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof Credentials)) {
|
||||
if (!(other instanceof Credentials otherCred)) {
|
||||
return false;
|
||||
}
|
||||
Credentials otherCred = (Credentials) other;
|
||||
return (this.username.equals(otherCred.username) && this.password.equals(otherCred.password));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,8 +70,7 @@ class ChangePathPatternParserVisitor implements RouterFunctions.Visitor {
|
||||
}
|
||||
|
||||
private void changeParser(RequestPredicate predicate) {
|
||||
if (predicate instanceof Target) {
|
||||
Target target = (Target) predicate;
|
||||
if (predicate instanceof Target target) {
|
||||
target.changeParser(this.parser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ class DefaultEntityResponseBuilder<T> implements EntityResponse.Builder<T> {
|
||||
|
||||
@Override
|
||||
public Mono<EntityResponse<T>> build() {
|
||||
return Mono.just(new DefaultEntityResponse<T>(
|
||||
return Mono.just(new DefaultEntityResponse<>(
|
||||
this.status, this.headers, this.cookies, this.entity, this.inserter, this.hints));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,7 +69,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
|
||||
|
||||
private final List<HttpMessageReader<?>> messageReaders;
|
||||
|
||||
private ServerWebExchange exchange;
|
||||
private final ServerWebExchange exchange;
|
||||
|
||||
private String methodName;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,8 +78,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
|
||||
Assert.notNull(other, "ServerResponse must not be null");
|
||||
this.headers.addAll(other.headers());
|
||||
this.cookies.addAll(other.cookies());
|
||||
if (other instanceof AbstractServerResponse) {
|
||||
AbstractServerResponse abstractOther = (AbstractServerResponse) other;
|
||||
if (other instanceof AbstractServerResponse abstractOther) {
|
||||
this.statusCode = abstractOther.statusCode;
|
||||
this.hints.putAll(abstractOther.hints);
|
||||
}
|
||||
|
||||
@@ -153,8 +153,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
|
||||
Object handler = this.handlerMap.get(pattern);
|
||||
|
||||
// Bean name or resolved handler?
|
||||
if (handler instanceof String) {
|
||||
String handlerName = (String) handler;
|
||||
if (handler instanceof String handlerName) {
|
||||
handler = obtainApplicationContext().getBean(handlerName);
|
||||
}
|
||||
|
||||
@@ -223,8 +222,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
|
||||
}
|
||||
|
||||
// Eagerly resolve handler if referencing singleton via name.
|
||||
if (!this.lazyInitHandlers && handler instanceof String) {
|
||||
String handlerName = (String) handler;
|
||||
if (!this.lazyInitHandlers && handler instanceof String handlerName) {
|
||||
if (obtainApplicationContext().isSingleton(handlerName)) {
|
||||
resolvedHandler = obtainApplicationContext().getBean(handlerName);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -288,10 +288,9 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof ContentChunkInfo)) {
|
||||
if (!(other instanceof ContentChunkInfo otherCci)) {
|
||||
return false;
|
||||
}
|
||||
ContentChunkInfo otherCci = (ContentChunkInfo) other;
|
||||
return (this.start == otherCci.start && this.end == otherCci.end);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.web.util.UriUtils;
|
||||
* expected to be configured at the end in a chain of resolvers.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
* @since 5.0
|
||||
*/
|
||||
public class PathResourceResolver extends AbstractResourceResolver {
|
||||
@@ -119,11 +120,12 @@ public class PathResourceResolver extends AbstractResourceResolver {
|
||||
return Mono.just(resource);
|
||||
}
|
||||
else if (logger.isWarnEnabled()) {
|
||||
Resource[] allowedLocations = getAllowedLocations();
|
||||
logger.warn("Resource path \"" + resourcePath + "\" was successfully resolved " +
|
||||
"but resource \"" + resource.getURL() + "\" is neither under the " +
|
||||
"current location \"" + location.getURL() + "\" nor under any of the " +
|
||||
"allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]"));
|
||||
Object allowedLocationsText = (getAllowedLocations() != null ? Arrays.asList(getAllowedLocations()) : "[]");
|
||||
logger.warn("""
|
||||
Resource path "%s" was successfully resolved, but resource \
|
||||
"%s" is neither under the current location "%s" nor under any \
|
||||
of the allowed locations %s"\
|
||||
""".formatted(resourcePath, resource.getURL(),location.getURL(), allowedLocationsText));
|
||||
}
|
||||
}
|
||||
return Mono.empty();
|
||||
@@ -177,8 +179,8 @@ public class PathResourceResolver extends AbstractResourceResolver {
|
||||
resourcePath = resource.getURL().toExternalForm();
|
||||
locationPath = StringUtils.cleanPath(location.getURL().toString());
|
||||
}
|
||||
else if (resource instanceof ClassPathResource) {
|
||||
resourcePath = ((ClassPathResource) resource).getPath();
|
||||
else if (resource instanceof ClassPathResource classPathResource) {
|
||||
resourcePath = classPathResource.getPath();
|
||||
locationPath = StringUtils.cleanPath(((ClassPathResource) location).getPath());
|
||||
}
|
||||
else {
|
||||
@@ -203,10 +205,7 @@ public class PathResourceResolver extends AbstractResourceResolver {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// May not be possible to decode...
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
catch (IllegalArgumentException | UnsupportedEncodingException ex) {
|
||||
// Should never happen...
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,8 +106,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
|
||||
mappings.forEach(mapping ->
|
||||
mapping.getHandlerMap().forEach((pattern, handler) -> {
|
||||
if (handler instanceof ResourceWebHandler) {
|
||||
ResourceWebHandler resourceHandler = (ResourceWebHandler) handler;
|
||||
if (handler instanceof ResourceWebHandler resourceHandler) {
|
||||
this.handlerMap.put(pattern, resourceHandler);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -354,8 +354,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
|
||||
return;
|
||||
}
|
||||
for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
|
||||
if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
|
||||
PathResourceResolver resolver = (PathResourceResolver) getResourceResolvers().get(i);
|
||||
if (getResourceResolvers().get(i) instanceof PathResourceResolver resolver) {
|
||||
if (ObjectUtils.isEmpty(resolver.getAllowedLocations())) {
|
||||
resolver.setAllowedLocations(getLocations().toArray(new Resource[0]));
|
||||
}
|
||||
@@ -522,10 +521,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// May not be possible to decode...
|
||||
}
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
catch (IllegalArgumentException | UnsupportedEncodingException ex) {
|
||||
// Should never happen...
|
||||
}
|
||||
}
|
||||
@@ -609,9 +605,8 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
|
||||
headers.setContentType(mediaType);
|
||||
}
|
||||
|
||||
if (resource instanceof HttpResource) {
|
||||
HttpHeaders resourceHeaders = ((HttpResource) resource).getResponseHeaders();
|
||||
exchange.getResponse().getHeaders().putAll(resourceHeaders);
|
||||
if (resource instanceof HttpResource httpResource) {
|
||||
exchange.getResponse().getHeaders().putAll(httpResource.getResponseHeaders());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -65,7 +65,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
*/
|
||||
public class VersionResourceResolver extends AbstractResourceResolver {
|
||||
|
||||
private AntPathMatcher pathMatcher = new AntPathMatcher();
|
||||
private final AntPathMatcher pathMatcher = new AntPathMatcher();
|
||||
|
||||
/** Map from path pattern -> VersionStrategy. */
|
||||
private final Map<String, VersionStrategy> versionStrategyMap = new LinkedHashMap<>();
|
||||
@@ -315,8 +315,8 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
||||
|
||||
@Override
|
||||
public HttpHeaders getResponseHeaders() {
|
||||
HttpHeaders headers = (this.original instanceof HttpResource ?
|
||||
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
|
||||
HttpHeaders headers = (this.original instanceof HttpResource httpResource ?
|
||||
httpResource.getResponseHeaders() : new HttpHeaders());
|
||||
headers.setETag("W/\"" + this.version + "\"");
|
||||
return headers;
|
||||
}
|
||||
|
||||
@@ -200,8 +200,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
* @param handler the bean name of a handler or a handler instance
|
||||
*/
|
||||
protected void detectHandlerMethods(final Object handler) {
|
||||
Class<?> handlerType = (handler instanceof String ?
|
||||
obtainApplicationContext().getType((String) handler) : handler.getClass());
|
||||
Class<?> handlerType = (handler instanceof String beanName ?
|
||||
obtainApplicationContext().getType(beanName) : handler.getClass());
|
||||
|
||||
if (handlerType != null) {
|
||||
final Class<?> userType = ClassUtils.getUserClass(handlerType);
|
||||
@@ -258,8 +258,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
* @return the created HandlerMethod
|
||||
*/
|
||||
protected HandlerMethod createHandlerMethod(Object handler, Method method) {
|
||||
if (handler instanceof String) {
|
||||
return new HandlerMethod((String) handler,
|
||||
if (handler instanceof String beanName) {
|
||||
return new HandlerMethod(beanName,
|
||||
obtainApplicationContext().getAutowireCapableBeanFactory(),
|
||||
obtainApplicationContext(),
|
||||
method);
|
||||
@@ -397,14 +397,13 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
@Override
|
||||
protected boolean hasCorsConfigurationSource(Object handler) {
|
||||
return super.hasCorsConfigurationSource(handler) ||
|
||||
(handler instanceof HandlerMethod && this.mappingRegistry.getCorsConfiguration((HandlerMethod) handler) != null);
|
||||
(handler instanceof HandlerMethod handlerMethod && this.mappingRegistry.getCorsConfiguration(handlerMethod) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) {
|
||||
CorsConfiguration corsConfig = super.getCorsConfiguration(handler, exchange);
|
||||
if (handler instanceof HandlerMethod) {
|
||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||
if (handler instanceof HandlerMethod handlerMethod) {
|
||||
if (handlerMethod.equals(PREFLIGHT_AMBIGUOUS_MATCH)) {
|
||||
return ALLOW_CORS_CONFIG;
|
||||
}
|
||||
|
||||
@@ -224,8 +224,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
return true;
|
||||
}
|
||||
Type parameterType = returnType.getGenericParameterType();
|
||||
if (parameterType instanceof ParameterizedType) {
|
||||
ParameterizedType type = (ParameterizedType) parameterType;
|
||||
if (parameterType instanceof ParameterizedType type) {
|
||||
if (type.getActualTypeArguments().length == 1) {
|
||||
return Void.class.equals(type.getActualTypeArguments()[0]);
|
||||
}
|
||||
|
||||
@@ -343,10 +343,9 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof RequestMappingInfo)) {
|
||||
if (!(other instanceof RequestMappingInfo otherInfo)) {
|
||||
return false;
|
||||
}
|
||||
RequestMappingInfo otherInfo = (RequestMappingInfo) other;
|
||||
return (this.patternsCondition.equals(otherInfo.patternsCondition) &&
|
||||
this.methodsCondition.equals(otherInfo.methodsCondition) &&
|
||||
this.paramsCondition.equals(otherInfo.paramsCondition) &&
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -72,7 +72,7 @@ public class RequestContext {
|
||||
private Map<String, Errors> errorsMap;
|
||||
|
||||
@Nullable
|
||||
private RequestDataValueProcessor dataValueProcessor;
|
||||
private final RequestDataValueProcessor dataValueProcessor;
|
||||
|
||||
|
||||
public RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource) {
|
||||
@@ -92,8 +92,8 @@ public class RequestContext {
|
||||
LocaleContext localeContext = exchange.getLocaleContext();
|
||||
Locale locale = localeContext.getLocale();
|
||||
this.locale = (locale != null ? locale : Locale.getDefault());
|
||||
TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext ?
|
||||
((TimeZoneAwareLocaleContext) localeContext).getTimeZone() : null);
|
||||
TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext tzaLocaleContext ?
|
||||
tzaLocaleContext.getTimeZone() : null);
|
||||
this.timeZone = (timeZone != null ? timeZone : TimeZone.getDefault());
|
||||
|
||||
this.defaultHtmlEscape = null; // TODO
|
||||
@@ -385,15 +385,15 @@ public class RequestContext {
|
||||
}
|
||||
}
|
||||
|
||||
if (errors instanceof BindException) {
|
||||
errors = ((BindException) errors).getBindingResult();
|
||||
if (errors instanceof BindException bindException) {
|
||||
errors = bindException.getBindingResult();
|
||||
}
|
||||
|
||||
if (htmlEscape && !(errors instanceof EscapedErrors)) {
|
||||
errors = new EscapedErrors(errors);
|
||||
}
|
||||
else if (!htmlEscape && errors instanceof EscapedErrors) {
|
||||
errors = ((EscapedErrors) errors).getSource();
|
||||
else if (!htmlEscape && errors instanceof EscapedErrors escapedErrors) {
|
||||
errors = escapedErrors.getSource();
|
||||
}
|
||||
|
||||
this.errorsMap.put(name, errors);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ public abstract class ViewResolverSupport implements Ordered {
|
||||
public static final MediaType DEFAULT_CONTENT_TYPE = MediaType.parseMediaType("text/html;charset=UTF-8");
|
||||
|
||||
|
||||
private List<MediaType> mediaTypes = new ArrayList<>(4);
|
||||
private final List<MediaType> mediaTypes = new ArrayList<>(4);
|
||||
|
||||
private Charset defaultCharset = StandardCharsets.UTF_8;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -239,10 +239,9 @@ public final class CloseStatus {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof CloseStatus)) {
|
||||
if (!(other instanceof CloseStatus otherStatus)) {
|
||||
return false;
|
||||
}
|
||||
CloseStatus otherStatus = (CloseStatus) other;
|
||||
return (this.code == otherStatus.code &&
|
||||
ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -151,10 +151,9 @@ public class WebSocketMessage {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof WebSocketMessage)) {
|
||||
if (!(other instanceof WebSocketMessage otherMessage)) {
|
||||
return false;
|
||||
}
|
||||
WebSocketMessage otherMessage = (WebSocketMessage) other;
|
||||
return (this.type.equals(otherMessage.type) &&
|
||||
ObjectUtils.nullSafeEquals(this.payload, otherMessage.payload));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,13 +41,14 @@ import org.springframework.web.reactive.socket.WebSocketSession;
|
||||
*
|
||||
* @author Violeta Georgieva
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
* @since 5.0
|
||||
*/
|
||||
public class StandardWebSocketHandlerAdapter extends Endpoint {
|
||||
|
||||
private final WebSocketHandler delegateHandler;
|
||||
|
||||
private Function<Session, StandardWebSocketSession> sessionFactory;
|
||||
private final Function<Session, StandardWebSocketSession> sessionFactory;
|
||||
|
||||
@Nullable
|
||||
private StandardWebSocketSession delegateSession;
|
||||
@@ -89,16 +90,16 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
|
||||
private <T> WebSocketMessage toMessage(T message) {
|
||||
WebSocketSession session = this.delegateSession;
|
||||
Assert.state(session != null, "Cannot create message without a session");
|
||||
if (message instanceof String) {
|
||||
byte[] bytes = ((String) message).getBytes(StandardCharsets.UTF_8);
|
||||
if (message instanceof String text) {
|
||||
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
|
||||
return new WebSocketMessage(Type.TEXT, session.bufferFactory().wrap(bytes));
|
||||
}
|
||||
else if (message instanceof ByteBuffer) {
|
||||
DataBuffer buffer = session.bufferFactory().wrap((ByteBuffer) message);
|
||||
else if (message instanceof ByteBuffer byteBuffer) {
|
||||
DataBuffer buffer = session.bufferFactory().wrap(byteBuffer);
|
||||
return new WebSocketMessage(Type.BINARY, buffer);
|
||||
}
|
||||
else if (message instanceof PongMessage) {
|
||||
DataBuffer buffer = session.bufferFactory().wrap(((PongMessage) message).getApplicationData());
|
||||
else if (message instanceof PongMessage pongMessage) {
|
||||
DataBuffer buffer = session.bufferFactory().wrap(pongMessage.getApplicationData());
|
||||
return new WebSocketMessage(Type.PONG, buffer);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user