Created
July 10, 2014 23:43
-
-
Save craigbeck/fb71818063175b9b4210 to your computer and use it in GitHub Desktop.
Enable cross origin requests (CORS) using the Jersey CrossOriginFilter to Dropwizard 0.7.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in run method of your application: | |
final FilterRegistration.Dynamic cors = environment.servlets().addFilter("crossOriginRequsts", CrossOriginFilter.class); | |
cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); |
Worth noting that if you have authentication / authorization filters setup, you'll likely want to configure the filter with this:
cors.setInitParameter(CrossOriginFilter.CHAIN_PREFLIGHT_PARAM, Boolean.FALSE.toString());
This will prevent preflight requests (that don't have authorization headers on them) from getting filtered by your down-stream authentication / authorization filters which would result in a 401~403 instead of a 200.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should work, there is a typo in the snippet however, "crossOriginRequsts" should be "crossOriginRequests"