/** * Convert the given RMI RemoteException that happened during remote access * to Spring's RemoteAccessException if the method signature does not declare * RemoteException. Else, return the original RemoteException. * @param method the invoked method * @param ex the RemoteException that happened * @return the exception to be thrown to the caller */ private Exception convertRmiAccessException(RemoteException ex, Method method) { return RmiClientInterceptorUtils.convertRmiAccessException(method, ex, isConnectFailure(ex), getJndiName()); }
/** * Create an ObjectInputStream for the given InputStream. * <p>The default implementation creates a Spring {@link CodebaseAwareObjectInputStream}. * @param is the InputStream to read from * @return the new ObjectInputStream instance to use * @throws java.io.IOException if creation of the ObjectInputStream failed */ protected ObjectInputStream createObjectInputStream(InputStream is) throws IOException { return new CodebaseAwareObjectInputStream(is, getBeanClassLoader(), isAcceptProxyClasses()); }
/** * Convert the given RemoteException that happened during remote access * to Spring's RemoteAccessException if the method signature does not * support RemoteException. Else, return the original RemoteException. * @param method the invoked method * @param ex the RemoteException that happened * @param serviceName the name of the service (for debugging purposes) * @return the exception to be thrown to the caller */ public static Exception convertRmiAccessException(Method method, RemoteException ex, String serviceName) { return convertRmiAccessException(method, ex, isConnectFailure(ex), serviceName); }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Class<?> ifc = getServiceInterface(); Assert.notNull(ifc, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(ifc, this).getProxy(getBeanClassLoader()); }
@Test public void rmiProxyFactoryBean() throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IRemoteBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.afterPropertiesSet(); assertTrue("Correct singleton value", factory.isSingleton()); assertTrue(factory.getObject() instanceof IRemoteBean); IRemoteBean proxy = (IRemoteBean) factory.getObject(); proxy.setName("myName"); assertEquals("myName", RemoteBean.name); assertEquals(1, factory.counter); }
@Override public void afterPropertiesSet() throws NamingException { super.afterPropertiesSet(); Class<?> ifc = getServiceInterface(); Assert.notNull(ifc, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(ifc, this).getProxy(this.beanClassLoader); }
@Override public void afterPropertiesSet() throws RemoteException { prepare(); }
@Test public void rmiProxyFactoryBeanWithBusinessInterface() throws Exception { CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean(); factory.setServiceInterface(IBusinessBean.class); factory.setServiceUrl("rmi://localhost:1090/test"); factory.afterPropertiesSet(); assertTrue(factory.getObject() instanceof IBusinessBean); IBusinessBean proxy = (IBusinessBean) factory.getObject(); assertFalse(proxy instanceof IRemoteBean); proxy.setName("myName"); assertEquals("myName", RemoteBean.name); assertEquals(1, factory.counter); }
@Override public Class<?> getObjectType() { return getServiceInterface(); }
/** * Determine whether the given RMI exception indicates a connect failure. * <p>The default implementation delegates to * {@link RmiClientInterceptorUtils#isConnectFailure}. * @param ex the RMI exception to check * @return whether the exception should be treated as connect failure */ protected boolean isConnectFailure(RemoteException ex) { return RmiClientInterceptorUtils.isConnectFailure(ex); }
/** * Initialize this service exporter. */ public void prepare() { this.proxy = getProxyForService(); }
@Override public void afterPropertiesSet() throws NamingException, RemoteException { prepare(); }
@Override public void afterPropertiesSet() { prepare(); }
@Override public Class<?> getObjectType() { return getServiceInterface(); }
@Override public void afterPropertiesSet() throws NamingException { super.afterPropertiesSet(); prepare(); }
@Override protected Remote lookupStub() { counter++; return new RemoteBean(); } }
@Test public void rmiProxyFactoryBeanWithBusinessInterfaceAndRemoteException() throws Exception { doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException( RemoteException.class, RemoteAccessException.class); }
@Test public void rmiProxyFactoryBeanWithBusinessInterfaceAndRemoteExceptionAndRefresh() throws Exception { doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh( RemoteException.class, RemoteAccessException.class); }
/** * Determine whether the given RMI exception indicates a connect failure. * <p>The default implementation delegates to RmiClientInterceptorUtils. * @param ex the RMI exception to check * @return whether the exception should be treated as connect failure * @see org.springframework.remoting.rmi.RmiClientInterceptorUtils#isConnectFailure */ protected boolean isConnectFailure(RemoteException ex) { return RmiClientInterceptorUtils.isConnectFailure(ex); }
/** * Determine whether the given RMI exception indicates a connect failure. * <p>The default implementation delegates to * {@link RmiClientInterceptorUtils#isConnectFailure}. * @param ex the RMI exception to check * @return whether the exception should be treated as connect failure */ protected boolean isConnectFailure(RemoteException ex) { return RmiClientInterceptorUtils.isConnectFailure(ex); }