cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grzegorz Kossakowski <>
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].
 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

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
implementing class implementing PostableSource and delegating it to HttpConnection I would
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

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
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
you can do whatever you need in your own, simple servlet like handling of authentication or
custom headers.

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


Grzegorz Kossakowski

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message