Framework build compatible with JDK 9 (even with -target 1.9)
Issue: SPR-13344
This commit is contained in:
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,28 +21,23 @@ import java.lang.reflect.Method;
|
||||
import java.rmi.RemoteException;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
import javax.rmi.PortableRemoteObject;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.omg.CORBA.OBJECT_NOT_EXIST;
|
||||
import org.omg.CORBA.SystemException;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jndi.JndiObjectLocator;
|
||||
import org.springframework.remoting.RemoteAccessException;
|
||||
import org.springframework.remoting.RemoteConnectFailureException;
|
||||
import org.springframework.remoting.RemoteInvocationFailureException;
|
||||
import org.springframework.remoting.RemoteLookupFailureException;
|
||||
import org.springframework.remoting.support.DefaultRemoteInvocationFactory;
|
||||
import org.springframework.remoting.support.RemoteInvocation;
|
||||
import org.springframework.remoting.support.RemoteInvocationFactory;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* {@link org.aopalliance.intercept.MethodInterceptor} for accessing RMI services from JNDI.
|
||||
* Typically used for RMI-IIOP (CORBA), but can also be used for EJB home objects
|
||||
* {@link org.aopalliance.intercept.MethodInterceptor} for accessing RMI services
|
||||
* from JNDI. Typically used for RMI-IIOP but can also be used for EJB home objects
|
||||
* (for example, a Stateful Session Bean home). In contrast to a plain JNDI lookup,
|
||||
* this accessor also performs narrowing through PortableRemoteObject.
|
||||
*
|
||||
@@ -74,7 +69,6 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @see org.springframework.remoting.RemoteAccessException
|
||||
* @see java.rmi.RemoteException
|
||||
* @see java.rmi.Remote
|
||||
* @see javax.rmi.PortableRemoteObject#narrow
|
||||
*/
|
||||
public class JndiRmiClientInterceptor extends JndiObjectLocator implements MethodInterceptor, InitializingBean {
|
||||
|
||||
@@ -227,17 +221,7 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho
|
||||
*/
|
||||
protected Object lookupStub() throws RemoteLookupFailureException {
|
||||
try {
|
||||
Object stub = lookup();
|
||||
if (getServiceInterface() != null && !(stub instanceof RmiInvocationHandler)) {
|
||||
try {
|
||||
stub = PortableRemoteObject.narrow(stub, getServiceInterface());
|
||||
}
|
||||
catch (ClassCastException ex) {
|
||||
throw new RemoteLookupFailureException(
|
||||
"Could not narrow RMI stub to service interface [" + getServiceInterface().getName() + "]", ex);
|
||||
}
|
||||
}
|
||||
return stub;
|
||||
return lookup();
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
throw new RemoteLookupFailureException("JNDI lookup for RMI service [" + getJndiName() + "] failed", ex);
|
||||
@@ -306,14 +290,6 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
catch (SystemException ex) {
|
||||
if (isConnectFailure(ex)) {
|
||||
return handleRemoteConnectFailure(invocation, ex);
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
getJndiTemplate().releaseContext(ctx);
|
||||
}
|
||||
@@ -330,17 +306,6 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho
|
||||
return RmiClientInterceptorUtils.isConnectFailure(ex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the given CORBA exception indicates a connect failure.
|
||||
* <p>The default implementation checks for CORBA's
|
||||
* {@link org.omg.CORBA.OBJECT_NOT_EXIST} exception.
|
||||
* @param ex the RMI exception to check
|
||||
* @return whether the exception should be treated as connect failure
|
||||
*/
|
||||
protected boolean isConnectFailure(SystemException ex) {
|
||||
return (ex instanceof OBJECT_NOT_EXIST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the stub and retry the remote invocation if necessary.
|
||||
* <p>If not configured to refresh on connect failure, this method
|
||||
@@ -402,9 +367,6 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho
|
||||
catch (RemoteException ex) {
|
||||
throw convertRmiAccessException(ex, invocation.getMethod());
|
||||
}
|
||||
catch (SystemException ex) {
|
||||
throw convertCorbaAccessException(ex, invocation.getMethod());
|
||||
}
|
||||
catch (InvocationTargetException ex) {
|
||||
throw ex.getTargetException();
|
||||
}
|
||||
@@ -423,9 +385,6 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho
|
||||
if (targetEx instanceof RemoteException) {
|
||||
throw convertRmiAccessException((RemoteException) targetEx, invocation.getMethod());
|
||||
}
|
||||
else if (targetEx instanceof SystemException) {
|
||||
throw convertCorbaAccessException((SystemException) targetEx, invocation.getMethod());
|
||||
}
|
||||
else {
|
||||
throw targetEx;
|
||||
}
|
||||
@@ -483,27 +442,4 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho
|
||||
return RmiClientInterceptorUtils.convertRmiAccessException(method, ex, isConnectFailure(ex), getJndiName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given CORBA SystemException that happened during remote access
|
||||
* to Spring's RemoteAccessException if the method signature does not declare
|
||||
* RemoteException. Else, return the SystemException wrapped in a RemoteException.
|
||||
* @param method the invoked method
|
||||
* @param ex the RemoteException that happened
|
||||
* @return the exception to be thrown to the caller
|
||||
*/
|
||||
private Exception convertCorbaAccessException(SystemException ex, Method method) {
|
||||
if (ReflectionUtils.declaresException(method, RemoteException.class)) {
|
||||
// A traditional RMI service: wrap CORBA exceptions in standard RemoteExceptions.
|
||||
return new RemoteException("Failed to access CORBA service [" + getJndiName() + "]", ex);
|
||||
}
|
||||
else {
|
||||
if (isConnectFailure(ex)) {
|
||||
return new RemoteConnectFailureException("Could not connect to CORBA service [" + getJndiName() + "]", ex);
|
||||
}
|
||||
else {
|
||||
return new RemoteAccessException("Could not access CORBA service [" + getJndiName() + "]", 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,6 @@ import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Properties;
|
||||
import javax.naming.NamingException;
|
||||
import javax.rmi.PortableRemoteObject;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -117,7 +116,6 @@ public class JndiRmiServiceExporter extends RmiBasedExporter implements Initiali
|
||||
|
||||
// Initialize and cache exported object.
|
||||
this.exportedObject = getObjectToExport();
|
||||
PortableRemoteObject.exportObject(this.exportedObject);
|
||||
|
||||
rebind();
|
||||
}
|
||||
@@ -143,7 +141,6 @@ public class JndiRmiServiceExporter extends RmiBasedExporter implements Initiali
|
||||
logger.info("Unbinding RMI service from JNDI location [" + this.jndiName + "]");
|
||||
}
|
||||
this.jndiTemplate.unbind(this.jndiName);
|
||||
PortableRemoteObject.unexportObject(this.exportedObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user