...
Div | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||
|
Examples
|
CorsFilter
If you use the swagger ui to view the REST api then you likely need to enable support for CORS. This is needed if the swagger ui is hosted and running on another hostname/port than the actual REST apis. When doing this the swagger ui needs to be allowed to access the REST resources across the origin (CORS). The CorsFilter adds the necessary HTTP headers to enable CORS.
To use CORS adds the following filter org.apache.camel.component.swagger.RestSwaggerCorsFilter
to your web.xml.
Wiki Markup |
---|
{snippet:id=e2|lang=xml|url=camel/trunk/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml} |
The CorsFilter sets the following headers for all requests
- Access-Control-Allow-Origin = *
- Access-Control-Allow-Methods = GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH
- Access-Control-Max-Age = 3600
- Access-Control-Allow-Headers = Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers
Notice this is a very simple CORS filter. You may need to use a more sophisticated filter to set the header values differently for a given client. Or block certain clients etc.
Examples
In the Apache Camel distribution we ship the camel-example-servlet-rest-tomcat
which demonstrates using this Swagger component.TODO: rest example