问题: 我正在尝试将 uuid 作为新元素添加到传入的 xml 消息中。我可以看到在我记录结果时添加了它,但是 mule 将它的命名空间和 java util uuid 命名空间添加到结果中,这导致我路由此消息的另一个服务,不识别它,因为它有一个它没有的命名空间知道关于。
有没有办法配置 xslt 转换器来实现我在这里尝试做的事情?还有其他可以替代的建议吗?
目标是让 xslt 生成一个 uuid 并标记传入消息并将其传递给服务端点。感谢这方面的所有帮助。
骡配置:
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:billing="http://mycompany.com/billing"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<mulexml:xslt-transformer name="xslt"
doc:name="XSLT">
<mulexml:xslt-text>
<xsl:stylesheet version="2.0" xmlns:uuid="java:java.util.UUID">
<xsl:variable name="uid" select="uuid:randomUUID()" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="Request">
<Request>
<xsl:apply-templates select="node()|@*" />
<RequestId>
<xsl:value-of select="$uid" />
</RequestId>
</Request>
</xsl:template>
</xsl:stylesheet>
</mulexml:xslt-text>
</mulexml:xslt-transformer>
<flow name="rsi_invoiceFlow1" doc:name="rsi_invoiceFlow1">
<http:inbound-endpoint exchange-pattern="request-response"
address="${listener.hostname}:${listener.port}/${listener.path.invoice.rsi}"
doc:name="HTTP" transformer-refs="xslt" />
<logger message="#[message.payloadAs(java.lang.String)]" level="ERROR"
doc:name="Logger" />
<http:outbound-endpoint exchange-pattern="request-response"
method="POST" address="${destination.dev2.url}/" doc:name="HTTP"
doc:description="The '/' at the end of the URL is required on the RSI outbound call" />
</flow>
</mule>
传入的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<billing:RQ xmlns:billing="http://mycompany.com/billing">
<Request>
<CallingHostOrWeblogicInstance>SOAPUI</CallingHostOrWeblogicInstance>
</Request>
输出:
<?xml version="1.0" encoding="UTF-8"?>
<billing:RQ xmlns:billing="http://mycompany.com/billing">
<Request xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:uuid="java:java.util.UUID"><CallingHostOrWeblogicInstance xmlns="">SOAPUI</CallingHostOrWeblogicInstance>
<RequestId>bff3e1d6-ecdd-41ae-8807-ec04085a2b54</RequestId>
</Request>