CORS - Tomcat - Geoserver

use*_*784 21 tomcat cross-domain geoserver cors tomcat7

所有,我试图在Tomcat 7.0.52上为Geoserver启用CORS.

我修改了tomcat中conf的web.xml,如 http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter中所述

但是,这无助于在标题中设置交叉起源.我甚至尝试过geoserver web-inf/web.xml但没有帮助.

任何建议表示赞赏.

谢谢!

jgr*_*cha 35

我需要做同样的事情以避免在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>
Run Code Online (Sandbox Code Playgroud)

然后重启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
(...)
Run Code Online (Sandbox Code Playgroud)

响应标头:

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
Run Code Online (Sandbox Code Playgroud)

这适用于Chrome(Ver.35.0.1916.153)和Firefox(Ver.31.0).

  • 对我来说,文件是`/ var / lib / tomcat7 / webapps / geoserver / WEB-INF / web.xml` (2认同)

stv*_*tvn 6

我需要将以下内容添加到 CorsFilter 以确保允许预检“OPTIONS”请求

<init-param>
  <param-name>cors.allowed.methods</param-name>
  <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
Run Code Online (Sandbox Code Playgroud)