You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Alireza Fattahi (JIRA)" <ji...@apache.org> on 2015/11/03 08:38:27 UTC
[jira] [Created] (WW-4559) Define a bean of java.io.FileInputStream
in Spring makes the Struts stream result not work
Alireza Fattahi created WW-4559:
-----------------------------------
Summary: 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
Fix For: 2.3.x
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=My Title|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
(v6.3.4#6332)