2016-11-22 4 views
0

を使用するときにIは、例えば、顧客の注文 1を介してステップAngularjsに書き込まれたUI画面のセットを有するMulleに毎回受信 2. 3.作成製品を得る顧客を取得していませんHTTP POSTリクエストメッセージは、CORS

UIとMuleはクロスソースリソース共有(CORS)用に設定されており、HTTP GET呼び出しは正しく機能しますが、HTTP POSTリクエストはChrome DevToolsネットワークコンソールにエラーとして表示され、キャンセルされました。

私はMuleをデバッグモードで実行すると、UIから毎回HTTP POST要求が受信されず、POSTリクエストが3つの顧客注文ステップを2回実行して、トリガされると正常に完了します。 POST呼び出しはChrome DevToolsでキャンセルされたと表示されますが、毎回。

誰もがこの動作の原因となっている可能性があること、および毎回MuleのワークフローをトリガするPOSTメッセージを取得する方法を知っていますか?

CORSプロシージャの一部として送信されるOPTIONSメッセージが、Muleコード内の何かのためにPOSTを起動していないか、OPTIONS応答がキャッシュされているため、 POST要求をすぐに送信するか、または何か他のものがあるかどうかを送信します。

XMLフロー:時々要求はラバによって受信され、正しく処理されていてもキャンセルとして

<?xml version="1.0" encoding="UTF-8"?> 
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:cors="http://www.mulesoft.org/schema/mule/cors" xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/cors http://www.mulesoft.org/schema/mule/cors/current/mule-cors.xsd 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> 
    <apikit:config name="test-order-config" raml="test-order.raml" consoleEnabled="true" consolePath="console" doc:name="Router"> 
     <apikit:flow-mapping resource="/orders/order" action="post" content-type="application/json" flow-ref="post:/orders/order:test-order-config"/>  
    </apikit:config> 

    <cors:config name="Cors_Configuration" doc:name="Cors Configuration"> 
     <cors:origins> 
      <cors:origin url="*"> 
       <cors:methods> 
        <cors:method>POST</cors:method> 
        <cors:method>DELETE</cors:method> 
        <cors:method>PUT</cors:method> 
        <cors:method>GET</cors:method> 
        <cors:method>OPTIONS</cors:method> 
       </cors:methods> 
       <cors:headers> 
        <cors:header>Content-Type</cors:header> 
       </cors:headers> 
      </cors:origin> 
     </cors:origins> 
    </cors:config> 

    <flow name="test-order-main"> 
     <http:listener config-ref="HTTP_Experience_Listener_Configuration" path="/*" doc:name="HTTP"/> 
     <cors:validate config-ref="Cors_Configuration" publicResource="true" acceptsCredentials="false" doc:name="CORS Validate"/> 
     <apikit:router config-ref="test-order-config" doc:name="APIkit Router"/>    
     <exception-strategy ref="test-order-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/> 
    </flow> 

    <flow name="set-access-control-allow"> 
     <set-property propertyName="Access-Control-Allow-Origin" value="*" doc:name="Set Access Control Allow Origin"/> 
     <set-property propertyName="Access-Control-Allow-Credentials" value="false" doc:name="Set Access Control Allow Credentials"/> 
     <set-property propertyName="Access-Control-Allow-Methods" value="GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS" doc:name="Set Access Control Allow Methods"/> 
     <set-property propertyName="Access-Control-Allow-Headers" value="DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,origin,authorization,accept,client-security-token" doc:name="Set Access Control Allow Headers"/> 
    </flow> 

    <flow name="get:/products:test-order-config"> 
     <set-payload value="#['{ &quot;getProducts&quot;: { &quot;productsList&quot;: [{ &quot;productId&quot;: &quot;001&quot;, &quot;name&quot;: &quot;test_product1&quot;}]}}']" doc:name="Set Payload"/> 
     <flow-ref name="set-access-control-allow" doc:name="set-access-control-allow"/> 
     <logger message="#[payload]" level="INFO" doc:name="Logger"/> 
    </flow> 

    <flow name="get:/customer/{customerId}:test-order-config"> 
     <set-payload value="#['{&quot;getCustomer&quot;:{&quot;customerId&quot;:&quot;1234567890&quot;,&quot;title&quot;:&quot;MR&quot;,&quot;Name&quot;:&quot;John&quot;}}']" doc:name="Set Payload"/> 
     <flow-ref name="set-access-control-allow" doc:name="set-access-control-allow"/> 
     <logger message="#[payload]" level="INFO" doc:name="Logger"/> 
    </flow> 

    <flow name="post:/orders/order:test-order-config"> 
     <set-payload value="#['{&quot;createOrder&quot;:{&quot;orderId&quot;:&quot;8a493ecd-e842-4ca2-b33b-a03aa9136673&quot;,&quot;success&quot;:true}}']" doc:name="Set Payload"/> 
     <flow-ref name="set-access-control-allow" doc:name="set-access-control-allow"/> 
     <logger message="#[payload]" level="INFO" doc:name="Logger"/> 
    </flow> 

    <apikit:mapping-exception-strategy name="test-order-apiKitGlobalExceptionMapping"> 
     <apikit:mapping statusCode="404"> 
      <apikit:exception value="org.mule.module.apikit.exception.NotFoundException"/> 
      <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> 
      <set-payload value="{ &quot;message&quot;: &quot;Resource not found&quot; }" doc:name="Set Payload"/> 
     </apikit:mapping> 
     <apikit:mapping statusCode="405"> 
      <apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException"/> 
      <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> 
      <set-payload value="{ &quot;message&quot;: &quot;Method not allowed&quot; }" doc:name="Set Payload"/> 
     </apikit:mapping> 
     <apikit:mapping statusCode="415"> 
      <apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException"/> 
      <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> 
      <set-payload value="{ &quot;message&quot;: &quot;Unsupported media type&quot; }" doc:name="Set Payload"/> 
     </apikit:mapping> 
     <apikit:mapping statusCode="406"> 
      <apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException"/> 
      <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> 
      <set-payload value="{ &quot;message&quot;: &quot;Not acceptable&quot; }" doc:name="Set Payload"/> 
     </apikit:mapping> 
     <apikit:mapping statusCode="400"> 
      <apikit:exception value="org.mule.module.apikit.exception.BadRequestException"/> 
      <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> 
      <set-payload value="{ &quot;message&quot;: &quot;Bad request&quot; }" doc:name="Set Payload"/> 
     </apikit:mapping> 
    </apikit:mapping-exception-strategy> 

</mule> 

はクロームデベロッパーツールはそれを呼び出すPOSTで暫定としてリクエストヘッダを示しが表示されます。 angularjsコードで

enter image description here

enter image description here

enter image description here

enter image description here

HTTPのPOST呼び出し:

postContent: function (link, data) { 
      $http({ 
       method: 'POST', 
       url: link, 
       headers: {'Content-Type':'application/json'}, 
       data: angular.toJson(data) 
      }).success(function (responseData) { 
       //do stuff with response 
       var returnData = responseData; 
      }).error(function (e) { 
       //do stuff with response 
       var error = e; 
      }); 
     } 
+0

コンソールで、OPTIONS要求への応答を取得した後、ブラウザがPOST要求をキャンセルした理由を示すエラーメッセージが表示されます。 – Quentin

+0

こんにちは - コンソールからスクリーンショットを追加しましたが、エラーは表示されません。私は見なければならないどこにもありますか? – user3165854

答えて

0

ちょうどを追加しますが許可要求に:

<cors:methods> 
    <cors:method>OPTIONS</cors:method> 
</cors:methods> 

EDIT OPはまた彼の$http呼び出しからContent-typeヘッダを削除しなければならなかった、これは、すべてのコメントが約あるものです。

+0

上記のコードを更新しましたが、POST要求が毎回Muleで受信されず、ワークフローに表示されるPOSTメッセージを取得するために最低2回(通常)ステップを繰り返す必要があるという問題がまだ発生しています – user3165854

+0

また、ブラウザのコンソールにネットワークタブのスクリーンショットを投稿できますか? – trichetriche

+0

要求されたスクリーンショットを追加 – user3165854