GWT getResults () SubmitCompleteEvent returns null after submitting form with FileUpload

After successfully implementing file upload using GWT

in one application, I tried to port this to another application, but the string returned from the boot servlet cannot be restored in the provided one SubmitCompleteHandler

. SubmitCompleteEvent.getResults()

just returns null.

The typical reason for returning null seems to be because the upload servlet is on a different domain. But since GWT and the loading servlet run in the same context, this shouldn't be a cross-domain access issue.

The widget is FileUpload

contained in FormPanel

. When the button is clicked, the form is submitted. This calls the servlet (indeed, a breakpoint is hit during debugging). In the real world it will save the file on the server side and return the filename. In this given example, it just writes a String to the Writer response.

FormPanel

with a FileUpload

snippet:

final FormPanel form = new FormPanel();
form.setAction("upload"); // results "upload" directly below context
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
VerticalPanel panel = new VerticalPanel();
form.setWidget(panel);
FileUpload upload = new FileUpload();
upload.setName("uploadFormElement");
panel.add(upload);

panel.add(new Button("Submit", new ClickHandler() {
    public void onClick(ClickEvent event) {
        form.submit();
    }
}));
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
    public void onSubmitComplete(SubmitCompleteEvent event) {
        Window.alert("===> " + event.getResults() + " <==="); // shows "===> null <==="
    }
});

      

web.xml

fragment:

<servlet> 
    <servlet-name>FileUploadServlet</servlet-name>
    <servlet-class>mypackage.FileUploadServlet</servlet-class> 
</servlet> 
<servlet-mapping>
    <servlet-name>FileUploadServlet</servlet-name>
    <url-pattern>/upload</url-pattern> 
</servlet-mapping>

      

FileUploadServlet

fragment:

public class FileUploadServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        response.getWriter().write("OK");
        response.getWriter().flush();
    }

}

      

Are there libraries or libraries known to conflict with the GWT SubmitCompleteHandler?

Any ideas are appreciated ...

UPDATE : After downgrading all artifacts belonging to spring-security from 4.0.4.RELEASE to 3.2.4.RELEASE, it works. With updating them to 4.1.2.RELEASE it doesn't work either.

+3


source to share


1 answer


This issue is related to the header X-Frame-Options: DENY

that spring-security 4.x is being added to the responses [1]. Since a GWT application is typically loaded into an iframe, this header prevents form submission from being processed correctly from client code running in the frame.

To fix the frame settings policy, you must disable or switch to SAMEORIGIN

. For example. for xml config in <s:http>

:

<s:headers>
  <s:frame-options policy="SAMEORIGIN" />
</s:headers>

      



Or for Java configuration with org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.frameOptions()

:

 HttpSecurity cfg = ...;
 cfg.headers().frameOptions().sameOrigin();

      

[1] https://docs.spring.io/spring-security/site/docs/current/reference/html/headers.html#headers-frame-options

+2


source







All Articles