2014-12-19 45 views
0

我有一種情況,我必須解析CDATA部分中涉及複雜業務邏輯的平面數據,並生成可發送到其他服務的XML請求。由於生成XML涉及解析平面文件的複雜業務邏輯,因此我不認爲我可以使用現有的WSO2介體(如XSLT等)。我覺得階級調解人可以使用。任何建議?WSO2 Mediator解析平面數據?

輸入: 5 A4L01G0
5 $ P200033450
56- A2A08
5- A2A14
5- A2A16
16- A2G01
- A2G02
7723- A2J04
5-A2K023
5-A2K03
767312365- A2P01
5- A2R12313107
512313- A2S02
6F01
6F02
36127316F03
6F04
900000000021]]

預期輸出: 說,例如,

<RequestMessage> 
    <element1>1</element1> 
    <element>Data</DCTLibraryName> 
    <dummyy>PosinaManualLibraryCSet1</dummy> 

    <DCTIDs> 
     <elelemt10 attrib=" Base" attrib1="eweew" attrib2="GRR_D_PACK" Name="lib"/> 
     <elelemt11 attrib ="Base" attrib1="10665" attrib2="temp" Name="lib"/> 
> 
</RequestMessage> 

回答

0

如果你對Java更滿意,你可以實現一個自定義中介。

//some idea - this code never got tested in a real setup 
public class MyCustomMediator extends AbstractMediator { 
    public boolean mediate(MessageContext context) { 
     //omitted any safety checks/exception handling 
     SynapseLog synLog = getLog(context); 
     //adapt to your message 
     OMElement element = (OMElement) context.getEnvelope().getBody() 
        .getFirstOMChild(); 
     BufferedReader reader = new BufferedReader(new StringReader(
        element.getText())); 
     // your custom logic in here 

     //return the result of your custom logic 
     element.setText(result.toString()); 

     return true; 
    } 
} 
0

我建議使用XSLT mediator.It具有豐富的函數來讀取CDATA部分並從中計算xml .XSLT是位成本,但如果您的負載不高,則可以使用XSLT。如果你使用類中介所有邏輯你必須實現..