0

我需要一个问题的解决方案:我刚刚为 WSO2 ESB 尝试了这个示例,它正在工作: http ://wso2.org/library/articles/2011/01/wso2-esb-example-file-processing

但我喜欢使用 XML 文件作为输入并将其写入 MySQL-DB。XML 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
  <Name>word</Name>
  <Surname>processor</Surname>
  <Phone>12333</Phone>
</soapenv:Body>
</soapenv:Envelope>

如果我把它放入我的“in”文件夹,文件将被移动到“out”文件夹,但没有任何内容写入数据库。没有错误信息。

我的代理服务:

    <proxy xmlns="http://ws.apache.org/ns/synapse" name="FileProxy" transports="vfs" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="full"/>
         <clone>
            <target sequence="fileWriteSequence"/>
            <target sequence="databaseSequence"/>
         </clone>
      </inSequence>
   </target>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.PollInterval">15</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">C:/wso2esb/testordner/out</parameter>
   <parameter name="transport.vfs.FileURI">C:/wso2esb/testordner/in</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">C:/wso2esb/testordner/error</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
   <parameter name="transport.vfs.ContentType">text/xml</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
   <description></description>
</proxy>

还有我的序列:

    <?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse"
          name="databaseSequence"
          trace="enable"
          statistics="enable">
   <log level="full">
      <property name="sequence" value="before-smooks"/>
   </log>
   <smooks config-key="smooks">
      <input type="xml"/>
      <output type="xml"/>
   </smooks>
   <log level="full">
      <property name="sequence" value="after-smooks"/>
   </log>
   <log level="full">
      <property xmlns:ns="http://org.apache.synapse/xsd"
                name="name"
                expression="//csv-record/name/text()"/>
      <property xmlns:ns="http://org.apache.synapse/xsd"
                name="surname"
                expression="//csv-record/surname/text()"/>
      <property name="phone" value="//csv-record/phone/text()"/>
   </log>
   <iterate xmlns:ns2="http://org.apache.synapse/xsd"
            xmlns:ns="http://org.apache.synapse/xsd"
            xmlns:sec="http://secservice.samples.esb.wso2.org"
            expression="//csv-set/csv-record">
      <target>
         <sequence>
            <log level="full">
               <property name="State" value="Iteration"/>
            </log>
            <log level="full" category="DEBUG"/>
            <dbreport>
               <connection>
                  <pool>
                     <password>passwort</password>
                     <user>esb</user>
                     <url>jdbc:mysql://localhost:3306/</url>
                     <driver>com.mysql.jdbc.Driver</driver>
                  </pool>
               </connection>
               <statement>
                  <sql>insert into info.info (name, surname, phone) values (?, ?, ?)</sql>
                  <parameter expression="//csv-record/name/text()" type="VARCHAR"/>
                  <parameter expression="//csv-record/surname/text()" type="VARCHAR"/>
                  <parameter expression="//csv-record/phone/text()" type="VARCHAR"/>
               </statement>
            </dbreport>
         </sequence>
      </target>
   </iterate>
   <log level="full" category="DEBUG"/>
</sequence>

我认为这将是一个简单的问题,但我无法得到它......就像我说的,它适用于普通的文本文件,但不适用于 XML。我尝试了不同的想法,不知道我还能尝试什么……有人知道我的错误是什么吗?

更新:

来自控制台的日志:

[2013-04-12 09:35:55,687]  INFO - DBReportMediator Successfully created data source for jdbc:mysql://localhost:3306/.
[2013-04-12 09:36:10,170]  INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:
2CBD1753113A1373101365752170177, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope x
mlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
  <Name>word</Name>
  <Surname>processor</Surname>
  <Phone>12333</Phone>
</soapenv:Body></soapenv:Envelope>
[2013-04-12 09:36:10,175]  INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:
a9252cd8-fe73-4e85-9f41-0842872d3a73, Direction: request, sequence = before-smooks, Envelope: <?xml version='1.0' encodi
ng='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
  <Name>word</Name>
  <Surname>processor</Surname>
  <Phone>12333</Phone>
</soapenv:Body></soapenv:Envelope>
[2013-04-12 09:36:10,178]  INFO - LogMediator sequence = fileWriteSequence
[2013-04-12 09:36:10,246]  INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:
a9252cd8-fe73-4e85-9f41-0842872d3a73, Direction: request, sequence = after-smooks, Envelope: <?xml version='1.0' encodin
g='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><csv-set/></soapenv
:Body></soapenv:Envelope>
[2013-04-12 09:36:10,249]  INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:
a9252cd8-fe73-4e85-9f41-0842872d3a73, Direction: request, name = , surname = , phone = //csv-record/phone/text(), Envelo
pe: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><s
oapenv:Body><csv-set/></soapenv:Body></soapenv:Envelope>
[2013-04-12 09:36:11,254]  WARN - TimeoutHandler Expiring message ID : urn:uuid:4c422f4e-aed5-4eaa-ad9b-e5407db20562; dr
opping message after global timeout of : 120 seconds

fileWriteSequence 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse"
          name="fileWriteSequence"
          trace="enable"
          statistics="enable">
   <log level="custom">
      <property name="sequence" value="fileWriteSequence"/>
   </log>
   <property xmlns:ns2="http://org.apache.synapse/xsd"
             xmlns:ns="http://org.apache.synapse/xsd"
             name="transport.vfs.ReplyFileName"
             expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.xml')"
             scope="transport"
             type="STRING"/>
   <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
   <send>
      <endpoint name="FileEpr">
         <address uri="vfs:C:/wso2esb/testordner/out"/>
      </endpoint>
   </send>
</sequence>

烟雾配置:

<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">

  <!--Configure the CSVParser to parse the message into a stream of SAX events. -->
  <resource-config selector="org.xml.sax.driver">
    <resource>org.milyn.csv.CSVParser</resource>
    <param name="fields" type="string-list">name,surname,phone</param>
  </resource-config>

</smooks-resource-list>

我还更改了上面databaseSequence的代码。

谢谢你。

4

1 回答 1

0

您的代理服务看起来不错。但我几乎没有什么顾虑。

  1. 为什么将 sql 查询作为 CDATA。请在此处查看可用示例。
  2. 您没有在连接 url 中提到数据库名称。可能这不是问题,因为您在 sql 查询中使用了 database.table 格式。
  3. 修复 1 和 2 后,如果问题仍然存在,请尝试仅使用一个序列的代理。即暂时避免文件写入序列,仅尝试使用 dbwrite 序列。

您还可以记录要在 DBReport 中介之前插入的条目。即在smooks 调解员之后,放置一个日志调解员并记录姓名、姓氏和电话。这将确保您尝试插入从消息中正确提取的值。

于 2013-04-11T15:24:50.713 回答