launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java
branchlauncher
changeset 332 6949044415df
parent 323 d41cfd77842d
child 342 60f9aad12731
     1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java	Sat Dec 15 16:25:28 2012 +0100
     1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Console.java	Sun Dec 16 20:11:18 2012 +0100
     1.3 @@ -17,7 +17,10 @@
     1.4   */
     1.5  package org.apidesign.bck2brwsr.launcher;
     1.6  
     1.7 +import java.io.InputStream;
     1.8 +import java.lang.reflect.InvocationTargetException;
     1.9  import java.lang.reflect.Method;
    1.10 +import java.net.URL;
    1.11  import org.apidesign.bck2brwsr.core.JavaScriptBody;
    1.12  
    1.13  /**
    1.14 @@ -45,7 +48,23 @@
    1.15      public static void execute() throws Exception {
    1.16          String clazz = (String) getAttr("clazz", "value");
    1.17          String method = (String) getAttr("method", "value");
    1.18 +        Object res = invokeMethod(clazz, method);
    1.19 +        setAttr("result", "value", res);
    1.20 +    }
    1.21 +    
    1.22 +    public static void harness() {
    1.23 +        try {
    1.24 +            URL u = new URL("/execute/data");
    1.25 +            String data = (String) u.getContent(new Class[] { String.class });
    1.26 +            setAttr("result", "value", data);
    1.27 +        } catch (Exception ex) {
    1.28 +            setAttr("result", "value", ex.getMessage());
    1.29 +        }
    1.30 +    }
    1.31  
    1.32 +    private static Object invokeMethod(String clazz, String method) 
    1.33 +    throws ClassNotFoundException, InvocationTargetException, 
    1.34 +    SecurityException, IllegalAccessException, IllegalArgumentException {
    1.35          Method found = null;
    1.36          Class<?> c = Class.forName(clazz);
    1.37          for (Method m : c.getMethods()) {
    1.38 @@ -59,7 +78,6 @@
    1.39          } else {
    1.40              res = "Can't find method " + method + " in " + clazz;
    1.41          }
    1.42 -        
    1.43 -        setAttr("result", "value", res);
    1.44 +        return res;
    1.45      }
    1.46  }