[ 
https://issues.apache.org/jira/browse/WW-5733?focusedWorklogId=1041107&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1041107
 ]

ASF GitHub Bot logged work on WW-5733:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Sep/26 10:14
            Start Date: 12/Sep/26 10:14
    Worklog Time Spent: 10m 
      Work Description: sonarqubecloud[bot] commented on PR #1923:
URL: https://github.com/apache/struts/pull/1923#issuecomment-5645262266

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=1923) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 New 
issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=1923&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=1923&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_struts&pullRequest=1923&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [100.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=1923&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=1923&metric=new_duplicated_lines_density&view=list)
  
     
   <!

Issue Time Tracking
-------------------

    Worklog Id:     (was: 1041107)
    Time Spent: 20m  (was: 10m)

> JasperReports 7 exporter providers close the response stream before the 
> report is written — empty response on Tomcat
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: WW-5733
>                 URL: https://issues.apache.org/jira/browse/WW-5733
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - JasperReports
>            Reporter: Lukasz Lenart
>            Assignee: Lukasz Lenart
>            Priority: Major
>             Fix For: 7.4.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Every {{JasperReport7*ExporterProvider.createExporter}} in 
> {{struts2-jasperreports7-plugin}} (CSV, HTML, PDF, RTF, XML, XLSX) wires the 
> exporter output like this:
> {code:java}try (OutputStream responseStream = response.getOutputStream()) {
>     exporter.setExporterOutput(new 
> SimpleWriterExporterOutput(responseStream));
> }
> {code}
> The try-with-resources closes the servlet output stream when 
> {{createExporter}} returns. Only afterwards does 
> {{JasperReport7Result.exportReport}} call {{exporter.exportReport()}} and 
> {{response.getOutputStream().flush()}}, so the whole report is written to an 
> already closed stream.
> On Tomcat, {{ServletOutputStream.close()}} commits the response with the 
> bytes written so far, which is none, and discards every later write. 
> Reproduced with an embedded Tomcat 10.1.34 and a servlet performing the same 
> sequence (close inside try-with-resources, then write, then flush):
> {code}/good -> status=200 content-length=(none) body=28 bytes
> /bad  -> status=200 content-length=0     body=0 bytes
> {code}
> So on Tomcat the plugin returns an empty {{200}} with {{Content-Length: 0}} 
> for every format. {{JasperReport7ResultTest}} does not catch it because 
> Spring's {{MockHttpServletResponse}} keeps accepting writes after {{close()}}.
> The 6.x {{struts2-jasperreports-plugin}} is unaffected: 
> {{JasperReportsResult}} exports into a {{ByteArrayOutputStream}}, sets 
> {{Content-Length}}, then writes and closes.
> Fix: obtain {{response.getOutputStream()}} without try-with-resources in all 
> six providers (the {{IOException}} is still wrapped into 
> {{StrutsException}}), keep streaming directly to the response, and leave 
> flushing to {{JasperReport7Result}} and closing to the container. Guard it 
> with a test that runs the result against an {{HttpServletResponseWrapper}} 
> whose {{ServletOutputStream}} rejects writes after {{close()}}, which is the 
> semantics the mock lacks.
> Affects every release since 7.1.0.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to