Examples of BSFEngine


Examples of com.dotcms.repackage.org.apache.bsf.BSFEngine

   * @throws DotSecurityException
   * @throws IOException
   * @throws NoSuchUserException
   */
  public Object callMethod(String language, String filePath, Host host, String methodName, Object[] args) throws BSFException, NoSuchUserException, IOException, DotSecurityException, DotDataException{
    BSFEngine engine = manager.get().loadScriptingEngine(language);
    String source = readFile(filePath, host);
    return engine.call(source, methodName, args);
  }
View Full Code Here

Examples of com.dotcms.repackage.org.apache.bsf.BSFEngine

   * @throws DotSecurityException
   * @throws IOException
   * @throws NoSuchUserException
   */
  public Object callMethod(String language, Object o, Host host, String methodName, Object[] args) throws BSFException, NoSuchUserException, IOException, DotSecurityException, DotDataException{
    BSFEngine engine = manager.get().loadScriptingEngine(language);
    return engine.call(o, methodName, args);
  }
View Full Code Here

Examples of com.ibm.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

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

    }

    public boolean mediate(MessageContext synCtx) {
        try {

            BSFEngine engine = getBSFEngine(synCtx.getConfiguration());

            Object[] args = new Object[] { new ScriptMessageContext(synCtx, convertor) };

            Object response = engine.call(null, functionName, args);
            if (response instanceof Boolean) {
                return ((Boolean) response).booleanValue();
            }

            return true; // default to returning true
View Full Code Here

Examples of org.apache.bsf.BSFEngine

    protected BSFEngine createBSFEngine(String scriptName, String scriptSrc) {
        try {

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

            return bsfEngine;

        } catch (BSFException e) {
            throw new SynapseException(e.getTargetException());
View Full Code Here

Examples of org.apache.bsf.BSFEngine

        SampleResult prev = jmctx.getPreviousResult();
        mgr.declareBean("prev", prev, SampleResult.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());
        } else {// we have a file, read and process it
            try {
                String script=FileUtils.readFileToString(new File(scriptFile));
                bsfEngine.exec(scriptFile,0,0,script);
            } catch (IOException e) {
                log.warn(e.getLocalizedMessage());
                throw new BSFException(BSFException.REASON_IO_ERROR,"Problem reading script file",e);
            }
        }
View Full Code Here

Examples of org.apache.bsf.BSFEngine

            }
        }
    }

    protected Object evalFileOrScript(BSFManager mgr) throws BSFException{
        BSFEngine bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());
        final String scriptFile = getFilename();
        if (scriptFile.length() == 0) {
            return bsfEngine.eval("[script]",0,0,getScript());
        } else {// we have a file, read and process it
            try {
                String script=FileUtils.readFileToString(new File(scriptFile));
                return bsfEngine.eval(scriptFile,0,0,script);
            } catch (IOException e) {
                log.warn(e.getLocalizedMessage());
                throw new BSFException(BSFException.REASON_IO_ERROR,"Problem reading script file",e);
            }
        }
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
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.