/** * 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; }
private void handleError(Exception e) throws RemoteException { LOG.error("Error occured while consuming Crowd REST service", e); throw new RemoteException(e.getMessage()); }
/** * 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; }
private void handleHTTPError(CloseableHttpResponse response) throws RemoteException { final StatusLine statusLine = response.getStatusLine(); final int status = statusLine.getStatusCode(); final String statusText = statusLine.getReasonPhrase(); final String body = response.getEntity().toString(); StringBuilder strBuf = new StringBuilder(); strBuf.append("Crowd returned HTTP error code:").append(status); strBuf.append(" - ").append(statusText); if (StringUtils.isNotBlank(body)) { strBuf.append("\n").append(body); } throw new RemoteException(strBuf.toString()); }
/** * 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); } }
/** * 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; }
/** * 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 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; } }
/** * 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 final RemoteException transactionPropagationNotSupported() { final RemoteException result = new RemoteException(String.format(getLoggingLocale(), transactionPropagationNotSupported$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String cannotCallMethodInAfterCompletion = "WFLYEJB0388: Cannot call method %s in afterCompletion callback";
@Test public void testRemoteException() throws Exception { doTestException(new RemoteException()); }
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!")); } }
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())); }
return locatorRef.get().narrowAsEntity(EJBObject.class).getPrimaryKey(); throw new RemoteException("Cannot invoke getPrimaryKey() on " + proxy); throw new RemoteException("Cannot invoke getHomeHandle() on " + proxy); throw new RemoteException("Error", e);
@Test public void testAspectMethodThrowsExceptionIllegalOnSignature() { TestBean target = new TestBean(); RemoteException expectedException = new RemoteException(); List<Advisor> advisors = getFixture().getAdvisors( new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean")); assertEquals("One advice method was found", 1, advisors.size()); ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class); try { itb.getAge(); fail(); } catch (UndeclaredThrowableException ex) { assertSame(expectedException, ex.getCause()); } }
@Test public void testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException() throws Exception { final RemoteInterface ejb = mock(RemoteInterface.class); given(ejb.targetMethod()).willThrow(new RemoteException()); final String jndiName= "foobar"; Context mockContext = mockContext(jndiName, ejb); SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName); BusinessInterface target = (BusinessInterface) configuredProxy(si, BusinessInterface.class); try { target.targetMethod(); fail("Should have thrown RemoteAccessException"); } catch (RemoteAccessException ex) { // expected } verify(mockContext).close(); verify(ejb).remove(); }
@Override public Object processInvocation(final InterceptorContext context) throws Exception { try { return context.proceed(); } catch (EJBTransactionRequiredException e) { // this exception explicitly forbids initializing a cause throw copyStackTrace(new TransactionRequiredException(e.getMessage()), e); } catch (EJBTransactionRolledbackException e) { // this exception explicitly forbids initializing a cause throw copyStackTrace(new TransactionRolledbackException(e.getMessage()), e); } catch (NoSuchEJBException e) { // this exception explicitly forbids initializing a cause throw copyStackTrace(new NoSuchObjectException(e.getMessage()), e); } catch (NoSuchEntityException e) { // this exception explicitly forbids initializing a cause throw copyStackTrace(new NoSuchObjectException(e.getMessage()), e); } catch (EJBException e) { //as the create exception is not propagated the init method interceptor just stashes it in a ThreadLocal CreateException createException = popCreateException(); if (createException != null) { throw createException; } throw new RemoteException("Invocation failed", e); } } });
@Test public void testInvokesMethodOnEjbInstanceWithRemoteException() throws Exception { final RemoteInterface ejb = mock(RemoteInterface.class); given(ejb.targetMethod()).willThrow(new RemoteException()); ejb.remove(); final String jndiName= "foobar"; Context mockContext = mockContext(jndiName, ejb); SimpleRemoteSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName); RemoteInterface target = (RemoteInterface) configuredProxy(si, RemoteInterface.class); try { target.targetMethod(); fail("Should have thrown RemoteException"); } catch (RemoteException ex) { // expected } verify(mockContext).close(); verify(ejb, times(2)).remove(); }
@Override @Test public void testRemoteException() throws Exception { final RemoteException rex = new RemoteException(); final String jndiName = "foo";
@Override public void init() throws RemoteException { _spi.init(); try { _spiAgent.init(this); } catch (PortalResiliencyException pre) { throw new RemoteException("Unable to initialize SPI agent", pre); } }