2013-04-29 33 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; 
} 

}