3

I am using a Grizzly HttpServer and i want to add a specific header in every response. Specifically, i want to avoid CORS problems by adding an 'Access-Control-Allow-Origin' header.

So, ideally, i want something like this:

HttpServer server = GrizzlyServerFactory.createHttpServer(uri, crc);
server.setHeader("Access-Control-Allow-Origin" , "*");

Generally, i am looking for a solution that does not require that i have to manually insert this header in every request-response action.

Is there any way to do this?

Mario
  • 767
  • 1
  • 14
  • 42
  • 2
    There is no such a way at the moment, but you can file a request for improvement at https://java.net/jira/browse/GRIZZLY and we'll take care of that ASAP. – alexey Mar 02 '15 at 18:57

1 Answers1

1

As @alexey said, there is no way (from the current Grizzly Server version) to do this. If anyone finds something else that works, i will gladly confirm it as an accepted answer.

The best alternative that works quite well is to extend the 'ContainerResponseFilter' class and override the 'filter' method.

Here is an example for 1.x API

Here is an example for 2.x API (minor changes)

Community
  • 1
  • 1
Mario
  • 767
  • 1
  • 14
  • 42