我正在尝试使用datapower设置URL重写。来自客户的请求将采用以下格式- /products/ {productid} /balance每个客户的{productid}都会更改,我需要将格式更改为/balance/products/{productid},这样我就不需要在Websphere中有多个上下文根。我已经设置了一个MPGW,但是我无法放入正确的变量来更改上面的请求,上面的请求应该是用Perl (我不知道)编写的,有人能帮我吗?
发布于 2017-11-08 18:58:13
如果我没弄错,你需要创建包含如下XSL转换的Request-Rule策略:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
extension-element-prefixes="dp"
exclude-result-prefixes="dp" >
<xsl:template match="/">
<xsl:variable name="originalUrl" select="dp:variable('var://service/URI')"/>
<xsl:variable name="productId" select="substring-before(substring-after($originalUrl, '/products/'), '/balance')"/>
<xsl:variable name="modifiedUrl" select="concat('/balance/products/', $productId)"/>
<!--Set your own destination host ofc-->
<dp:set-variable name="'var://service/routing-url'" value="concat('http://127.0.0.1', $modifiedUrl)"/>
</xsl:template>
</xsl:stylesheet>var:// service /URI是一个只读服务变量,它包含来自HTTP请求的URL-path var:// service / routing url是一个可写服务变量,它包含一个用于路由的URI
https://stackoverflow.com/questions/47162233
复制相似问题