WSO2 ESB API配置将相同的发布请求发送到不同的Rest服务

时间:2015-04-21 05:56:14

标签: wso2esb

我需要向不同的REST服务发送一个post请求,下面是完整的要求。 我正在使用WSO2 ESB的REST API配置 首先,我需要向一个服务发布请求,并根据成功发布,然后需要将此相同的内容发布到另一个服务。但我需要从第一个服务获得响应并将其发送到fronend。但我不需要从第二次服务中获得响应。

请在下面找到API配置并帮助我。

<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
   <resource methods="POST DELETE PUT GET">
      <inSequence>
         <log level="custom">
            <property name="Message Flow" value="Roovershof Plant Search API - IN"></property>
            <property name="HTTP_METHOD IS###########" expression="$axis2:HTTP_METHOD"></property>
            <property name="ip address" expression="get-property('axis2','REMOTE_ADDR')"></property>
            <property name="Authorization" expression="get-property('transport','Authorization')"></property>
         </log>
         <property name="TIME_IN" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"></property>
         <send>
            <endpoint>
               <address uri="service1"></address>
            </endpoint>
         </send>
         <log level="custom">
            <property name="Request Method :" expression="get-property('axis2', 'HTTP_METHOD')"></property>
         </log>
         <filter source="get-property('axis2', 'HTTP_SC')" regex="201">
            <then>
            <clone continueParent="true">
   <target>
      <property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
               <property name="messageType" value="application/json" scope="axis2"></property>
               <property name="HTTP_METHOD" value="POST" scope="axis2"></property>
               <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"></property>
               <property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
               <send>
                  <endpoint>
                     <address uri="servicr2"></address>
                  </endpoint>
               </send>
   </target>
   <target sequence="magento" />
</clone> 

1 个答案:

答案 0 :(得分:0)

您的synapse配置与您的陈述不符。您必须使用enrich mediator保留原始邮件,然后使用call mediator进行第一次端点调用。

然后根据结果,您将响应发送回客户端并通过从保存中重新加载消息来执行发送调用。

<api xmlns="http://ws.apache.org/ns/synapse" name="TestApi" context="/TestContext">
   <resource methods="POST GET">
      <inSequence>
         <log level="custom">
            <property name="Message Flow" value="Roovershof Plant Search API - IN"></property>
            <property name="HTTP_METHOD IS###########" expression="$axis2:HTTP_METHOD"></property>
            <property name="ip address" expression="get-property('axis2','REMOTE_ADDR')"></property>
            <property name="Authorization" expression="get-property('transport','Authorization')"></property>
         </log>
         <property name="TIME_IN" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"></property>

         <enrich>
            <source type="body" clone="true"></source>
            <target type="property" property="INIT_MSG_PAYLOAD"></target>
         </enrich>
         <call>
            <endpoint>
               <address uri="service1"></address>
            </endpoint>
         </call>
         <filter source="get-property('axis2', 'HTTP_SC')" regex="201">
            <then>
               <clone continueParent="true">
                  <target>
                     <sequence>
                        <respond></respond>
                     </sequence>
                  </target>
                  <target>
                     <sequence>
                        <enrich>
                           <source type="property" clone="true" property="INIT_MSG_PAYLOAD"></source>
                           <target type="body"></target>
                        </enrich>
                        <property name="REST_URL_POSTFIX" scope="axis2" action="remove"></property>
                        <property name="messageType" value="application/json" scope="axis2"></property>
                        <property name="HTTP_METHOD" value="POST" scope="axis2"></property>
                        <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"></property>
                        <property name="OUT_ONLY" value="true" scope="default" type="STRING"></property>
                        <send>
                           <endpoint>
                              <address uri="servicr2"></address>
                           </endpoint>
                        </send>
                     </sequence>
                  </target>
               </clone>
            </then>
            <else>
               <respond/>
            </else>
         </filter>
      </inSequence>
   </resource>
</api>