2013-04-29 34 views
0

我在自己的wso2代理服務中有一個自定義介體,它將傳入的xml轉換爲另一種格式,並轉而由代理將其轉發給jms隊列。但是xml格式不正確。它是這個樣子的控制檯和隊列:WSO2自定義介體未以正確的xml格式返回

<?xml version='1.0' encoding='utf-8'?> 
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
     <soapenv:Body> 
      <soapenv:Envelope xmlns:ws="http://isova.wipro.com/"> 


       <arg0>&lt;Prescription xmlns="http://hl7.org/fhir">&#xd; 
        &lt;identifier>&#xd; 
        &lt;id value="A0001"/>&#xd; 
        &lt;/identifier>&#xd; 
        &lt;status value="active"/>&#xd; 
        &lt;patient>&#xd; 
        &lt;type value="Patient"/>&#xd; 
        &lt;url value="Bhavani"/>&#xd; 
        &lt;/patient>&#xd; 
        &lt;prescriber>&#xd; 
        &lt;type value="Provider"/>&#xd; 
        &lt;url value="Dr.Mathews"/>&#xd; 
        &lt;/prescriber>&#xd; 
        &lt;medicine>&#xd; 
        &lt;identification>&#xd; 
        &lt;text value="Zintac"/>&#xd; 
        &lt;/identification>&#xd; 
        &lt;/medicine>&#xd; 
        &lt;/Prescription></arg0> 
      </soapenv:Envelope> 
     </soapenv:Body> 
    </soapenv:Envelope> 

我的代理服務:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="risresult" 
     transports="https,http,jms" statistics="disable" trace="disable" 
     startOnLoad="true"> 
     <target> 
      <inSequence> 
       <property name="ContentType" value="text/plain" scope="default" 
        type="STRING" /> 
       <class name="com.test.guru.HL7RISPrescription" /> 
       <property name="RESPONSE" value="true" /> 
       <header name="To" action="remove" /> 
       <send> 
        <endpoint> 
         <address 
          uri="jms:/prescription? 

    transport.jms.ConnectionFactoryJNDIName 
    =QueueConnectionFactory&amp;java.naming. 
    factory.initial=org.apache.activemq.jndi. 
    ActiveMQInitialContextFactory&amp;java. 
    naming.provider.url=tcp://localhost:61616" /> 
        </endpoint> 
       </send> 
      </inSequence> 
      <outSequence> 
       <drop /> 
      </outSequence> 
      <faultSequence /> 
     </target> 
     <parameter name="transport.jms.ContentType"> 
      <rules> 
       <jmsProperty>contentType</jmsProperty> 
       <default>application/xml</default> 
      </rules> 
     </parameter> 
     <description></description> 
    </proxy> 

可能是什麼原因呢?是因爲axis2元素的問題嗎?

我的中介類有這些最後陳述:

OMFactory factoryOM = OMAbstractFactory.getOMFactory(); 
    OMElement code  = factoryOM.createOMElement("arg0","",""); 
    code.setText(pdoc.toString()); 
    axis2Element.addChild(code); 

回答

0

在conifiguration看看來你是使用代理服務器的順序。

<property name="ContentType" value="text/plain" scope="default" 
        type="STRING" /> 

這是什麼原因?刪除並嘗試。這應該導致逃逸的XML使其成爲文本/純文本。在班級調解員之前和之後使用日誌中介並記錄日誌,以觀察郵件內容,如果還有其他問題,將對您有所幫助。

+0

謝謝Shelan。我刪除它,現在嘗試,它沒有幫助。它仍然給出同樣的問題。對我有其他建議嗎? – gnanagurus 2013-04-29 18:27:48

+2

只是注意到在調解器中你使用的是code.setText(pdoc.toString());使用該字符串構建OMelement(未設置文本),然後添加爲arg0的子元素。您將它設置爲文本而不是xml元素。 – 2013-04-29 18:34:31

+0

參考此轉換。 http://www.keith-chapman.org/2008/10/axiom-how-to-crate-omelement-from.html – 2013-04-29 18:36:06

0

這應該很好地工作..

公共類GetLocationMockMediator擴展AbstractMediator {

public boolean mediate(MessageContext context) {   
    StringBuilder xml = new StringBuilder("<result><field1>field1Value</field1></result>"); 

    InputStream xmlInputStream = new ByteArrayInputStream(xml.toString().getBytes()); 
    try { 
     context.getEnvelope().getBody().addChild(new StAXOMBuilder(xmlInputStream).getDocumentElement()); 
    } catch (final Exception e) { 
     // ignore 
    } 

    return true; 
} 

}