【问题标题】:How to Integrate RESTful service in the WSO2 ESB如何在 WSO2 ESB 中集成 RESTful 服务
【发布时间】:2017-06-11 15:08:32
【问题描述】:

我正在尝试通过 WSO2 ESB(RESTful API 服务集成)创建一个集成层。

端点 - http://www.thomas-bayer.com/

上下文 - /sqlrest

URI 模板 - /CUSTOMER/3

(API 端点 - www.thomas-bayer.com/sqlrest/CUSTOMER/3)

当我尝试使用 (http://localhost:8280:/sqlrest/CUSTOMER/3) 调用 api 请求时

我收到的响应是带有 404 错误代码的完整 HTML,而不是 XML 数据。

【问题讨论】:

  • 对不起,我对 URL 不是很好,但为什么是本地主机和?端口号?而不是端点?
  • @marshalcraft localhost 由您计算机中的 ESO2 ESB 部署。

标签: api wso2 integration wso2esb esb


【解决方案1】:

您提供的上下文不需要是来自实际端点 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

【讨论】:

    【解决方案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
    

    【讨论】:

    • 我自己想通了。但你是对的,这是正确的解决方案。谢谢...
    • 很高兴听到您可以自己找到解决方案。你能把我的答案标记为正确的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 2012-12-08
    相关资源
    最近更新 更多