CORS - Tomcat - 地理服务器 [英] CORS - Tomcat - Geoserver
问题描述
所有,我正在尝试在 Tomcat 7.0.52 上为 Geoserver 启用 CORS.
All, I am trying to get CORS enabled on Tomcat 7.0.52 for Geoserver.
我在tomcat的conf中修改了web.xml,在http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter
I modified web.xml in conf in tomcat, as specified in http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter
但是,这无助于在标题中设置跨域.我什至为 geoserver web-inf/web.xml 尝试了它,但没有帮助.
But, that did not help set cross-origins in the header. I even tried it for geoserver web-inf/web.xml which did not help.
欢迎提出任何建议.
谢谢!
推荐答案
我需要做同样的事情以避免在 OpenLayers 中使用代理.
I need to do the same to avoid the usage of a proxy in OpenLayers.
由于我运行的是 Ubuntu 12.04,因此我安装了 Tomcat 7.0.55,而不是默认的 7.0.26(从软件包安装).
Since I'm running Ubuntu 12.04, I've installed Tomcat 7.0.55, instead of the default 7.0.26 (installed from packages).
要添加 CORS 标头,我只需在 $CATALINA_HOME/conf/web.xml
中添加以下几行:
To add CORS headers, I simply added to $CATALINA_HOME/conf/web.xml
the following lines:
<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.
and then restart tomcat.
例如,当我尝试从运行在 http://localhost:3000 上的应用程序中从 Geoserver 获取 URL
我得到以下标题:http://development.localhost.lan/geoserver/wfs
时
For example, when I try to fetch from Geoserver the URL http://development.localhost.lan/geoserver/wfs
from my application running on http://localhost:3000
I get the following headers:
请求的标头:
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).
This worked with Chrome (Ver. 35.0.1916.153) and Firefox (Ver. 31.0).
这篇关于CORS - Tomcat - 地理服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!