问题
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}
.
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
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>
Is it possible to configure resourcePath that match the whole directory tree?
Instead of: /files/v1/api/{ver}/{auth}/{signIn}
I would like /files/v1/api/**
My problem is that I have approx. 6 top-level directories to serve files from and some of the directories are 15 levels deep.
回答1:
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>
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
instead of
/css/somedir/somefile.css
来源:https://stackoverflow.com/questions/46187504/wso2-how-to-create-custom-mediation-sequence-to-serve-static-content