CSV to SOAP Message conversion with Smooks Mediator

Smook Mediator available in WSO2 EI/ESB can be used to do various message transformations. For an example read CSV file and transform to XML . I had a requirement where I wanted to load a CSV file content into the database. So, my initial idea was to convert CSV content into XML, then use the XSLT mediator to generate a data service request. But it will be a costly operation with lots of resource consumption. Therefore, instead of generating a data service request via XSLT, I tried to use the options available in Smooks. Smooks provides FreeMaker based templating support that can be used to convert CSV to SOAP. Here, first I have created a sample input CSV file and expected Data Service sample request message. With this, it will be very easy to generate data mapping. Below are the examples of CSV and Data Service models Sample.csv: UserId,NameFirst,NameLast 1,Chandana,Napagoda 2,John,Tester SampleOut.xml :  <au:addUsers_batch_req xmlns:au="https://blo

Configure Kerberos based Authentication into WSO2 Datasources

As you know, Kerberos can be used to authenticate System or users reside on a none secured network. In my use case, I have Windows AD and MSSQL server and I have a couple of WSO2 Servers running on Linux systems. In my initial setup I have configured, WSO2 servers has to use SQL users. But instead of using SQL users, I prefer to use AD users. So I have started configuring Kerberos and faced a lot of troubles. If you are starting from scratch, I would recommend writing a Java class to connect MSSQL server using Kerberos. Then You can identify all small mistakes such as character case issues, typos, JDBC driver compatibility issues, etc.  Below are a few issues I have faced: 1) CASE is significant in krb5.conf file 2) I found that we need to use MSSQL JDBC 6.4 version in order to get new tickets. But if you are just planning use pre-generated tickets, you can use the older version as well. Here are the steps you need follow when configuring Kerberos with WSO2 Enterp

Compare Two XML Elements and Filter using WSO2 EI

Think about an integration scenario, where you are getting a list of data from a service endpoint(Data 1) and you want to exclude or match this response against the data returned by another service endpoint(Data 2). In such a situation, first, you need to have a unique attribute in both data set to exclude or match elements. So in my use case, list of data and matching content is as below <CodeLists> <CodeList> <Id> O </Id> <Name> Open </Name> </CodeList> <CodeList> <Id> C </Id> <Name> Cancelled </Name> </CodeList> <CodeList> <Id> X </Id> <Name> Denied </Name> </CodeList> <CodeList> <Id> P </Id> <Name> Pending </Name> </CodeList> <CodeList> <Id> D </Id> <Name> Duplicate </Name>

XSLT - Modify Date and DateTime value

If you want to perform date and time related opertions with XSLT 'date' or 'dateTime' values, you can use 'xs:yearMonthDuration' or 'xs:dayTimeDuration' function to achieve this. You can add or reduce years, months, date, hours or even minutes through those functions.  xs:yearMonthDuration For this function input value is year month duration and it should be passed in  ISO_8601 format n- the [n] is replaced by the value for each of the date and time elements P - The duration designator(for period). nY- the number of years. nM- the number of months. ex: xs:yearMonthDuration('P1Y2M') - 1 Year and 2 Months ex:  xs:yearMonthDuration('-P1Y2M')  - Negative 1 Year and 2 Months xs:dayTimeDuration For this function input value is day time duration and it also needs to be passed in  ISO_8601 format n- the [n] is replaced by the value for each of the date and time elements P - The duration designator(for period). nD- the

WSO2 EI/ESB Change Backend Response Status Code

With WSO2 Enterprise Integrator or Enterprise Service Bus servers, if you want to change the backend server response code, you can set custom status status code as below:  <property name="HTTP_SC" scope="axis2" type="STRING" value="403"/> If you are getting 'HTTP/1.1 202 Accepted' response from your backend, you need to set "SC_ACCEPTED" as false by setting a custom SC_ACCEPTED Ex:  Receiving 202 from backend and change it to 200 <filter regex="202" source="$axis2:HTTP_SC">         <then>             <property action="remove" name="HTTP_SC" scope="axis2"/>             <property name="SC_ACCEPTED" scope="axis2" value="false"/>             <property name="HTTP_SC" scope="axis2" type="STRING" value="200"/>         </then>         <else/>

Read XML content of the LocalEntry in WSO2 ESB

Local Entry is one of the data storage points in the WSO2 Enterprise Service Bus, where you can store text strings, XML content, and File URLs.  I have been asked a question that, how can we read the content of the local entry if it as an XML file. Below is an example to read the content of the local entry(Name: NameOfLocalEntry) and assign the value of XML elements as properties.  Content of Local Entry: <?xml version="1.0"?> <Server> <userName>chandana</userName> <URL></URL> </Server> Synapse Configuration:  <property name="localEntry" expression="get-property('NameOfLocalEntry')" scope="default" type="OM"/> <property name="userName" expression="$ctx:localEntry//*[local-name()='userName']"/> <property name="URL" expression="$ctx:localEntry//*[local-name()='URL']&q

Payload Factory Mediators for JSON Message

WSO2 ESB/EI PayloadFactory mediator can be used to replace the contents of a message. As an example, if the backend is accepting a different message structure than what you are receiving, you can use PayloadFactory mediator to change the message structure. Other than that, if you want to transform XML payload into JSON or JSON to XML with different message structure you can use this mediator. Recently, I faced an issue while transforming a message into JSON which is originally read from a CSV file(using Smooks Mediator ). This message can have empty values in the content sometimes and such messages look like below: <Users> <User> <FirstName>Chandana</FirstName> <MiddleName/> </Users> </User> I initially wrote a payload factory mediator like below: <payloadFactory media-type="json">         <format>    {   "UserInfo": {     "fName": "$1",     "mName": "$2&qu