通过smook创建XML到XML转换的唯一文件名
问题描述:
我一直在与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
答
也许你可以使用的其他节点,像一行。@ iBookID,从输入XML来编写文件名?
答
我有一个类似的问题 - 看起来像升级到1.4的Smooks答案是... PUUID和PTIME上http://www.smooks.org/mediawiki/index.php?title=V1.4:Smooks_v1.4_User_Guide
但是如果有谁知道有什么不同,请让我知道太:)
我做但它不够独特。许多行可以是重复的。这些都通过表存储过程来处理。 – John
有没有办法从smooks内部生成一个随机数或UID?或者仅仅基于我们存储在XML中的信息?我一直无法找到关于此的任何信息。谢谢。 – John
我无法帮助你:当我需要用smooks分割一个大的xml文件时,我不会将这些片段发送到文件中,而是发送到JMS消息中,我不必担心独特的名称......你能否考虑使用JMS代理? –