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;
}
}