Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty Cross Origin Filter

> Does anyone know how to configure the Jetty-Maven plugin to use the
> cross origin filter?
>
> I added the following to the application web.xml file, but when I
> execute "mvn jetty:run" I get "java.lang.ClassNotFoundException:
> org.eclipse.jetty.servlets.CrossOriginFilter"
>
> <web-app ...>
>    ...
>    <filter>
>        <filter-name>cross-origin</filter-name>
>        <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
>    </filter>
>    <filter-mapping>
>        <filter-name>cross-origin</filter-name>
>        <url-pattern>/*</url-pattern>
>    </filter-mapping>
>    ...
> </web-app>

To solve the "ClassNotFoundException" I needed to add
jetty-servlets.jar to the classpath; originally, I assumed it was
already on the classpath. While jetty now runs, I continue to be
unable to do cross origin resource sharing (CORS); specifically, I get
the error:

"Origin http://localhost:8081 is not allowed by Access-Control-Allow-Origin."

I've included my override descriptor below; does anyone know what
could be wrong? Thanks.

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd"; >

<web-app>
  <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>
      <filter-pattern>/*</filter-pattern>
  </filter-mapping>
</web-app>


Back to the top