Search in sources :

Example 16 with ProviderRuntimeException

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

the class AttributePollInterpreter method execute.

@Nonnull
public Promise<?> execute(ProviderContainer providerContainer, Method method) {
    String interfaceName = providerContainer.getInterfaceName();
    Object returnValueFromProvider = null;
    try {
        returnValueFromProvider = method.invoke(providerContainer.getProviderProxy());
    } catch (IllegalAccessException e) {
        String message = String.format("Method \"%s\" is not accessible on \"%s\" provider (exception: \"%s\").", method.getName(), interfaceName, e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    } catch (IllegalArgumentException e) {
        String message = String.format("Provider of interface \"%s\" does not declare method \"%s\" (exception: \"%s\")", interfaceName, method.getName(), e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        String message = String.format("Calling method \"%s\" on \"%s\" provider threw an exception: \"%s\"", method.getName(), interfaceName, cause == null ? e.toString() : cause.toString());
        logger.error(message, e);
        throw new ProviderRuntimeException(cause == null ? e.toString() : cause.toString());
    } catch (Exception e) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider threw an unexpected exception: \"%s\"", method.getName(), interfaceName, e.toString());
        logger.error(message, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
    }
    if (returnValueFromProvider == null) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider returned \"null\".", method.getName(), interfaceName);
        logger.error(message);
        throw new JoynrRuntimeException(message);
    }
    Promise<?> returnedPromiseFromProvider = null;
    try {
        returnedPromiseFromProvider = (Promise<?>) returnValueFromProvider;
    } catch (ClassCastException e) {
        String message = String.format("Calling method \"%s\" on \"%s\" provider did not return a promise.", method.getName(), interfaceName);
        logger.error(message, e);
        throw new JoynrRuntimeException(message, e);
    }
    return returnedPromiseFromProvider;
}
Also used : JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodInvocationException(joynr.exceptions.MethodInvocationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) MethodInvocationException(joynr.exceptions.MethodInvocationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Nonnull(javax.annotation.Nonnull)

Example 17 with ProviderRuntimeException

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

the class PublicationManagerImpl method triggerPublication.

private void triggerPublication(final PublicationInformation publicationInformation, ProviderContainer providerContainer, Method method) {
    try {
        Promise<?> attributeGetterPromise = attributePollInterpreter.execute(providerContainer, method);
        attributeGetterPromise.then(new PromiseListener() {

            @Override
            public void onRejection(JoynrException error) {
                if (error instanceof JoynrRuntimeException) {
                    sendPublicationError((JoynrRuntimeException) error, publicationInformation);
                } else {
                    sendPublicationError(new ProviderRuntimeException("Unexpected exception while calling getter for attribute " + publicationInformation.getSubscribedToName()), publicationInformation);
                }
            }

            @Override
            public void onFulfillment(Object... values) {
                // attribute getters only return a single value
                sendPublication(prepareAttributePublication(values[0], publicationInformation.getSubscriptionId()), publicationInformation);
            }
        });
    } catch (JoynrRuntimeException error) {
        sendPublicationError(error, publicationInformation);
    }
}
Also used : PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 18 with ProviderRuntimeException

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

the class SerializationTest method serializeReplyWithProviderRuntimenException.

@Test
public void serializeReplyWithProviderRuntimenException() throws IOException {
    ProviderRuntimeException error = new ProviderRuntimeException("detail message: ProviderRuntimeException");
    Reply reply = new Reply(UUID.randomUUID().toString(), error);
    String writeValueAsString = objectMapper.writeValueAsString(reply);
    System.out.println(writeValueAsString);
    Reply receivedReply = objectMapper.readValue(writeValueAsString, Reply.class);
    Assert.assertEquals(reply, receivedReply);
}
Also used : Reply(joynr.Reply) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 19 with ProviderRuntimeException

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

the class AbstractProviderProxyEnd2EndTest method syncGetAttributeWithProviderRuntimeException.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void syncGetAttributeWithProviderRuntimeException() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    try {
        proxy.getAttributeWithProviderRuntimeException();
        fail("Should throw ProviderRuntimeException");
    } catch (ProviderRuntimeException e) {
        ProviderRuntimeException expected = new ProviderRuntimeException("ProviderRuntimeException");
        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)

Example 20 with ProviderRuntimeException

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

the class AbstractProviderProxyEnd2EndTest method syncMethodCallReturnsThrownException.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void syncMethodCallReturnsThrownException() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    try {
        proxy.methodWithThrownException();
        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