This is because when you end a pipeline with the map:redirect, nothing else gets executed. The redirect happens when the pipeline is setup. We've had need for similar pipelines where processing is done, then a redirect is performed. We wrote a redirect transformer that we'd be glad to contribute. It takes a url in XML or as a sitemap parameter. Instead of doing a redirect during setup, it does it when endDocument is called.

David

PS. coding credits to Daniel McOrmond of D.O.Tech

Dean Cording wrote:
I am having some problems with SQLTransformer not commiting inserts into a database.  I am running Cocoon 2.1 and MS SQLServer.
 
My pipeline looks like:
 
               <map:match pattern="CodeCreate-add">
                    <map:generate type="request"/>
                    
                    <map:transform type="xslt" src="">
                        <map:parameter name="use-request-parameters" value="true"/>
                    </map:transform>
                   
                    <map:transform type="sql">                              
                        <map:parameter name="use-connection" value="{global:db-connection}"/>
                        <map:parameter name="show-nr-of-rows" value="true"/>
                        <map:parameter name="isupdate" value="true"/>
                    </map:transform>
                   
                    <!-- Redirect back to the table display page -->
                    <map:redirect-to uri="CodeTableList"/>                    
                </map:match>
 
 
And CodeAddTest.xsl looks like:
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:sql="http://apache.org/cocoon/SQL/2.0">
    <xsl:param name="CodeType"/>
    <xsl:param name="CodeValue"/>
   
    <xsl:template match="/">
                         
    <page>
        <execute-query xmlns="http://apache.org/cocoon/SQL/2.0">
            <query> 
                INSERT INTO Codes (CodeType, CodeValue)
                VALUES ('<xsl:value-of select="$CodeType"/>', '<xsl:value-of select="$CodeValue"/>')
            </query>
        </execute-query>
    </page> 
   
    </xsl:template>
   
</xsl:stylesheet>
 
The values to be inserted are generated from a form and passed in as request parameters.  At the end of the pipeline it redirects to a list page that shows all of the values in the database.  The problem is that the new values aren't being inserted.  If I remove the redirect (and replace it with a static page for example) then the insert works fine.
 
 
Any ideas?
 
 
Thanks,
 
Dean
package com.dotech.cocoon.transformation;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.cocoon.environment.http.HttpResponse;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.AbstractSAXTransformer;
import org.apache.cocoon.ProcessingException;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;

import java.io.IOException;
import java.util.Map;


/**
 * The Redirect Transformer
 * 
 * redirects the user to another url. You can specify the new url within an xml file
 * and it can also be specified as a transformer parameter in the sitemap. <i>A 
redirect url
 * specified in the xml takes higher precendence than a redirect url specified in the 
sitemap</i>.
 *
 * <br/><br/>
 * XML Example:
 * <pre>
 * &lt;redirect 
xmlns="http://dotech.com/redirect/1.0"&gt;http://www.dotech.com&lt;/redirect&gt;
 * </pre>
 *
 * <b>The url can be either fully qualified or relative</b>.
 * <br/><br/>
 * Sitemap Example:
 * <pre>
 * &lt;map:transformer type="redirect"&gt;
 * &lt;map:parameter name="redirectURL" value="http://www.dotech.com"/&gt;
 * &lt;/map:transformer&gt;
 * </pre>
 *
 * If an url is not specified in either place, this transformer acts as if it didn't 
exist. The
 * sitemap execution passes on to the next component.
 * 
 * @author <a href="mailto:[EMAIL PROTECTED]">Daniel McOrmond</a>
 * @version $Revision: 1.2 $ $Date: 2003/07/22 02:41:34 $
 */

public class RedirectTransformer extends AbstractSAXTransformer {

        public static final String NAMESPACE = "http://dotech.com/redirect/1.0";;
        private String redirectLocation;

        public RedirectTransformer() {
                this.namespaceURI = NAMESPACE;  
        }

        public void setupTransforming() throws IOException, ProcessingException, 
SAXException {
                super.setupTransforming();
                redirectLocation = parameters.getParameter("redirectURL", "");
                getLogger().debug("redirect URL set from param : "+redirectLocation);
        }

        public void endDocument() throws SAXException {

                if (redirectLocation != null && !redirectLocation.trim().equals("")) {
                        HttpResponse hr = (HttpResponse)response;
                        try {
                                getLogger().debug("about to set redirect on response 
object : "+redirectLocation);
                                hr.sendRedirect( redirectLocation );
                        } catch( Exception e ) { getLogger().error( "some error", e ); 
}
                        response = hr;
                }
        }

        public void startTransformingElement(String uri, String name, String raw, 
Attributes attr) 
                throws ProcessingException, IOException, SAXException {

                if( name.toLowerCase().equals("redirect") ) {
                        startTextRecording();
                }
        }

        public void endTransformingElement(String uri, String name, String raw) 
                throws ProcessingException, IOException, SAXException {


                if( name.toLowerCase().equals("redirect") ) {
                        redirectLocation = endTextRecording();  
                        getLogger().debug("redirect URL set from xml : 
"+redirectLocation);
                }
        }

} //RedirectTransformer

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to