Only a week ago I was in a need of a proxy generator which will handle
POST/GET to generate HTML from external sources for embedding in my
Forrest site. None of the generator classes seem to have done the job
so I finally merged parts a proxy generated I found under Lenya with
the Cocoon HTMLGenerator, with the built-in jtidy support. If none of
the existing proxy generators do the job for you, try to compile the
following and put a line like this in your sitemap.xmap:


 <map:components>
   ....
   <map:generators default="file">
      ....
     <map:generator name="proxy"
src="org.nargila.cocoon.generation.MyHttpProxyGenerator">
        <jtidy-config>WEB-INF/jtidy.properties</jtidy-config>
     </map:generator>
    ...
   </map:generators default="file">
   ...
</map:components>

============== MyHttpProxyGenerator.java ===========
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nargila.cocoon.generation;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.ResourceNotFoundException;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Response;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.generation.ServiceableGenerator;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.xml.dom.DOMStreamer;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpURL;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.xml.sax.SAXParser;
import org.apache.excalibur.xml.xpath.XPathProcessor;
import org.w3c.dom.NodeList;
import org.w3c.tidy.Tidy;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

/**
 * The <code>HttpProxyGenerator</code> is a Cocoon generator using the
 * <b>Jakarta Commons HTTPClient Library</b> to access an XML stream
* over HTTP.
*
 * @author <a href="mailto:[EMAIL PROTECTED]">Ivelin Ivanov</a>, June 2002
* @author <a href="mailto:[EMAIL PROTECTED]">Tony Collen</a>, December 2002
 * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>, February 2003
 * @version CVS $Id: HttpProxyGenerator.java 433543 2006-08-22
06:22:54Z crossley $
*/
public class MyHttpProxyGenerator extends ServiceableGenerator
implements Configurable {
//    private static Logger log = Logger.getLogger(MyHttpProxyGenerator.class);

        /** The HTTP method to use at request time. */
        private HttpMethodBase method = null;
        /** The base HTTP URL for requests. */
        private HttpURL url = null;
        /** The list of request parameters for the request */
        private ArrayList reqParams = null;
        /** The list of query parameters for the request */
        private ArrayList qryParams = null;
        /** Wether we want a debug output or not */
        private boolean debug = false;
        private String xpath;
        private XPathProcessor processor;
        private Properties properties;
        private Map cookies = new HashMap();
        
        /**
         * Default (empty) constructor.
         */
        public MyHttpProxyGenerator() {
                super();
        }
        
        /**
         * Set up this <code>Generator</code> instance from its sitemap
<code>Configuration</code>
         *
         * @param configuration The base <code>Configuration</code> for this
<code>Generator</code>.
         * @throws ConfigurationException If this instance cannot be
configured properly.
         * @see #recycle()
         */
        public void configure(Configuration configuration)
        throws ConfigurationException {
                
                /* Setup the HTTP method to use. */
                String method = 
configuration.getChild("method").getValue("GET");
                if ("GET".equalsIgnoreCase(method)) {
                        this.method = new GetMethod();
                } else if ("POST".equalsIgnoreCase(method)) {
                        this.method = new PostMethod();
                        /* TODO: Is this still needed? Does it refer to a bug 
in bugzilla?
                         *       At least the handling in httpclient has 
completely changed.
                         * Work around a bug from the HttpClient library */
                        ((PostMethod) this.method).setRequestBody("");
                } else {
                        throw new ConfigurationException("Invalid method \"" + method + 
"\"
specified"
                                        + " at " + 
configuration.getChild("method").getLocation());
                }
                
                /* Create the base URL */
                String url = configuration.getChild("url").getValue(null);
                try {
                        if (url != null) this.url = new HttpURL(url);
                } catch (URIException e) {
                        throw new ConfigurationException("Cannot process URL 
\"" + url +
"\" specified"
                                        + " at " + 
configuration.getChild("url").getLocation());
                }
                
                String configUrl = 
configuration.getChild("jtidy-config").getValue(null);
                
                if(configUrl != null) {
                        org.apache.excalibur.source.SourceResolver resolver = 
null;
                        Source configSource = null;
                        try {
                                resolver = 
(org.apache.excalibur.source.SourceResolver)this.manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE);
                                configSource = resolver.resolveURI(configUrl);
                                if (getLogger().isDebugEnabled()) {
                                        getLogger().debug("Loading configuration 
from " + configSource.getURI());
                                }
                                
                                this.properties = new Properties();
                                
this.properties.load(configSource.getInputStream());
                                
                        } catch (Exception e) {
                                getLogger().warn("Cannot load configuration from 
" + configUrl);
                                throw new ConfigurationException("Cannot load 
configuration from "
+ configUrl, e);
                        } finally {
                                if ( null != resolver ) {
                                        this.manager.release(resolver);
                                        resolver.release(configSource);
                                }
                        }
                }
                
                /* Prepare the base request and query parameters */
                this.reqParams = 
this.getParams(configuration.getChildren("param"));
                this.qryParams = 
this.getParams(configuration.getChildren("query"));
        }
        
        /**
         * Setup this <code>Generator</code> with its runtime configurations
and parameters
         * specified in the sitemap, and prepare it for generation.
         *
         * @param sourceResolver The <code>SourceResolver</code> instance
resolving sources by
         *                       system identifiers.
         * @param objectModel The Cocoon "object model" <code>Map</code>
         * @param parameters The runtime <code>Parameters</code> instance.
         * @throws ProcessingException If this instance could not be setup.
         * @throws SAXException If a SAX error occurred during setup.
         * @throws IOException If an I/O error occurred during setup.
         * @see #recycle()
         */
        public void setup(SourceResolver sourceResolver, Map objectModel,
                        String source, Parameters parameters)
        throws ProcessingException, SAXException, IOException {
                /* Do the usual stuff */
                super.setup(sourceResolver, objectModel, source, parameters);
                
                /*
                 * Parameter handling: In case the method is a POST method, 
query
                 * parameters and request parameters will be two different 
arrays
                 * (one for the body, one for the query string, otherwise it's 
going
                 * to be the same one, as all parameters are passed on the 
query string
                 */
                ArrayList req = new ArrayList();
                ArrayList qry = req;
                if (this.method instanceof PostMethod) qry = new ArrayList();
                req.addAll(this.reqParams);
                qry.addAll(this.qryParams);

                /*
                 * Parameter handling: complete or override the configured 
parameters with
                 * those specified in the pipeline.
                 */
                String names[] = parameters.getNames();
                for (int x = 0; x < names.length; x++) {
                        String name = names[x];
                        String value = parameters.getParameter(name, null);
                        if (value == null) continue;
                        
                        if (name.startsWith("query:")) {
                                name = name.substring("query:".length());
                                qry.add(new NameValuePair(name, value));
                        } else if (name.startsWith("param:")) {
                                name = name.substring("param:".length());
                                req.add(new NameValuePair(name, value));
                        } else if (name.startsWith("query-override:")) {
                                name = 
name.substring("query-override:".length());
                                qry = overrideParams(qry, name, value);
                        } else if (name.startsWith("param-override:")) {
                                name = 
name.substring("param-override:".length());
                                req = overrideParams(req, name, value);
                        } else if (name.startsWith("cookie:")) {
                                name = name.substring("cookie:".length());
                                this.cookies.put(name, value);
                        }
                }
                
                /* Process the current source URL in relation to the configured 
one */
                HttpURL src = (super.source == null ? null : new 
HttpURL(super.source));
                if (this.url != null) src = (src == null ? this.url : new
HttpURL(this.url, src));
                if (src == null) throw new ProcessingException("No URL 
specified");
                if (src.isRelativeURI()) {
                        throw new ProcessingException("Invalid URL \"" + src.toString() + 
"\"");
                }
                
                /* Configure the method with the resolved URL */
                HostConfiguration hc = new HostConfiguration();
                hc.setHost(src);
                this.method.setHostConfiguration(hc);
                this.method.setPath(src.getPath());
                this.method.setQueryString(src.getQuery());
                
                /* And now process the query string (from the parameters above) 
*/
                if (qry.size() > 0) {
                        String qs = this.method.getQueryString();
                        NameValuePair nvpa[] = new NameValuePair[qry.size()];
                        this.method.setQueryString((NameValuePair []) 
qry.toArray(nvpa));
                        if (qs != null) {
                                this.method.setQueryString(qs + "&" + 
this.method.getQueryString());
                        }
                }
                
                /* Finally process the body parameters */
                if ((this.method instanceof PostMethod) && (req.size() > 0)) {
                        PostMethod post = (PostMethod) this.method;
                        NameValuePair nvpa[] = new NameValuePair[req.size()];
                        post.setRequestBody((NameValuePair []) 
req.toArray(nvpa));
                }
                
                this.xpath = parameters.getParameter("xpath",null);
                
                /* Check the debugging flag */
                this.debug = parameters.getParameterAsBoolean("debug", false);
        }
        
        /**
         * Recycle this instance, clearing all done during setup and
generation, and reverting
         * back to what was configured in the sitemap.
         *
         * @see #configure(Configuration)
         * @see #setup(SourceResolver, Map, String, Parameters)
         * @see #generate()
         */
        public void recycle() {
                /* Recycle the method */
                this.method.recycle();
                /* TODO: Is this still needed? Does it refer to a bug in 
bugzilla?
                 *       At least the handling in httpclient has completely 
changed.
                 *  Work around a bug from the HttpClient library */
                if (this.method instanceof PostMethod) ((PostMethod)
this.method).setRequestBody("");
                
                /* Clean up our parent */
                super.recycle();
        }
        
        /**
         * Generate debugging output as XML data from the current configuration.
         *
         * @throws SAXException If an error occurred parsing or processing
XML in the pipeline.
         * @throws IOException If an I/O error occurred accessing the HTTP 
server.
         */
        private void generateDebugOutput()
        throws SAXException, IOException {
                super.xmlConsumer.startDocument();
                
                AttributesImpl attributes = new AttributesImpl();
                attributes.addAttribute("", "method", "method", "CDATA",
this.method.getName());
                attributes.addAttribute("", "url", "url", "CDATA",
this.method.getURI().toString());
                attributes.addAttribute("", "protocol", "protocol", "CDATA",
                                (this.method.isHttp11() ? "HTTP/1.1" : 
"HTTP/1.0"));
                super.xmlConsumer.startElement("", "request", "request", 
attributes);
                
                if (this.method instanceof PostMethod) {
                        String body = ((PostMethod) 
this.method).getRequestBodyAsString();
                        
                        attributes.clear();
                        attributes.addAttribute("", "name", "name", "CDATA", 
"Content-Type");
                        attributes.addAttribute("", "value", "value", "CDATA",
"application/x-www-form-urlencoded");
                        super.xmlConsumer.startElement("", "header", "header", 
attributes);
                        super.xmlConsumer.endElement("", "header", "header");
                        
                        attributes.clear();
                        attributes.addAttribute("", "name", "name", "CDATA", 
"Content-Length");
                        attributes.addAttribute("", "value", "value", "CDATA",
Integer.toString(body.length()));
                        super.xmlConsumer.startElement("", "header", "header", 
attributes);
                        super.xmlConsumer.endElement("", "header", "header");
                        
                        attributes.clear();
                        super.xmlConsumer.startElement("", "body", "body", 
attributes);
                        super.xmlConsumer.characters(body.toCharArray(), 0, 
body.length());
                        super.xmlConsumer.endElement("", "body", "body");
                }
                
                super.xmlConsumer.endElement("", "request", "request");
                
                super.xmlConsumer.endDocument();
                return;
        }
        
        /**
         * Prepare a map of parameters from an array of 
<code>Configuration</code>
         * items.
         *
         * @param configurations An array of <code>Configuration</code> 
elements.
         * @return A <code>List</code> of <code>NameValuePair</code> elements.
         * @throws ConfigurationException If a parameter doesn't specify a name.
         */
        private ArrayList getParams(Configuration configurations[])
        throws ConfigurationException {
                ArrayList list = new ArrayList();
                
                if (configurations.length < 1) return (list);
                
                for (int x = 0; x < configurations.length; x++) {
                        Configuration configuration = configurations[x];
                        String name = configuration.getAttribute("name", null);
                        if (name == null) {
                                throw new ConfigurationException("No name specified 
for parameter at "
                                                + configuration.getLocation());
                        }
                        
                        String value = configuration.getAttribute("value", 
null);
                        if (value != null) list.add(new NameValuePair(name, 
value));
                        
                        Configuration subconfigurations[] = 
configuration.getChildren("value");
                        for (int y = 0; y < subconfigurations.length; y++) {
                                value = subconfigurations[y].getValue(null);
                                if (value != null) list.add(new 
NameValuePair(name, value));
                        }
                }
                
                return (list);
        }
        
        /**
         * Override the value for a named parameter in a specfied
<code>ArrayList</code>
         * or add it if the parameter was not found.
         *
         * @param list The <code>ArrayList</code> where the parameter is stored.
         * @param name The parameter name.
         * @param value The new parameter value.
         * @return The same <code>List</code> of <code>NameValuePair</code> 
elements.
         */
        private ArrayList overrideParams(ArrayList list, String name, String 
value) {
                Iterator iterator = list.iterator();
                while (iterator.hasNext()) {
                        NameValuePair param = (NameValuePair) iterator.next();
                        if (param.getName().equals(name)) {
                                iterator.remove();
                                break;
                        }
                }
                list.add(new NameValuePair(name, value));
                return (list);
        }
        
        /**
         * @see org.apache.cocoon.generation.Generator#generate()
         */
        public void generate()
        throws ResourceNotFoundException, ProcessingException, SAXException,
IOException {
                Request request = 
(Request)objectModel.get(ObjectModelHelper.REQUEST_OBJECT);
                Response response =
(Response)objectModel.get(ObjectModelHelper.RESPONSE_OBJECT);
//                          
log.debug("\n----------------------------------------------------------------"
//                                  + "\n- Request: (" + 
request.getClass().getName() +
") at port "
//                                  + request.getServerPort()
//                                  +
"\n----------------------------------------------------------------");
                // Return XML
                try {
                        
                        String submitMethod = request.getMethod();
                        
                        SAXParser parser = null;
                        
                        URL url = new URL(this.source);
                        
                        // Forward "InputStream", Parameters, QueryString to 
Servlet
                        HttpMethod httpMethod = null;
                        
                        if (submitMethod.equals("POST")) {
                                httpMethod = new PostMethod();
                                
                                Enumeration params = 
request.getParameterNames();
                                
                                while (params.hasMoreElements()) {
                                        String paramName = (String) 
params.nextElement();
                                        String[] paramValues = 
request.getParameterValues(paramName);
                                        
                                        for (int i = 0; i < paramValues.length; 
i++) {
                                                ((PostMethod) 
httpMethod).setParameter(paramName, paramValues[i]);
                                        }
                                }
                        } else if (submitMethod.equals("GET")) {
                                httpMethod = new GetMethod();
                                
httpMethod.setQueryString(request.getQueryString());
                        }
                        
                        // Copy/clone Cookies
                        org.apache.cocoon.environment.Cookie[] cookies = 
request.getCookies();
                        org.apache.commons.httpclient.Cookie[] 
transferedCookies = null;
                        
                        if (cookies != null) {
                                transferedCookies = new
org.apache.commons.httpclient.Cookie[cookies.length];
                                
                                for (int i = 0; i < cookies.length; i++) {
                                        boolean secure = false; // http: false, 
https: true
                                        
                                        final String name =  
cookies[i].getName();
                                        
                                if ("!".equals(this.cookies.get(name))) {
//                              System.err.println("skipping cookie: Name=" + 
name +
"value=" + cookies[i].getValue() + " file=" + url.getFile());
//                                  log.debug("skipping header: Name=" + name + 
"value="
+ request.getHeader(name));
                                                // filter this header
                                        } else {
                        
                                                transferedCookies[i] = new
org.apache.commons.httpclient.Cookie(url.getHost(),
                                                                
cookies[i].getName(), cookies[i].getValue(), url.getFile(), null,
                                                                secure);
                                        }
                                }
                        }
                        
                        // Initialize HttpClient
                        HttpClient httpClient = new HttpClient();
                        
                        // Set cookies
                        if ((transferedCookies != null) && 
(transferedCookies.length > 0)) {
                                HttpState httpState = new HttpState();
                                httpState.addCookies(transferedCookies);
                                httpClient.setState(httpState);
                        }
                        
                        // DEBUG cookies
                        // Send request to servlet
                        //              httpMethod.setRequestHeader("Content-type", 
"text/plain");
                        httpMethod.setPath(url.getPath());
                        
                        httpMethod.setFollowRedirects(true);
                        
                        // FIXME
                        for (Enumeration e = request.getHeaderNames(); 
e.hasMoreElements();) {
                                String name = (String) e.nextElement();
                                
//                  log.debug("Header Name=" + name + "value=" +
request.getHeader(name));

                        httpMethod.addRequestHeader(name, 
request.getHeader(name));                             
                        }
                        
                        HostConfiguration hostConfiguration = new 
HostConfiguration();
                        hostConfiguration.setHost(url.getHost(), url.getPort(), 
url.getProtocol());
                        
                        //              
log.debug("\n----------------------------------------------------------------"
                        //                      + "\n- Starting session at URI: " + 
url + "\n-
Host:                    "
                        //                      + url.getHost() + "\n- Port:
" + url.getPort()
                        //                      +
"\n----------------------------------------------------------------");
                        
                        int result = httpClient.executeMethod(hostConfiguration,
httpMethod);
                        
                        // Send the output to the client: set the status code...
                        //response.setStatus(result);
                        
                        String redirectUrl = null;
                        
                        // ... retrieve the headers from the origin server and 
pass them on
                        Header[] methodHeaders = 
httpMethod.getResponseHeaders();
                        for (int i = 0; i < methodHeaders.length; i++) {
                                if (result >= 300 && result < 400 &&
methodHeaders[i].getName().equalsIgnoreCase("Location")) {
                                        redirectUrl = 
methodHeaders[i].getValue();
                                }
                                
                                // there is more than one DAV header
                                if (methodHeaders[i].getName().equals("DAV")) {
                                        
response.addHeader(methodHeaders[i].getName(),
methodHeaders[i].getValue());
                                } else if 
(methodHeaders[i].getName().equals("Content-Length")) {
                                        // drop the original Content-Length 
header. Don't ask me why but there
                                        // it's always one byte off
                                } else {
                                        
response.setHeader(methodHeaders[i].getName(),
methodHeaders[i].getValue());
                                }
                        }
                        
                        
                        //              
log.debug("\n----------------------------------------------------------------"
                        //                      + "\n- Result:                    
" + result
                        //                      +
"\n----------------------------------------------------------------");
                        
                        // Handle GZIP Content-Encoding
                        InputStream is  = httpMethod.getResponseBodyAsStream();
                        
                        
                        if (result >= 300 && result < 400) {
                                objectModel.put("new-location", new 
URL(redirectUrl));                                
                                
                                String xml = "<html><body>\n";
                                xml += "<script 
type='text/javascript'>document.location = '" +
redirectUrl + "';</script>\n";
                                xml += "<noscript>To continue, click on the following 
link:<br/>\n";
                                xml += "<a href='" +  redirectUrl + "'>" + 
redirectUrl +
"</a>\n</noscript>\n";
                                xml += "</body></html>";
                                
                                is = new 
ByteArrayInputStream(xml.getBytes("UTF-8"));
                        }
                        
                        // Setup an instance of Tidy.
                        Tidy tidy = new Tidy();
                        tidy.setXmlOut(true);
                        
                        if (this.properties == null) {
                                tidy.setXHTML(true);
                        } else {
                                tidy.setConfigurationFromProps(this.properties);
                        }
                        
                        //Set Jtidy warnings on-off
                        tidy.setShowWarnings(getLogger().isWarnEnabled());
                        //Set Jtidy final result summary on-off
                        tidy.setQuiet(!getLogger().isInfoEnabled());
                        //Set Jtidy infos to a String (will be logged) instead 
of System.out
                        StringWriter stringWriter = new StringWriter();
                        PrintWriter errorWriter = new PrintWriter(stringWriter);
                        tidy.setErrout(errorWriter);
                        
                        // Extract the document using JTidy and stream it.
                        
                        
                        org.w3c.dom.Document doc = tidy.parseDOM(new 
BufferedInputStream(is), null);
                        
                        // FIXME: Jtidy doesn't warn or strip duplicate 
attributes in same
                        // tag; stripping.
                        XMLUtils.stripDuplicateAttributes(doc, null);
                        
                        errorWriter.flush();
                        errorWriter.close();
                        if(getLogger().isWarnEnabled()) {
                                getLogger().warn(stringWriter.toString());
                        }
                        
                        DOMStreamer domStreamer = new 
DOMStreamer(this.contentHandler,
                                        this.lexicalHandler);
                        this.contentHandler.startDocument();
                        
                        if(xpath != null) {
                                NodeList nl = processor.selectNodeList(doc, 
xpath);
                                int length = nl.getLength();
                                for(int i=0; i < length; i++) {
                                        domStreamer.stream(nl.item(i));
                                }
                        } else {
                                // If the HTML document contained a <?xml ... 
declaration, tidy
would have recognized
                                // this as a processing instruction (with a 
'null' target), giving
problems further
                                // on in the pipeline. Therefore we only 
serialize the document element.
                                domStreamer.stream(doc.getDocumentElement());
//                              domStreamer.stream(doc);
                        }
                        this.contentHandler.endDocument();
                } catch (SAXException e){
                        SourceUtil.handleSAXException(this.source, e);
                } finally {
                        this.method.releaseConnection();
                        //                          connection.close();
                }
        }
        
        public void service(ServiceManager manager)
        throws ServiceException {
                super.service( manager );
                this.processor = 
(XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
        }
}

============== MyHttpProxyGenerator.java ===========

and which will also handle , with no prior knowledge of what
parameters are passed.
On 06/11/06, Ard Schrijvers <[EMAIL PROTECTED]> wrote:

> Btw i did not full understand ur last hint .... about a 'my
> own inputmodule' ... do u mean to make a resource
> parametrized with {myparams} and in the match pattern doing a
> call to that resource, passing as param all url params i
> need? es.: [btw i did not try these lines of code yet]
>

No, I meant something else. In the cocoon.xconf, there are a bunch of 
inputModules defined, like request,session, request-param, date, etc etc. But, 
if you need something that  is not yet there, you just create your own input 
module. Look at the implementation of some inputModule, and extend it, or make 
an entire new one, that meets your goals. That is what I meant. Think you 
should still try how the POST is translated to a queryString when you add non 
ASCII chars (not sure if only non ASCII but you know what I mean, right?)

>
> Btw i presume that the impossibility to do a POST is due to
> the use of TextSerializer ... maybe the HtmlSerializer could
> do the job.

No no, you are thinking here in the wrong direction. It is totally irrespective 
of whatever you do after the generator. You just have a generator, that happens 
to be a url to another server/site. After your generator, your call to the 
other server is finished. The serializer you choose changes nothing. What you 
actually want, is to forward the POST via a generator or transformer, and then 
get the result, right? I know there is some proxy stuff, you could look for, 
but I think the easiest way is by far the cinclude transformer:

http://cocoon.apache.org/2.1/userdocs/cinclude-transformer.html

though, this is about including external XML. And you want javascript. Not sure what 
happens, but I think when you fetch the external data and wrap it with <date> 
and serialize it as text/javascript, it probably will strip the element...never 
tried, but I suppose it works :-)

Good luck,

Ard

>
> Regards,
> Maurizio
> --------------
>
>
> 2006/11/6, Ard Schrijvers <[EMAIL PROTECTED]>:
> I know there was something to include all the params at once,
> without having to configure them all seperately...something
> with queryString. Must be in the archives somewhere.
>
> And otherwise, just create your own inputmodule, {myparams}
> and let this inputmodule return all params + values in one
> string, like the GET looks like (perhaps you have to url
> encode as well...).
>
> Regards Ard
>
>
>
>
> In fact i am using ur solution adding params on the url...
> the bad side is that for each different json call and
> different params i have to write different matches in
> sitemap... each one with his params... btw in GET is
> functioning... also fi i think it's not the best solution btw.
>
> Thank u very much for the quick answer
>
> Best regards,
> Maurizio
> --------------
>
>
> 2006/11/5, Ard Schrijvers <[EMAIL PROTECTED] >:
> Is it possible to add the parameters to src="
> http://www.myhost.com/{1}.php"; ? So, if you get a post with
> param id, just call src="
> http://www.myhost.com/{1}.php?id={request-param:id} ". There
> also must be some way to append all request parameters with
> one input module, I forgot how, but there has been a thread
> about it ones, you could find it in the archives. But, you
> are then changing a POST into a GET then, with parameters in
> the url, perhaps you dont want this.
>
> Can't the ProxyTransformer, or the cinclude transformer help
> you out (though I am not to familiar with both)...you
> probably have to change them a little since you are expecting
> text/javascript...
>
> Regards Ard
>
>
> Greetings all.
>
> I found out that FileGenerator may let me grab output from a
> PHP page that outputs javascript code (header("Content-Type:
> text/javascript");):
> Unfortunately it does NOT propagate the POST data sent by
> javascript JSON call.
>
> <!--sitemap snip-->
> <map:match pattern="*.json">
>   <map:generate type="text"
> mime-type="application/javascript" src="
http://www.myhost.com/{1}.php";>
  <map:serialize type="text">
</map:match>

Indeed i successfully receive the Javascript string that i produce from PHP, 
but PHP does NOT receive POST data from JSON call.

The QUESTION is: i DO POST data from browser javascript function ---> to cocoon 
--> arriving to PHP and back, but in some way in PHP i don't see any parameter 
sent by the browser, so i presume that cocoon is NOT sending the params that browser 
sent to it through calling xmlhttp.send.

I tested the example using just php and it is functioning good (POST data from 
json call is in $GLOBALS['HTTP_RAW_POST_DATA']), but when i pass through cocoon 
i loose POST data in some way.

Is there any way i can POST data in javascript to a PHP page ?

May a gentle soul between U all give me an hint (and maybe a piece of code) 
that can drive me to solution, please?

Any idea is well accepted.

thanks in advance to all.

Maurizio
-----------

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





--
Saluti,
Maurizio

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





--
Saluti,
Maurizio

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




--
Tal Shalif
+972 (0)54 313 8146

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

Reply via email to