Fine-tune HTTP/RMI Invoker exception handling
Issue: SPR-15684
This commit is contained in:
@@ -33,6 +33,7 @@ import org.springframework.remoting.rmi.CodebaseAwareObjectInputStream;
|
||||
import org.springframework.remoting.support.RemoteInvocation;
|
||||
import org.springframework.remoting.support.RemoteInvocationResult;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Abstract base implementation of the HttpInvokerRequestExecutor interface.
|
||||
@@ -291,7 +292,7 @@ public abstract class AbstractHttpInvokerRequestExecutor implements HttpInvokerR
|
||||
Object obj = ois.readObject();
|
||||
if (!(obj instanceof RemoteInvocationResult)) {
|
||||
throw new RemoteException("Deserialized object needs to be assignable to type [" +
|
||||
RemoteInvocationResult.class.getName() + "]: " + obj);
|
||||
RemoteInvocationResult.class.getName() + "]: " + ClassUtils.getDescriptiveType(obj));
|
||||
}
|
||||
return (RemoteInvocationResult) obj;
|
||||
}
|
||||
|
||||
@@ -212,10 +212,12 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
|
||||
*/
|
||||
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
|
||||
HttpPost httpPost = new HttpPost(config.getServiceUrl());
|
||||
|
||||
RequestConfig requestConfig = createRequestConfig(config);
|
||||
if (requestConfig != null) {
|
||||
httpPost.setConfig(requestConfig);
|
||||
}
|
||||
|
||||
LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
|
||||
if (localeContext != null) {
|
||||
Locale locale = localeContext.getLocale();
|
||||
@@ -223,9 +225,11 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
|
||||
httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale));
|
||||
}
|
||||
}
|
||||
|
||||
if (isAcceptGzipEncoding()) {
|
||||
httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
|
||||
}
|
||||
|
||||
return httpPost;
|
||||
}
|
||||
|
||||
@@ -250,9 +254,10 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
|
||||
}
|
||||
|
||||
private RequestConfig mergeRequestConfig(RequestConfig defaultRequestConfig) {
|
||||
if (this.requestConfig == null) { // nothing to merge
|
||||
if (this.requestConfig == null) { // nothing to merge
|
||||
return defaultRequestConfig;
|
||||
}
|
||||
|
||||
RequestConfig.Builder builder = RequestConfig.copy(defaultRequestConfig);
|
||||
int connectTimeout = this.requestConfig.getConnectTimeout();
|
||||
if (connectTimeout >= 0) {
|
||||
|
||||
@@ -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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.remoting.httpinvoker;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link FactoryBean} for HTTP invoker proxies. Exposes the proxied service
|
||||
@@ -60,10 +61,9 @@ public class HttpInvokerProxyFactoryBean extends HttpInvokerClientInterceptor im
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
if (getServiceInterface() == null) {
|
||||
throw new IllegalArgumentException("Property 'serviceInterface' is required");
|
||||
}
|
||||
this.serviceProxy = new ProxyFactory(getServiceInterface(), this).getProxy(getBeanClassLoader());
|
||||
Class<?> ifc = getServiceInterface();
|
||||
Assert.notNull(ifc, "Property 'serviceInterface' is required");
|
||||
this.serviceProxy = new ProxyFactory(ifc, this).getProxy(getBeanClassLoader());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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");
|
||||
* 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 {
|
||||
URLConnection con = new URL(config.getServiceUrl()).openConnection();
|
||||
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;
|
||||
}
|
||||
@@ -130,6 +131,7 @@ public class SimpleHttpInvokerRequestExecutor extends AbstractHttpInvokerRequest
|
||||
if (this.readTimeout >= 0) {
|
||||
connection.setReadTimeout(this.readTimeout);
|
||||
}
|
||||
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestMethod(HTTP_METHOD_POST);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
if (isAcceptGzipEncoding()) {
|
||||
connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
|
||||
}
|
||||
|
||||
@@ -278,16 +278,14 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory
|
||||
* Set the interface of the service that this factory should create a proxy for.
|
||||
*/
|
||||
public void setServiceInterface(Class<?> serviceInterface) {
|
||||
if (!serviceInterface.isInterface()) {
|
||||
throw new IllegalArgumentException("'serviceInterface' must be an interface");
|
||||
}
|
||||
Assert.notNull(serviceInterface, "'serviceInterface' must not be null");
|
||||
Assert.isTrue(serviceInterface.isInterface(), "'serviceInterface' must be an interface");
|
||||
this.serviceInterface = serviceInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the interface of the service that this factory should create a proxy for.
|
||||
*/
|
||||
@Nullable
|
||||
public Class<?> getServiceInterface() {
|
||||
return this.serviceInterface;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user