-
Notifications
You must be signed in to change notification settings - Fork 0
/
CORSFilter.java
executable file
·36 lines (29 loc) · 1.02 KB
/
CORSFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package epod.web;
import java.io.IOException;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
/*
Add this filter to your webapp.
Don't forget to change the package name above ^^^^^^
*/
@WebFilter(urlPatterns = "/*", asyncSupported = true, dispatcherTypes = DispatcherType.REQUEST)
public class CORSFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException { }
@Override
public void destroy() { }
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletResponse resp = (HttpServletResponse)response;
resp.setHeader("Access-Control-Allow-Origin", "*");
chain.doFilter(request, response);
}
}