Java Code Examples for com.gargoylesoftware.htmlunit.WebRequest#getUrl()
The following examples show how to use
com.gargoylesoftware.htmlunit.WebRequest#getUrl() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HostRequestMatcher.java From spring-analysis-note with MIT License | 6 votes |
@Override public boolean matches(WebRequest request) { URL url = request.getUrl(); String host = url.getHost(); if (this.hosts.contains(host)) { return true; } int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } String hostAndPort = host + ":" + port; return this.hosts.contains(hostAndPort); }
Example 2
Source File: HostRequestMatcher.java From java-technology-stack with MIT License | 6 votes |
@Override public boolean matches(WebRequest request) { URL url = request.getUrl(); String host = url.getHost(); if (this.hosts.contains(host)) { return true; } int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } String hostAndPort = host + ":" + port; return this.hosts.contains(hostAndPort); }
Example 3
Source File: HostRequestMatcher.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public boolean matches(WebRequest request) { URL url = request.getUrl(); String host = url.getHost(); if (this.hosts.contains(host)) { return true; } int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } String hostAndPort = host + ":" + port; return this.hosts.contains(hostAndPort); }
Example 4
Source File: FalsifyingWebConnection.java From htmlunit with Apache License 2.0 | 5 votes |
/** * 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; }
Example 5
Source File: FalsifyingWebConnection.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * 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; }
Example 6
Source File: RegexHttpWebConnection.java From nutch-htmlunit with Apache License 2.0 | 5 votes |
@Override public WebResponse getResponse(final WebRequest request) throws IOException { final URL url = request.getUrl(); if (StringUtils.isBlank(filter(url.toString())) || url.toString().indexOf("robots.txt") > -1) { LOG.info("Thread: {}, - Http Excluding URL: {}", Thread.currentThread().getId(), url); return new StringWebResponse("", url); } if (LOG.isInfoEnabled()) { LOG.info("Thread: {}, + Http Fetching URL: {}", Thread.currentThread().getId(), url); } return super.getResponse(request); }
Example 7
Source File: FalsifyingWebConnection.java From htmlunit with Apache License 2.0 | 3 votes |
/** * Creates a faked WebResponse for the request with the provided content. * @param wr the web request for which a response should be created * @param content the content to place in the response * @param contentType the content type of the response * @param responseCode the HTTP code for the response * @param responseMessage the HTTP message for the response * @return a web response with the provided content * @throws IOException if an encoding problem occurred */ protected WebResponse createWebResponse(final WebRequest wr, final String content, final String contentType, final int responseCode, final String responseMessage) throws IOException { final List<NameValuePair> headers = new ArrayList<>(); headers.add(new NameValuePair(HttpHeader.CONTENT_TYPE_LC, contentType + "; charset=" + UTF_8)); final byte[] body = content.getBytes(UTF_8); final WebResponseData wrd = new WebResponseData(body, responseCode, responseMessage, headers); return new WebResponse(wrd, wr.getUrl(), wr.getHttpMethod(), 0); }
Example 8
Source File: FalsifyingWebConnection.java From HtmlUnit-Android with Apache License 2.0 | 3 votes |
/** * Creates a faked WebResponse for the request with the provided content. * @param wr the web request for which a response should be created * @param content the content to place in the response * @param contentType the content type of the response * @param responseCode the HTTP code for the response * @param responseMessage the HTTP message for the response * @return a web response with the provided content * @throws IOException if an encoding problem occurred */ protected WebResponse createWebResponse(final WebRequest wr, final String content, final String contentType, final int responseCode, final String responseMessage) throws IOException { final List<NameValuePair> headers = new ArrayList<>(); headers.add(new NameValuePair(HttpHeader.CONTENT_TYPE_LC, contentType + "; charset=" + UTF_8)); final byte[] body = content.getBytes(UTF_8); final WebResponseData wrd = new WebResponseData(body, responseCode, responseMessage, headers); return new WebResponse(wrd, wr.getUrl(), wr.getHttpMethod(), 0); }