Problems with upload file into form

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with upload file into form

makson
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Hi.
My general task is submit file in form with HtmlUnit.
This form:
<form action="/incoming/Upload.cfg" enctype="multipart/form-data" method="post" onsubmit="return doSubmit();">
  <table id="autoWidth" border="0" style="width: 100%;">
    <tbody>
      <tr>
        <td class="h1" colspan="4" id="t_title">
          Резервная копия и Восстановление
        </td>
      </tr>
      <tr>
        <td class="blue" colspan="4"/>
      </tr>
      <tr>
        <td class="Item" id="t_backup">
          Сохранить:
        </td>
        <td colspan="3">
          <input type="button" class="buttonBigL" name="Backup" value="Резервная копия" onclick="location.href='config.bin';"/>
        </td>
      </tr>
      <tr>
        <td class="Item" id="t_file">
          Файл:
        </td>
        <td>
          <input class="text" name="filename" type="file" size="20" onkeydown="return false"/>
        </td>
        <td>
          <input name="Restore" type="submit" class="buttonBigL" id="Submit" value="Восстановить"/>
        </td>
        <td width="100%">
           
        </td>
      </tr>
      <tr>
        <td class="blue" colspan="4"/>
      </tr>
    </tbody>
  </table>
</form>

My code is
        final WebClient webClient = new WebClient(BrowserVersion.CHROME);
        webClient.getOptions().setTimeout(20000);
        webClient.getOptions().setJavaScriptEnabled(true);
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);

        webClient.setConfirmHandler(new ConfirmHandler() {
            public boolean handleConfirm(Page page, String message) {
                return true;
            }
        });
        htmlForm.<HtmlFileInput>getInputByName("filename").setValueAttribute(model);
        htmlForm.<HtmlFileInput>getInputByName("filename").setContentType("multipart/form-data");
        HtmlPage restore = htmlForm.getInputByName("Restore").click();

 When I click() button the "upgrade" should begin but nothing happens.
More, then click() I must get HtmlPage restore, but I got
java.lang.ClassCastException: com.gargoylesoftware.htmlunit.TextPage cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlPage

Help please with this task
Reply | Threaded
Open this post in threaded view
|

Re: Problems with upload file into form

makson
This post has NOT been accepted by the mailing list yet.
Colleagues. The code is working, the overload goes. But I ran the tests in the spring container, and for some reason I got this error.
@RunWith(SpringRunner.class)
@SpringBootTest

If you run without springs everything works.
Please tell me why can this problem arise?
Reply | Threaded
Open this post in threaded view
|

Re: Problems with upload file into form

makson
This post has NOT been accepted by the mailing list yet.
The problem is - "Target server failed to respond exception."
I avoid this across

            webClient.getOptions().setTimeout(20000);
            webClient.getOptions().setThrowExceptionOnScriptError(false);
            webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
            webClient.getOptions().setCssEnabled(false);
            webClient.getOptions().setJavaScriptEnabled(true);
            webClient.getOptions().setUseInsecureSSL(true);
            webClient.getOptions().setRedirectEnabled(true);

Decided