• GeoServer 跨域方法汇总


    环境

    • Linux CentOS 7.5
    • tomcat 9.0.33
    • geoserver 2.15.2
    • geowebcache 1.10.0

    操作步骤

    Geoserver有多个跨域解决方法,在各个环境下有的有效有的无效,具体原因未知,请客官们自行尝试。在此只是对用到过成功的案例做个记录。

    方法一(独立bat版现用方法)

    1. 找到geoserver配置文件/geoserver/WEB-INF/web.xml
      geoserver配置文件

    2. 文档中搜索关键词'cross-origin',发现web.xml中有两处被注释的节点,放开注释。
      filter
      filter-mapping

    3. 找到jetty-servlets-9.4.12.v20180830.jar,将其复制到/geoserver/WEB-INF/lib目录底下

    4. 重启Geoserver。这时候Geoserver可能会启动不了,报错503(Problem accessing /geoserver/web/. Reason: Service Unavailable Powered)

    5. 这时再下载对应 jetty-http-9.4.12.v20180830.jar 和 jetty-util-9.4.12.v20180830.jar jar包,放在WEB-INF/lib目录,再次重启即可(注意:jetty-servlets的jar包要跟jetty-util及jetty-http的jar包版本匹配)

    6. 重启geoserver

    方法二

    ** 方法二与方法五类似,方法二是放在geoserver的lib下,方法五是放在tomcat的lib下。区别是独立版和tomcat版部署方式 **

    1. 同时下载cors-filter-1.7.jar 跟 java-property-utils-1.9.jar (其他版本可能会导致 geoserver 打不开,测试过用最新版本出现geoserver打不开),放进 /geoserver/WEB-INF/lib 文件夹里面

    2. /geoserver/WEB-INF/web.xml增加以下配置:

    <filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
    <init-param>
    <param-name>cors.allowOrigin</param-name>
    <param-value>*</param-value>
    </init-param>
    <init-param>
    <param-name>cors.supportedMethods</param-name>
    <param-value>GET, POST, HEAD, PUT, DELETE</param-value>
    </init-param>
    <init-param>
    <param-name>cors.supportedHeaders</param-name>
    <param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value>
    </init-param>
    <init-param>
    <param-name>cors.exposedHeaders</param-name>
    <param-value>Set-Cookie</param-value>
    </init-param>
    <init-param>
    <param-name>cors.supportsCredentials</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>CORS</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    

    方法三

    1. 下载跨域文件CrossOriginFilter.class,然后解压到 geoserverWEB-INFclasses,保持原有路径(geoserverWEB-INFclassesorgmortbayservletsCrossOriginFilter.class)
      CrossOriginFilter

    2. 然后在 /geoserver/WEB-INF/web.xml 配置:

    <filter>
    <filter-name>cross-origin</filter-name>
    <filter-class>org.mortbay.servlets.CrossOriginFilter</filter-class>
    <init-param>
    <param-name>allowedOrigins</param-name>
    <param-value>*</param-value>
    </init-param>
    <init-param>
    <param-name>allowedMethods</param-name>
    <param-value>GET,POST</param-value>
    </init-param>
    <init-param>
    <param-name>allowedHeaders</param-name>
    <param-value>x-requested-with,content-type</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>cross-origin</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    

    方法四

    1. 编辑 geoserverWEB-INFweb.xml,不需要引入任何库,进行如下配置
    <filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    

    方法五(tomcat版现用方法)

    1. 基于tomcat可以对tomcat进行跨域

    2. 将cors-filter-2.4.jar 和 java-property-utils-1.9.1.jar 包放到 /tomcat/lib 下

    3. 修改/tomcat/conf/下的web.xml文件,在<web-app></web-app>节点中添加
      web-app下添加位置

    <filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
    <init-param>
    <param-name>cors.allowOrigin</param-name>
    <param-value>*</param-value>
    </init-param>
    <init-param>
    <param-name>cors.supportedMethods</param-name>
    <param-value>GET,POST,HEAD,PUT,DELETE</param-value>
    </init-param>
    <init-param>
    <param-name>cors.supportedHeaders</param-name>
    <param-value>Accept,Origin,X-Requested-With,Content-Type,Last-Modified</param-value>
    </init-param>
    <init-param>
    <param-name>cors.exposedHeaders</param-name>
    <param-value>Set-Cookie</param-value>
    </init-param>
    <init-param>
    <param-name>cors.supportsCredentials</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>CORS</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    
  • 相关阅读:
    那些书本上不曾告诉你的秘密
    附件十四面的数学模型与自动化算法分析
    ICAO 附件十四面课件分享
    风螺旋线的公式与特性
    How to describe the wind sprial in computer system?
    性能分析中看到螺旋线的影子
    风螺旋线的画法比较(三)
    风螺旋线的画法比较(二)
    风螺旋线的画法比较(一)
    网卡工作原理和wireshark混杂模式
  • 原文地址:https://www.cnblogs.com/giser-s/p/12627482.html
Copyright © 2020-2023  润新知