2016-03-04 60 views
0

我們在Linux系統上收到編碼爲ISO-8859-1的XML文件(格式不正確)。一個ESB代理挑選它並使用序列與SAMBA VFS一起轉發到Windows共享。ISO-8859-1通過VFS輸入到UTF-8輸出

在Windows上,某些字符顯示不正確,因爲我無法將其編碼爲UTF-8。我嘗試過幾種方法都沒有成功。使用xxd這些是我遇到的問題:

0000b70: 4c55 45ef bfbd 5344 204a 503c 2f69 7373 LUEï.½SD JP</iss 
0000bf0: 5445 4749 4320 5641 4c55 45ef bfbd 5344 TEGIC VALUEï.½SD 

半符號。代理是:

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy" transports="vfs" statistics="enable" trace="disable" startOnLoad="true"> 
    <target faultSequence="ErrorSequence"> 
    <inSequence> 
     <property name="OUT_ONLY" value="true"/> 
     <clone sequential="true"> 
     <target sequence="Sequence"/> 
     </clone> 
    </inSequence> 
    </target> 
    <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter> 
    <parameter name="transport.PollInterval">60</parameter> 
    <parameter name="transport.vfs.MoveAfterProcess">file:///data/process</parameter> 
    <parameter name="transport.vfs.FileURI">file:///data/incoming</parameter> 
    <parameter name="transport.vfs.MoveAfterFailure">file:///data/failed</parameter> 
    <parameter name="transport.vfs.FileNamePattern">security.*</parameter> 
    <parameter name="transport.vfs.ContentType">text/plain; charset="UTF-8"</parameter> 
    <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter> 
    <description/> 
</proxy> 

的順序是:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="Sequence" onError="ErrorSequence" trace="enable"> 
    <xslt key="UTF8Convert"> 
    <property name="encoding" value="UTF-8"></property> 
    <property name="messageType" value="text/xml"></property> 
    <property name="ContentType" value="text/xml; charset=UTF-8</property> 
    </xslt> 
    <property xmlns:ns="http://org.apache.synapse/xsd" name="filename" expression="(get-property('transport', 'FILE_NAME'))"></property> 
    <property name="transport.vfs.ContentType" value="text/xml; charset=&quot;UTF-8&quot;" scope="transport" type="STRING"></property 
    <property xmlns:ns="http://org.apache.synapse/xsd" name="transport.vfs.ReplyFileName" expression="get-property('filename')" scope="transport"></property> 
    <property name="OUT_ONLY" value="true"></property> 
    <property xmlns:ns="http://org.apache.synapse/xsd" name="serverurl" expression="fn:concat('vfs:smb://',fn:normalize-space(get-property('DOMAIN')),'\',fn:normalize-space(get-property('USERNAME')),':',fn:normalize-space(get-property('PWD')),'@',fn:normalize-space(get-property('DESTINATION')),'/',fn:normalize-space(get-property('DIR')),'/')"></property> 
    <header xmlns:ns="http://org.apache.synapse/xsd" name="To" expression="fn:concat(get-property('serverurl'),get-property('filename'))"></header> 
    <send> 
    <endpoint> 
     <default></default> 
    </endpoint> 
    </send> 
</sequence> 

的XSLT是:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8"></xsl:output> 
    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"></xsl:apply-templates> 
    </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

跟蹤日誌是這樣的:

00:35:09,924 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : Sequence<ApexXMLToEPMSequence> 
00:35:09,924 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting the onError handler : ErrorSequence for the sequence : Sequence 
00:35:09,924 [-] [vfs-Worker-18] INFO TRACE_LOGGER Sequence <SequenceMediator> ::mediate() 
00:35:09,925 [-] [vfs-Worker-18] INFO TRACE_LOGGER Mediation started from mediator position : 0 
00:35:09,925 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : XSLT mediator 
00:35:09,927 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting parameter 'encoding' to 'UTF-8' 
00:35:09,927 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting parameter 'messageType' to 'text/xml' 
00:35:09,927 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting parameter 'ContentType' to 'text/xml; charset=UTF-8' 
00:35:09,927 [-] [vfs-Worker-18] INFO TRACE_LOGGER output method: xml; encoding: UTF-8 
00:35:09,927 [-] [vfs-Worker-18] INFO TRACE_LOGGER Using org.apache.synapse.util.jaxp.StreamSourceBuilder 
00:35:09,932 [-] [vfs-Worker-18] INFO TRACE_LOGGER Transformation completed - processing result 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER Replace node with result 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : XSLT mediator 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : Property mediator 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting property : filename at scope : default to : security.2016046.113132 (i.e. result of expression : (get-property('transport', 'FILE_NAME'))) 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : Property mediator 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : Property mediator 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting property : transport.vfs.ContentType at scope : transport to : text/xml; charset="UTF-8" (i.e. constant : text/xml; charset="UTF-8") 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : Property mediator 
00:35:09,933 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : Property mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting property : transport.vfs.ReplyFileName at scope : transport to : security.2016046 (i.e. result of expression : get-property('filename')) 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : Property mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : Property mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting property : OUT_ONLY at scope : default to : true (i.e. constant : true) 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : Property mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : Property mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Setting property : serverurl at scope : default to : vfs:smb://AC\user:[email protected]/folder/ (i.e. result of expression : fn:concat('vfs:smb://',fn:normalize-space(get-property('DOMAIN')),'\',fn:normalize-space(get-property('USERNAME')),':',fn:normalize-space(get-property('PWD')),'@',fn:normalize-space(get-property('DESTINATION')),'/', fn:normalize-space(get-property('DIR')),'/')) 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : Property mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : Header mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Set SOAP header : To to : vfs:smb://AC\user:[email protected]/folder/security.2016046 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : Header mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Start : Send mediator 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER Sending message through endpoint : null resolving to address = vfs:smb://AC\user:[email protected]/folder/security.2016046 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER SOAPAction: urn:mediate 
00:35:09,934 [-] [vfs-Worker-18] INFO TRACE_LOGGER WSA-Action: urn:mediate 
00:35:09,935 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : Send mediator 
00:35:09,935 [-] [vfs-Worker-18] INFO TRACE_LOGGER End : Sequence <Sequence> 

輸出上Windows顯示爲上面沒有編碼的輸入到UTF-8。我如何使ESB重新編碼?

回答

0

如果你的xml文件被編碼爲ISO-8859-1,你爲什麼要配置你的VFS代理把它讀爲UTF-8:<parameter name="transport.vfs.ContentType">text/plain; charset="UTF-8"</parameter>

看來你讀它爲UTF-8,如果你想強行與VFS輸出編碼,嘗試設置一個命名的屬性寫爲UTF-8

「CHARACTER_SET_ENCODING」之前送

0

如果您嘗試使用UTF-8解碼ISO-8859-1編碼文件,則最終會出現一些符號字符表示(如重音字符)。所以最好的事情就是發送文件。

使用VFS參數如下圖所示,

<parameter name="transport.vfs.ContentType">text/plain; charset=iso-8859-1</parameter> 

添加以下屬性,並嘗試您的方案。

<property name="messageType" value="text/plain; charset=iso-8859-1" scope="axis2"/>