<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" 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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <http:request-config name="QoppaPAS"  host="localhost" port="8090" basePath="/qoppapdf/v1" doc:name="HTTP Request Configuration"/>
    <flow name="PAS_Add_Watermark">
        <file:inbound-endpoint path="c:/qoppa/pas/input" responseTimeout="10000" doc:name="Watch Folder">
            <file:filename-regex-filter pattern=".*.pdf" caseSensitive="false"/>
        </file:inbound-endpoint>
        <file:file-to-byte-array-transformer doc:name="Convert to Byte Array"/>
        <set-attachment attachmentName="#[originalFilename]" value="#[payload]" contentType="application/pdf" doc:name="Convert Payload to Attachment"/>
        <http:request config-ref="QoppaPAS" path="documents/mulesample?namingMode=2" method="POST" doc:name="PAS - POST the PDF">
            <http:request-builder>
                <http:header headerName="content-type" value="multipart/form-data"/>
            </http:request-builder>
        </http:request>
        <set-session-variable variableName="serverfilepath" value="#[json:path]" doc:name="Save Document Name"/>
        <set-attachment attachmentName="pageAction" value="{  &quot;TextStampAction&quot;:{   &quot;rotation&quot;:45,   &quot;transparency&quot;:50,   &quot;x&quot;:200,   &quot;y&quot;:200,   &quot;text&quot;:&quot;Confidential&quot;,   &quot;color&quot;:65280, &quot;fontSize&quot;:64} }" contentType="application/json" doc:name="JSON Action as Attachment"/>
        <http:request config-ref="QoppaPAS" path="documents/#[sessionVars['serverfilepath']]/pages" method="POST" doc:name="PAS - Add Watermark">
            <http:request-builder>
                <http:header headerName="content-type" value="multipart/form-data"/>
            </http:request-builder>
        </http:request>
        <http:request config-ref="QoppaPAS" path="documents/#[sessionVars['serverfilepath']]/content" method="GET" doc:name="PAS - Get the Document">
            <http:request-builder>
                <http:header headerName="Accept" value="application/pdf"/>
            </http:request-builder>
        </http:request>
        <file:outbound-endpoint path="c:/qoppa/pas/output" outputPattern="#[originalFilename]" responseTimeout="10000" doc:name="Save the PDF to a File"/>
    </flow>
</mule>
