Skip to content

AbstractXlsxView does not work on WebSphere Liberty Profile [SPR-13910] #18484

@spring-projects-issues

Description

@spring-projects-issues

Tomoyuki Ikeya opened SPR-13910 and commented

We tried AbstractXlsxView as following implementation with Websphere Liberty Profile 8.5.5.8.
Then we got IOException (stream is closed) at AbstractXlsView#renderWorkbook().
Of course, we confirmed the same implementation on Tomcat and it succeeded.

@Component
public class ExcelView extends AbstractXlsxView {
    @Override
    protected void buildExcelDocument(Map<String, Object> model,
            Workbook workbook, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        Sheet sheet = workbook.createSheet("sheet1");
        sheet.setFitToPage(true);

        String filename = "sample.xlsx";
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename*=''" + URLEncoder.encode(filename, "UTF-8"));
    }
}

We got following stacktrace.

[16/01/26 17:41:44:764 JST] 00000452 com.ibm.ws.webcontainer.util.ApplicationErrorUtils           E SRVE0777E: アプリケーション・クラス 'com.ibm.ws.http.channel.internal.outbound.HttpOutputStreamImpl.validate:196' によって例外がスローされました
java.io.IOException: Stream is closed
              at com.ibm.ws.http.channel.internal.outbound.HttpOutputStreamImpl.validate(HttpOutputStreamImpl.java:196)
              at com.ibm.ws.http.channel.internal.outbound.HttpOutputStreamImpl.flush(HttpOutputStreamImpl.java:571)
              at com.ibm.wsspi.http.ee7.HttpOutputStreamEE7.flush(HttpOutputStreamEE7.java:289)
              at com.ibm.ws.webcontainer.osgi.response.WCOutputStream.flush(WCOutputStream.java:234)
              at org.springframework.security.web.context.OnCommittedResponseWrapper$SaveContextServletOutputStream.flush(OnCommittedResponseWrapper.java:437)
              at org.springframework.web.servlet.view.document.AbstractXlsView.renderWorkbook(AbstractXlsView.java:101)
              at org.springframework.web.servlet.view.document.AbstractXlsView.renderMergedOutputModel(AbstractXlsView.java:74)
              at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)

By our investigation, the cause may be that AbstractXlsView (super class of AbstractXlsxView) calls outputStream#flush() twice.
If we prevent one of them as following extension to disable flush, we never see the stacktrace and can download an expected excel file.

In my opinion, it should be fixed to call once to support WebSphere Liberty Profile if there is no reason to flush twice.

    @Override
    protected void renderWorkbook(Workbook workbook, HttpServletResponse response) throws IOException {
        ServletOutputStream out = response.getOutputStream();
        workbook.write(out);
        //out.flush();

        // Closeable only implemented as of POI 3.10
        if (workbook instanceof Closeable) {
            ((Closeable) workbook).close();
        }
    }

Affects: 4.2.4

Referenced from: commits 28e8af2, e483155

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions