2015-10-20 46 views
0

我一直在與smooks一起嘗試處理半大型XML文件(170MB - 250MB)。我設法讓它工作,我可以很快地處理XML中的一些元素。通過smook創建XML到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 

回答

0

也許你可以使用的其他節點,像一行。@ iBookID,從輸入XML來編寫文件名?

+0

我做但它不夠獨特。許多行可以是重複的。這些都通過表存儲過程來處理。 – John

+0

有沒有辦法從smooks內部生成一個隨機數或UID?或者僅僅基於我們存儲在XML中的信息?我一直無法找到關於此的任何信息。謝謝。 – John

+0

我無法幫助你:當我需要用smooks分割一個大的xml文件時,我不會將這些片段發送到文件中,而是發送到JMS消息中,我不必擔心獨特的名稱......你能否考慮使用JMS代理? –