Polishing
This commit is contained in:
@@ -63,7 +63,6 @@ public aspect JCacheCacheAspect extends JCacheAspectSupport {
|
||||
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
return execute(aspectJInvoker, thisJoinPoint.getTarget(), method, thisJoinPoint.getArgs());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -83,8 +82,7 @@ public abstract class YamlProcessor {
|
||||
* @param matchers a map of keys to value patterns (regular expressions)
|
||||
*/
|
||||
public void setDocumentMatchers(DocumentMatcher... matchers) {
|
||||
this.documentMatchers = Collections
|
||||
.unmodifiableList(new ArrayList<DocumentMatcher>(Arrays.asList(matchers)));
|
||||
this.documentMatchers = Arrays.asList(matchers);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +112,7 @@ public abstract class YamlProcessor {
|
||||
* @see ResolutionMethod
|
||||
*/
|
||||
public void setResources(Resource... resources) {
|
||||
this.resources = (resources == null ? null : resources.clone());
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,8 +150,8 @@ public abstract class YamlProcessor {
|
||||
}
|
||||
}
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Loaded " + count + " document"
|
||||
+ (count > 1 ? "s" : "") + " from YAML resource: " + resource);
|
||||
this.logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") +
|
||||
" from YAML resource: " + resource);
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
@@ -218,8 +216,7 @@ public abstract class YamlProcessor {
|
||||
result = MatchStatus.getMostSpecific(match, result);
|
||||
if (match == MatchStatus.FOUND) {
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Matched document with document matcher: "
|
||||
+ properties);
|
||||
this.logger.debug("Matched document with document matcher: " + properties);
|
||||
}
|
||||
callback.process(properties, map);
|
||||
return true;
|
||||
@@ -328,7 +325,7 @@ public abstract class YamlProcessor {
|
||||
* Compare two {@link MatchStatus} items, returning the most specific status.
|
||||
*/
|
||||
public static MatchStatus getMostSpecific(MatchStatus a, MatchStatus b) {
|
||||
return a.ordinal() < b.ordinal() ? a : b;
|
||||
return (a.ordinal() < b.ordinal() ? a : b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,4 +50,5 @@ public class CachingConfigurerSupport implements CachingConfigurer {
|
||||
public CacheErrorHandler errorHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,8 +96,7 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
|
||||
* and logs exceptions (a la
|
||||
* {@link org.springframework.scheduling.support.TaskUtils#LOG_AND_SUPPRESS_ERROR_HANDLER})
|
||||
* or an implementation that logs exceptions while nevertheless propagating them
|
||||
* (e.g.,
|
||||
* {@link org.springframework.scheduling.support.TaskUtils#LOG_AND_PROPAGATE_ERROR_HANDLER}).
|
||||
* (e.g. {@link org.springframework.scheduling.support.TaskUtils#LOG_AND_PROPAGATE_ERROR_HANDLER}).
|
||||
* @since 4.1
|
||||
*/
|
||||
public void setErrorHandler(ErrorHandler errorHandler) {
|
||||
|
||||
@@ -56,8 +56,7 @@ import org.springframework.util.Assert;
|
||||
* @see #setBeforeExistingAdvisors
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class AsyncAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostProcessor
|
||||
implements BeanFactoryAware {
|
||||
public class AsyncAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostProcessor implements BeanFactoryAware {
|
||||
|
||||
private Class<? extends Annotation> asyncAnnotationType;
|
||||
|
||||
@@ -70,6 +69,7 @@ public class AsyncAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostPr
|
||||
setBeforeExistingAdvisors(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the 'async' annotation type to be detected at either class or method
|
||||
* level. By default, both the {@link Async} annotation and the EJB 3.1
|
||||
|
||||
@@ -39,4 +39,5 @@ public class AsyncConfigurerSupport implements AsyncConfigurer {
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -150,8 +150,7 @@ public class ImportSelectorTests {
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Import({ DeferredImportSelector1.class, DeferredImportSelector2.class,
|
||||
ImportSelector1.class, ImportSelector2.class })
|
||||
@Import({DeferredImportSelector1.class, DeferredImportSelector2.class, ImportSelector1.class, ImportSelector2.class})
|
||||
public static @interface Sample {
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ public class AntPathMatcher implements PathMatcher {
|
||||
* Create a new instance with the {@link #DEFAULT_PATH_SEPARATOR}.
|
||||
*/
|
||||
public AntPathMatcher() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,8 +27,8 @@ public interface FailureCallback {
|
||||
|
||||
/**
|
||||
* Called when the {@link ListenableFuture} fails to complete.
|
||||
* @param t the exception that triggered the failure
|
||||
* @param ex the exception that triggered the failure
|
||||
*/
|
||||
void onFailure(Throwable t);
|
||||
void onFailure(Throwable ex);
|
||||
|
||||
}
|
||||
|
||||
@@ -30,11 +30,10 @@ import java.util.concurrent.ExecutionException;
|
||||
* @author Arjen Poutsma
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S>
|
||||
implements ListenableFuture<T> {
|
||||
public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S> implements ListenableFuture<T> {
|
||||
|
||||
/**
|
||||
* Constructs a new {@code ListenableFutureAdapter} with the given adaptee.
|
||||
* Construct a new {@code ListenableFutureAdapter} with the given adaptee.
|
||||
* @param adaptee the future to adaptee to
|
||||
*/
|
||||
protected ListenableFutureAdapter(ListenableFuture<S> adaptee) {
|
||||
@@ -48,8 +47,7 @@ public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(final SuccessCallback<? super T> successCallback,
|
||||
final FailureCallback failureCallback) {
|
||||
public void addCallback(final SuccessCallback<? super T> successCallback, final FailureCallback failureCallback) {
|
||||
ListenableFuture<S> listenableAdaptee = (ListenableFuture<S>) getAdaptee();
|
||||
listenableAdaptee.addCallback(new ListenableFutureCallback<S>() {
|
||||
@Override
|
||||
@@ -65,10 +63,9 @@ public abstract class ListenableFutureAdapter<T, S> extends FutureAdapter<T, S>
|
||||
onFailure(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
failureCallback.onFailure(t);
|
||||
public void onFailure(Throwable ex) {
|
||||
failureCallback.onFailure(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,11 +32,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ListenableFutureCallbackRegistry<T> {
|
||||
|
||||
private final Queue<SuccessCallback<? super T>> successCallbacks =
|
||||
new LinkedList<SuccessCallback<? super T>>();
|
||||
private final Queue<SuccessCallback<? super T>> successCallbacks = new LinkedList<SuccessCallback<? super T>>();
|
||||
|
||||
private final Queue<FailureCallback> failureCallbacks =
|
||||
new LinkedList<FailureCallback>();
|
||||
private final Queue<FailureCallback> failureCallbacks = new LinkedList<FailureCallback>();
|
||||
|
||||
private State state = State.NEW;
|
||||
|
||||
@@ -52,18 +50,17 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addCallback(ListenableFutureCallback<? super T> callback) {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
|
||||
synchronized (mutex) {
|
||||
switch (state) {
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
successCallbacks.add(callback);
|
||||
failureCallbacks.add(callback);
|
||||
this.successCallbacks.add(callback);
|
||||
this.failureCallbacks.add(callback);
|
||||
break;
|
||||
case SUCCESS:
|
||||
callback.onSuccess((T)result);
|
||||
callback.onSuccess((T) this.result);
|
||||
break;
|
||||
case FAILURE:
|
||||
callback.onFailure((Throwable) result);
|
||||
callback.onFailure((Throwable) this.result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -72,20 +69,18 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
/**
|
||||
* Adds the given success callback to this registry.
|
||||
* @param callback the success callback to add
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addSuccessCallback(SuccessCallback<? super T> callback) {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
|
||||
synchronized (mutex) {
|
||||
switch (state) {
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
successCallbacks.add(callback);
|
||||
this.successCallbacks.add(callback);
|
||||
break;
|
||||
case SUCCESS:
|
||||
callback.onSuccess((T)result);
|
||||
callback.onSuccess((T) this.result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -94,57 +89,54 @@ public class ListenableFutureCallbackRegistry<T> {
|
||||
/**
|
||||
* Adds the given failure callback to this registry.
|
||||
* @param callback the failure callback to add
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addFailureCallback(FailureCallback callback) {
|
||||
Assert.notNull(callback, "'callback' must not be null");
|
||||
|
||||
synchronized (mutex) {
|
||||
switch (state) {
|
||||
synchronized (this.mutex) {
|
||||
switch (this.state) {
|
||||
case NEW:
|
||||
failureCallbacks.add(callback);
|
||||
this.failureCallbacks.add(callback);
|
||||
break;
|
||||
case FAILURE:
|
||||
callback.onFailure((Throwable) result);
|
||||
callback.onFailure((Throwable) this.result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a {@link ListenableFutureCallback#onSuccess(Object)} call on all added
|
||||
* callbacks with the given result
|
||||
* Triggers a {@link ListenableFutureCallback#onSuccess(Object)} call on all
|
||||
* added callbacks with the given result
|
||||
* @param result the result to trigger the callbacks with
|
||||
*/
|
||||
public void success(T result) {
|
||||
synchronized (mutex) {
|
||||
state = State.SUCCESS;
|
||||
synchronized (this.mutex) {
|
||||
this.state = State.SUCCESS;
|
||||
this.result = result;
|
||||
|
||||
while (!successCallbacks.isEmpty()) {
|
||||
successCallbacks.poll().onSuccess(result);
|
||||
while (!this.successCallbacks.isEmpty()) {
|
||||
this.successCallbacks.poll().onSuccess(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a {@link ListenableFutureCallback#onFailure(Throwable)} call on all added
|
||||
* callbacks with the given {@code Throwable}.
|
||||
* @param t the exception to trigger the callbacks with
|
||||
* Triggers a {@link ListenableFutureCallback#onFailure(Throwable)} call on all
|
||||
* added callbacks with the given {@code Throwable}.
|
||||
* @param ex the exception to trigger the callbacks with
|
||||
*/
|
||||
public void failure(Throwable t) {
|
||||
synchronized (mutex) {
|
||||
state = State.FAILURE;
|
||||
this.result = t;
|
||||
|
||||
while (!failureCallbacks.isEmpty()) {
|
||||
failureCallbacks.poll().onFailure(t);
|
||||
public void failure(Throwable ex) {
|
||||
synchronized (this.mutex) {
|
||||
this.state = State.FAILURE;
|
||||
this.result = ex;
|
||||
while (!this.failureCallbacks.isEmpty()) {
|
||||
this.failureCallbacks.poll().onFailure(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private enum State {NEW, SUCCESS, FAILURE}
|
||||
|
||||
}
|
||||
|
||||
@@ -155,7 +155,6 @@ public class SettableListenableFuture<T> implements ListenableFuture<T> {
|
||||
|
||||
private volatile boolean cancelled = false;
|
||||
|
||||
|
||||
public boolean setValue(T value) {
|
||||
if (this.cancelled) {
|
||||
return false;
|
||||
|
||||
@@ -51,8 +51,8 @@ public class ListenableFutureTaskTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
task.run();
|
||||
@@ -75,8 +75,8 @@ public class ListenableFutureTaskTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
assertEquals(s, t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
assertEquals(s, ex.getMessage());
|
||||
}
|
||||
});
|
||||
task.run();
|
||||
|
||||
@@ -86,7 +86,7 @@ public class SettableListenableFutureTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
public void onFailure(Throwable ex) {
|
||||
fail("Expected onSuccess() to be called");
|
||||
}
|
||||
});
|
||||
@@ -105,7 +105,7 @@ public class SettableListenableFutureTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
public void onFailure(Throwable ex) {
|
||||
fail("Expected onSuccess() to be called");
|
||||
}
|
||||
});
|
||||
@@ -125,8 +125,8 @@ public class SettableListenableFutureTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
callbackHolder[0] = t;
|
||||
public void onFailure(Throwable ex) {
|
||||
callbackHolder[0] = ex;
|
||||
}
|
||||
});
|
||||
settableListenableFuture.setException(exception);
|
||||
@@ -144,8 +144,8 @@ public class SettableListenableFutureTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
callbackHolder[0] = t;
|
||||
public void onFailure(Throwable ex) {
|
||||
callbackHolder[0] = ex;
|
||||
}
|
||||
});
|
||||
settableListenableFuture.setException(exception);
|
||||
|
||||
@@ -44,8 +44,10 @@ import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
|
||||
/**
|
||||
* A {@link org.springframework.messaging.MessageHandler} that handles messages by forwarding them to a STOMP broker.
|
||||
* For each new {@link SimpMessageType#CONNECT CONNECT} message, an independent TCP
|
||||
* A {@link org.springframework.messaging.MessageHandler} that handles messages by
|
||||
* forwarding them to a STOMP broker.
|
||||
*
|
||||
* <p>For each new {@link SimpMessageType#CONNECT CONNECT} message, an independent TCP
|
||||
* connection to the broker is opened and used exclusively for all messages from the
|
||||
* client that originated the CONNECT message. Messages from the same client are
|
||||
* identified through the session id message header. Reversely, when the STOMP broker
|
||||
@@ -60,10 +62,10 @@ import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
* shared and cannot be used to receive messages. Several properties are provided to
|
||||
* configure the "system" connection including:
|
||||
* <ul>
|
||||
* <li>{@link #setSystemLogin(String)}</li>
|
||||
* <li>{@link #setSystemPasscode(String)}</li>
|
||||
* <li>{@link #setSystemHeartbeatSendInterval(long)}</li>
|
||||
* <li>{@link #setSystemHeartbeatReceiveInterval(long)}</li>
|
||||
* <li>{@link #setSystemLogin(String)}</li>
|
||||
* <li>{@link #setSystemPasscode(String)}</li>
|
||||
* <li>{@link #setSystemHeartbeatSendInterval(long)}</li>
|
||||
* <li>{@link #setSystemHeartbeatReceiveInterval(long)}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -83,6 +85,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
|
||||
private static final Message<byte[]> HEARTBEAT_MESSAGE;
|
||||
|
||||
|
||||
static {
|
||||
EMPTY_TASK.run();
|
||||
StompHeaderAccessor accessor = StompHeaderAccessor.createForHeartbeat();
|
||||
@@ -127,7 +130,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
/**
|
||||
* Create a StompBrokerRelayMessageHandler instance with the given message channels
|
||||
* and destination prefixes.
|
||||
*
|
||||
* @param clientInChannel the channel for receiving messages from clients (e.g. WebSocket clients)
|
||||
* @param clientOutChannel the channel for sending messages to clients (e.g. WebSocket clients)
|
||||
* @param brokerChannel the channel for the application to send messages to the broker
|
||||
@@ -138,11 +140,9 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
SubscribableChannel brokerChannel, Collection<String> destinationPrefixes) {
|
||||
|
||||
super(destinationPrefixes);
|
||||
|
||||
Assert.notNull(clientInChannel, "'clientInChannel' must not be null");
|
||||
Assert.notNull(clientOutChannel, "'clientOutChannel' must not be null");
|
||||
Assert.notNull(brokerChannel, "'brokerChannel' must not be null");
|
||||
|
||||
this.clientInboundChannel = clientInChannel;
|
||||
this.clientOutboundChannel = clientOutChannel;
|
||||
this.brokerChannel = brokerChannel;
|
||||
@@ -220,8 +220,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
/**
|
||||
* Set the login to use when creating connections to the STOMP broker on
|
||||
* behalf of connected clients.
|
||||
* <p>
|
||||
* By default this is set to "guest".
|
||||
* <p>By default this is set to "guest".
|
||||
* @see #setSystemLogin(String)
|
||||
*/
|
||||
public void setClientLogin(String clientLogin) {
|
||||
@@ -230,7 +229,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configured login to use for connections to the STOMP broker
|
||||
* Return the configured login to use for connections to the STOMP broker
|
||||
* on behalf of connected clients.
|
||||
* @see #getSystemLogin()
|
||||
*/
|
||||
@@ -241,9 +240,8 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
/**
|
||||
* Set the clientPasscode to use to create connections to the STOMP broker on
|
||||
* behalf of connected clients.
|
||||
* <p>
|
||||
* By default this is set to "guest".
|
||||
* @see #setSystemPasscode(String)
|
||||
* <p> By default this is set to "guest".
|
||||
* @see #setSystemPasscode
|
||||
*/
|
||||
public void setClientPasscode(String clientPasscode) {
|
||||
Assert.hasText(clientPasscode, "clientPasscode must not be empty");
|
||||
@@ -251,7 +249,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configured passocde to use for connections to the STOMP broker on
|
||||
* Return the configured passocde to use for connections to the STOMP broker on
|
||||
* behalf of connected clients.
|
||||
* @see #getSystemPasscode()
|
||||
*/
|
||||
@@ -263,8 +261,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
* Set the login for the shared "system" connection used to send messages to
|
||||
* the STOMP broker from within the application, i.e. messages not associated
|
||||
* with a specific client session (e.g. REST/HTTP request handling method).
|
||||
* <p>
|
||||
* By default this is set to "guest".
|
||||
* <p>By default this is set to "guest".
|
||||
*/
|
||||
public void setSystemLogin(String systemLogin) {
|
||||
Assert.hasText(systemLogin, "systemLogin must not be empty");
|
||||
@@ -272,7 +269,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the login used for the shared "system" connection to the STOMP broker
|
||||
* Return the login used for the shared "system" connection to the STOMP broker
|
||||
*/
|
||||
public String getSystemLogin() {
|
||||
return this.systemLogin;
|
||||
@@ -282,8 +279,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
* Set the passcode for the shared "system" connection used to send messages to
|
||||
* the STOMP broker from within the application, i.e. messages not associated
|
||||
* with a specific client session (e.g. REST/HTTP request handling method).
|
||||
* <p>
|
||||
* By default this is set to "guest".
|
||||
* <p>By default this is set to "guest".
|
||||
*/
|
||||
public void setSystemPasscode(String systemPasscode) {
|
||||
this.systemPasscode = systemPasscode;
|
||||
@@ -343,7 +339,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
* Configure a {@link MessageHeaderInitializer} to apply to the headers of all
|
||||
* messages created through the {@code StompBrokerRelayMessageHandler} that
|
||||
* are sent to the client outbound message channel.
|
||||
*
|
||||
* <p>By default this property is not set.
|
||||
*/
|
||||
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
|
||||
@@ -351,7 +346,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configured header initializer.
|
||||
* Return the configured header initializer.
|
||||
*/
|
||||
public MessageHeaderInitializer getHeaderInitializer() {
|
||||
return this.headerInitializer;
|
||||
@@ -367,7 +362,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
|
||||
@Override
|
||||
protected void startInternal() {
|
||||
|
||||
this.clientInboundChannel.subscribe(this);
|
||||
this.brokerChannel.subscribe(this);
|
||||
|
||||
@@ -402,7 +396,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
|
||||
@Override
|
||||
protected void stopInternal() {
|
||||
|
||||
publishBrokerUnavailableEvent();
|
||||
|
||||
this.clientInboundChannel.unsubscribe(this);
|
||||
@@ -411,14 +404,13 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
try {
|
||||
this.tcpClient.shutdown().get(5000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
logger.error("Error in shutdown of TCP client", t);
|
||||
catch (Throwable ex) {
|
||||
logger.error("Error in shutdown of TCP client", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMessageInternal(Message<?> message) {
|
||||
|
||||
String sessionId = SimpMessageHeaderAccessor.getSessionId(message.getHeaders());
|
||||
|
||||
if (!isBrokerAvailable()) {
|
||||
@@ -427,7 +419,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
"receive BrokerAvailabilityEvent's from an ApplicationListener Spring bean.");
|
||||
}
|
||||
SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders());
|
||||
if (messageType.equals(SimpMessageType.CONNECT) && logger.isErrorEnabled()) {
|
||||
if (logger.isErrorEnabled() && messageType.equals(SimpMessageType.CONNECT)) {
|
||||
logger.error("Broker not active. Ignoring " + message);
|
||||
}
|
||||
else if (logger.isDebugEnabled()) {
|
||||
@@ -462,7 +454,9 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
|
||||
if (sessionId == null) {
|
||||
if (!SimpMessageType.MESSAGE.equals(stompAccessor.getMessageType())) {
|
||||
logger.error("Only STOMP SEND supported from within the server side. Ignoring " + message);
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("Only STOMP SEND supported from within the server side. Ignoring " + message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
sessionId = SYSTEM_SESSION_ID;
|
||||
@@ -576,10 +570,10 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
try {
|
||||
clearConnection();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable ex2) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("Failure while cleaning up state for TCP connection" +
|
||||
" in session " + this.sessionId, t);
|
||||
logger.error("Failure while cleaning up state for TCP connection in session " +
|
||||
this.sessionId, ex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -641,13 +635,13 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
if (this.isRemoteClientSession) {
|
||||
return;
|
||||
}
|
||||
|
||||
long clientSendInterval = this.connectHeaders.getHeartbeat()[0];
|
||||
long clientReceiveInterval = this.connectHeaders.getHeartbeat()[1];
|
||||
|
||||
long serverSendInterval = connectedHeaders.getHeartbeat()[0];
|
||||
long serverReceiveInterval = connectedHeaders.getHeartbeat()[1];
|
||||
|
||||
if ((clientSendInterval > 0) && (serverReceiveInterval > 0)) {
|
||||
if (clientSendInterval > 0 && serverReceiveInterval > 0) {
|
||||
long interval = Math.max(clientSendInterval, serverReceiveInterval);
|
||||
this.tcpConnection.onWriteInactivity(new Runnable() {
|
||||
@Override
|
||||
@@ -656,11 +650,12 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
if (conn != null) {
|
||||
conn.send(HEARTBEAT_MESSAGE).addCallback(
|
||||
new ListenableFutureCallback<Void>() {
|
||||
public void onFailure(Throwable t) {
|
||||
String error = "failed to forward heartbeat in \"system\" session.";
|
||||
handleTcpConnectionFailure(error, t);
|
||||
public void onSuccess(Void result) {
|
||||
}
|
||||
public void onFailure(Throwable ex) {
|
||||
String error = "failed to forward heartbeat in \"system\" session.";
|
||||
handleTcpConnectionFailure(error, ex);
|
||||
}
|
||||
public void onSuccess(Void result) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -712,7 +707,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
|
||||
/**
|
||||
* Forward the given message to the STOMP broker.
|
||||
*
|
||||
* <p>The method checks whether we have an active TCP connection and have
|
||||
* received the STOMP CONNECTED frame. For client messages this should be
|
||||
* false only if we lose the TCP connection around the same time when a
|
||||
@@ -721,7 +715,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
* the "system" connection an exception is raised so that components sending
|
||||
* the message have a chance to handle it -- by default the broker message
|
||||
* channel is synchronous.
|
||||
*
|
||||
* <p>Note that if messages arrive concurrently around the same time a TCP
|
||||
* connection is lost, there is a brief period of time before the connection
|
||||
* is reset when one or more messages may sneak through and an attempt made
|
||||
@@ -729,14 +722,11 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
* method simply lets them try and fail. For client sessions that may
|
||||
* result in an additional STOMP ERROR frame(s) being sent downstream but
|
||||
* code handling that downstream should be idempotent in such cases.
|
||||
*
|
||||
* @param message the message to send, never {@code null}
|
||||
* @param message the message to send (never {@code null})
|
||||
* @return a future to wait for the result
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ListenableFuture<Void> forward(final Message<?> message, final StompHeaderAccessor accessor) {
|
||||
|
||||
|
||||
TcpConnection<byte[]> conn = this.tcpConnection;
|
||||
|
||||
if (!this.isStompConnected) {
|
||||
@@ -760,15 +750,12 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
MessageBuilder.createMessage(message.getPayload(), accessor.getMessageHeaders()) : message;
|
||||
|
||||
StompCommand command = accessor.getCommand();
|
||||
if (logger.isDebugEnabled() &&
|
||||
StompCommand.SEND.equals(command) ||
|
||||
StompCommand.SUBSCRIBE.equals(command) ||
|
||||
StompCommand.UNSUBSCRIBE.equals(command) ||
|
||||
StompCommand.DISCONNECT.equals(command)) {
|
||||
logger.debug("Forwarding " + accessor.getShortLogMessage((byte[]) message.getPayload()));
|
||||
if (logger.isDebugEnabled() && (StompCommand.SEND.equals(command) || StompCommand.SUBSCRIBE.equals(command) ||
|
||||
StompCommand.UNSUBSCRIBE.equals(command) || StompCommand.DISCONNECT.equals(command))) {
|
||||
logger.debug("Forwarding " + accessor.getShortLogMessage(message.getPayload()));
|
||||
}
|
||||
else if (logger.isTraceEnabled()) {
|
||||
logger.trace("Forwarding " + accessor.getDetailedLogMessage((byte[]) message.getPayload()));
|
||||
logger.trace("Forwarding " + accessor.getDetailedLogMessage(message.getPayload()));
|
||||
}
|
||||
|
||||
ListenableFuture<Void> future = conn.send((Message<byte[]>) messageToSend);
|
||||
@@ -780,14 +767,13 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
public void onFailure(Throwable ex) {
|
||||
if (tcpConnection != null) {
|
||||
handleTcpConnectionFailure("failed to forward " +
|
||||
accessor.getShortLogMessage((byte[]) message.getPayload()), t);
|
||||
accessor.getShortLogMessage(message.getPayload()), ex);
|
||||
}
|
||||
else if (logger.isErrorEnabled()) {
|
||||
logger.error("Failed to forward " +
|
||||
accessor.getShortLogMessage((byte[]) message.getPayload()));
|
||||
logger.error("Failed to forward " + accessor.getShortLogMessage(message.getPayload()));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -799,7 +785,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
* close the connection pro-actively. However, if the DISCONNECT has a
|
||||
* receipt header we leave the connection open and expect the server will
|
||||
* respond with a RECEIPT and then close the connection.
|
||||
*
|
||||
* @see <a href="http://stomp.github.io/stomp-specification-1.2.html#DISCONNECT">
|
||||
* STOMP Specification 1.2 DISCONNECT</a>
|
||||
*/
|
||||
@@ -840,6 +825,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class SystemStompConnectionHandler extends StompConnectionHandler {
|
||||
|
||||
public SystemStompConnectionHandler(StompHeaderAccessor connectHeaders) {
|
||||
@@ -874,12 +860,13 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
future.get();
|
||||
return future;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw new MessageDeliveryException(message, t);
|
||||
catch (Throwable ex) {
|
||||
throw new MessageDeliveryException(message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class StompTcpClientFactory {
|
||||
|
||||
public TcpOperations<byte[]> create(String relayHost, int relayPort, Reactor11StompCodec codec) {
|
||||
@@ -887,6 +874,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class VoidCallable implements Callable<Void> {
|
||||
|
||||
@Override
|
||||
@@ -895,6 +883,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class Stats {
|
||||
|
||||
private final AtomicInteger connect = new AtomicInteger();
|
||||
@@ -903,7 +892,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
|
||||
|
||||
private final AtomicInteger disconnect = new AtomicInteger();
|
||||
|
||||
|
||||
public void incrementConnectCount() {
|
||||
this.connect.incrementAndGet();
|
||||
}
|
||||
|
||||
@@ -90,8 +90,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
*/
|
||||
public AsyncRestTemplate(AsyncListenableTaskExecutor taskExecutor) {
|
||||
Assert.notNull(taskExecutor, "AsyncTaskExecutor must not be null");
|
||||
SimpleClientHttpRequestFactory requestFactory =
|
||||
new SimpleClientHttpRequestFactory();
|
||||
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
|
||||
requestFactory.setTaskExecutor(taskExecutor);
|
||||
this.syncTemplate = new RestTemplate(requestFactory);
|
||||
setAsyncRequestFactory(requestFactory);
|
||||
@@ -116,8 +115,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
* @param asyncRequestFactory the asynchronous request factory
|
||||
* @param syncRequestFactory the synchronous request factory
|
||||
*/
|
||||
public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory,
|
||||
ClientHttpRequestFactory syncRequestFactory) {
|
||||
public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory) {
|
||||
this(asyncRequestFactory, new RestTemplate(syncRequestFactory));
|
||||
}
|
||||
|
||||
@@ -127,8 +125,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
* @param requestFactory the asynchronous request factory to use
|
||||
* @param restTemplate the synchronous template to use
|
||||
*/
|
||||
public AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory,
|
||||
RestTemplate restTemplate) {
|
||||
public AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory, RestTemplate restTemplate) {
|
||||
Assert.notNull(restTemplate, "'restTemplate' must not be null");
|
||||
this.syncTemplate = restTemplate;
|
||||
setAsyncRequestFactory(requestFactory);
|
||||
@@ -197,6 +194,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
return execute(url, HttpMethod.GET, requestCallback, responseExtractor);
|
||||
}
|
||||
|
||||
|
||||
// HEAD
|
||||
|
||||
@Override
|
||||
@@ -220,30 +218,29 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
// POST
|
||||
|
||||
@Override
|
||||
public ListenableFuture<URI> postForLocation(String url, HttpEntity<?> request,
|
||||
Object... uriVariables) throws RestClientException {
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request);
|
||||
ResponseExtractor<HttpHeaders> headersExtractor = headersExtractor();
|
||||
ListenableFuture<HttpHeaders> headersFuture =
|
||||
execute(url, HttpMethod.POST, requestCallback, headersExtractor,
|
||||
uriVariables);
|
||||
return extractLocationHeader(headersFuture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<URI> postForLocation(String url, HttpEntity<?> request,
|
||||
Map<String, ?> uriVariables) throws RestClientException {
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request);
|
||||
ResponseExtractor<HttpHeaders> headersExtractor = headersExtractor();
|
||||
ListenableFuture<HttpHeaders> headersFuture =
|
||||
execute(url, HttpMethod.POST, requestCallback, headersExtractor,
|
||||
uriVariables);
|
||||
return extractLocationHeader(headersFuture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<URI> postForLocation(URI url, HttpEntity<?> request)
|
||||
public ListenableFuture<URI> postForLocation(String url, HttpEntity<?> request, Object... uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request);
|
||||
ResponseExtractor<HttpHeaders> headersExtractor = headersExtractor();
|
||||
ListenableFuture<HttpHeaders> headersFuture =
|
||||
execute(url, HttpMethod.POST, requestCallback, headersExtractor, uriVariables);
|
||||
return extractLocationHeader(headersFuture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<URI> postForLocation(String url, HttpEntity<?> request, Map<String, ?> uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request);
|
||||
ResponseExtractor<HttpHeaders> headersExtractor = headersExtractor();
|
||||
ListenableFuture<HttpHeaders> headersFuture =
|
||||
execute(url, HttpMethod.POST, requestCallback, headersExtractor, uriVariables);
|
||||
return extractLocationHeader(headersFuture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<URI> postForLocation(URI url, HttpEntity<?> request) throws RestClientException {
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request);
|
||||
ResponseExtractor<HttpHeaders> headersExtractor = headersExtractor();
|
||||
ListenableFuture<HttpHeaders> headersFuture =
|
||||
@@ -253,28 +250,23 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
|
||||
private static ListenableFuture<URI> extractLocationHeader(final ListenableFuture<HttpHeaders> headersFuture) {
|
||||
return new ListenableFuture<URI>() {
|
||||
|
||||
@Override
|
||||
public void addCallback(final ListenableFutureCallback<? super URI> callback) {
|
||||
addCallback(callback, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(final SuccessCallback<? super URI> successCallback,
|
||||
final FailureCallback failureCallback) {
|
||||
public void addCallback(final SuccessCallback<? super URI> successCallback, final FailureCallback failureCallback) {
|
||||
headersFuture.addCallback(new ListenableFutureCallback<HttpHeaders>() {
|
||||
@Override
|
||||
public void onSuccess(HttpHeaders result) {
|
||||
successCallback.onSuccess(result.getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
failureCallback.onFailure(t);
|
||||
public void onFailure(Throwable ex) {
|
||||
failureCallback.onFailure(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return headersFuture.cancel(mayInterruptIfRunning);
|
||||
@@ -293,8 +285,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
return headers.getLocation();
|
||||
}
|
||||
@Override
|
||||
public URI get(long timeout, TimeUnit unit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
public URI get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
HttpHeaders headers = headersFuture.get(timeout, unit);
|
||||
return headers.getLocation();
|
||||
}
|
||||
@@ -304,45 +295,41 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(String url, HttpEntity<?> request,
|
||||
Class<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(responseType);
|
||||
return execute(url, HttpMethod.POST, requestCallback, responseExtractor,
|
||||
uriVariables);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
|
||||
return execute(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(String url, HttpEntity<?> request,
|
||||
Class<T> responseType, Map<String, ?> uriVariables)
|
||||
throws RestClientException {
|
||||
Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
|
||||
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(responseType);
|
||||
return execute(url, HttpMethod.POST, requestCallback, responseExtractor,
|
||||
uriVariables);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
|
||||
return execute(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(URI url, HttpEntity<?> request,
|
||||
Class<T> responseType) throws RestClientException {
|
||||
public <T> ListenableFuture<ResponseEntity<T>> postForEntity(URI url, HttpEntity<?> request, Class<T> responseType)
|
||||
throws RestClientException {
|
||||
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
|
||||
return execute(url, HttpMethod.POST, requestCallback, responseExtractor);
|
||||
}
|
||||
|
||||
|
||||
// PUT
|
||||
|
||||
@Override
|
||||
public ListenableFuture<?> put(String url, HttpEntity<?> request, Object... uriVariables)
|
||||
throws RestClientException {
|
||||
public ListenableFuture<?> put(String url, HttpEntity<?> request, Object... uriVariables) throws RestClientException {
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request);
|
||||
return execute(url, HttpMethod.PUT, requestCallback, null, uriVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<?> put(String url, HttpEntity<?> request,
|
||||
Map<String, ?> uriVariables) throws RestClientException {
|
||||
public ListenableFuture<?> put(String url, HttpEntity<?> request, Map<String, ?> uriVariables) throws RestClientException {
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(request);
|
||||
return execute(url, HttpMethod.PUT, requestCallback, null, uriVariables);
|
||||
}
|
||||
@@ -353,17 +340,16 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
return execute(url, HttpMethod.PUT, requestCallback, null);
|
||||
}
|
||||
|
||||
|
||||
// DELETE
|
||||
|
||||
@Override
|
||||
public ListenableFuture<?> delete(String url, Object... urlVariables)
|
||||
throws RestClientException {
|
||||
public ListenableFuture<?> delete(String url, Object... urlVariables) throws RestClientException {
|
||||
return execute(url, HttpMethod.DELETE, null, null, urlVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<?> delete(String url, Map<String, ?> urlVariables)
|
||||
throws RestClientException {
|
||||
public ListenableFuture<?> delete(String url, Map<String, ?> urlVariables) throws RestClientException {
|
||||
return execute(url, HttpMethod.DELETE, null, null, urlVariables);
|
||||
}
|
||||
|
||||
@@ -372,6 +358,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
return execute(url, HttpMethod.DELETE, null, null);
|
||||
}
|
||||
|
||||
|
||||
// OPTIONS
|
||||
|
||||
@Override
|
||||
@@ -397,12 +384,10 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
|
||||
private static ListenableFuture<Set<HttpMethod>> extractAllowHeader(final ListenableFuture<HttpHeaders> headersFuture) {
|
||||
return new ListenableFuture<Set<HttpMethod>>() {
|
||||
|
||||
@Override
|
||||
public void addCallback(final ListenableFutureCallback<? super Set<HttpMethod>> callback) {
|
||||
addCallback(callback, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(final SuccessCallback<? super Set<HttpMethod>> successCallback, final FailureCallback failureCallback) {
|
||||
headersFuture.addCallback(new ListenableFutureCallback<HttpHeaders>() {
|
||||
@@ -410,14 +395,12 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
public void onSuccess(HttpHeaders result) {
|
||||
successCallback.onSuccess(result.getAllow());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
failureCallback.onFailure(t);
|
||||
public void onFailure(Throwable ex) {
|
||||
failureCallback.onFailure(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return headersFuture.cancel(mayInterruptIfRunning);
|
||||
@@ -436,8 +419,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
return headers.getAllow();
|
||||
}
|
||||
@Override
|
||||
public Set<HttpMethod> get(long timeout, TimeUnit unit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
public Set<HttpMethod> get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
HttpHeaders headers = headersFuture.get(timeout, unit);
|
||||
return headers.getAllow();
|
||||
}
|
||||
@@ -448,68 +430,59 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
// exchange
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method,
|
||||
HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables)
|
||||
throws RestClientException {
|
||||
AsyncRequestCallback requestCallback =
|
||||
httpEntityCallback(requestEntity, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(responseType);
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
Class<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
|
||||
return execute(url, method, requestCallback, responseExtractor, uriVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method,
|
||||
HttpEntity<?> requestEntity, Class<T> responseType,
|
||||
Map<String, ?> uriVariables) throws RestClientException {
|
||||
AsyncRequestCallback requestCallback =
|
||||
httpEntityCallback(requestEntity, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(responseType);
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
|
||||
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
|
||||
return execute(url, method, requestCallback, responseExtractor, uriVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method,
|
||||
HttpEntity<?> requestEntity, Class<T> responseType)
|
||||
throws RestClientException {
|
||||
AsyncRequestCallback requestCallback =
|
||||
httpEntityCallback(requestEntity, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(responseType);
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
Class<T> responseType) throws RestClientException {
|
||||
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
|
||||
return execute(url, method, requestCallback, responseExtractor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method,
|
||||
HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType,
|
||||
Object... uriVariables) throws RestClientException {
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
|
||||
Type type = responseType.getType();
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(type);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
|
||||
return execute(url, method, requestCallback, responseExtractor, uriVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method,
|
||||
HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType,
|
||||
Map<String, ?> uriVariables) throws RestClientException {
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
|
||||
|
||||
Type type = responseType.getType();
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(type);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
|
||||
return execute(url, method, requestCallback, responseExtractor, uriVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method,
|
||||
HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType)
|
||||
throws RestClientException {
|
||||
public <T> ListenableFuture<ResponseEntity<T>> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType) throws RestClientException {
|
||||
|
||||
Type type = responseType.getType();
|
||||
AsyncRequestCallback requestCallback = httpEntityCallback(requestEntity, type);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor =
|
||||
responseEntityExtractor(type);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(type);
|
||||
return execute(url, method, requestCallback, responseExtractor);
|
||||
}
|
||||
|
||||
@@ -517,27 +490,24 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
// general execution
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<T> execute(String url, HttpMethod method,
|
||||
AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor,
|
||||
Object... urlVariables) throws RestClientException {
|
||||
public <T> ListenableFuture<T> execute(String url, HttpMethod method, AsyncRequestCallback requestCallback,
|
||||
ResponseExtractor<T> responseExtractor, Object... urlVariables) throws RestClientException {
|
||||
|
||||
URI expanded = new UriTemplate(url).expand(urlVariables);
|
||||
return doExecute(expanded, method, requestCallback, responseExtractor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<T> execute(String url, HttpMethod method,
|
||||
AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor,
|
||||
Map<String, ?> urlVariables) throws RestClientException {
|
||||
public <T> ListenableFuture<T> execute(String url, HttpMethod method, AsyncRequestCallback requestCallback,
|
||||
ResponseExtractor<T> responseExtractor, Map<String, ?> urlVariables) throws RestClientException {
|
||||
|
||||
URI expanded = new UriTemplate(url).expand(urlVariables);
|
||||
return doExecute(expanded, method, requestCallback, responseExtractor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ListenableFuture<T> execute(URI url, HttpMethod method,
|
||||
AsyncRequestCallback requestCallback, ResponseExtractor<T> responseExtractor)
|
||||
throws RestClientException {
|
||||
public <T> ListenableFuture<T> execute(URI url, HttpMethod method, AsyncRequestCallback requestCallback,
|
||||
ResponseExtractor<T> responseExtractor) throws RestClientException {
|
||||
|
||||
return doExecute(url, method, requestCallback, responseExtractor);
|
||||
}
|
||||
@@ -565,8 +535,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
requestCallback.doWithRequest(request);
|
||||
}
|
||||
ListenableFuture<ClientHttpResponse> responseFuture = request.executeAsync();
|
||||
return new ResponseExtractorFuture<T>(method, url, responseFuture,
|
||||
responseExtractor);
|
||||
return new ResponseExtractorFuture<T>(method, url, responseFuture, responseExtractor);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new ResourceAccessException("I/O error on " + method.name() +
|
||||
@@ -577,9 +546,8 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
private void logResponseStatus(HttpMethod method, URI url, ClientHttpResponse response) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
try {
|
||||
logger.debug("Async " + method.name() + " request for \"" + url +
|
||||
"\" resulted in " + response.getStatusCode() + " (" +
|
||||
response.getStatusText() + ")");
|
||||
logger.debug("Async " + method.name() + " request for \"" + url + "\" resulted in " +
|
||||
response.getStatusCode() + " (" + response.getStatusText() + ")");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
@@ -590,9 +558,8 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
private void handleResponseError(HttpMethod method, URI url, ClientHttpResponse response) throws IOException {
|
||||
if (logger.isWarnEnabled()) {
|
||||
try {
|
||||
logger.warn("Async " + method.name() + " request for \"" + url +
|
||||
"\" resulted in " + response.getStatusCode() + " (" +
|
||||
response.getStatusText() + "); invoking error handler");
|
||||
logger.warn("Async " + method.name() + " request for \"" + url + "\" resulted in " +
|
||||
response.getStatusCode() + " (" + response.getStatusText() + "); invoking error handler");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
@@ -640,12 +607,12 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
return this.syncTemplate.headersExtractor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Future returned from
|
||||
* {@link #doExecute(URI, HttpMethod, AsyncRequestCallback, ResponseExtractor)}
|
||||
*/
|
||||
private class ResponseExtractorFuture<T>
|
||||
extends ListenableFutureAdapter<T, ClientHttpResponse> {
|
||||
private class ResponseExtractorFuture<T> extends ListenableFutureAdapter<T, ClientHttpResponse> {
|
||||
|
||||
private final HttpMethod method;
|
||||
|
||||
@@ -654,8 +621,7 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
private final ResponseExtractor<T> responseExtractor;
|
||||
|
||||
public ResponseExtractorFuture(HttpMethod method, URI url,
|
||||
ListenableFuture<ClientHttpResponse> clientHttpResponseFuture,
|
||||
ResponseExtractor<T> responseExtractor) {
|
||||
ListenableFuture<ClientHttpResponse> clientHttpResponseFuture, ResponseExtractor<T> responseExtractor) {
|
||||
super(clientHttpResponseFuture);
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
@@ -684,12 +650,11 @@ public class AsyncRestTemplate extends AsyncHttpAccessor implements AsyncRestOpe
|
||||
}
|
||||
|
||||
protected T convertResponse(ClientHttpResponse response) throws IOException {
|
||||
return responseExtractor != null ? responseExtractor.extractData(response) :
|
||||
null;
|
||||
return (this.responseExtractor != null ? this.responseExtractor.extractData(response) : null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapts a {@link RequestCallback} to the {@link AsyncRequestCallback} interface.
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.http.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
@@ -37,11 +36,11 @@ import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||
AbstractJettyServerTestCase {
|
||||
public abstract class AbstractAsyncHttpRequestFactoryTestCase extends AbstractJettyServerTestCase {
|
||||
|
||||
protected AsyncClientHttpRequestFactory factory;
|
||||
|
||||
|
||||
@Before
|
||||
public final void createFactory() throws Exception {
|
||||
factory = createRequestFactory();
|
||||
@@ -52,6 +51,7 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||
|
||||
protected abstract AsyncClientHttpRequestFactory createRequestFactory();
|
||||
|
||||
|
||||
@Test
|
||||
public void status() throws Exception {
|
||||
URI uri = new URI(baseUrl + "/status/notfound");
|
||||
@@ -60,8 +60,7 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||
assertEquals("Invalid HTTP URI", uri, request.getURI());
|
||||
Future<ClientHttpResponse> futureResponse = request.executeAsync();
|
||||
ClientHttpResponse response = futureResponse.get();
|
||||
assertEquals("Invalid status code", HttpStatus.NOT_FOUND,
|
||||
response.getStatusCode());
|
||||
assertEquals("Invalid status code", HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,46 +69,34 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||
AsyncClientHttpRequest request = factory.createAsyncRequest(uri, HttpMethod.GET);
|
||||
assertEquals("Invalid HTTP method", HttpMethod.GET, request.getMethod());
|
||||
assertEquals("Invalid HTTP URI", uri, request.getURI());
|
||||
Future<ClientHttpResponse> futureResponse = request.executeAsync();
|
||||
if (futureResponse instanceof ListenableFuture) {
|
||||
ListenableFuture<ClientHttpResponse> listenableFuture =
|
||||
(ListenableFuture<ClientHttpResponse>) futureResponse;
|
||||
|
||||
|
||||
listenableFuture.addCallback(new ListenableFutureCallback<ClientHttpResponse>() {
|
||||
@Override
|
||||
public void onSuccess(ClientHttpResponse result) {
|
||||
try {
|
||||
System.out.println("SUCCESS! " + result.getStatusCode());
|
||||
System.out.println("Callback: " + System.currentTimeMillis());
|
||||
System.out.println(Thread.currentThread().getId());
|
||||
assertEquals("Invalid status code", HttpStatus.NOT_FOUND,
|
||||
result.getStatusCode());
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
ListenableFuture<ClientHttpResponse> listenableFuture = request.executeAsync();
|
||||
listenableFuture.addCallback(new ListenableFutureCallback<ClientHttpResponse>() {
|
||||
@Override
|
||||
public void onSuccess(ClientHttpResponse result) {
|
||||
try {
|
||||
System.out.println("SUCCESS! " + result.getStatusCode());
|
||||
System.out.println("Callback: " + System.currentTimeMillis());
|
||||
System.out.println(Thread.currentThread().getId());
|
||||
assertEquals("Invalid status code", HttpStatus.NOT_FOUND, result.getStatusCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
System.out.println("FAILURE: " + t);
|
||||
catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
ClientHttpResponse response = futureResponse.get();
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
System.out.println("FAILURE: " + ex);
|
||||
}
|
||||
});
|
||||
ClientHttpResponse response = listenableFuture.get();
|
||||
System.out.println("Main thread: " + System.currentTimeMillis());
|
||||
assertEquals("Invalid status code", HttpStatus.NOT_FOUND,
|
||||
response.getStatusCode());
|
||||
assertEquals("Invalid status code", HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
System.out.println(Thread.currentThread().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void echo() throws Exception {
|
||||
AsyncClientHttpRequest
|
||||
request = factory.createAsyncRequest(new URI(baseUrl + "/echo"),
|
||||
HttpMethod.PUT);
|
||||
AsyncClientHttpRequest request = factory.createAsyncRequest(new URI(baseUrl + "/echo"), HttpMethod.PUT);
|
||||
assertEquals("Invalid HTTP method", HttpMethod.PUT, request.getMethod());
|
||||
String headerName = "MyHeader";
|
||||
String headerValue1 = "value1";
|
||||
@@ -118,19 +105,15 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||
request.getHeaders().add(headerName, headerValue2);
|
||||
final byte[] body = "Hello World".getBytes("UTF-8");
|
||||
request.getHeaders().setContentLength(body.length);
|
||||
|
||||
if (request instanceof StreamingHttpOutputMessage) {
|
||||
StreamingHttpOutputMessage streamingRequest =
|
||||
(StreamingHttpOutputMessage) request;
|
||||
streamingRequest.setBody(new StreamingHttpOutputMessage.Body() {
|
||||
@Override
|
||||
public void writeTo(OutputStream outputStream) throws IOException {
|
||||
StreamUtils.copy(body, outputStream);
|
||||
}
|
||||
});
|
||||
StreamingHttpOutputMessage streamingRequest = (StreamingHttpOutputMessage) request;
|
||||
streamingRequest.setBody(outputStream -> StreamUtils.copy(body, outputStream));
|
||||
}
|
||||
else {
|
||||
StreamUtils.copy(body, request.getBody());
|
||||
}
|
||||
|
||||
Future<ClientHttpResponse> futureResponse = request.executeAsync();
|
||||
ClientHttpResponse response = futureResponse.get();
|
||||
try {
|
||||
@@ -148,19 +131,12 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void multipleWrites() throws Exception {
|
||||
AsyncClientHttpRequest
|
||||
request = factory.createAsyncRequest(new URI(baseUrl + "/echo"),
|
||||
HttpMethod.POST);
|
||||
AsyncClientHttpRequest request = factory.createAsyncRequest(new URI(baseUrl + "/echo"), HttpMethod.POST);
|
||||
final byte[] body = "Hello World".getBytes("UTF-8");
|
||||
|
||||
if (request instanceof StreamingHttpOutputMessage) {
|
||||
StreamingHttpOutputMessage streamingRequest =
|
||||
(StreamingHttpOutputMessage) request;
|
||||
streamingRequest.setBody(new StreamingHttpOutputMessage.Body() {
|
||||
@Override
|
||||
public void writeTo(OutputStream outputStream) throws IOException {
|
||||
StreamUtils.copy(body, outputStream);
|
||||
}
|
||||
});
|
||||
StreamingHttpOutputMessage streamingRequest = (StreamingHttpOutputMessage) request;
|
||||
streamingRequest.setBody(outputStream -> StreamUtils.copy(body, outputStream));
|
||||
}
|
||||
else {
|
||||
StreamUtils.copy(body, request.getBody());
|
||||
@@ -178,9 +154,7 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void headersAfterExecute() throws Exception {
|
||||
AsyncClientHttpRequest
|
||||
request = factory.createAsyncRequest(new URI(baseUrl + "/echo"),
|
||||
HttpMethod.POST);
|
||||
AsyncClientHttpRequest request = factory.createAsyncRequest(new URI(baseUrl + "/echo"), HttpMethod.POST);
|
||||
request.getHeaders().add("MyHeader", "value");
|
||||
byte[] body = "Hello World".getBytes("UTF-8");
|
||||
FileCopyUtils.copy(body, request.getBody());
|
||||
@@ -208,9 +182,7 @@ public abstract class AbstractAsyncHttpRequestFactoryTestCase extends
|
||||
protected void assertHttpMethod(String path, HttpMethod method) throws Exception {
|
||||
ClientHttpResponse response = null;
|
||||
try {
|
||||
AsyncClientHttpRequest request = factory.createAsyncRequest(
|
||||
new URI(baseUrl + "/methods/" + path), method);
|
||||
|
||||
AsyncClientHttpRequest request = factory.createAsyncRequest(new URI(baseUrl + "/methods/" + path), method);
|
||||
Future<ClientHttpResponse> futureResponse = request.executeAsync();
|
||||
response = futureResponse.get();
|
||||
assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
|
||||
|
||||
@@ -16,16 +16,12 @@
|
||||
|
||||
package org.springframework.web.client;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -43,6 +39,8 @@ import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
* @author Sebastien Deleuze
|
||||
@@ -51,16 +49,17 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
|
||||
private AsyncRestTemplate template;
|
||||
|
||||
|
||||
@Before
|
||||
public void createTemplate() {
|
||||
template = new AsyncRestTemplate(
|
||||
new HttpComponentsAsyncClientHttpRequestFactory());
|
||||
template = new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getEntity() throws ExecutionException, InterruptedException {
|
||||
Future<ResponseEntity<String>>
|
||||
futureEntity = template.getForEntity(baseUrl + "/{method}", String.class, "get");
|
||||
public void getEntity() throws Exception {
|
||||
Future<ResponseEntity<String>> futureEntity =
|
||||
template.getForEntity(baseUrl + "/{method}", String.class, "get");
|
||||
ResponseEntity<String> entity = futureEntity.get();
|
||||
assertEquals("Invalid content", helloWorld, entity.getBody());
|
||||
assertFalse("No headers", entity.getHeaders().isEmpty());
|
||||
@@ -69,17 +68,17 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleFutureGets() throws ExecutionException, InterruptedException {
|
||||
Future<ResponseEntity<String>>
|
||||
futureEntity = template.getForEntity(baseUrl + "/{method}", String.class, "get");
|
||||
public void multipleFutureGets() throws Exception {
|
||||
Future<ResponseEntity<String>> futureEntity =
|
||||
template.getForEntity(baseUrl + "/{method}", String.class, "get");
|
||||
futureEntity.get();
|
||||
futureEntity.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntityCallback() throws ExecutionException, InterruptedException {
|
||||
ListenableFuture<ResponseEntity<String>>
|
||||
futureEntity = template.getForEntity(baseUrl + "/{method}", String.class, "get");
|
||||
public void getEntityCallback() throws Exception {
|
||||
ListenableFuture<ResponseEntity<String>> futureEntity =
|
||||
template.getForEntity(baseUrl + "/{method}", String.class, "get");
|
||||
futureEntity.addCallback(new ListenableFutureCallback<ResponseEntity<String>>() {
|
||||
@Override
|
||||
public void onSuccess(ResponseEntity<String> entity) {
|
||||
@@ -88,10 +87,9 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
assertEquals("Invalid content-type", textContentType, entity.getHeaders().getContentType());
|
||||
assertEquals("Invalid status code", HttpStatus.OK, entity.getStatusCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
// wait till done
|
||||
@@ -100,80 +98,70 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntityCallbackWithLambdas() throws ExecutionException, InterruptedException {
|
||||
ListenableFuture<ResponseEntity<String>>
|
||||
futureEntity = template.getForEntity(baseUrl + "/{method}", String.class, "get");
|
||||
public void getEntityCallbackWithLambdas() throws Exception {
|
||||
ListenableFuture<ResponseEntity<String>> futureEntity =
|
||||
template.getForEntity(baseUrl + "/{method}", String.class, "get");
|
||||
futureEntity.addCallback((entity) -> {
|
||||
assertEquals("Invalid content", helloWorld, entity.getBody());
|
||||
assertFalse("No headers", entity.getHeaders().isEmpty());
|
||||
assertEquals("Invalid content-type", textContentType, entity.getHeaders().getContentType());
|
||||
assertEquals("Invalid status code", HttpStatus.OK, entity.getStatusCode());
|
||||
}, (t) -> fail(t.getMessage()));
|
||||
}, ex -> fail(ex.getMessage()));
|
||||
// wait till done
|
||||
while (!futureEntity.isDone()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNoResponse() throws ExecutionException, InterruptedException {
|
||||
Future<ResponseEntity<String>>
|
||||
futureEntity = template.getForEntity(baseUrl + "/get/nothing", String.class);
|
||||
public void getNoResponse() throws Exception {
|
||||
Future<ResponseEntity<String>> futureEntity = template.getForEntity(baseUrl + "/get/nothing", String.class);
|
||||
ResponseEntity<String> entity = futureEntity.get();
|
||||
assertNull("Invalid content", entity.getBody());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getNoContentTypeHeader()
|
||||
throws UnsupportedEncodingException, ExecutionException,
|
||||
InterruptedException {
|
||||
Future<ResponseEntity<byte[]>>
|
||||
futureEntity = template.getForEntity(baseUrl + "/get/nocontenttype",
|
||||
byte[].class);
|
||||
public void getNoContentTypeHeader() throws Exception {
|
||||
Future<ResponseEntity<byte[]>> futureEntity = template.getForEntity(baseUrl + "/get/nocontenttype", byte[].class);
|
||||
ResponseEntity<byte[]> responseEntity = futureEntity.get();
|
||||
assertArrayEquals("Invalid content", helloWorld.getBytes("UTF-8"),
|
||||
responseEntity.getBody());
|
||||
assertArrayEquals("Invalid content", helloWorld.getBytes("UTF-8"), responseEntity.getBody());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getNoContent() throws ExecutionException, InterruptedException {
|
||||
Future<ResponseEntity<String>>
|
||||
responseFuture = template.getForEntity(baseUrl + "/status/nocontent", String.class);
|
||||
public void getNoContent() throws Exception {
|
||||
Future<ResponseEntity<String>> responseFuture = template.getForEntity(baseUrl + "/status/nocontent", String.class);
|
||||
ResponseEntity<String> entity = responseFuture.get();
|
||||
assertEquals("Invalid response code", HttpStatus.NO_CONTENT, entity.getStatusCode());
|
||||
assertNull("Invalid content", entity.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNotModified() throws ExecutionException, InterruptedException {
|
||||
Future<ResponseEntity<String>>
|
||||
responseFuture = template.getForEntity(baseUrl + "/status/notmodified",
|
||||
String.class);
|
||||
public void getNotModified() throws Exception {
|
||||
Future<ResponseEntity<String>> responseFuture = template.getForEntity(baseUrl + "/status/notmodified", String.class);
|
||||
ResponseEntity<String> entity = responseFuture.get();
|
||||
assertEquals("Invalid response code", HttpStatus.NOT_MODIFIED, entity.getStatusCode());
|
||||
assertNull("Invalid content", entity.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headForHeaders() throws ExecutionException, InterruptedException {
|
||||
public void headForHeaders() throws Exception {
|
||||
Future<HttpHeaders> headersFuture = template.headForHeaders(baseUrl + "/get");
|
||||
HttpHeaders headers = headersFuture.get();
|
||||
assertTrue("No Content-Type header", headers.containsKey("Content-Type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headForHeadersCallback() throws ExecutionException, InterruptedException {
|
||||
public void headForHeadersCallback() throws Exception {
|
||||
ListenableFuture<HttpHeaders> headersFuture = template.headForHeaders(baseUrl + "/get");
|
||||
headersFuture.addCallback(new ListenableFutureCallback<HttpHeaders>() {
|
||||
@Override
|
||||
public void onSuccess(HttpHeaders result) {
|
||||
assertTrue("No Content-Type header", result.containsKey("Content-Type"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
while (!headersFuture.isDone()) {
|
||||
@@ -181,46 +169,39 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headForHeadersCallbackWithLambdas() throws ExecutionException, InterruptedException {
|
||||
public void headForHeadersCallbackWithLambdas() throws Exception {
|
||||
ListenableFuture<HttpHeaders> headersFuture = template.headForHeaders(baseUrl + "/get");
|
||||
headersFuture.addCallback(result -> assertTrue("No Content-Type header",
|
||||
result.containsKey("Content-Type")), t -> fail(t.getMessage()));
|
||||
result.containsKey("Content-Type")), ex -> fail(ex.getMessage()));
|
||||
while (!headersFuture.isDone()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocation()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void postForLocation() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
HttpEntity<String> entity = new HttpEntity<String>(helloWorld, entityHeaders);
|
||||
Future<URI>
|
||||
locationFuture = template.postForLocation(baseUrl + "/{method}", entity,
|
||||
"post");
|
||||
Future<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
URI location = locationFuture.get();
|
||||
assertEquals("Invalid location", new URI(baseUrl + "/post/1"), location);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocationCallback()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void postForLocationCallback() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
HttpEntity<String> entity = new HttpEntity<String>(helloWorld, entityHeaders);
|
||||
final URI expected = new URI(baseUrl + "/post/1");
|
||||
ListenableFuture<URI>
|
||||
locationFuture = template.postForLocation(baseUrl + "/{method}", entity,
|
||||
"post");
|
||||
ListenableFuture<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
locationFuture.addCallback(new ListenableFutureCallback<URI>() {
|
||||
@Override
|
||||
public void onSuccess(URI result) {
|
||||
assertEquals("Invalid location", expected, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
while (!locationFuture.isDone()) {
|
||||
@@ -228,48 +209,40 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocationCallbackWithLambdas()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void postForLocationCallbackWithLambdas() throws Exception {
|
||||
HttpHeaders entityHeaders = new HttpHeaders();
|
||||
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
|
||||
HttpEntity<String> entity = new HttpEntity<String>(helloWorld, entityHeaders);
|
||||
final URI expected = new URI(baseUrl + "/post/1");
|
||||
ListenableFuture<URI>
|
||||
locationFuture = template.postForLocation(baseUrl + "/{method}", entity,
|
||||
"post");
|
||||
locationFuture.addCallback(result -> assertEquals("Invalid location", expected, result)
|
||||
, t -> fail(t.getMessage()));
|
||||
ListenableFuture<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
|
||||
locationFuture.addCallback(result -> assertEquals("Invalid location", expected, result),
|
||||
ex -> fail(ex.getMessage()));
|
||||
while (!locationFuture.isDone()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForEntity()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void postForEntity() throws Exception {
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(helloWorld);
|
||||
Future<ResponseEntity<String>>
|
||||
responseEntityFuture = template.postForEntity(baseUrl + "/{method}", requestEntity,
|
||||
String.class, "post");
|
||||
Future<ResponseEntity<String>> responseEntityFuture =
|
||||
template.postForEntity(baseUrl + "/{method}", requestEntity, String.class, "post");
|
||||
ResponseEntity<String> responseEntity = responseEntityFuture.get();
|
||||
assertEquals("Invalid content", helloWorld, responseEntity.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForEntityCallback()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void postForEntityCallback() throws Exception {
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(helloWorld);
|
||||
ListenableFuture<ResponseEntity<String>>
|
||||
responseEntityFuture = template.postForEntity(baseUrl + "/{method}", requestEntity,
|
||||
String.class, "post");
|
||||
ListenableFuture<ResponseEntity<String>> responseEntityFuture =
|
||||
template.postForEntity(baseUrl + "/{method}", requestEntity, String.class, "post");
|
||||
responseEntityFuture.addCallback(new ListenableFutureCallback<ResponseEntity<String>>() {
|
||||
@Override
|
||||
public void onSuccess(ResponseEntity<String> result) {
|
||||
assertEquals("Invalid content", helloWorld, result.getBody());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
while (!responseEntityFuture.isDone()) {
|
||||
@@ -277,44 +250,35 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForEntityCallbackWithLambdas()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void postForEntityCallbackWithLambdas() throws Exception {
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(helloWorld);
|
||||
ListenableFuture<ResponseEntity<String>>
|
||||
responseEntityFuture = template.postForEntity(baseUrl + "/{method}", requestEntity,
|
||||
String.class, "post");
|
||||
responseEntityFuture.addCallback(result -> assertEquals("Invalid content", helloWorld, result.getBody())
|
||||
, t -> fail(t.getMessage()));
|
||||
ListenableFuture<ResponseEntity<String>> responseEntityFuture =
|
||||
template.postForEntity(baseUrl + "/{method}", requestEntity, String.class, "post");
|
||||
responseEntityFuture.addCallback(result -> assertEquals("Invalid content", helloWorld, result.getBody()),
|
||||
ex -> fail(ex.getMessage()));
|
||||
while (!responseEntityFuture.isDone()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void put()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void put() throws Exception {
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(helloWorld);
|
||||
Future<?>
|
||||
responseEntityFuture = template.put(baseUrl + "/{method}", requestEntity,
|
||||
"put");
|
||||
Future<?> responseEntityFuture = template.put(baseUrl + "/{method}", requestEntity, "put");
|
||||
responseEntityFuture.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putCallback()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void putCallback() throws Exception {
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(helloWorld);
|
||||
ListenableFuture<?>
|
||||
responseEntityFuture = template.put(baseUrl + "/{method}", requestEntity,
|
||||
"put");
|
||||
ListenableFuture<?> responseEntityFuture = template.put(baseUrl + "/{method}", requestEntity, "put");
|
||||
responseEntityFuture.addCallback(new ListenableFutureCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
while (!responseEntityFuture.isDone()) {
|
||||
@@ -322,26 +286,22 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void delete() throws Exception {
|
||||
Future<?> deletedFuture = template.delete(new URI(baseUrl + "/delete"));
|
||||
|
||||
deletedFuture.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteCallback()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void deleteCallback() throws Exception {
|
||||
ListenableFuture<?> deletedFuture = template.delete(new URI(baseUrl + "/delete"));
|
||||
deletedFuture.addCallback(new ListenableFutureCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
while (!deletedFuture.isDone()) {
|
||||
@@ -349,16 +309,15 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteCallbackWithLambdas()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
public void deleteCallbackWithLambdas() throws Exception {
|
||||
ListenableFuture<?> deletedFuture = template.delete(new URI(baseUrl + "/delete"));
|
||||
deletedFuture.addCallback(result -> assertNull(result), t -> fail(t.getMessage()));
|
||||
deletedFuture.addCallback(result -> assertNull(result), ex -> fail(ex.getMessage()));
|
||||
while (!deletedFuture.isDone()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notFound() throws ExecutionException, InterruptedException {
|
||||
public void notFound() throws Exception {
|
||||
try {
|
||||
Future<?> future = template.execute(baseUrl + "/status/notfound", HttpMethod.GET, null, null);
|
||||
future.get();
|
||||
@@ -372,16 +331,13 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notFoundCallback() throws ExecutionException, InterruptedException {
|
||||
ListenableFuture<?> future =
|
||||
template.execute(baseUrl + "/status/notfound", HttpMethod.GET, null,
|
||||
null);
|
||||
public void notFoundCallback() throws Exception {
|
||||
ListenableFuture<?> future = template.execute(baseUrl + "/status/notfound", HttpMethod.GET, null, null);
|
||||
future.addCallback(new ListenableFutureCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
fail("onSuccess not expected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
assertTrue(t instanceof HttpClientErrorException);
|
||||
@@ -396,23 +352,21 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notFoundCallbackWithLambdas() throws ExecutionException, InterruptedException {
|
||||
ListenableFuture<?> future =
|
||||
template.execute(baseUrl + "/status/notfound", HttpMethod.GET, null,
|
||||
null);
|
||||
future.addCallback(result -> fail("onSuccess not expected"), t -> {
|
||||
assertTrue(t instanceof HttpClientErrorException);
|
||||
HttpClientErrorException ex = (HttpClientErrorException) t;
|
||||
assertEquals(HttpStatus.NOT_FOUND, ex.getStatusCode());
|
||||
assertNotNull(ex.getStatusText());
|
||||
assertNotNull(ex.getResponseBodyAsString());
|
||||
public void notFoundCallbackWithLambdas() throws Exception {
|
||||
ListenableFuture<?> future = template.execute(baseUrl + "/status/notfound", HttpMethod.GET, null, null);
|
||||
future.addCallback(result -> fail("onSuccess not expected"), ex -> {
|
||||
assertTrue(ex instanceof HttpClientErrorException);
|
||||
HttpClientErrorException hcex = (HttpClientErrorException) ex;
|
||||
assertEquals(HttpStatus.NOT_FOUND, hcex.getStatusCode());
|
||||
assertNotNull(hcex.getStatusText());
|
||||
assertNotNull(hcex.getResponseBodyAsString());
|
||||
});
|
||||
while (!future.isDone()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverError() throws ExecutionException, InterruptedException {
|
||||
public void serverError() throws Exception {
|
||||
try {
|
||||
Future<Void> future = template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null);
|
||||
future.get();
|
||||
@@ -426,21 +380,20 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverErrorCallback() throws ExecutionException, InterruptedException {
|
||||
public void serverErrorCallback() throws Exception {
|
||||
ListenableFuture<Void> future = template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null);
|
||||
future.addCallback(new ListenableFutureCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
fail("onSuccess not expected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
assertTrue(t instanceof HttpServerErrorException);
|
||||
HttpServerErrorException ex = (HttpServerErrorException) t;
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode());
|
||||
assertNotNull(ex.getStatusText());
|
||||
assertNotNull(ex.getResponseBodyAsString());
|
||||
public void onFailure(Throwable ex) {
|
||||
assertTrue(ex instanceof HttpServerErrorException);
|
||||
HttpServerErrorException hsex = (HttpServerErrorException) ex;
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, hsex.getStatusCode());
|
||||
assertNotNull(hsex.getStatusText());
|
||||
assertNotNull(hsex.getResponseBodyAsString());
|
||||
}
|
||||
});
|
||||
while (!future.isDone()) {
|
||||
@@ -448,44 +401,39 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverErrorCallbackWithLambdas() throws ExecutionException, InterruptedException {
|
||||
public void serverErrorCallbackWithLambdas() throws Exception {
|
||||
ListenableFuture<Void> future = template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null);
|
||||
future.addCallback(result -> fail("onSuccess not expected"), t -> {
|
||||
assertTrue(t instanceof HttpServerErrorException);
|
||||
HttpServerErrorException ex = (HttpServerErrorException) t;
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode());
|
||||
assertNotNull(ex.getStatusText());
|
||||
assertNotNull(ex.getResponseBodyAsString());
|
||||
future.addCallback(result -> fail("onSuccess not expected"), ex -> {
|
||||
assertTrue(ex instanceof HttpServerErrorException);
|
||||
HttpServerErrorException hsex = (HttpServerErrorException) ex;
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, hsex.getStatusCode());
|
||||
assertNotNull(hsex.getStatusText());
|
||||
assertNotNull(hsex.getResponseBodyAsString());
|
||||
});
|
||||
while (!future.isDone()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsForAllow()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
Future<Set<HttpMethod>>
|
||||
allowedFuture = template.optionsForAllow(new URI(baseUrl + "/get"));
|
||||
public void optionsForAllow() throws Exception {
|
||||
Future<Set<HttpMethod>> allowedFuture = template.optionsForAllow(new URI(baseUrl + "/get"));
|
||||
Set<HttpMethod> allowed = allowedFuture.get();
|
||||
assertEquals("Invalid response",
|
||||
EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS, HttpMethod.HEAD, HttpMethod.TRACE), allowed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsForAllowCallback()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
ListenableFuture<Set<HttpMethod>>
|
||||
allowedFuture = template.optionsForAllow(new URI(baseUrl + "/get"));
|
||||
public void optionsForAllowCallback() throws Exception {
|
||||
ListenableFuture<Set<HttpMethod>> allowedFuture = template.optionsForAllow(new URI(baseUrl + "/get"));
|
||||
allowedFuture.addCallback(new ListenableFutureCallback<Set<HttpMethod>>() {
|
||||
@Override
|
||||
public void onSuccess(Set<HttpMethod> result) {
|
||||
assertEquals("Invalid response", EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS,
|
||||
HttpMethod.HEAD, HttpMethod.TRACE), result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
while (!allowedFuture.isDone()) {
|
||||
@@ -493,13 +441,11 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsForAllowCallbackWithLambdas()
|
||||
throws URISyntaxException, ExecutionException, InterruptedException {
|
||||
ListenableFuture<Set<HttpMethod>>
|
||||
allowedFuture = template.optionsForAllow(new URI(baseUrl + "/get"));
|
||||
public void optionsForAllowCallbackWithLambdas() throws Exception{
|
||||
ListenableFuture<Set<HttpMethod>> allowedFuture = template.optionsForAllow(new URI(baseUrl + "/get"));
|
||||
allowedFuture.addCallback(result -> assertEquals("Invalid response",
|
||||
EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS, HttpMethod.HEAD,HttpMethod.TRACE), result),
|
||||
t-> fail(t.getMessage()));
|
||||
ex -> fail(ex.getMessage()));
|
||||
while (!allowedFuture.isDone()) {
|
||||
}
|
||||
}
|
||||
@@ -511,8 +457,7 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
requestHeaders.set("MyHeader", "MyValue");
|
||||
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
|
||||
Future<ResponseEntity<String>> responseFuture =
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.GET, requestEntity,
|
||||
String.class, "get");
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.GET, requestEntity, String.class, "get");
|
||||
ResponseEntity<String> response = responseFuture.get();
|
||||
assertEquals("Invalid content", helloWorld, response.getBody());
|
||||
}
|
||||
@@ -524,17 +469,15 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
requestHeaders.set("MyHeader", "MyValue");
|
||||
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
|
||||
ListenableFuture<ResponseEntity<String>> responseFuture =
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.GET, requestEntity,
|
||||
String.class, "get");
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.GET, requestEntity, String.class, "get");
|
||||
responseFuture.addCallback(new ListenableFutureCallback<ResponseEntity<String>>() {
|
||||
@Override
|
||||
public void onSuccess(ResponseEntity<String> result) {
|
||||
assertEquals("Invalid content", helloWorld, result.getBody());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
while (!responseFuture.isDone()) {
|
||||
@@ -548,10 +491,9 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
requestHeaders.set("MyHeader", "MyValue");
|
||||
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
|
||||
ListenableFuture<ResponseEntity<String>> responseFuture =
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.GET, requestEntity,
|
||||
String.class, "get");
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.GET, requestEntity, String.class, "get");
|
||||
responseFuture.addCallback(result -> assertEquals("Invalid content", helloWorld,
|
||||
result.getBody()), t -> fail(t.getMessage()));
|
||||
result.getBody()), ex -> fail(ex.getMessage()));
|
||||
while (!responseFuture.isDone()) {
|
||||
}
|
||||
}
|
||||
@@ -562,9 +504,8 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
requestHeaders.set("MyHeader", "MyValue");
|
||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
HttpEntity<String> requestEntity = new HttpEntity<String>(helloWorld, requestHeaders);
|
||||
Future<ResponseEntity<Void>>
|
||||
resultFuture = template.exchange(baseUrl + "/{method}", HttpMethod.POST,
|
||||
requestEntity, Void.class, "post");
|
||||
Future<ResponseEntity<Void>> resultFuture =
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.POST, requestEntity, Void.class, "post");
|
||||
ResponseEntity<Void> result = resultFuture.get();
|
||||
assertEquals("Invalid location", new URI(baseUrl + "/post/1"),
|
||||
result.getHeaders().getLocation());
|
||||
@@ -577,21 +518,18 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
requestHeaders.set("MyHeader", "MyValue");
|
||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
HttpEntity<String> requestEntity = new HttpEntity<String>(helloWorld, requestHeaders);
|
||||
ListenableFuture<ResponseEntity<Void>>
|
||||
resultFuture = template.exchange(baseUrl + "/{method}", HttpMethod.POST,
|
||||
requestEntity, Void.class, "post");
|
||||
ListenableFuture<ResponseEntity<Void>> resultFuture =
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.POST, requestEntity, Void.class, "post");
|
||||
final URI expected =new URI(baseUrl + "/post/1");
|
||||
resultFuture.addCallback(new ListenableFutureCallback<ResponseEntity<Void>>() {
|
||||
@Override
|
||||
public void onSuccess(ResponseEntity<Void> result) {
|
||||
assertEquals("Invalid location", expected,
|
||||
result.getHeaders().getLocation());
|
||||
assertEquals("Invalid location", expected, result.getHeaders().getLocation());
|
||||
assertFalse(result.hasBody());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
fail(t.getMessage());
|
||||
public void onFailure(Throwable ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
});
|
||||
while (!resultFuture.isDone()) {
|
||||
@@ -604,21 +542,19 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
requestHeaders.set("MyHeader", "MyValue");
|
||||
requestHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
HttpEntity<String> requestEntity = new HttpEntity<String>(helloWorld, requestHeaders);
|
||||
ListenableFuture<ResponseEntity<Void>>
|
||||
resultFuture = template.exchange(baseUrl + "/{method}", HttpMethod.POST,
|
||||
requestEntity, Void.class, "post");
|
||||
ListenableFuture<ResponseEntity<Void>> resultFuture =
|
||||
template.exchange(baseUrl + "/{method}", HttpMethod.POST, requestEntity, Void.class, "post");
|
||||
final URI expected =new URI(baseUrl + "/post/1");
|
||||
resultFuture.addCallback(result -> {
|
||||
assertEquals("Invalid location", expected, result.getHeaders().getLocation());
|
||||
assertFalse(result.hasBody());
|
||||
}, t -> fail(t.getMessage()));
|
||||
assertEquals("Invalid location", expected, result.getHeaders().getLocation());
|
||||
assertFalse(result.hasBody());
|
||||
}, ex -> fail(ex.getMessage()));
|
||||
while (!resultFuture.isDone()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipart() throws UnsupportedEncodingException, ExecutionException,
|
||||
InterruptedException {
|
||||
public void multipart() throws Exception {
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
|
||||
parts.add("name 1", "value 1");
|
||||
parts.add("name 2", "value 2+1");
|
||||
@@ -627,8 +563,7 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa
|
||||
parts.add("logo", logo);
|
||||
|
||||
HttpEntity<MultiValueMap<String, Object>> requestBody = new HttpEntity<>(parts);
|
||||
Future<URI> future =
|
||||
template.postForLocation(baseUrl + "/multipart", requestBody);
|
||||
Future<URI> future = template.postForLocation(baseUrl + "/multipart", requestBody);
|
||||
future.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -129,8 +129,9 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
|
||||
|
||||
@Override
|
||||
protected void openConnection() {
|
||||
|
||||
logger.info("Connecting to WebSocket at " + getUri());
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Connecting to WebSocket at " + getUri());
|
||||
}
|
||||
|
||||
ListenableFuture<WebSocketSession> future =
|
||||
this.client.doHandshake(this.webSocketHandler, this.headers, getUri());
|
||||
@@ -142,8 +143,8 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
|
||||
logger.info("Successfully connected");
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
logger.error("Failed to connect", t);
|
||||
public void onFailure(Throwable ex) {
|
||||
logger.error("Failed to connect", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -155,7 +156,7 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
|
||||
|
||||
@Override
|
||||
protected boolean isConnected() {
|
||||
return ((this.webSocketSession != null) && (this.webSocketSession.isOpen()));
|
||||
return (this.webSocketSession != null && this.webSocketSession.isOpen());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,16 @@
|
||||
|
||||
package org.springframework.web.socket.sockjs.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -29,17 +37,8 @@ import org.springframework.web.socket.sockjs.SockJsTransportFailureException;
|
||||
import org.springframework.web.socket.sockjs.frame.SockJsMessageCodec;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* A default implementation of
|
||||
* {@link org.springframework.web.socket.sockjs.client.TransportRequest
|
||||
* TransportRequest}.
|
||||
* A default implementation of {@link TransportRequest}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.1
|
||||
@@ -176,26 +175,24 @@ class DefaultTransportRequest implements TransportRequest {
|
||||
|
||||
private final AtomicBoolean handled = new AtomicBoolean(false);
|
||||
|
||||
|
||||
public ConnectCallback(WebSocketHandler handler, SettableListenableFuture<WebSocketSession> future) {
|
||||
this.handler = handler;
|
||||
this.future = future;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSuccess(WebSocketSession session) {
|
||||
if (this.handled.compareAndSet(false, true)) {
|
||||
this.future.set(session);
|
||||
}
|
||||
else {
|
||||
else if (logger.isErrorEnabled()) {
|
||||
logger.error("Connect success/failure already handled for " + DefaultTransportRequest.this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable failure) {
|
||||
handleFailure(failure, false);
|
||||
public void onFailure(Throwable ex) {
|
||||
handleFailure(ex, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,20 +200,20 @@ class DefaultTransportRequest implements TransportRequest {
|
||||
handleFailure(null, true);
|
||||
}
|
||||
|
||||
private void handleFailure(Throwable failure, boolean isTimeoutFailure) {
|
||||
private void handleFailure(Throwable ex, boolean isTimeoutFailure) {
|
||||
if (this.handled.compareAndSet(false, true)) {
|
||||
if (isTimeoutFailure) {
|
||||
String message = "Connect timed out for " + DefaultTransportRequest.this;
|
||||
logger.error(message);
|
||||
failure = new SockJsTransportFailureException(message, getSockJsUrlInfo().getSessionId(), null);
|
||||
ex = new SockJsTransportFailureException(message, getSockJsUrlInfo().getSessionId(), null);
|
||||
}
|
||||
if (fallbackRequest != null) {
|
||||
logger.error(DefaultTransportRequest.this + " failed. Falling back on next transport.", failure);
|
||||
logger.error(DefaultTransportRequest.this + " failed. Falling back on next transport.", ex);
|
||||
fallbackRequest.connect(this.handler, this.future);
|
||||
}
|
||||
else {
|
||||
logger.error("No more fallback transports after " + DefaultTransportRequest.this, failure);
|
||||
this.future.setException(failure);
|
||||
logger.error("No more fallback transports after " + DefaultTransportRequest.this, ex);
|
||||
this.future.setException(ex);
|
||||
}
|
||||
if (isTimeoutFailure) {
|
||||
try {
|
||||
@@ -224,15 +221,16 @@ class DefaultTransportRequest implements TransportRequest {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.error("Transport failed to run timeout tasks for " + DefaultTransportRequest.this, ex);
|
||||
catch (Throwable ex2) {
|
||||
logger.error("Transport failed to run timeout tasks for " + DefaultTransportRequest.this, ex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.error("Connect success/failure events already took place for " +
|
||||
DefaultTransportRequest.this + ". Ignoring this additional failure event.", failure);
|
||||
DefaultTransportRequest.this + ". Ignoring this additional failure event.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,14 @@
|
||||
|
||||
package org.springframework.web.socket.sockjs.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
@@ -32,11 +38,6 @@ import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* A SockJS {@link Transport} that uses a
|
||||
* {@link org.springframework.web.socket.client.WebSocketClient WebSocketClient}.
|
||||
@@ -59,11 +60,6 @@ public class WebSocketTransport implements Transport, Lifecycle {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<TransportType> getTransportTypes() {
|
||||
return Arrays.asList(TransportType.WEBSOCKET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured {@code WebSocketClient}.
|
||||
*/
|
||||
@@ -71,6 +67,38 @@ public class WebSocketTransport implements Transport, Lifecycle {
|
||||
return this.webSocketClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TransportType> getTransportTypes() {
|
||||
return Arrays.asList(TransportType.WEBSOCKET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
|
||||
final SettableListenableFuture<WebSocketSession> future = new SettableListenableFuture<WebSocketSession>();
|
||||
WebSocketClientSockJsSession session = new WebSocketClientSockJsSession(request, handler, future);
|
||||
handler = new ClientSockJsWebSocketHandler(session);
|
||||
request.addTimeoutTask(session.getTimeoutTask());
|
||||
|
||||
URI url = request.getTransportUrl();
|
||||
WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHandshakeHeaders());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Starting WebSocket session url=" + url);
|
||||
}
|
||||
this.webSocketClient.doHandshake(handler, headers, url).addCallback(
|
||||
new ListenableFutureCallback<WebSocketSession>() {
|
||||
@Override
|
||||
public void onSuccess(WebSocketSession webSocketSession) {
|
||||
// WebSocket session ready, SockJS Session not yet
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
future.setException(ex);
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (!isRunning()) {
|
||||
@@ -106,32 +134,6 @@ public class WebSocketTransport implements Transport, Lifecycle {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
|
||||
final SettableListenableFuture<WebSocketSession> future = new SettableListenableFuture<WebSocketSession>();
|
||||
WebSocketClientSockJsSession session = new WebSocketClientSockJsSession(request, handler, future);
|
||||
handler = new ClientSockJsWebSocketHandler(session);
|
||||
request.addTimeoutTask(session.getTimeoutTask());
|
||||
|
||||
URI url = request.getTransportUrl();
|
||||
WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHandshakeHeaders());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Starting WebSocket session url=" + url);
|
||||
}
|
||||
this.webSocketClient.doHandshake(handler, headers, url).addCallback(
|
||||
new ListenableFutureCallback<WebSocketSession>() {
|
||||
@Override
|
||||
public void onSuccess(WebSocketSession webSocketSession) {
|
||||
// WebSocket session ready, SockJS Session not yet
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
future.setException(t);
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WebSocketTransport[client=" + this.webSocketClient + "]";
|
||||
@@ -144,7 +146,6 @@ public class WebSocketTransport implements Transport, Lifecycle {
|
||||
|
||||
private final AtomicInteger connectCount = new AtomicInteger(0);
|
||||
|
||||
|
||||
private ClientSockJsWebSocketHandler(WebSocketClientSockJsSession session) {
|
||||
Assert.notNull(session);
|
||||
this.sockJsSession = session;
|
||||
|
||||
@@ -16,6 +16,25 @@
|
||||
|
||||
package org.springframework.web.socket.sockjs.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
@@ -24,6 +43,7 @@ import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -41,29 +61,7 @@ import org.springframework.web.socket.server.HandshakeHandler;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Integration tests using the
|
||||
@@ -188,10 +186,9 @@ public abstract class AbstractSockJsIntegrationTests {
|
||||
new ListenableFutureCallback<WebSocketSession>() {
|
||||
@Override
|
||||
public void onSuccess(WebSocketSession result) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
public void onFailure(Throwable ex) {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -136,8 +137,8 @@ public class RestTemplateXhrTransportTests {
|
||||
public void onSuccess(WebSocketSession result) {
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable actual) {
|
||||
if (actual == expected) {
|
||||
public void onFailure(Throwable ex) {
|
||||
if (ex == expected) {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,11 +314,8 @@ public class EnvironmentIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void webApplicationContext() {
|
||||
GenericWebApplicationContext ctx =
|
||||
new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
|
||||
|
||||
GenericWebApplicationContext ctx = new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
|
||||
assertHasStandardServletEnvironment(ctx);
|
||||
|
||||
ctx.setEnvironment(prodWebEnv);
|
||||
ctx.refresh();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user