public Object invoke()

in sdk/host/src/main/java/org/apache/teaclave/javasdk/host/ProxyEnclaveInvocationHandler.java [42:93]


    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        EnclaveInvocationContext methodInvokeMetaWrapper;
        String[] parameterTypes;
        // Building a method wrapper for enclave native invocation.
        if (args != null) {
            parameterTypes = new String[args.length];
            // Get a method's parameter type exactly.
            Class<?>[] paraTypes = method.getParameterTypes();
            for (int index = 0x0; index < args.length; index++) {
                parameterTypes[index] = paraTypes[index].getName();
            }
            methodInvokeMetaWrapper = new EnclaveInvocationContext(
                    serviceHandler,
                    method.getName(),
                    parameterTypes,
                    args);
        } else {
            methodInvokeMetaWrapper = new EnclaveInvocationContext(
                    serviceHandler,
                    method.getName(), null, null);
        }

        // Handle service method invocation exception.
        try (MetricTraceContext trace = new MetricTraceContext(
                enclave.getEnclaveInfo(),
                MetricTraceContext.LogPrefix.METRIC_LOG_ENCLAVE_SERVICE_INVOKING_PATTERN,
                method.getName())) {
            EnclaveInvocationResult result = enclave.InvokeEnclaveMethod(methodInvokeMetaWrapper);
            trace.setCostInnerEnclave(result.getCost());
            Throwable causeException = result.getException();
            if (causeException instanceof ConfidentialComputingException) {
                Throwable enclaveCauseException = causeException.getCause();
                Class<?>[] exceptionTypes = method.getExceptionTypes();
                if (enclaveCauseException instanceof InvocationTargetException) {
                    // Check whether cause exception matches one of the method's exception declaration.
                    // If it's true, it illustrates that an exception happened in enclave when the service
                    // method was invoked in enclave, we should throw this exception directly and user will
                    // handle it.
                    // If it's false, it illustrates that an exception happened in host side or enclave side,
                    // but the exception is not belong to the method's declaration. In the case we should throw
                    // EnclaveMethodInvokingException again.
                    Throwable rootCause = enclaveCauseException.getCause();
                    for (Class<?> exception : exceptionTypes) {
                        if (exception == rootCause.getClass()) {
                            throw rootCause;
                        }
                    }
                }
            }
            return result.getResult();
        }
    }