我需要创建一个 mule 服务,它将数据 POST 到需要名称/值对(而不是 xml)的 Web 服务,然后处理来自该服务的 XML 响应。我找不到关于如何为 http POST 准备有效负载的好示例。
有人可以提供一些见解或示例吗?
到目前为止我所拥有的是(我不知道是否需要“PathToTransformerClass”):
<service name="myService">
<inbound>
<vm:inbound-endpoint path="myService.request" synchronous="true">
<custom-transformer class="PathToTransformerClass" />
</vm:inbound-endpoint>
</inbound>
<outbound>
<pass-through-router>
<http:outbound-endpoint address="URIofWebServiceToPostTo" method="POST" synchronous="true">
<response-transformers>
<custom-transformer class="PathToClassToProcessTheResponse" />
</response-transformers>
</http:outbound-endpoint>
</pass-through-router>
</outbound>
</service>
最佳答案
以下内容可能会有所帮助:http://comments.gmane.org/gmane.comp.java.mule.user/29342
我也找不到任何示例,但看起来像是内置的 HTTP transformers是
http-response-to-object-transformer A transformer that converts an HTTP response to a Mule Message. The payload may be a String, stream, or byte array.
http-response-to-string-transformer Converts an HTTP response payload into a string. The headers of the response will be preserved on the message.
object-to-http-request-transformer This transformer will create a valid HTTP request using the current message and any HTTP headers set on the current message.
message-to-http-response-transformer This transformer will create a valid HTTP response using the current message and any HTTP headers set on the current message.
对象到http-request-transformer可能是你最好的选择;也许您可以创建一个键值对映射,然后将其转换为 URL 编码形式?不确定,但希望这能为您提供一些有关 Google 的信息。
关于web-services - 如何使用名称/值对创建 HTTP POST 的 Mule ESB 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3295188/