0

This is for my work project so i can't be as specific as i would like to be.

The java app i am designing is supposed to do the following :

  • fills the web-page's form,
  • clicks on the submit
  • opens a new page that displays success/failure
  • in 5 seconds, the new page automatically redirects itself to another page depending on success/failure
  • the database is updated as a result.

(the web pages already exist and are setup as i have described here, and my app is suppose to handle them automatically)

I attempt to use HtmlUnit to handle the pages, filling of forms and clicking buttons.

However i am getting some exceptions i would wish to avoid if possible.

1) when i configure my web client like so :

    wc = new WebClient();
    wc.setJavaScriptEnabled(false);

The code does what it is supposed to, but throws this exception :

dec 09, 2015 5:28:37 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary
INFO: statusCode=[400] contentType=[]
dec 09, 2015 5:28:37 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary
INFO: 
com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException: 400 Bad Request for http://www.booking.com/flexiproduct.html
    at com.gargoylesoftware.htmlunit.WebClient.throwFailingHttpStatusCodeExceptionIfNecessary(WebClient.java:540)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:360)
    at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPageIfPossible(BaseFrame.java:136)
    at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPage(BaseFrame.java:109)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadFrames(HtmlPage.java:1527)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:138)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:461)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:359)
    at com.gargoylesoftware.htmlunit.ImmediateRefreshHandler.handleRefresh(ImmediateRefreshHandler.java:83)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeRefreshIfNeeded(HtmlPage.java:1093)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:145)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:461)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:359)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:382)
    at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:242)
    at com.gargoylesoftware.htmlunit.html.HtmlImageInput.doClickAction(HtmlImageInput.java:150)
    at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:148)
    at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:109)
    at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:87)
    at com.gargoylesoftware.htmlunit.html.HtmlImageInput.click(HtmlImageInput.java:175)
    at com.gargoylesoftware.htmlunit.html.HtmlImageInput.click(HtmlImageInput.java:132)
    at paymentproviders.PProvider.submitForm(PProvider.java:52)
    at paymentproviders.APXProvider.completeTransaction(APXProvider.java:114)
    at workApps.Lazaruss1.App.main(App.java:80)

The code works, the database is successfully updated, but it fails on the last redirect and does not open the final page. :(

2) when i configure the web client as such :

    wc.setThrowExceptionOnFailingStatusCode(false);

I get the following exception and the program does not work :

dec 09, 2015 5:31:12 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary
INFO: statusCode=[400] contentType=[]
dec 09, 2015 5:31:12 PM com.gargoylesoftware.htmlunit.WebClient printContentIfNecessary
INFO: 
Failed to read the SOAP message.

java.lang.RuntimeException: Refresh Aborted by HtmlUnit: Attempted to refresh a page using an ImmediateRefreshHandler which could have caused an OutOfMemoryError Please use WaitingRefreshHandler or ThreadedRefreshHandler instead.
    at com.gargoylesoftware.htmlunit.ImmediateRefreshHandler.handleRefresh(ImmediateRefreshHandler.java:81)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeRefreshIfNeeded(HtmlPage.java:1093)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:145)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:461)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:359)
    at com.gargoylesoftware.htmlunit.ImmediateRefreshHandler.handleRefresh(ImmediateRefreshHandler.java:83)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeRefreshIfNeeded(HtmlPage.java:1093)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:145)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:461)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:359)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:382)
    at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:242)
    at com.gargoylesoftware.htmlunit.html.HtmlImageInput.doClickAction(HtmlImageInput.java:150)
    at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:148)
    at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:109)
    at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:87)
    at com.gargoylesoftware.htmlunit.html.HtmlImageInput.click(HtmlImageInput.java:175)
    at com.gargoylesoftware.htmlunit.html.HtmlImageInput.click(HtmlImageInput.java:132)
    at paymentproviders.PProvider.submitForm(PProvider.java:52)
    at paymentproviders.APXProvider.completeTransaction(APXProvider.java:114)
    at workApps.Lazaruss1.App.main(App.java:80)

The code exits after this point and the database is not changed.

What i want is to eliminate these exceptions completely. How do i configure WebClient to stop acting like such a jerk ?

Lazaruss
  • 1,107
  • 1
  • 13
  • 24
  • Update - the submit button is not , but is instead an image. I click on it using the following code : – Lazaruss Dec 10 '15 at 08:50
  • page = (HtmlPage) ((ClickableElement) form.getFirstByXPath(nameValues.get("submitXPath"))).click(); – Lazaruss Dec 10 '15 at 08:51

2 Answers2

0

More info :

this is the form of the initial page :

 <form id="paymentPageData" action="processConfirmPaymentPage" method="post">

                    <div style="display: none;">
                        <input id="transactionId" name="tranId" type="hidden" value="1510351"/>
                        <input id="cashAmount" name="amount" type="hidden" value="5.43"/>
                        <input id="usedCurrency" name="currency" type="hidden" value="EUR"/>
                        <input id="merchantRef" name="merchantTxRef" type="hidden" value="83002679818"/>
                        <input id="digestKey" name="digest" type="hidden" value="aa76e7f0db12ddbe86c1d3e13fd512e70ccfa535fbd93a347cbe2847c6187aca"/>
                        <input id="cssUrl" name="cssUrl" type="hidden" value=""/>
                    </div>

                    <div>
                        <input type="image" name="confirm" src="common/images/confirm-ukash_en_GB.jpg" border="0">
                    </div>
                    <div>
                        <input type="image" name="reverse" src="common/images/cancel-ukash_en_GB.jpg" border="0">
                    </div>

                </form>

This is the page that the success button opens :

<link rel="stylesheet" type="text/css" href="">


    <meta http-equiv="refresh" content="3;url=http://www.b92.net?Operation.ResultMessage=Success&amp;DigestKey=05980b62080143b0e9c1d56b304425cde3bd4acd1277c759bad007fb5eba5f95&amp;Merch.ID=78700005&amp;Processor.Response=00&amp;Account.Num=00000007&amp;Tran.Ref=83002679818&amp;OperationResult=SUCCESS&amp;Operation.Currency=EUR&amp;Operation.Amount=543&amp;Operation.Date=2015-12-10T10:29:26Z&amp;Transaction.Auth=01234&amp;Merchant.TxReference=83002679818">

</head>

<body>
    <div id="page">
        <div id="redirectPage">
            <div id="successfulRedirectPage">
                <div id="header"></div>
                <div id="left"></div>
                <div id="centre">
                    <div id="successfulHeader">
                        Your payment was successful
                    </div>
                    <div id="successfulMessage">
                        You will shortly be redirected back to the original site. Or, simply click the link below.
                    </div>
                    <div id="successfulLink">

                            <a href="http://www.b92.net?Operation.ResultMessage=Success&amp;DigestKey=05980b62080143b0e9c1d56b304425cde3bd4acd1277c759bad007fb5eba5f95&amp;Merch.ID=78700005&amp;Processor.Response=00&amp;Account.Num=00000007&amp;Tran.Ref=83002679818&amp;OperationResult=SUCCESS&amp;Operation.Currency=EUR&amp;Operation.Amount=543&amp;Operation.Date=2015-12-10T10:29:26Z&amp;Transaction.Auth=01234&amp;Merchant.TxReference=83002679818">Return</a>

                    </div>
                </div>
                <div id="right"></div>
                <div id="footer"></div>
            </div>
        </div>
    </div>
</body>

(i have changed the property names to protect the privacy of my employer)

Lazaruss
  • 1,107
  • 1
  • 13
  • 24
  • I think that turning off JavaScript in my webclient is what prevents this redirection. But if i leave it on, i get a huge exception which is too big to fit in the console. – Lazaruss Dec 10 '15 at 11:08
0

I solved the problem :)

The page that the refresh was leading was WAY TOO BIG and couldn't fit into the page object.

I changed the redirection url to : https://login.live.com/

And it works now.

Lazaruss
  • 1,107
  • 1
  • 13
  • 24