2013-11-04 74 views
1

我想在WSO2 ESB 4.7.0上创建一个API来处理RESTful服务的请求。看起来URL映射功能不起作用,或者像过滤器一样工作,选择发送到端点的内容以及要删除的内容。我遵循本教程:http://wso2.com/library/articles/2012/09/get-cup-coffee-wso2-way/。这里是我的API配置:WSO2 ESB 4.7.0 API url-mapping

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

有三种情况:

  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-Mapping会将“/ numbers”的请求路由到“/ allnumbers”。我究竟做错了什么?

回答

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的作品呢! :)