Using files with embedded Mule Expression Language for better looking HTML

We struggled building decent looking pages until we started using the Mule Parse Template component and groovy component that invokes the Mule Expression Language (MEL) processor against the markup. The example to the right shows how our default behavior in a our web choice router processes a web template.
Sample Code
You can find sample code in the Coda Hale exception metrics counter demo on GitHub
Parse Template

Processing MEL embedded in a payload using Groovy
Mule uses the current Expression Manager to process MEL expressions used in normal component. We can use the same Expression Manager to parse and process our parameterized payload. I use a Groovy script component for this because it is simple and because the component lets us set the outbound MIME type without an additional component. The magic groovy script that takes the payload, applies the expression processor and puts the results into the outbound message isis:
return muleContext.getExpressionManager().parse(payload,message)
<ul>
<li>http.context.path: #[message.inboundProperties['http.context.path']]</li>
return muleContext.getExpressionManager().parse(payload,message)Here is how this looks in Anypoint Studio.
return muleContext.getExpressionManager().parse(payload,message)
Sample Markup
This HTML fragment displays various http properties in an HTML list.
<li>http.context.path: #[message.inboundProperties['http.context.path']]</li>
<li>http.context.uri: #[message.inboundProperties['http.context.uri']]</li>
<li>http.relative.path: #[message.inboundProperties['http.relative.path']]</li>
<li>http.request.path: #[message.inboundProperties['http.request.path']]</li>
<li>http.query.params: #[message.inboundProperties['http.query.params']]</li>
</ul>
Last Edited 2015 Jan 04
Comments
Post a Comment