cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grzegorz Kossakowski <gkossakow...@apache.org>
Subject Re: how to write my own transfomer with C2.2
Date Tue, 28 Aug 2007 13:49:31 GMT
S├ębastien Geindre pisze:
> hello everybody,
> 
> I need to make a http POST request inside my pipeline.
> So i need to write my own transformer which :
> get the SAX event and transform into DOM
> request a http server (web feature service) posting xml data
> get the response back and generate SAX event.
> 
> Is there any transformer that already does this thing (posting xml data
> to http server) ?
> If not, how could i write my own in C2.2 ? Any documentation ?
> 
> thanks

You are lucky, most of the functionality is already implemented in ServletServiceTransformer[1].
You
 can see example of its usage in cocoon-servlet-service-sample[2]. This transformer works
only with
sources that implement PostableSource interface. The only source that implements this interface
is
ServletSource.

This transformer was designed to make calls to a servlet services (see [3] for details) and
I don't
think it should be directly used for making general HTTP calls to any HTTP server. Instead
of
implementing class implementing PostableSource and delegating it to HttpConnection I would
suggest
to create a new block that would handle calling your web feature. By creating new block I
don't have
in mind block with Cocoon sitemap and using SitemapServlet as explained in this tutorial [4].

You will need to implement simple Servlet like:

public class WebFeatureServlet implements HttpServlet {
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
    //you may need to use other method for obtaining path
    if (request.getPathTranslated().equals("service/webFeature")) {
      //make a request to your web feature service and copy it's response to the response
parameter
    }
  }
}

Then mount your servlet as a new block. You just may want to create a new block using block
archetype by following[4]. Since you don't need sitemap (your servlet will handle calls) you
can
safely remove src/main/resources/COB-INF directory.

Last step is to mount your servlet, finally. Open
src/main/resources/META-INF/cocoon/spring/servlet-service.xml file and change class from
org.apache.cocoon.sitemap.SitemapServlet to your.package.WebFeatureServlet.

After completing these steps your new block is ready to handle servlet service calls, you
just have
to connect to it and use servletService transformer to make a calls.

I hope this will help you. Also, I hope that you will like this approach, it's very powerful
because
you can do whatever you need in your own, simple servlet like handling of authentication or
setting
custom headers.

I would be grateful for any feedback related to the new functionality as it wasn't much tested.

[1]
http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/postable/components/ServletServiceTransformer.java
[2]
http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-sample
[3] https://issues.apache.org/jira/browse/COCOON-2046
[4] http://cocoon.zones.apache.org/daisy/cdocs/g2/g2/g1/1159.html

-- 
Grzegorz Kossakowski
http://reflectingonthevicissitudes.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message