如何发送消息在wso2esb-4.8.1中使用Send mediator

时间:2014-10-21 12:51:53

标签: wso2 wso2esb wso2carbon

我使用的是wso2esb-4.8.1, 我希望发送我的消息之后,想要审核我的消息出去并获得审计当我使用callout mediator Url选项我使用send mediator URI它不工作。 样本代理和序列是

 <proxy xmlns="http://ws.apache.org/ns/synapse" name="Test_Proxy" transports="https http" startOnLoad="true" trace="disable">
        <description/>
        <target>
            <inSequence onError="FaultSeq">
                <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
                <log>
                <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" name="ProxyInRequest" 
                expression="/soapenv:Envelope"/>
                </log>
                 <xquery key="ProxyRequestTransformation">
            <variable xmlns:ns="http://org.apache.synapse/xsd" name="Operation" expression="//Operation/text()" type="STRING"/>
            <variable xmlns:ns="http://org.apache.synapse/xsd" name="ServiceNameSpace" expression="//ServiceNameSpace/text()" type="STRING"/>
            <variable name="Payload" type="DOCUMENT_ELEMENT"/>
            <variable xmlns:ns="http://org.apache.synapse/xsd" name="ServiceName" expression="//Service/text()" type="STRING"/>
        </xquery>

           <send>
                    <endpoint>
                        <address uri="http://localhost:8081/middleware/services/test1" format="soap11"/>
                    </endpoint>
                </send>
            </inSequence>
            <outSequence onError="FaultSeq">
                <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
                    <property action="set" name="RESPONSE" scope="default" type="STRING" value="true"/>
                <send/>
                <sequence key="AuditSeq"/>
            </outSequence>
        </target>
        <publishWSDL key="EaiEnvelope"/>
</proxy>

并且sequnce就像这样

<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuditSeq"> <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
    <property xmlns:ns="http://org.apache.synapse/xsd" name="RESULT_CODE" expression="get-property('ResultCode')" scope="default" type="STRING"/>
    <property xmlns:ns="http://org.apache.synapse/xsd" name="RESULT_MESSAGE" expression="get-property('ResultMessage')" scope="default" type="STRING"/>
    <property xmlns:ns="http://org.apache.synapse/xsd" name="REFERENCE_ID" expression="get-property('ReferenceID')" scope="default" type="STRING"/>
    <property xmlns:ns="http://org.apache.synapse/xsd" name="FAULT_DETAILS" expression="concat(get-property('ERROR_CODE'),get-property('ERROR_MESSAGE'))" scope="default" type="STRING"/>
            <payloadFactory media-type="xml">
                <format>
                    <open:processRequest xmlns:open="http://www.openuri.org/">
                        <aud:Auditor xmlns:aud="http://jhm.kkk.fff/Auditor">
                            <aud:Request>
                                <aud:Operation_Name>processRequest</aud:Operation_Name>
                                <aud:Auditor_InputData>
                                    <aud:Result_Code>$1</aud:Result_Code>
                                    <aud:Result_Message>$2</aud:Result_Message>
                                    <aud:Reference_Id>$3</aud:Reference_Id>
                                    </aud:Auditor_InputData>
                            </aud:Request>
                        </aud:Auditor>
                    </open:processRequest>
                </format>
                <args>

                    <arg evaluator="xml" expression="get-property('RESULT_CODE')"/>
                    <arg evaluator="xml" expression="get-property('RESULT_MESSAGE')"/>
                     <arg evaluator="xml" expression="get-property('REFERENCE_ID')"/>
                     </args>
            </payloadFactory>
            <header name="Action" scope="default" value="http://www.openuri.org/processRequest"/>
           <send>
                <endpoint>
                    <address uri="http://localhost:8081/middleware/services/AuditService" format="soap11"/>
                </endpoint>
            </send>
        </sequence>

如果我使用send mediator配置,则不会调用它。因为callout mediator与URL选项一起工作正常并再次使用addressendpoint,

                                                                   

    if i use below properties its working fine




<callout serviceURL="http:///localhost:8081/middleware/services/AuditService">
                <source type="envelope"/>
                <target key="IsThisResponse"/>
            </callout>

我使用了这个属性,我得到了WSAction,soapAction变为NULL

 < header name="Action" scope="default" value="urn:http://www.openuri.org/processRequest"/>
            <header action="remove" name="To"/>
    <property action="set" name="RESPONSE" scope="default" type="STRING" value="true"/>
<property name="target.endpoint" value="AuditEndpoint"/>  
       <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>  
       <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>  

提前致谢

1 个答案:

答案 0 :(得分:1)

首先,您必须更改代理中的 outSequence

  • 您应该使用克隆介体
  • 克隆响应消息
  • 在第一个目标中,您使用<send/>
  • 将回复发回给客户
  • 在第二个目标中,您使用<sequence key="AuditSeq"/>
  • 调用AuditSeq

第二件事,我找不到 OUT_ONLY 属性设置为true,因此,http://localhost:8081/middleware/services/AuditService的审核服务应该向您发回响应,您必须配置发送中介来处理此响应(您不希望再次调用代理的outSeuqence)=&gt;您必须更改您的AuditSeq,将xml attribut 接收添加到发送中介:

<send receive="AuditServiceResponse">
  <endpoint>
    <address uri="http://localhost:8081/middleware/services/AuditService" format="soap11"/>
  </endpoint>
</send>

其中 AuditServiceResponse 是一个序列(您可以记录或删除响应或任何您想要的内容)

所以,你代理的outSequence应该成为:

<outSequence onError="FaultSeq">
    <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
    <clone>
        <target>
            <sequence>
                <send/>
            </sequence>
        </target>
        <target>
            <sequence>
                <sequence key="AuditSeq"/>
            </sequence>
        </target>
    </clone>
</outSequence>

你的序列AuditSeq应该成为:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuditSeq">
    <property name="FORCE_ERROR_ON_SOAP_FAULT" value="true" scope="default" type="STRING"/>
    <property name="RESULT_CODE" expression="get-property('ResultCode')" scope="default" type="STRING"/>
    <property name="RESULT_MESSAGE" expression="get-property('ResultMessage')" scope="default" type="STRING"/>
    <property name="REFERENCE_ID" expression="get-property('ReferenceID')" scope="default" type="STRING"/>
    <property name="FAULT_DETAILS" expression="concat(get-property('ERROR_CODE'),get-property('ERROR_MESSAGE'))" scope="default" type="STRING"/>
    <payloadFactory media-type="xml">
        <format>
            <open:processRequest xmlns:open="http://www.openuri.org/">
                <aud:Auditor xmlns:aud="http://jhm.kkk.fff/Auditor">
                    <aud:Request>
                        <aud:Operation_Name>processRequest</aud:Operation_Name>
                        <aud:Auditor_InputData>
                            <aud:Result_Code>$1</aud:Result_Code>
                            <aud:Result_Message>$2</aud:Result_Message>
                            <aud:Reference_Id>$3</aud:Reference_Id>
                        </aud:Auditor_InputData>
                    </aud:Request>
                </aud:Auditor>
            </open:processRequest>
        </format>
        <args>
            <arg evaluator="xml" expression="get-property('RESULT_CODE')"/>
            <arg evaluator="xml" expression="get-property('RESULT_MESSAGE')"/>
            <arg evaluator="xml" expression="get-property('REFERENCE_ID')"/>
        </args>
    </payloadFactory>
    <header name="Action" scope="default" value="http://www.openuri.org/processRequest"/>
    <send receive="AuditServiceResponse">
        <endpoint>
            <address uri="http://localhost:8081/middleware/services/AuditService" format="soap11"/>
        </endpoint>
    </send>
</sequence>

这里有一个示例AuditServiceResponse序列:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuditServiceResponse">
   <log level="full"/>
   <drop/>
</sequence>