Http(Async)Client not actually nullable, plus MethodInterceptor nullability
Issue: SPR-15720
This commit is contained in:
parent
1e66191cbd
commit
c292a89b24
|
@ -98,6 +98,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
||||||
Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
|
Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
|
||||||
Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
|
Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
|
||||||
|
|
|
@ -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");
|
* 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,6 +24,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||||
import org.springframework.aop.DynamicIntroductionAdvice;
|
import org.springframework.aop.DynamicIntroductionAdvice;
|
||||||
import org.springframework.aop.IntroductionInterceptor;
|
import org.springframework.aop.IntroductionInterceptor;
|
||||||
import org.springframework.aop.ProxyMethodInvocation;
|
import org.springframework.aop.ProxyMethodInvocation;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,6 +86,7 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction
|
||||||
* method, which handles introduced interfaces and forwarding to the target.
|
* method, which handles introduced interfaces and forwarding to the target.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||||
if (isMethodOnIntroducedInterface(mi)) {
|
if (isMethodOnIntroducedInterface(mi)) {
|
||||||
Object delegate = getIntroductionDelegateFor(mi.getThis());
|
Object delegate = getIntroductionDelegateFor(mi.getThis());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 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.
|
||||||
|
@ -21,6 +21,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||||
import org.springframework.aop.DynamicIntroductionAdvice;
|
import org.springframework.aop.DynamicIntroductionAdvice;
|
||||||
import org.springframework.aop.IntroductionInterceptor;
|
import org.springframework.aop.IntroductionInterceptor;
|
||||||
import org.springframework.aop.ProxyMethodInvocation;
|
import org.springframework.aop.ProxyMethodInvocation;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,6 +101,7 @@ public class DelegatingIntroductionInterceptor extends IntroductionInfoSupport
|
||||||
* method, which handles introduced interfaces and forwarding to the target.
|
* method, which handles introduced interfaces and forwarding to the target.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||||
if (isMethodOnIntroducedInterface(mi)) {
|
if (isMethodOnIntroducedInterface(mi)) {
|
||||||
// Using the following method rather than direct reflection, we
|
// Using the following method rather than direct reflection, we
|
||||||
|
|
|
@ -22,6 +22,8 @@ import java.lang.reflect.Method;
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AOP Alliance MethodInterceptor for declarative cache
|
* AOP Alliance MethodInterceptor for declarative cache
|
||||||
* management using the common Spring caching infrastructure
|
* management using the common Spring caching infrastructure
|
||||||
|
@ -42,6 +44,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||||
public class CacheInterceptor extends CacheAspectSupport implements MethodInterceptor, Serializable {
|
public class CacheInterceptor extends CacheAspectSupport implements MethodInterceptor, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
||||||
Method method = invocation.getMethod();
|
Method method = invocation.getMethod();
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,7 @@ public abstract class AbstractSlsbInvokerInterceptor extends JndiObjectLocator
|
||||||
* {@link #invokeInContext}.
|
* {@link #invokeInContext}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||||
Context ctx = (this.exposeAccessContext ? getJndiTemplate().getContext() : null);
|
Context ctx = (this.exposeAccessContext ? getJndiTemplate().getContext() : null);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -354,6 +354,7 @@ public class MBeanClientInterceptor
|
||||||
* @see #handleConnectFailure
|
* @see #handleConnectFailure
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||||
// Lazily connect to MBeanServer if necessary.
|
// Lazily connect to MBeanServer if necessary.
|
||||||
synchronized (this.preparationMonitor) {
|
synchronized (this.preparationMonitor) {
|
||||||
|
|
|
@ -192,6 +192,7 @@ public class JmsInvokerClientInterceptor implements MethodInterceptor, Initializ
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||||
if (AopUtils.isToStringMethod(methodInvocation.getMethod())) {
|
if (AopUtils.isToStringMethod(methodInvocation.getMethod())) {
|
||||||
return "JMS invoker proxy for queue [" + this.queue + "]";
|
return "JMS invoker proxy for queue [" + this.queue + "]";
|
||||||
|
|
|
@ -420,8 +420,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||||
conHolder.setTimeoutInSeconds(timeoutToUse);
|
conHolder.setTimeoutInSeconds(timeoutToUse);
|
||||||
}
|
}
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Exposing JPA transaction as JDBC transaction [" +
|
logger.debug("Exposing JPA transaction as JDBC transaction [" + conHandle + "]");
|
||||||
conHolder.getConnectionHandle() + "]");
|
|
||||||
}
|
}
|
||||||
TransactionSynchronizationManager.bindResource(getDataSource(), conHolder);
|
TransactionSynchronizationManager.bindResource(getDataSource(), conHolder);
|
||||||
txObject.setConnectionHolder(conHolder);
|
txObject.setConnectionHolder(conHolder);
|
||||||
|
@ -601,13 +600,16 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
|
||||||
// Remove the JDBC connection holder from the thread, if exposed.
|
// Remove the JDBC connection holder from the thread, if exposed.
|
||||||
if (getDataSource() != null && txObject.hasConnectionHolder()) {
|
if (getDataSource() != null && txObject.hasConnectionHolder()) {
|
||||||
TransactionSynchronizationManager.unbindResource(getDataSource());
|
TransactionSynchronizationManager.unbindResource(getDataSource());
|
||||||
try {
|
ConnectionHandle conHandle = txObject.getConnectionHolder().getConnectionHandle();
|
||||||
getJpaDialect().releaseJdbcConnection(txObject.getConnectionHolder().getConnectionHandle(),
|
if (conHandle != null) {
|
||||||
txObject.getEntityManagerHolder().getEntityManager());
|
try {
|
||||||
}
|
getJpaDialect().releaseJdbcConnection(conHandle,
|
||||||
catch (Exception ex) {
|
txObject.getEntityManagerHolder().getEntityManager());
|
||||||
// Just log it, to keep a transaction-related exception.
|
}
|
||||||
logger.error("Could not close JDBC connection after transaction", ex);
|
catch (Exception ex) {
|
||||||
|
// Just log it, to keep a transaction-related exception.
|
||||||
|
logger.error("Could not close JDBC connection after transaction", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,6 +87,7 @@ public class TransactionInterceptor extends TransactionAspectSupport implements
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
public Object invoke(final MethodInvocation invocation) throws Throwable {
|
||||||
// Work out the target class: may be {@code null}.
|
// Work out the target class: may be {@code null}.
|
||||||
// The TransactionAttributeSource should be passed the target class
|
// The TransactionAttributeSource should be passed the target class
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.apache.http.protocol.HttpContext;
|
||||||
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +50,6 @@ import org.springframework.util.Assert;
|
||||||
public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory
|
public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory
|
||||||
implements AsyncClientHttpRequestFactory, InitializingBean {
|
implements AsyncClientHttpRequestFactory, InitializingBean {
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private HttpAsyncClient asyncClient;
|
private HttpAsyncClient asyncClient;
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +70,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
|
||||||
*/
|
*/
|
||||||
public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) {
|
public HttpComponentsAsyncClientHttpRequestFactory(HttpAsyncClient asyncClient) {
|
||||||
super();
|
super();
|
||||||
setAsyncClient(asyncClient);
|
this.asyncClient = asyncClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,7 +80,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
|
||||||
*/
|
*/
|
||||||
public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) {
|
public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpAsyncClient asyncClient) {
|
||||||
super();
|
super();
|
||||||
setAsyncClient(asyncClient);
|
this.asyncClient = asyncClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,7 +92,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
|
||||||
*/
|
*/
|
||||||
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) {
|
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, HttpAsyncClient asyncClient) {
|
||||||
super(httpClient);
|
super(httpClient);
|
||||||
setAsyncClient(asyncClient);
|
this.asyncClient = asyncClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,7 +105,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
|
||||||
CloseableHttpClient httpClient, CloseableHttpAsyncClient asyncClient) {
|
CloseableHttpClient httpClient, CloseableHttpAsyncClient asyncClient) {
|
||||||
|
|
||||||
super(httpClient);
|
super(httpClient);
|
||||||
setAsyncClient(asyncClient);
|
this.asyncClient = asyncClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +126,6 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
|
||||||
* @since 4.3.10
|
* @since 4.3.10
|
||||||
* @see #getHttpClient()
|
* @see #getHttpClient()
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
public HttpAsyncClient getAsyncClient() {
|
public HttpAsyncClient getAsyncClient() {
|
||||||
return this.asyncClient;
|
return this.asyncClient;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +147,7 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public CloseableHttpAsyncClient getHttpAsyncClient() {
|
public CloseableHttpAsyncClient getHttpAsyncClient() {
|
||||||
Assert.state(this.asyncClient == null || this.asyncClient instanceof CloseableHttpAsyncClient,
|
Assert.state(this.asyncClient instanceof CloseableHttpAsyncClient,
|
||||||
"No CloseableHttpAsyncClient - use getAsyncClient() instead");
|
"No CloseableHttpAsyncClient - use getAsyncClient() instead");
|
||||||
return (CloseableHttpAsyncClient) this.asyncClient;
|
return (CloseableHttpAsyncClient) this.asyncClient;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +160,6 @@ public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsC
|
||||||
|
|
||||||
private HttpAsyncClient startAsyncClient() {
|
private HttpAsyncClient startAsyncClient() {
|
||||||
HttpAsyncClient client = getAsyncClient();
|
HttpAsyncClient client = getAsyncClient();
|
||||||
Assert.state(client != null, "No HttpAsyncClient set");
|
|
||||||
if (client instanceof CloseableHttpAsyncClient) {
|
if (client instanceof CloseableHttpAsyncClient) {
|
||||||
CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) client;
|
CloseableHttpAsyncClient closeableAsyncClient = (CloseableHttpAsyncClient) client;
|
||||||
if (!closeableAsyncClient.isRunning()) {
|
if (!closeableAsyncClient.isRunning()) {
|
||||||
|
|
|
@ -59,7 +59,6 @@ import org.springframework.util.Assert;
|
||||||
*/
|
*/
|
||||||
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
|
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -82,7 +81,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
||||||
* @param httpClient the HttpClient instance to use for this request factory
|
* @param httpClient the HttpClient instance to use for this request factory
|
||||||
*/
|
*/
|
||||||
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) {
|
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) {
|
||||||
setHttpClient(httpClient);
|
this.httpClient = httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,7 +98,6 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
||||||
* Return the {@code HttpClient} used for
|
* Return the {@code HttpClient} used for
|
||||||
* {@linkplain #createRequest(URI, HttpMethod) synchronous execution}.
|
* {@linkplain #createRequest(URI, HttpMethod) synchronous execution}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
public HttpClient getHttpClient() {
|
public HttpClient getHttpClient() {
|
||||||
return this.httpClient;
|
return this.httpClient;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +154,6 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
||||||
@Override
|
@Override
|
||||||
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
|
||||||
HttpClient client = getHttpClient();
|
HttpClient client = getHttpClient();
|
||||||
Assert.state(client != null, "No HttpClient set");
|
|
||||||
|
|
||||||
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
|
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
|
||||||
postProcessHttpRequest(httpRequest);
|
postProcessHttpRequest(httpRequest);
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.springframework.util.MimeType;
|
||||||
*/
|
*/
|
||||||
public class Jackson2JsonEncoder extends AbstractJackson2Encoder {
|
public class Jackson2JsonEncoder extends AbstractJackson2Encoder {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private final PrettyPrinter ssePrettyPrinter;
|
private final PrettyPrinter ssePrettyPrinter;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -494,6 +494,7 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||||
if (AopUtils.isToStringMethod(invocation.getMethod())) {
|
if (AopUtils.isToStringMethod(invocation.getMethod())) {
|
||||||
return "JAX-WS proxy for port [" + getPortName() + "] of service [" + getServiceName() + "]";
|
return "JAX-WS proxy for port [" + getPortName() + "] of service [" + getServiceName() + "]";
|
||||||
|
|
|
@ -753,6 +753,7 @@ public class MvcUriComponentsBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable {
|
public Object invoke(org.aopalliance.intercept.MethodInvocation inv) throws Throwable {
|
||||||
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null);
|
return intercept(inv.getThis(), inv.getMethod(), inv.getArguments(), null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue