Examples of BSFEngine


Examples of org.apache.bsf.BSFEngine

      String [] bshExtensions = { "bsh" };
      String bshEngine = "bsh.util.BeanShellBSFEngine";
      BSFManager.registerScriptingEngine("beanshell", bshEngine, bshExtensions);

      // 2. Load Scripting Engine
      @SuppressWarnings("unused")    //for completeness
      BSFEngine engine = bsfMgr_.loadScriptingEngine("beanshell");

      // 3. Map application objects
      bsfMgr_.declareBean("ScriptAPI", scriptAPI_, ScriptAPI.class);
      //legacy
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        final String fileName = getFilename();
    log.debug(label + " " + fileName);
    SampleResult res = new SampleResult();
    res.setSampleLabel(label);
    FileInputStream is = null;
    BSFEngine bsfEngine = null;
    // There's little point saving the manager between invocations
    // as we need to reset most of the beans anyway
        BSFManager mgr = new BSFManager();

        // TODO: find out how to retrieve these from the script
        // At present the script has to use SampleResult methods to set them.
        res.setResponseCode("200"); // $NON-NLS-1$
        res.setResponseMessage("OK"); // $NON-NLS-1$
        res.setSuccessful(true);
        res.setDataType(SampleResult.TEXT); // Default (can be overridden by the script)

        res.sampleStart();
    try {
      initManager(mgr);
      mgr.declareBean("SampleResult", res, res.getClass()); // $NON-NLS-1$
     
      // These are not useful yet, as have not found how to get updated values back
      //mgr.declareBean("ResponseCode", "200", String.class); // $NON-NLS-1$
      //mgr.declareBean("ResponseMessage", "OK", String.class); // $NON-NLS-1$
      //mgr.declareBean("IsSuccess", Boolean.TRUE, Boolean.class); // $NON-NLS-1$

      // N.B. some engines (e.g. Javascript) cannot handle certain declareBean() calls
      // after the engine has been initialised, so create the engine last
      bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());

      Object bsfOut = null;
      if (fileName.length()>0) {
        res.setSamplerData("File: "+fileName);
        is = new FileInputStream(fileName);
        bsfOut = bsfEngine.eval(fileName, 0, 0, IOUtils.toString(is));
      } else {
        res.setSamplerData(request);
          bsfOut = bsfEngine.eval("script", 0, 0, request);
      }

      if (bsfOut != null) {
          res.setResponseData(bsfOut.toString().getBytes());
      }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        // For use in debugging:
        mgr.declareBean("OUT", System.out, PrintStream.class);
    }

    protected void processFileOrScript(BSFManager mgr) throws BSFException{
        BSFEngine bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());
    final String scriptFile = getFilename();
        if (scriptFile.length() == 0) {
      bsfEngine.exec("[script]",0,0,getScript());
    }
    bsfEngine.exec(scriptFile,0,0,scriptFile);
    }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        // create 'out' object
        ByteArrayOutputStream bbuf = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(bbuf);

        try {
            BSFEngine bsfEngine = bsfManager.loadScriptingEngine(scriptingEngine);

            bsfManager.getObjectRegistry().register("out", out);
            bsfEngine.exec("", 0, 0, template);

        }
        catch (BSFException e) {
            throw new XDocletException(e, "Exception when running scriptengine='" + scriptingEngine + "'");
        }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        final String fileName = getFilename();
        log.debug(label + " " + fileName);
        SampleResult res = new SampleResult();
        res.setSampleLabel(label);
        InputStream is = null;
        BSFEngine bsfEngine = null;
        // There's little point saving the manager between invocations
        // as we need to reset most of the beans anyway
        BSFManager mgr = new BSFManager();

        // TODO: find out how to retrieve these from the script
        // At present the script has to use SampleResult methods to set them.
        res.setResponseCode("200"); // $NON-NLS-1$
        res.setResponseMessage("OK"); // $NON-NLS-1$
        res.setSuccessful(true);
        res.setDataType(SampleResult.TEXT); // Default (can be overridden by the script)

        res.sampleStart();
        try {
            initManager(mgr);
            mgr.declareBean("SampleResult", res, res.getClass()); // $NON-NLS-1$

            // These are not useful yet, as have not found how to get updated values back
            //mgr.declareBean("ResponseCode", "200", String.class); // $NON-NLS-1$
            //mgr.declareBean("ResponseMessage", "OK", String.class); // $NON-NLS-1$
            //mgr.declareBean("IsSuccess", Boolean.TRUE, Boolean.class); // $NON-NLS-1$

            // N.B. some engines (e.g. Javascript) cannot handle certain declareBean() calls
            // after the engine has been initialised, so create the engine last
            bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());

            Object bsfOut = null;
            if (fileName.length()>0) {
                res.setSamplerData("File: "+fileName);
                is = new BufferedInputStream(new FileInputStream(fileName));
                bsfOut = bsfEngine.eval(fileName, 0, 0, IOUtils.toString(is));
            } else {
                res.setSamplerData(request);
                bsfOut = bsfEngine.eval("script", 0, 0, request);
            }

            if (bsfOut != null) {
                res.setResponseData(bsfOut.toString(), null);
            }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        final String fileName = getFilename();
        log.debug(label + " " + fileName);
        SampleResult res = new SampleResult();
        res.setSampleLabel(label);
        FileInputStream is = null;
        BSFEngine bsfEngine = null;
        // There's little point saving the manager between invocations
        // as we need to reset most of the beans anyway
        BSFManager mgr = new BSFManager();

        // TODO: find out how to retrieve these from the script
        // At present the script has to use SampleResult methods to set them.
        res.setResponseCode("200"); // $NON-NLS-1$
        res.setResponseMessage("OK"); // $NON-NLS-1$
        res.setSuccessful(true);
        res.setDataType(SampleResult.TEXT); // Default (can be overridden by the script)

        res.sampleStart();
        try {
            initManager(mgr);
            mgr.declareBean("SampleResult", res, res.getClass()); // $NON-NLS-1$

            // These are not useful yet, as have not found how to get updated values back
            //mgr.declareBean("ResponseCode", "200", String.class); // $NON-NLS-1$
            //mgr.declareBean("ResponseMessage", "OK", String.class); // $NON-NLS-1$
            //mgr.declareBean("IsSuccess", Boolean.TRUE, Boolean.class); // $NON-NLS-1$

            // N.B. some engines (e.g. Javascript) cannot handle certain declareBean() calls
            // after the engine has been initialised, so create the engine last
            bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());

            Object bsfOut = null;
            if (fileName.length()>0) {
                res.setSamplerData("File: "+fileName);
                is = new FileInputStream(fileName);
                bsfOut = bsfEngine.eval(fileName, 0, 0, IOUtils.toString(is));
            } else {
                res.setSamplerData(request);
                bsfOut = bsfEngine.eval("script", 0, 0, request);
            }

            if (bsfOut != null) {
                res.setResponseData(bsfOut.toString(), null);
            }
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

            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
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.