Search in sources :

Example 6 with ApplicationException

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

the class JoynrMessagingConnectorInvocationHandler method executeSyncMethod.

@CheckForNull
@Override
public Object executeSyncMethod(Method method, Object[] args) throws ApplicationException {
    // TODO does a method with 0 args pass in an empty args array, or null for args?
    if (method == null) {
        throw new IllegalArgumentException("Method cannot be null");
    }
    if (toDiscoveryEntries.size() > 1) {
        throw new JoynrIllegalStateException("You can't execute sync methods for multiple participants.");
    }
    if (toDiscoveryEntries.isEmpty()) {
        throw new JoynrIllegalStateException("You must have exactly one participant to be able to execute a sync method.");
    }
    MethodMetaInformation methodMetaInformation = JoynrMessagingConnectorFactory.ensureMethodMetaInformationPresent(method);
    Request request = new Request(method.getName(), args, method.getParameterTypes());
    Reply reply;
    String requestReplyId = request.getRequestReplyId();
    SynchronizedReplyCaller synchronizedReplyCaller = new SynchronizedReplyCaller(fromParticipantId, requestReplyId, request);
    ExpiryDate expiryDate = DispatcherUtils.convertTtlToExpirationDate(qosSettings.getRoundTripTtl_ms());
    replyCallerDirectory.addReplyCaller(requestReplyId, synchronizedReplyCaller, expiryDate);
    reply = (Reply) requestReplyManager.sendSyncRequest(fromParticipantId, toDiscoveryEntries.iterator().next(), request, synchronizedReplyCaller, qosSettings);
    if (reply.getError() == null) {
        if (method.getReturnType().equals(void.class)) {
            return null;
        }
        Object response = RpcUtils.reconstructReturnedObject(method, methodMetaInformation, reply.getResponse());
        logger.debug("REQUEST returns successful: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), response);
        return response;
    } else if (reply.getError() instanceof ApplicationException) {
        logger.debug("REQUEST returns error: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), reply.getError());
        throw (ApplicationException) reply.getError();
    } else {
        logger.debug("REQUEST returns error: requestReplyId: {}, method {}, response: {}", requestReplyId, method.getName(), reply.getError());
        throw (JoynrRuntimeException) reply.getError();
    }
}
Also used : ExpiryDate(io.joynr.common.ExpiryDate) ApplicationException(joynr.exceptions.ApplicationException) MethodMetaInformation(joynr.MethodMetaInformation) OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) Reply(joynr.Reply) SynchronizedReplyCaller(io.joynr.dispatching.rpc.SynchronizedReplyCaller) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) CheckForNull(javax.annotation.CheckForNull)

Example 7 with ApplicationException

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

the class ProxyInvocationHandlerImpl method invoke.

@Override
@CheckForNull
public Object invoke(@Nonnull Method method, Object[] args) throws ApplicationException {
    logger.trace("calling proxy.{}({}) on domain: {} and interface {}, proxy participant ID: {}", method.getName(), args, domains, interfaceName, proxyParticipantId);
    Class<?> methodInterfaceClass = method.getDeclaringClass();
    try {
        if (JoynrSubscriptionInterface.class.isAssignableFrom(methodInterfaceClass) || JoynrBroadcastSubscriptionInterface.class.isAssignableFrom(methodInterfaceClass)) {
            return executeSubscriptionMethod(method, args);
        } else if (methodInterfaceClass.getAnnotation(FireAndForget.class) != null) {
            return executeOneWayMethod(method, args);
        } else if (methodInterfaceClass.getAnnotation(Sync.class) != null) {
            return executeSyncMethod(method, args);
        } else if (methodInterfaceClass.getAnnotation(Async.class) != null) {
            return executeAsyncMethod(method, args);
        } else {
            throw new JoynrIllegalStateException("Method is not part of sync, async or subscription interface");
        }
    } catch (JoynrRuntimeException | ApplicationException e) {
        throw e;
    } catch (Exception e) {
        throw new JoynrRuntimeException(e);
    }
}
Also used : JoynrSubscriptionInterface(io.joynr.dispatcher.rpc.JoynrSubscriptionInterface) ApplicationException(joynr.exceptions.ApplicationException) Sync(io.joynr.Sync) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrBroadcastSubscriptionInterface(io.joynr.dispatcher.rpc.JoynrBroadcastSubscriptionInterface) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) DiscoveryException(io.joynr.exceptions.DiscoveryException) JoynrException(io.joynr.exceptions.JoynrException) ApplicationException(joynr.exceptions.ApplicationException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) CheckForNull(javax.annotation.CheckForNull)

Example 8 with ApplicationException

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

the class SerializationTest method serializeReplyWithJoynrApplicationExceptionWithoutMessage.

@Test
public void serializeReplyWithJoynrApplicationExceptionWithoutMessage() throws IOException {
    ApplicationException error = new ApplicationException(TestEnum.TWO);
    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 : ApplicationException(joynr.exceptions.ApplicationException) Reply(joynr.Reply) Test(org.junit.Test)

Example 9 with ApplicationException

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

the class AbstractProviderProxyEnd2EndTest method asyncMethodCallReturnsImplicitErrorEnum.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void asyncMethodCallReturnsImplicitErrorEnum() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    ApplicationException expected = new ApplicationException(MethodWithImplicitErrorEnumErrorEnum.IMPLICIT_ERROR);
    Future<Void> future = proxy.methodWithImplicitErrorEnum(callbackWithApplicationExceptionMethodWithImplicitErrorEnumErrorEnum);
    try {
        future.get();
        fail("Should throw ApplicationException");
    } catch (JoynrRuntimeException | InterruptedException e) {
        fail(e.toString());
    } catch (ApplicationException e) {
        assertEquals(expected, e);
    }
    verify(callbackWithApplicationExceptionMethodWithImplicitErrorEnumErrorEnum).onFailure((MethodWithImplicitErrorEnumErrorEnum) (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 10 with ApplicationException

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

the class AbstractProviderProxyEnd2EndTest method asyncMethodCallReturnsErrorEnum.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void asyncMethodCallReturnsErrorEnum() {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    ApplicationException expected = new ApplicationException(ErrorEnumBase.BASE_ERROR_TYPECOLLECTION);
    Future<Void> future = proxy.methodWithErrorEnum(callbackWithApplicationExceptionErrorEnumBase);
    try {
        future.get();
        fail("Should throw ApplicationException");
    } catch (JoynrRuntimeException | InterruptedException e) {
        fail(e.toString());
    } catch (ApplicationException e) {
        assertEquals(expected, e);
    }
    verify(callbackWithApplicationExceptionErrorEnumBase).onFailure((ErrorEnumBase) (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)

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