2

我部署在 ESB 上的代理服务正在调用另一个独立的 REST 服务。此服务返回 HTTP 状态 200 以及响应正文中的一些数据。我的问题是如何从响应中检索 HTTP 状态。这是我的配置:

   <proxy name="CQProxy"
          transports="https http"
          startOnLoad="true"
          trace="disable">
      <description/>
      <target>
         <inSequence>
            <switch source="get-property('Action')">
               <case regex="getTaskTicket">
                  <sequence key="GetTaskTicket"/>
               </case>
               <default/>
            </switch>
         </inSequence>
         <outSequence>
            <log>
               <property xmlns:ns="http://org.apache.synapse/xsd"
                         name="Status"
                         expression="get-property('HTTP_SC')"/>
            </log>
            <send/>
         </outSequence>
         <faultSequence/>
      </target>
      <publishWSDL key="gov:/services/cqproxy/CQProxy.wsdl">
         <resource location="CQProxy.xsd" key="gov:/services/cqproxy/CQProxy.xsd"/>
      </publishWSDL>
   </proxy>
   <sequence name="GetTaskTicket">
...
      <property name="REST_URL_POSTFIX"
                value="/16783484?oslc.select=dcterms:title,oslc_cm:status"
                scope="axis2"
                type="STRING"/>
      <property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
      <send>
         <endpoint>
            <address uri="http://.../simpleQuery"
                     format="rest"/>
            <property name="OSLC-Core-Version" value="2.0" scope="transport"/>
            <property name="Accept" value="application/rdf+xml" scope="transport"/>
         </endpoint>
      </send>
   </sequence>
...

我尝试了以下代码:

<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('HTTP_SC')"/>
</log>

还有这个:

<log>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="get-property('axis2', 'HTTP_SC')"/>
</log>

但是它们都返回了null。

4

2 回答 2

6

在详细阅读了 WSO2 文档后,我找到了正确答案:

<property xmlns:ns="http://org.apache.synapse/xsd" name="Status" expression="$axis2:HTTP_SC"/>

奇怪的是,记录在案的 get-property('axis2', 'HTTP_SC') 不起作用。

于 2013-06-03T18:41:13.130 回答
0

发布对我有用的解决方案:

<property scope="default" type="STRING" name="HTTP_STATUS_CODE" expression="get-property('axis2', 'HTTP_SC')"/>
    <log level="custom">
        <property expression="get-property('HTTP_STATUS_CODE')" name="HTTP status code received: "/>
    </log>
于 2021-09-22T06:09:45.773 回答