我有捲曲命令與後操作如下所示。這在curl命令中運行時工作正常。我將它轉換爲Mule代碼,如下所示,但有一些問題。Mule響應代碼415映射爲失敗休息後與文件
curl -X POST -H "Authorization: bearer 61e888d88-9iu-2b1cd13a3cee" -H "X-ANYPNT-ORG-ID: 34edrf6-77f7-40fd-6c06a7bcf909" -H "X-ANYPNT-ENV-ID: cdf63246-69ed-4fc6-bbd8-" -H "Content-Type:
multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" -H "Cache-Control: no-cache" -H -F "[email protected]:\myproject\zip\app-test.zip"
-F "targetId=12345" -F "artifactName=myapp11" "https://anypoint.mulesoft.com/hybrid/api/v1/applications"
騾代碼:
<set-payload value="[email protected]:\project\zip\app-test.zip&targetId=12345&artifactName=myapp11" doc:name="Set Payload"/>
<http:request config-ref="Hybrid" path="v1/applications" method="POST" doc:name="HTTP">
<http:request-builder>
<http:header headerName="Authorization" value="Bearer #[flowVars.accessToken]"/>
<http:header headerName="X-ANYPNT-ORG-ID" value="#[flowVars.orgId]"/>
<http:header headerName="X-ANYPNT-ENV-ID" value="#[flowVars.envId]"/>
<http:header headerName="Cache-Control" value="no-cache"/>
</http:request-builder>
</http:request>
錯誤消息:
ERROR 2017-02-13 12:54:45,605 [[deploy].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Response code 415 mapped as failure.
Payload : [email protected]
Element : /deployFlow/processors/18 @ deploy:deploy.xml:61 (HTTP)
Element XML : <http:request config-ref="Hybrid" path="v1/applications" method="POST" doc:name="HTTP">
<http:request-builder>
<http:header headerName="Authorization" value="Bearer #[flowVars.accessToken]"></http:header>
<http:header headerName="X-ANYPNT-ORG-ID" value="#[flowVars.orgId]"></http:header>
<http:header headerName="X-ANYPNT-ENV-ID" value="#[flowVars.envId]"></http:header>
<http:header headerName="Cache-Control" value="no-cache"></http:header>
</http:request-builder>
</http:request>
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.module.http.internal.request.ResponseValidatorException: Response code 415 mapped as failure.
at org.mule.module.http.internal.request.SuccessStatusCodeValidator.validate(SuccessStatusCodeValidator.java:37)
at org.mule.module.http.internal.request.DefaultHttpRequester.validateResponse(DefaultHttpRequester.java:356)
at org.mule.module.http.internal.request.DefaultHttpRequester.innerProcess(DefaultHttpRequester.java:344)
UPDATE:
<http:request-config name="Hybrid" protocol="HTTPS" host="anypoint.mulesoft.com" port="443" basePath="hybrid/api/v1/" doc:name="HTTPS req"/>
<message-properties-transformer overwrite="true" doc:name="Message Properties">
<add-message-property key="Content-Type" value="multipart/form-data;boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW;charset=UTF-8"/>
</message-properties-transformer>
<set-attachment attachmentName="targetId" value="#[flowVars.targetId]" contentType="text/plain" doc:name="targetid"/>
<set-attachment attachmentName="artifactName" value="myapp4" contentType="text/plain" doc:name="artifactName"/>
<set-attachment attachmentName="file" value="@C:\myproject\zip\app-test.zip" contentType="application/zip" doc:name="file"/>
<http:request config-ref="Hybrid" path="applications" method="POST" doc:name="HTTPS">
<http:request-builder>
<http:header headerName="Authorization" value="bearer #[flowVars.accessToken]"/>
<http:header headerName="X-ANYPNT-ORG-ID" value="#[flowVars.orgId]"/>
<http:header headerName="X-ANYPNT-ENV-ID" value="#[flowVars.envId]"/>
<http:header headerName="Cache-Control" value="no-cache"/>
</http:request-builder>
</http:request>
錯誤消息:響應代碼400映射爲失敗。
ERROR 2017-02-14 11:26:50,087 [[deploy].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Response code 400 mapped as failure.
Payload : [email protected]
Element : /deployFlow/processors/21 @ deploy:deploy.xml:71 (HTTPS)
Element XML : <http:request config-ref="Hybrid" path="applications" method="POST" doc:name="HTTPS">
<http:request-builder>
<http:header headerName="Authorization" value="bearer #[flowVars.accessToken]"></http:header>
<http:header headerName="X-ANYPNT-ORG-ID" value="#[flowVars.orgId]"></http:header>
<http:header headerName="X-ANYPNT-ENV-ID" value="#[flowVars.envId]"></http:header>
<http:header headerName="Cache-Control" value="no-cache"></http:header>
</http:request-builder>
</http:request>
--------------------------------------------------------------------------------
關鍵是如果你想訪問附件,你必須使用:#[message.inboundAttachments] –