cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emilio Arce <ea...@dataware.com>
Subject using producer=request and filtering content from cgi programs (q uestion and my hacky solution)
Date Fri, 15 Sep 2000 20:20:41 GMT
Hi there,
 
    I recently started working with Cocoon (after seeing it in action at XML
World 2000). 
Everything seems to work fine when retrieving xml files from the file system
(this uses ?producer=file, org.apache.cocoon.producer.ProducerFromFile).
However, I tried to use producer=request
(org.apache.cocoon.producer.ProducerFromRequest) and this hanged my Apache
server. I tried to look for answers on some mail list but without much
success (apache.org archives seem to be flaky lately, too).
Anyway, I think the problem with the ProducerFromRequest is when it tries to
use the Reader object from the Servlet request. I'm not sure about this
though. 
Anyway, my next step was trying to use this with the content generated by a
cgi program for which I thought producer=request was made for. But this
didn't work either... so I got my hands dirty. I wrote a new 'hacky'
Producer
called ProducerFromFetch which makes another URL connection. This seems
inefficient but it works in the mean time. (as long as you don't retrieve
another page that is filtered by Cocoon as well :-) ) 
Does anybody know a better way to filter content from cgi and/or use the
producer=request?
(attached you will find the modifications to cocoon.properties, and the java
class)
 
Thanks.

cocoon.properties:
.....
# The syntax for this is
# producer.type.xxx = full.class.name
# where "xxx" is the producer indentier used in the request
producer.type.file = org.apache.cocoon.producer.ProducerFromFile
producer.type.request = org.apache.cocoon.producer.ProducerFromRequest
producer.type.fetch = org.apache.cocoon.producer.ProducerFromFetch
.....
 
 
java for org.apache.cocoon.producer.ProducerFromFetch:
 
package org.apache.cocoon.producer;
 
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.http.*;
import org.apache.cocoon.*;
import org.apache.cocoon.framework.*;
 
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
 
/**
 * This class implements the producer interface to get the document
 * pointed by the 'url' parameter in the HttpServletRequest
 * and then Cocoon-ize it
 * 
 */
 

public class ProducerFromFetch extends AbstractProducer implements Status {
    
    /**
     * Return a reader to the data of the HttpRequest.
     */
    public Reader getStream(HttpServletRequest request) 
        throws IOException
    {
        try
        {
          return this.getPage(request.getParameter("url"));
        }
        catch(MalformedURLException ex)
        {
          return null;
        }
        catch(Exception ex)
        {
          return null;
        }
    }
 
    /*
     * Return the path associated to the requested document.
     */
    public String getPath(HttpServletRequest request) 
    {
        return request.getParameter("url");
    }
    
    public String getStatus() {
        return "Producer from URL
(org.apache.cocoon.producer.ProducerFromFetch)";
    }
    
    private Reader getPage(String path)
                          throws MalformedURLException, IOException,
Exception
    {
       if (!path.equals(""))
       {
        URL url = new URL(path);
        URLConnection connection = url.openConnection();
        InputStream in = connection.getInputStream();
          InputStreamReader reader = new InputStreamReader(in);
          return reader;
       } 
 
        return null;
    }
    
}


Emilio J. Arce 
Dataware Technologies, Inc.
Hadley, MA - 01035
Phone: (413) 587 - 2208
Fax: (413) 587 2246

 

Mime
View raw message