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