private static ContextHandler buildContext ( String basePath ) { ResourceConfig resourceConfig = new ResourceConfig ( ) ; resourceConfig . packages ( QueryResource . class . getPackage ( ) . getName ( ) , ApiListingResource . class . getPackage ( ) . getName ( ) ) ; ServletContainer servletContainer = new ServletContainer ( resourceConfig ) ; ServletHolder entityBrowser = new ServletHolder ( servletContainer ) ; ServletContextHandler entityBrowserContext = new ServletContextHandler ( ServletContextHandler . SESSIONS ) ; entityBrowserContext . setContextPath ( basePath ) ; entityBrowserContext . addServlet ( entityBrowser , "/*" ) ; FilterHolder corsFilter = new FilterHolder ( CrossOriginFilter . class ) ; corsFilter . setAsyncSupported ( true ) ; corsFilter . setInitParameter ( CrossOriginFilter . ALLOWED_ORIGINS_PARAM , "*" ) ; corsFilter . setInitParameter ( CrossOriginFilter . ALLOWED_HEADERS_PARAM , "*" ) ; corsFilter . setInitParameter ( CrossOriginFilter . ACCESS_CONTROL_ALLOW_ORIGIN_HEADER , "*" ) ; corsFilter . setInitParameter ( CrossOriginFilter . ALLOWED_METHODS_PARAM , "GET,POST,HEAD,DELETE,PUT,OPTIONS" ) ; entityBrowserContext . addFilter ( corsFilter , "/*" , EnumSet . allOf ( DispatcherType . class ) ) ; return entityBrowserContext ; }
Adds resources to the context to be run on the server