Example #1
1
static void OutputExceptionDetails(MonoObject* exc)
{
	MonoClass* eclass = mono_object_get_class(exc);

	if (eclass)
	{
		MonoObject* toStringExc = nullptr;
		MonoString* msg = mono_object_to_string(exc, &toStringExc);

		MonoProperty* prop = mono_class_get_property_from_name(eclass, "StackTrace");
		MonoMethod* getter = mono_property_get_get_method(prop);
		MonoString* msg2 = (MonoString*)mono_runtime_invoke(getter, exc, NULL, NULL);

		if (toStringExc)
		{
			MonoProperty* prop = mono_class_get_property_from_name(eclass, "Message");
			MonoMethod* getter = mono_property_get_get_method(prop);
			msg = (MonoString*)mono_runtime_invoke(getter, exc, NULL, NULL);
		}

		GlobalError("Unhandled exception in Mono script environment: %s %s", mono_string_to_utf8(msg), mono_string_to_utf8(msg2));
	}
}
Example #2
0
void JniManager::toProcessRequest(jobject obj, MonoObject* processRequest)
{
    JNIEnv* env = getEnv();

    MonoDomain* monoDomain = getMonoDomain();

    string c_assemblyName = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getAssemblyName, "()Ljava/lang/String;"));
    string c_assemblyPath = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getAssemblyPath, "()Ljava/lang/String;"));
    string c_methodName = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getMethodName, "()Ljava/lang/String;"));

    MonoString* assemblyName = mono_string_new(monoDomain, c_assemblyName.c_str());
    MonoString* assemblyPath = mono_string_new(monoDomain, c_assemblyPath.c_str());
    MonoString* methodName = mono_string_new(monoDomain, c_methodName.c_str());
    bool fullTrust = env->CallBooleanMethod(obj, getFullTrust);
    bool isSingleton = env->CallBooleanMethod(obj, getIsSingleton);
    bool log = env->CallBooleanMethod(obj, getLog);
    bool notifyEvents = env->CallBooleanMethod(obj, getNotifyEvents);

    MonoObject* exception = NULL;

    void* args[1];
    args[0] = assemblyName;
    mono_runtime_invoke(setAssemblyNameField, processRequest, args, &exception);

    args[0] = assemblyPath;
    mono_runtime_invoke(setAssemblyPathField, processRequest, args, &exception);

    args[0] = methodName;
    mono_runtime_invoke(setMethodNameField, processRequest, args, &exception);

    args[0] = &fullTrust;
    mono_runtime_invoke(setFullTrustField, processRequest, args, &exception);

    args[0] = &log;
    mono_runtime_invoke(setLogField, processRequest, args, &exception);

    args[0] = &isSingleton;
    mono_runtime_invoke(setIsSingletonField, processRequest, args, &exception);

    args[0] = &notifyEvents;
    mono_runtime_invoke(setNotifyEventsField, processRequest, args, &exception);

    if (exception)
    {
        const char* message = mono_string_to_utf8(mono_object_to_string(exception, NULL));
        throwException(message);
    }

    jobject javaMethodArguments = env->CallObjectMethod(obj, getMethodArguments);

    setProperties(env, javaMethodArguments, addMethodArgumentsProperty, processRequest);
    //request->MethodArguments = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getMethodArguments));
    //request->InboundProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getInboundProperties));
    //request->InvocationProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getInvocationProperties));
    //request->OutboundProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getOutboundProperties));
    //request->SessionProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getSessionProperties));
}
Example #3
0
void JniManager::setProperties(JNIEnv* env, jobject map, MonoMethod* method, MonoObject* instance)
{
    assert(env);

    MonoDomain* monoDomain = getMonoDomain();

    if (map == NULL)
    {
        return;
    }

    int mapSize = env->CallIntMethod(map, typeConverter->size);

    jobject keys = env->CallObjectMethod(map, typeConverter->keySet);

    jobjectArray arrayOfKeys = (jobjectArray)env->CallObjectMethod(keys, typeConverter->toArray);

    for (int i = 0; i < mapSize; i++)
    {
        jstring javaKeyName = (jstring)env->GetObjectArrayElement(arrayOfKeys, i);
        string keyName = typeConverter->convertToC<string>(env, javaKeyName);
        jobject mapValue = env->CallObjectMethod(map, typeConverter->getMapValue, javaKeyName);

        //if (env->IsInstanceOf(mapValue, typeConverter->mapClazz))
        //{

        //}

        MonoObject* exc = NULL;
        void* args[2];
        args[0] = mono_string_new(monoDomain, keyName.c_str());
        args[1] = toMonoObject(env, mapValue);

        mono_runtime_invoke(method, instance, args, &exc);

        if (exc)
        {
            const char* message = mono_string_to_utf8(mono_object_to_string(exc, NULL));
            throwException(message);
            return;
        }


        env->DeleteLocalRef(javaKeyName);
        env->DeleteLocalRef(mapValue);
    }

    env->DeleteLocalRef(keys);
    env->DeleteLocalRef(arrayOfKeys);
    env->DeleteLocalRef(map);
}
Example #4
0
MonoString *object_to_string(MonoObject *p_obj, MonoException **p_exc) {
	GD_MONO_BEGIN_RUNTIME_INVOKE;
	MonoString *ret = mono_object_to_string(p_obj, (MonoObject **)p_exc);
	GD_MONO_END_RUNTIME_INVOKE;
	return ret;
}
Example #5
0
jobject JniManager::toResponse(MonoObject* monoObject)
{
    assert(monoObject);

    JNIEnv* env = getEnv();

    assert(env);

    jobject response = env->NewObject(responseClazz, responseCtor);

    MonoObject* exc = NULL;

    MonoObject* result = mono_runtime_invoke(getResult, monoObject, NULL, &exc);

    if (exc)
    {
        const char* message = mono_string_to_utf8(mono_object_to_string(exc, NULL));
        throwException(message);
        return NULL;
    }

    jobject jPayload = NULL;

    if (result != NULL)
    {
        MonoClass* resultClass = mono_object_get_class(result);

        MonoType* monoType = mono_class_get_type(resultClass);

        string typeName = string(mono_type_get_name(monoType));

        // If it's a string or byte[]
        if (typeName == "System.String")
        {
            const char* convertedPayload = mono_string_to_utf8(mono_object_to_string(result, NULL));
            jPayload = env->NewStringUTF(convertedPayload);
        }
        else
        {
            jPayload = typeConverter->convertToJavaArray<jbyteArray>(env, result);
        }

        env->CallVoidMethod(response, setPayloadMethod, jPayload);
        env->DeleteLocalRef(jPayload);
    }

    // set Mule Message properties
    //jobject jInvocationProperties = typeConverter->convertToJavaMap(env, request->InvocationProperties);
    //jobject jSessionProperties = typeConverter->convertToJavaMap(env, request->SessionProperties);
    //jobject jOutboundProperties = typeConverter->convertToJavaMap(env, request->OutboundProperties);

    /*env->CallVoidMethod(response, setInvocationProperties, jInvocationProperties);
    env->CallVoidMethod(response, setOutboundProperties, jOutboundProperties);
    env->CallVoidMethod(response, setSessionProperties, jSessionProperties);

    env->DeleteLocalRef(jInvocationProperties);
    env->DeleteLocalRef(jOutboundProperties);
    env->DeleteLocalRef(jSessionProperties);*/

    return response;
}