Search in sources :

Example 56 with ProviderRuntimeException

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

the class IltProviderBean method methodWithMultiplePrimitiveParameters.

/*
     * methodWithMultiplePrimitiveParameters
     *
     * the 'float' of France is delivered as Double here, just return it as 'double'
     * and return the integer argument as string
     */
@Override
public MethodWithMultiplePrimitiveParametersReturned methodWithMultiplePrimitiveParameters(Integer int32Arg, Float floatArg, Boolean booleanArg) {
    logger.warn("**********************************************************");
    logger.warn("* IltProvider.methodWithMultiplePrimitiveParameters called");
    logger.warn("**********************************************************");
    // check input parameters
    if (int32Arg != 2147483647 || !IltUtil.cmpFloat(floatArg, 47.11f) || booleanArg) {
        logger.warn("methodWithMultiplePrimitiveParameters: invalid argument int32Arg, floatArg or booleanArg");
        throw new ProviderRuntimeException("methodWithMultiplePrimitiveParameters: received wrong argument");
    }
    // prepare output parameters
    Double doubleOut = (double) floatArg;
    String stringOut = int32Arg.toString();
    return new MethodWithMultiplePrimitiveParametersReturned(doubleOut, stringOut);
}
Also used : MapStringString(joynr.interlanguagetest.namedTypeCollection2.MapStringString) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 57 with ProviderRuntimeException

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

the class ProviderWrapperTest method testInvokeMethodThrowingProviderRuntimeException.

@Test
public void testInvokeMethodThrowingProviderRuntimeException() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("testThrowsProviderRuntimeException");
    Object result = subject.invoke(proxy, method, new Object[0]);
    assertNotNull(result);
    assertTrue(result instanceof Promise);
    assertTrue(((Promise<?>) result).isRejected());
    ((Promise<?>) result).then(new PromiseListener() {

        @Override
        public void onFulfillment(Object... values) {
            fail("Should never get here");
        }

        @Override
        public void onRejection(JoynrException error) {
            assertTrue(error instanceof ProviderRuntimeException);
        }
    });
}
Also used : Promise(io.joynr.provider.Promise) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 58 with ProviderRuntimeException

use of joynr.exceptions.ProviderRuntimeException 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 59 with ProviderRuntimeException

use of joynr.exceptions.ProviderRuntimeException 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 60 with ProviderRuntimeException

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

the class AbstractProviderProxyEnd2EndTest method syncSetAttributeWithThrownException.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void syncSetAttributeWithThrownException() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    try {
        proxy.setAttributeWithProviderRuntimeException(42);
        fail("Should throw ProviderRuntimeException");
    } catch (ProviderRuntimeException e) {
        ProviderRuntimeException expected = new ProviderRuntimeException(new IllegalArgumentException("thrownException").toString());
        assertEquals(expected, e);
    } catch (Exception e) {
        fail(e.toString());
    }
}
Also used : joynr.tests.testProxy(joynr.tests.testProxy) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) JoynrTimeoutException(io.joynr.exceptions.JoynrTimeoutException) DiscoveryException(io.joynr.exceptions.DiscoveryException) JoynrWaitExpiredException(io.joynr.exceptions.JoynrWaitExpiredException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Aggregations

ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)67 Promise (io.joynr.provider.Promise)27 ApplicationException (joynr.exceptions.ApplicationException)23 Test (org.junit.Test)21 MapStringString (joynr.interlanguagetest.namedTypeCollection2.MapStringString)19 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)13 DiscoveryException (io.joynr.exceptions.DiscoveryException)10 DeferredVoid (io.joynr.provider.DeferredVoid)10 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)8 JoynrTimeoutException (io.joynr.exceptions.JoynrTimeoutException)8 JoynrWaitExpiredException (io.joynr.exceptions.JoynrWaitExpiredException)8 joynr.tests.testProxy (joynr.tests.testProxy)8 ExtendedExtendedBaseStruct (joynr.interlanguagetest.namedTypeCollection2.ExtendedExtendedBaseStruct)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 JoynrException (io.joynr.exceptions.JoynrException)4 ExtendedBaseStruct (joynr.interlanguagetest.namedTypeCollection2.ExtendedBaseStruct)4 JoynrVersion (io.joynr.JoynrVersion)3 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)3 Deferred (io.joynr.provider.Deferred)3 PromiseListener (io.joynr.provider.PromiseListener)3