WSO2 如何创建自定义中介序列以提供静态内容 [英] WSO2 How to create custom mediation sequence to serve static content

查看:32
本文介绍了WSO2 如何创建自定义中介序列以提供静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个直通"WSO2 API 来提供一些静态的内部服务器上的文件到外部.据我了解,WSO2 要求我在 /{context}/{version}/{resourcePath} 下配置多个 {resources}.

I'm trying to create an "pass-through" WSO2 API to serve some static files on an internal server to the outside. As I understand it, WSO2 requires me to configure multiple {resources} under /{context}/{version}/{resourcePath}.

假设我的上下文和版本是文件"和v1",我需要映射这些外部路径指向我的后端服务器上的这些内部路径.

Assuming my context and version are 'files' and 'v1' I need to map these external paths to these internal paths on my backend server.

  • /files/v1/js/api.js ->/js/api.js
  • /files/v1/css/file.css ->/css/file.css
  • /files/v1/api/2.0/auth/signin ->/api/2.0/auth/signin

基本上我需要做的就是去掉前面的上下文 &版本所以我在 InSequence 中尝试了这个自定义中介序列

Basically all I need to do is strip away the preceding context & version so I tried this custom mediation sequence in the InSequence

<sequence xmlns="http://ws.apache.org/ns/synapse" name="custom-seq">
  <log level="full">
    <property name="IN_MESSAGE" value="IN_MESSAGE"
  </log>
  <property name="resource_ep" 
            expression="get-property('axis2','REST_URL_POSTFIX')"/>
  <header name="To" expression="get-property('resource_ep')"/>
  <log level="custom">
    <property name="to" expression="get-property('To')"/>
  </log>
</sequence>

是否可以配置匹配整个目录树的resourcePath?

代替:/files/v1/api/{ver}/{auth}/{signIn}我想要 /files/v1/api/**

我的问题是我有大约.6 个用于提供文件的顶级目录,其中一些目录的深度为 15 级.

推荐答案

我能够用这个 In Flow Mediation 序列定义解决它.

I was able to solve it with this In Flow Mediation sequence definition.

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="custom-seq">
<property> name="resource_ep"
           expression="get-property('axis2', 'REST_URL_POSTFIX')"/>
 <switch source="get-property('axis2', 'REST_URL_POSTFIX')">
  <case > regex=".*/api.*">
    <log level="custom">
      <property name="My-Mediator" value="/api"/>
    </log>
    <header name="To" expression="get-property('resource_ep')"/>
  </case>
  <case regex=".*/js.*">
    <log level="custom">
      <property name="My-Mediator" value="/js"/>
    </log>
    <header name="To" expression="get-property('resource_ep')"/>
  </case>
  <default>
    <log level="custom">
      <property name="Tableau-Mediator" value="default (ignored)"/>
    </log>
  </default>
 </switch>
</sequence>

每个案例块都定义了一个我想通过它提供服务的顶级目录/files/v1/(如果我将 v1 设为默认版本,则仅/files/).

Each case block defines a top-level directory that I want to serve via /files/v1/ (or just /files/ if I make v1 the default version).

默认块应该忽略其他所有内容.

The default block should ignore everything else.

我仍然需要调整我的客户端应用程序以发送请求到

I still have to adapt my client app to send requests to

/files/v1/css/somedir/somefile.css

/files/v1/css/somedir/somefile.css

而不是

/css/somedir/somefile.css

/css/somedir/somefile.css

这篇关于WSO2 如何创建自定义中介序列以提供静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆