我正在尝试通过WSO2 ESB(RESTful API服务集成)创建集成层。
端点 - http://www.thomas-bayer.com/
上下文 - / sqlrest
和
URI-template - / CUSTOMER / 3
(API端点 - www.thomas-bayer.com/sqlrest/CUSTOMER/3)
当我尝试使用(http://localhost:8280:/sqlrest/CUSTOMER/3)
调用api请求时我的响应是完整的HTML,包含404错误代码,而不是XML数据。
答案 0 :(得分:2)
您可以在WSO2 ESB中使用此API:
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
name="sqlrestAPI"
context="/sqlrest">
<resource methods="GET" protocol="http" uri-template="/CUSTOMER/{id}">
<inSequence>
<log level="full"/>
<send>
<endpoint>
<http method="GET"
uri-template="http://www.thomas-bayer.com/sqlrest/CUSTOMER/{uri.var.id}"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
并使用(在我的情况下OFFSET = 3)调用它:
curl -v http://localhost:8283/sqlrest/CUSTOMER/3
回应:
* 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 /sqlrest/CUSTOMER/3 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/xml
< Date: Thu, 26 Jan 2017 16:40:08 GMT
< Transfer-Encoding: chunked
<
<?xml version="1.0"?><CUSTOMER xmlns:xlink="http://www.w3.org/1999/xlink">
<ID>3</ID>
<FIRSTNAME>Michael</FIRSTNAME>
<LASTNAME>Clancy</LASTNAME>
<STREET>542 Upland Pl.</STREET>
<CITY>San Francisco</CITY>
</CUSTOMER>* Connection #0 to host localhost left intact
* Closing connection #0
答案 1 :(得分:0)
您提供的上下文不需要是实际端点URL中的任何内容。
例如,您可以将上下文定义为myapi
。那你有2个选择。
选项1:
将端点配置为http://www.thomas-bayer.com/
然后,您可以将您的API称为http://localhost:8280/myapi/sqlrest/CUSTOMER/3
选项2:
将端点配置为http://www.thomas-bayer.com/sqlrest/
然后,您可以将您的API称为http://localhost:8280/myapi/CUSTOMER/3