150.2. Configuring WAR deployments
For WAR implementations, you need to configure the servlet options in the
WEB-INF/web.xml
file.
Camel 2.15.x
Use relative paths for both the base.path and api.path parameters.
For example, to set up the Camel Swagger API servlet for any environment:
... <servlet> <servlet-name>ApiDeclarationServlet</servlet-name> <servlet-class>org.apache.camel.component.swagger.DefaultCamelSwaggerServlet</servlet-class> <!-- Specify the base.path and the api.path values using relative notation because the actual paths will be calculated at runtime as http://server:port/contextpath/rest and http://server:port/contextpath/api-docs, respectively --> <init-param> <param-name>base.path</param-name> <param-value>rest</param-value> </init-param> <init-param> <param-name>api.path</param-name> <param-value>api-docs</param-value> </init-param> <init-param> <param-name>api.version</param-name> <param-value>1.2.3</param-value> </init-param> <init-param> <param-name>api.title</param-name> <param-value>User Services</param-value> </init-param> <init-param> <param-name>api.description</param-name> <param-value>Camel Rest Example with Swagger that provides a User Rest service</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <!-- swagger api declaration --> <servlet-mapping> <servlet-name>ApiDeclarationServlet</servlet-name> <url-pattern>/api-docs/*</url-pattern> </servlet-mapping>
Camel 2.14.x
Both servlets,
org.apache.camel.component.swagger.spring.SpringRestSwaggerApiDeclarationServlet
and org.apache.camel.component.swagger.servletlistener.ServletListenerRestSwaggerApiDelarationServlet
, support the same options.
Use absolute paths for both the base.path and api.path parameters.
For example, to set up the Camel Swagger API servlet for Spring:
... <servlet> <servlet-name>ApiDeclarationServlet</servlet-name> <servlet-class>org.apache.camel.component.swagger.spring.SpringRestSwaggerApiDeclarationServlet</servlet-class> <init-param> <param-name>base.path</param-name> <param-value>http://localhost:8080/rest</param-value> </init-param> <init-param> <param-name>api.path</param-name> <param-value>http://localhost:8080/api-docs</param-value> </init-param> <init-param> <param-name>api.version</param-name> <param-value>1.2.3</param-value> </init-param> <init-param> <param-name>api.title</param-name> <param-value>User Services</param-value> </init-param> <init-param> <param-name>api.description</param-name> <param-value>Camel Rest Example with Swagger that provides a User Rest service</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <!-- swagger api declaration --> <servlet-mapping> <servlet-name>ApiDeclarationServlet</servlet-name> <url-pattern>/api-docs/*</url-pattern> </servlet-mapping>