1
votes

I have the needs to use WSO2 ESB to mediate the incoming fixed length text data as received via MQ, one line of text per message, into XML format and then send the transformed data onto an SOAP endpoint via HTTP.

I understand that I could use WSO2 ESB admin console to configure an InSequence to do the data parsing and mapping with substring function and then set up a proxy service to include this configured sequenece.

I would need helps about how to do all these in details in steps. Greatly appreciate if someone could provide some examples or links to some webpages about how-to.

Thanks!

3

3 Answers

2
votes

You should have a look to smooks, I think this is the best solution :

CSV : http://wso2.com/library/blog-post/2013/09/csv-to-xml-transformation-with-wso2-esb-smooks-mediator/

Fixed Lengh text : http://vvratha.blogspot.fr/2014/05/processing-large-text-file-using-smooks.html

An other solution would be to write your own messageBuilder, search "org.apache.axis2.format.PlainTextBuilder" to find the source code...

1
votes

I agree with Jean-Michel, that smooks would be a good solution. But, this is also possible to do within a single simple proxy service. Set up a simple pass-through proxy to your endpoint. Then, open it up in source view (or the wizard) and configure the insequence to add a PayloadMediator.

Here is an example of how to use Payload Mediator [1] Here is an excerpted example of what that would look like with a few xpath expressions to extract fixed-length fields from your input:

    <payloadFactory media-type="xml">
        <format>
            <m:body xmlns:m="http://services.samples">
                <m:field1>$1</m:field1>
                <m:field2>$2</m:field2>
            </m:body>
        </format>
        <args>
            <arg expression="substring(//*,0,10)"/>
            <arg expression="substring(//*,10,10)"/>
        </args>
    </payloadFactory>

You may also need to use the content type property in your sequence, because you're changing the content type to xml:

<property name="ContentType" value="text/xml" scope="axis2"/>

Best of luck!

[1] https://docs.wso2.com/pages/viewpage.action?pageId=33136018

0
votes

For those who are interested in a working solution, here is my smooks configuration:

<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:fl="http://www.milyn.org/xsd/smooks/fixed-length-1.3.xsd">
<fl:reader fields="price[5]?trim,quantity[5]?trim,symbol[5]?trim.upper_case,comment[10]?trim" recordElementName="order">
    <fl:listBinding beanId="order" class="test.Order" />
</fl:reader>
</smooks-resource-list>

Also, need to add the jar file of test.Order to the classpath of WSO2 ESB.