Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -50,13 +50,10 @@ public abstract class Conventions {
|
|||||||
* when searching for the 'primary' interface of a proxy.
|
* when searching for the 'primary' interface of a proxy.
|
||||||
*/
|
*/
|
||||||
private static final Set<Class<?>> IGNORED_INTERFACES;
|
private static final Set<Class<?>> IGNORED_INTERFACES;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
IGNORED_INTERFACES = Collections.unmodifiableSet(
|
IGNORED_INTERFACES = Collections.unmodifiableSet(new HashSet<Class<?>>(Arrays.<Class<?>>asList(
|
||||||
new HashSet<Class<?>>(Arrays.<Class<?>> asList(
|
Serializable.class, Externalizable.class, Cloneable.class, Comparable.class)));
|
||||||
Serializable.class,
|
|
||||||
Externalizable.class,
|
|
||||||
Cloneable.class,
|
|
||||||
Comparable.class)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -54,8 +54,8 @@ public class InstanceFilter<T> {
|
|||||||
public InstanceFilter(Collection<? extends T> includes,
|
public InstanceFilter(Collection<? extends T> includes,
|
||||||
Collection<? extends T> excludes, boolean matchIfEmpty) {
|
Collection<? extends T> excludes, boolean matchIfEmpty) {
|
||||||
|
|
||||||
this.includes = includes != null ? includes : Collections.<T>emptyList();
|
this.includes = (includes != null ? includes : Collections.<T>emptyList());
|
||||||
this.excludes = excludes != null ? excludes : Collections.<T>emptyList();
|
this.excludes = (excludes != null ? excludes : Collections.<T>emptyList());
|
||||||
this.matchIfEmpty = matchIfEmpty;
|
this.matchIfEmpty = matchIfEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class InstanceFilter<T> {
|
|||||||
* Determine if the specified {code instance} matches this filter.
|
* Determine if the specified {code instance} matches this filter.
|
||||||
*/
|
*/
|
||||||
public boolean match(T instance) {
|
public boolean match(T instance) {
|
||||||
Assert.notNull(instance, "The instance to match is mandatory");
|
Assert.notNull(instance, "Instance to match must not be null");
|
||||||
|
|
||||||
boolean includesSet = !this.includes.isEmpty();
|
boolean includesSet = !this.includes.isEmpty();
|
||||||
boolean excludesSet = !this.excludes.isEmpty();
|
boolean excludesSet = !this.excludes.isEmpty();
|
||||||
@@ -74,11 +74,9 @@ public class InstanceFilter<T> {
|
|||||||
|
|
||||||
boolean matchIncludes = match(instance, this.includes);
|
boolean matchIncludes = match(instance, this.includes);
|
||||||
boolean matchExcludes = match(instance, this.excludes);
|
boolean matchExcludes = match(instance, this.excludes);
|
||||||
|
|
||||||
if (!includesSet) {
|
if (!includesSet) {
|
||||||
return !matchExcludes;
|
return !matchExcludes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!excludesSet) {
|
if (!excludesSet) {
|
||||||
return matchIncludes;
|
return matchIncludes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -50,8 +50,8 @@ public abstract class AbstractBrokerRegistration {
|
|||||||
this.clientInboundChannel = clientInboundChannel;
|
this.clientInboundChannel = clientInboundChannel;
|
||||||
this.clientOutboundChannel = clientOutboundChannel;
|
this.clientOutboundChannel = clientOutboundChannel;
|
||||||
|
|
||||||
this.destinationPrefixes = (destinationPrefixes != null)
|
this.destinationPrefixes = (destinationPrefixes != null ?
|
||||||
? Arrays.<String>asList(destinationPrefixes) : Collections.<String>emptyList();
|
Arrays.asList(destinationPrefixes) : Collections.<String>emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -67,6 +67,7 @@ public abstract class AbstractBrokerRegistration {
|
|||||||
return this.destinationPrefixes;
|
return this.destinationPrefixes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected abstract AbstractBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel);
|
protected abstract AbstractBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -43,8 +43,6 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractWebSocketClient implements WebSocketClient {
|
public abstract class AbstractWebSocketClient implements WebSocketClient {
|
||||||
|
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
|
||||||
|
|
||||||
private static final Set<String> specialHeaders = new HashSet<String>();
|
private static final Set<String> specialHeaders = new HashSet<String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -60,11 +58,14 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
|
public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
|
||||||
String uriTemplate, Object... uriVars) {
|
String uriTemplate, Object... uriVars) {
|
||||||
|
|
||||||
Assert.notNull(uriTemplate, "uriTemplate must not be null");
|
Assert.notNull(uriTemplate, "'uriTemplate' must not be null");
|
||||||
URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri();
|
URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri();
|
||||||
return doHandshake(webSocketHandler, null, uri);
|
return doHandshake(webSocketHandler, null, uri);
|
||||||
}
|
}
|
||||||
@@ -73,7 +74,7 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
|||||||
public final ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
|
public final ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
|
||||||
WebSocketHttpHeaders headers, URI uri) {
|
WebSocketHttpHeaders headers, URI uri) {
|
||||||
|
|
||||||
Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
|
Assert.notNull(webSocketHandler, "WebSocketHandler must not be null");
|
||||||
assertUri(uri);
|
assertUri(uri);
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
@@ -89,25 +90,26 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> subProtocols = ((headers != null) && (headers.getSecWebSocketProtocol() != null)) ?
|
List<String> subProtocols = (headers != null && headers.getSecWebSocketProtocol() != null ?
|
||||||
headers.getSecWebSocketProtocol() : Collections.<String>emptyList();
|
headers.getSecWebSocketProtocol() : Collections.<String>emptyList());
|
||||||
|
|
||||||
List<WebSocketExtension> extensions = ((headers != null) && (headers.getSecWebSocketExtensions() != null)) ?
|
List<WebSocketExtension> extensions = (headers != null && headers.getSecWebSocketExtensions() != null ?
|
||||||
headers.getSecWebSocketExtensions() : Collections.<WebSocketExtension>emptyList();
|
headers.getSecWebSocketExtensions() : Collections.<WebSocketExtension>emptyList());
|
||||||
|
|
||||||
return doHandshakeInternal(webSocketHandler, headersToUse, uri, subProtocols, extensions,
|
return doHandshakeInternal(webSocketHandler, headersToUse, uri, subProtocols, extensions,
|
||||||
Collections.<String, Object>emptyMap());
|
Collections.<String, Object>emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertUri(URI uri) {
|
protected void assertUri(URI uri) {
|
||||||
Assert.notNull(uri, "uri must not be null");
|
Assert.notNull(uri, "URI must not be null");
|
||||||
String scheme = uri.getScheme();
|
String scheme = uri.getScheme();
|
||||||
Assert.isTrue(scheme != null && ("ws".equals(scheme) || "wss".equals(scheme)), "Invalid scheme: " + scheme);
|
if (!"ws".equals(scheme) && !"wss".equals(scheme)) {
|
||||||
|
throw new IllegalArgumentException("Invalid scheme: " + scheme);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the actual handshake to establish a connection to the server.
|
* Perform the actual handshake to establish a connection to the server.
|
||||||
*
|
|
||||||
* @param webSocketHandler the client-side handler for WebSocket messages
|
* @param webSocketHandler the client-side handler for WebSocket messages
|
||||||
* @param headers HTTP headers to use for the handshake, with unwanted (forbidden)
|
* @param headers HTTP headers to use for the handshake, with unwanted (forbidden)
|
||||||
* headers filtered out, never {@code null}
|
* headers filtered out, never {@code null}
|
||||||
@@ -116,7 +118,6 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
|
|||||||
* @param extensions requested WebSocket extensions, or an empty list
|
* @param extensions requested WebSocket extensions, or an empty list
|
||||||
* @param attributes attributes to associate with the WebSocketSession, i.e. via
|
* @param attributes attributes to associate with the WebSocketSession, i.e. via
|
||||||
* {@link WebSocketSession#getAttributes()}; currently always an empty map.
|
* {@link WebSocketSession#getAttributes()}; currently always an empty map.
|
||||||
*
|
|
||||||
* @return the established WebSocket session wrapped in a ListenableFuture.
|
* @return the established WebSocket session wrapped in a ListenableFuture.
|
||||||
*/
|
*/
|
||||||
protected abstract ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
|
protected abstract ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
|
||||||
|
|||||||
Reference in New Issue
Block a user