0

I have an application using Htmlunit and I needs to use a PAC file, but HtmlUnit shows an error and I don't know why.

The PAC file is written in Javascript and it has ".cgi" extension.

The code is:

WebClient webClient = new WebClient();

webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setActiveXNative(true); webClient.getOptions().setAppletEnabled(true); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setPopupBlockerEnabled(true); webClient.getOptions().setRedirectEnabled(true); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setUseInsecureSSL(true);

webClient.setAjaxController(new NicelyResynchronizingAjaxController());

webClient.getOptions().getProxyConfig().setProxyAutoConfigUrl("http://domain/proxy.pac");

HtmlPage currentPage = webClient.getPage(web);

And the errors are:

Exception in thread "main" java.lang.StackOverflowError at java.io.IOException.<init>(IOException.java:58) at java.io.InterruptedIOException.<init>(InterruptedIOException.java:64) at java.net.SocketTimeoutException.<init>(SocketTimeoutException.java:43) at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:150) at java.net.SocketInputStream.read(SocketInputStream.java:121) at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160) at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84) at org.apache.http.impl.io.SocketInputBuffer.isDataAvailable(SocketInputBuffer.java:95) at org.apache.http.impl.AbstractHttpClientConnection.isStale(AbstractHttpClientConnection.java:310) at org.apache.http.impl.conn.ManagedClientConnectionImpl.isStale(ManagedClientConnectionImpl.java:158) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:432) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:167) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1281) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1198) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:376) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:361) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1237) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1339) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1198) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:376) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:361)

There are more lines of errors but I have not putt.

Any ideas?

angelo087
  • 51
  • 5

1 Answers1

0
webClient.getOptions().getProxyConfig().setProxyAutoConfigUrl("http://domain/proxy.pac");   

I think problem in above line please check url of proxy this is not correct. please open first it in the browser if it is open correctly then apply it on code.

  • This url is invented. When I check the real url of proxy, the browser downloads an file with extension ".cgi" with code in javascript. Maybe is this the problem? – angelo087 Nov 21 '13 at 23:03
  • In other way, I have a file with a function in javascript (I think is the autoconfiguration proxy) with extension "cgi", not pac (I don't know if this is correct because I don't undestand about proxy). Is there way to assign this configuration to the webClient? :( – angelo087 Nov 23 '13 at 11:44