Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileDownload: "Response already committed" warning printed on WebSphere #3955

Closed
wtlucy opened this issue Aug 9, 2018 · 3 comments
Closed
Labels
🐞 defect Bug...Something isn't working
Milestone

Comments

@wtlucy
Copy link
Contributor

wtlucy commented Aug 9, 2018

1) Environment

  • PrimeFaces version: 6.2
  • Does it work on the newest released PrimeFaces version? Version?
  • Does it work on the newest sources in GitHub? no
  • Application server + version: Open Liberty 18.0.0.2 with jsf-2.2 (MyFaces 2.2)
  • Affected browsers: all

2) Expected behavior

No warning messages are printed when using p:fileDownload to download a file.

3) Actual behavior

Downloading files that are larger than the servlet response buffer size results in a WebSphere warning message:
[WARNING ] WARNING: Cannot set status. Response already committed.

4) Steps to reproduce

Use a p:fileDownload button to attempt to download a large file; a warning message will be printed to the output log for every (download) request.

5) Sample XHTML

    <p:commandButton id="download" value="Download"
        ajax="false"
        onclick="PrimeFaces.monitorDownload(startMessage, finishMessage);">
        <p:fileDownload value="#{uploadController.XLSExport}"/>
    </p:commandButton>

6) Sample bean

public class UploadController implements java.io.Serializable {
	
	public UploadController() {
	}

	public StreamedContent getXLSExport() {
		byte[] bytes = new byte[33000]; // larger than 32K
		for (int i = 0; i < 33000; i++) {
			bytes[i] = 'f';
		}
		byte[] content = bytes;
	    return new DefaultStreamedContent(new ByteArrayInputStream(content), "application/csv", "something.xlsx", "UTF-8");
	}
}

The problem here looks to be that FileDownloadActionListener.processAction() makes a call to update the response status code after writing the entire contents of the downloaded file to the response output stream. If the downloaded file length is larger than the response output stream buffer size, then on WebSphere the response will be committed - and then the status code cannot be updated.

A fix for this would be to check externalContext.isResponseCommitted() before trying to call externalContext.setResponseStatus(200)

@tandraschko tandraschko added the 🐞 defect Bug...Something isn't working label Aug 9, 2018
@tandraschko
Copy link
Member

a PR would be great!

wtlucy added a commit to wtlucy/primefaces that referenced this issue Aug 10, 2018
tandraschko added a commit that referenced this issue Aug 10, 2018
Fix #3955 FileDownload "Response already committed" warning
@tandraschko tandraschko added this to the 6.3 milestone Aug 10, 2018
@tandraschko
Copy link
Member

THanks!

@wtlucy
Copy link
Contributor Author

wtlucy commented Aug 10, 2018

Thanks for the quick review/merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 defect Bug...Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants