如何使用名称/值对创建 HTTP POST 的 Mule ESB 服务?
我需要创建一个 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>
I need to create a mule service that will POST data to a web service that expects name/value pairs (not xml), then process the XML response from that service. I cannot find a good example on how to prep the payload for an http POST.
Can someone provide some insight or examples?
What I have so far is (I don't know if 'PathToTransformerClass' is needed):
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下内容可能会有所帮助: http://comments.gmane.org/ gmane.comp.java.mule.user/29342
我也找不到任何示例,但它看起来像内置的 HTTP 转换器 是
object-to-http-request-transformer 可能是你最好的选择;也许您可以创建一个键值对映射,然后将其转换为 URL 编码形式?不确定,但希望这能给你一些谷歌的东西。
The following might be helpful: http://comments.gmane.org/gmane.comp.java.mule.user/29342
I can't find any examples either, but it looks like the built-in HTTP transformers are
object-to-http-request-transformer might be your best bet; perhaps you can create a map of key-value pairs and then convert that into URL encoded form? Not sure but hopefully this gives you some things to Google.
您是否询问如何获取 XML 并创建键值对以通过 HTTP 发送?为此,您可以使用 XLST 转换器,在 XSL 中将方法输出设置为文本。
Are you asking about how to take XML and create key value pairs to send out via HTTP? For that you can use an XLST transformer where in the XSL you set the method output to be text.
1)设
variables=
&options=user: admin
是作为 HTTP 请求发布的地图主体。
2)对其进行 URL 编码(例如,使用 http://meyerweb.com/eric/tools/dencoder/< /a>)
产生:
3) 然后创建一个 Mule set-payload 转换器:
4) 然后创建一个 Mule HTTP 端点:
并且它可以工作
1) Let
variables=<map><entry><string>idEvent_Type</string><string>1</string></entry></map>&options=user:admin
be the Map body to post as HTTP request.
2) URL encode it (eg. using http://meyerweb.com/eric/tools/dencoder/)
which produce :
3) then create a Mule set-payload transformer :
4) then create a Mule HTTP endpoint :
and it works
也许您可以尝试使用对象到http请求转换器,因为该转换器将使用当前收到的消息和当前消息上设置的任何HTTP标头创建有效的HTTP请求。
从未尝试过,但这是阅读你的查询后我能想到的唯一变压器...希望它能工作..:D
Maybe U can give a try using Object-to-http-request-transformer as this transformer will create a valid HTTP request using the message currently received and any HTTP headers set on the current message.
Have never tried it, but that is the only transformer I can get in my mind after reading ur query...hope it works.. :D