Search in sources :

Example 31 with ProviderRuntimeException

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

the class IltConsumerSyncMethodTest method callMethodWithAnonymousErrorEnum.

@Test
public void callMethodWithAnonymousErrorEnum() {
    LOG.info(name.getMethodName() + "");
    try {
        String wantedExceptionArg = "ProviderRuntimeException";
        testInterfaceProxy.methodWithAnonymousErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - got no result");
        return;
    } catch (ProviderRuntimeException e) {
        if (e.getMessage() == null || !e.getMessage().endsWith("Exception from methodWithAnonymousErrorEnum")) {
            fail(name.getMethodName() + " - FAILED - got invalid ProviderRuntimeException");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    // 2nd test
    try {
        String wantedExceptionArg = "ApplicationException";
        testInterfaceProxy.methodWithAnonymousErrorEnum(wantedExceptionArg);
        fail(name.getMethodName() + " - FAILED - unexpected return of method");
        return;
    } catch (ApplicationException e) {
        if (e.getError() != MethodWithAnonymousErrorEnumErrorEnum.ERROR_3_1_NTC) {
            fail(name.getMethodName() + " - FAILED - got invalid exception error enum value");
            return;
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
    LOG.info(name.getMethodName() + " - OK");
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) MapStringString(joynr.interlanguagetest.namedTypeCollection2.MapStringString) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 32 with ProviderRuntimeException

use of joynr.exceptions.ProviderRuntimeException 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();
    }
}
Also used : MethodSignature(io.joynr.proxy.MethodSignature) JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) Method(java.lang.reflect.Method) MethodInvocationException(joynr.exceptions.MethodInvocationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 33 with ProviderRuntimeException

use of joynr.exceptions.ProviderRuntimeException 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));
        }
    });
}
Also used : JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) MethodInvocationException(joynr.exceptions.MethodInvocationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) MethodInvocationException(joynr.exceptions.MethodInvocationException) JoynrException(io.joynr.exceptions.JoynrException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 34 with ProviderRuntimeException

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

the class IltProvider method methodWithSingleArrayParameters.

/*
     * methodWithSingleArrayParameters
     *
     * Return an array with the stringified double entries
     */
@Override
public Promise<MethodWithSingleArrayParametersDeferred> methodWithSingleArrayParameters(Double[] doubleArrayArg) {
    logger.warn("****************************************************");
    logger.warn("* IltProvider.methodWithSingleArrayParameters called");
    logger.warn("****************************************************");
    MethodWithSingleArrayParametersDeferred deferred = new MethodWithSingleArrayParametersDeferred();
    // check input parameter
    if (!IltUtil.checkDoubleArray(doubleArrayArg)) {
        logger.warn("methodWithMultiplePrimitiveParameters: invalid argument doubleArrayArg");
        deferred.reject(new ProviderRuntimeException("methodWithSingleArrayParameters: received wrong argument"));
        return new Promise<MethodWithSingleArrayParametersDeferred>(deferred);
    }
    // prepare output parameter
    String[] stringArrayOut = IltUtil.createStringArray();
    deferred.resolve(stringArrayOut);
    return new Promise<MethodWithSingleArrayParametersDeferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) MapStringString(joynr.interlanguagetest.namedTypeCollection2.MapStringString) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 35 with ProviderRuntimeException

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

the class IltProvider method methodWithMultipleArrayParameters.

/*
     * methodWithMultipleArrayParameters
     *
     * return the byte array as int64array
     * return the string list as list of string arrays with 1 element each, where this element
     * refers to the one from input
     */
@Override
public Promise<MethodWithMultipleArrayParametersDeferred> methodWithMultipleArrayParameters(String[] stringArrayArg, Byte[] int8ArrayArg, ExtendedInterfaceEnumerationInTypeCollection[] enumArrayArg, StructWithStringArray[] structWithStringArrayArrayArg) {
    logger.warn("******************************************************");
    logger.warn("* IltProvider.methodWithMultipleArrayParameters called");
    logger.warn("******************************************************");
    MethodWithMultipleArrayParametersDeferred deferred = new MethodWithMultipleArrayParametersDeferred();
    if (!IltUtil.checkStringArray(stringArrayArg)) {
        deferred.reject(new ProviderRuntimeException("methodWithMultipleArrayParameters: invalid stringArrayArg"));
        return new Promise<MethodWithMultipleArrayParametersDeferred>(deferred);
    }
    if (!IltUtil.checkByteArray(int8ArrayArg)) {
        deferred.reject(new ProviderRuntimeException("methodWithMultipleArrayParameters: invalid int8ArrayArg"));
        return new Promise<MethodWithMultipleArrayParametersDeferred>(deferred);
    }
    if (!IltUtil.checkExtendedInterfaceEnumerationInTypeCollectionArray(enumArrayArg)) {
        deferred.reject(new ProviderRuntimeException("methodWithMultipleArrayParameters: invalid enumArrayArg"));
        return new Promise<MethodWithMultipleArrayParametersDeferred>(deferred);
    }
    if (!IltUtil.checkStructWithStringArrayArray(structWithStringArrayArrayArg)) {
        deferred.reject(new ProviderRuntimeException("methodWithMultipleArrayParameters: invalid structWithStringArrayArrayArg"));
        return new Promise<MethodWithMultipleArrayParametersDeferred>(deferred);
    }
    Long[] uInt64ArrayOut = IltUtil.createUInt64Array();
    StructWithStringArray[] structWithStringArrayArrayOut = new StructWithStringArray[2];
    structWithStringArrayArrayOut[0] = IltUtil.createStructWithStringArray();
    structWithStringArrayArrayOut[1] = IltUtil.createStructWithStringArray();
    deferred.resolve(uInt64ArrayOut, structWithStringArrayArrayOut);
    return new Promise<MethodWithMultipleArrayParametersDeferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) StructWithStringArray(joynr.interlanguagetest.namedTypeCollection1.StructWithStringArray) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

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