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

Don Brown resolved WW-2551.
---------------------------

       Resolution: Fixed
    Fix Version/s: 2.1.2
         Assignee: Don Brown

Fixed, thanks for the detailed solution

> premature close of stream in XLSTResult
> ---------------------------------------
>
>                 Key: WW-2551
>                 URL: https://issues.apache.org/struts/browse/WW-2551
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: Struts-2.0.11
>            Reporter: Martin Gainty
>            Assignee: Don Brown
>            Priority: Critical
>             Fix For: 2.1.2
>
>
> //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();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to