WSO2 ESB - 配置CORS

Ale*_*tos 3 wso2 wso2esb

我在WSO2 ESB 5.0.0上创建了一个包含任何端点的Rest API.

我的端点调用在java上运行的api休息(在Tomcat 8上运行),如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="RecuperarArmadilhaPorId">
   <http statistics="enable"
     method="GET"
     uri-template="http://localhost:8080/impactorcamentosgpmpu/ns/rest/pga/armadilhas/detalhePorId/{uri.var.id}"/>
</endpoint>
Run Code Online (Sandbox Code Playgroud)

我没有使用Identity Server,我不想在此刻使用.

当我打电话给我的网址wso2(http://192.168.10.178:8280/mapaHomologacao/ns/rest/pga/localidadesPorRota/101)内部移动应用程序时,我收到了cors错误:

XMLHttpRequest cannot load 
http://192.168.10.178:8280/mapaHomologacaorotas/completa/1/101. No 'Access-
Control-Allow-Origin' header is present on the requested resource. Origin 
'http://localhost:8100' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

我尝试在repository/conf/tomcat/carbon/WEB-INF上进行以下配置,我按照这个url WSO2 API Manager CORS

但没有变化.

我该如何解决这个问题?

问候,

亚历山德罗

Bee*_*Bee 6

对于飞行前请求:

你必须像这样创建一个过滤器(检查OPTIONS调用)

<filter source="get-property('axis2', 'HTTP_METHOD')" regex="OPTIONS">
    <then>
        ... 
    </then>
</filter>
Run Code Online (Sandbox Code Playgroud)

或创建一个单独的资源OPTIONS /*并将此内容放入其中.

<property name="Access-Control-Allow-Origin" value="*"  scope="transport" type="STRING"/>
<property name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,PATCH,OPTIONS" scope="transport" type="STRING"/>
<property name="Access-Control-Allow-Headers" value="Authorization,Access-Control-Allow-Origin,Content-Type" scope="transport" type="STRING"/>
<respond/>
Run Code Online (Sandbox Code Playgroud)

请注意,上述属性中的值应根据您的要求进行更改.

对于简单的请求:

你还必须将它放在你的序列中.

<property name="Access-Control-Allow-Origin" value="*"  scope="transport" type="STRING"/>
Run Code Online (Sandbox Code Playgroud)