@PreMatching public class CorsFilter extends Object implements ContainerRequestFilter, ContainerResponseFilter
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowCredentials |
protected String |
allowedHeaders |
protected String |
allowedMethods |
protected Set<String> |
allowedOrigins |
protected int |
corsMaxAge |
protected String |
exposedHeaders |
Constructor and Description |
---|
CorsFilter() |
Modifier and Type | Method and Description |
---|---|
protected void |
checkOrigin(ContainerRequestContext requestContext,
String origin) |
void |
filter(ContainerRequestContext requestContext)
Filter method called before a request has been dispatched to a resource.
|
void |
filter(ContainerRequestContext requestContext,
ContainerResponseContext responseContext)
Filter method called after a response has been provided for a request
(either by a
request filter or by a
matched resource method. |
String |
getAllowedHeaders() |
String |
getAllowedMethods()
Will allow all by default.
|
Set<String> |
getAllowedOrigins()
Put "*" if you want to accept all origins.
|
int |
getCorsMaxAge() |
String |
getExposedHeaders() |
boolean |
isAllowCredentials()
Defaults to true.
|
protected void |
preflight(String origin,
ContainerRequestContext requestContext) |
void |
setAllowCredentials(boolean allowCredentials) |
void |
setAllowedHeaders(String allowedHeaders)
Will allow all by default
comma delimited string for Access-Control-Allow-Headers.
|
void |
setAllowedMethods(String allowedMethods)
Will allow all by default
comma delimited string for Access-Control-Allow-Methods.
|
void |
setCorsMaxAge(int corsMaxAge) |
void |
setExposedHeaders(String exposedHeaders)
Comma delimited list.
|
protected boolean allowCredentials
protected String allowedMethods
protected String allowedHeaders
protected String exposedHeaders
protected int corsMaxAge
public Set<String> getAllowedOrigins()
public boolean isAllowCredentials()
public void setAllowCredentials(boolean allowCredentials)
public String getAllowedMethods()
public void setAllowedMethods(String allowedMethods)
allowedMethods
- allowed methodspublic String getAllowedHeaders()
public void setAllowedHeaders(String allowedHeaders)
allowedHeaders
- allowed headerspublic int getCorsMaxAge()
public void setCorsMaxAge(int corsMaxAge)
public String getExposedHeaders()
public void setExposedHeaders(String exposedHeaders)
exposedHeaders
- exposed headerspublic void filter(ContainerRequestContext requestContext) throws IOException
ContainerRequestFilter
Filters in the filter chain are ordered according to their javax.annotation.Priority
class-level annotation value.
If a request filter produces a response by calling ContainerRequestContext.abortWith(javax.ws.rs.core.Response)
method, the execution of the (either pre-match or post-match) request filter
chain is stopped and the response is passed to the corresponding response
filter chain (either pre-match or post-match). For example, a pre-match
caching filter may produce a response in this way, which would effectively
skip any post-match request filters as well as post-match response filters.
Note however that a responses produced in this manner would still be processed
by the pre-match response filter chain.
filter
in interface ContainerRequestFilter
requestContext
- request context.IOException
- if an I/O exception occurs.PreMatching
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException
ContainerResponseFilter
request filter
or by a
matched resource method.
Filters in the filter chain are ordered according to their javax.annotation.Priority
class-level annotation value.
filter
in interface ContainerResponseFilter
requestContext
- request context.responseContext
- response context.IOException
- if an I/O exception occurs.protected void preflight(String origin, ContainerRequestContext requestContext) throws IOException
IOException
protected void checkOrigin(ContainerRequestContext requestContext, String origin)
Copyright © 2021 JBoss by Red Hat. All rights reserved.