jimjonesbr / lod4wfs

Server application for publishing Geographic Linked Open Datasets via Web Feature Services.
MIT License
13 stars 7 forks source link

CORS Support #24

Closed semanticfire closed 7 years ago

semanticfire commented 7 years ago

Currently the WFS service has no CORS support, this can only be achieved by putting a proxy in front of LOD4WFS.

I understand that a proxy is good thing anyway, but you don't want to mess with headers manually

jimjonesbr commented 7 years ago

Hello @semanticfire , thanks for reporting the issue.

I just submitted a quick fix that might solve your problem. Try the latest version and let me know if the fix works for you.

nicky508 commented 7 years ago

Tried CORS with the new build, but CORS seems not to work. It still gives the CORS-header ‘Access-Control-Allow-Origin’ is missing error.

jimjonesbr commented 7 years ago

Hey @nicky508 CORS is actually handled outside of the application and can be configured directly in the Jetty web.xml file, which can be located at: jsp/xml/web.xml

Have you tried with the following parameters?

<filter-mapping>
    <filter-name>cross-origin</filter-name>
    <url-pattern>/cometd/*</url-pattern>
</filter-mapping>
semanticfire commented 7 years ago

I think the easiest solution is to add a CORS header in the actual WFS servlet: https://github.com/jimjonesbr/lod4wfs/blob/master/lod4wfs/src/main/java/de/ifgi/lod4wfs/web/ServletWFS.java#L38

nicky508 commented 7 years ago

Hi @jimjonesbr,

Nope, it does not work. Adding the filter-mapping to the web.xml causes a InvocationTargetException:

java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.eclipse.jetty.webapp.IterativeDescriptorProcessor.visit(IterativeDescriptorProcessor.java:85)

jimjonesbr commented 7 years ago

I'm afraid I'm forgetting to submit some important change. In my computer (as always in developers computers) this error does not pop up.

I added the following lines to the servlet:

response.addHeader("Access-Control-Allow-Origin","*"); response.addHeader("Access-Control-Allow-Methods","GET,POST"); response.addHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");

nicky508 commented 7 years ago

Nice! pulled, build and it works. Nice, thanks again for the fast fix again :+1:

jimjonesbr commented 7 years ago

Awesome!

Set to closed.