How to create an ESB proxy which serves a PDF

Malintha Amarasinghe
1 min readNov 20, 2016

1. Download WSO2 ESB from here. I have tested this for ESB 4.9.0 and 5.0.0 versions.

2. Download file connector v2 from ESB Connector Store. I have tested it for v2.0.0 and it can be downloaded from here.

3. Do following changes to repository/conf/axis2/axis2.xml

  • Add the following message builder for “application/pdf” under <messageBuilders> element.
<messageBuilder contentType="application/pdf" 
class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
  • Add the following message formatter for “application/pdf” under <messageFormatters> element.
<messageFormatter contentType="application/pdf" 
class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>

4. Start the ESB and upload the connector to ESB from management console. After that make it Enabled.

5. Create the following proxy in ESB. Change the <source> with the location of your PDF file.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="fileDownload"
transports="https http"
startOnLoad="true">
<description/>
<target>
<inSequence>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<fileconnector.read>
<source>/home/malintha/wso2apim/cur/sample.pdf</source>
<contentType>application/pdf</contentType>
</fileconnector.read>
<respond/>
</inSequence>
</target>
</proxy>

6. Now you can access the content using cURL.

curl http://localhost:8280/services/fileDownload.fileDownloadHttpSoap12Endpoint  > sample.pdf

--

--