struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alireza Fattahi <afatt...@yahoo.com.INVALID>
Subject Define a bean of java.io.FileInputStream in Spring makes the Struts stream result not work
Date Sun, 25 Oct 2015 15:15:34 GMT
We are using the struts with spring in a project.

Consider a simple action with **stream** result 

    @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;

    }


This works fine. 

Some thing strange happens when I add below line in `spring-applicaiton-context.xml` !!

      <bean id="sampleStream" class="java.io.FileInputStream" >
            <constructor-arg  value="c:/sample.jks"/>  
      </bean>

After adding above line the inputStream of action will be a zero size file! When I set a break
point in **StreamResult**,  **doExecute** method the `inputStream.read(oBuff)` is always
**-1**.

--------
The created bean (**sampleStream**) will be referenced by other beans by using ref for example
`<ref bean="sampleStream"/>`. When I change this structure and use **sampleStream**
as an inline parameter it works fine:

    <bean id="anotherBean" class="foo.bar">
            <bean class="org.xml.sax.InputSource">
                <constructor-arg index="0" >
                        <bean class="java.io.FileInputStream">
                            <constructor-arg index="0" type="java.lang.String"
value="c:/sample.jks"/>
                        </bean>
                </constructor-arg>
            </bean>
        </property>
    </bean>

------------

Well can you help me to find what is going wrong ?! Why defining a bean of `FileInputStream`
will cause this happens ?!

Also asked at:Define a bean of java.io.FileInputStream in Spring makes the Struts stream result
not work
|   |
|   |  |   |   |   |   |   |
| Define a bean of java.io.FileInputStream in Spring makes...We are using the struts with
spring in a project. Consider a simple action with stream result @Action(value = "sample-export",
results = { @Result(name = "success",... |
|  |
| View on stackoverflow.com | Preview by Yahoo |
|  |
|   |


 ~Regards,
~~Alireza Fattahi
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message