You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lukasz Lenart (Jira)" <ji...@apache.org> on 2022/09/15 07:17:00 UTC

[jira] [Closed] (WW-4559) Define a bean of java.io.FileInputStream in Spring makes the Struts stream result not work

     [ https://issues.apache.org/jira/browse/WW-4559?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart closed WW-4559.
-----------------------------
    Resolution: Won't Fix

> Define a bean of java.io.FileInputStream in Spring makes the Struts stream result not work
> ------------------------------------------------------------------------------------------
>
>                 Key: WW-4559
>                 URL: https://issues.apache.org/jira/browse/WW-4559
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Dispatch Filter
>            Reporter: Alireza Fattahi
>            Priority: Minor
>             Fix For: 6.1.0
>
>
> In a strust2 + Spring 4 project
> Consider a simple action with stream result 
> {code:title=Bar.java|borderStyle=solid}
> @Action(value = "sample-export", 
>         results = { @Result(name = "success", type = "stream", params = {
>         "inputName", "exportInputStream", "contentType",
>         "${exportContentType}; charset=UTF-8", "Content-Disposition",
>         "attachment; filename=\"${filename}\"", "contentDisposition",
>         "attachment; filename=\"${filename}\"", "bufferSize", "2048" }) })
> public String export() throws ClientException {
>     //buildExportInputStream() creates and returns new ByteArrayOutputStream by using jasper
>     exportInputStream = buildExportInputStream();
>     LOG.debug("Exporting to {} file ", getFilename());
>     return SUCCESS;
> }
> {code}
> This works fine,
> Now define a bean 
> {code:xml}
>  <bean id="sampleStream" class="java.io.FileInputStream" >
>         <constructor-arg  value="c:/sample.jks"/>  
>   </bean>
> {code}
> The export will not work correctly any more, first time you get the c:/sample.jks as file and then an  error which same stream already closed.
> I have found that the sampleStream will be autowired to org.apache.struts2.dispatcher.StreamResult and I see this log:
> {panel:title=LOG|borderStyle=dashed|borderColor=#ccc|titleBGColor=#F7D6C1|bgColor=#FFFFCE}
> DEBUG ort.DefaultListableBeanFactory Returning cached instance of singleton bean 'sampleStream'
> DEBUG ort.DefaultListableBeanFactory Autowiring by type from bean name 'org.apache.struts2.dispatcher.StreamResult' via constructor to bean named 'sampleStream'
> {panel}
> This mistaken autowired is the source of problem ! Is there any workaround. And by the way, why the sampleStream is autowired here !



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