ule子http:outbound-endpoint + multipart/form-data [英] Mule http:outbound-endpoint + multipart/form-data

查看:135
本文介绍了ule子http:outbound-endpoint + multipart/form-data的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调用一个预期会收到multipart/form-data的rest服务,与此同时我遇到了一些问题.

I'm trying to call a rest service that expects to receive a multipart/form-data and I am facing some issues with this.

经过一段时间的搜索,我了解到必须将有效负载移动到出站附件,并将有效负载设置为null.

After a while searching, I've understood that I had to move the payload to an outbound attachment and set the payload to null.

  <expression-component><![CDATA[
        ds = new org.mule.message.ds.StringDataSource(formdata,'payload','multipart/form-data');
        dh = new javax.activation.DataHandler(ds);
        message.outboundAttachments['payload'] = dh;
    ]]></expression-component>          

    <set-payload value="#[null]" />

我也这样做了,但是出现了错误:

I've also done that, but got the error:

我收到一个内容类型错误: 消息:当期望"multipart/form-data"时,消息包含MIME类型"text/xml".

I received a content-type error: Message : Message contained MIME type "text/xml" when "multipart/form-data" was expected.

不好.:我必须使用expression-component,因为如果我仅使用set-attachment,则会收到名称一定不能为null"错误.

Obs.: I had to to use expression-component, because if I just use set-attachment I receive a " name must not be null" error.

由于这里的问题是内容的类型,所以我也尝试了转换消息属性.

Since the issue here was the type of the content, I also tried transforming the message properties.

    <message-properties-transformer overwrite="true" doc:name="Message Properties">
        <add-message-property key="Content-Type" value="multipart/form-data;charset=utf-8"/>
    </message-properties-transformer>           

此后,我从其余服务处收到400错误.

After that, I received a 400 error from the rest service.

我还尝试将多部分中的每个属性(键值)放在单独的附件中作为内容类型:文本/纯文本,此处存在相同问题.

I've also tried to put each atribute (key-value) from the multipart in separated attachments as content type: text/plain, same issue here.

我想我的问题是如何正确附加内容,以便成功地将内容类型转换为multipart/form-data.

I guess my problem is how to attach correctly, so that the content type is transformed to multipart/form-data with success.

感谢您的帮助.谢谢.

http出站呼叫代码:

http outbound call code:

    <enricher source="#[message.inboundProperties['http.status']]"  target="#[variable:out]" doc:name="Message Enricher">
        <http:outbound-endpoint exchange-pattern="request-response" method="POST"  host="${jbpm.host}" port="${jbpm.port}" path="#[address]" doc:name="HTTP" mimeType="multipart/form-data">
            <response>
              <object-to-string-transformer />
            </response>
        </http:outbound-endpoint>
    </enricher>
    <logger message="RESPONSE STATUS - #[variable:out]" level="INFO" doc:name="Logger"/>
    <set-payload value="needAXml" doc:name="Set Payload"/>
    <mulexml:object-to-xml-transformer doc:name="Object to XML"/>

    <mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" doc:name="XSLT">
        <mulexml:xslt-text>
            <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                          xmlns:bpmsws="http://www.arizona.com.br/esb/bpmsws/service/v1_0_0/"
                                                          xmlns:bpms="http://www.arizona.com.br/bpms/core/v1_0_0/">
                <xsl:param name="responseStatus"/>

                <xsl:template match="/">
                    <bpmsws:httpPostResponse>
                        <status xmlns=""><xsl:value-of select="$responseStatus" /></status>
                    </bpmsws:httpPostResponse>
                </xsl:template>
            </xsl:stylesheet>
        </mulexml:xslt-text>
        <mulexml:context-property key="responseStatus" value="#[variable:out]"/>

    </mulexml:xslt-transformer>

推荐答案

下面显示了如何发布具有两个字段值的多部分实体:

The following shows how to POST a multipart entity with two field values:

<expression-component><![CDATA[
    ds = new org.mule.message.ds.StringDataSource('key1','value1','text/plain');
    dh = new javax.activation.DataHandler(ds);
    message.outboundAttachments['key1'] = dh;

    ds = new org.mule.message.ds.StringDataSource('key2','value2','text/plain');
    dh = new javax.activation.DataHandler(ds);
    message.outboundAttachments['key2'] = dh;
]]></expression-component>

<set-payload value="#[null]" />

<http:outbound-endpoint exchange-pattern="request-response"
    method="POST" address="http://localhost:8082/path" />

请注意不要为contentType指定一个值,否则Mule将无法在POST中提供多部分边界.

Be careful to not specify a value for contentType otherwise Mule will not be able to provide the multi-part boundary in the POST.

如果出站范围内恰好具有Content-Type消息属性,请使用以下方法将其删除:

If you happen to have a Content-Type message property in the outbound scope, remove it with:

<remove-property propertyName="Content-Type" />

在HTTP出站终结点之前.

before the HTTP outbound endpoint.

这篇关于ule子http:outbound-endpoint + multipart/form-data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆