Beispiel #1
0
 private String getInputString(SampleResult result) {
   String inputString =
       useUrl()
           ? result.getUrlAsString() // Bug 39707
           : useHeaders()
               ? result.getResponseHeaders()
               : useRequestHeaders()
                   ? result.getRequestHeaders()
                   : useCode()
                       ? result.getResponseCode() // Bug 43451
                       : useMessage()
                           ? result.getResponseMessage() // Bug 43451
                           : useUnescapedBody()
                               ? StringEscapeUtils.unescapeHtml4(result.getResponseDataAsString())
                               : useBodyAsDocument()
                                   ? Document.getTextFromDocument(result.getResponseData())
                                   : result.getResponseDataAsString() // Bug 36898
       ;
   if (log.isDebugEnabled()) {
     log.debug("Input = " + inputString);
   }
   return inputString;
 }
Beispiel #2
0
  /** {@inheritDoc} */
  @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
     * try to catch this error separately catch (bsh.EvalError ex) {
     * log.debug("",ex); result.setError(true);
     * result.setFailureMessage(ex.toString()); }
     */
    // but we do trap this error to make tests work better
    catch (NoClassDefFoundError ex) {
      log.error("BeanShell Jar missing? " + ex.toString());
      result.setError(true);
      result.setFailureMessage("BeanShell Jar missing? " + ex.toString());
      response.setStopThread(true); // No point continuing
    } catch (Exception ex) // Mainly for bsh.EvalError
    {
      result.setError(true);
      result.setFailureMessage(ex.toString());
      log.warn(ex.toString());
    }

    return result;
  }