本文整理了Java中com.gargoylesoftware.htmlunit.WebClient.loadWebResponse()
方法的一些代码示例,展示了WebClient.loadWebResponse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebClient.loadWebResponse()
方法的具体详情如下:
包路径:com.gargoylesoftware.htmlunit.WebClient
类名称:WebClient
方法名:loadWebResponse
[英]Loads a WebResponse from the server.
[中]从服务器加载WebResponse。
代码示例来源:origin: timurstrekalov/saga
@Override
public WebResponse loadWebResponse(final WebRequest webRequest) throws IOException {
return new WebResponseProxy(super.loadWebResponse(webRequest));
}
};
代码示例来源:origin: jenkinsci/jenkins-test-harness
@Override
public WebResponse loadWebResponse(final WebRequest webRequest) throws IOException {
WebResponse webResponse = super.loadWebResponse(webRequest);
if (!webResponseListeners.isEmpty()) {
for (WebResponseListener listener : webResponseListeners) {
listener.onLoadWebResponse(webRequest, webResponse);
}
}
return webResponse;
}
代码示例来源:origin: org.apache.camel/camel-linkedin-api
private OAuthToken getAccessToken(String refreshToken) throws IOException {
final String tokenUrl = String.format(ACCESS_TOKEN_URL, refreshToken,
oAuthParams.getRedirectUri(), oAuthParams.getClientId(), oAuthParams.getClientSecret());
final WebRequest webRequest = new WebRequest(new URL(tokenUrl), HttpMethod.POST);
final WebResponse webResponse = webClient.loadWebResponse(webRequest);
if (webResponse.getStatusCode() != HttpStatus.SC_OK) {
throw new IOException(String.format("Error getting access token: [%s: %s]",
webResponse.getStatusCode(), webResponse.getStatusMessage()));
}
final long currentTime = System.currentTimeMillis();
final ObjectMapper mapper = new ObjectMapper();
final Map map = mapper.readValue(webResponse.getContentAsStream(), Map.class);
final String accessToken = map.get("access_token").toString();
final Integer expiresIn = Integer.valueOf(map.get("expires_in").toString());
return new OAuthToken(refreshToken, accessToken,
currentTime + TimeUnit.MILLISECONDS.convert(expiresIn, TimeUnit.SECONDS));
}
代码示例来源:origin: org.jenkins-ci/htmlunit
/**
* <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE RESOURCE - USE AT YOUR OWN RISK.</span><br/>
* If the linked content is not already downloaded it triggers a download. Then it stores the response
* for later use.<br/>
*
* @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously
* @return <code>null</code> if no download should be performed and when this wasn't already done; the response
* received when performing a request for the content referenced by this tag otherwise
* @throws IOException if an error occurs while downloading the content
*/
public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException {
if (downloadIfNeeded && cachedWebResponse_ == null) {
final WebClient webclient = getPage().getWebClient();
cachedWebResponse_ = webclient.loadWebResponse(getWebRequestSettings());
}
return cachedWebResponse_;
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE RESOURCE - USE AT YOUR OWN RISK.</span><br/>
* If the linked content is not already downloaded it triggers a download. Then it stores the response
* for later use.<br/>
*
* @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously
* @return <code>null</code> if no download should be performed and when this wasn't already done; the response
* received when performing a request for the content referenced by this tag otherwise
* @throws IOException if an error occurs while downloading the content
*/
public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException {
if (downloadIfNeeded && cachedWebResponse_ == null) {
final WebClient webclient = getPage().getWebClient();
cachedWebResponse_ = webclient.loadWebResponse(getWebRequestSettings());
}
return cachedWebResponse_;
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
/**
* <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE RESOURCE - USE AT YOUR OWN RISK.</span><br/>
* If the linked content is not already downloaded it triggers a download. Then it stores the response
* for later use.<br/>
*
* @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously
* @return <code>null</code> if no download should be performed and when this wasn't already done; the response
* received when performing a request for the content referenced by this tag otherwise
* @throws IOException if an error occurs while downloading the content
*/
public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException {
if (downloadIfNeeded && cachedWebResponse_ == null) {
final WebClient webclient = getPage().getWebClient();
cachedWebResponse_ = webclient.loadWebResponse(getWebRequestSettings());
}
return cachedWebResponse_;
}
代码示例来源:origin: HtmlUnit/htmlunit
/**
* Saves this content as the specified file.
* @param file the file to save to
* @throws IOException if an IO error occurs
*/
public void saveAs(final File file) throws IOException {
final HtmlPage page = (HtmlPage) getPage();
final WebClient webclient = page.getWebClient();
final URL url = page.getFullyQualifiedUrl(getAttributeDirect(SRC_ATTRIBUTE));
final WebRequest request = new WebRequest(url);
request.setCharset(page.getCharset());
request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm());
final WebResponse webResponse = webclient.loadWebResponse(request);
try (OutputStream fos = Files.newOutputStream(file.toPath());
InputStream content = webResponse.getContentAsStream()) {
IOUtils.copy(content, fos);
}
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* Saves this content as the specified file.
* @param file the file to save to
* @throws IOException if an IO error occurs
*/
public void saveAs(final File file) throws IOException {
final HtmlPage page = (HtmlPage) getPage();
final WebClient webclient = page.getWebClient();
final URL url = page.getFullyQualifiedUrl(getAttributeDirect("src"));
final WebRequest request = new WebRequest(url);
request.setCharset(page.getCharset());
request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm());
final WebResponse webResponse = webclient.loadWebResponse(request);
try (FileOutputStream fos = new FileOutputStream(file);
InputStream content = webResponse.getContentAsStream()) {
IOUtils.copy(content, fos);
}
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* Loads an XML document from the specified location.
*
* @param xmlSource a string containing a URL that specifies the location of the XML file
* @return true if the load succeeded; false if the load failed
*/
@JsxFunction(FF)
public boolean load(final String xmlSource) {
if (async_) {
if (LOG.isDebugEnabled()) {
LOG.debug("XMLDocument.load(): 'async' is true, currently treated as false.");
}
}
try {
final WebWindow ww = getWindow().getWebWindow();
final HtmlPage htmlPage = (HtmlPage) ww.getEnclosedPage();
final WebRequest request = new WebRequest(htmlPage.getFullyQualifiedUrl(xmlSource));
final WebResponse webResponse = ww.getWebClient().loadWebResponse(request);
final XmlPage page = new XmlPage(webResponse, ww, false);
setDomNode(page);
return true;
}
catch (final IOException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Error parsing XML from '" + xmlSource + "'", e);
}
return false;
}
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* Performs the download and calls the callback method.
*/
@Override
public void run() {
final Scriptable scope = callback_.getParentScope();
final WebRequest request = new WebRequest(url_);
try {
final WebResponse webResponse = client_.loadWebResponse(request);
final String content = webResponse.getContentAsString();
if (LOG.isDebugEnabled()) {
LOG.debug("Downloaded content: " + StringUtils.abbreviate(content, 512));
}
final Object[] args = new Object[] {content};
final ContextFactory cf = ((JavaScriptEngine) client_.getJavaScriptEngine()).getContextFactory();
cf.call(cx -> {
callback_.call(cx, scope, scope, args);
return null;
});
}
catch (final IOException e) {
LOG.error("Behavior #default#download: Cannot download " + url_, e);
}
}
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
/**
* Performs the download and calls the callback method.
*/
public void run() {
final WebClient client = getWindow().getWebWindow().getWebClient();
final Scriptable scope = callback_.getParentScope();
final WebRequestSettings settings = new WebRequestSettings(url_);
try {
final WebResponse webResponse = client.loadWebResponse(settings);
final String content = webResponse.getContentAsString();
LOG.debug("Downloaded content: " + StringUtils.abbreviate(content, 512));
final Object[] args = new Object[] {content};
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
callback_.call(cx, scope, scope, args);
return null;
}
};
final ContextFactory cf = client.getJavaScriptEngine().getContextFactory();
cf.call(action);
}
catch (final IOException e) {
LOG.error("Behavior #default#download: Cannot download " + url_, e);
}
}
}
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* Performs the download and calls the callback method.
*/
public void run() {
final WebClient client = getWindow().getWebWindow().getWebClient();
final Scriptable scope = callback_.getParentScope();
final WebRequestSettings settings = new WebRequestSettings(url_);
try {
final WebResponse webResponse = client.loadWebResponse(settings);
final String content = webResponse.getContentAsString();
LOG.debug("Downloaded content: " + StringUtils.abbreviate(content, 512));
final Object[] args = new Object[] {content};
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
callback_.call(cx, scope, scope, args);
return null;
}
};
final ContextFactory cf = client.getJavaScriptEngine().getContextFactory();
cf.call(action);
}
catch (final IOException e) {
LOG.error("Behavior #default#download: Cannot download " + url_, e);
}
}
}
代码示例来源:origin: org.jenkins-ci/htmlunit
/**
* Performs the download and calls the callback method.
*/
public void run() {
final WebClient client = getWindow().getWebWindow().getWebClient();
final Scriptable scope = callback_.getParentScope();
final WebRequestSettings settings = new WebRequestSettings(url_);
try {
final WebResponse webResponse = client.loadWebResponse(settings);
final String content = webResponse.getContentAsString();
LOG.debug("Downloaded content: " + StringUtils.abbreviate(content, 512));
final Object[] args = new Object[] {content};
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
callback_.call(cx, scope, scope, args);
return null;
}
};
final ContextFactory cf = client.getJavaScriptEngine().getContextFactory();
cf.call(action);
}
catch (final IOException e) {
LOG.error("Behavior #default#download: Cannot download " + url_, e);
}
}
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* <p>Downloads the image contained by this image element.</p>
* <p><span style="color:red">POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK</span></p>
* <p>If the image has not already been downloaded, this method triggers a download and caches the image.</p>
*
* @throws IOException if an error occurs while downloading the image
*/
private void downloadImageIfNeeded() throws IOException {
if (!downloaded_) {
// HTMLIMAGE_BLANK_SRC_AS_EMPTY
final String src = getSrcAttribute();
if (!"".equals(src)
&& !(hasFeature(HTMLIMAGE_BLANK_SRC_AS_EMPTY) && StringUtils.isBlank(src))) {
final HtmlPage page = (HtmlPage) getPage();
final WebClient webclient = page.getWebClient();
final URL url = page.getFullyQualifiedUrl(src);
final String accept = webclient.getBrowserVersion().getImgAcceptHeader();
final WebRequest request = new WebRequest(url, accept);
request.setCharset(page.getCharset());
request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm());
imageWebResponse_ = webclient.loadWebResponse(request);
}
if (imageData_ != null) {
imageData_.close();
imageData_ = null;
}
downloaded_ = hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST)
|| (imageWebResponse_ != null && imageWebResponse_.getContentType().contains("image"));
}
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
request.setCharset(page.getCharset());
request.setAdditionalHeader(HttpHeader.REFERER, page.getUrl().toExternalForm());
imageWebResponse_ = webclient.loadWebResponse(request);
代码示例来源:origin: net.disy.htmlunit/htmlunit
/**
* <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK.</span><br/>
* If the image is not already downloaded it triggers a download. Then it stores the image in the HtmlImage
* object for later use.<br/>
*
* Downloads the image specified in the src attribute.
*
* @throws IOException if an error occurs while downloading the image or if the stream is of an
* unsupported content-type
*/
private void downloadImageIfNeeded() throws IOException {
if (!downloaded_) {
final HtmlPage page = (HtmlPage) getPage();
final WebClient webclient = page.getWebClient();
final URL url = page.getFullyQualifiedUrl(getSrcAttribute());
final WebRequestSettings request = new WebRequestSettings(url);
request.setAdditionalHeader("Referer",
page.getWebResponse().getRequestSettings().getUrl().toExternalForm());
imageWebResponse_ = webclient.loadWebResponse(request);
downloaded_ = true;
}
}
代码示例来源:origin: org.jenkins-ci/htmlunit
/**
* <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK.</span><br/>
* If the image is not already downloaded it triggers a download. Then it stores the image in the HtmlImage
* object for later use.<br/>
*
* Downloads the image specified in the src attribute.
*
* @throws IOException if an error occurs while downloading the image or if the stream is of an
* unsupported content-type
*/
private void downloadImageIfNeeded() throws IOException {
if (!downloaded_) {
final HtmlPage page = (HtmlPage) getPage();
final WebClient webclient = page.getWebClient();
final URL url = page.getFullyQualifiedUrl(getSrcAttribute());
final WebRequestSettings request = new WebRequestSettings(url);
request.setAdditionalHeader("Referer",
page.getWebResponse().getRequestSettings().getUrl().toExternalForm());
imageWebResponse_ = webclient.loadWebResponse(request);
downloaded_ = true;
}
}
代码示例来源:origin: org.jvnet.hudson/htmlunit
/**
* <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK.</span><br/>
* If the image is not already downloaded it triggers a download. Then it stores the image in the HtmlImage
* object for later use.<br/>
*
* Downloads the image specified in the src attribute.
*
* @throws IOException if an error occurs while downloading the image or if the stream is of an
* unsupported content-type
*/
private void downloadImageIfNeeded() throws IOException {
if (!downloaded_) {
final HtmlPage page = (HtmlPage) getPage();
final WebClient webclient = page.getWebClient();
final URL url = page.getFullyQualifiedUrl(getSrcAttribute());
final WebRequestSettings request = new WebRequestSettings(url);
request.setAdditionalHeader("Referer",
page.getWebResponse().getRequestSettings().getUrl().toExternalForm());
imageWebResponse_ = webclient.loadWebResponse(request);
downloaded_ = true;
}
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
final WebResponse response = webClient.loadWebResponse(webRequest);
final String scriptCode = response.getContentAsString();
final JavaScriptEngine javaScriptEngine = (JavaScriptEngine) webClient.getJavaScriptEngine();
代码示例来源:origin: HtmlUnit/htmlunit
final WebResponse response = webClient.loadWebResponse(webRequest);
final String scriptCode = response.getContentAsString();
final JavaScriptEngine javaScriptEngine = (JavaScriptEngine) webClient.getJavaScriptEngine();
内容来源于网络,如有侵权,请联系作者删除!