小编典典

CORS-Tomcat-Geoserver

tomcat

全部,我正在尝试在Tomcat 7.0.52上为Geoserver启用CORS。

我按照http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter中的指定在Tomcat的conf中修改了web.xml。

但是,这无助于在标头中设置跨域。我什至在没有帮助的geoserver web-inf / web.xml中尝试了它。

任何建议表示赞赏。

谢谢!


阅读 318

收藏
2020-06-16

共1个答案

小编典典

我需要做同样的事情,以避免在OpenLayers中使用代理。

由于我正在运行Ubuntu 12.04,因此我已经安装了 Tomcat 7.0.55 ,而不是默认的7.0.26(从软件包安装)。

要添加CORS标头,我仅添加$CATALINA_HOME/conf/web.xml了以下几行:

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

然后重新启动tomcat。

例如,当我尝试从Geoserver中获取http://development.localhost.lan/geoserver/wfs运行中的应用程序的URL时,将http://localhost:3000获得以下标头:

请求的标头:

POST /geoserver/wfs HTTP/1.1
Host: development.localhost.lan
Origin: http://localhost:3000
X-Requested-With: XMLHttpRequest
(...)

响应头:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://localhost:3000
Connection:Keep-Alive
Content-Disposition:inline; filename=geoserver-GetFeature.text
Content-Encoding:gzip
Content-Length:469
Content-Type:text/xml; subtype=gml/3.1.1
Date:Tue, 29 Jul 2014 21:31:08 GMT
Keep-Alive:timeout=5, max=100
Server:Apache-Coyote/1.1

该版本适用于Chrome(版本35.0.1916.153)和Firefox(版本31.0)。

2020-06-16