6
在具有REST服務的wildfly 8.1中,我想實現CORS ContainerRequestFilter和ContainerResponseFilter。ContainerResponseFilter不起作用
我的要求過濾器工作正常,但ContainerResponseFilter
從來沒有被加載,也不叫
package org.test.rest;
import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.ext.Provider;
@Provider
@PreMatching // <-- EDIT : This was my mistake ! DO NOT ADD THIS
public class CorsResponseFilter implements ContainerResponseFilter {
public CorsResponseFilter() {
System.out.println("CorsResponseFilter.init");
}
@Override
public void filter(ContainerRequestContext req,
ContainerResponseContext resp) throws IOException {
System.out.println("CorsResponseFilter.filter");
resp.getHeaders().add("Access-Control-Allow-Origin", "*");
resp.getHeaders().add("Access-Control-Allow-Credentials", "true");
resp.getHeaders().add("Access-Control-Allow-Methods",
"GET, POST, DELETE, PUT");
resp.getHeaders().add("Access-Control-Allow-Headers",
"Content-Type, Accept");
}
}
這在我看來,作爲一個Wildfly/RestEasy的錯誤。你有另一個想法/我錯過了什麼嗎?