通过 HTTP 入站端点公开现有 API

Expose an existing API through HTTP Inbound Endpoint

我有一个 API 部署在 wso2 ESB500 上。以此为例

<api xmlns="http://ws.apache.org/ns/synapse" name="patient" context="/patient">
   <resource methods="GET" uri-template="/{patientID}">
      <inSequence>
         <payloadFactory media-type="text">
            <format>I am patient </format>
            <args>
               <arg evaluator="xml" expression="get-property('uri.var.patientID')"/>
            </args>
         </payloadFactory>
         <respond/>
      </inSequence>
   </resource>
</api>

我有要求以三种不同的方式公开它。一种是纯 HTTP,一种是 HTTPS,两种是 HTTPS。因此 API 有 3 种消费者,非安全消费者、安全消费者和“双重”安全消费者。

多 HTTPS 不是一个选项,因为我们无法使用不同的监听接口启动 ESB。所以我决定通过三个不同的 HTTP 入站端点

公开原始 API

这个在常规 HTTP

中公开 API
<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"
                 name="http"
                 protocol="http"
                 suspend="false">
   <parameters>
      <parameter name="inbound.http.port">40000</parameter>
      <parameter name="dispatch.filter.pattern">/patient/.*</parameter>
   </parameters>
</inboundEndpoint>

另一个以 HTTPS

的一种方式公开 API
<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"
                 name="oneWayHttps"
                 protocol="https"
                 suspend="false">
   <parameters>
      <parameter name="inbound.http.port">40001</parameter>
      <parameter name="keystore">
         <KeyStore xmlns="">
            <Location>repository/resources/security/wso2carbon0.jks</Location>
            <Type>JKS</Type>
            <Password>wso2carbon</Password>
            <KeyPassword>wso2carbon</KeyPassword>
         </KeyStore>
      </parameter>
      <parameter name="dispatch.filter.pattern">/patient/.*</parameter>
   </parameters>
</inboundEndpoint>

最后是双向 HTTPS

<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"
                 name="twoWayHttps"
                 protocol="https"
                 suspend="false">
   <parameters>
      <parameter name="inbound.http.port">40002</parameter>
      <parameter name="keystore">
         <KeyStore xmlns="">
            <Location>repository/resources/security/wso2carbon1.jks</Location>
            <Type>JKS</Type>
            <Password>wso2carbon</Password>
            <KeyPassword>wso2carbon</KeyPassword>
         </KeyStore>
      </parameter>
      <parameter name="truststore">
         <TrustStore xmlns="">
            <Location>repository/resources/security/client-truststore.jks</Location>
            <Type>JKS</Type>
            <Password>wso2carbon</Password>
         </TrustStore>
      </parameter>
      <parameter name="SSLVerifyClient">require</parameter>
      <parameter name="dispatch.filter.pattern">/patient/[0-9]+</parameter>
   </parameters>
</inboundEndpoint>

一切都很完美。我给每个客户一个不同的端口,他们很高兴。但我注意到原来的 API 仍然通过 axis2.xml 文件中配置的 transportReceiver 公开。所以我希望它被隐藏起来,没有人应该直接调用它,而是通过 Inbounds。我知道您可以使用防火墙或负载平衡器来实现这一点。但是我想知道是否有办法使用 ESB 解决方案来实现它。

我想过在入站端点内插入一个 属性 并检查它在 API 本身中是否存在。但这对我不起作用,因为入站端点的序列似乎仅在没有 dispatch.filter.pattern.

时执行

来自docs

The regular expression that defines the proxy services and API's to expose via the inbound endpoint. Provide the .* expression to expose all proxy services and API's or provide an expression similar to ^(/foo|/bar|/services/MyProxy)$ to define a set of services to expose via the inbound endpoint. If you do not provide an expression only the defined sequence of the inbound endpoint will be accessible.

所以在这里我问了很多问题。但我认为最重要的是每当我已经部署了一个 API en ESB 时,我如何才能在 http、https 单向和双向公开它?我怎样才能隐藏原来的 API?

EDIT,inbound.only 参数似乎正是我要找的。不幸的是,它仅适用于代理服务,不适用于 API。此外,根据文档,它只能用于 HTTP Inbound,不能用于 HTTPS。

您不仅可以公开 API,还可以通过入站端点公开代理服务。这里对于代理服务,有一个参数inbound.only,它只允许入站端点调用代理服务。此参数似乎仅适用于代理服务 [1]。参考以下示例配置

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="patient"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
   <target>
      <inSequence>
         <log level="custom">
            <property name="--Proxy--" value="invoked"/>
         </log>
         <respond/>
      </inSequence>
   </target>
   <parameter name="inbound.only">true</parameter>
   <description/>
</proxy>

[1]- https://docs.wso2.com/display/EI660/HTTP+Inbound+Protocol