Colin Maudry
2015-07-15 17:24:30 UTC
Hello people,
I did follow the instructions in the Jetty documentation, but that was
not very helpful, as it's very succint.
After experimenting, I realized that we have to be quite explicit in our
configuration.
So I managed to have my Fuseki2 SPARQL endpoint accessible to a YASGUI
instance, doing this:
https://github.com/YASGUI/YASGUI/issues/65#issuecomment-121673221
For the lazy ones:
1. Open |webapp/WEB-INF/web.xml
2. Insert the following snipped before any other <filter>
|
<!-- CORS filter-->
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.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,DELETE,PUT,HEAD,OPTIONS</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified, Authorization</param-value>
</init-param>
<init-param>
<param-name>exposedHeaders</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3. Configure to your taste, but it works as-is. The key, compared to what the documentation says,
is that you should configure the servers to return certain headers that indicate CORS is enabled.
Cheers,
Colin
On 02/06/15 17:52, Jeffrey Witt wrote:
Hi, I just updated to Fuseki2 from Fuseki1. With Fuseki1 I was enjoying
the enabled *CORS* support, especially important for javascript only,
single page apps.
But, as I¹ve gleaned from this post:
https://issues.apache.org/jira/browse/JENA-652 *CORS* is not enabled by
default for Fueski2. I wonder if it is now possible to enable *CORS* for
Fueski2. If so could someone guide me through the enabling process.
(I have little to no experience with writing in Java, so I might need
detailed instructions).
Thanks in advance. jw
Hi there,
You'r right - *CORS* is not enabled in Fuseki2. It would eb re
if you are deploying Fuseki2 with the standalone server jar
(fuseki-server.jar), not the WAR file, you can follow the instructions
for Jetty [1] to enable it (no Java required, editing web.xml is required).
The web.xml file is in webapp/WEB-INF/web.xml of what usually FUSEKI_HOME
The war file can also be done - it needs unpacking, changing web.xml and
repacking.
----------- There's machinery in Fuseki2 for this (and a request routing
problem - now being fixed).
What would help me is someone with experience to advise what the headers
should be for the various options and especially whether one choice of
settings is good for everyone or whether this needs configuration in
some way. Even if the latter, what is the best out-of-the-box settings?
If it is one universal set of settings, is better (safe) to do in
Fuseki2 or, for example when running in Tomcat, should Tomcat do it?
Andy
[1]
http://www.eclipse.org/jetty/documentation/current/cross-origin-filter.html
I did follow the instructions in the Jetty documentation, but that was
not very helpful, as it's very succint.
After experimenting, I realized that we have to be quite explicit in our
configuration.
So I managed to have my Fuseki2 SPARQL endpoint accessible to a YASGUI
instance, doing this:
https://github.com/YASGUI/YASGUI/issues/65#issuecomment-121673221
For the lazy ones:
1. Open |webapp/WEB-INF/web.xml
2. Insert the following snipped before any other <filter>
|
<!-- CORS filter-->
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.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,DELETE,PUT,HEAD,OPTIONS</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified, Authorization</param-value>
</init-param>
<init-param>
<param-name>exposedHeaders</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3. Configure to your taste, but it works as-is. The key, compared to what the documentation says,
is that you should configure the servers to return certain headers that indicate CORS is enabled.
Cheers,
Colin
On 02/06/15 17:52, Jeffrey Witt wrote:
Hi, I just updated to Fuseki2 from Fuseki1. With Fuseki1 I was enjoying
the enabled *CORS* support, especially important for javascript only,
single page apps.
But, as I¹ve gleaned from this post:
https://issues.apache.org/jira/browse/JENA-652 *CORS* is not enabled by
default for Fueski2. I wonder if it is now possible to enable *CORS* for
Fueski2. If so could someone guide me through the enabling process.
(I have little to no experience with writing in Java, so I might need
detailed instructions).
Thanks in advance. jw
Hi there,
You'r right - *CORS* is not enabled in Fuseki2. It would eb re
if you are deploying Fuseki2 with the standalone server jar
(fuseki-server.jar), not the WAR file, you can follow the instructions
for Jetty [1] to enable it (no Java required, editing web.xml is required).
The web.xml file is in webapp/WEB-INF/web.xml of what usually FUSEKI_HOME
The war file can also be done - it needs unpacking, changing web.xml and
repacking.
----------- There's machinery in Fuseki2 for this (and a request routing
problem - now being fixed).
What would help me is someone with experience to advise what the headers
should be for the various options and especially whether one choice of
settings is good for everyone or whether this needs configuration in
some way. Even if the latter, what is the best out-of-the-box settings?
If it is one universal set of settings, is better (safe) to do in
Fuseki2 or, for example when running in Tomcat, should Tomcat do it?
Andy
[1]
http://www.eclipse.org/jetty/documentation/current/cross-origin-filter.html