Invoke node.js api from WSO2

1k views Asked by At

I am trying to invoke a node.js REST api (http://localhost:3000/users) from WSO2 Api Mgmt on-prem configuration but it doesn't work. The node.js REST api works fine from a browser/Postman. When called from WSO2, it returns empty response.

Endpoint exposed from WSO2 AM is http://localhost:801/api/v1/users and it is supposed to call the node.js REST api. I tried to use the debug features in WSO2 and found that the call never reaches the node.js endpoint due to some very long exception dump displayed in the console.

I am using Authorization header for the WSO2 front and it seems to work fine.

Though I have worked a bit in node.js, I am super-new to WSO2. So any help will be much appreciated.

Edit: I am using WSO2 AM 1.9.0 Response body from WSO2 API console given below -

<html>
<head>
    <title>Apache Tomcat/7.0.55 - Error report</title>
    <style>
        <!
        --H1
        {
            font-family: Tahoma,Arial,sans-serif;
            color: white;
            background-color: #525D76;
            font-size: 22px;
        }
        H2
        {
            font-family: Tahoma,Arial,sans-serif;
            color: white;
            background-color: #525D76;
            font-size: 16px;
        }
        H3
        {
            font-family: Tahoma,Arial,sans-serif;
            color: white;
            background-color: #525D76;
            font-size: 14px;
        }
        BODY
        {
            font-family: Tahoma,Arial,sans-serif;
            color: black;
            background-color: white;
        }
        B
        {
            font-family: Tahoma,Arial,sans-serif;
            color: white;
            background-color: #525D76;
        }
        P
        {
            font-family: Tahoma,Arial,sans-serif;
            background: white;
            color: black;
            font-size: 12px;
        }
        A
        {
            color: black;
        }
        A.name
        {
            color: black;
        }
        HR
        {
            color: #525D76;
        }
        -- ></style>
</head>
<body>
    <h1>
        HTTP Status 405 - HTTP method GET is not supported by this URL</h1>
    <hr size="1" noshade="noshade">
    <p>
        <b>type</b> Status report</p>
    <p>
        <b>message</b> <u>HTTP method GET is not supported by this URL</u></p>
    <p>
        <b>description</b> <u>The specified HTTP method is not allowed for the requested resource.</u></p>
    <hr size="1" noshade="noshade">
    <h3>
        Apache Tomcat/7.0.55</h3>
</body>
</html>

Edit : API Manager log

[2015-06-23 14:36:04,903]  INFO - HandlerUtils Massage Info: Transaction id=1499
743816386524554259  Message direction=IN  Server name=192.168.1.5:9763  Timestam
p=1435050364903  Service name=__SynapseService  Operation Name=mediate
[2015-06-23 14:36:04,906] DEBUG - HTTPEndpoint Sending message through endpoint
: admin--GetUsers_APIproductionEndpoint_0 resolving to address = http://127.0.0.
1:3000/users
[2015-06-23 14:36:04,909] DEBUG - HTTPEndpoint SOAPAction: null
[2015-06-23 14:36:04,910] DEBUG - HTTPEndpoint WSA-Action: null
[2015-06-23 14:36:04,926]  INFO - HandlerUtils Massage Info: Transaction id=1499
743816386524554259  Message direction=OUT  Server name=192.168.1.5:9763  Timesta
mp=1435050364926  Service name=__SynapseService  Operation Name=mediate

Edit : Remaining details from API log

Curl curl -X GET --header "Accept: application/json" --header "Authorization: Bearer 6a931d4fb2f6c85be750ee7cea8bc094" "https://localhost:9443/api/v1/users"

Request URL https://localhost:9443/api/v1/users

Response Code 405 Response Headers { "date": "Tue, 23 Jun 2015 09:05:49 GMT", "server": "WSO2 Carbon Server", "content-type": "text/html;charset=utf-8", "content-length": "1065", "content-language": "en" }

2

There are 2 answers

0
Fazlan Nazeem On

Your API creation has probably had some issues, and therefore it has not been mapped correctly to your nodeJS REST endpoint.

In the API creation wizard, you have the option to test whether the API-M can reach your endpoint. This step can verify that there is no issue in connecting.

I have written a blog post on step by step process for your use case. Please follow these steps, and hopefully, it should work.

Make sure the URL pattern field and production endpoint field have correct values.

0
John Desilva On

You have to check the GET checkbox value while giving the endpoint address.

Use this API sequence

<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
     name="nodejsAPI"
     context="/api">
   <resource methods="GET" protocol="http" uri-template="/v1/users">
      <inSequence>
         <log level="full"/>
         <send>
            <endpoint>
               <http method="GET"
                     uri-template="http://localhost:3000/users/"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
      <faultSequence/>
   </resource>
</api>