如何使用名称/值对创建 HTTP POST 的 Mule ESB 服务?

发布于 2024-09-10 09:17:39 字数 1009 浏览 15 评论 0原文

我需要创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨落□心尘 2024-09-17 09:17:39

以下内容可能会有所帮助: http://comments.gmane.org/ gmane.comp.java.mule.user/29342

我也找不到任何示例,但它看起来像内置的 HTTP 转换器

http 响应对象转换器 A
转换 HTTP 的转换器
对 Mule 消息的响应。这
有效负载可以是字符串、流或
字节数组。

http 响应到字符串转换器
转换 HTTP 响应负载
成字符串。的标题
响应将被保留在
消息。

对象到http请求转换器
该变压器将创建一个有效的
使用当前消息的 HTTP 请求
以及设置的任何 HTTP 标头
当前消息。

消息到http响应转换器
该变压器将创建一个有效的
使用当前的 HTTP 响应
消息和设置的任何 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

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.

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.

橪书 2024-09-17 09:17:39

您是否询问如何获取 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.

极度宠爱 2024-09-17 09:17:39

1)设variables=

idEvent_Type1

&options=user: admin

是作为 HTTP 请求发布的地图主体。

2)对其进行 URL 编码(例如,使用 http://meyerweb.com/eric/tools/dencoder/< /a>)

产生:

variables%3D%3Cmap%3E%3Centry%3E%3Cstring%3EidEvent_Type%3C%2Fstring%3E%3Cstring%3E1%3C%2Fstring%3E%3C%2Fentry%3E%3C%2Fmap%3E%26options%3Duser%3Aadmin

3) 然后创建一个 Mule set-payload 转换器:

<set-payload value="variables%3D%3Cmap%3E%3Centry%3E%3Cstring%3EidEvent_Type%3C%2Fstring%3E%3Cstring%3E1%3C%2Fstring%3E%3C%2Fentry%3E%3C%2Fmap%3E%26options%3Duser%3Aadmin
" doc:name="Set playload"/>

4) 然后创建一个 Mule HTTP 端点:

<http:outbound-endpoint exchange-pattern="request-response" host="..." port="..." path="..." user="..." password="..." contentType="application/x-www-form-urlencoded" doc:name="POSTHTTPRequest"/>

并且它可以工作

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 :

variables%3D%3Cmap%3E%3Centry%3E%3Cstring%3EidEvent_Type%3C%2Fstring%3E%3Cstring%3E1%3C%2Fstring%3E%3C%2Fentry%3E%3C%2Fmap%3E%26options%3Duser%3Aadmin

3) then create a Mule set-payload transformer :

<set-payload value="variables%3D%3Cmap%3E%3Centry%3E%3Cstring%3EidEvent_Type%3C%2Fstring%3E%3Cstring%3E1%3C%2Fstring%3E%3C%2Fentry%3E%3C%2Fmap%3E%26options%3Duser%3Aadmin
" doc:name="Set playload"/>

4) then create a Mule HTTP endpoint :

<http:outbound-endpoint exchange-pattern="request-response" host="..." port="..." path="..." user="..." password="..." contentType="application/x-www-form-urlencoded" doc:name="POSTHTTPRequest"/>

and it works

守不住的情 2024-09-17 09:17:39

也许您可以尝试使用对象到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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文