1

I am working on openlayers with xampp and geoserver. My openlayer application is running on URL http://localhost:8008 I am trying to access a URL http://localhost:8080/geoserver/workspace

But I am unable to access it. In browser console I have following error. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:8080/geoserver/workspace/ows?. (Reason: CORS request did not succeed).. please help me with this

I have tried apply filter in web.xml in tomcat and geoserver with following

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
  <param-name>cors.allowed.methods</param-name>
  <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

also in geoserver webinf/web.xml I added


<filter>
        <filter-name>cross-origin</filter-name>
        <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
       <init-param>
           <param-name>chainPreflight</param-name>
           <param-value>false</param-value>
       </init-param>
       <init-param>
           <param-name>allowedOrigins</param-name>
           <param-value>*</param-value>
       </init-param>
       <init-param>
           <param-name>allowedMethods</param-name>
           <param-value>GET,POST,PUT,DELETE,HEAD,OPTIONS</param-value>
       </init-param>
       <init-param>
           <param-name>allowedHeaders</param-name>
           <param-value>*</param-value>
       </init-param>
    </filter>
Dave Cassel
  • 8,352
  • 20
  • 38
Ashutosh Mishra
  • 103
  • 1
  • 6
  • Think I solved a similar problem by using a reverse proxy. I used IIS so my solution won't help you, but it might be something to look into. You might find posts like the following helpful: https://gis.stackexchange.com/questions/37514/how-do-i-get-geoserver-to-run-on-my-web-server?rq=1 – mlinth Apr 12 '19 at 07:17

1 Answers1

0

Add a Proxy to your xampp configuration to have the geoserver also at localhost:8008 so you can access it via localhost:8008/geoserver.

ProxyPass /geoserver/ http://localhost:8080/geoserver/

Maybe you need to load the proxy module in your Apache config to use the ProxyPass option.

bennos
  • 313
  • 4
  • 17