Mule 在基于soap的web服务中访问多消息

Mule 在基于soap的web服务中访问多消息,mule,Mule,在基于soap的web服务中,我希望访问Mule消息属性。我知道一种使用RequestContext.getEvent().getMessage()的方法,但我想这是不推荐的。访问web服务中多消息属性的另一种方法。有人能提供一些关于这方面的建议吗 代码片段 <flow name="MyWebService" doc:name="MyWebService"> <http:inbound-endpoint exchange-pattern="request-respons

在基于soap的web服务中,我希望访问Mule消息属性。我知道一种使用RequestContext.getEvent().getMessage()的方法,但我想这是不推荐的。访问web服务中多消息属性的另一种方法。有人能提供一些关于这方面的建议吗

代码片段

<flow name="MyWebService" doc:name="MyWebService">
    <http:inbound-endpoint exchange-pattern="request-response" address="${WEB_SERVICE_PROTOCOL}://${WEB_SERVICE_HOST}:${WEB_SERVICE_PORT}/MyWebService?wsdl" tracking:enable-default-events="true">
        <cxf:jaxws-service serviceClass="com.XXX.XXX.service.MyWebService" doc:name="SOAP"/>
    </http:inbound-endpoint>
    <component doc:name="My Web Service">
        <spring-object bean="WebServiceImpl"/>
    </component>
</flow>            

如果您有权访问MuleMessage,则可以使用该方法获得所需的属性

Set<String> getPropertyNames(PropertyScope scope);

这就是您试图实现的吗?

您可以通过根本不实现服务接口,并将SOAP请求作为Mule消息处理(属性可访问),而不是处理服务类中的反序列化对象来实现这一点

下面是一个示例片段,假设您已经使用wsdl2java从WSDL生成了必要的类和接口:

<flow name="WebServiceFlow">
    <http:inbound-endpoint exchange-pattern="request-response"
        address="http://localhost:8080/services/some" />

    <cxf:jaxws-service
        serviceClass="com.amce.SomePortType" />

    <choice>
        <when
            expression="#[cxf_operation.localPart == 'SomeOperation']">
            <flow-ref name="HandleSomeOperation" />
        </when>

根据您获取消息属性的目的,一个选项是使用cxf拦截器访问消息。请参见下面的示例

添加拦截器:

<cxf:jaxws-service serviceClass="org.example.HelloWorld">
   <cxf:inInterceptors>
     <spring:bean class="org.example.MyInterceptor"/>
   </cxf:inInterceptors>
</cxf:jaxws-service>

我的web服务有一个界面和一个实现,如上所示。我编辑了我的问题,添加了一个代码片段。因此,在我的实现类中,只有MuleMessage有效负载可用。如果您有一个实现类,那么您必须使用
RequestContext.getEvent().getMessage()
。它已被弃用,但MuleSoft仍然没有为您的用例提供替代品,因此您没有其他选择。感谢Anton的输入,这也是使用CXF拦截器获取消息的另一种方式。但在web service impl中,我希望阅读包含文件元数据的Mule message属性,并更新数据库因此,我将有一个从web服务到dao层的调用,dao层将把元数据存储在数据库中。
<cxf:jaxws-service serviceClass="org.example.HelloWorld">
   <cxf:inInterceptors>
     <spring:bean class="org.example.MyInterceptor"/>
   </cxf:inInterceptors>
</cxf:jaxws-service>
package org.example;

import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.Phase;
import org.mule.api.MuleEvent;
import org.mule.api.MuleMessage;

public class MyInterceptor extends AbstractSoapInterceptor {

    public MyInterceptor() {
        super(Phase.USER_PROTOCOL);
    }

    @Override
    public void handleMessage(SoapMessage message) throws Fault {
         MuleEvent muleEvent = (MuleEvent)message.getContextualProperty("mule.event");
         MuleMessage muleMessage = muleEvent.getMessage();
         System.out.println(muleMessage.toString());
    }

}