通过smook为XML到XML转换创建唯一的文件名

时间:2015-10-20 02:56:45

标签: wso2esb smooks

我一直在使用smooks来尝试处理半大型XML文件(170MB - 250MB)。我设法让它工作,我可以让它很快地处理我的XML中的一些元素。

我相信我遇到的问题是我在<file:fileNamePattern>元素中设置的输出文件名不够独特。

我是否有通过文件编号增量(基于当前目录中的文件数),时间戳或随机生成的messageId在smooks配置中创建唯一文件名?

非常感谢任何帮助。我发布了我收到的错误以及我在下面测试过的smooks配置。

Smooks配置

<?xml version="1.0" encoding="UTF-8"?>
<smooks-resource-list xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.3.xsd" 
xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd" 
xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.2.xsd" 
xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" 
xmlns:file="http://www.milyn.org/xsd/smooks/file-routing-1.1.xsd">

 <core:filterSettings defaultSerialization="false" type="SAX" />
 <!-- Extract and decode data from the message.  Later Used in the freemarker template.
         Note that we could also use a NodeModel here... -->
  <jb:bean beanId="row" class="java.util.Hashtable" createOnElement="row">

     <jb:value data="row/@iBookID" decoder="Integer" property="iBookID"></jb:value>
     <jb:value data="row/@vchEAN" decoder="String" property="vchEAN"></jb:value>
     <jb:value data="row/@vchISBN" decoder="String" property="vchISBN"></jb:value>

 </jb:bean>

<jb:bean beanId="myDate" createOnElement="row"/>
</jb:bean>

 <ftl:freemarker applyOnElement="row">
  <ftl:template><!--<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
        <p:insert_Levels_AR_ISBN_operation>
            <p:iBookID xmlns:xs="http://ws.wso2.org/dataservice">${row.iBookID}</p:iBookID>
            <p:vchEAN xmlns:xs="http://ws.wso2.org/dataservice">${row.vchEAN}</p:vchEAN>
        </p:insert_Levels_AR_ISBN_operation>
    </soapenv:Body>
</soapenv:Envelope>--></ftl:template>
  <ftl:use>
       <!-- Output the templating result to the "rowSplitStream" file output stream... -->
       <ftl:outputTo outputStreamResource="rowSplitStream"></ftl:outputTo>
  </ftl:use>
</ftl:freemarker>

<!-- Create/open a file output stream.  This is writen to by the freemarker template (above).. -->
<file:outputStream openOnElement="row" resourceName="rowSplitStream">
     <file:fileNamePattern>isbn-${myDate?datetime}.xml</file:fileNamePattern>
     <file:destinationDirectoryPattern>var/process/renaissance/smooks/tmprows</file:destinationDirectoryPattern>
     <file:highWaterMark mark="10000000"></file:highWaterMark>
</file:outputStream>

</smooks-resource-list>

错误消息

Caused by: org.milyn.SmooksException: Could not rename [/opt/wso2esb-4.9.0/var/process/renaissance/smooks/tmprows/.d95ba4b8-aa71-44e6-8486-adb8c9ad4bdd2660246907791429571.working] to [/opt/wso2esb-4.9.0/var/process/renaissance/smooks/tmprows/isbn-102-9780394885124-0-394-88512-0.xml]. [/opt/wso2esb-4.9.0/var/process/renaissance/smooks/tmprows/isbn-102-9780394885124-0-394-88512-0.xml] already exists.
    at org.milyn.routing.file.FileOutputStreamResource.renameWorkingFile(FileOutputStreamResource.java:308)
    at org.milyn.routing.file.FileOutputStreamResource.closeResource(FileOutputStreamResource.java:284)
    at org.milyn.io.AbstractOutputStreamResource.executeVisitLifecycleCleanup(AbstractOutputStreamResource.java:135)
    at org.milyn.delivery.sax.SAXHandler.endElement(SAXHandler.java:245)
    at org.milyn.delivery.SmooksContentHandler.endElement(SmooksContentHandler.java:83)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:70)
    at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:75)
    ... 19 more

2 个答案:

答案 0 :(得分:1)

我遇到类似的问题 - 看起来升级到Smooks 1.4就是答案...... http://www.smooks.org/mediawiki/index.php?title=V1.4:Smooks_v1.4_User_Guide上的PUUID和PTIME

但如果有人知道任何不同,请告诉我:)

答案 1 :(得分:0)

也许您可以使用输入xml中的其他节点(如row。@ iBookID)来编写文件名吗?