Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000456 [Resin] minor always 11-17-05 00:00 01-27-06 14:48
Reporter urutora90 View Status public  
Assigned To ferg
Priority high Resolution fixed  
Status closed   Product Version 3.0.15
Summary 0000456: Error when doing xsl transformation: flush() may not be called in a body
Description RSN-505
The following JSP throws an exception when called:

test.jsp:
----------
<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" [^] prefix="x" %>
<%@ taglib uri="http://java.sun.com/jstl/core" [^] prefix="c" %>

<c:set var="sheet"><?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> [^]
        <xsl:template match="/">
            <div>hello world</div>
        </xsl:template>
    </xsl:stylesheet>
</c:set>

<c:set var="result">
    <x:transform xslt="${sheet}" xsltSystemId="xslt">
        <foo/>
    </x:transform>
</c:set>

<c:out value="${result}"/>

----------

The stack trace I get is:

javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.xml.transform.TransformerException: java.io.IOException: flush() may not be called in a body
    at com.caucho.jsp.PageContextImpl.handlePageException(PageContextImpl.java:1058)
    at _jsp._test__jsp._jspService(_test__jsp.java:68)
    at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
    at com.caucho.jsp.Page.pageservice(Page.java:570)
    at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:159)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:259)
    at com.caucho.server.port.TcpConnection.run(TcpConnection.java:386)
    at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:490)
    at com.caucho.util.ThreadPool.run(ThreadPool.java:423)
    at java.lang.Thread.run(Thread.java:534)
Caused by: javax.servlet.jsp.JspException: javax.xml.transform.TransformerException: java.io.IOException: flush() may not be called in a body
    at com.caucho.jstl.rt.XmlTransformTag.doEndTag(XmlTransformTag.java:223)
    at _jsp._test__jsp._jspService(_test__jsp.java:53)
    ... 10 more
Caused by: javax.xml.transform.TransformerException: java.io.IOException: flush() may not be called in a body
    at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1276)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:668)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1129)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1107)
    at com.caucho.jstl.rt.XmlTransformTag.doEndTag(XmlTransformTag.java:218)
    ... 11 more
Caused by: java.io.IOException: flush() may not be called in a body
    at org.apache.xalan.serialize.SerializerToXML.flushWriter(SerializerToXML.java:1514)
    at org.apache.xalan.serialize.SerializerToXML.endDocument(SerializerToXML.java:738)
    at org.apache.xalan.transformer.ResultTreeHandler.endDocument(ResultTreeHandler.java:192)
    at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1224)
    ... 15 more


The XSLT related system properties I've specified in resin.conf are:

<system-property javax.xml.parsers.DocumentBuilderFactory=
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
<system-property javax.xml.transform.TransformerFactory=
"org.apache.xalan.processor.TransformerFactoryImpl"/>
Additional Information Windows XP, JDK 1.4.2_10 (issue exists also mit JDK 5 update 5), Fast-JSTL
Attached Files

- Relationships

- Notes
(0000485)
urutora90
11-17-05 00:00

After some research, I found out that the cause is com.caucho.jsp.BodyContentImpl since flush() will always throw an IOException since 3.0.15 (this seems to be the correct behaviour according to the JspWriter API).

This bug can be circumvented by changing for example com.caucho.jstl.rt.XmlTransformTag (line 204) to:
      Result result;
      Node top = null;
      java.io.StringWriter buffer = null;
      if (_result != null) {
        result = (Result) _result;
      }
      else if (_var != null) {
        top = new com.caucho.xml.QDocument();
        
        result = new DOMResult(top);
      }
      else {
        buffer = new java.io.StringWriter();
        result = new StreamResult(buffer);
      }

      transformer.transform(source, result);

      if (_result != null) {
      } else if (_var != null)
        CoreSetTag.setValue(pageContext, _var, _scope, top);
      else {
        out.print(buffer.getBuffer().toString());
      }
 

- Issue History
Date Modified Username Field Change
11-17-05 00:00 urutora90 New Issue
01-27-06 14:48 ferg Assigned To  => ferg
01-27-06 14:48 ferg Status acknowledged => closed
01-27-06 14:48 ferg Resolution open => fixed
01-27-06 14:48 ferg Fixed in Version  => 3.0.18


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
28 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker