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();
}
}
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);
}
}
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);
}
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()));
}
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()));
}
Aggregations