Internal Pipeline Snippet
Overview
This Snippet shows how to create and use an internal pipeline in the sitemap. An internal pipeline processes a request from another pipeline in a sitemap. It then returns a pipeline fragment to the requesting pipeline for additional processing. The pipeline fragment produced by an internal pipeline cannot be accessed externally, for example, from an explicit browser request. An internal pipeline is distinguished from other pipelines by the value of its internal-only attribute which is set to true.
Version
At the time of this writing, this Snippet was tested against the current release version, 2.0.3, and head version, 2.1, of Cocoon.
Example
<map:pipeline internal-only="true"> <map:match pattern="salad"> <!-- do something --> </map:match> <map:match pattern="soup"> <!-- do something else --> </map:match> </map:pipeline> <map:pipeline> <map:match pattern="meal"> <map:aggregate element="lunch"> <map:part src="cocoon:/salad"/> <map:part src="cocoon:/soup"/> </map:aggregate> <map:transform src="stylesheets/lunch2html.xsl"/> <map:serialize/> </map:match> </map:pipeline>
Discussion
In the above snippet example, you'll find two pipelines. The first is an internal pipeline which provides XML content to the second pipeline upon request. The second pipeline makes requests of the first internal pipeline through the cocoon:/ protocol. For example, when a request such http://localhost:8080/meal is received, the second pipeline, whose map:match element contains the value "meal," is matched. This pipeline begins processing by making two internal requests of the internal pipeline: one for cocoon:/salad and another for cocoon:/soup. It then aggregates the fragments returned by the internal pipeline within a lunch element. It continues processing by transforming and serializing the result.
Tips
You may need to check the pipeline fragments returned by your internal pipelines by calling them externally, for example, in your browser. If so, change the internal-only attribute of the pipeline to false until your testing is complete. In the above snippet, you could evaluate the pipeline fragment for soup with the following request: http://localhost:8080/soup. Once your testing is complete, make sure to change the value of the internal-only attribute back to true.
Comments
Care to comment on this Snippet? Got another tip? Help keep this Snippet relevant by passing along any useful feedback to the author, Diana Shannon.
Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).