title: Cross Origin Filter with embedded Jetty
body: <p>I'm trying to get a CrossOriginFilter working with a couple of embedded Jetty servers, both running on our internal network. Both are running servlets, but I need server A's web page to be able to post to server B's servlets. I think I need to add ACCESS_CONTROL_ALLOW_ORIGIN to a CrossOriginFilter but finding out how to do this with an embedded Jetty instance with no web.xml isn't proving to be easy. I get the following error message in the browser when trying to access server b's serlvets</p>
  
  <pre><code>No 'Access-Control-Allow-Origin' header is present on the requested resource
  </code></pre>
  
  <p>Im using angularjs to post to the other server's servlets in a controller.</p>
  
  <p>And here is the code for one of the servers (both are pretty much the same)</p>
  
  <pre><code>Server server = new Server(httpPort);
  
  ResourceHandler resource_handler = new ResourceHandler();
  resource_handler.setDirectoriesListed(true);
  resource_handler.setWelcomeFiles(new String[] { "index.html" });
  resource_handler.setResourceBase("./http/");
  
  ServletHandler handler = new ServletHandler();
  handler.addServletWithMapping(ServerPageRoot.class, "/servlet/*");
  
  FilterHolder holder = new FilterHolder(CrossOriginFilter.class);
  holder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
  holder.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
  holder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,POST,HEAD");
  holder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin");
  
  handler.addFilter(holder );
  
  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[] { resource_handler, handler,new DefaultHandler() });
  server.setHandler(handlers);
  server.start();
  </code></pre>