diff --git a/spring-websocket/src/main/java/org/springframework/websocket/client/AbstractEndpointConnectionManager.java b/spring-websocket/src/main/java/org/springframework/websocket/client/AbstractEndpointConnectionManager.java index 1cb0d35102..a95b9ab53f 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/client/AbstractEndpointConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/client/AbstractEndpointConnectionManager.java @@ -101,9 +101,8 @@ public abstract class AbstractEndpointConnectionManager implements ApplicationCo } /** - * Set whether to auto-connect to the {@link #setDefaultUri(URI) default URI} after - * this endpoint connection factory has been initialized and the Spring context has - * been refreshed. + * Set whether to auto-connect to the remote endpoint after this connection manager + * has been initialized and the Spring context has been refreshed. *

Default is "false". */ public void setAutoStartup(boolean autoStartup) { @@ -112,17 +111,17 @@ public abstract class AbstractEndpointConnectionManager implements ApplicationCo /** * Return the value for the 'autoStartup' property. If "true", this endpoint - * connection factory will connect to the {@link #setDefaultUri(URI) default URI} upon - * a ContextRefreshedEvent. + * connection manager will connect to the remote endpoint upon a + * ContextRefreshedEvent. */ public boolean isAutoStartup() { return this.autoStartup; } /** - * Specify the phase in which this endpoint connection factory should be - * auto-connected and closed. The startup order proceeds from lowest to highest, and - * the shutdown order is the reverse of that. By default this value is + * Specify the phase in which a connection should be established to the remote + * endpoint and subsequently closed. The startup order proceeds from lowest to + * highest, and the shutdown order is the reverse of that. By default this value is * Integer.MAX_VALUE meaning that this endpoint connection factory connects as late as * possible and is closed as soon as possible. */ diff --git a/spring-websocket/src/main/java/org/springframework/websocket/server/endpoint/EndpointRegistration.java b/spring-websocket/src/main/java/org/springframework/websocket/server/endpoint/EndpointRegistration.java index 12367774fb..843cb07598 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/server/endpoint/EndpointRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/server/endpoint/EndpointRegistration.java @@ -17,7 +17,6 @@ package org.springframework.websocket.server.endpoint; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,6 +36,7 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebApplicationContext; +import org.springframework.websocket.endpoint.StandardWebSocketHandlerAdapter; /** @@ -60,16 +60,20 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw private final Object endpointBean; + private List> encoders; + + private List> decoders; + private List subprotocols = new ArrayList(); private List extensions = new ArrayList(); - private Map userProperties = new HashMap(); + private final Map userProperties = new HashMap(); + + private Configurator configurator = new Configurator() {}; private BeanFactory beanFactory; - private final Configurator configurator = new Configurator() {}; - /** * Class constructor with the {@code javax.webscoket.Endpoint} class. @@ -138,18 +142,13 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw return (Endpoint) bean; } - @Override - public List getSubprotocols() { - return this.subprotocols; - } - public void setSubprotocols(List subprotocols) { this.subprotocols = subprotocols; } @Override - public List getExtensions() { - return this.extensions; + public List getSubprotocols() { + return this.subprotocols; } public void setExtensions(List extensions) { @@ -157,23 +156,37 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw this.extensions = extensions; } + @Override + public List getExtensions() { + return this.extensions; + } + + public void setUserProperties(Map userProperties) { + this.userProperties.clear(); + this.userProperties.putAll(userProperties); + } + @Override public Map getUserProperties() { return this.userProperties; } - public void setUserProperties(Map userProperties) { - this.userProperties = userProperties; + public void setEncoders(List> encoders) { + this.encoders = encoders; } @Override public List> getEncoders() { - return Collections.emptyList(); + return this.encoders; + } + + public void setDecoders(List> decoders) { + this.decoders = decoders; } @Override public List> getDecoders() { - return Collections.emptyList(); + return this.decoders; } @Override @@ -181,6 +194,13 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw this.beanFactory = beanFactory; } + /** + * The {@link Configurator#getEndpointInstance(Class)} method is always ignored. + */ + public void setConfigurator(Configurator configurator) { + this.configurator = configurator; + } + @Override public Configurator getConfigurator() { return new Configurator() { @@ -191,37 +211,21 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw } @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { - EndpointRegistration.this.modifyHandshake(request, response); + EndpointRegistration.this.configurator.modifyHandshake(sec, request, response); } @Override public boolean checkOrigin(String originHeaderValue) { - return EndpointRegistration.this.checkOrigin(originHeaderValue); + return EndpointRegistration.this.configurator.checkOrigin(originHeaderValue); } @Override public String getNegotiatedSubprotocol(List supported, List requested) { - return EndpointRegistration.this.selectSubProtocol(requested); + return EndpointRegistration.this.configurator.getNegotiatedSubprotocol(supported, requested); } @Override public List getNegotiatedExtensions(List installed, List requested) { - return EndpointRegistration.this.selectExtensions(requested); + return EndpointRegistration.this.configurator.getNegotiatedExtensions(installed, requested); } }; } - protected void modifyHandshake(HandshakeRequest request, HandshakeResponse response) { - this.configurator.modifyHandshake(this, request, response); - } - - protected boolean checkOrigin(String originHeaderValue) { - return this.configurator.checkOrigin(originHeaderValue); - } - - protected String selectSubProtocol(List requested) { - return this.configurator.getNegotiatedSubprotocol(getSubprotocols(), requested); - } - - protected List selectExtensions(List requested) { - return this.configurator.getNegotiatedExtensions(getExtensions(), requested); - } - }