com.gargoylesoftware.htmlunit.util.WebConnectionWrapper类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中com.gargoylesoftware.htmlunit.util.WebConnectionWrapper类的一些代码示例,展示了WebConnectionWrapper类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebConnectionWrapper类的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.util.WebConnectionWrapper
类名称:WebConnectionWrapper

WebConnectionWrapper介绍

[英]Provides a convenient implementation of the WebConnection interface that can be subclassed by developers wishing to adapt a particular WebConnection.

This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped web connection object.
[中]提供WebConnection接口的便捷实现,希望调整特定WebConnection的开发人员可以对其进行子类化。
此类实现了包装器或装饰器模式。方法默认为通过包装的web连接对象调用。

代码示例

代码示例来源:origin: org.apache.camel/camel-linkedin-api

@Override
  public WebResponse getResponse(WebRequest request) throws IOException {
    request.setAdditionalHeader(HttpHeaders.ACCEPT_ENCODING, "identity");
    return super.getResponse(request);
  }
};

代码示例来源:origin: javaserverfaces/mojarra

@Override
public WebResponse getResponse(WebRequest request) throws IOException {
  if (urlFragmentToMonitor == null || request.getUrl().toString().contains(urlFragmentToMonitor)) {
    rawRequestBody = request.getRequestBody();
    WebResponse response = super.getResponse(request);
    rawResponse = response.getContentAsString();
    
    return response;
  }
  return super.getResponse(request);
}

代码示例来源:origin: openaudible/openaudible

public WebResponse getResponse(WebRequest request) throws IOException {
    WebResponse response = super.getResponse(request);
    String u = request.getUrl().toExternalForm();
    if (u.contains(".js")) {
      System.err.println(u);
      
      
      String content = response.getContentAsString("UTF-8");
      if (content.contains("append: function")) {
        System.err.println(content);
        
      }
      //change content
      
      WebResponseData data = new WebResponseData(content.getBytes("UTF-8"),
          response.getStatusCode(), response.getStatusMessage(), response.getResponseHeaders());
      response = new WebResponse(data, request, response.getLoadTime());
    }
    return response;
  }
};

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

/**
 * Delivers the content for an alternate URL as if it comes from the requested URL.
 * @param webRequest the original web request
 * @param url the URL from which the content should be retrieved
 * @return the response
 * @throws IOException if a problem occurred
 */
protected WebResponse deliverFromAlternateUrl(final WebRequest webRequest, final URL url)
  throws IOException {
  final URL originalUrl = webRequest.getUrl();
  webRequest.setUrl(url);
  final WebResponse resp = super.getResponse(webRequest);
  resp.getWebRequest().setUrl(originalUrl);
  return resp;
}

代码示例来源:origin: net.disy.htmlunit/htmlunit

/**
 * Delivers the content for an alternate URL as if it comes from the requested URL.
 * @param webRequestSettings the original web request settings
 * @param url the URL from which the content should be retrieved
 * @return the response
 * @throws IOException if a problem occurred
 */
protected WebResponse deliverFromAlternateUrl(final WebRequestSettings webRequestSettings, final URL url)
  throws IOException {
  final URL originalUrl = webRequestSettings.getUrl();
  webRequestSettings.setUrl(url);
  final WebResponse resp = super.getResponse(webRequestSettings);
  resp.getRequestSettings().setUrl(originalUrl);
  return resp;
}

代码示例来源:origin: org.jvnet.hudson/htmlunit

/**
 * Delivers the content for an alternate URL as if it comes from the requested URL.
 * @param webRequestSettings the original web request settings
 * @param url the URL from which the content should be retrieved
 * @return the response
 * @throws IOException if a problem occurred
 */
protected WebResponse deliverFromAlternateUrl(final WebRequestSettings webRequestSettings, final URL url)
  throws IOException {
  final URL originalUrl = webRequestSettings.getUrl();
  webRequestSettings.setUrl(url);
  final WebResponse resp = super.getResponse(webRequestSettings);
  resp.getRequestSettings().setUrl(originalUrl);
  return resp;
}

代码示例来源:origin: org.jenkins-ci/htmlunit

/**
 * Delivers the content for an alternate URL as if it comes from the requested URL.
 * @param webRequestSettings the original web request settings
 * @param url the URL from which the content should be retrieved
 * @return the response
 * @throws IOException if a problem occurred
 */
protected WebResponse deliverFromAlternateUrl(final WebRequestSettings webRequestSettings, final URL url)
  throws IOException {
  final URL originalUrl = webRequestSettings.getUrl();
  webRequestSettings.setUrl(url);
  final WebResponse resp = super.getResponse(webRequestSettings);
  resp.getRequestSettings().setUrl(originalUrl);
  return resp;
}

代码示例来源:origin: HtmlUnit/htmlunit

/**
 * Delivers the content for an alternate URL as if it comes from the requested URL.
 * @param webRequest the original web request
 * @param url the URL from which the content should be retrieved
 * @return the response
 * @throws IOException if a problem occurred
 */
protected WebResponse deliverFromAlternateUrl(final WebRequest webRequest, final URL url)
  throws IOException {
  final URL originalUrl = webRequest.getUrl();
  webRequest.setUrl(url);
  final WebResponse resp = super.getResponse(webRequest);
  resp.getWebRequest().setUrl(originalUrl);
  return resp;
}

代码示例来源:origin: com.github.seykron/htmlunit-maven-plugin

@Override
 public WebResponse getResponse(final WebRequest request)
   throws IOException {
  String protocol = request.getUrl().getProtocol();
  // Default web response is retrieved using commons HttpClient.
  // It assumes HttpClient created internally by HtmlUnit is using the
  // default registry. We check for supported schemes by the default
  // registry.
  boolean canHandle = SchemeRegistryFactory.createDefault()
    .get(protocol) != null;
  if (!canHandle) {
   // For unsupported schemes, it tries to read the response using
   // native URL connection.
   String data = ResourceUtils.readAsText(request.getUrl());
   return new StringWebResponse(data, request.getUrl());
  }
  return super.getResponse(request);
 }
};

代码示例来源:origin: com.axway.ats.framework/ats-uiengine

public WebResponse getResponse( WebRequest request ) throws IOException {
    Cookie jsCookie = webClient.getCookieManager().getCookie("JSESSIONID");
    if (jsCookie != null && (!jsCookie.getValue().startsWith("\"")
                 && !jsCookie.getValue().endsWith("\""))) {
      Cookie newCookie = new Cookie(jsCookie.getDomain(), jsCookie.getName(),
                     "\"" + jsCookie.getValue() + "\"", jsCookie.getPath(),
                     jsCookie.getExpires(), jsCookie.isSecure());
      webClient.getCookieManager().removeCookie(jsCookie);
      webClient.getCookieManager().addCookie(newCookie);
    }
    return super.getResponse(request);
  }
};

相关文章

微信公众号

最新文章

更多

WebConnectionWrapper类方法