/// <summary>
 /// Refreshes the specified page using the specified URL after the specified number of seconds.
 /// @throws IOException if the refresh fails
 /// </summary>
 /// <param name="page">the page that is going to be refreshed</param>
 /// <param name="url">the URL where the new page will be loaded</param>
 /// <param name="requestedWait">the number of seconds to wait before reloading the page; if this is greater than <tt>maxwait</tt> then <tt>maxwait</tt> will be used instead</param>
 public void HandleRefresh(AbstractPage page, URL url, int requestedWait)
 {
     int seconds = requestedWait;
     if (seconds > maxwait_ && maxwait_ > 0)
     {
         seconds = maxwait_;
     }
     try
     {
         Thread.Sleep(seconds * 1000);
     }
     catch (/*InterruptedException*/Exception e)
     {
         /* This can happen when the refresh is happening from a navigation that started
          * from a setTimeout or setInterval. The navigation will cause all threads to get
          * interrupted, including the current thread in this case. It should be safe to
          * ignore it since this is the thread now doing the navigation. Eventually we should
          * refactor to force all navigation to happen back on the main thread.
          */
         if (LOG.IsDebugEnabled)
         {
             LOG.Debug("Waiting thread was interrupted. Ignoring interruption to continue navigation.");
         }
     }
     IWebWindow window = page.EnclosingWindow;
     if (window == null)
     {
         return;
     }
     WebClient client = window.WebClient;
     client.getPage(window, new WebRequest(url));
 }
        /// <summary>
        /// Refreshes the specified page using the specified URL immediately if the <tt>requestedWait</tt>
        /// not larget that the <tt>maxDelay</tt>. Does nothing otherwise.
        /// @throws IOException if the refresh fails
        /// </summary>
        /// <param name="page">the page that is going to be refreshed</param>
        /// <param name="url">the URL where the new page will be loaded</param>
        /// <param name="requestedWait">the number of seconds to wait before reloading the page</param>
        public void HandleRefresh(IPage page, URL url, int requestedWait)
        {
            if (requestedWait > maxDelay_)
            {
                return;
            }

            base.HandleRefresh(page, url, requestedWait);
        }
 /// <summary>
 /// Refreshes the specified page using the specified URL after the specified number
 /// of seconds.
 /// </summary>
 /// <param name="page">the page that is going to be refreshed</param>
 /// <param name="url">the URL where the new page will be loaded</param>
 /// <param name="seconds">the number of seconds to wait before reloading the page</param>
 public void HandleRefresh(IPage page, URL url, int seconds)
 {
     Thread thread = new Thread(new ThreadStart(() =>
     {
         try
         {
             new WaitingRefreshHandler().HandleRefresh(page, url, seconds);
         }
         catch (IOException e)
         {
             LOG.Error("Unable to refresh page!", e);
             throw new SystemException("Unable to refresh page!", e);
         }
     }));
     // TODO : thread.setDaemon(true);
     thread.Start();
 }
 /// <summary>
 /// Immediately refreshes the specified page using the specified URL.
 /// @throws IOException if the refresh fails
 /// </summary>
 /// <param name="page">the page that is going to be refreshed</param>
 /// <param name="url">the URL where the new page will be loaded</param>
 /// <param name="seconds">the number of seconds to wait before reloading the page (ignored!)</param>
 public void HandleRefresh(IPage page, URL url, int seconds)
 {
     IWebWindow window = page.EnclosingWindow;
     if (window == null)
     {
         return;
     }
     WebClient client = window.WebClient;
     if (String.Equals(page.Url.ToExternalForm(), url.ToExternalForm()) && HttpMethod.GET == page.WebResponse.WebRequest.HttpMethod)
     {
         String msg = "Refresh to " + url + " (" + seconds + "s) aborted by HtmlUnit: "
             + "Attempted to refresh a page using an ImmediateRefreshHandler "
             + "which could have caused an OutOfMemoryError "
             + "Please use WaitingRefreshHandler or ThreadedRefreshHandler instead.";
         throw new RuntimeException(msg);
     }
     client.getPage(window, new WebRequest(url));
 }
Example #5
0
 private URL BuildUrlWithNewFile(URL url, String newFile)
 {
     try
     {
         if (url.getRef() != null)
         {
             newFile += '#' + url.getRef();
         }
         if ("file".equals(url.getProtocol()) && url.getAuthority() != null && url.getAuthority().endsWith(":"))
         {
             newFile = ":" + newFile;
         }
         url = new URL(url.getProtocol(), url.getHost(), url.getPort(), newFile);
     }
     catch (Exception e)
     {
         throw new RuntimeException("Cannot set URL: " + url.toExternalForm(), e);
     }
     return url;
 }
Example #6
0
 /**
  * Instantiates a {@link WebRequest} for the specified URL using the specified HTTP submit method.
  * @param url the target URL
  * @param submitMethod the HTTP submit method to use
  */
 public WebRequest(URL url, HttpMethod submitMethod) :
     this(url)
 {
     this.HttpMethod = submitMethod;
 }
Example #7
0
 /**
  * Instantiates a {@link WebRequest} for the specified URL.
  * @param url the target URL
  */
 public WebRequest(URL url) :
     this(url, "*/*")
 {
 }
Example #8
0
 /// <summary>
 /// Instantiates a {@link WebRequest} for the specified URL.
 /// </summary>
 /// <param name="url">the target URL</param>
 /// <param name="acceptHeader">the accept header to use</param>
 public WebRequest(URL url, String acceptHeader)
 {
     this.Url = url;
     SetAdditionalHeader("Accept", acceptHeader);
     SetAdditionalHeader("Accept-Encoding", "gzip, deflate");
 }
 private static WebRequest BuildWebRequest(URL originatingURL, String charset)
 {
     WebRequest webRequest = new WebRequest(originatingURL, HttpMethod.GET);
     webRequest.Charset = charset;
     return webRequest;
 }
 /// <summary>
 /// Creates an instance associated with the specified originating URL.
 /// </summary>
 /// <param name="content">the content to return</param>
 /// <param name="charset">the charset used to convert the content</param>
 /// <param name="originatingURL">the URL that this should be associated with</param>
 public StringWebResponse(String content, String charset, URL originatingURL) :
     base(GetWebResponseData(content, charset), BuildWebRequest(originatingURL, charset), 0)
 {
 }
 /// <summary>
 /// Creates an instance associated with the specified originating URL.
 /// </summary>
 /// <param name="content">the content to return</param>
 /// <param name="originatingURL">the URL that this should be associated with</param>
 public StringWebResponse(String content, URL originatingURL) :
     // use UTF-8 here to be sure, all chars in the string are part of the charset
     this(content, "UTF-8", originatingURL)
 {
 }
Example #12
0
 /// <summary>
 /// Constructs with all data.
 /// </summary>
 /// <param name="responseData">Data that was send back</param>
 /// <param name="url">Where this response came from</param>
 /// <param name="requestMethod">the method used to get this response</param>
 /// <param name="loadTime">How long the response took to be sent</param>
 public WebResponse(WebResponseData responseData, URL url, HttpMethod requestMethod, long loadTime) :
     this(responseData, new WebRequest(url, requestMethod), loadTime)
 {
 }