0
Mule ESBを使用してmultipart/form-dataをポストしようとしていますが、動作させることができません。私は、残りのクライアントとcURLを通じて同じリクエストが正常に機能しています。Mule ESBマルチパート/フォームデータのポストが動作しない
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 "[email protected]\"./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>
HTTPステータス400が戻ってきました.HTTPコールをコメントアウトすると、要求が正しく形成されません。
Unexpected character (-) at position 0.
--null
Content-Type: application/x-zip-compressed
C:\DEV\zips\test-1.0.0-SNAPSHOT.zip (byte content removed for post)
--null
Content-Type: text/plain
xxxxxx (value correct here just masked)
--null
Content-Type: text/plain
test
--null--
コンテンツの配置、添付ファイル名、ファイル名の追加に失敗したようです。
私はすべてを試してみましたが、すべてを読んでいて、紛失しています。何か案は?
コンテンツタイプを明示的に追加しないでください。マルチパートデータには、コンテンツタイプがすでに設定されていない限り、内部的に計算される境界要素が必要です。私はそれが問題だと思う。それを削除してみてください。 – afelisatti
また、どのミュールバージョンがこれですか? – afelisatti
残念ながら、それはうまくいきませんでした、私はまだ400を取得しています。私は最新の3.8.2 EEです。 –