This post will explain how one can transfer PDF files through VFS transport within WSO2 ESB.
In this example, I will be providing the configuration which is tested on WSO2 ESB 4.8.1.
In order for you to get the scenario to work, first you will need to enable the VFS sender and listener through the following configuration in the axis2.xml. The below lines will be commented out by default and all you need to do to enable the VFS transport is uncomment the following two entries.
<transportReceiver name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportListener"/>
<transportSender name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportSender"/>
Next, to enable PDF file transferring within ESB, you will have to enable the message relay feature. For this, we need to add the appropriate message builder and formatter to the axis2.xml file.
<messageFormatters>
<messageFormatter contentType="application/pdf" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
:
:
</messageFormatters>
<messageBuilders>
<messageBuilder contentType="application/pdf" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
:
:
</messageBuilders>
Once the above changes have been done, create a Proxy Service as shown below.
<proxy name="PdfProxy" transports="vfs" startOnLoad="true">
<target>
<inSequence>
<log level="custom">
<property name="status=" value="PDF file transferred"/>
</log>
<drop/>
</inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">15</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///Users/evanthika/Downloads/vfs/out</parameter>
<parameter name="transport.vfs.FileURI">file:///Users/evanthika/Downloads/vfs/in</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///Users/evanthika/Downloads/vfs/failure</parameter>
<parameter name="transport.vfs.FileNamePattern">.*\.pdf</parameter>
<parameter name="transport.vfs.ContentType">application/pdf</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
</proxy>
Now drop the relevant PDF file to the location mentioned in the transport.vfs.FileURI
parameter. After the time specified in the transport.PollInterval parameter, the relevant PDF file will be read and moved to the folder specified as the transport.vfs.MoveAfterProcess parameter value.
Wednesday, September 27, 2017
Saturday, September 2, 2017
How to accept requests from different URLs that has different query parameters through ESB APIs
Products used - WSO2 ESB 4.8.1
WSO2 DSS 3.5.0
Assume that we have a back-end service which reads a database and returns employee information depending on particular parameters that are being passed. Let's say that we are using the following Data Services Server which is hosted in WSO2 DSS product.
<data name="GetEmployees" transports="http https local">
<config enableOData="false" id="mysql">
<property name="driverClassName">com.mysql.jdbc.Driver</property>
<property name="url">jdbc:mysql://localhost:3306/employee</property>
<property name="username">root</property>
<property name="password">root</property>
</config>
<query id="query1" useConfig="mysql">
<sql>select * from employees where id=? and lastname=?</sql>
<result element="employees" rowName="employee">
<element column="id" name="id" xsdType="string"/>
<element column="lastname" name="lastname" xsdType="string"/>
<element column="firstname" name="firstname" xsdType="string"/>
</result>
<param name="id" sqlType="STRING"/>
<param name="lastname" sqlType="STRING"/>
</query>
<query id="query2" useConfig="mysql">
<sql>select * from employees</sql>
<result element="employees" rowName="employee">
<element column="id" name="id" xsdType="string"/>
<element column="lastname" name="lastname" xsdType="string"/>
<element column="firstname" name="firstname" xsdType="string"/>
</result>
</query>
<query id="query3" useConfig="mysql">
<sql>select * from employees where id=?</sql>
<result element="employees" rowName="employee">
<element column="id" name="id" xsdType="string"/>
<element column="lastname" name="lastname" xsdType="string"/>
<element column="firstname" name="firstname" xsdType="string"/>
</result>
<param name="param0" sqlType="STRING"/>
</query>
<operation name="getemployee">
<call-query href="query1">
<with-param name="id" query-param="id"/>
<with-param name="lastname" query-param="lastname"/>
</call-query>
</operation>
<operation name="getemployeeid">
<call-query href="query3">
<with-param name="param0" query-param="param0"/>
</call-query>
</operation>
<operation name="getAllEmployees">
<call-query href="query2"/>
</operation>
</data>
Lets assume that the client expects to send the requests in the following format.
To get all the employee details of the database - http://localhost:8280/newsample/employee/get/employees
To get employee details which matches a particular id - http://localhost:8280/newsample/employee/get/employees?id={id_number}
To get details of a particular employee which matches a particular id and the lastname - http://localhost:8280/newsample/employee/get/employees?id=1&lastname=Amarasiri
To support this, we can create an API in WSO2 ESB with the following configuration.
<api name="EmployeeDetApi" context="/newsample">
<resource methods="GET"
uri-template="/employee/get/employees?id={id}&lastname={lastname}">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:getemployee>
<dat:id>$1</dat:id>
<dat:lastname>$2</dat:lastname>
</dat:getemployee>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$url:id"/>
<arg evaluator="xml" expression="$url:lastname"/>
</args>
</payloadFactory>
<property name="SOAPAction"
value="urn:getemployee"
scope="transport"
type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<log>
<property name="incoming_message"
value="*******GET EMPLOYEE DETAILS - id ,lastname *******"/>
</log>
<send>
<endpoint key="AddressEpr"/>
</send>
</inSequence>
</resource>
<resource methods="GET" uri-template="/employee/get/employees?id={param0}">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:getemployeeid>
<dat:param0>$1</dat:param0>
</dat:getemployeeid>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$url:id"/>
</args>
</payloadFactory>
<property name="SOAPAction"
value="urn:getemployeeid"
scope="transport"
type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<log>
<property name="incoming_message"
value="*******GET EMPLOYEE DETAILS - id *******"/>
</log>
<send>
<endpoint key="AddressEpr"/>
</send>
</inSequence>
</resource>
<resource methods="GET" uri-template="/employee/get/employees">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:getAllEmployees/>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<property name="SOAPAction"
value="urn:getemployeedetails"
scope="transport"
type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<log>
<property name="incoming_message"
value="*******GET EMPLOYEE DETAILS - All employees details *******”/>
</log>
<send>
<endpoint key="AddressEpr"/>
</send>
</inSequence>
</resource>
</api>
WSO2 DSS 3.5.0
Assume that we have a back-end service which reads a database and returns employee information depending on particular parameters that are being passed. Let's say that we are using the following Data Services Server which is hosted in WSO2 DSS product.
<data name="GetEmployees" transports="http https local">
<config enableOData="false" id="mysql">
<property name="driverClassName">com.mysql.jdbc.Driver</property>
<property name="url">jdbc:mysql://localhost:3306/employee</property>
<property name="username">root</property>
<property name="password">root</property>
</config>
<query id="query1" useConfig="mysql">
<sql>select * from employees where id=? and lastname=?</sql>
<result element="employees" rowName="employee">
<element column="id" name="id" xsdType="string"/>
<element column="lastname" name="lastname" xsdType="string"/>
<element column="firstname" name="firstname" xsdType="string"/>
</result>
<param name="id" sqlType="STRING"/>
<param name="lastname" sqlType="STRING"/>
</query>
<query id="query2" useConfig="mysql">
<sql>select * from employees</sql>
<result element="employees" rowName="employee">
<element column="id" name="id" xsdType="string"/>
<element column="lastname" name="lastname" xsdType="string"/>
<element column="firstname" name="firstname" xsdType="string"/>
</result>
</query>
<query id="query3" useConfig="mysql">
<sql>select * from employees where id=?</sql>
<result element="employees" rowName="employee">
<element column="id" name="id" xsdType="string"/>
<element column="lastname" name="lastname" xsdType="string"/>
<element column="firstname" name="firstname" xsdType="string"/>
</result>
<param name="param0" sqlType="STRING"/>
</query>
<operation name="getemployee">
<call-query href="query1">
<with-param name="id" query-param="id"/>
<with-param name="lastname" query-param="lastname"/>
</call-query>
</operation>
<operation name="getemployeeid">
<call-query href="query3">
<with-param name="param0" query-param="param0"/>
</call-query>
</operation>
<operation name="getAllEmployees">
<call-query href="query2"/>
</operation>
</data>
Lets assume that the client expects to send the requests in the following format.
To get all the employee details of the database - http://localhost:8280/newsample/employee/get/employees
To get employee details which matches a particular id - http://localhost:8280/newsample/employee/get/employees?id={id_number}
To get details of a particular employee which matches a particular id and the lastname - http://localhost:8280/newsample/employee/get/employees?id=1&lastname=Amarasiri
To support this, we can create an API in WSO2 ESB with the following configuration.
<api name="EmployeeDetApi" context="/newsample">
<resource methods="GET"
uri-template="/employee/get/employees?id={id}&lastname={lastname}">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:getemployee>
<dat:id>$1</dat:id>
<dat:lastname>$2</dat:lastname>
</dat:getemployee>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$url:id"/>
<arg evaluator="xml" expression="$url:lastname"/>
</args>
</payloadFactory>
<property name="SOAPAction"
value="urn:getemployee"
scope="transport"
type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<log>
<property name="incoming_message"
value="*******GET EMPLOYEE DETAILS - id ,lastname *******"/>
</log>
<send>
<endpoint key="AddressEpr"/>
</send>
</inSequence>
</resource>
<resource methods="GET" uri-template="/employee/get/employees?id={param0}">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:getemployeeid>
<dat:param0>$1</dat:param0>
</dat:getemployeeid>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg evaluator="xml" expression="$url:id"/>
</args>
</payloadFactory>
<property name="SOAPAction"
value="urn:getemployeeid"
scope="transport"
type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<log>
<property name="incoming_message"
value="*******GET EMPLOYEE DETAILS - id *******"/>
</log>
<send>
<endpoint key="AddressEpr"/>
</send>
</inSequence>
</resource>
<resource methods="GET" uri-template="/employee/get/employees">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:getAllEmployees/>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args/>
</payloadFactory>
<property name="SOAPAction"
value="urn:getemployeedetails"
scope="transport"
type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<log>
<property name="incoming_message"
value="*******GET EMPLOYEE DETAILS - All employees details *******”/>
</log>
<send>
<endpoint key="AddressEpr"/>
</send>
</inSequence>
</resource>
</api>
Subscribe to:
Posts (Atom)