The following example demonstrates the use of a parse template in an application which accepts queries by employeeID in order to acquire data about an employee.
The parse template uses a flow-external file as a template into which it inserts values for fields – name, department, job title, start date, and employee type – drawn from the message payload. The flow then returns the template-built payload to the caller.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<jdbc-ee:mssql-data-source name="MySQL_Data_Source" user="mule" password="MuleR0cks" url="jdbc:mysql://localhost:3306/hrDB" transactionIsolation="UNSPECIFIED" doc:name="MS SQL Data Source"/>
<jdbc-ee:connector name="Database" dataSource-ref="MySQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database">
<jdbc-ee:query key="getEmployeeById" value="SELECT * FROM Employees WHERE id=#[message.inboundProperties.'http.query.params'.id]"/>
</jdbc-ee:connector>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" basePath="getEmployee" doc:name="HTTP Listener Configuration"/>
<flow name="exampleTemplateFlow1" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP" doc:description="Send GET request with a parameter, for example, http://localhost:8081/getEmployee?id=12345"/>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="getEmployeeById" queryTimeout="-1" connector-ref="Database" doc:name="Database" doc:description="Returns list of maps containing records; only the first one is required."/>
<parse-template location="src/test/resources/responseHtml.template" doc:name="Parse Template"/>
<set-property doc:name="Content Type" propertyName="Content-Type" value="text/html"/>
</flow>