这些是我使用Mule的第一步,因此我可能不了解一些基本概念。
有一家运行Prestashop的商店,该商店提供REST服务。
我现在要做的就是发送请求以存储,获取响应,替换一个值并将其保存到文件中。
响应如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<stock_available>
<id><![CDATA[1]]></id>
<id_product xlink:href="http://xxxxxxxxxxxxx/api/products/1"><![CDATA[1]]></id_product>
<id_product_attribute><![CDATA[0]]></id_product_attribute>
<id_shop xlink:href="http://xxxxxxxxxxxxx/api/shops/1"><![CDATA[1]]></id_shop>
<id_shop_group><![CDATA[0]]></id_shop_group>
<quantity><![CDATA[0]]></quantity>
<depends_on_stock><![CDATA[0]]></depends_on_stock>
<out_of_stock><![CDATA[2]]></out_of_stock>
</stock_available>
</prestashop>
我想替换值“ quantity”。现在-具有恒定值。我当前的流程是:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 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.6.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="xxxxxxxxxxxxxxxx" port="80" basePath="/api/" doc:name="HTTP Request Configuration">
<http:basic-authentication username="xxxxxxxxxxxxxxxxxxxxxxx" password="x"/>
<http:raml-api-configuration location="api.raml"/>
</http:request-config>
<flow name="1Flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/stock_availables/{id}" method="GET" doc:name="HTTP">
<http:request-builder>
<http:uri-param paramName="id" value="#[message.inboundProperties.'http.query.params'.id]"/>
</http:request-builder>
</http:request>
<byte-array-to-object-transformer doc:name="Byte Array to Object" mimeType="text/xml"/>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<file:outbound-endpoint path="C:\test" outputPattern="test.txt" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>
这已经连接到服务,获取响应并保存文件。但是我不知道如何修改它的内容。
我无法理解的问题之一是:当我查看调试器时,在“字节数组到对象”之后,有效负载的类型为java.lang.string。在“对象到XML”之后,有效负载仍然键入java.lang.string,并且有效负载的值为:
<string><?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<stock_available>..............blahblahblah.........</string>
当我尝试使用xslt转换时,会导致错误。
如何修改该值?
您在这里有几个选择。首先,您的http传输将返回一个字节数组,然后您可以使用字节数组到字符串转换器将其转换为字符串。之后,您可以调用自定义处理器并在Java代码中转换字符串有效负载,也可以尝试MEL(#[regex()])中的regex函数和字符串附加转换器的某种组合,以在mule xml中完全转换有效负载代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句