-
Notifications
You must be signed in to change notification settings - Fork 0
prob acces geader
Bonjour, Finalement j'ai trouvé, il faut créer la classe suivante dans le package de la classe ApplicationConfig.java : import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ContainerResponseFilter; import javax.ws.rs.ext.Provider;
@Provider public class CORSFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext response) { response.getHeaders().putSingle("Access-Control-Allow-Origin", "*"); response.getHeaders().putSingle("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, DELETE"); response.getHeaders().putSingle("Access-Control-Allow-Headers", "Content-Type"); } } Puis la référencer dans ApplicationConfig.java : private void addRestResourceClasses(Set<Class<?>> resources) { resources.add(webservice.CORSFilter.class); // Ajouter ici resources.add(webservice.OeuvresResource.class); }
@OPTIONS @Path("/getsample") public Response getOptions() { return Response.ok() .header("Access-Control-Allow-Origin", "*") .header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS") .header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build(); }
dans le web services
If non of this work, try to exchange the "" provided for "Access-Control-Allow-Origin" header with your custom domain where you access this resource. I.g. If you call this from http://localhost::8080 use something like this ("Access-Control-Allow-Origin", "http://localhost:8080") instead of asterisk ""