parent
ac5e2599f7
commit
47a7475898
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -24,6 +24,7 @@ import org.apache.commons.pool2.impl.GenericObjectPool;
|
|||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.aop.TargetSource} implementation that holds
|
||||
|
|
@ -230,6 +231,7 @@ public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implem
|
|||
*/
|
||||
@Override
|
||||
public Object getTarget() throws Exception {
|
||||
Assert.state(this.pool != null, "No Commons ObjectPool available");
|
||||
return this.pool.borrowObject();
|
||||
}
|
||||
|
||||
|
|
@ -238,17 +240,19 @@ public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implem
|
|||
*/
|
||||
@Override
|
||||
public void releaseTarget(Object target) throws Exception {
|
||||
this.pool.returnObject(target);
|
||||
if (this.pool != null) {
|
||||
this.pool.returnObject(target);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActiveCount() throws UnsupportedOperationException {
|
||||
return this.pool.getNumActive();
|
||||
return (this.pool != null ? this.pool.getNumActive() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIdleCount() throws UnsupportedOperationException {
|
||||
return this.pool.getNumIdle();
|
||||
return (this.pool != null ? this.pool.getNumIdle() : 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -257,8 +261,10 @@ public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implem
|
|||
*/
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
logger.debug("Closing Commons ObjectPool");
|
||||
this.pool.close();
|
||||
if (this.pool != null) {
|
||||
logger.debug("Closing Commons ObjectPool");
|
||||
this.pool.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -446,14 +446,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
|||
|
||||
@Override
|
||||
public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
List<T> result = query(sql, new RowMapperResultSetExtractor<>(rowMapper));
|
||||
Assert.state(result != null, "No result list");
|
||||
return result;
|
||||
return nonNull(query(sql, new RowMapperResultSetExtractor<>(rowMapper)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryForMap(String sql) throws DataAccessException {
|
||||
return queryForObject(sql, getColumnMapRowMapper());
|
||||
return nonNull(queryForObject(sql, getColumnMapRowMapper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -481,9 +479,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
|||
|
||||
@Override
|
||||
public SqlRowSet queryForRowSet(String sql) throws DataAccessException {
|
||||
SqlRowSet result = query(sql, new SqlRowSetResultSetExtractor());
|
||||
Assert.state(result != null, "No SqlRowSet");
|
||||
return result;
|
||||
return nonNull(query(sql, new SqlRowSetResultSetExtractor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -798,12 +794,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
|||
|
||||
@Override
|
||||
public Map<String, Object> queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException {
|
||||
return queryForObject(sql, args, argTypes, getColumnMapRowMapper());
|
||||
return nonNull(queryForObject(sql, args, argTypes, getColumnMapRowMapper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryForMap(String sql, @Nullable Object... args) throws DataAccessException {
|
||||
return queryForObject(sql, args, getColumnMapRowMapper());
|
||||
return nonNull(queryForObject(sql, args, getColumnMapRowMapper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -246,12 +246,16 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
|
|||
|
||||
@Override
|
||||
public Map<String, Object> queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException {
|
||||
return queryForObject(sql, paramSource, new ColumnMapRowMapper());
|
||||
Map<String, Object> result = queryForObject(sql, paramSource, new ColumnMapRowMapper());
|
||||
Assert.state(result != null, "No result map");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryForMap(String sql, Map<String, ?> paramMap) throws DataAccessException {
|
||||
return queryForObject(sql, paramMap, new ColumnMapRowMapper());
|
||||
Map<String, Object> result = queryForObject(sql, paramMap, new ColumnMapRowMapper());
|
||||
Assert.state(result != null, "No result map");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -216,11 +216,6 @@ public class MessageListenerAdapter extends AbstractAdaptableMessageListener imp
|
|||
// Regular case: find a handler method reflectively.
|
||||
Object convertedMessage = extractMessage(message);
|
||||
String methodName = getListenerMethodName(message, convertedMessage);
|
||||
if (methodName == null) {
|
||||
throw new javax.jms.IllegalStateException("No default listener method specified: " +
|
||||
"Either specify a non-null value for the 'defaultListenerMethod' property or " +
|
||||
"override the 'getListenerMethodName' method.");
|
||||
}
|
||||
|
||||
// Invoke the handler method with appropriate arguments.
|
||||
Object[] listenerArguments = buildListenerArguments(convertedMessage);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,7 +19,6 @@ package org.springframework.jms.listener.adapter;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.Serializable;
|
||||
import javax.jms.BytesMessage;
|
||||
import javax.jms.IllegalStateException;
|
||||
import javax.jms.InvalidDestinationException;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
|
|
@ -377,40 +376,6 @@ public class MessageListenerAdapterTests {
|
|||
catch (ListenerExecutionFailedException ex) { /* expected */ }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailsIfNoDefaultListenerMethodNameIsSupplied() throws Exception {
|
||||
final TextMessage message = mock(TextMessage.class);
|
||||
given(message.getText()).willReturn(TEXT);
|
||||
|
||||
final MessageListenerAdapter adapter = new MessageListenerAdapter() {
|
||||
@Override
|
||||
protected void handleListenerException(Throwable ex) {
|
||||
assertTrue(ex instanceof IllegalStateException);
|
||||
}
|
||||
};
|
||||
adapter.setDefaultListenerMethod(null);
|
||||
adapter.onMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailsWhenOverriddenGetListenerMethodNameReturnsNull() throws Exception {
|
||||
final TextMessage message = mock(TextMessage.class);
|
||||
given(message.getText()).willReturn(TEXT);
|
||||
|
||||
final MessageListenerAdapter adapter = new MessageListenerAdapter() {
|
||||
@Override
|
||||
protected void handleListenerException(Throwable ex) {
|
||||
assertTrue(ex instanceof javax.jms.IllegalStateException);
|
||||
}
|
||||
@Override
|
||||
protected String getListenerMethodName(Message originalMessage, Object extractedMessage) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
adapter.setDefaultListenerMethod(null);
|
||||
adapter.onMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithResponsiveMessageDelegateWhenReturnTypeIsNotAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
|
||||
final TextMessage sentTextMessage = mock(TextMessage.class);
|
||||
|
|
|
|||
|
|
@ -525,7 +525,7 @@ public class MediaType extends MimeType implements Serializable {
|
|||
* @return the list of media types
|
||||
* @throws InvalidMediaTypeException if the media type value cannot be parsed
|
||||
*/
|
||||
public static List<MediaType> parseMediaTypes(String mediaTypes) {
|
||||
public static List<MediaType> parseMediaTypes(@Nullable String mediaTypes) {
|
||||
if (!StringUtils.hasLength(mediaTypes)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.web.reactive.result.condition;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
|
|
@ -36,20 +37,22 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
|||
|
||||
protected final boolean isNegated;
|
||||
|
||||
|
||||
AbstractNameValueExpression(String expression) {
|
||||
int separator = expression.indexOf('=');
|
||||
if (separator == -1) {
|
||||
this.isNegated = expression.startsWith("!");
|
||||
this.name = isNegated ? expression.substring(1) : expression;
|
||||
this.name = (this.isNegated ? expression.substring(1) : expression);
|
||||
this.value = null;
|
||||
}
|
||||
else {
|
||||
this.isNegated = (separator > 0) && (expression.charAt(separator - 1) == '!');
|
||||
this.name = isNegated ? expression.substring(0, separator - 1) : expression.substring(0, separator);
|
||||
this.name = (this.isNegated ? expression.substring(0, separator - 1) : expression.substring(0, separator));
|
||||
this.value = parseValue(expression.substring(separator + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
|
|
@ -66,10 +69,6 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
|||
return this.isNegated;
|
||||
}
|
||||
|
||||
protected abstract boolean isCaseSensitiveName();
|
||||
|
||||
protected abstract T parseValue(String valueExpression);
|
||||
|
||||
public final boolean match(ServerWebExchange exchange) {
|
||||
boolean isMatch;
|
||||
if (this.value != null) {
|
||||
|
|
@ -81,10 +80,16 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
|||
return this.isNegated != isMatch;
|
||||
}
|
||||
|
||||
|
||||
protected abstract boolean isCaseSensitiveName();
|
||||
|
||||
protected abstract T parseValue(String valueExpression);
|
||||
|
||||
protected abstract boolean matchName(ServerWebExchange exchange);
|
||||
|
||||
protected abstract boolean matchValue(ServerWebExchange exchange);
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
|
@ -103,28 +108,28 @@ abstract class AbstractNameValueExpression<T> implements NameValueExpression<T>
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = isCaseSensitiveName() ? name.hashCode() : name.toLowerCase().hashCode();
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
result = 31 * result + (isNegated ? 1 : 0);
|
||||
int result = (isCaseSensitiveName() ? this.name : this.name.toLowerCase()).hashCode();
|
||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.value);
|
||||
result = 31 * result + (this.isNegated ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (value != null) {
|
||||
builder.append(name);
|
||||
if (isNegated) {
|
||||
if (this.value != null) {
|
||||
builder.append(this.name);
|
||||
if (this.isNegated) {
|
||||
builder.append('!');
|
||||
}
|
||||
builder.append('=');
|
||||
builder.append(value);
|
||||
builder.append(this.value);
|
||||
}
|
||||
else {
|
||||
if (isNegated) {
|
||||
if (this.isNegated) {
|
||||
builder.append('!');
|
||||
}
|
||||
builder.append(name);
|
||||
builder.append(this.name);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -159,12 +159,12 @@ public final class HeadersRequestCondition extends AbstractRequestCondition<Head
|
|||
|
||||
@Override
|
||||
protected boolean matchName(ServerWebExchange exchange) {
|
||||
return exchange.getRequest().getHeaders().get(name) != null;
|
||||
return (exchange.getRequest().getHeaders().get(this.name) != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchValue(ServerWebExchange exchange) {
|
||||
return value.equals(exchange.getRequest().getHeaders().getFirst(name));
|
||||
return (this.value != null && this.value.equals(exchange.getRequest().getHeaders().getFirst(this.name)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -146,7 +146,8 @@ public final class ParamsRequestCondition extends AbstractRequestCondition<Param
|
|||
|
||||
@Override
|
||||
protected boolean matchValue(ServerWebExchange exchange) {
|
||||
return this.value.equals(exchange.getRequest().getQueryParams().getFirst(this.name));
|
||||
return (this.value != null &&
|
||||
this.value.equals(exchange.getRequest().getQueryParams().getFirst(this.name)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class DefaultRendering implements Rendering {
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object view() {
|
||||
return this.view;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ public interface Rendering {
|
|||
/**
|
||||
* Return the selected {@link String} view name or {@link View} object.
|
||||
*/
|
||||
@Nullable
|
||||
Object view();
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue