简体   繁体   English

如何使用WSO2 ESB来调解固定长度的文本数据

[英]How to use WSO2 ESB to mediate fixed length text data

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. 我需要使用WSO2 ESB将通过MQ接收的传入固定长度文本数据(每个消息一行文本)调解为XML格式,然后通过HTTP将转换后的数据发送到SOAP端点。

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. 我知道我可以使用WSO2 ESB管理控制台来配置InSequence以使用子字符串函数进行数据解析和映射,然后设置代理服务以包含此配置的序列。

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! 谢谢!

You should have a look to smooks, I think this is the best solution : 你应该看看smooks,我认为这是最好的解决方案:

CSV : http://wso2.com/library/blog-post/2013/09/csv-to-xml-transformation-with-wso2-esb-smooks-mediator/ CSV: http://wso2.com/library/blog-post/2013/09/csv-to-xml-transformation-with-wso2-esb-smooks-mediator/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 修复了Lengh文本: http://vvratha.blogspot.fr/2014/05/processing-large-text-file-using-smooks.html ://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... 另一种解决方案是编写自己的messageBuilder,搜索“ org.apache.axis2.format.PlainTextBuilder ”以查找源代码......

I agree with Jean-Michel, that smooks would be a good solution. 我同意Jean-Michel的观点,认为smooks是一个很好的解决方案。 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. 然后,在源视图(或向导)中打开它并配置insequence以添加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: 以下是如何使用Payload Mediator的示例[1]以下是一些摘录示例,其中包含一些xpath表达式,用于从输入中提取固定长度字段:

    <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: 您可能还需要在序列中使用内容类型属性,因为您要将内容类型更改为xml:

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

Best of luck! 祝你好运!

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

For those who are interested in a working solution, here is my smooks configuration: 对于那些对工作解决方案感兴趣的人,这是我的smooks配置:

<?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. 另外,需要将test.Order的jar文件添加到WSO2 ESB的类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM