首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Datapower Gateway重写URL

使用Datapower Gateway重写URL
EN

Stack Overflow用户
提问于 2017-11-07 23:57:31
回答 1查看 1.6K关注 0票数 0

我正在尝试使用datapower设置URL重写。来自客户的请求将采用以下格式- /products/ {productid} /balance每个客户的{productid}都会更改,我需要将格式更改为/balance/products/{productid},这样我就不需要在Websphere中有多个上下文根。我已经设置了一个MPGW,但是我无法放入正确的变量来更改上面的请求,上面的请求应该是用Perl (我不知道)编写的,有人能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2017-11-08 18:58:13

如果我没弄错,你需要创建包含如下XSL转换的Request-Rule策略:

代码语言:javascript
复制
<?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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47162233

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档