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

premature close of stream in XLSTResult

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.11
    • Fix Version/s: 2.1.2
    • Component/s: Core Actions
    • Labels:
      None
    • Environment:

      Struts-2.0.11

      Description

      //2 streams are created from same Response
      //when the stream is closed the writer for the second becomes non-operational..

      public void execute(ActionInvocation invocation) throws Exception {
      long startTime = System.currentTimeMillis();
      String location = getStylesheetLocation();
      if (parse)

      { ValueStack stack = ActionContext.getContext().getValueStack(); location = TextParseUtil.translateVariables(location, stack); }

      try {
      HttpServletResponse response = ServletActionContext.getResponse();
      /***********************HERE is a PrintWriter object that can return character data to the client************************/
      Writer writer = response.getWriter();
      // Create a transformer for the stylesheet.
      Templates templates = null;
      Transformer transformer;
      if (location != null)

      { templates = getTemplates(location); transformer = templates.newTransformer(); }

      else
      transformer = TransformerFactory.newInstance().newTransformer();

      transformer.setURIResolver(getURIResolver());
      String mimeType;
      if (templates == null)
      mimeType = "text/xml"; // no stylesheet, raw xml
      else
      mimeType = templates.getOutputProperties().getProperty(OutputKeys.MEDIA_TYPE);
      if (mimeType == null)

      { // guess (this is a servlet, so text/html might be the best guess) mimeType = "text/html"; }

      response.setContentType(mimeType);
      Object result = invocation.getAction();
      if (exposedValue != null)

      { ValueStack stack = invocation.getStack(); result = stack.findValue(exposedValue); }

      Source xmlSource = getDOMSourceForStack(result);

      // Transform the source XML to System.out.
      /************************Why a second writer ..whats wrong with writer???*******************************/
      PrintWriter out = response.getWriter();
      LOG.debug("xmlSource = " + xmlSource);
      transformer.transform(xmlSource, new StreamResult(out));
      /*************************TROUBLE here closing The character-output stream of this PrintWriter. **************/
      out.close(); // ...and flush...
      if (LOG.isDebugEnabled())

      { LOG.debug("Time:" + (System.currentTimeMillis() - startTime) + "ms"); }

      /***********Whats this flush doing here the character output-stream is already closed!***********/
      writer.flush();

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mrdon Donald J. Brown
                Reporter:
                mgainty Martin Gainty
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: