Basic pipelines

Minimal pipeline

Our first pipeline uses the RequestGenerator to output the request attributes in XML.

Sitemap excerpt

<map:match id="requestPipeline" pattern="dump-request">
<map:generate id="12" type="request"/>
<map:serialize type="xml"/>
</map:match>

Typical output

Shown below is the result of a request to dump-request?param=xyz. The response is XML as specified by the serializer, and describes the request attributes and parameters, converted to XML by the RequestGenerator component.

<h:request target="/demos/release/samples/blocks/tour/pipelines/docs/basic-pipelines.html" sitemap="dump-request" source="">
<h:requestHeaders>
<h:header name="Host"> localhost:11001 </h:header>
<h:header name="User-Agent"> CCBot/1.0 (+http://www.commoncrawl.org/bot.html) </h:header>
<h:header name="Accept"> Accept: application/xhtml+xml,text/html;q=0.9,text/plain; </h:header>
<h:header name="Accept-Language"> en-us,en;q=0.5 </h:header>
<h:header name="Accept-Encoding"> gzip </h:header>
<h:header name="Accept-Charset"> ISO-8859-1,utf-8;q=0.7,*;q=0.7 </h:header>
<h:header name="Cache-Control"> no-cache </h:header>
<h:header name="Pragma"> no-cache </h:header>
<h:header name="Max-Forwards"> 10 </h:header>
<h:header name="X-Forwarded-For"> 38.103.63.59 </h:header>
<h:header name="X-Forwarded-Host"> cocoon.zones.apache.org </h:header>
<h:header name="X-Forwarded-Server"> cocoon.zones.apache.org </h:header>
<h:header name="Connection"> close </h:header>
</h:requestHeaders>
<h:requestParameters>
<h:parameter name="param">
<h:value> xyz </h:value>
</h:parameter>
</h:requestParameters>
<h:configurationParameters/>
<h:remoteUser/>
</h:request>

Converting XML to HTML

Adding a transformer with map:transform and changing the serializer to HTML allows us to generate HTML out of the XML of the previous example.

You can also view the output here: request.html

Sitemap excerpt

<map:match id="requestToHtml" pattern="request.html">
<map:generate type="request"/>
<map:transform src="xsl/request-to-html.xsl"/>
<map:serialize type="html"/>
</map:match>

XSL transformation

<xsl:template name="main" match="/">
<html>
<body>
<h1> Request to host
<xsl:value-of select="//h:header[@name='Host']"/>
</h1>
<h2> Request headers </h2>
<xsl:for-each select="//h:header">
<b>
<xsl:value-of select="@name"/>
</b>
:
<xsl:value-of select="."/>
<br/>
</xsl:for-each>
</body>
</html>
</xsl:template>

Typical output

<html>
<body>
<h1> Request to host localhost:11001 </h1>
<h2> Request headers </h2>
<b> Host </b>
: localhost:11001
<br/>
<b> User-Agent </b>
: CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
<br/>
<b> Accept </b>
: Accept: application/xhtml+xml,text/html;q=0.9,text/plain;
<br/>
<b> Accept-Language </b>
: en-us,en;q=0.5
<br/>
<b> Accept-Encoding </b>
: gzip
<br/>
<b> Accept-Charset </b>
: ISO-8859-1,utf-8;q=0.7,*;q=0.7
<br/>
<b> Cache-Control </b>
: no-cache
<br/>
<b> Pragma </b>
: no-cache
<br/>
<b> Max-Forwards </b>
: 10
<br/>
<b> X-Forwarded-For </b>
: 38.103.63.59
<br/>
<b> X-Forwarded-Host </b>
: cocoon.zones.apache.org
<br/>
<b> X-Forwarded-Server </b>
: cocoon.zones.apache.org
<br/>
<b> Connection </b>
: close
<br/>
</body>
</html>

Adding a touch of style

You can chain several transformers in a pipeline. In this example we add some style to our HTML by adding an additional XSL transform.

View the output in your browser: styled/request.html

Sitemap excerpt

<map:match id="styledHtml" pattern="styled/request.html">
<map:generate type="request"/>
<map:transform src="xsl/request-to-html.xsl"/>
<map:transform src="xsl/html-styling.xsl"/>
<map:serialize type="html"/>
</map:match>

XSL transformation

<xsl:template name="main" match="/">
<html>
<head>
<link rel="stylesheet" href="css/tour.css" type="text/css"/>
<xsl:copy-of select="//head/node()"/>
</head>
<body>
<xsl:copy-of select="//body/node()"/>
<p class="footer"> This footer has been added by html-styling.xsl </p>
</body>
</html>
</xsl:template>

Typical output

<html>
<head>
<link type="text/css" href="css/tour.css" rel="stylesheet"/>
</head>
<body>
<h1> Request to host localhost:11001 </h1>
<h2> Request headers </h2>
<b> Host </b>
: localhost:11001
<br/>
<b> User-Agent </b>
: CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
<br/>
<b> Accept </b>
: Accept: application/xhtml+xml,text/html;q=0.9,text/plain;
<br/>
<b> Accept-Language </b>
: en-us,en;q=0.5
<br/>
<b> Accept-Encoding </b>
: gzip
<br/>
<b> Accept-Charset </b>
: ISO-8859-1,utf-8;q=0.7,*;q=0.7
<br/>
<b> Cache-Control </b>
: no-cache
<br/>
<b> Pragma </b>
: no-cache
<br/>
<b> Max-Forwards </b>
: 10
<br/>
<b> X-Forwarded-For </b>
: 38.103.63.59
<br/>
<b> X-Forwarded-Host </b>
: cocoon.zones.apache.org
<br/>
<b> X-Forwarded-Server </b>
: cocoon.zones.apache.org
<br/>
<b> Connection </b>
: close
<br/>
<p class="footer"> This footer has been added by html-styling.xsl </p>
</body>
</html>