If you have frequent, simple Java code to execute, you might avail yourself of an INTERPRETER like BeanShell
Just copy bsh-2.0b4.jar to $DOMAIN_HOME/lib directory, restart your server, and you are ready to use the BeanShellJavaCallout Java wrapper to BeanShell:
package com.acme.javacallout; import bsh.EvalError; import bsh.Interpreter; public class BeanShellJavaCallout { public static String callBeanShell(String code) throws EvalError { Interpreter i = new Interpreter(); Object result = i.eval(code); return result.toString(); } }
package com.acme.javacallout; import static org.junit.Assert.*; import org.junit.Test; import bsh.EvalError; import bsh.Interpreter; public class BeanShellJavaCalloutTest { @Test public void callBeanShellTest() throws EvalError { System.setProperty("weblogic.Name", "osbdv1ms1"); String result = BeanShellJavaCallout.callBeanShell("return java.lang.System.getProperty(\"weblogic.Name\")"); assertEquals("osbdv1ms1", result); } }
No comments:
Post a Comment