HTTP POST 요청을 받아들이고 각도로 작성된 UI 응용 프로그램에서 호출되는 mule 3.7.3 워크 플로우가 있습니다.HTTP POST 호출이 반환됩니다. HTTP 메소드가 OPTIONS로 설정되어 있기 때문에 Mule에서 허용되지 않는 오류가 발생했습니다.
HTTP POST 호출이 Mule에 수행되면 http 메소드가 OPTIONS로 설정된 상태로 메시지가 전송되므로 허용되지 않는 메소드로 실패합니다. 응용 프로그램/json으로 설정된 콘텐츠 형식을 가진 XHR 형식 메시지를 보내는 응용 프로그램의 예상 동작이며 이러한 상황에서는 POST 요청을 보내기 전에 UI 응용 프로그램이 미리 작성된 OPTIONS 요청을 보내 게됩니다.
내 질문은 :
- UI를에만 POST 요청을 전송하는 것이 가능 그것?
- Mule이 이것을 처리하는 가장 좋은 방법은 무엇입니까? OPTIONS 호출을 모든 POST 메서드와 함께 RAML 파일에 추가하고 워크 플로를 추가로 만들어야합니까?
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: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_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-values">
<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="#['{ "getProducts": { "productsList": [{ "productId": "001", "name": "test_product1"}]}}']" 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="#['{"getCustomer":{"customerId":"1234567890","title":"MR","Name":"John"}}']" 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="#['{"createOrder":{"orderId":"8a493ecd-e842-4ca2-b33b-a03aa9136673","success":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="{ "message": "Resource not found" }" 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="{ "message": "Method not allowed" }" 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="{ "message": "Unsupported media type" }" 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="{ "message": "Not acceptable" }" 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="{ "message": "Bad request" }" doc:name="Set Payload"/>
</apikit:mapping>
</apikit:mapping-exception-strategy>
</mule>
감사
CORS 문제가있어
나는 노새를 잘 모릅니다하지만 당신은이 옵션을 적용해야한다. 요청은 결과를 리턴 할 필요는 없지만 200 상태로 응답해야합니다. –
아마도 'CORS'에 맞닥 뜨리게 될 것입니다. 실제 오류 문자열을 게시 할 수 있습니까? –