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 ?