Search in sources :

Example 21 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class ProviderWrapper method createAndResolveOrRejectDeferred.

@SuppressWarnings("unchecked")
private AbstractDeferred createAndResolveOrRejectDeferred(Method method, Object result, JoynrException joynrException) {
    AbstractDeferred deferred;
    if (result == null && method.getReturnType().equals(Void.class)) {
        deferred = new DeferredVoid();
        if (joynrException == null) {
            ((DeferredVoid) deferred).resolve();
        }
    } else {
        if (result instanceof MultiReturnValuesContainer) {
            deferred = new MultiValueDeferred();
            if (joynrException == null) {
                ((MultiValueDeferred) deferred).resolve(((MultiReturnValuesContainer) result).getValues());
            }
        } else {
            deferred = new Deferred<Object>();
            if (joynrException == null) {
                ((Deferred<Object>) deferred).resolve(result);
            }
        }
    }
    if (joynrException != null) {
        LOG.debug("Provider method invocation resulted in provider runtime exception - rejecting the deferred {} with {}", deferred, joynrException);
        if (joynrException instanceof ApplicationException) {
            try {
                Method rejectMethod = AbstractDeferred.class.getDeclaredMethod("reject", new Class[] { JoynrException.class });
                rejectMethod.setAccessible(true);
                rejectMethod.invoke(deferred, new Object[] { joynrException });
            } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
                LOG.warn("Unable to set {} as rejection reason on {}. Wrapping in ProviderRuntimeException instead.", joynrException, deferred);
                deferred.reject(new ProviderRuntimeException(((ApplicationException) joynrException).getMessage()));
            }
        } else if (joynrException instanceof ProviderRuntimeException) {
            deferred.reject((ProviderRuntimeException) joynrException);
        }
    }
    return deferred;
}
Also used : AbstractDeferred(io.joynr.provider.AbstractDeferred) MultiValueDeferred(io.joynr.provider.MultiValueDeferred) Deferred(io.joynr.provider.Deferred) Method(java.lang.reflect.Method) AbstractDeferred(io.joynr.provider.AbstractDeferred) DeferredVoid(io.joynr.provider.DeferredVoid) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultiReturnValuesContainer(io.joynr.dispatcher.rpc.MultiReturnValuesContainer) ApplicationException(joynr.exceptions.ApplicationException) DeferredVoid(io.joynr.provider.DeferredVoid) MultiValueDeferred(io.joynr.provider.MultiValueDeferred) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 22 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class ProviderWrapper method getJoynrExceptionFromInvocationException.

private JoynrException getJoynrExceptionFromInvocationException(InvocationTargetException e) throws InvocationTargetException {
    JoynrException joynrException = null;
    if (e.getCause() != null) {
        if (e.getCause() instanceof EJBException) {
            Exception exception = ((EJBException) e.getCause()).getCausedByException();
            if (exception instanceof ProviderRuntimeException) {
                joynrException = (ProviderRuntimeException) exception;
            }
        } else if (e.getCause() instanceof ProviderRuntimeException || e.getCause() instanceof ApplicationException) {
            joynrException = (JoynrException) e.getCause();
        }
    }
    if (joynrException == null) {
        throw e;
    }
    LOG.trace("Returning joynr exception: {}", joynrException);
    return joynrException;
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) JoynrException(io.joynr.exceptions.JoynrException) EJBException(javax.ejb.EJBException) JoynrException(io.joynr.exceptions.JoynrException) ApplicationException(joynr.exceptions.ApplicationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EJBException(javax.ejb.EJBException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 23 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method syncMethodCallReturnsErrorEnum.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void syncMethodCallReturnsErrorEnum() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    try {
        proxy.methodWithErrorEnum();
        fail("Should throw ApplicationException");
    } catch (JoynrRuntimeException e) {
        fail(e.toString());
    } catch (ApplicationException e) {
        ApplicationException expected = new ApplicationException(ErrorEnumBase.BASE_ERROR_TYPECOLLECTION);
        assertEquals(expected, e);
    }
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) joynr.tests.testProxy(joynr.tests.testProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 24 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method asyncMethodCallReturnsExtendedErrorEnum.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void asyncMethodCallReturnsExtendedErrorEnum() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    ApplicationException expected = new ApplicationException(MethodWithErrorEnumExtendedErrorEnum.IMPLICIT_ERROR_TYPECOLLECTION);
    Future<Void> future = proxy.methodWithErrorEnumExtended(callbackWithApplicationExceptionMethodWithErrorEnumExtendedErrorEnum);
    try {
        future.get();
        fail("Should throw ApplicationException");
    } catch (JoynrRuntimeException | InterruptedException e) {
        fail(e.toString());
    } catch (ApplicationException e) {
        assertEquals(expected, e);
    }
    verify(callbackWithApplicationExceptionMethodWithErrorEnumExtendedErrorEnum).onFailure((MethodWithErrorEnumExtendedErrorEnum) (expected.getError()));
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) joynr.tests.testProxy(joynr.tests.testProxy) DeferredVoid(io.joynr.provider.DeferredVoid) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 25 with ApplicationException

use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method syncMethodCallReturnsExtendedErrorEnum.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void syncMethodCallReturnsExtendedErrorEnum() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    try {
        proxy.methodWithErrorEnumExtended();
        fail("Should throw ApplicationException");
    } catch (JoynrRuntimeException e) {
        fail(e.toString());
    } catch (ApplicationException e) {
        ApplicationException expected = new ApplicationException(MethodWithErrorEnumExtendedErrorEnum.IMPLICIT_ERROR_TYPECOLLECTION);
        assertEquals(expected, e);
    }
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) joynr.tests.testProxy(joynr.tests.testProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Aggregations

ApplicationException (joynr.exceptions.ApplicationException)31 Test (org.junit.Test)21 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)13 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)13 joynr.tests.testProxy (joynr.tests.testProxy)7 MapStringString (joynr.interlanguagetest.namedTypeCollection2.MapStringString)6 Reply (joynr.Reply)5 DeferredVoid (io.joynr.provider.DeferredVoid)4 DiscoveryException (io.joynr.exceptions.DiscoveryException)3 JoynrException (io.joynr.exceptions.JoynrException)3 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)3 CheckForNull (javax.annotation.CheckForNull)3 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 SynchronizedReplyCaller (io.joynr.dispatching.rpc.SynchronizedReplyCaller)2 MessagingQos (io.joynr.messaging.MessagingQos)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)2 Ignore (org.junit.Ignore)2