Skip to content

Instantly share code, notes, and snippets.

@Vp3n
Last active December 15, 2015 23:29
Show Gist options
  • Save Vp3n/5340950 to your computer and use it in GitHub Desktop.
Save Vp3n/5340950 to your computer and use it in GitHub Desktop.
Handle CORS (Cross-Origin Resource Sharing) requests from any Java web application
<!-- pom.xml, adding required dependency-->
<dependencies>
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<!-- then setup filter on web.xml, this configuration allow everything : suitable for dev environment -->
<!-- more options and informations on http://software.dzhuvinov.com/cors-filter-configuration.html -->
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Content-Type, X-Requested-With, Accept, Origin</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<servlet-name>servletName</servlet-name>
</filter-mapping>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment