/** * Determine whether the given RMI exception indicates a connect failure. * <p>Treats RMI's ConnectException, ConnectIOException, UnknownHostException, * NoSuchObjectException and StubNotFoundException as connect failure. * @param ex the RMI exception to check * @return whether the exception should be treated as connect failure * @see java.rmi.ConnectException * @see java.rmi.ConnectIOException * @see java.rmi.UnknownHostException * @see java.rmi.NoSuchObjectException * @see java.rmi.StubNotFoundException */ public static boolean isConnectFailure(RemoteException ex) { return (ex instanceof ConnectException || ex instanceof ConnectIOException || ex instanceof UnknownHostException || ex instanceof NoSuchObjectException || ex instanceof StubNotFoundException || ex.getCause() instanceof SocketException); }
public void unbind(String paramString) throws AccessException { throw new AccessException("Cannot modify this registry"); } }
Message message = Message.obtain(null, MyService.ADD_RESPONSE_HANDLER); message.replyTo = messenger; try { myService.send(message); catch (RemoteException e) { e.printStackTrace(); }
/** * Perform the actual reading of an invocation result object from the * given ObjectInputStream. * <p>The default implementation simply calls * {@link java.io.ObjectInputStream#readObject()}. * Can be overridden for deserialization of a custom wrapper object rather * than the plain invocation, for example an encryption-aware holder. * @param ois the ObjectInputStream to read from * @return the RemoteInvocationResult object * @throws java.io.IOException in case of I/O failure * @throws ClassNotFoundException if case of a transferred class not * being found in the local ClassLoader */ protected RemoteInvocation doReadRemoteInvocation(ObjectInputStream ois) throws IOException, ClassNotFoundException { Object obj = ois.readObject(); if (!(obj instanceof RemoteInvocation)) { throw new RemoteException("Deserialized object needs to be assignable to type [" + RemoteInvocation.class.getName() + "]: " + ClassUtils.getDescriptiveType(obj)); } return (RemoteInvocation) obj; }
@Override protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException { final RmiServiceExporter rmiServiceExporter = new RmiServiceExporter(); rmiServiceExporter.setRegistryPort(url.getPort()); rmiServiceExporter.setServiceName(url.getPath()); rmiServiceExporter.setServiceInterface(type); rmiServiceExporter.setService(impl); try { rmiServiceExporter.afterPropertiesSet(); } catch (RemoteException e) { throw new RpcException(e.getMessage(), e); } return new Runnable() { @Override public void run() { try { rmiServiceExporter.destroy(); } catch (Throwable e) { logger.warn(e.getMessage(), e); } } }; }
public Remote lookup(String paramString) throws NotBoundException { if (paramString.equals(this.name)) return this.object; throw new NotBoundException("Not bound: \"" + paramString + "\" (only " + "bound name is \"" + this.name + "\")"); }
/** * Perform the actual reading of an invocation object from the * given ObjectInputStream. * <p>The default implementation simply calls {@code readObject}. * Can be overridden for deserialization of a custom wrapper object rather * than the plain invocation, for example an encryption-aware holder. * @param ois the ObjectInputStream to read from * @return the RemoteInvocationResult object * @throws IOException if thrown by I/O methods * @throws ClassNotFoundException if the class name of a serialized object * couldn't get resolved * @see java.io.ObjectOutputStream#writeObject */ protected RemoteInvocationResult doReadRemoteInvocationResult(ObjectInputStream ois) throws IOException, ClassNotFoundException { Object obj = ois.readObject(); if (!(obj instanceof RemoteInvocationResult)) { throw new RemoteException("Deserialized object needs to be assignable to type [" + RemoteInvocationResult.class.getName() + "]: " + ClassUtils.getDescriptiveType(obj)); } return (RemoteInvocationResult) obj; }
@Override protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException { final RmiServiceExporter rmiServiceExporter = new RmiServiceExporter(); rmiServiceExporter.setRegistryPort(url.getPort()); rmiServiceExporter.setServiceName(url.getPath()); rmiServiceExporter.setServiceInterface(type); rmiServiceExporter.setService(impl); try { rmiServiceExporter.afterPropertiesSet(); } catch (RemoteException e) { throw new RpcException(e.getMessage(), e); } return new Runnable() { @Override public void run() { try { rmiServiceExporter.destroy(); } catch (Throwable e) { logger.warn(e.getMessage(), e); } } }; }
public void sendMessage(ProgressBarState state) { Message message = Message.obtain(); switch (state) { case SHOW : message.arg1 = Home.SHOW; break; case HIDE : message.arg1 = Home.HIDE; break; } try { messageHandler.send(message); } catch (RemoteException e) { e.printStackTrace(); } }
public void rebind(String paramString, Remote paramRemote) throws AccessException { throw new AccessException("Cannot modify this registry"); }
/** * Determine whether the given RMI exception indicates a connect failure. * <p>Treats RMI's ConnectException, ConnectIOException, UnknownHostException, * NoSuchObjectException and StubNotFoundException as connect failure. * @param ex the RMI exception to check * @return whether the exception should be treated as connect failure * @see java.rmi.ConnectException * @see java.rmi.ConnectIOException * @see java.rmi.UnknownHostException * @see java.rmi.NoSuchObjectException * @see java.rmi.StubNotFoundException */ public static boolean isConnectFailure(RemoteException ex) { return (ex instanceof ConnectException || ex instanceof ConnectIOException || ex instanceof UnknownHostException || ex instanceof NoSuchObjectException || ex instanceof StubNotFoundException || ex.getCause() instanceof SocketException); }
/** * Wrap the given arbitrary exception that happened during remote access * in either a RemoteException or a Spring RemoteAccessException (if the * method signature does not support RemoteException). * <p>Only call this for remote access exceptions, not for exceptions * thrown by the target service itself! * @param method the invoked method * @param ex the exception that happened, to be used as cause for the * RemoteAccessException or RemoteException * @param message the message for the RemoteAccessException respectively * RemoteException * @return the exception to be thrown to the caller */ public static Exception convertRmiAccessException(Method method, Throwable ex, String message) { if (logger.isDebugEnabled()) { logger.debug(message, ex); } if (ReflectionUtils.declaresException(method, RemoteException.class)) { return new RemoteException(message, ex); } else { return new RemoteAccessException(message, ex); } }
@Override public void info(String text) { try { callback.infoReported(text); } catch (RemoteException e) { e.printStackTrace(); } }
public void bind(String paramString, Remote paramRemote) throws AccessException { throw new AccessException("Cannot modify this registry"); }
@Override public void setName(String nam) throws RemoteException { if (nam != null && nam.endsWith("Exception")) { RemoteException rex; try { Class<?> exClass = Class.forName(nam); Constructor<?> ctor = exClass.getConstructor(String.class); rex = (RemoteException) ctor.newInstance("myMessage"); } catch (Exception ex) { throw new RemoteException("Illegal exception class name: " + nam, ex); } throw rex; } name = nam; } }
@Override public void warning(String text) { try { callback.warningReported(text); } catch (RemoteException e) { e.printStackTrace(); } }
import java.rmi.RemoteException; class Thrower { public static void spit(final Throwable exception) { class EvilThrower<T extends Throwable> { @SuppressWarnings("unchecked") private void sneakyThrow(Throwable exception) throws T { throw (T) exception; } } new EvilThrower<RuntimeException>().sneakyThrow(exception); } } public class ThrowerSample { public static void main( String[] args ) { Thrower.spit(new RemoteException("go unchecked!")); } }
@Override public void error(String text) { try { callback.errorReported(text); } catch (RemoteException e) { e.printStackTrace(); } }
@Test public void testRemoteException() throws Exception { doTestException(new RemoteException()); }
private void doTestRuleForSelectiveRollbackOnChecked(RuleBasedTransactionAttribute rta) { assertTrue(rta.rollbackOn(new RuntimeException())); // Check default behaviour is overridden assertFalse(rta.rollbackOn(new Exception())); // Check that default behaviour is overridden assertTrue(rta.rollbackOn(new RemoteException())); }