How to get around CORS issue with geoserver?

2,377 views
Skip to first unread message

shawncrawley

unread,
Feb 18, 2016, 10:38:35 PM2/18/16
to Tethys Platform
I'm wanting to access xml pages of layers on my localhost geoserver (port 8181) through AJAX in an app that I am making, but I keep getting this infamous error: 'No 'Access-Control-Allow-Origin' header is present on the requested resource.' I was trying to find a way to change the access header on the localhost server, which I assume is possible since I should be the admin of that server, but I have no idea where the .conf or .htaccess file would be. Please correct me on all of my assumptions if I am wrong, and help me know if there is a way that I can successfully access the xml information on this geoserver.

alansnow21

unread,
Feb 19, 2016, 8:39:55 AM2/19/16
to Tethys Platform

swainn

unread,
Feb 19, 2016, 12:00:58 PM2/19/16
to Tethys Platform
The GeoServer Docker container has been configured to get around the CORS problem when using JSONP. I didn't realize it was a problem with the xml files as well... This may be helpful too:


You can get a bash on the running geoserver Docker container like this:

$ sudo docker exec -it tethys_geoserver /bin/bash

Then you can make any changes to the config that you need too. Just restart the docker when you are done. The most config files are the web.xml and server.xml and there are varying levels (server level vs app level). Here are the paths to the ones the way the docker image is setup:

/var/lib/tomcat7/conf/server.xml
/var/lib/tomcat7/conf/web.xml (server level)
/var/lib/tomcat7/webapps/geoserver/WEB-INF/web.xml (app level)

I'll likely be updating the GeoServer docker image soon, so if you find something that works, please post it so that we can incorporate it into the docker.

alansnow21

unread,
Feb 23, 2016, 10:00:32 AM2/23/16
to Tethys Platform

Here is what I did, and it seems to work without needing jsonp. It is just a start and will probably need to be improved.


vim /usr/share/tomcat/webapps/geoserver/WEB-INF/web.xml

Add CORS stuff next to last filter tag. See: http://enable-cors.org/server_tomcat.html

<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>

Shawn Crawley

unread,
Mar 11, 2016, 11:43:41 AM3/11/16
to alansnow21, Tethys Platform
I know it's been a while, but I wanted to respond with two things. 

First, I did not ever need to change anything with the geoserver setup to accomplish what I wanted. I ended up using the python requests library to call for a JSON page of data and had to pass the geoserver username and password with the request.

Second thing, I am now messing around with changing the display styles of my geoserver layers. I know geoserver does its default styling with .sld files that are written in XML. However, I noticed that they have a CSS extension for styling that (as implied) makes styling possible in CSS (http://docs.geoserver.org/stable/en/user/extensions/css/install.html#extensions-css-install). That is the way I would prefer to go, as I'm both already familiar with CSS and it reduces the number of lines of code dramatically. Thus, I am asking that you consider including that css extension in the default geoserver configuration that comes with Tethys. Any thoughts?

--
You received this message because you are subscribed to the Google Groups "Tethys Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tethysplatfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tethysplatform/e1fd1bfe-0e4d-4d4d-8a27-d766f5442462%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

swainn

unread,
Mar 11, 2016, 12:41:49 PM3/11/16
to Tethys Platform
Sounds good to me. I vote +1 on this. I can work work this in when I refactor GeoServer, which should be this month.

sdc50

unread,
Mar 11, 2016, 5:08:57 PM3/11/16
to Tethys Platform
+1. I'm not particularly familiar with the Geoserver api, but if Nathan is going to be implementing this then I trust his design without needed a full description here.
Reply all
Reply to author
Forward
0 new messages