public class CorsService extends Service
CorsService corsService = new CorsService();
corsService.setAllowedOrigins(new HashSet(Arrays.asList("http://server.com")));
corsService.setAllowedCredentials(true);
| Constructor and Description |
|---|
CorsService()
Constructor.
|
CorsService(boolean enabled)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Filter |
createInboundFilter(Context context)
Create the filter that should be invoked for incoming calls.
|
Set<String> |
getAllowedHeaders()
Returns the modifiable set of headers allowed by the actual request on the
current resource.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Allow-Headers" header. |
Set<String> |
getAllowedOrigins()
Returns the URI an origin server allows for the requested resource.
|
Set<Method> |
getDefaultAllowedMethods()
Returns the list of methods allowed by default, used when
skippingResourceForCorsOptions is turned on. |
Set<String> |
getExposedHeaders()
Returns a modifiable whitelist of headers an origin server allows for the
requested resource.
Note that when used with HTTP connectors, this property maps to the "Access-Control-Expose-Headers" header. |
int |
getMaxAge()
Indicates how long (in seconds) the results of a preflight request can be
cached in a preflight result cache.
In case of a negative value, the results of a preflight request is not meant to be cached. Note that when used with HTTP connectors, this property maps to the "Access-Control-Max-Age" header. |
boolean |
isAllowedCredentials()
If true, adds 'Access-Control-Allow-Credentials' header.
|
boolean |
isAllowingAllRequestedHeaders()
If true, indicates that the value of 'Access-Control-Request-Headers' request
header will be copied into the 'Access-Control-Allow-Headers' response
header.
|
boolean |
isSkippingResourceForCorsOptions()
If true, the filter does not call the server resource for OPTIONS method of
CORS request and set Access-Control-Allow-Methods header with the default
methods.
|
void |
setAllowedCredentials(boolean allowedCredentials)
If true, adds 'Access-Control-Allow-Credentials' header.
|
void |
setAllowedHeaders(Set<String> allowedHeaders)
Sets the value of the 'Access-Control-Allow-Headers' response header.
|
void |
setAllowedOrigins(Set<String> allowedOrigins)
Sets the value of 'Access-Control-Allow-Origin' header.
|
void |
setAllowingAllRequestedHeaders(boolean allowingAllRequestedHeaders)
If true, copies the value of 'Access-Control-Request-Headers' request header
into the 'Access-Control-Allow-Headers' response header.
|
void |
setDefaultAllowedMethods(Set<Method> defaultAllowedMethods)
Sets the list of methods allowed by default, used when
skippingResourceForCorsOptions is turned on. |
void |
setExposedHeaders(Set<String> exposedHeaders)
Sets the value of 'Access-Control-Expose-Headers' response header.
|
void |
setMaxAge(int maxAge)
Sets the value of 'Access-Control-Max-Age' response header.
In case of negative value, the header is not set. |
void |
setSkippingResourceForCorsOptions(boolean skipResourceForCorsOptions)
Sets the value of skipResourceForCorsOptions field.
|
createOutboundFilter, getContext, isEnabled, isStarted, isStopped, setContext, setEnabled, start, stoppublic CorsService()
public CorsService(boolean enabled)
enabled - True if the service has been enabled.public Filter createInboundFilter(Context context)
ServicecreateInboundFilter in class Servicecontext - The current context.public Set<String> getAllowedHeaders()
public Set<String> getAllowedOrigins()
public Set<Method> getDefaultAllowedMethods()
skippingResourceForCorsOptions is turned on.skippingResourceForCorsOptions is turned on.public Set<String> getExposedHeaders()
public int getMaxAge()
public boolean isAllowedCredentials()
public boolean isAllowingAllRequestedHeaders()
allowedHeaders.public boolean isSkippingResourceForCorsOptions()
public void setAllowedCredentials(boolean allowedCredentials)
allowedCredentials - True to add the 'Access-Control-Allow-Credentials'
header.public void setAllowedHeaders(Set<String> allowedHeaders)
allowingAllRequestedHeaders is false.allowedHeaders - The value of 'Access-Control-Allow-Headers' response
header.public void setAllowedOrigins(Set<String> allowedOrigins)
allowedOrigins - The value of 'Access-Control-Allow-Origin' header.public void setAllowingAllRequestedHeaders(boolean allowingAllRequestedHeaders)
allowedHeaders.allowingAllRequestedHeaders - True to copy the value of
'Access-Control-Request-Headers' request
header into the
'Access-Control-Allow-Headers' response
header. If false, use
allowedHeaders.public void setDefaultAllowedMethods(Set<Method> defaultAllowedMethods)
skippingResourceForCorsOptions is turned on.defaultAllowedMethods - The list of methods allowed by default, used
when skippingResourceForCorsOptions is
turned on.public void setExposedHeaders(Set<String> exposedHeaders)
exposedHeaders - The value of 'Access-Control-Expose-Headers' response
header.public void setMaxAge(int maxAge)
maxAge - The value of 'Access-Control-Max-Age' response header.public void setSkippingResourceForCorsOptions(boolean skipResourceForCorsOptions)
skipResourceForCorsOptions - True if the filter does not call the server
resource for OPTIONS method of CORS
request.Copyright © 2005–2025. All rights reserved.