0

Sample URL: http://www.heatpressnation.com/sublimation-printers-ink.html
Websocket URL: https://us22.zopim.com

When calling that page, HtmlUnit never completes because of the websocket connection to zopim.com. How can I force the page to finish after a set timeout or identify the web socket and close it. Here is the meat of my code:

try
{
        URL url = new URL(strUrl);
        WebRequest webRequest = new WebRequest(url);

        WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);

        new WebConnectionWrapper(webClient) {
                public WebResponse getResponse(WebRequest request) throws IOException {
                        System.err.println("Url: " + request.getUrl());
                        WebResponse response = super.getResponse(request);
                        if(response.getContentType().equals("text/html") || response.getContentType().equals(null) || response.getContentType().equals("") || response.getContentType().equals("application/x-www-form-urlencoded"))
                        {
                                System.out.println(response.getWebRequest().getUrl());
                        }
                        return response;
                }
        };
        webClient.getOptions().setTimeout(10000);
        webClient.setJavaScriptTimeout(5000);
        webClient.setRefreshHandler(new ImmediateRefreshHandler());
        webClient.getPage(webRequest);
        webClient.waitForBackgroundJavaScript(3000);
}
catch(Exception error)
{
        System.err.println("Error: " + error.toString());
} 
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Vaibhav
  • 2,073
  • 4
  • 23
  • 26
  • Hi Ahmed, I have source code with me. Can you please suggest any quick fix for this, I am stucked. – Vaibhav Jul 26 '15 at 07:40
  • WebSocket constructor is not called, please use latest snapshot or [build](https://ci.canoo.com/teamcity/viewLog.html?buildTypeId=HtmlUnit_FastBuild&buildId=lastSuccessful&tab=artifacts), there are other errors, please read https://github.com/HtmlUnit/HtmlUnit/blob/master/src/site/xdoc/submittingJSBugs.xml – Ahmed Ashour Jul 26 '15 at 09:12

0 Answers0