如何通过WSO2 ESB发出API请求

时间:2017-01-25 23:52:06

标签: javascript json api wso2 wso2esb

我已按照本教程中给出的步骤进行操作。

https://docs.wso2.com/display/ESB500/Sending+a+Simple+Message

一切正常但是当我尝试通过ESB(通过8280端口)调用api时,会显示错误代码202。即使我没有指定任何故障序列。

我已经正确地尝试了每一步,并确保api的终点正常工作。

1 个答案:

答案 0 :(得分:1)

我也做了这个例子......在这里你有我的配置: - 端点定义(右键单击示例 - > endpoint->创建新端点) -

<endpoint name="QueryDoctorEP" xmlns="http://ws.apache.org/ns/synapse">
    <http method="get" uri-template="http://wso2training-restsamples.wso2apps.com/healthcare/{uri.var.category}"/>
</endpoint>

- 我的api定义(右键点击示例 - &gt; API Rest-&gt;创建新的API Rest)

<?xml version="1.0" encoding="UTF-8"?>
<api context="/healthcare" name="HealthcareAPI" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" uri-template="/querydoctor/{category}">
        <inSequence>
            <log description="Request Log" level="custom">
                <property name="message" value="Welcome to HealthcareService"/>
            </log>
            <send>
                <endpoint key="QueryDoctorEP"/>
            </send>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
        <faultSequence/>
    </resource>
</api>

等到服务器部署配置... 请求:(我的偏移是3)

curl -v http://localhost:8283/healthcare/querydoctor/surgery

这里有卷曲响应

About to connect() to localhost port 8283 (#0)
*   Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 8283 (#0)
> GET /healthcare/querydoctor/surgery HTTP/1.1
> User-Agent: curl/7.25.0 (i386-pc-win32) libcurl/7.25.0 OpenSSL/0.9.8u zlib/1.2.6 libssh2/1.4.0
> Host: localhost:8283
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Thu, 26 Jan 2017 16:00:51 GMT
< Transfer-Encoding: chunked
<
[{"name":"thomas collins","hospital":"grand oak community hospital","category":"surgery","availability":"9.00 a.m - 11.00 a.m","fee":7000.0},{"name":"anne clement","hospital":"clemency
 medical center","category":"surgery","availability":"8.00 a.m - 10.00 a.m","fee":12000.0},{"name":"seth mears","hospital":"pine valley community hospital","category":"surgery","availa
bility":"3.00 p.m - 5.00 p.m","fee":8000.0}]* Connection #0 to host localhost left intact
* Closing connection #0