我的要求如下:
<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:代理服务如下
<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>
但我无法获取soap标头中的元素。我尝试使用interceprots与下面的方法
@Override
public void handleMessage(SoapMessage message) throws Fault {
System.out.println("The headers is " + message.getHeaders() );
}
但这是印刷一个真实的收藏品。
请建议我如何得到这个。
答案 0 :(得分: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。看看How to implement a Mule Message Observer?
而且,该框架有许多处理器可供您使用,而不是构建自己的处理器。
答案 1 :(得分: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>
如果有更好的方法,请提出建议。