1

I have exposed a REST service using <api> in wso2 esb. But the response does not come. REST service is written in Apache Wink.

API

<api name="API_2" context="/hello" hostname="localhost" port="8080">
  <resource url-mapping="/name" methods="GET">
    <inSequence>    
      <log level="full"/>
      <property name="messageType" value="text/plain" scope="transport" type="STRING"/>             
      <send>
        <endpoint>                              
          <address uri="http://localhost:8080/HelloService/rest/test/hello"/>
        </endpoint>
      </send>
    </inSequence>
    <outSequence>
      <log level="full"/>
      <send/>
    </outSequence>
  </resource>   
</api>

esb log

[2013-12-11 12:28:24,643]  INFO - API Initializing API: API_2
[2013-12-11 12:28:35,467]  INFO - LogMediator To: /hello/name, MessageID: urn:uuid:52d2ddf1-301e-42e0-ac9d-ac4a57ac8c72, Direction: request
Community
  • 1
  • 1
user3049576
  • 101
  • 1
  • 10

1 Answers1

1

I think your endpoint address is wrong , look like you have repeat hello twice. since you have hello in proxy name also which will append to URL.

try <address uri="http://localhost:8080/HelloService/rest/test"/>

Also You can verify your backend works by calling "uri + url-mapping" in separate browser

I have shown sample API works for me below, you should have called your API as below and log will print as below.

URL to call: http://localhost:8280/TestAPI/customerservice/customers/123

INFO - LogMediator To: /TestAPI/customerservice/customers/123

    <api xmlns="http://ws.apache.org/ns/synapse" name="TestAPI" context="/TestAPI">
   <resource methods="GET" url-mapping="/customerservice/customers/123">
      <inSequence>
         <log/>
         <send>
            <endpoint>
               <address uri="http://localhost:9764/jaxrs_basic/services/customers"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log/>
         <send/>
      </outSequence>
   </resource>
</api>
jayalalk
  • 2,382
  • 3
  • 17
  • 14
  • "http://localhost:8080/HelloService/rest/test/hello" is the actual RESTful web service implementation. When the request is sent to "http://localhost:8280/hello/name", doesn't it act as a proxy and forward the request to the actual implementation? – user3049576 Dec 11 '13 at 11:53
  • well, in your case proxy will forward your request to the address (http://localhost:8080/HelloService/rest/test/hello/ ) which is http://localhost:8080/HelloService/rest/test/hello/name , so see whether you get response in browser for this url. – jayalalk Dec 11 '13 at 12:28
  • Also if above backend URL works, please remove hostname and port from api definition, this is the issue here. use like my sample , let me know whether your problem solved by this. – jayalalk Dec 11 '13 at 12:36
  • it worked. thanks a lot!!!. Issue was with the endpoint url. But when I checked the logs, I saw that the REST message is wrapped in SOAP envelope. Is there a way to send the message as POX. I tried setting format="rest" by using an http endpoint. But didnt solve – user3049576 Dec 11 '13 at 13:39
  • Glad to here your issue is solved now, please note if you print logs inside ESB, it will print your POX inside soap body tag since ESB log mediator convert it into soap message before printing the log.However client will receive POX as it is sent by your back end,I have verified this, if you need further assistance better open new issue , so we an follow it separately. – jayalalk Dec 12 '13 at 07:59
  • the thing is I need to apply content based routing on POX messages. But the XPath expression fails since it is wrapped in a SOAP message – user3049576 Dec 12 '13 at 09:57
  • OK, have your own namespace for your body part and access with that, so xpath will find the patch exactly to your namespace independent of SOAP nodes. – jayalalk Dec 12 '13 at 12:16