Examples of BSFEngine


Examples of org.apache.bsf.BSFEngine

    @Test
    public void testAccess() throws BSFException {
        // tag::bsf_access[]
        BSFManager manager = new BSFManager();
        BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
        manager.declareBean("myvar", "hello", String.class);
        Object myvar = manager.lookupBean("myvar");
        String result = (String) bsfEngine.call(myvar, "reverse", new Object[0]);
        assertEquals("olleh", result);
        // end::bsf_access[]
    }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        answer = manager.eval("groovy", "Test1.groovy", 0, 0, "abc");
        assertNull("Undeclared beans should yield null", answer);
    }

    public void testCall() throws Exception {
        BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
        manager.declareBean("myvar", "hello", String.class);
        Object myvar = manager.lookupBean("myvar");
        String result = (String) bsfEngine.call(myvar, "reverse", new Object[]{});
        assertEquals("olleh", result);
    }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        manager = new BSFManager();
    }

    public void testVersion() throws Exception {
        //System.out.println("BSFManager.getVersion() = " + BSFManager.getVersion());
        BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
        assertEquals(CACHING_ENGINE, bsfEngine.getClass());
    }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        final Logger logger = LoggerFactory.getLogger(controllerName);
        try {
            // pre-load the engine to make sure we were called right
            final SiteContext site = context.getSiteContext();
            if (site != null) {
                BSFEngine bsfEngine = site.getBSFEngine(language, context, configuration, logger);
                // Execute with the proper language, the fileName (for error reporting),
                // the row and column to start at, and finally the contents of the script
                // some examples: http://massapi.com/class/bs/BSFManager.html
                bsfEngine.exec(controllerName, 0, 0, script);

            } else {
                throw new ControllerException("Micro site is not in the current context, please review");
            }
            // return bsfManager.lookupBean(Globals.SCRIPT_CONTROLLER_RESPONSE);
View Full Code Here

Examples of org.apache.bsf.BSFEngine

  @Test
  public void testBSFEngineIntegration() throws Exception {
    Context context = new MicroContext();


    BSFEngine engine = micro.getSite().getBSFEngine("beanshell",
        (MicroContext) context.with("unu", 1),
        Collections.singletonMap("foo", "bar"));

    engine.exec("complexCalculus", 0, 0,
        "context.with(\"one\", context.get(\"unu\") * 1);" +
            "log.info(\"One is: \" + context.get(\"one\"));"); // :P
    Assert.assertEquals("BSFEngine failure", 1, context.get("one"));
  }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

            log.debug("invoking script service");

            outMC.setEnvelope(getSOAPFactory(inMC).getDefaultEnvelope());

            BSFEngine engine = getBSFEngine(inMC);
            OMElementConvertor convertor = (OMElementConvertor) inMC.getServiceContext().getProperty(CONVERTOR_PROP);

            Parameter scriptFunctionParam = inMC.getAxisService().getParameter(FUNCTION_ATTR);
            String scriptFunction = scriptFunctionParam == null ? DEFAULT_FUNCTION : (String) scriptFunctionParam.getValue();

            ScriptMessageContext inScriptMC = new ScriptMessageContext(inMC, convertor);
            ScriptMessageContext outScriptMC = new ScriptMessageContext(outMC, convertor);
            Object[] args = new Object[] { inScriptMC, outScriptMC };

            engine.call(null, scriptFunction, args);

        } catch (BSFException e) {
            throw AxisFault.makeFault(e);
        }
    }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

     *
     * The first service invocation creates the BSFEngine and caches
     * it in the Axis2 ServiceContext for reuse by subsequent requests.
     */
    protected BSFEngine getBSFEngine(MessageContext mc) throws AxisFault {
        BSFEngine bsfEngine;
        ServiceContext serviceContext = mc.getServiceContext();
        synchronized (serviceContext) {
            bsfEngine = (BSFEngine) serviceContext.getProperty(BSFENGINE_PROP);
            if (bsfEngine == null) {
                bsfEngine = initScript(mc);
View Full Code Here

Examples of org.apache.bsf.BSFEngine

            String scriptLanguage = BSFManager.getLangFromFilename(scriptName);
            BSFManager bsfManager = new BSFManager();
            bsfManager.setClassLoader(BSFManager.class.getClassLoader());
            bsfManager.declareBean("_AxisService", axisService, AxisService.class);

            BSFEngine bsfEngine = bsfManager.loadScriptingEngine(scriptLanguage);
            bsfEngine.exec(scriptName, 0, 0, scriptSrc);

            ServiceContext serviceContext = mc.getServiceContext();
            serviceContext.setProperty(BSFENGINE_PROP, bsfEngine);

            OMElementConvertor convertor = ConvertorFactory.createOMElementConvertor(axisService, scriptName);
View Full Code Here

Examples of org.apache.bsf.BSFEngine

public class BSF implements Script {
    public Object run(String language, String name, String scriptStr, String methodName, Object[] argValues)
            throws Exception {
        BSFManager manager = new BSFManager();
        BSFEngine engine = manager.loadScriptingEngine(language);

        manager.exec(language, "service script for '" +
                name + "'", 0, 0, scriptStr);

        Object result = engine.call(null, methodName, argValues);
        return result;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.