Fine-tune HTTP/RMI Invoker exception handling
Issue: SPR-15684
(cherry picked from commit 535103c)
This commit is contained in:
parent
a17255a2e3
commit
016b7d753c
|
|
@ -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.
|
||||||
|
|
@ -107,7 +107,9 @@ public abstract class RemoteInvocationSerializingExporter extends RemoteInvocati
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Object getProxy() {
|
protected final Object getProxy() {
|
||||||
Assert.notNull(this.proxy, ClassUtils.getShortName(getClass()) + " has not been initialized");
|
if (this.proxy == null) {
|
||||||
|
throw new IllegalStateException(ClassUtils.getShortName(getClass()) + " has not been initialized");
|
||||||
|
}
|
||||||
return this.proxy;
|
return this.proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,7 +144,7 @@ public abstract class RemoteInvocationSerializingExporter extends RemoteInvocati
|
||||||
Object obj = ois.readObject();
|
Object obj = ois.readObject();
|
||||||
if (!(obj instanceof RemoteInvocation)) {
|
if (!(obj instanceof RemoteInvocation)) {
|
||||||
throw new RemoteException("Deserialized object needs to be assignable to type [" +
|
throw new RemoteException("Deserialized object needs to be assignable to type [" +
|
||||||
RemoteInvocation.class.getName() + "]: " + obj);
|
RemoteInvocation.class.getName() + "]: " + ClassUtils.getDescriptiveType(obj));
|
||||||
}
|
}
|
||||||
return (RemoteInvocation) obj;
|
return (RemoteInvocation) obj;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -89,7 +89,7 @@ public abstract class RemoteExporter extends RemotingSupport {
|
||||||
* @see RemoteInvocationTraceInterceptor
|
* @see RemoteInvocationTraceInterceptor
|
||||||
*/
|
*/
|
||||||
public void setRegisterTraceInterceptor(boolean registerTraceInterceptor) {
|
public void setRegisterTraceInterceptor(boolean registerTraceInterceptor) {
|
||||||
this.registerTraceInterceptor = Boolean.valueOf(registerTraceInterceptor);
|
this.registerTraceInterceptor = registerTraceInterceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -153,20 +153,23 @@ public abstract class RemoteExporter extends RemotingSupport {
|
||||||
protected Object getProxyForService() {
|
protected Object getProxyForService() {
|
||||||
checkService();
|
checkService();
|
||||||
checkServiceInterface();
|
checkServiceInterface();
|
||||||
|
|
||||||
ProxyFactory proxyFactory = new ProxyFactory();
|
ProxyFactory proxyFactory = new ProxyFactory();
|
||||||
proxyFactory.addInterface(getServiceInterface());
|
proxyFactory.addInterface(getServiceInterface());
|
||||||
if (this.registerTraceInterceptor != null ?
|
|
||||||
this.registerTraceInterceptor.booleanValue() : this.interceptors == null) {
|
if (this.registerTraceInterceptor != null ? this.registerTraceInterceptor : this.interceptors == null) {
|
||||||
proxyFactory.addAdvice(new RemoteInvocationTraceInterceptor(getExporterName()));
|
proxyFactory.addAdvice(new RemoteInvocationTraceInterceptor(getExporterName()));
|
||||||
}
|
}
|
||||||
if (this.interceptors != null) {
|
if (this.interceptors != null) {
|
||||||
AdvisorAdapterRegistry adapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
|
AdvisorAdapterRegistry adapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
|
||||||
for (int i = 0; i < this.interceptors.length; i++) {
|
for (Object interceptor : this.interceptors) {
|
||||||
proxyFactory.addAdvisor(adapterRegistry.wrap(this.interceptors[i]));
|
proxyFactory.addAdvisor(adapterRegistry.wrap(interceptor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyFactory.setTarget(getService());
|
proxyFactory.setTarget(getService());
|
||||||
proxyFactory.setOpaque(true);
|
proxyFactory.setOpaque(true);
|
||||||
|
|
||||||
return proxyFactory.getProxy(getBeanClassLoader());
|
return proxyFactory.getProxy(getBeanClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import org.springframework.remoting.rmi.CodebaseAwareObjectInputStream;
|
||||||
import org.springframework.remoting.support.RemoteInvocation;
|
import org.springframework.remoting.support.RemoteInvocation;
|
||||||
import org.springframework.remoting.support.RemoteInvocationResult;
|
import org.springframework.remoting.support.RemoteInvocationResult;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base implementation of the HttpInvokerRequestExecutor interface.
|
* Abstract base implementation of the HttpInvokerRequestExecutor interface.
|
||||||
|
|
@ -290,7 +291,7 @@ public abstract class AbstractHttpInvokerRequestExecutor implements HttpInvokerR
|
||||||
Object obj = ois.readObject();
|
Object obj = ois.readObject();
|
||||||
if (!(obj instanceof RemoteInvocationResult)) {
|
if (!(obj instanceof RemoteInvocationResult)) {
|
||||||
throw new RemoteException("Deserialized object needs to be assignable to type [" +
|
throw new RemoteException("Deserialized object needs to be assignable to type [" +
|
||||||
RemoteInvocationResult.class.getName() + "]: " + obj);
|
RemoteInvocationResult.class.getName() + "]: " + ClassUtils.getDescriptiveType(obj));
|
||||||
}
|
}
|
||||||
return (RemoteInvocationResult) obj;
|
return (RemoteInvocationResult) obj;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -263,10 +263,12 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
|
||||||
*/
|
*/
|
||||||
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
|
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
|
||||||
HttpPost httpPost = new HttpPost(config.getServiceUrl());
|
HttpPost httpPost = new HttpPost(config.getServiceUrl());
|
||||||
|
|
||||||
RequestConfig requestConfig = createRequestConfig(config);
|
RequestConfig requestConfig = createRequestConfig(config);
|
||||||
if (requestConfig != null) {
|
if (requestConfig != null) {
|
||||||
httpPost.setConfig(requestConfig);
|
httpPost.setConfig(requestConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
|
LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
|
||||||
if (localeContext != null) {
|
if (localeContext != null) {
|
||||||
Locale locale = localeContext.getLocale();
|
Locale locale = localeContext.getLocale();
|
||||||
|
|
@ -274,9 +276,11 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
|
||||||
httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale));
|
httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAcceptGzipEncoding()) {
|
if (isAcceptGzipEncoding()) {
|
||||||
httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
|
httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
return httpPost;
|
return httpPost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -303,6 +307,7 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
|
||||||
if (this.requestConfig == null) { // nothing to merge
|
if (this.requestConfig == null) { // nothing to merge
|
||||||
return defaultRequestConfig;
|
return defaultRequestConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestConfig.Builder builder = RequestConfig.copy(defaultRequestConfig);
|
RequestConfig.Builder builder = RequestConfig.copy(defaultRequestConfig);
|
||||||
int connectTimeout = this.requestConfig.getConnectTimeout();
|
int connectTimeout = this.requestConfig.getConnectTimeout();
|
||||||
if (connectTimeout >= 0) {
|
if (connectTimeout >= 0) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 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.
|
||||||
|
|
@ -107,7 +107,8 @@ public class SimpleHttpInvokerRequestExecutor extends AbstractHttpInvokerRequest
|
||||||
protected HttpURLConnection openConnection(HttpInvokerClientConfiguration config) throws IOException {
|
protected HttpURLConnection openConnection(HttpInvokerClientConfiguration config) throws IOException {
|
||||||
URLConnection con = new URL(config.getServiceUrl()).openConnection();
|
URLConnection con = new URL(config.getServiceUrl()).openConnection();
|
||||||
if (!(con instanceof HttpURLConnection)) {
|
if (!(con instanceof HttpURLConnection)) {
|
||||||
throw new IOException("Service URL [" + config.getServiceUrl() + "] is not an HTTP URL");
|
throw new IOException(
|
||||||
|
"Service URL [" + config.getServiceUrl() + "] does not resolve to an HTTP connection");
|
||||||
}
|
}
|
||||||
return (HttpURLConnection) con;
|
return (HttpURLConnection) con;
|
||||||
}
|
}
|
||||||
|
|
@ -130,6 +131,7 @@ public class SimpleHttpInvokerRequestExecutor extends AbstractHttpInvokerRequest
|
||||||
if (this.readTimeout >= 0) {
|
if (this.readTimeout >= 0) {
|
||||||
connection.setReadTimeout(this.readTimeout);
|
connection.setReadTimeout(this.readTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setRequestMethod(HTTP_METHOD_POST);
|
connection.setRequestMethod(HTTP_METHOD_POST);
|
||||||
connection.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType());
|
connection.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType());
|
||||||
|
|
@ -142,6 +144,7 @@ public class SimpleHttpInvokerRequestExecutor extends AbstractHttpInvokerRequest
|
||||||
connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale));
|
connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAcceptGzipEncoding()) {
|
if (isAcceptGzipEncoding()) {
|
||||||
connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
|
connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue