Package org.apache.jmeter.util

Examples of org.apache.jmeter.util.BeanShellInterpreter


    protected String getInitFileProperty() {
        return INIT_FILE;
    }

    public void sampleOccurred(SampleEvent se) {
        final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
        if (bshInterpreter == null) {
            log.error("BeanShell not found");
            return;
        }

        SampleResult samp=se.getResult();
        try {
            bshInterpreter.set("sampleEvent", se);//$NON-NLS-1$
            bshInterpreter.set("sampleResult", samp);//$NON-NLS-1$
            processFileOrScript(bshInterpreter);
        } catch (JMeterException e) {
            log.warn("Problem in BeanShell script "+e);
        }
    }
View Full Code Here


        checkParameterCount(parameters, 1, 2);

        values = parameters.toArray();

        try {
            bshInterpreter = new BeanShellInterpreter(JMeterUtils.getProperty(INIT_FILE), log);
        } catch (ClassNotFoundException e) {
            throw new InvalidVariableException("BeanShell not found");
        }
    }
View Full Code Here

        // Should we run a beanshell script on startup?
        String bshinit = JMeterUtils.getProperty("beanshell.init.file");// $NON-NLS-1$
        if (bshinit != null){
            log.info("Run Beanshell on file: "+bshinit);
            try {
                BeanShellInterpreter bsi = new BeanShellInterpreter();//bshinit,log);
                bsi.source(bshinit);
            } catch (ClassNotFoundException e) {
                log.warn("Could not start Beanshell: "+e.getLocalizedMessage());
            } catch (JMeterException e) {
                log.warn("Could not process Beanshell file: "+e.getLocalizedMessage());
            }
View Full Code Here

        SampleResult prev = jmctx.getPreviousResult();
        if (prev == null) {
            return; // TODO - should we skip processing here?
        }
        final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
        if (bshInterpreter == null) {
            log.error("BeanShell not found");
            return;
        }

        try {
            // Add variables for access to context and variables
            bshInterpreter.set("data", prev.getResponseData());//$NON-NLS-1$
            processFileOrScript(bshInterpreter);
        } catch (JMeterException e) {
            log.warn("Problem in BeanShell script "+e);
        }
    }
View Full Code Here

     */
    @Override
    public AssertionResult getResult(SampleResult response) {
        AssertionResult result = new AssertionResult(getName());

        final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
        if (bshInterpreter == null) {
            result.setFailure(true);
            result.setError(true);
            result.setFailureMessage("BeanShell Interpreter not found");
            return result;
        }
        try {

            // Add SamplerData for consistency with BeanShell Sampler
            bshInterpreter.set("SampleResult", response); //$NON-NLS-1$
            bshInterpreter.set("Response", response); //$NON-NLS-1$
            bshInterpreter.set("ResponseData", response.getResponseData());//$NON-NLS-1$
            bshInterpreter.set("ResponseCode", response.getResponseCode());//$NON-NLS-1$
            bshInterpreter.set("ResponseMessage", response.getResponseMessage());//$NON-NLS-1$
            bshInterpreter.set("ResponseHeaders", response.getResponseHeaders());//$NON-NLS-1$
            bshInterpreter.set("RequestHeaders", response.getRequestHeaders());//$NON-NLS-1$
            bshInterpreter.set("SampleLabel", response.getSampleLabel());//$NON-NLS-1$
            bshInterpreter.set("SamplerData", response.getSamplerData());//$NON-NLS-1$
            bshInterpreter.set("Successful", response.isSuccessful());//$NON-NLS-1$

            // The following are used to set the Result details on return from
            // the script:
            bshInterpreter.set("FailureMessage", "");//$NON-NLS-1$ //$NON-NLS-2$
            bshInterpreter.set("Failure", false);//$NON-NLS-1$

            processFileOrScript(bshInterpreter);

            result.setFailureMessage(bshInterpreter.get("FailureMessage").toString());//$NON-NLS-1$
            result.setFailure(Boolean.parseBoolean(bshInterpreter.get("Failure") //$NON-NLS-1$
                    .toString()));
            result.setError(false);
        }
        /*
         * To avoid class loading problems when the BSH jar is missing, we don't
View Full Code Here

        // log.info(getLabel()+" "+getFilename());
        SampleResult res = new SampleResult();
        boolean isSuccessful = false;
        res.setSampleLabel(getName());
        res.sampleStart();
        final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
        if (bshInterpreter == null) {
            res.sampleEnd();
            res.setResponseCode("503");//$NON-NLS-1$
            res.setResponseMessage("BeanShell Interpreter not found");
            res.setSuccessful(false);
            return res;
        }
        try {
            String request = getScript();
            String fileName = getFilename();
            if (fileName.length() == 0) {
                res.setSamplerData(request);
            } else {
                res.setSamplerData(fileName);
            }

            bshInterpreter.set("SampleResult", res); //$NON-NLS-1$

            // Set default values
            bshInterpreter.set("ResponseCode", "200"); //$NON-NLS-1$
            bshInterpreter.set("ResponseMessage", "OK");//$NON-NLS-1$
            bshInterpreter.set("IsSuccess", true);//$NON-NLS-1$

            res.setDataType(SampleResult.TEXT); // assume text output - script can override if necessary

            savedBsh = bshInterpreter;
            Object bshOut = processFileOrScript(bshInterpreter);
            savedBsh = null;

            if (bshOut != null) {// Set response data
                String out = bshOut.toString();
                res.setResponseData(out, null);
            }
            // script can also use setResponseData() so long as it returns null

            res.setResponseCode(bshInterpreter.get("ResponseCode").toString());//$NON-NLS-1$
            res.setResponseMessage(bshInterpreter.get("ResponseMessage").toString());//$NON-NLS-1$
            isSuccessful = Boolean.valueOf(bshInterpreter.get("IsSuccess") //$NON-NLS-1$
                    .toString()).booleanValue();
        }
        /*
         * To avoid class loading problems when bsh,jar is missing, we don't try
         * to catch this error separately catch (bsh.EvalError ex) {
View Full Code Here

        return INIT_FILE;
    }

    @Override
    public void process(){
        final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
        if (bshInterpreter == null) {
            log.error("BeanShell not found");
            return;
        }
        JMeterContext jmctx = JMeterContextService.getContext();
        Sampler sam = jmctx.getCurrentSampler();
        try {
            // Add variables for access to context and variables
            bshInterpreter.set("sampler", sam);//$NON-NLS-1$
            processFileOrScript(bshInterpreter);
        } catch (JMeterException e) {
            log.warn("Problem in BeanShell script "+e);
        }
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public long delay() {
        String ret="0";
        final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
        if (bshInterpreter == null) {
            log.error("BeanShell not found");
            return 0;
        }
        try {
View Full Code Here

    // log.info(getLabel()+" "+getFilename());
    SampleResult res = new SampleResult();
    boolean isSuccessful = false;
    res.setSampleLabel(getLabel());
    res.sampleStart();
    final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
    if (bshInterpreter == null) {
      res.sampleEnd();
      res.setResponseCode("503");//$NON-NLS-1$
      res.setResponseMessage("BeanShell Interpreter not found");
      res.setSuccessful(false);
      return res;
    }
    try {
      String request = getScript();
      String fileName = getFilename();
      if (fileName.length() == 0) {
        res.setSamplerData(request);
      } else {
        res.setSamplerData(fileName);
      }

      bshInterpreter.set("Label", getLabel()); //$NON-NLS-1$
      bshInterpreter.set("FileName", getFilename()); //$NON-NLS-1$
      bshInterpreter.set("SampleResult", res); //$NON-NLS-1$
     
      // Save parameters as single line and as string array
      bshInterpreter.set("Parameters", getParameters());//$NON-NLS-1$
      bshInterpreter.set("bsh.args", //$NON-NLS-1$
          JOrphanUtils.split(getParameters(), " "));//$NON-NLS-1$

      // Set default values
      bshInterpreter.set("ResponseCode", "200"); //$NON-NLS-1$
      bshInterpreter.set("ResponseMessage", "OK");//$NON-NLS-1$
      bshInterpreter.set("IsSuccess", true);//$NON-NLS-1$

      // Add variables for access to context and variables
      JMeterContext jmctx = JMeterContextService.getContext();
      JMeterVariables vars = jmctx.getVariables();
      bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$
      bshInterpreter.set("vars", vars);//$NON-NLS-1$

            res.setDataType(SampleResult.TEXT); // assume text output - script can override if necessary

            Object bshOut;

      if (fileName.length() == 0) {
        bshOut = bshInterpreter.eval(request);
      } else {
        bshOut = bshInterpreter.source(fileName);
      }

      if (bshOut != null) {// Set response data
                String out = bshOut.toString();
                res.setResponseData(out.getBytes());
      }
            // script can also use setResponseData() so long as it returns null
           
      res.setResponseCode(bshInterpreter.get("ResponseCode").toString());//$NON-NLS-1$
      res.setResponseMessage(bshInterpreter.get("ResponseMessage").toString());//$NON-NLS-1$
      isSuccessful = Boolean.valueOf(bshInterpreter.get("IsSuccess") //$NON-NLS-1$
          .toString()).booleanValue();
    }
    /*
     * To avoid class loading problems when bsh,jar is missing, we don't try
     * to catch this error separately catch (bsh.EvalError ex) {
View Full Code Here

    checkParameterCount(parameters, 1, 2);

    values = parameters.toArray();

    try {
      bshInterpreter = new BeanShellInterpreter(JMeterUtils.getProperty(INIT_FILE), log);
    } catch (ClassNotFoundException e) {
      throw new InvalidVariableException("BeanShell not found");
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.jmeter.util.BeanShellInterpreter

Copyright © 2018 www.massapicom. 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.