-1

I'm working on an application that provides a local rest service. To do this I use resteasy (3.5.0) and for server com.sun.net.httpserver.HttpServer. My goal is to include the CORS header in the all replies. According to the documentation, resteasy provides a CorsFilter filter that puts the header, but nowhere can I find documentation on how I can use it in my case (without using an application server). And at all, how do I make some specific configuration.

I am currently writing this header manually, in each method

@Path("/api")
public class Endpoint {

    @GET
    @Path("version")
    @Produces(MediaType.APPLICATION_JSON)
    public Response version() {
        return Response.ok(new Version())
                .header("Access-Control-Allow-Origin", "*")
                .build();
    }

}
mr mcwolf
  • 2,574
  • 2
  • 14
  • 27

1 Answers1

0

Hi try to use the filter below are the given url..
https://howtodoinjava.com/servlets/java-cors-filter-example/

Anup pandey
  • 437
  • 2
  • 9
  • It does not work for me. There, an application server is used and `web.xml` for configuration is used accordingly. For me, a server uses embedded `com.sun.net.httpserver.HttpServer` – mr mcwolf Mar 22 '18 at 07:35
  • you are using any security framework like Spring Security? – Anup pandey Mar 22 '18 at 08:54
  • No, I use only resteasy and httpserver http://docs.jboss.org/resteasy/docs/3.5.0.Final/userguide/html/RESTEasy_Embedded_Container.html#d4e1973 – mr mcwolf Mar 22 '18 at 09:04
  • Please follow the like http://docs.jboss.org/resteasy/docs/3.0.24.Final/userguide/html_single/index.html#d4e1486 – Anup pandey Mar 22 '18 at 09:16