- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
又是我。作为一项技术练习,我尝试使用 WSO2 ESB 来代理一些 Web 流量。具体来说,我尝试代理网络流量并即时更改返回的响应,如下所示:
有人会认为这是一个简单的正则表达式或 XSLT 操作,但事实证明这比我想象的要困难得多。目前,这是我正在使用的代理脚本...
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="PassProxy"
transports="https http"
startOnLoad="true"
trace="disable">
<description>Route content from a web server through the ESB service and alter it</description>
<target>
<endpoint>
<address uri="http://server.yoyodyne.com/"/>
</endpoint>
<inSequence/>
<outSequence>
<property name="TheContentIncludingTheSoapEnvelope" expression="."/>
<property xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://org.apache.synapse/xsd"
name="TheContentFromSoapBodyButNotReally"
expression="//soapenv:Envelope/soapenv:Body/*"/>
<property name="TheContent"
value="An initial value that should be replaced"
scope="default"
type="STRING"/>
<enrich>
<source type="body" clone="true"/>
<target type="property" property="TheContent"/>
</enrich>
<property name="ContentType" expression="$trp:Content-Type"/>
<property name="ContentLength" expression="$trp:Content-Length"/>
<log level="custom">
<property name="ContentType" expression="$trp:Content-Type"/>
<property name="ContentLength" expression="$trp:Content-Length"/>
<property name="MessageVar" value="TheContent"/>
<property name="TargetMessage" expression="get-property('TheContent')"/>
</log>
<script language="js">
//hack because xpath fn:replace does not work in property tags and fn:translate works on chars not whole strings
var contentType=mc.getProperty('ContentType');
var contentObject=mc.getProperty('TheContent'); //how to get the text of this? And do it in un-escaped format???
if(/text/i.test(contentType)) {
if(!contentObject) {
mc.setProperty('TheAlteredContent','Well that didn\'t work as expected');
} else {
if(typeof contentObject == 'object' || typeof contentObject == 'undefined') {
var returnMessage='';
for (var key in contentObject) {
returnMessage=returnMessage+'found key "'+key+'"\n';
} //end object key for
returnMessage='Can\'t work with this type of input - '+typeof contentObject+'n\Available keys to try:\n'+returnMessage;
contentObject=returnMessage;
} else {
contentObject=contentObject.replaceAll('sad', 'happy');
//more regex statements to go here
} //end typeof if
} //end property check if
} else {
//not text - do nothing
contentObject='binary content (I think). Found content type of "'+contentType+'"';
} //end content type check if
//send the content back
mc.setProperty('TheAlteredContent',contentObject);
</script>
<enrich>
<!-- need to figure out how to replace the content and not append to the end of it. Replace tag on target keeps getting removed for some reason -->
<source type="property" property="TheAlteredContent" clone="true"/>
<target type="body"/>
</enrich>
<!-- doctype headers in the HTML cause logging to fail, so no debugging for you -->
<!--<log level="full"/>-->
<send/>
</outSequence>
</target>
</proxy>
当然,使用丰富操作可能不是处理此问题的最佳方法,但在当时似乎是个好主意。最终发生的情况是,响应的 HTML 部分作为带有转义内容的对象传递到 JS 代码中(或者被传递出去???)。因为“contentObject”变量是一个对象,所以正则表达式失败。使用 toString() 强制“contentObject”为字符串也不起作用。即使它确实有效,HTML 内容仍然处于转义形式,并且转换回来可能会出现问题,因为 HTML 代码中可能存在需要保留 HTML 格式的转义条目。这里的最后一个问题是,“TheAlteredContent”属性的内容被附加到内容中,而不是替换它,即使属性“action=replace”被添加到最终的丰富操作中(ESB 实际上删除了它)。
有人知道更好的方法来做到这一点,或者可能是使上述代码工作的方法吗?
最佳答案
我相信,您正在从后端收到 HTML 响应。只需在输出路径中使用自定义类中介器并更改内容即可。我的意思是,在 mediate() 代码中执行 String.replace 。这比使用 JavaScript 在代理配置中制作整个复杂的编码逻辑相当简单。
这能解决您的问题吗?
关于javascript - 带响应处理的 WSO2 ESB (Apache Synapse) 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20553217/
当存储帐户访问 key 被禁用时,Dataverse 的突触链接运行正常。我们可以创建新记录,这里没有问题。但当存储帐户 key 被禁用时,它无法为 Dataverse 设置新的突触链接。有人以前见过
是否有计划支持专用池的开放行集?优点: 比外部文件格式更多(更快)的解析器选项,例如行分隔符 可以自动推断模式 直接定义文件格式更方便 最佳答案 这是一个很棒的功能请求,安德斯。我看到您已经创建了一个
我有一个天蓝色的突触工作区,其中包含无服务器 SQL 池中的许多管道和外部表。所有这些都与一个特定项目相关。 还有另外 2-3 个完全独立的项目正在进行中,需要突触工具集。 我应该创建一个新的工作区,
我有一个天蓝色的突触工作区,其中包含无服务器 SQL 池中的许多管道和外部表。所有这些都与一个特定项目相关。 还有另外 2-3 个完全独立的项目正在进行中,需要突触工具集。 我应该创建一个新的工作区,
能否请您帮助我在 Azure Synapse 中使用 FOR XML PATH。如果不是,还有什么选择。 谢谢 最佳答案 如果您希望使用 FOR XML 来准备,例如动态数据透视查询的列名,那么 st
编辑:这是一个连接到 git 存储库的工作区。如果我向处于“实时”模式的工作区添加触发器,触发器将显示。如何将触发器添加到设置到 git 存储库的工作区? 使用 Azure Synapse,我在创建和
我在 AzureSynapse 无服务器池中定义了一个 View ,它使用 openrowset 获取数据。我在专用 sql 池中的表中也有数据。 我可以做一个连接这两个表的 sql 查询吗? 最佳答
我在 Synapse 工作区中有一个主管道,其中有 2 个事件: 第一 - 笔记本事件 第二 - If 条件事件 对于第一个(Synapse 笔记本、spark 池、pyspark),我有一个如下所示
我在 Synapse 工作区中有一个主管道,其中有 2 个事件: 第一 - 笔记本事件 第二 - If 条件事件 对于第一个(Synapse 笔记本、spark 池、pyspark),我有一个如下所示
我们将从本地迁移到 Azure,并将使用 Azure Synapse。我们的转换主要是从 SQL 存储过程的直接迁移开始。 查看高级文档,我没有发现 ADF 和 Azure Synapse Pipel
最近,我们将专用 SQL 池部署到生产中的 Synapse 工作区。在开发中,我们可以访问无服务器 SQL 池和专用 SQL 池。但是,在生产中,我们可以访问无服务器 SQL 池,但无法访问专用 SQ
我正在尝试克隆 Synapse Serverless SQL 数据库,以便可以使用它进行测试。 当我在 Synapse Studio 中单击 SQL 数据库时,没有克隆选项。 No 'Clone' o
我正在尝试克隆 Synapse Serverless SQL 数据库,以便可以使用它进行测试。 当我在 Synapse Studio 中单击 SQL 数据库时,没有克隆选项。 No 'Clone' o
根据Doc。这是否意味着,目前数据库设计器不支持Delta格式来可视化地创建Lake数据库表?
以下 Azure 服务之间有什么区别? Azure Synapse Analytics(以前称为 SQL DW) Azure Synapse Analytics(专用链接中心预览版) Azure Sy
以下 Azure 服务之间有什么区别? Azure Synapse Analytics(以前称为 SQL DW) Azure Synapse Analytics(专用链接中心预览版) Azure Sy
我正在尝试使用 Synapse Pipelines 中的 Notebook Activity 执行 Azure Synapse Notebook,它在调试 Pipelines 时不断出现错误,Note
我有一个表,由于名称列中的差异,它为相同的ID返回多个行。有些名字在名字后面加上中间字母,或者在姓氏后面加上后缀。在下面的示例中,我只想要第一行,因为它有完整的名称。。我尝试按名称长度进行排名,但因未
我有一个表,由于名称列中的差异,它为相同的ID返回多个行。有些名字在名字后面加上中间字母,或者在姓氏后面加上后缀。在下面的示例中,我只想要第一行,因为它有完整的名称。。我尝试按名称长度进行排名,但因未
我们在目录和订阅(我们将其称为目录_1 和订阅_1)下有不同的资源(存储帐户、逻辑应用、SQL 数据库、SQL Server、Synapse 工作区) 这些资源用于执行简单的 ETL 管道。 我们希望
我是一名优秀的程序员,十分优秀!