有没有办法在 ESB 或 API 管理器上打开全局负载压缩 (gzip)?

Is there a way to turn on global payload compression (gzip) on the ESB or API Manager?

有没有办法在 ESB(< 5.0.0)或 API 管理器(< 2.0.0)上打开负载压缩,特别是 application/json 内容类型?

我已经在资源级别上实现了这一点,但显然全局选项是理想的。

经过一些研究,我在 catalina-server.xml 中发现了以下可用选项:

压缩="on" & compressableMimeType.

这没有帮助,因为 tomcat 服务器是 web 界面,而不是服务,这就是 axis2 的用途。

经过更多挖掘,我发现了一篇存档文章 http://wso2.com/library/3316/。它里面引用了以下内容:

"MC_GZIP_RESPONSE (Server, Writable) : By default the HTTP response body is not compressed. Set this message context property to true to have the response body be GZIP compressed."

听起来这正是我需要的,但我不确定在哪里设置这个参数。

在 Api 管理器中您可以将此 属性 添加到 velocity_template.xml,因此默认情况下会将其添加到正在创建的所有 API。

谢谢"ycr"。你让我走上了正确的道路。

我为实现这一点所做的是为部署在 API Manager 中的 api 创建全局自定义 inSequence 和 outSequence(全局扩展),如 [=12= 中所述].

inSequence 检查请求的 Accept-Encoding header 的 value/existence,outSequence 相应地 gzip 响应。

步骤:

创建 "inSequence" 处理程序 xml 文件:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--Ext--In">
<property name="encoding" expression="$trp:Accept-Encoding"/>
<filter xpath="fn:contains(fn:lower-case(get-property('encoding')) , 'gzip')">
    <then>
        <property name="compression" value="true"/>
    </then>
    <else>
        <property name="compression" value="false"/>
    </else>
</filter>

文件名可以任意,但标签内的名称必须是WSO2AM--Ext--In

同样创建 "outSequence" 文件:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--Ext--Out">
<filter source="get-property('compression')" regex="true">
    <then>
        <property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
        <property name="Content-Encoding" scope="transport" type="STRING" value="gzip"/>
        <property name="Transfer-Encoding" scope="transport" type="STRING" value="gzip"/>
    </then>
    <else>
        <property name="TRANSPORT_HEADERS" action="remove" scope="axis2"/>
    </else>
</filter>

复制/repository/deployment/server/synapse-configs/default/sequences目录中的文件。他们将是 hot-deployed。

向任何已部署的 api 发送请求,其中 header Accept-Encoding 设置为 gzip(任何包含 gzip 的字符串都将被压缩)并且它应该响应 Content-Encoding: gzip