0

The getPage() function of HtmlUnit is throwing javax.net.ssl.SSLException: Invalid TLS padding data and javax.net.ssl.SSLException: Received fatal alert: bad_record_mac not always but when after two three requests it starts throwing exception.

The URL uses HTTPS protocol.

Any idea what can be wrong with it? How can be resolved?

SNIPPET:

Calling the webpage for multiple request throws above exceptions:

public static WebClient getLoggedInHtmlUnit() {


        webClient = new WebClient(BrowserVersion.FIREFOX_24);
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setCssEnabled(false); // I think this speeds the thing up
        webClient.getOptions().setRedirectEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.setAjaxController(new NicelyResynchronizingAjaxController());
        webClient.getCookieManager().setCookiesEnabled(true);
        webClient.getOptions().setUseInsecureSSL(true);



        try {

            final HtmlPage page =  webClient.getPage(LOGIN_URL); //https://consyn.elsevier.com/user/login

            final HtmlForm form = page.getForms().get(0);  

            final HtmlTextInput textField =  form.getInputByName(USERNAME_BYINPUT_NAME);
            final HtmlPasswordInput pwd =  form.getInputByName(PASSWORD_BYINPUT_NAME);        
            textField.setValueAttribute(USERNAME);
            pwd.setValueAttribute(PASSWORD);   

            final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue(LOGIN_BYVALUE).get(0);
            button.click();

            return webClient;

        } catch (FailingHttpStatusCodeException | IOException e) {
            e.printStackTrace();
            return null;
        }



}
halfer
  • 19,824
  • 17
  • 99
  • 186
gursahib.singh.sahni
  • 1,559
  • 3
  • 26
  • 51

1 Answers1

0

I have used the following and it worked fine and prints "Page Loaded ..." . Use this inside the Try catch block not outside. I have tried in Ubuntu Linux environment with jdk 6. If this fails check with another OS other than MAC. (I think you are using a MAC)

            WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
            webClient.getOptions().setJavaScriptEnabled(false);
            webClient.getOptions().setUseInsecureSSL(true);
            HtmlPage page = (HtmlPage)     webClient.getPage("https://consyn.elsevier.com/user/login");
            System.out.println("Page Loaded ...");