use of joynr.exceptions.MethodInvocationException 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.MethodInvocationException in project joynr by bmwcarit.
the class RequestInterpreter method invokeMethod.
public Object invokeMethod(RequestCaller requestCaller, OneWayRequest request) {
// A method is identified by its defining request caller, its name and the types of its arguments
MethodSignature methodSignature = new MethodSignature(requestCaller, request.getMethodName(), request.getParamDatatypes());
ensureMethodMetaInformationPresent(requestCaller, request, methodSignature);
Method method = methodSignatureToMethodMap.get(methodSignature);
Object[] params = null;
try {
if (method.getParameterTypes().length > 0) {
// method with parameters
params = request.getParams();
}
joynrMessageScope.activate();
setContext(requestCaller, request);
logger.trace("invoke provider method {}({})", method.getName(), params == null ? "" : params);
return requestCaller.invoke(method, params);
} catch (IllegalAccessException e) {
logger.error("RequestInterpreter: Received an RPC invocation for a non public method {}", request);
JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(requestCaller.getProxy().getClass(), JoynrVersion.class);
throw new MethodInvocationException(e, new Version(joynrVersion.major(), joynrVersion.minor()));
} catch (InvocationTargetException e) {
logger.debug("invokeMethod error", e);
Throwable cause = e.getCause();
logger.error("RequestInterpreter: Could not perform an RPC invocation: {}", cause == null ? e.toString() : cause.getMessage());
throw new ProviderRuntimeException(cause == null ? e.toString() : cause.toString());
} finally {
requestCaller.removeContext();
joynrMessageScope.deactivate();
}
}
use of joynr.exceptions.MethodInvocationException in project joynr by bmwcarit.
the class RequestInterpreter method execute.
public void execute(final ProviderCallback<Reply> callback, RequestCaller requestCaller, final Request request) {
Promise<? extends AbstractDeferred> promise;
logger.debug("execute request on provider: {}", request);
try {
promise = (Promise<?>) invokeMethod(requestCaller, request);
} catch (MethodInvocationException | ProviderRuntimeException e) {
logger.warn("execute request on provider failed with exception: {}, request: {}", e, request);
callback.onFailure(e);
return;
} catch (Exception e) {
JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(requestCaller.getProxy().getClass(), JoynrVersion.class);
MethodInvocationException methodInvocationException = new MethodInvocationException(e, new Version(joynrVersion.major(), joynrVersion.minor()));
logger.warn("execute request on provider failed with exception: {}, request: {}", methodInvocationException, request);
callback.onFailure(methodInvocationException);
return;
}
promise.then(new PromiseListener() {
@Override
public void onRejection(JoynrException error) {
logger.debug("execute request on provider onRejection: {}, request: {}", error, request);
callback.onFailure(error);
}
@Override
public void onFulfillment(Object... values) {
logger.debug("execute request on provider onFulfillment: {}, request: {}", values, request);
callback.onSuccess(createReply(request, values));
}
});
}
use of joynr.exceptions.MethodInvocationException in project joynr by bmwcarit.
the class RequestInterpreter method ensureMethodMetaInformationPresent.
private void ensureMethodMetaInformationPresent(RequestCaller requestCaller, OneWayRequest request, MethodSignature methodSignature) {
try {
if (!methodSignatureToMethodMap.containsKey(methodSignature)) {
Method method;
method = ReflectionUtils.findMethodByParamTypeNames(methodSignature.getRequestCaller().getProxy().getClass(), methodSignature.getMethodName(), methodSignature.getParameterTypeNames());
methodSignatureToMethodMap.putIfAbsent(methodSignature, method);
}
} catch (NoSuchMethodException e) {
logger.error("RequestInterpreter: Received an RPC invocation for a non existing method" + request, e);
JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(requestCaller.getProxy().getClass(), JoynrVersion.class);
throw new MethodInvocationException(e.toString(), new Version(joynrVersion.major(), joynrVersion.minor()));
}
}
use of joynr.exceptions.MethodInvocationException in project joynr by bmwcarit.
the class SerializationTest method serializeReplyWithMethodInvocationException.
@Test
public void serializeReplyWithMethodInvocationException() throws IOException {
MethodInvocationException error = new MethodInvocationException("detail message: MessageInvocationException");
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);
}
Aggregations