0

I found the following error when trying to use the getPage method of the HtmlUnit WebClient object:

java.lang.ClassCastException: java.net.Socket cannot be cast to javax.net.ssl.SSLSocket

My Code:

        BrowserVersion firefox17WithUptoDateFlash = new BrowserVersion(BrowserVersion.FIREFOX_17.getApplicationName(),
            BrowserVersion.FIREFOX_17.getApplicationVersion(), BrowserVersion.FIREFOX_17.getUserAgent(),
            BrowserVersion.FIREFOX_17.getBrowserVersionNumeric(),
            new BrowserVersionFeatures[] { BrowserVersionFeatures.JS_FRAME_RESOLVE_URL_WITH_PARENT_WINDOW,
                    BrowserVersionFeatures.STYLESHEET_HREF_EXPANDURL,
                    BrowserVersionFeatures.STYLESHEET_HREF_STYLE_NULL });

    PluginConfiguration plugin = new PluginConfiguration("Shockwave Flash", "Shockwave Flash 14.0 r0",
            "NPSWF32_14_0_0_145.dll");
    plugin.getMimeTypes()
            .add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Adobe Flash movie", "swf"));

    firefox17WithUptoDateFlash.getPlugins().add(plugin);

    webClient = new WebClient(firefox17WithUptoDateFlash);
    webClient.getOptions().setJavaScriptEnabled(false);
    webClient.getOptions().setThrowExceptionOnScriptError(false);


    // Get the first page
    final HtmlPage page1 = webClient.getPage("https://www.example.com/login.html");

Note 1: I am trying to execute this code from an Action in Struts.

Note 2: To put it here in the stack, I changed the url. But I'm trying to access a page login using https.

Stack Trace:

java.lang.ClassCastException: java.net.Socket cannot be cast to javax.net.ssl.SSLSocket
at com.gargoylesoftware.htmlunit.HtmlUnitSSLSocketFactory.createSocket(HtmlUnitSSLSocketFactory.java:116)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:168)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
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 br.com.yyyyy.xxxxx.integracao.LeitorAtendimento.<init>(LeitorAtendimento.java:58)
at br.com.yyyyy.xxxxx.action.caldario.obrig.AbrirAct.executar(AbrirAct.java:122)
at br.com.yyyyy.xxxxx.action.AjaxAction.execute(AjaxAction.java:61)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.ajaxanywhere.AAFilter.doFilter(AAFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

I would just like to solve this. Can someone help me?

4
  • Please post your stack trace Commented Jun 3, 2018 at 12:03
  • @RBRi Here's my stacktrace. Commented Jun 4, 2018 at 16:34
  • 1
    Please make sure you have the correct version of httpclient (and only one) in your classpath. Commented Jun 5, 2018 at 4:24
  • Thank you for your help @RBRi. I updated the version of htmlunit to the most current one. Just like the other dependencies. Commented Jun 6, 2018 at 13:30

1 Answer 1

1

The error has been resolved while updating the project dependencies.

Sign up to request clarification or add additional context in comments.

1 Comment

Ran into this issue because Google referenced the version 2.13 as the #1 result when looking for the HtmlUnit maven package. I c/c the mvnrepository snippet as usual without noticing it wasn't the last version. Your post & answer helped look in the right direction :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.