Bug 17211

Summary: FIX: Tomcat 4.1.x taglib pooling causes problems
Product: Taglibs Reporter: Eduardo Suastegui <esuastegui>
Component: XTags TaglibAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED LATER    
Severity: blocker    
Priority: P3    
Version: 1.1   
Target Milestone: ---   
Hardware: Other   
OS: other   

Description Eduardo Suastegui 2003-02-19 18:12:28 UTC
I am running Tomcat 4.1.18 with JDK 1.4.1.01, and use the xtags library for
server-side XSL transformation (XSLT). The first time I access the page that
includes XML to be displayed through xtags' XSLT, it works. The 2nd time, it
fails (see exception stack trace below), the 3rd time it works, the 4th time
it fails, and so on--odds are okay; evens fail. I do not have this problem
with either Tomcat 4.0.3 or 4.0.6; when I switch to these versions, all
works as expected. I have also tried disabling taglibs pooling in the
web.xml for 4.1.18, and though that works, it is a work-around, so I offer the 
following fix.

With thanks to David Spencer for pointing me in the right direction, I would
like to submit the following fix to 
org.apache.taglibs.xtags.xslt.StyleTag.java. I only list code that has
changed from the source base (which I downloaded 3 days ago).

    /** Perform the transformation and render the output.
      *
      * @exception JspException if a JSP exception occurs
      */
    public int doEndTag() throws JspException {
        if ( xml == null || xsl == null ) {
            throw new JspException( "Must specify both XML and an XSLT to
style" );
        }
        
        // Prepare an input source for the data
        System.out.print("XML: ");
        Source data = getSource(xml);

        // Prepare an input source for the stylesheet
        System.out.print("XSL: ");
        Source style = getSource(xsl);

        // Prepare an output source for the outputs
        Result result = getResult();

        // Use JAXP to perform the stylesheet
        try {
            TransformerFactory factory = TransformerFactory.newInstance();
            factory.setURIResolver( createURIResolver() );
            Transformer transformer = factory.newTransformer(style);
            configure(transformer);
            transformer.transform( data, result );
            if ( stringWriter != null ) {
                pageContext.getOut().write( stringWriter.toString() );
            }
        } 
        catch (TransformerException e) {
            handleException(e);
        }
        catch (IOException e) {
            handleException(e);
        }
        finally {
            stringWriter = null;
            // Release state to help out with Tomcat 4.1.18:
            cleanUp();
        }
	return EVAL_PAGE;
    }
    
    /**
     * Since Tomcat 4.1.18 uses taglibs pooling, we must clean up (release
     * state) after doEndTag().
     * E. Suastegui -- 02/14/03
     */
    private void cleanUp()
    {
        xml = null;
        xsl = null;
        result = null;
        parameters = null;
    }

    
    /**
     * Release any allocated resources.
     */
    public void release() {
	    cleanUp();
    }
Comment 1 David Valentine 2003-03-09 07:41:29 UTC
Just ran into this problem. My fix. Parse it first

<xtags:parse id="areport">
   some information
</xtags:parse>
<xtags:style document="<%= areport %>"
 style="style" />
Comment 2 Henri Yandell 2009-11-29 19:47:11 UTC
Resolving. Taglib has been retired.