@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -31,14 +31,16 @@ public abstract class AbstractCacheInvoker {
|
|||||||
|
|
||||||
private CacheErrorHandler errorHandler;
|
private CacheErrorHandler errorHandler;
|
||||||
|
|
||||||
|
|
||||||
|
protected AbstractCacheInvoker() {
|
||||||
|
this(new SimpleCacheErrorHandler());
|
||||||
|
}
|
||||||
|
|
||||||
protected AbstractCacheInvoker(CacheErrorHandler errorHandler) {
|
protected AbstractCacheInvoker(CacheErrorHandler errorHandler) {
|
||||||
Assert.notNull("ErrorHandler must not be null");
|
Assert.notNull("ErrorHandler must not be null");
|
||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractCacheInvoker() {
|
|
||||||
this(new SimpleCacheErrorHandler());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the {@link CacheErrorHandler} instance to use to handle errors
|
* Set the {@link CacheErrorHandler} instance to use to handle errors
|
||||||
@@ -56,6 +58,7 @@ public abstract class AbstractCacheInvoker {
|
|||||||
return this.errorHandler;
|
return this.errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute {@link Cache#get(Object)} on the specified {@link Cache} and
|
* Execute {@link Cache#get(Object)} on the specified {@link Cache} and
|
||||||
* invoke the error handler if an exception occurs. Return {@code null}
|
* invoke the error handler if an exception occurs. Return {@code null}
|
||||||
@@ -67,9 +70,9 @@ public abstract class AbstractCacheInvoker {
|
|||||||
try {
|
try {
|
||||||
return cache.get(key);
|
return cache.get(key);
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException ex) {
|
||||||
getErrorHandler().handleCacheGetError(e, cache, key);
|
getErrorHandler().handleCacheGetError(ex, cache, key);
|
||||||
return null; // If the exception is handled, return a cache miss
|
return null; // If the exception is handled, return a cache miss
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +84,8 @@ public abstract class AbstractCacheInvoker {
|
|||||||
try {
|
try {
|
||||||
cache.put(key, result);
|
cache.put(key, result);
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException ex) {
|
||||||
getErrorHandler().handleCachePutError(e, cache, key, result);
|
getErrorHandler().handleCachePutError(ex, cache, key, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +97,8 @@ public abstract class AbstractCacheInvoker {
|
|||||||
try {
|
try {
|
||||||
cache.evict(key);
|
cache.evict(key);
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException ex) {
|
||||||
getErrorHandler().handleCacheEvictError(e, cache, key);
|
getErrorHandler().handleCacheEvictError(ex, cache, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +110,8 @@ public abstract class AbstractCacheInvoker {
|
|||||||
try {
|
try {
|
||||||
cache.clear();
|
cache.clear();
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
catch (RuntimeException ex) {
|
||||||
getErrorHandler().handleCacheClearError(e, cache);
|
getErrorHandler().handleCacheClearError(ex, cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -76,13 +76,10 @@ import org.springframework.util.StringUtils;
|
|||||||
* @since 3.1
|
* @since 3.1
|
||||||
*/
|
*/
|
||||||
public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||||
implements InitializingBean, SmartInitializingSingleton, ApplicationContextAware {
|
implements ApplicationContextAware, InitializingBean, SmartInitializingSingleton {
|
||||||
|
|
||||||
protected final Log logger = LogFactory.getLog(getClass());
|
protected final Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache of CacheOperationMetadata, keyed by {@link CacheOperationCacheKey}.
|
|
||||||
*/
|
|
||||||
private final Map<CacheOperationCacheKey, CacheOperationMetadata> metadataCache =
|
private final Map<CacheOperationCacheKey, CacheOperationMetadata> metadataCache =
|
||||||
new ConcurrentHashMap<CacheOperationCacheKey, CacheOperationMetadata>(1024);
|
new ConcurrentHashMap<CacheOperationCacheKey, CacheOperationMetadata>(1024);
|
||||||
|
|
||||||
@@ -273,7 +270,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||||||
* Return a bean with the specified name and type. Used to resolve services that
|
* Return a bean with the specified name and type. Used to resolve services that
|
||||||
* are referenced by name in a {@link CacheOperation}.
|
* are referenced by name in a {@link CacheOperation}.
|
||||||
* @param beanName the name of the bean, as defined by the operation
|
* @param beanName the name of the bean, as defined by the operation
|
||||||
* @param expectedType type type for the bean
|
* @param expectedType type for the bean
|
||||||
* @return the bean matching that name
|
* @return the bean matching that name
|
||||||
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist
|
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist
|
||||||
* @see CacheOperation#keyGenerator
|
* @see CacheOperation#keyGenerator
|
||||||
@@ -293,8 +290,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) {
|
protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) {
|
||||||
// check whether aspect is enabled
|
// Check whether aspect is enabled (to cope with cases where the AJ is pulled in automatically)
|
||||||
// to cope with cases where the AJ is pulled in automatically
|
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
Class<?> targetClass = getTargetClass(target);
|
Class<?> targetClass = getTargetClass(target);
|
||||||
Collection<CacheOperation> operations = getCacheOperationSource().getCacheOperations(method, targetClass);
|
Collection<CacheOperation> operations = getCacheOperationSource().getCacheOperations(method, targetClass);
|
||||||
@@ -377,7 +373,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||||||
excluded.add(context);
|
excluded.add(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (VariableNotAvailableException e) {
|
catch (VariableNotAvailableException ex) {
|
||||||
// Ignoring failure due to missing result, consider the cache put has to proceed
|
// Ignoring failure due to missing result, consider the cache put has to proceed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,43 +18,45 @@ package org.springframework.jdbc.object;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A concrete variant of {@link SqlQuery} which can be configured
|
||||||
|
* with a {@link RowMapper}.
|
||||||
|
*
|
||||||
|
* @author Thomas Risberg
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
* @since 3.0
|
||||||
|
* @see #setRowMapperClass
|
||||||
|
*/
|
||||||
public class GenericSqlQuery<T> extends SqlQuery<T> {
|
public class GenericSqlQuery<T> extends SqlQuery<T> {
|
||||||
|
|
||||||
Class<?> rowMapperClass;
|
|
||||||
|
|
||||||
RowMapper<?> rowMapper;
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void setRowMapperClass(Class<? extends RowMapper> rowMapperClass)
|
private Class<? extends RowMapper> rowMapperClass;
|
||||||
throws IllegalAccessException, InstantiationException {
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a {@link RowMapper} class for this query, creating a fresh
|
||||||
|
* {@link RowMapper} instance per execution.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public void setRowMapperClass(Class<? extends RowMapper> rowMapperClass) {
|
||||||
this.rowMapperClass = rowMapperClass;
|
this.rowMapperClass = rowMapperClass;
|
||||||
if (!RowMapper.class.isAssignableFrom(rowMapperClass))
|
|
||||||
throw new IllegalStateException("The specified class '" +
|
|
||||||
rowMapperClass.getName() + " is not a sub class of " +
|
|
||||||
"'org.springframework.jdbc.core.RowMapper'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
super.afterPropertiesSet();
|
super.afterPropertiesSet();
|
||||||
Assert.notNull(rowMapperClass, "The 'rowMapperClass' property is required");
|
Assert.notNull(this.rowMapperClass, "'rowMapperClass' is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected RowMapper<T> newRowMapper(Object[] parameters, Map<?, ?> context) {
|
protected RowMapper<T> newRowMapper(Object[] parameters, Map<?, ?> context) {
|
||||||
try {
|
return BeanUtils.instantiateClass(this.rowMapperClass);
|
||||||
return (RowMapper<T>) rowMapperClass.newInstance();
|
|
||||||
}
|
|
||||||
catch (InstantiationException e) {
|
|
||||||
throw new InvalidDataAccessResourceUsageException("Unable to instantiate RowMapper", e);
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException e) {
|
|
||||||
throw new InvalidDataAccessResourceUsageException("Unable to instantiate RowMapper", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
try {
|
try {
|
||||||
jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
|
jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to set JMSCorrelationID, skipping", e);
|
logger.info("Failed to set JMSCorrelationID - skipping", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Destination jmsReplyTo = getHeaderIfAvailable(headers, JmsHeaders.REPLY_TO, Destination.class);
|
Destination jmsReplyTo = getHeaderIfAvailable(headers, JmsHeaders.REPLY_TO, Destination.class);
|
||||||
@@ -79,8 +79,8 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
try {
|
try {
|
||||||
jmsMessage.setJMSReplyTo(jmsReplyTo);
|
jmsMessage.setJMSReplyTo(jmsReplyTo);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to set JMSReplyTo, skipping", e);
|
logger.info("Failed to set JMSReplyTo - skipping", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String jmsType = getHeaderIfAvailable(headers, JmsHeaders.TYPE, String.class);
|
String jmsType = getHeaderIfAvailable(headers, JmsHeaders.TYPE, String.class);
|
||||||
@@ -88,8 +88,8 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
try {
|
try {
|
||||||
jmsMessage.setJMSType(jmsType);
|
jmsMessage.setJMSType(jmsType);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to set JMSType, skipping", e);
|
logger.info("Failed to set JMSType - skipping", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set<String> headerNames = headers.keySet();
|
Set<String> headerNames = headers.keySet();
|
||||||
@@ -101,14 +101,15 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
String propertyName = this.fromHeaderName(headerName);
|
String propertyName = this.fromHeaderName(headerName);
|
||||||
jmsMessage.setObjectProperty(propertyName, value);
|
jmsMessage.setObjectProperty(propertyName, value);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
if (headerName.startsWith("JMSX")) {
|
if (headerName.startsWith("JMSX")) {
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("skipping reserved header, it cannot be set by client: " + headerName);
|
logger.trace("Skipping reserved header '" + headerName +
|
||||||
|
"' since it cannot be set by client");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (logger.isWarnEnabled()) {
|
else if (logger.isWarnEnabled()) {
|
||||||
logger.warn("failed to map Message header '" + headerName + "' to JMS property", e);
|
logger.warn("Failed to map message header '" + headerName + "' to JMS property", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +118,7 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
if (logger.isWarnEnabled()) {
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("error occurred while mapping from MessageHeaders to JMS properties", ex);
|
logger.warn("Error occurred while mapping from MessageHeaders to JMS properties", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +134,7 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSCorrelationID property, skipping", ex);
|
logger.info("Failed to read JMSCorrelationID property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Destination destination = jmsMessage.getJMSDestination();
|
Destination destination = jmsMessage.getJMSDestination();
|
||||||
@@ -142,21 +143,21 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSDestination property, skipping", ex);
|
logger.info("Failed to read JMSDestination property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
int deliveryMode = jmsMessage.getJMSDeliveryMode();
|
int deliveryMode = jmsMessage.getJMSDeliveryMode();
|
||||||
headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode);
|
headers.put(JmsHeaders.DELIVERY_MODE, deliveryMode);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSDeliveryMode property, skipping", ex);
|
logger.info("Failed to read JMSDeliveryMode property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
long expiration = jmsMessage.getJMSExpiration();
|
long expiration = jmsMessage.getJMSExpiration();
|
||||||
headers.put(JmsHeaders.EXPIRATION, expiration);
|
headers.put(JmsHeaders.EXPIRATION, expiration);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSExpiration property, skipping", ex);
|
logger.info("Failed to read JMSExpiration property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String messageId = jmsMessage.getJMSMessageID();
|
String messageId = jmsMessage.getJMSMessageID();
|
||||||
@@ -165,13 +166,13 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSMessageID property, skipping", ex);
|
logger.info("Failed to read JMSMessageID property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority());
|
headers.put(JmsHeaders.PRIORITY, jmsMessage.getJMSPriority());
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSPriority property, skipping", ex);
|
logger.info("Failed to read JMSPriority property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Destination replyTo = jmsMessage.getJMSReplyTo();
|
Destination replyTo = jmsMessage.getJMSReplyTo();
|
||||||
@@ -180,13 +181,13 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSReplyTo property, skipping", ex);
|
logger.info("Failed to read JMSReplyTo property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
|
headers.put(JmsHeaders.REDELIVERED, jmsMessage.getJMSRedelivered());
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSRedelivered property, skipping", ex);
|
logger.info("Failed to read JMSRedelivered property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String type = jmsMessage.getJMSType();
|
String type = jmsMessage.getJMSType();
|
||||||
@@ -195,13 +196,13 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper<Message> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSType property, skipping", ex);
|
logger.info("Failed to read JMSType property - skipping", ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
|
headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.info("failed to read JMSTimestamp property, skipping", ex);
|
logger.info("Failed to read JMSTimestamp property - skipping", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -98,13 +98,13 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||||
super.setDestinationResolver(new BeanFactoryMessageChannelDestinationResolver(beanFactory));
|
setDestinationResolver(new BeanFactoryMessageChannelDestinationResolver(beanFactory));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void doSend(MessageChannel channel, Message<?> message) {
|
protected final void doSend(MessageChannel channel, Message<?> message) {
|
||||||
Assert.notNull(channel, "'channel' is required");
|
Assert.notNull(channel, "MessageChannel is required");
|
||||||
|
|
||||||
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
|
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
|
||||||
if (accessor != null && accessor.isMutable()) {
|
if (accessor != null && accessor.isMutable()) {
|
||||||
@@ -116,13 +116,13 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
|
|||||||
|
|
||||||
if (!sent) {
|
if (!sent) {
|
||||||
throw new MessageDeliveryException(message,
|
throw new MessageDeliveryException(message,
|
||||||
"failed to send message to channel '" + channel + "' within timeout: " + timeout);
|
"Failed to send message to channel '" + channel + "' within timeout: " + timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final Message<?> doReceive(MessageChannel channel) {
|
protected final Message<?> doReceive(MessageChannel channel) {
|
||||||
Assert.notNull(channel, "'channel' is required");
|
Assert.notNull(channel, "MessageChannel is required");
|
||||||
Assert.state(channel instanceof PollableChannel, "A PollableChannel is required to receive messages");
|
Assert.state(channel instanceof PollableChannel, "A PollableChannel is required to receive messages");
|
||||||
|
|
||||||
long timeout = this.receiveTimeout;
|
long timeout = this.receiveTimeout;
|
||||||
@@ -208,7 +208,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException ex) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
return this.replyMessage;
|
return this.replyMessage;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -61,10 +61,10 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
*/
|
*/
|
||||||
public MultiServerUserRegistry(SimpUserRegistry localRegistry) {
|
public MultiServerUserRegistry(SimpUserRegistry localRegistry) {
|
||||||
Assert.notNull(localRegistry, "'localRegistry' is required.");
|
Assert.notNull(localRegistry, "'localRegistry' is required.");
|
||||||
|
this.id = generateId();
|
||||||
this.localRegistry = localRegistry;
|
this.localRegistry = localRegistry;
|
||||||
this.listener = (this.localRegistry instanceof SmartApplicationListener ?
|
this.listener = (this.localRegistry instanceof SmartApplicationListener ?
|
||||||
(SmartApplicationListener) this.localRegistry : new NoOpSmartApplicationListener());
|
(SmartApplicationListener) this.localRegistry : new NoOpSmartApplicationListener());
|
||||||
this.id = generateId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
try {
|
try {
|
||||||
host = InetAddress.getLocalHost().getHostAddress();
|
host = InetAddress.getLocalHost().getHostAddress();
|
||||||
}
|
}
|
||||||
catch (UnknownHostException e) {
|
catch (UnknownHostException ex) {
|
||||||
host = "unknown";
|
host = "unknown";
|
||||||
}
|
}
|
||||||
return host + "-" + UUID.randomUUID();
|
return host + "-" + UUID.randomUUID();
|
||||||
@@ -160,11 +160,10 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "local=[" + this.localRegistry + "], remote=" + this.remoteRegistries + "]";
|
return "local=[" + this.localRegistry + "], remote=" + this.remoteRegistries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static class UserRegistryDto {
|
private static class UserRegistryDto {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
@@ -173,6 +172,10 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
|
|
||||||
private long expirationTime;
|
private long expirationTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for JSON deserialization.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public UserRegistryDto() {
|
public UserRegistryDto() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,13 +238,16 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static class SimpUserDto implements SimpUser {
|
private static class SimpUserDto implements SimpUser {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private Set<SimpSessionDto> sessions;
|
private Set<SimpSessionDto> sessions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for JSON deserialization.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public SimpUserDto() {
|
public SimpUserDto() {
|
||||||
this.sessions = new HashSet<SimpSessionDto>(1);
|
this.sessions = new HashSet<SimpSessionDto>(1);
|
||||||
}
|
}
|
||||||
@@ -312,7 +318,6 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static class SimpSessionDto implements SimpSession {
|
private static class SimpSessionDto implements SimpSession {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
@@ -321,6 +326,10 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
|
|
||||||
private final Set<SimpSubscriptionDto> subscriptions;
|
private final Set<SimpSubscriptionDto> subscriptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for JSON deserialization.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public SimpSessionDto() {
|
public SimpSessionDto() {
|
||||||
this.subscriptions = new HashSet<SimpSubscriptionDto>(4);
|
this.subscriptions = new HashSet<SimpSubscriptionDto>(4);
|
||||||
}
|
}
|
||||||
@@ -384,7 +393,6 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static class SimpSubscriptionDto implements SimpSubscription {
|
private static class SimpSubscriptionDto implements SimpSubscription {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
@@ -393,6 +401,10 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
|
|
||||||
private String destination;
|
private String destination;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for JSON deserialization.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public SimpSubscriptionDto() {
|
public SimpSubscriptionDto() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -940,7 +940,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
|||||||
try {
|
try {
|
||||||
contentId = URLEncoder.encode(contentId, "UTF-8");
|
contentId = URLEncoder.encode(contentId, "UTF-8");
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException e) {
|
catch (UnsupportedEncodingException ex) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
return CID + contentId;
|
return CID + contentId;
|
||||||
@@ -951,7 +951,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
|||||||
URI uri = new URI(elementNamespace);
|
URI uri = new URI(elementNamespace);
|
||||||
return uri.getHost();
|
return uri.getHost();
|
||||||
}
|
}
|
||||||
catch (URISyntaxException e) {
|
catch (URISyntaxException ex) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
return dataHandler.getName();
|
return dataHandler.getName();
|
||||||
@@ -997,7 +997,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
|
|||||||
try {
|
try {
|
||||||
contentId = URLDecoder.decode(contentId, "UTF-8");
|
contentId = URLDecoder.decode(contentId, "UTF-8");
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException e) {
|
catch (UnsupportedEncodingException ex) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
contentId = '<' + contentId + '>';
|
contentId = '<' + contentId + '>';
|
||||||
|
|||||||
@@ -112,8 +112,8 @@ public class MockAsyncContext implements AsyncContext {
|
|||||||
try {
|
try {
|
||||||
listener.onComplete(new AsyncEvent(this, this.request, this.response));
|
listener.onComplete(new AsyncEvent(this, this.request, this.response));
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
throw new IllegalStateException("AsyncListener failure", e);
|
throw new IllegalStateException("AsyncListener failure", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -26,8 +26,6 @@ import org.springframework.util.Assert;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static org.springframework.core.annotation.AnnotationUtils.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General utility methods for working with <em>profile values</em>.
|
* General utility methods for working with <em>profile values</em>.
|
||||||
*
|
*
|
||||||
@@ -49,12 +47,10 @@ public abstract class ProfileValueUtils {
|
|||||||
* {@link ProfileValueSourceConfiguration
|
* {@link ProfileValueSourceConfiguration
|
||||||
* @ProfileValueSourceConfiguration} annotation and instantiates a new
|
* @ProfileValueSourceConfiguration} annotation and instantiates a new
|
||||||
* instance of that type.
|
* instance of that type.
|
||||||
* <p>
|
* <p>If {@link ProfileValueSourceConfiguration
|
||||||
* If {@link ProfileValueSourceConfiguration
|
|
||||||
* @ProfileValueSourceConfiguration} is not present on the specified
|
* @ProfileValueSourceConfiguration} is not present on the specified
|
||||||
* class or if a custom {@link ProfileValueSource} is not declared, the
|
* class or if a custom {@link ProfileValueSource} is not declared, the
|
||||||
* default {@link SystemProfileValueSource} will be returned instead.
|
* default {@link SystemProfileValueSource} will be returned instead.
|
||||||
*
|
|
||||||
* @param testClass The test class for which the ProfileValueSource should
|
* @param testClass The test class for which the ProfileValueSource should
|
||||||
* be retrieved
|
* be retrieved
|
||||||
* @return the configured (or default) ProfileValueSource for the specified
|
* @return the configured (or default) ProfileValueSource for the specified
|
||||||
@@ -66,10 +62,10 @@ public abstract class ProfileValueUtils {
|
|||||||
Assert.notNull(testClass, "testClass must not be null");
|
Assert.notNull(testClass, "testClass must not be null");
|
||||||
|
|
||||||
Class<ProfileValueSourceConfiguration> annotationType = ProfileValueSourceConfiguration.class;
|
Class<ProfileValueSourceConfiguration> annotationType = ProfileValueSourceConfiguration.class;
|
||||||
ProfileValueSourceConfiguration config = findAnnotation(testClass, annotationType);
|
ProfileValueSourceConfiguration config = AnnotationUtils.findAnnotation(testClass, annotationType);
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Retrieved @ProfileValueSourceConfiguration [" + config + "] for test class ["
|
logger.debug("Retrieved @ProfileValueSourceConfiguration [" + config + "] for test class [" +
|
||||||
+ testClass.getName() + "]");
|
testClass.getName() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<? extends ProfileValueSource> profileValueSourceType;
|
Class<? extends ProfileValueSource> profileValueSourceType;
|
||||||
@@ -80,8 +76,8 @@ public abstract class ProfileValueUtils {
|
|||||||
profileValueSourceType = (Class<? extends ProfileValueSource>) AnnotationUtils.getDefaultValue(annotationType);
|
profileValueSourceType = (Class<? extends ProfileValueSource>) AnnotationUtils.getDefaultValue(annotationType);
|
||||||
}
|
}
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Retrieved ProfileValueSource type [" + profileValueSourceType + "] for class ["
|
logger.debug("Retrieved ProfileValueSource type [" + profileValueSourceType + "] for class [" +
|
||||||
+ testClass.getName() + "]");
|
testClass.getName() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileValueSource profileValueSource;
|
ProfileValueSource profileValueSource;
|
||||||
@@ -92,10 +88,10 @@ public abstract class ProfileValueUtils {
|
|||||||
try {
|
try {
|
||||||
profileValueSource = profileValueSourceType.newInstance();
|
profileValueSource = profileValueSourceType.newInstance();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
if (logger.isWarnEnabled()) {
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn("Could not instantiate a ProfileValueSource of type [" + profileValueSourceType
|
logger.warn("Could not instantiate a ProfileValueSource of type [" + profileValueSourceType +
|
||||||
+ "] for class [" + testClass.getName() + "]: using default.", e);
|
"] for class [" + testClass.getName() + "]: using default.", ex);
|
||||||
}
|
}
|
||||||
profileValueSource = SystemProfileValueSource.getInstance();
|
profileValueSource = SystemProfileValueSource.getInstance();
|
||||||
}
|
}
|
||||||
@@ -108,16 +104,14 @@ public abstract class ProfileValueUtils {
|
|||||||
* Determine if the supplied {@code testClass} is <em>enabled</em> in
|
* Determine if the supplied {@code testClass} is <em>enabled</em> in
|
||||||
* the current environment, as specified by the {@link IfProfileValue
|
* the current environment, as specified by the {@link IfProfileValue
|
||||||
* @IfProfileValue} annotation at the class level.
|
* @IfProfileValue} annotation at the class level.
|
||||||
* <p>
|
* <p>Defaults to {@code true} if no {@link IfProfileValue
|
||||||
* Defaults to {@code true} if no {@link IfProfileValue
|
|
||||||
* @IfProfileValue} annotation is declared.
|
* @IfProfileValue} annotation is declared.
|
||||||
*
|
|
||||||
* @param testClass the test class
|
* @param testClass the test class
|
||||||
* @return {@code true} if the test is <em>enabled</em> in the current
|
* @return {@code true} if the test is <em>enabled</em> in the current
|
||||||
* environment
|
* environment
|
||||||
*/
|
*/
|
||||||
public static boolean isTestEnabledInThisEnvironment(Class<?> testClass) {
|
public static boolean isTestEnabledInThisEnvironment(Class<?> testClass) {
|
||||||
IfProfileValue ifProfileValue = findAnnotation(testClass, IfProfileValue.class);
|
IfProfileValue ifProfileValue = AnnotationUtils.findAnnotation(testClass, IfProfileValue.class);
|
||||||
return isTestEnabledInThisEnvironment(retrieveProfileValueSource(testClass), ifProfileValue);
|
return isTestEnabledInThisEnvironment(retrieveProfileValueSource(testClass), ifProfileValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,10 +121,8 @@ public abstract class ProfileValueUtils {
|
|||||||
* @IfProfileValue} annotation, which may be declared on the test
|
* @IfProfileValue} annotation, which may be declared on the test
|
||||||
* method itself or at the class level. Class-level usage overrides
|
* method itself or at the class level. Class-level usage overrides
|
||||||
* method-level usage.
|
* method-level usage.
|
||||||
* <p>
|
* <p>Defaults to {@code true} if no {@link IfProfileValue
|
||||||
* Defaults to {@code true} if no {@link IfProfileValue
|
|
||||||
* @IfProfileValue} annotation is declared.
|
* @IfProfileValue} annotation is declared.
|
||||||
*
|
|
||||||
* @param testMethod the test method
|
* @param testMethod the test method
|
||||||
* @param testClass the test class
|
* @param testClass the test class
|
||||||
* @return {@code true} if the test is <em>enabled</em> in the current
|
* @return {@code true} if the test is <em>enabled</em> in the current
|
||||||
@@ -146,10 +138,8 @@ public abstract class ProfileValueUtils {
|
|||||||
* @IfProfileValue} annotation, which may be declared on the test
|
* @IfProfileValue} annotation, which may be declared on the test
|
||||||
* method itself or at the class level. Class-level usage overrides
|
* method itself or at the class level. Class-level usage overrides
|
||||||
* method-level usage.
|
* method-level usage.
|
||||||
* <p>
|
* <p>Defaults to {@code true} if no {@link IfProfileValue
|
||||||
* Defaults to {@code true} if no {@link IfProfileValue
|
|
||||||
* @IfProfileValue} annotation is declared.
|
* @IfProfileValue} annotation is declared.
|
||||||
*
|
|
||||||
* @param profileValueSource the ProfileValueSource to use to determine if
|
* @param profileValueSource the ProfileValueSource to use to determine if
|
||||||
* the test is enabled
|
* the test is enabled
|
||||||
* @param testMethod the test method
|
* @param testMethod the test method
|
||||||
@@ -160,11 +150,11 @@ public abstract class ProfileValueUtils {
|
|||||||
public static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, Method testMethod,
|
public static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, Method testMethod,
|
||||||
Class<?> testClass) {
|
Class<?> testClass) {
|
||||||
|
|
||||||
IfProfileValue ifProfileValue = findAnnotation(testClass, IfProfileValue.class);
|
IfProfileValue ifProfileValue = AnnotationUtils.findAnnotation(testClass, IfProfileValue.class);
|
||||||
boolean classLevelEnabled = isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue);
|
boolean classLevelEnabled = isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue);
|
||||||
|
|
||||||
if (classLevelEnabled) {
|
if (classLevelEnabled) {
|
||||||
ifProfileValue = findAnnotation(testMethod, IfProfileValue.class);
|
ifProfileValue = AnnotationUtils.findAnnotation(testMethod, IfProfileValue.class);
|
||||||
return isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue);
|
return isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +165,6 @@ public abstract class ProfileValueUtils {
|
|||||||
* Determine if the {@code value} (or one of the {@code values})
|
* Determine if the {@code value} (or one of the {@code values})
|
||||||
* in the supplied {@link IfProfileValue @IfProfileValue} annotation is
|
* in the supplied {@link IfProfileValue @IfProfileValue} annotation is
|
||||||
* <em>enabled</em> in the current environment.
|
* <em>enabled</em> in the current environment.
|
||||||
*
|
|
||||||
* @param profileValueSource the ProfileValueSource to use to determine if
|
* @param profileValueSource the ProfileValueSource to use to determine if
|
||||||
* the test is enabled
|
* the test is enabled
|
||||||
* @param ifProfileValue the annotation to introspect; may be
|
* @param ifProfileValue the annotation to introspect; may be
|
||||||
@@ -195,8 +184,8 @@ public abstract class ProfileValueUtils {
|
|||||||
String[] annotatedValues = ifProfileValue.values();
|
String[] annotatedValues = ifProfileValue.values();
|
||||||
if (StringUtils.hasLength(ifProfileValue.value())) {
|
if (StringUtils.hasLength(ifProfileValue.value())) {
|
||||||
if (annotatedValues.length > 0) {
|
if (annotatedValues.length > 0) {
|
||||||
throw new IllegalArgumentException("Setting both the 'value' and 'values' attributes "
|
throw new IllegalArgumentException("Setting both the 'value' and 'values' attributes " +
|
||||||
+ "of @IfProfileValue is not allowed: choose one or the other.");
|
"of @IfProfileValue is not allowed: choose one or the other.");
|
||||||
}
|
}
|
||||||
annotatedValues = new String[] { ifProfileValue.value() };
|
annotatedValues = new String[] { ifProfileValue.value() };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,7 +19,6 @@ package org.springframework.test.context.jdbc;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
@@ -147,17 +146,13 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
|||||||
/**
|
/**
|
||||||
* Execute the SQL scripts configured via the supplied {@link Sql @Sql}
|
* Execute the SQL scripts configured via the supplied {@link Sql @Sql}
|
||||||
* annotation for the given {@link ExecutionPhase} and {@link TestContext}.
|
* annotation for the given {@link ExecutionPhase} and {@link TestContext}.
|
||||||
*
|
|
||||||
* <p>Special care must be taken in order to properly support the configured
|
* <p>Special care must be taken in order to properly support the configured
|
||||||
* {@link SqlConfig#transactionMode}.
|
* {@link SqlConfig#transactionMode}.
|
||||||
*
|
|
||||||
* @param sql the {@code @Sql} annotation to parse
|
* @param sql the {@code @Sql} annotation to parse
|
||||||
* @param executionPhase the current execution phase
|
* @param executionPhase the current execution phase
|
||||||
* @param testContext the current {@code TestContext}
|
* @param testContext the current {@code TestContext}
|
||||||
* @param classLevel {@code true} if {@link Sql @Sql} was declared at the
|
* @param classLevel {@code true} if {@link Sql @Sql} was declared at the class level
|
||||||
* class level
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
|
||||||
private void executeSqlScripts(Sql sql, ExecutionPhase executionPhase, TestContext testContext, boolean classLevel)
|
private void executeSqlScripts(Sql sql, ExecutionPhase executionPhase, TestContext testContext, boolean classLevel)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if (executionPhase != sql.executionPhase()) {
|
if (executionPhase != sql.executionPhase()) {
|
||||||
@@ -222,10 +217,10 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
|||||||
DataSource dataSourceFromTxMgr = getDataSourceFromTransactionManager(transactionManager);
|
DataSource dataSourceFromTxMgr = getDataSourceFromTransactionManager(transactionManager);
|
||||||
|
|
||||||
// Ensure user configured an appropriate DataSource/TransactionManager pair.
|
// Ensure user configured an appropriate DataSource/TransactionManager pair.
|
||||||
if ((dataSource != null) && (dataSourceFromTxMgr != null) && !dataSource.equals(dataSourceFromTxMgr)) {
|
if (dataSource != null && dataSourceFromTxMgr != null && !dataSource.equals(dataSourceFromTxMgr)) {
|
||||||
throw new IllegalStateException(String.format("Failed to execute SQL scripts for test context %s: "
|
throw new IllegalStateException(String.format("Failed to execute SQL scripts for test context %s: " +
|
||||||
+ "the configured DataSource [%s] (named '%s') is not the one associated "
|
"the configured DataSource [%s] (named '%s') is not the one associated with " +
|
||||||
+ "with transaction manager [%s] (named '%s').", testContext, dataSource.getClass().getName(),
|
"transaction manager [%s] (named '%s').", testContext, dataSource.getClass().getName(),
|
||||||
dsName, transactionManager.getClass().getName(), tmName));
|
dsName, transactionManager.getClass().getName(), tmName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,8 +234,8 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
final DataSource finalDataSource = dataSource;
|
final DataSource finalDataSource = dataSource;
|
||||||
int propagation = newTxRequired ? TransactionDefinition.PROPAGATION_REQUIRES_NEW
|
int propagation = (newTxRequired ? TransactionDefinition.PROPAGATION_REQUIRES_NEW :
|
||||||
: TransactionDefinition.PROPAGATION_REQUIRED;
|
TransactionDefinition.PROPAGATION_REQUIRED);
|
||||||
|
|
||||||
TransactionAttribute transactionAttribute = TestContextTransactionUtils.createDelegatingTransactionAttribute(
|
TransactionAttribute transactionAttribute = TestContextTransactionUtils.createDelegatingTransactionAttribute(
|
||||||
testContext, new DefaultTransactionAttribute(propagation));
|
testContext, new DefaultTransactionAttribute(propagation));
|
||||||
@@ -263,8 +258,8 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
|||||||
return (DataSource) obj;
|
return (DataSource) obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
/* ignore */
|
// ignore
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -304,9 +299,9 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
|
|||||||
return prefixedResourcePath;
|
return prefixedResourcePath;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String msg = String.format("Could not detect default SQL script for test %s [%s]: "
|
String msg = String.format("Could not detect default SQL script for test %s [%s]: " +
|
||||||
+ "%s does not exist. Either declare statements or scripts via @Sql or make the "
|
"%s does not exist. Either declare statements or scripts via @Sql or make the " +
|
||||||
+ "default SQL script available.", elementType, elementName, classPathResource);
|
"default SQL script available.", elementType, elementName, classPathResource);
|
||||||
logger.error(msg);
|
logger.error(msg);
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -52,18 +52,12 @@ abstract class ActiveProfilesUtils {
|
|||||||
private static final Log logger = LogFactory.getLog(ActiveProfilesUtils.class);
|
private static final Log logger = LogFactory.getLog(ActiveProfilesUtils.class);
|
||||||
|
|
||||||
|
|
||||||
private ActiveProfilesUtils() {
|
|
||||||
/* no-op */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve <em>active bean definition profiles</em> for the supplied {@link Class}.
|
* Resolve <em>active bean definition profiles</em> for the supplied {@link Class}.
|
||||||
*
|
|
||||||
* <p>Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles} flag of
|
* <p>Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles} flag of
|
||||||
* {@link ActiveProfiles @ActiveProfiles} will be taken into consideration.
|
* {@link ActiveProfiles @ActiveProfiles} will be taken into consideration.
|
||||||
* Specifically, if the {@code inheritProfiles} flag is set to {@code true}, profiles
|
* Specifically, if the {@code inheritProfiles} flag is set to {@code true}, profiles
|
||||||
* defined in the test class will be merged with those defined in superclasses.
|
* defined in the test class will be merged with those defined in superclasses.
|
||||||
*
|
|
||||||
* @param testClass the class for which to resolve the active profiles (must not be
|
* @param testClass the class for which to resolve the active profiles (must not be
|
||||||
* {@code null})
|
* {@code null})
|
||||||
* @return the set of active profiles for the specified class, including active
|
* @return the set of active profiles for the specified class, including active
|
||||||
@@ -78,12 +72,12 @@ abstract class ActiveProfilesUtils {
|
|||||||
final List<String[]> profileArrays = new ArrayList<String[]>();
|
final List<String[]> profileArrays = new ArrayList<String[]>();
|
||||||
|
|
||||||
Class<ActiveProfiles> annotationType = ActiveProfiles.class;
|
Class<ActiveProfiles> annotationType = ActiveProfiles.class;
|
||||||
AnnotationDescriptor<ActiveProfiles> descriptor = MetaAnnotationUtils.findAnnotationDescriptor(testClass,
|
AnnotationDescriptor<ActiveProfiles> descriptor =
|
||||||
annotationType);
|
MetaAnnotationUtils.findAnnotationDescriptor(testClass, annotationType);
|
||||||
if (descriptor == null && logger.isDebugEnabled()) {
|
if (descriptor == null && logger.isDebugEnabled()) {
|
||||||
logger.debug(String.format(
|
logger.debug(String.format(
|
||||||
"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
|
"Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
|
||||||
annotationType.getName(), testClass.getName()));
|
annotationType.getName(), testClass.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
while (descriptor != null) {
|
while (descriptor != null) {
|
||||||
@@ -92,8 +86,8 @@ abstract class ActiveProfilesUtils {
|
|||||||
ActiveProfiles annotation = descriptor.synthesizeAnnotation();
|
ActiveProfiles annotation = descriptor.synthesizeAnnotation();
|
||||||
|
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation,
|
logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s]",
|
||||||
declaringClass.getName()));
|
annotation, declaringClass.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<? extends ActiveProfilesResolver> resolverClass = annotation.resolver();
|
Class<? extends ActiveProfilesResolver> resolverClass = annotation.resolver();
|
||||||
@@ -101,22 +95,22 @@ abstract class ActiveProfilesUtils {
|
|||||||
resolverClass = DefaultActiveProfilesResolver.class;
|
resolverClass = DefaultActiveProfilesResolver.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActiveProfilesResolver resolver = null;
|
ActiveProfilesResolver resolver;
|
||||||
try {
|
try {
|
||||||
resolver = BeanUtils.instantiateClass(resolverClass, ActiveProfilesResolver.class);
|
resolver = BeanUtils.instantiateClass(resolverClass, ActiveProfilesResolver.class);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
String msg = String.format("Could not instantiate ActiveProfilesResolver of "
|
String msg = String.format("Could not instantiate ActiveProfilesResolver of type [%s] " +
|
||||||
+ "type [%s] for test class [%s].", resolverClass.getName(), rootDeclaringClass.getName());
|
"for test class [%s]", resolverClass.getName(), rootDeclaringClass.getName());
|
||||||
logger.error(msg);
|
logger.error(msg);
|
||||||
throw new IllegalStateException(msg, e);
|
throw new IllegalStateException(msg, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] profiles = resolver.resolve(rootDeclaringClass);
|
String[] profiles = resolver.resolve(rootDeclaringClass);
|
||||||
if (profiles == null) {
|
if (profiles == null) {
|
||||||
String msg = String.format(
|
String msg = String.format(
|
||||||
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles.",
|
"ActiveProfilesResolver [%s] returned a null array of bean definition profiles",
|
||||||
resolverClass.getName());
|
resolverClass.getName());
|
||||||
logger.error(msg);
|
logger.error(msg);
|
||||||
throw new IllegalStateException(msg);
|
throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
@@ -124,7 +118,7 @@ abstract class ActiveProfilesUtils {
|
|||||||
profileArrays.add(profiles);
|
profileArrays.add(profiles);
|
||||||
|
|
||||||
descriptor = (annotation.inheritProfiles() ? MetaAnnotationUtils.findAnnotationDescriptor(
|
descriptor = (annotation.inheritProfiles() ? MetaAnnotationUtils.findAnnotationDescriptor(
|
||||||
rootDeclaringClass.getSuperclass(), annotationType) : null);
|
rootDeclaringClass.getSuperclass(), annotationType) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reverse the list so that we can traverse "down" the hierarchy.
|
// Reverse the list so that we can traverse "down" the hierarchy.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
|
|||||||
* @since 4.2
|
* @since 4.2
|
||||||
* @see org.springframework.aop.support.AopUtils
|
* @see org.springframework.aop.support.AopUtils
|
||||||
* @see org.springframework.aop.framework.AopProxyUtils
|
* @see org.springframework.aop.framework.AopProxyUtils
|
||||||
|
* @see ReflectionTestUtils
|
||||||
*/
|
*/
|
||||||
public class AopTestUtils {
|
public class AopTestUtils {
|
||||||
|
|
||||||
@@ -41,7 +42,6 @@ public class AopTestUtils {
|
|||||||
* {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will
|
* {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will
|
||||||
* be returned; otherwise, the {@code candidate} will be returned
|
* be returned; otherwise, the {@code candidate} will be returned
|
||||||
* <em>as is</em>.
|
* <em>as is</em>.
|
||||||
*
|
|
||||||
* @param candidate the instance to check (potentially a Spring AOP proxy);
|
* @param candidate the instance to check (potentially a Spring AOP proxy);
|
||||||
* never {@code null}
|
* never {@code null}
|
||||||
* @return the target object or the {@code candidate}; never {@code null}
|
* @return the target object or the {@code candidate}; never {@code null}
|
||||||
@@ -57,8 +57,8 @@ public class AopTestUtils {
|
|||||||
return (T) ((Advised) candidate).getTargetSource().getTarget();
|
return (T) ((Advised) candidate).getTargetSource().getTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException("Failed to unwrap proxied object.", e);
|
throw new IllegalStateException("Failed to unwrap proxied object", ex);
|
||||||
}
|
}
|
||||||
return (T) candidate;
|
return (T) candidate;
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,6 @@ public class AopTestUtils {
|
|||||||
* {@linkplain AopUtils#isAopProxy proxy}, the ultimate target of all
|
* {@linkplain AopUtils#isAopProxy proxy}, the ultimate target of all
|
||||||
* nested proxies will be returned; otherwise, the {@code candidate}
|
* nested proxies will be returned; otherwise, the {@code candidate}
|
||||||
* will be returned <em>as is</em>.
|
* will be returned <em>as is</em>.
|
||||||
*
|
|
||||||
* @param candidate the instance to check (potentially a Spring AOP proxy);
|
* @param candidate the instance to check (potentially a Spring AOP proxy);
|
||||||
* never {@code null}
|
* never {@code null}
|
||||||
* @return the ultimate target object or the {@code candidate}; never
|
* @return the ultimate target object or the {@code candidate}; never
|
||||||
@@ -88,8 +87,8 @@ public class AopTestUtils {
|
|||||||
return (T) getUltimateTargetObject(((Advised) candidate).getTargetSource().getTarget());
|
return (T) getUltimateTargetObject(((Advised) candidate).getTargetSource().getTarget());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException("Failed to unwrap proxied object.", e);
|
throw new IllegalStateException("Failed to unwrap proxied object", ex);
|
||||||
}
|
}
|
||||||
return (T) candidate;
|
return (T) candidate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.test.web.client.match;
|
package org.springframework.test.web.client.match;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -192,8 +193,8 @@ public class XpathRequestMatchers {
|
|||||||
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
|
||||||
matchInternal(mockRequest);
|
matchInternal(mockRequest);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new AssertionError("Failed to parse XML request content: " + e.getMessage());
|
throw new AssertionError("Failed to parse XML request content: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -133,8 +133,8 @@ public class MockHttpServletRequestBuilder
|
|||||||
* @since 4.0.3
|
* @since 4.0.3
|
||||||
*/
|
*/
|
||||||
MockHttpServletRequestBuilder(HttpMethod httpMethod, URI url) {
|
MockHttpServletRequestBuilder(HttpMethod httpMethod, URI url) {
|
||||||
Assert.notNull(httpMethod, "httpMethod is required");
|
Assert.notNull(httpMethod, "'httpMethod' is required");
|
||||||
Assert.notNull(url, "url is required");
|
Assert.notNull(url, "'url' is required");
|
||||||
this.method = httpMethod;
|
this.method = httpMethod;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
@@ -224,7 +224,7 @@ public class MockHttpServletRequestBuilder
|
|||||||
* @param mediaTypes one or more media types
|
* @param mediaTypes one or more media types
|
||||||
*/
|
*/
|
||||||
public MockHttpServletRequestBuilder accept(MediaType... mediaTypes) {
|
public MockHttpServletRequestBuilder accept(MediaType... mediaTypes) {
|
||||||
Assert.notEmpty(mediaTypes, "No 'Accept' media types");
|
Assert.notEmpty(mediaTypes, "'mediaTypes' must not be empty");
|
||||||
this.headers.set("Accept", MediaType.toString(Arrays.asList(mediaTypes)));
|
this.headers.set("Accept", MediaType.toString(Arrays.asList(mediaTypes)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ public class MockHttpServletRequestBuilder
|
|||||||
* @param mediaTypes one or more media types
|
* @param mediaTypes one or more media types
|
||||||
*/
|
*/
|
||||||
public MockHttpServletRequestBuilder accept(String... mediaTypes) {
|
public MockHttpServletRequestBuilder accept(String... mediaTypes) {
|
||||||
Assert.notEmpty(mediaTypes, "No 'Accept' media types");
|
Assert.notEmpty(mediaTypes, "'mediaTypes' must not be empty");
|
||||||
List<MediaType> result = new ArrayList<MediaType>(mediaTypes.length);
|
List<MediaType> result = new ArrayList<MediaType>(mediaTypes.length);
|
||||||
for (String mediaType : mediaTypes) {
|
for (String mediaType : mediaTypes) {
|
||||||
result.add(MediaType.parseMediaType(mediaType));
|
result.add(MediaType.parseMediaType(mediaType));
|
||||||
@@ -260,7 +260,7 @@ public class MockHttpServletRequestBuilder
|
|||||||
try {
|
try {
|
||||||
this.content = content.getBytes("UTF-8");
|
this.content = content.getBytes("UTF-8");
|
||||||
}
|
}
|
||||||
catch (UnsupportedEncodingException e) {
|
catch (UnsupportedEncodingException ex) {
|
||||||
// should never happen
|
// should never happen
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -271,7 +271,6 @@ public class MockHttpServletRequestBuilder
|
|||||||
* @param cookies the cookies to add
|
* @param cookies the cookies to add
|
||||||
*/
|
*/
|
||||||
public MockHttpServletRequestBuilder cookie(Cookie... cookies) {
|
public MockHttpServletRequestBuilder cookie(Cookie... cookies) {
|
||||||
Assert.notNull(cookies, "'cookies' must not be null");
|
|
||||||
Assert.notEmpty(cookies, "'cookies' must not be empty");
|
Assert.notEmpty(cookies, "'cookies' must not be empty");
|
||||||
this.cookies.addAll(Arrays.asList(cookies));
|
this.cookies.addAll(Arrays.asList(cookies));
|
||||||
return this;
|
return this;
|
||||||
@@ -320,7 +319,7 @@ public class MockHttpServletRequestBuilder
|
|||||||
* @param sessionAttributes the session attributes
|
* @param sessionAttributes the session attributes
|
||||||
*/
|
*/
|
||||||
public MockHttpServletRequestBuilder sessionAttrs(Map<String, Object> sessionAttributes) {
|
public MockHttpServletRequestBuilder sessionAttrs(Map<String, Object> sessionAttributes) {
|
||||||
Assert.notEmpty(sessionAttributes, "'sessionAttrs' must not be empty");
|
Assert.notEmpty(sessionAttributes, "'sessionAttributes' must not be empty");
|
||||||
for (String name : sessionAttributes.keySet()) {
|
for (String name : sessionAttributes.keySet()) {
|
||||||
sessionAttr(name, sessionAttributes.get(name));
|
sessionAttr(name, sessionAttributes.get(name));
|
||||||
}
|
}
|
||||||
@@ -342,7 +341,7 @@ public class MockHttpServletRequestBuilder
|
|||||||
* @param flashAttributes the flash attributes
|
* @param flashAttributes the flash attributes
|
||||||
*/
|
*/
|
||||||
public MockHttpServletRequestBuilder flashAttrs(Map<String, Object> flashAttributes) {
|
public MockHttpServletRequestBuilder flashAttrs(Map<String, Object> flashAttributes) {
|
||||||
Assert.notEmpty(flashAttributes, "'flashAttrs' must not be empty");
|
Assert.notEmpty(flashAttributes, "'flashAttributes' must not be empty");
|
||||||
for (String name : flashAttributes.keySet()) {
|
for (String name : flashAttributes.keySet()) {
|
||||||
flashAttr(name, flashAttributes.get(name));
|
flashAttr(name, flashAttributes.get(name));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -250,7 +250,8 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return HttpStatus.valueOf(response.getStatus()).is2xxSuccessful();
|
return HttpStatus.valueOf(response.getStatus()).is2xxSuccessful();
|
||||||
} catch (IllegalArgumentException e) {
|
}
|
||||||
|
catch (IllegalArgumentException ex) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -46,40 +46,47 @@ import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
|
|||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 3.1
|
* @since 3.1
|
||||||
*
|
|
||||||
* @see DefaultServletHandlerConfigurer
|
* @see DefaultServletHandlerConfigurer
|
||||||
*/
|
*/
|
||||||
public class ResourceHandlerRegistry {
|
public class ResourceHandlerRegistry {
|
||||||
|
|
||||||
private final ServletContext servletContext;
|
private final ServletContext servletContext;
|
||||||
|
|
||||||
private final ApplicationContext appContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
private final List<ResourceHandlerRegistration> registrations = new ArrayList<ResourceHandlerRegistration>();
|
private final List<ResourceHandlerRegistration> registrations = new ArrayList<ResourceHandlerRegistration>();
|
||||||
|
|
||||||
private int order = Integer.MAX_VALUE -1;
|
private int order = Integer.MAX_VALUE -1;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new resource handler registry for the given application context.
|
||||||
|
* @param applicationContext the Spring application context
|
||||||
|
* @param servletContext the corresponding Servlet context
|
||||||
|
*/
|
||||||
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext) {
|
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext) {
|
||||||
Assert.notNull(applicationContext, "ApplicationContext is required");
|
Assert.notNull(applicationContext, "ApplicationContext is required");
|
||||||
this.appContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
this.servletContext = servletContext;
|
this.servletContext = servletContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a resource handler for serving static resources based on the specified URL path patterns.
|
* Add a resource handler for serving static resources based on the specified URL path
|
||||||
* The handler will be invoked for every incoming request that matches to one of the specified path patterns.
|
* patterns. The handler will be invoked for every incoming request that matches to
|
||||||
* @return A {@link ResourceHandlerRegistration} to use to further configure the registered resource handler.
|
* one of the specified path patterns.
|
||||||
|
* @return A {@link ResourceHandlerRegistration} to use to further configure the
|
||||||
|
* registered resource handler
|
||||||
*/
|
*/
|
||||||
public ResourceHandlerRegistration addResourceHandler(String... pathPatterns) {
|
public ResourceHandlerRegistration addResourceHandler(String... pathPatterns) {
|
||||||
ResourceHandlerRegistration registration = new ResourceHandlerRegistration(this.appContext, pathPatterns);
|
ResourceHandlerRegistration registration =
|
||||||
|
new ResourceHandlerRegistration(this.applicationContext, pathPatterns);
|
||||||
this.registrations.add(registration);
|
this.registrations.add(registration);
|
||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether a resource handler has already been registered for the given pathPattern.
|
* Whether a resource handler has already been registered for the given path pattern.
|
||||||
*/
|
*/
|
||||||
public boolean hasMappingForPattern(String pathPattern) {
|
public boolean hasMappingForPattern(String pathPattern) {
|
||||||
for (ResourceHandlerRegistration registration : this.registrations) {
|
for (ResourceHandlerRegistration registration : this.registrations) {
|
||||||
@@ -91,8 +98,9 @@ public class ResourceHandlerRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the order to use for resource handling relative to other {@link HandlerMapping}s configured in
|
* Specify the order to use for resource handling relative to other {@link HandlerMapping}s
|
||||||
* the Spring MVC application context. The default value used is {@code Integer.MAX_VALUE-1}.
|
* configured in the Spring MVC application context.
|
||||||
|
* <p>The default value used is {@code Integer.MAX_VALUE-1}.
|
||||||
*/
|
*/
|
||||||
public ResourceHandlerRegistry setOrder(int order) {
|
public ResourceHandlerRegistry setOrder(int order) {
|
||||||
this.order = order;
|
this.order = order;
|
||||||
@@ -100,10 +108,11 @@ public class ResourceHandlerRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a handler mapping with the mapped resource handlers; or {@code null} in case of no registrations.
|
* Return a handler mapping with the mapped resource handlers; or {@code null} in case
|
||||||
|
* of no registrations.
|
||||||
*/
|
*/
|
||||||
protected AbstractHandlerMapping getHandlerMapping() {
|
protected AbstractHandlerMapping getHandlerMapping() {
|
||||||
if (registrations.isEmpty()) {
|
if (this.registrations.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,12 +121,12 @@ public class ResourceHandlerRegistry {
|
|||||||
for (String pathPattern : registration.getPathPatterns()) {
|
for (String pathPattern : registration.getPathPatterns()) {
|
||||||
ResourceHttpRequestHandler handler = registration.getRequestHandler();
|
ResourceHttpRequestHandler handler = registration.getRequestHandler();
|
||||||
handler.setServletContext(this.servletContext);
|
handler.setServletContext(this.servletContext);
|
||||||
handler.setApplicationContext(this.appContext);
|
handler.setApplicationContext(this.applicationContext);
|
||||||
try {
|
try {
|
||||||
handler.afterPropertiesSet();
|
handler.afterPropertiesSet();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", e);
|
throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", ex);
|
||||||
}
|
}
|
||||||
urlMap.put(pathPattern, handler);
|
urlMap.put(pathPattern, handler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
|||||||
try {
|
try {
|
||||||
pageContext.getOut().print(url);
|
pageContext.getOut().print(url);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
throw new JspException(e);
|
throw new JspException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,8 +25,8 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient super class for many html tags that render content using the databinding
|
* Convenient super class for many html tags that render content using the databinding
|
||||||
* features of the {@link AbstractHtmlElementTag AbstractHtmlElementTag}. The only thing sub tags
|
* features of the {@link AbstractHtmlElementTag AbstractHtmlElementTag}. The only thing
|
||||||
* need to do is override {@link #renderDefaultContent(TagWriter)}.
|
* sub-tags need to do is override {@link #renderDefaultContent(TagWriter)}.
|
||||||
*
|
*
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
@@ -136,8 +136,8 @@ public abstract class AbstractHtmlElementBodyTag extends AbstractHtmlElementTag
|
|||||||
try {
|
try {
|
||||||
bodyContent.writeOut(bodyContent.getEnclosingWriter());
|
bodyContent.writeOut(bodyContent.getEnclosingWriter());
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
throw new JspException("Unable to write buffered body content.", e);
|
throw new JspException("Unable to write buffered body content.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.servlet.view.tiles3;
|
package org.springframework.web.servlet.view.tiles3;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -46,8 +47,8 @@ public class SpringLocaleResolver extends DefaultLocaleResolver {
|
|||||||
return RequestContextUtils.getLocale(servletRequest);
|
return RequestContextUtils.getLocale(servletRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NotAServletEnvironmentException e) {
|
catch (NotAServletEnvironmentException ex) {
|
||||||
// Ignore
|
// ignore
|
||||||
}
|
}
|
||||||
return super.resolveLocale(request);
|
return super.resolveLocale(request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif
|
|||||||
}
|
}
|
||||||
this.client.start();
|
this.client.start();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException("Failed to start Jetty client", e);
|
throw new IllegalStateException("Failed to start Jetty client", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,8 +134,8 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif
|
|||||||
}
|
}
|
||||||
this.client.stop();
|
this.client.stop();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
logger.error("Error stopping Jetty WebSocketClient", e);
|
logger.error("Error stopping Jetty WebSocketClient", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,9 +24,11 @@ import org.springframework.web.socket.WebSocketHandler;
|
|||||||
import org.springframework.web.socket.WebSocketSession;
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenient base class for {@link WebSocketHandler} implementation that process binary
|
* A convenient base class for {@link WebSocketHandler} implementations
|
||||||
* messages only. Text messages are rejected with {@link CloseStatus#NOT_ACCEPTABLE}. All
|
* that process binary messages only.
|
||||||
* other methods have empty implementations.
|
*
|
||||||
|
* <p>Text messages are rejected with {@link CloseStatus#NOT_ACCEPTABLE}.
|
||||||
|
* All other methods have empty implementations.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
@@ -39,7 +41,7 @@ public class BinaryWebSocketHandler extends AbstractWebSocketHandler {
|
|||||||
try {
|
try {
|
||||||
session.close(CloseStatus.NOT_ACCEPTABLE.withReason("Text messages not supported"));
|
session.close(CloseStatus.NOT_ACCEPTABLE.withReason("Text messages not supported"));
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException ex) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,9 +24,11 @@ import org.springframework.web.socket.WebSocketHandler;
|
|||||||
import org.springframework.web.socket.WebSocketSession;
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenient base class for {@link WebSocketHandler} implementation that process text
|
* A convenient base class for {@link WebSocketHandler} implementations
|
||||||
* messages only. Binary messages are rejected with {@link CloseStatus#NOT_ACCEPTABLE}. All
|
* that process text messages only.
|
||||||
* other methods have empty implementations.
|
*
|
||||||
|
* <p>Binary messages are rejected with {@link CloseStatus#NOT_ACCEPTABLE}.
|
||||||
|
* All other methods have empty implementations.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ public class JettyXhrTransport extends AbstractXhrTransport implements Lifecycle
|
|||||||
this.httpClient.start();
|
this.httpClient.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new SockJsException("Failed to start " + this, e);
|
throw new SockJsException("Failed to start " + this, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +94,8 @@ public class JettyXhrTransport extends AbstractXhrTransport implements Lifecycle
|
|||||||
this.httpClient.stop();
|
this.httpClient.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw new SockJsException("Failed to stop " + this, e);
|
throw new SockJsException("Failed to stop " + this, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +154,7 @@ public class JettyXhrTransport extends AbstractXhrTransport implements Lifecycle
|
|||||||
new ResponseEntity<String>(responseHeaders, status));
|
new ResponseEntity<String>(responseHeaders, status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void addHttpHeaders(Request request, HttpHeaders headers) {
|
private static void addHttpHeaders(Request request, HttpHeaders headers) {
|
||||||
for (String name : headers.keySet()) {
|
for (String name : headers.keySet()) {
|
||||||
for (String value : headers.get(name)) {
|
for (String value : headers.get(name)) {
|
||||||
@@ -194,7 +195,6 @@ public class JettyXhrTransport extends AbstractXhrTransport implements Lifecycle
|
|||||||
|
|
||||||
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
|
||||||
public SockJsResponseListener(URI url, HttpHeaders headers, XhrClientSockJsSession sockJsSession,
|
public SockJsResponseListener(URI url, HttpHeaders headers, XhrClientSockJsSession sockJsSession,
|
||||||
SettableListenableFuture<WebSocketSession> connectFuture) {
|
SettableListenableFuture<WebSocketSession> connectFuture) {
|
||||||
|
|
||||||
@@ -204,7 +204,6 @@ public class JettyXhrTransport extends AbstractXhrTransport implements Lifecycle
|
|||||||
this.sockJsSession = sockJsSession;
|
this.sockJsSession = sockJsSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBegin(Response response) {
|
public void onBegin(Response response) {
|
||||||
if (response.getStatus() != 200) {
|
if (response.getStatus() != 200) {
|
||||||
|
|||||||
Reference in New Issue
Block a user