我通过synapse+axis2+activemq来实现webservice异步调用。 我的客户端采用STUB方式。 原先不加synapse跳转,返回的soap消息: 
------------------------------------------ 
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: application/soap+xml; action="urn:getInfoResponse";charset=UTF-8 Transfer-Encoding: chunked Date: Tue, 23 Aug 2011 07:32:52 GMT 10c <?xml version='1.0' encoding='UTF-8'?> 
   <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"> 
      <soapenv:Body> 
         <ns:getInfoResponse xmlns:ns="http://test"> 
            <ns:return>webservice:dsfsfsdsdf</ns:return>         </ns:getInfoResponse> 
      </soapenv:Body> 
   </soapenv:Envelope> 

------------------------------------------在自动生成的stub中,他解析获取soapenv:Body ->  ns:getInfoResponse ->ns:return 里的值
但经过我synapse跳转后,soap消息如下:------------------------------------------ 
HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=UTF-8; action="urn:getInfoResponse"JMS_DESTINATION: ID:sunnaoh-32807-1314058857144-0:2:43JMS_MESSAGE_ID: ID:sunnaoh-32807-1314058857144-0:3:43:1:1JMS_EXPIRATION: 0JMS_COORELATION_ID: ID:sunnaoh-32807-1314058857144-0:2:43:1:1JMS_PRIORITY: 4JMS_REDELIVERED: falseJMS_DELIVERY_MODE: 2Server: Apache-Coyote/1.1JMS_TIMESTAMP: 1314087564021Date: Tue, 23 Aug 2011 08:19:24 GMTTransfer-Encoding: chunked
333<?xml version='1.0' encoding='UTF-8'?>
   <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
      <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
         <wsa:MessageID>urn:uuid:6e095461-fe09-4d20-84ff-8696de1de720</wsa:MessageID>
         <wsa:Action>urn:getInfoResponse</wsa:Action>
         <wsa:RelatesTo>urn:uuid:34D85A466163EF41981314088922900</wsa:RelatesTo>
      </soapenv:Header>
      <soapenv:Body>
         <axis2ns43:text xmlns:axis2ns43="http://ws.apache.org/commons/ns/payload">&lt;?xml version='1.0' encoding='UTF-8'?>&lt;soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">&lt;soapenv:Body>&lt;ns:getInfoResponse xmlns:ns="http://test">&lt;ns:return>webservice:dsfsffsssf&lt;/ns:return>&lt;/ns:getInfoResponse>&lt;/soapenv:Body>&lt;/soapenv:Envelope></axis2ns43:text>      </soapenv:Body>
   </soapenv:Envelope>0
------------------------------------------ 
可以看到,加了JMS消息信息,然后将上面一个SOAP消息包在了自己的BODY中,自动套了axis2ns43:text标签,似乎是以TEXT存放。但这样,以原先stub解析方式就无法取到值了。我应该如何处理这个soap消息?是自己改写stub自带的解析方式(如果要改写解析方式,是怎么一个思路)?还是在synapse这里修改配置,去掉JMS消息头,还是?在网上搜了半天,也没找到相对应的,仅仅得到一个提示,就是在synapse配置中,    <proxy name="Proxy2" transports="jms">
        <target>
            <endpoint>
                <address uri="http://10.16.64.14:8088/axis2/services/TestInterface"/>
            </endpoint>
            <outSequence>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="http://10.16.64.14:8088/axis2/services/TestInterface?wsdl"/>
        <parameter name="transport.jms.ContentType">
            <rules>
                <jmsProperty>contentType</jmsProperty>
                <default>application/soap+xml</default>
            </rules>
        </parameter>
    
    </proxy>指定contentType 这样就不会产生axis2ns43:text ,但我加上去之后,还是有这个标签。谁对这方面有经验,请指教,谢谢。

解决方案 »

  1.   

    如果可以通过配置来解决问题最好不过了,
    不过我对lz解析2个xml的方法表示怀疑。
    你应该写一个通用的方法来解析ns:return,管他存在在哪里。肯定是你方法不当。
      

  2.   

    先用xmlns取到axis2ns43:text标签的内容,然后再用原先的方法取body的内容
    Element el = doc.getRootElement();
    List ls = el.getChildren("axis2ns43=\"http://ws.apache.org/commons/ns/payload\"");  
      

  3.   

    不知道你用什么解析的,看看有没有document.getElementByTagName方法。
    你这个通过层次关系来找,当结构变化了,必然出错。
      

  4.   

    谢谢楼上两位回复。我自己写了一层解析。我取外层body中的TEXT(即axis2ns43的这一层内容),取出来就是XML,然后解析这个XML,重新拼装一个soap:enveloap,替代上层的soap:enveloap,这样就回归到了第一个soap消息的格式,等于说:第二个soap消息->解析转换->第一个soap消息  ->取值这样就过滤了一下。