1

我的请求如下

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:hel="http://example.org/HelloService">
   <soapenv:Header>
<sampler>Test</sampler>     
   </soapenv:Header>
   <soapenv:Body>
  <hel:LastName>
     <lastName>Test</lastName>
  </hel:LastName>
   </soapenv:Body>
</soapenv:Envelope>

我的暴露 CXF:proxy-service 的流程如下

<flow name="WS_In">
    <http:inbound-endpoint address="http://localhost:8080/HelloService"
        exchange-pattern="request-response">            
        <cxf:proxy-service wsdlLocation="classpath:helloservice.wsdl"
            namespace="http://example.org/HelloService" service="ProxyService" >
            <cxf:inInterceptors>
            <spring:bean id="inLogger"  
                class="org.apache.cxf.interceptor.LoggingInInterceptor" />  
            <spring:bean id="msgInt" class="com.example.components.MessageInterceptor"/>            
            </cxf:inInterceptors>                           
        </cxf:proxy-service>
    </http:inbound-endpoint>
    <component>
        <spring-object bean="proxyService"></spring-object>         
    </component>        
    <echo-component></echo-component>   
</flow>

但我无法获取肥皂标题中的元素。我尝试使用如下方法使用拦截器

@Override
public void handleMessage(SoapMessage message) throws Fault {
    System.out.println("The headers is " + message.getHeaders() );

}

但这是打印一个emply Collection。

请建议我如何得到这个。

4

2 回答 2

1

尝试在代理服务之前在您的流程中添加自定义处理器

<flow name="WS_In">
<http:inbound-endpoint address="http://localhost:8080/HelloService"
    exchange-pattern="request-response">
    <custom-processor class="your.package.SoapHeaderObserver" />   
    <cxf:proxy-service wsdlLocation="classpath:helloservice.wsdl"
        namespace="http://example.org/HelloService" service="ProxyService" >
        <cxf:inInterceptors>
        <spring:bean id="inLogger"  
            class="org.apache.cxf.interceptor.LoggingInInterceptor" />  
        <spring:bean id="msgInt" class="com.example.components.MessageInterceptor"/>            
        </cxf:inInterceptors>                           
    </cxf:proxy-service>
</http:inbound-endpoint>
<component>
    <spring-object bean="proxyService"></spring-object>         
</component>        
<echo-component></echo-component>   

public class SoapHeaderObserver { 
   doSomething(SoapMessage message) {
     //try to get header here
   } 
}

此外,您的自定义处理器可以实现 MessageProcessor 或 Callable。在此处查看如何实现 Mule 消息观察器?

而且,该框架有很多您可能会使用的处理器,而不是构建您自己的处理器。

于 2013-01-25T17:15:43.893 回答
1

我得到的解决方案是在我的代理服务之前添加一个消息处理器。

下面给出的是我的处理器。

public class SOAPHeaderExtractor implements MessageProcessor {

    @Override
    public MuleEvent process(MuleEvent event) {     
        try
        {
            MuleMessage inputMessage =  event.getMessage(); 
            SOAPMessage soapMsg = MessageFactory.newInstance().createMessage(null, 
                    new java.io.ByteArrayInputStream(inputMessage.getPayloadAsString().getBytes()));
             SOAPHeader header = soapMsg.getSOAPHeader();            
             System.out.println(header.getElementsByTagName("sampler").item(0).getTextContent() );
        }
        catch(Exception e){
            e.printStackTrace();            
        }       
        return event ;
    }
}

以及我的流程的变化。

<http:inbound-endpoint address="http://localhost:8080/HelloService"
        exchange-pattern="request-response">
        <custom-processor class="com.example.processors.SOAPHeaderExtractor" /> 
        <cxf:proxy-service wsdlLocation="classpath:helloservice.wsdl"
            namespace="http://example.org/HelloService" service="ProxyService" >
            <cxf:inInterceptors  >
            <spring:bean id="inLogger" class="org.apache.cxf.interceptor.LoggingInInterceptor" />   
            </cxf:inInterceptors>   
        </cxf:proxy-service>        
</http:inbound-endpoint>

如果有更好的方法,请提出建议。

于 2013-01-25T20:49:59.927 回答