public EnclaveInvocationResult callMethod()

in sdk/enclave/src/main/java/org/apache/teaclave/javasdk/enclave/framework/ServiceMethodInvoker.java [48:85]


    public EnclaveInvocationResult callMethod(EnclaveInvocationContext inputData) {
        Throwable throwable = null;
        Object returnedValue = null;
        List<Class<?>> parameterClassList = extractParamClasses(inputData.getParameterTypes());
        ServiceHandler serviceHandler = inputData.getServiceHandler();
        String instanceIdentity = serviceHandler.getInstanceIdentity();
        String serviceName = serviceHandler.getServiceInterfaceName();
        String implementationClassName = serviceHandler.getServiceImplClassName();
        Object receiverInstance;
        try {
            receiverInstance = EnclaveContext.getInstance().lookupServiceInstance(instanceIdentity, serviceName, implementationClassName);
        } catch (ConfidentialComputingException e) {
            return new EnclaveInvocationResult(null, e);
        }
        if (receiverInstance != null) {
            String methodName = inputData.getMethodName();
            Method method;
            // Get the public method to invoke
            try {
                Class<?> serviceClass = Class.forName(implementationClassName);
                method = serviceClass.getMethod(methodName, parameterClassList.toArray(new Class<?>[0]));
                method.setAccessible(true);
            } catch (ReflectiveOperationException e) {
                // Reflection exception is taken as framework's exception
                return new EnclaveInvocationResult(null, new ConfidentialComputingException(e));
            }
            try {
                // Call the actual method
                returnedValue = method.invoke(receiverInstance, inputData.getArguments());
            } catch (Throwable t) {
                return new EnclaveInvocationResult(null, new ConfidentialComputingException(t));
            }
        } else {
            throwable = new ConfidentialComputingException(
                    String.format("Didn't match any service implementation with the given class name: %s", implementationClassName));
        }
        return new EnclaveInvocationResult(returnedValue, throwable);
    }