You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Srikanth Hugar <sr...@gmail.com> on 2014/11/20 10:09:21 UTC

Karaf - WAB - Access-Control-Allow-Origin

I am trying to add a cross-origin headers (Access-Control-Allow-Origin: *) in
response while serving static files from jetty.
But somehow it is not working. What could be the issue????

This is done with Web Application bundle and WAB deployment is successful.

Karaf version : 3.0.0
Pax-web version : 3.0.5.


*WEB-INF/jetty-web.xml*
<?xml version="1.0"  encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "
http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/cssdocs</Set>
<Set name="handler">
        <New class="org.eclipse.jetty.server.handler.ResourceHandler">
            <Set name="resourceBase">/opt/polycom/css</Set>
            <Set name="directoriesListed">true</Set>
            <Set name="cacheControl">max-age=3600,public</Set>
        </New>
    </Set>
</Configure>


*WEB-INF/web.xml*
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<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>*</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>