1

RESTful サービスの要求を処理するために、WSO2 ESB 4.7.0 で API を作成しようとしています。URL マッピング機能が動作していないか、エンドポイントに送信するものとドロップするものを選択するフィルターのように動作しているようです。このチュートリアルに従いました: http://wso2.com/library/articles/2012/09/get-cup-coffee-wso2-way/。これが私のAPI構成です:

<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/rest">
   <resource methods="GET" url-mapping="/">
      <inSequence>
         <send>
            <endpoint>
               <http method="get" uri-template="http://myserver/REST"/>
            </endpoint>
         </send>
      </inSequence>
   </resource>
   <resource methods="GET" url-mapping="/numbers">
      <inSequence>
         <send>
            <endpoint>
               <http method="get" uri-template="http://myserver/REST/allnumbers"/>
            </endpoint>
         </send>
      </inSequence>
   </resource>
</api>

次の 3 つの状況があります。

  1. この URL は動作します:http://esb/rest
  2. この URL は機能しません:http://esb/rest/numbers
  3. この URL は動作します:http://myserver/REST/allnumbers

状況 2 では、Apache Tomcat エラーが発生しました。

HTTP Status 404 - Not Found

type Status report

message Not Found

description The requested resource (Not Found) is not available.
Apache Tomcat/6.0.32

しかし、エンドポイント アドレスを試してみると、うまくいきます。URL マッピングは「/numbers」のリクエストを「/allnumbers」にルーティングすると考えていました。私は何を間違っていますか?

4

1 に答える 1

4

解決しました!エンドポイントに送信する前に、REST_URL_POSTFIX を削除する必要がありました。

<api xmlns="http://ws.apache.org/ns/synapse" name="rest" context="/rest"> 
<resource methods="GET" url-mapping="/">
  <inSequence>
     <send>
        <endpoint>
           <http method="get" uri-template="http://myserver/REST"/>
        </endpoint>
     </send>
  </inSequence>
</resource>
<resource methods="GET" url-mapping="/numbers">
  <inSequence>
     <property name="REST_URL_POSTFIX" scope="axis2" action="remove"/>
     <send>
        <endpoint>
           <http method="get" uri-template="http://myserver/REST/allnumbers"/>
        </endpoint>
     </send>
  </inSequence>
</resource>
</api>

今、 http://esb/rest/numbersあまりにも動作します!:)

于 2013-11-07T19:31:00.980 に答える