Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebResponse


    }

    final String savePrefix = getSavePrefix();
    final File file;

    final WebResponse resp;
    // new current response
    if (isNewResponse(event))
    {
      if (isExceptionWithResponse(event))
      {
        final Throwable cause = event.getException().getCause();
        if (cause instanceof FailingHttpStatusCodeException)
        {
          resp = ((FailingHttpStatusCodeException) cause).getResponse();
        }
        else
        {
          resp = ((ScriptException) cause).getPage().getWebResponse();
        }
      }
      else
      {
        resp = fContext.getCurrentResponse().getWebResponse();
        if (fContext.getCurrentResponse() instanceof HtmlPage) {
          final HtmlPage page = (HtmlPage) fContext.getCurrentResponse();
          page.addDomChangeListener(domChangeListener);
        }
      }
     
      file = getResponseFile(resp, savePrefix, fCurrentResult.getTaskName());
      ContextHelper.writeResponseFile(resp, file);
    }
    else if (domChangedInLastPage && fContext.getCurrentResponse() instanceof HtmlPage)
    {
      final HtmlPage page = (HtmlPage) fContext.getCurrentResponse();
      resp = page.getWebResponse();
      file = getResponseFile("html", savePrefix, fCurrentResult.getTaskName());
      writeStringToFile(file, page.asXml());
    }
    else
    {
      // nothing to dump
      return;
    }

    final File infoFile = new File(file.getParentFile(), file.getName() + ".info");
    LOG.debug("Writing additional info to " + infoFile);
    final String data = "url=" + resp.getRequestUrl();
    writeStringToFile(infoFile, data);

    fCurrentResult.getAttributes().put("resultFilename", file.getName());
    domChangedInLastPage = false;
  }
View Full Code Here


    public String getRemove() {
        return fRemove;
    }

    public void doExecute() throws Exception {
        final WebResponse webResponse = getContext().getCurrentResponse().getWebResponse();
        final String orig = webResponse.getContentAsString();
        final String origType = webResponse.getContentType();
        final boolean remove = ConversionUtil.convertToBoolean(getRemove(), false);
        final String lineStr = "(^.*$)";
        final Pattern linePattern = Pattern.compile(lineStr, Pattern.MULTILINE);
        final Matcher matcher = linePattern.matcher(orig);
        final StringBuffer buf = new StringBuffer();
View Full Code Here

          + ")");
    }

    public void webWindowContentChanged(final WebWindowEvent event) {
      final WebWindow window = event.getWebWindow();
      final WebResponse webResp = event.getNewPage().getWebResponse();
            LOG.info("Content of window changed to " + webResp.getRequestUrl() + " (" + webResp.getContentType() + ")");

      final boolean takeItAsNew;
      if (window instanceof TopLevelWindow && event.getOldPage() == null) {
        takeItAsNew = true;
        LOG.info("Content loaded in newly opened window, its content will become current response");
View Full Code Here

    public void setProperty(final String name) {
        super.setProperty(name);
    }

    public void doExecute() {
        final WebResponse response = getContext().getCurrentResponse().getWebResponse();
        storeProperty(Integer.toString(response.getStatusCode()));
    }
View Full Code Here

    public String getReplacement() {
        return fReplacement;
    }

    public void doExecute() throws Exception {
        final WebResponse response = getContext().getCurrentResponse().getWebResponse();
        final String orig = response.getContentAsString();
        final String origType = response.getContentType();
        final String resultStr = orig.replaceAll(getRegex(), getReplacement() == null ? "[REMOVED]" : getReplacement());
        defineAsCurrentResponse(resultStr, origType);
    }
View Full Code Here

        paramCheck(getStartRegex() == null && getStopRegex() == null, "One of 'startRegex' or 'stopRegex' must be set!");
        nullResponseCheck();
    }

    public void doExecute() throws Exception {
        final WebResponse webResponse = getContext().getCurrentResponse().getWebResponse();
        final String orig = webResponse.getContentAsString();
        final String origType = webResponse.getContentType();
        final boolean remove = ConversionUtil.convertToBoolean(getRemove(), false);
        final boolean repeat = ConversionUtil.convertToBoolean(getRepeat(), false);
        final boolean includeStart = ConversionUtil.convertToBoolean(getIncludeStart(), true);
        final boolean includeStop = ConversionUtil.convertToBoolean(getIncludeStop(), true);
        final Matcher matcher = LINE_PATTERN.matcher(orig);
View Full Code Here

            {
              visit((HtmlPage) page, depth - 1);
            }
            else
            {
              final WebResponse response = page.getWebResponse();
              LOG.info("Don't going deeper in response for " + response.getRequestUrl()
                  + " as it isn't an html page (content type: "
                  + response.getContentType() + ", page" + page + ")");
            }
        }
        catch (final StepFailedException e) {
            LOG.error(e.getMessage(), e);
            if (fFailOnError) {
View Full Code Here

    public String getName() {
        return fHeaderName;
    }

    public void doExecute() {
        final WebResponse response = getContext().getCurrentResponse().getWebResponse();
        final String headerValue = response.getResponseHeaderValue(fHeaderName);

        if (headerValue == null) {
            throw new StepFailedException("Header \"" + fHeaderName + "\" not set!", this);
        }
        storeProperty(headerValue, getName());
View Full Code Here

public class LineSeparatorFilter extends AbstractFilter
{
    private static final String LF = "\n";

    public void doExecute() throws Exception {
        final WebResponse webResponse = getContext().getCurrentResponse().getWebResponse();
        final String content = webResponse.getContentAsString();
        final String origType = webResponse.getContentType();
        final String sep = System.getProperty("line.separator");
        final int sepSize = sep.length();
        final StringBuffer buf = new StringBuffer();
        int last = 0;
        int pos = content.indexOf(sep, last);
View Full Code Here

            final Step step = (Step) iter.next();
            executeContainedStep(step);
    }
        final WebClientContext.StoredResponses srcResponses = context.getResponses();
        final Page actualPage = context.getCurrentResponse();
        final WebResponse actualResponse = actualPage.getWebResponse();

        LOG.debug("Processig reference file: " + getReferenceFile());
      WebClientContext.StoredResponses referenceResponses = preProcessFiles(getReferenceFile(), context);
      if (isReadFiltered()) {
            LOG.debug("Applying filter on reference file too");
            context.restoreResponses(referenceResponses);
            for (final Iterator iter = steps.iterator(); iter.hasNext();) {
                final Step step = (Step) iter.next();
                step.execute();
        }
            referenceResponses = context.getResponses();
          context.restoreResponses(srcResponses);
      }

        LOG.debug("Source: " + actualResponse.getContentType() + " (" + actualResponse.getRequestUrl() + ")");
        context.restoreResponses(referenceResponses);
        final Page referencePage = context.getCurrentResponse();
        final WebResponse referenceResponse = referencePage.getWebResponse();
        LOG.debug("Reference: " + referenceResponse.getContentType() + " (" + referenceResponse.getRequestUrl() + ")");

        return produceDiffMessage(actualPage, referencePage);
    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.WebResponse

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.