Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4559

Define a bean of java.io.FileInputStream in Spring makes the Struts stream result not work

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 2.5.x
    • Component/s: Dispatch Filter
    • Labels:
      None

      Description

      In a strust2 + Spring 4 project

      Consider a simple action with stream result

      Bar.java
      @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,

      Now define a bean

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

      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:

      LOG

      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'

      This mistaken autowired is the source of problem ! Is there any workaround. And by the way, why the sampleStream is autowired here !

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              afattahi Alireza Fattahi
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: