如何在代理wso2 esb中获取属性值并设置有效负载

时间:2013-04-10 05:16:37

标签: wso2 wso2esb

这是我的代理代码:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="ProviderPublication" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
  <inSequence>
     <filter xmlns:p="http://www.openoandm.org/xml/ISBM/" xpath="//p:OpenPublicationSession">
        <then>
           <property xmlns:xs="http://www.openoandm.org/xml/ISBM/" name="ChannelURI" expression="//xs:ChannelURI" scope="default" type="STRING"/>
           <class name="wso2.org.Communicator.OpenPublication">
              <property name="channelURI" value="myChannelURI"/>
           </class>
           **<property name="sessionIDFromClassMediator" expression="get-property('SessionID')" scope="default" type="STRING"/>**
           <header name="To" action="remove"/>
           <property name="RESPONSE" value="true" scope="default" type="STRING"/>
           <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
           <payloadFactory>
              <format>
                 <ns1:OpenPublicationSessionResponse xmlns:ns1="http://www.openoandm.org/xml/ISBM/">
                    <ns1:SessionID>$1</ns1:SessionID>
                 </ns1:OpenPublicationSessionResponse>
              </format>
              <args>
                 <arg expression="get-property('sessionIDFromClassMediator')"/>
              </args>
           </payloadFactory>
           <send/>
        </then>
        <else>
           <filter xpath="//p:PostPublication">
              <then>
                 <property xmlns:xs="http://www.openoandm.org/xml/ISBM/" name="SessionID" expression="//xs:SessionID" scope="default" type="STRING"/>
                 <property xmlns:xs="http://www.openoandm.org/xml/ISBM/" name="Topic" expression="//xs:Topic" scope="default" type="STRING"/>
                 <property xmlns:xs="http://www.openoandm.org/xml/ISBM/" name="Expiry" expression="//xs:Expiry" scope="default" type="STRING"/>
                 <property xmlns:ns="http://www.openoandm.org/xml/ISBM/" name="MessageContent" expression="//MessageContent" scope="default" type="STRING"/>
                 <class name="wso2.org.postPublication.PostPublication">
                    <property name="topic" value="Sports"/>
                    <property name="sessionID" value="session_001"/>
                    <property name="messagecontent" value="Cricket on air"/>
                    <property name="expiry" value="Monday"/>
                 </class>
                 <property name="getMessageIDFromClassMed" expression="get-property('MessageID')" scope="default" type="STRING"/>
                 <log level="full">
                    **<property name="SessionIDFromFstFltr" expression="get-property('sessionIDFromClassMediator')"/>**
                 </log>

我无法获得sessionIDFromClassMediator的属性值所以我的过滤器从未获得真实且无法进入过滤器

                 **<filter xpath="get-property('sessionIDFromClassMediator') = get-property('SessionID')">
                    <then>
                       <log level="custom">
                          <property name="STATE" value="message is sent to queue"/>
                       </log>
                       <property name="OUT_ONLY" value="true"/>
                       <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
                       <header name="To" action="remove"/>
                       <property name="RESPONSE" value="true" scope="default" type="STRING"/>
                       <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
                       <payloadFactory>
                          <format>
                             <ns1:PostPublicationResponse xmlns:ns1="http://www.openoandm.org/xml/ISBM/">
                                <ns1:MessageID>$1</ns1:MessageID>
                             </ns1:PostPublicationResponse>
                          </format>
                          <args>
                             <arg expression="get-property('getMessageIDFromClassMed')"/>
                          </args>
                       </payloadFactory>
                       <send/>
                    </then>
                    <else>
                       <log level="full">
                          <property name="FilterNotRunning" value="----------FilterNotRunning------------------"/>
                       </log>
                       <drop/>
                    </else>
                 </filter>**
              </then>
              <else>
                 <drop/>
              </else>
           </filter>
        </else>
     </filter>
  </inSequence>
  <endpoint>
     <address uri="jms:/myQueue?&transport.jms.DestinationType=queue"/>
  </endpoint>

所以我希望得到<property name="sessionIDFromClassMediator" expression="get-property('SessionID')" scope="default" type="STRING"/>的值,以便我可以在

后使用此属性值与其他属性匹配
<class name="wso2.org.postPublication.PostPublication">
                            <property name="topic" value="Sports"/>
                            <property name="sessionID" value="session_001"/>
                            <property name="messagecontent" value="Cricket on air"/>
                            <property name="expiry" value="Monday"/>
                         </class>

之后我发送消息到消息代理但在此之前我想关联应该发送到消息代理队列的有效负载。我想在

中实现有效载荷

我无法获得sessionIDFromClassMediator的属性值所以我的过滤器从未获得真实且无法进入过滤器

 **<filter xpath="get-property('sessionIDFromClassMediator') = get-property('SessionID')">
                        <then>
                           <log level="custom">
                              <property name="STATE" value="message is sent to queue"/>
                           </log>
                           <property name="OUT_ONLY" value="true"/>
                           <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
                           <header name="To" action="remove"/>
                           <property name="RESPONSE" value="true" scope="default" type="STRING"/>
                           <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
                           <payloadFactory>
                              <format>
                                 <ns1:PostPublicationResponse xmlns:ns1="http://www.openoandm.org/xml/ISBM/">
                                    <ns1:MessageID>$1</ns1:MessageID>
                                 </ns1:PostPublicationResponse>
                              </format>
                              <args>
                                 <arg expression="get-property('getMessageIDFromClassMed')"/>
                              </args>
                           </payloadFactory>
                           <send/>
                        </then>
                        <else>
                           <log level="full">
                              <property name="FilterNotRunning" value="----------FilterNotRunning------------------"/>
                           </log>
                           <drop/>
                        </else>
                     </filter>**
部分。主要问题是当我进行操作开放时,第一个过滤器被执行,当我进行第二次操作时,所有的属性值都会重置。那么我如何才能让物业价值持续下去,这样它永远不会丢失?希望您理解我的问题并期待您的解决方案。提前致谢

1 个答案:

答案 0 :(得分:2)

尝试添加属性的一些日志以查看它是否存在:

<log level="custom">
   <property name="your property" expression="get-property('sessionIDFromClassMediator'))"/>
</log>

请注意不同的levels of the properties (transport, axis2, axis2-client).

使用xpath属性filter mediator也遇到了一些问题。我不再使用它了,总是使用“source”和“regex”的组合。

示例:

<filter source="$body/anElementInTheBody" regex="true">

因此,对于您的情况,您可以创建一个附加属性(就在过滤器之前),如果它应该被过滤,它将包含布尔值。然后使用regex = true,您将进入过滤器。

这只是你的例子的伪代码 - 可能需要一些更正:

<property name="filterCondition" expression="get-property('sessionIDFromClassMediator') = get-property('SessionID')"/>
<filter source="get-property('filterCondition')" regex="true">