Browse Source

Update ServerEndpointRegistration

In addition to implementing ServerEndpointConfig, the
ServerEndpointRegistration now also extends
ServerEndpointConfig.Configurator making it easier to override
handshake customization methods without having to extend a separate
class.
pull/337/merge
Rossen Stoyanchev 13 years ago
parent
commit
48996cf572
  1. 77
      spring-websocket/src/main/java/org/springframework/web/socket/server/endpoint/ServerEndpointRegistration.java

77
spring-websocket/src/main/java/org/springframework/web/socket/server/endpoint/ServerEndpointRegistration.java

@ -36,19 +36,26 @@ import org.springframework.util.Assert;
import org.springframework.web.socket.support.BeanCreatingHandlerProvider; import org.springframework.web.socket.support.BeanCreatingHandlerProvider;
/** /**
* An implementation of {@link javax.websocket.server.ServerEndpointConfig} that also * An implementation of {@link javax.websocket.server.ServerEndpointConfig} for use in
* contains the target {@link javax.websocket.Endpoint}, provided either as a reference or * Spring applications. A {@link ServerEndpointRegistration} bean is detected by
* as a bean name.
*
* <p>{@link ServerEndpointRegistration} beans are detected by
* {@link ServerEndpointExporter} and registered with a Java WebSocket runtime at startup. * {@link ServerEndpointExporter} and registered with a Java WebSocket runtime at startup.
* *
* <p>Class constructors accept a singleton {@link javax.websocket.Endpoint} instance
* or an Endpoint specified by type {@link Class}. When specified by type, the endpoint
* will be instantiated and initialized through the Spring ApplicationContext before
* each client WebSocket connection.
*
* <p>This class also extends
* {@link javax.websocket.server.ServerEndpointConfig.Configurator} to make it easier to
* override methods for customizing the handshake process.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.0 * @since 4.0
* *
* @see ServerEndpointExporter * @see ServerEndpointExporter
*/ */
public class ServerEndpointRegistration implements ServerEndpointConfig, BeanFactoryAware { public class ServerEndpointRegistration extends ServerEndpointConfig.Configurator
implements ServerEndpointConfig, BeanFactoryAware {
private final String path; private final String path;
@ -66,8 +73,6 @@ public class ServerEndpointRegistration implements ServerEndpointConfig, BeanFac
private final Map<String, Object> userProperties = new HashMap<String, Object>(); private final Map<String, Object> userProperties = new HashMap<String, Object>();
private final Configurator configurator = new EndpointRegistrationConfigurator();
/** /**
* Create a new {@link ServerEndpointRegistration} instance from an * Create a new {@link ServerEndpointRegistration} instance from an
@ -161,7 +166,7 @@ public class ServerEndpointRegistration implements ServerEndpointConfig, BeanFac
@Override @Override
public Configurator getConfigurator() { public Configurator getConfigurator() {
return this.configurator; return this;
} }
@Override @Override
@ -171,50 +176,32 @@ public class ServerEndpointRegistration implements ServerEndpointConfig, BeanFac
} }
} }
protected void modifyHandshake(HandshakeRequest request, HandshakeResponse response) { // Implementations of ServerEndpointConfig.Configurator
this.configurator.modifyHandshake(this, request, response);
}
protected boolean checkOrigin(String originHeaderValue) { @SuppressWarnings("unchecked")
return this.configurator.checkOrigin(originHeaderValue); @Override
public final <T> T getEndpointInstance(Class<T> clazz) throws InstantiationException {
return (T) getEndpoint();
} }
protected String getNegotiatedSubprotocol(List<String> supported, List<String> requested) { @Override
return this.configurator.getNegotiatedSubprotocol(supported, requested); public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
super.modifyHandshake(this, request, response);
} }
protected List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) { @Override
return this.configurator.getNegotiatedExtensions(installed, requested); public boolean checkOrigin(String originHeaderValue) {
return super.checkOrigin(originHeaderValue);
} }
@Override
public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) {
return super.getNegotiatedSubprotocol(supported, requested);
}
private class EndpointRegistrationConfigurator extends Configurator { @Override
public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) {
@SuppressWarnings("unchecked") return super.getNegotiatedExtensions(installed, requested);
@Override
public <T> T getEndpointInstance(Class<T> clazz) throws InstantiationException {
return (T) getEndpoint();
}
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
super.modifyHandshake(sec, request, response);
}
@Override
public boolean checkOrigin(String originHeaderValue) {
return super.checkOrigin(originHeaderValue);
}
@Override
public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) {
return super.getNegotiatedSubprotocol(supported, requested);
}
@Override
public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) {
return super.getNegotiatedExtensions(installed, requested);
}
} }
} }

Loading…
Cancel
Save