Question

I have my Geoserver running at a Tomcat on address http://localhost:8888 and I have a JSP Application running at a Tomcat on address http://localhost:8080 with OpenLayers API.

I need to make WFS request with OpenLayers to Geoserver that is hosted at Tomcat in port 8888, given that my application is on port 8080.

Its possible make CrossDomain request? Because my requests are denied by the Geoserver.

Was it helpful?

Solution

Yes it is possible to do cross domain requests to geoserver. However you need to have or write a proxy script or service. In old versions of Geoserver the had a proxy service. However that would not help you here as you need to have the service running inside the same tomcat instance that the application is running that needs to access accross domains.

You could use a jsp script to do what you require. I have used one in the past that looked something like this. Please note that this sort of proxy script has security implications. The example given does not have any security precautions in place and can be used by a skilled hacker to do scripting attacks against your website. If this is going to be a production server or public internet facing please put in some filters that limit where and what sites can be access by the proxy script.

In order to use this script you will need to modify where your jsp applications looks for you geoserver application and change it. so instead of having

String Geoserver_Address = "http://localhost:8888/geoserver/ows"

You would put

String Geoserver_Address = "http://localhost:8080/Application/ProxyScript.jsp?http://localhost:8888/geoserver/ows

It is also worth noting that it is not Geoserver that cause the cross domain restriction but a security feature built into most browsers. It is a fairly common problem to run into when trying to load code or unsupported formats from across domains. Please see here and here for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top