RemoteInvocation(Result) explicitly designed for JavaBean-style deserialization
Issue: SPR-11337
This commit is contained in:
parent
eac4881809
commit
84310c8a11
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
|
|
@ -33,6 +33,9 @@ import org.springframework.util.ClassUtils;
|
|||
* <p>This is an SPI class, typically not used directly by applications.
|
||||
* Can be subclassed for additional invocation parameters.
|
||||
*
|
||||
* <p>Both {@link RemoteInvocation} and {@link RemoteInvocationResult} are designed
|
||||
* for use with standard Java serialization as well as JavaBean-style serialization.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 25.02.2004
|
||||
* @see RemoteInvocationResult
|
||||
|
|
@ -59,9 +62,13 @@ public class RemoteInvocation implements Serializable {
|
|||
|
||||
|
||||
/**
|
||||
* Create a new RemoteInvocation for use as JavaBean.
|
||||
* Create a new RemoteInvocation for the given AOP method invocation.
|
||||
* @param methodInvocation the AOP invocation to convert
|
||||
*/
|
||||
public RemoteInvocation() {
|
||||
public RemoteInvocation(MethodInvocation methodInvocation) {
|
||||
this.methodName = methodInvocation.getMethod().getName();
|
||||
this.parameterTypes = methodInvocation.getMethod().getParameterTypes();
|
||||
this.arguments = methodInvocation.getArguments();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,18 +84,16 @@ public class RemoteInvocation implements Serializable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a new RemoteInvocation for the given AOP method invocation.
|
||||
* @param methodInvocation the AOP invocation to convert
|
||||
* Create a new RemoteInvocation for JavaBean-style deserialization
|
||||
* (e.g. with Jackson).
|
||||
*/
|
||||
public RemoteInvocation(MethodInvocation methodInvocation) {
|
||||
this.methodName = methodInvocation.getMethod().getName();
|
||||
this.parameterTypes = methodInvocation.getMethod().getParameterTypes();
|
||||
this.arguments = methodInvocation.getArguments();
|
||||
public RemoteInvocation() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of the target method.
|
||||
* <p>This setter is intended for JavaBean-style deserialization.
|
||||
*/
|
||||
public void setMethodName(String methodName) {
|
||||
this.methodName = methodName;
|
||||
|
|
@ -103,6 +108,7 @@ public class RemoteInvocation implements Serializable {
|
|||
|
||||
/**
|
||||
* Set the parameter types of the target method.
|
||||
* <p>This setter is intended for JavaBean-style deserialization.
|
||||
*/
|
||||
public void setParameterTypes(Class<?>[] parameterTypes) {
|
||||
this.parameterTypes = parameterTypes;
|
||||
|
|
@ -117,6 +123,7 @@ public class RemoteInvocation implements Serializable {
|
|||
|
||||
/**
|
||||
* Set the arguments for the target method call.
|
||||
* <p>This setter is intended for JavaBean-style deserialization.
|
||||
*/
|
||||
public void setArguments(Object[] arguments) {
|
||||
this.arguments = arguments;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
|
|
@ -26,6 +26,9 @@ import java.lang.reflect.InvocationTargetException;
|
|||
* <p>This is an SPI class, typically not used directly by applications.
|
||||
* Can be subclassed for additional invocation parameters.
|
||||
*
|
||||
* <p>Both {@link RemoteInvocation} and {@link RemoteInvocationResult} are designed
|
||||
* for use with standard Java serialization as well as JavaBean-style serialization.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.1
|
||||
* @see RemoteInvocation
|
||||
|
|
@ -59,6 +62,26 @@ public class RemoteInvocationResult implements Serializable {
|
|||
this.exception = exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new RemoteInvocationResult for JavaBean-style deserialization
|
||||
* (e.g. with Jackson).
|
||||
* @see #setValue
|
||||
* @see #setException
|
||||
*/
|
||||
public RemoteInvocationResult() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the result value returned by a successful invocation of the
|
||||
* target method, if any.
|
||||
* <p>This setter is intended for JavaBean-style deserialization.
|
||||
* Use {@link #RemoteInvocationResult(Object)} otherwise.
|
||||
* @see #RemoteInvocationResult()
|
||||
*/
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the result value returned by a successful invocation
|
||||
|
|
@ -69,6 +92,17 @@ public class RemoteInvocationResult implements Serializable {
|
|||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the exception thrown by an unsuccessful invocation of the
|
||||
* target method, if any.
|
||||
* <p>This setter is intended for JavaBean-style deserialization.
|
||||
* Use {@link #RemoteInvocationResult(Throwable)} otherwise.
|
||||
* @see #RemoteInvocationResult()
|
||||
*/
|
||||
public void setException(Throwable exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the exception thrown by an unsuccessful invocation
|
||||
* of the target method, if any.
|
||||
|
|
@ -81,7 +115,7 @@ public class RemoteInvocationResult implements Serializable {
|
|||
/**
|
||||
* Return whether this invocation result holds an exception.
|
||||
* If this returns {@code false}, the result value applies
|
||||
* (even if {@code null}).
|
||||
* (even if it is {@code null}).
|
||||
* @see #getValue
|
||||
* @see #getException
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
|
|
@ -180,8 +180,8 @@ public class RmiSupportTests extends TestCase {
|
|||
}
|
||||
catch (RemoteProxyFailureException ex) {
|
||||
assertTrue(ex.getCause() instanceof NoSuchMethodException);
|
||||
assertTrue(ex.getMessage().indexOf("setOtherName") != -1);
|
||||
assertTrue(ex.getMessage().indexOf("IWrongBusinessBean") != -1);
|
||||
assertTrue(ex.getMessage().contains("setOtherName"));
|
||||
assertTrue(ex.getMessage().contains("IWrongBusinessBean"));
|
||||
}
|
||||
assertEquals(1, factory.counter);
|
||||
}
|
||||
|
|
@ -319,7 +319,7 @@ public class RmiSupportTests extends TestCase {
|
|||
// let's see if the remote invocation object works
|
||||
|
||||
final RemoteBean rb = new RemoteBean();
|
||||
final Method setNameMethod = rb.getClass().getDeclaredMethod("setName", new Class<?>[] {String.class});
|
||||
final Method setNameMethod = rb.getClass().getDeclaredMethod("setName", String.class);
|
||||
|
||||
MethodInvocation mi = new MethodInvocation() {
|
||||
@Override
|
||||
|
|
@ -388,8 +388,8 @@ public class RmiSupportTests extends TestCase {
|
|||
IBusinessBean proxy = (IBusinessBean) factory.getObject();
|
||||
|
||||
// shouldn't go through to remote service
|
||||
assertTrue(proxy.toString().indexOf("RMI invoker") != -1);
|
||||
assertTrue(proxy.toString().indexOf(serviceUrl) != -1);
|
||||
assertTrue(proxy.toString().contains("RMI invoker"));
|
||||
assertTrue(proxy.toString().contains(serviceUrl));
|
||||
assertEquals(proxy.hashCode(), proxy.hashCode());
|
||||
assertTrue(proxy.equals(proxy));
|
||||
|
||||
|
|
@ -444,11 +444,11 @@ public class RmiSupportTests extends TestCase {
|
|||
@Override
|
||||
public void setName(String nam) throws RemoteException {
|
||||
if (nam != null && nam.endsWith("Exception")) {
|
||||
RemoteException rex = null;
|
||||
RemoteException rex;
|
||||
try {
|
||||
Class<?> exClass = Class.forName(nam);
|
||||
Constructor<?> ctor = exClass.getConstructor(new Class<?>[] {String.class});
|
||||
rex = (RemoteException) ctor.newInstance(new Object[] {"myMessage"});
|
||||
Constructor<?> ctor = exClass.getConstructor(String.class);
|
||||
rex = (RemoteException) ctor.newInstance("myMessage");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RemoteException("Illegal exception class name: " + nam, ex);
|
||||
|
|
|
|||
Loading…
Reference in New Issue