1
votes

I am trying to make an API at WSO2 ESB 4.7.0 to process requests for a RESTful service. It seems that the URL-Mapping feature is not working or is working just like a filter, choosing what to send to the endpoint and what to drop. I have followed this tutorial: http://wso2.com/library/articles/2012/09/get-cup-coffee-wso2-way/. Here is my API configuration:

<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>

There are three situations:

  1. This URL works: http://esb/rest
  2. This URL doesn't work: http://esb/rest/numbers
  3. This URL works: http://myserver/REST/allnumbers

In situation 2, I got an Apache Tomcat error:

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

But if I try the endpoint address, it works. I thought that the URL-Mapping would route requests for "/numbers" to "/allnumbers". What am I doing wrong?

1

1 Answers

4
votes

Solved! I had to remove the REST_URL_POSTFIX before sending to the endpoint:

<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>

Now, http://esb/rest/numbers works too! :)