GWT server side reflection

I am trying to use Server Side Reflection for a GWT application only. I have a basic example working in an example other than GWT, which can be seen below.

package com.xyz.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class EntryPoint {

/**
 * @param args
 */
public static void main(String[] args) {

    ClassLoader dynClassLoader = ClassLoader.getSystemClassLoader();

    Class<?> dynClass = null;
    try {
        dynClass = dynClassLoader.loadClass("com.xyz.reflection.RunMe");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    Object dynInstance = null;
    try {
        dynInstance = dynClass.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    Method dynMethod = null;
    try {
        try {
            dynMethod = dynInstance.getClass().getMethod("returnSid",
                    new Class[] { PassMe.class });

        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }

        String returnValue = (String) dynMethod.invoke(dynInstance,
                new Object[] { new PassMe() });

        System.out.println("Return Value: " + returnValue.toString());

    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}

}

using aptly named:

    package com.xyz.reflection;

public class PassMe {

private String sid = "DEFAULT_SID";

public PassMe() {
    this.sid = "INITIATED_SID";
}

public String getSid() {
    return sid;
}

public void setSid(String sid) {
    this.sid = sid;
}

}

and

    package com.xyz.reflection;


public class RunMe {

    public String returnSid(PassMe s) {
        return s.getSid();
    }
}

This is normal. When I try to run this from the GWT server side class, it does not work and instead returns

 java.lang.NoSuchMethodException: com.xyz.reflection.RunMe.returnSid(com.xyz.reflection.PassMe)

If I change the parameter to String (instead of the PassMe class), it works fine. Why don't I like to go through my PassMe class? I thought this might be a serialization issue, even though it is 100% server code, but I was not lucky either.

Thanks in advance for any help anyone can give me.

+3
source share
4

finrod - :

ClassLoader dynClassLoader = PassMe.class.getClassLoader();

PassMe.class. , , -, . .

. , GWT - .

: . GWT com.google.appengine.tools.development.IsolatedAppClassLoader dev.

+1

, - , , .

:

:

ClassLoader dynClassLoader = ClassLoader.getSystemClassLoader();

dynClass = dynClassLoader.loadClass("com.xyz.reflection.RunMe");

RunMe.

PassMe :

PassMe.class

PassMe dynClassLoader getMethod() PassMe.class.

, dynClassLoader?

+1

, dynMethod = dynInstance.getClass().getMethod("returnSid", new Class[] { PassMe.class });

dynMethod = dynInstance.getClass().getMethod("returnSid", PassMe.class );

GWT, VM -.

0

? :
org.myproject.client - gwt ( java , java script NO REFLECTION)
org.myproject.server - java ,
org.myproject.shared - java-, java script

0

Source: https://habr.com/ru/post/1753616/


All Articles