1

I am trying to use htmlunit-2.7 Library (which is the default library avalilable in SoapUI-5.2.1) to Automate the User Level Token Retrieval Process (Authorization Code Grant flow of OAuth2). But I am receiving the Connection reset error when I tried to connect to Google Page via WebClient Class of htmlunit-2.7.

Below is my code,

Dependency Jar Files I have used in my project,

commons-codec-1.3.jar commons-httpclient-3.1.jar commons-io-2.4.jar commons-lang-2.4.jar commons-logging-1.1.1.jar htmlunit-2.7.jar htmlunit-core-js-2.7.jar sac-1.3.jar xercesImpl-2.9.1.jar

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class HTMLUnitClass 
{

    public static void main(String[] args) 
    {
        // TODO Auto-generated method stub


        System.out.println("Starting the  Script");

        try
         {
          //Webpage Login  
            WebClient driver = new WebClient();
            System.out.println("Instantiating the WebClient");


            driver.setJavaScriptEnabled(true);
            System.out.println("Enabling the Java Script");
            driver.setThrowExceptionOnScriptError(false);
            System.out.println("Disabling the Throw Exception on Script Error");


            try
            {
                driver.getPage("https://www.google.com");
                System.out.println("Getting the Google Page");

            }
            catch(Exception e)
            {
                System.out.println("Exception in the HTML Unit Driver Block: " + e);
            }


            }
            catch (Exception e)
            {
                System.out.println("Exception in the HTTPClient Block" + e);
            }




    }

}

And I am getting the below error - stack below,

Starting the Script
Instantiating the HTMLUnit Driver
Enabling the Java Script
Disabling the Throw Exception on Script Error
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset
Jul 18, 2017 6:34:41 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
Exception in the HTML Unit Driver Block: java.net.SocketException: Connection reset

NOTE-1: Please note that, I cannot go with the latest HtmlUnitDriver Library (Jar), because that will cause version conflicts with the default libraries of the SoapUI-5.2.1 That is the reason for me to stick to the Default Libraries provided in the Installation package of SoapUI-5.2.1 and trying to integrate this solution with the Groovy Script available in one of the Test Steps of the SoapUI.

NOTE-2: I tried using the Apache OAuth Client 2.0 Library as well for automating the Level Token Generation (My Clarification on OAuth Client 2.0 Library)

Could someone throw some lights on how to resolve this Connection RESET issue ?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Found this on an old post. Try adding it in webClient.getOptions().setSSLClientProtocols(new String[] { "TLSv1.2", "TLSv1.1" }); . Taken from here https://sourceforge.net/p/htmlunit/mailman/message/34726040/ – canpan14 Jul 18 '17 at 14:39
  • I tried with `2.7`, and your case works. Which country are you from? Since `google.com` can go to e.g. `google.de`. Also, which Java/eclipse/maven version you use? – Ahmed Ashour Jul 19 '17 at 13:54
  • @AhmedAshour: I am from India but am using the network from US (VM). Below are the version details that you've asked.. Java: Build 1.8.0_131-b11 Eclipse: Version: Neon Release (4.6.0) & Build id: 20160613-1800 – Aravamudhan Sivanandam Jul 20 '17 at 10:03

1 Answers1

0

I had the same problem my self and the correct solution is the one proposed on the first comment by @canpan14

My solution to overcome this error is the following:

WebClient webClient = new WebClient(BEST_SUPPORTED);
webClient.getOptions().setUseInsecureSSL(true); //ignore insecure ssl exception
webClient.getOptions().setSSLClientProtocols(new String[] { "TLSv1.2","TLSv1.1" });

The last line of code actually sets the type of TLS to use. The preferred is TLSv1.2 for your code to work correctly.

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125