【问题标题】:WSO2 ESB - Configure CORSWSO2 ESB - 配置 CORS
【发布时间】:2017-07-29 15:56:16
【问题描述】:

我在 WSO2 ESB 5.0.0 上创建了一个带有任何端点的 Rest API。

我的端点调用在 java 上创建的 api rest(在 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>

我没有使用 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.

我尝试在 repository/conf/tomcat/carbon/WEB-INF,我按照这个 url WSO2 API Manager CORS

但没有任何改变。

我该如何解决这个问题?

问候,

亚历山德罗

【问题讨论】:

    标签: wso2 wso2esb


    【解决方案1】:

    对于预检请求:

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

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

    或者为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/>
    

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

    对于简单的请求:

    你还必须把它放在你的输出序列中。

    <property name="Access-Control-Allow-Origin" value="*"  scope="transport" type="STRING"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 2016-05-19
      • 1970-01-01
      相关资源
      最近更新 更多