2
votes

I am trying to invoke a simple RESTFul API that POST username and password using WSO2 ESB, but i did not get response when trying to invoke it using postman:

the RESTFul API URL is: http://{REST service IP:port}/api/signup

the URL to call from ESB is http://{ESP IP:PORT}/api1/signup

the API Configuration i made in the WSO2 ESB is

<api xmlns="http://ws.apache.org/ns/synapse" name="API_TEST"   context="/api1">
  <resource methods="POST" url-mapping="/signup">
    <inSequence>
      <log/>
      <send>
        <endpoint>
          <address uri="http://< REST service IP:port>/api/signup"/>
        </endpoint>
      </send>
    </inSequence>
    <outSequence>
      <log/>
      <send/>
    </outSequence>
  </resource>
</api>

I posted a Simple JSON elements:

{
  "name":"adnan",
  "password":"adnan1"
} 

the WSO2 Console show the following message:

INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:8073ca47-1ea3-4232-bcb7-4f947bca6591, Direction: response, MESSAGE = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = Error while building message, Envelope:

3

3 Answers

1
votes

If you are sending json in post body you need to set Content-Type: application/json header from your client.

0
votes

adding previous answer -: for GET request this works fine.but POST request you need to specify Content-Type:application/json header for the rest client.

0
votes

I Solved it : I edit the URI-Mapping tp "/" and edit the LOG mediators..

<api xmlns="http://ws.apache.org/ns/synapse" name="API_TEST"context="/api1">
   <resource methods="POST" url-mapping="/">
  <inSequence>
     <send>
        <endpoint>
           <address uri="http://{ESB IP:PORT}/api/signup"/>
        </endpoint>
     </send>
  </inSequence>
  <outSequence>
         <send/>
       </outSequence>
   </resource>
  </api>