简体   繁体   English

WSO2 ESB-XML到MySQL数据库

[英]WSO2 ESB - XML to MySQL Database

I need a solution for a problem: I just tried this example for the WSO2 ESB and it is working: http://wso2.org/library/articles/2011/01/wso2-esb-example-file-processing 我需要一个解决方案:我刚刚为WSO2 ESB尝试了此示例,并且该示例正在运行: http : //wso2.org/library/articles/2011/01/wso2-esb-example-file-processing

But I like to use an XML file as input and write this to a MySQL-DB. 但是我喜欢使用XML文件作为输入并将其写入MySQL-DB。 The XML-file looks like this: 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>

If i put this into my "in"-folder the file will be moved to the "out"-folder, but nothing is written into the database. 如果我将此文件放入“ in”文件夹,则文件将移至“ out”文件夹,但没有任何内容写入数据库。 There is no error message. 没有错误信息。

My Proxy-Service: 我的代理服务:

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

And my Sequence: 而我的序列:

    <?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>

I thought this would be a simple problem, but I'm not able to get it... Like I said, it's working with a normal text-file, but not with XML. 我以为这将是一个简单的问题,但我无法解决……就像我说的那样,它可以使用普通的文本文件,但不能使用XML。 I tried different thinks and have no idea what else I could try... Does someone know what's my mistake? 我尝试了不同的想法,不知道还能尝试什么...有人知道我的错误吗?

Update: 更新:

The log from the console: 来自控制台的日志:

[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

The fileWriteSequence looks like this: 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 config: 烟雾配置:

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

I also changed the code of the databaseSequence above. 我还更改了上面的databaseSequence的代码。

Thank you. 谢谢。

Your proxy service looks ok. 您的代理服务看起来还不错。 But I have few concerns. 但我很少担心。

  1. Why have you put the sql query as CDATA. 为什么将sql查询作为CDATA。 Please see the sample available here . 请在此处查看可用的示例。
  2. You have not mentioned the database name in the connection url. 您没有在连接URL中提到数据库名称。 May be it is not a problem since you have used the database.table format in your sql query. 可能不是问题,因为您在sql查询中使用了database.table格式。
  3. After fixing and 1 and 2, if the issue still exists, try your proxy with only one sequence. 修复了1和2之后,如果问题仍然存在,请仅按一个顺序尝试使用代理。 ie Avoid the file write sequence temporarily and try only with the dbwrite sequence. 即暂时避免文件写入序列,仅尝试dbwrite序列。

You can also log the entries which you are going to insert before the DBReport mediator. 您还可以在DBReport中介程序之前记录要插入的条目。 ie Right after the smooks mediator, put a log mediator and log the name, surname and phone. 例如,在伪装中介器之后,放置一个日志中介器,并记录名称,姓氏和电话。 This will make sure you are trying to insert values which are correctly extracted from the message. 这样可以确保您尝试插入从消息中正确提取的值。

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

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