Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mule ESB多部分/表单数据post不工作_Mule_Multipartform Data_Mule Esb - Fatal编程技术网

Mule ESB多部分/表单数据post不工作

Mule ESB多部分/表单数据post不工作,mule,multipartform-data,mule-esb,Mule,Multipartform Data,Mule Esb,我试图使用Mule ESB发布多部分/表单数据,但无法使其正常工作。我通过我的rest客户机和cURL成功地处理了相同的请求 curl -i -X POST \ -H "Authorization:bearer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -H "X-ANYPNT-ORG-ID:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -H "X-ANYPNT-ENV-ID:xxxxxxxx-xxxx-xxxx-xxxx-

我试图使用Mule ESB发布多部分/表单数据,但无法使其正常工作。我通过我的rest客户机和cURL成功地处理了相同的请求

curl -i -X POST \
-H "Authorization:bearer xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
-H "X-ANYPNT-ORG-ID:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
-H "X-ANYPNT-ENV-ID:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
-H "Content-Type:multipart/form-data" \
-F "artifactName=test" \
-F "targetId=xxxxxx" \
-F "file=@\"./test-1.0.0-SNAPSHOT.zip\";type=application/x-zip-compressed;filename=\"test-1.0.0-SNAPSHOT.zip\"" \ 'https://anypoint.mulesoft.com/hybrid/api/v1/applications'
我正在使用转换器添加出站附件

message.setPayload(NullPayload.getInstance());
message.addOutboundAttachment("artifactName", AttachmentHelper.getStringAttachment("artifactName", artifactName));
message.addOutboundAttachment("targetId", AttachmentHelper.getStringAttachment("targetId", targetId.toString()));
message.addOutboundAttachment("file", AttachmentHelper.getURLAttachment("file", file));

public class AttachmentHelper {
  public static DataHandler getStringAttachment(String name, String value) {
    logger.info("Adding string attachment " + name + ": " + value);
    byte[] bytes = value.getBytes();
    return new DataHandler(new ByteArrayDataSource(bytes, "text/plain", name));
  }

  public static DataHandler getURLAttachment(String name, String value) throws Exception {
    InputStream is = new URL(value).openStream();
    byte[] bytes = IOUtils.toByteArray(is);
    return new DataHandler(new ByteArrayDataSource(bytes, "application/x-zip-compressed", name));
  }
}
然后只是打服务电话

<http:request method="POST" path="/hybrid/api/v1/applications" config-ref="http_request_mule" doc:name="POST Deploy Application Call">
        <http:request-builder>
            <http:header headerName="Authorization" value="bearer #[sessionVars.token]" />
            <http:header headerName="X-ANYPNT-ORG-ID" value="#[sessionVars.orgId]" />
            <http:header headerName="X-ANYPNT-ENV-ID" value="#[sessionVars.envId]" />
            <http:header headerName="Content-Type" value="multipart/form-data" />
        </http:request-builder>
    </http:request>
似乎无法添加内容配置、附件名称和文件名


我几乎什么都试过了,几乎什么都读过,我不知所措。有什么想法吗?

解决了!我唯一需要做的改变就是添加文件名

message.addOutboundAttachment("file", AttachmentHelper.getURLAttachment(FilenameUtils.getName(file), file));

不要显式添加内容类型。多部分数据需要一个将在内部计算的边界元素,除非已经设置了内容类型。我想这就是问题所在。试着把它去掉。还有,这是哪一个骡子版本?不幸的是,这不起作用,我仍然得到一个400。我使用的是最新的3.8.2 EE。如果您注释掉HTTP传输,您可以在响应中看到发送的请求返回,它与上面的一样,缺少内容配置、附件名称和文件名,并且具有这些--null元素。我尝试将附件名称和数据处理程序名称添加为内容处置,但没有显示任何差异。
message.addOutboundAttachment("file", AttachmentHelper.getURLAttachment(FilenameUtils.getName(file), file));