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>
...
<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>
Copy to ClipboardCopied!Toggle word wrapToggle overflow
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>
...
<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>
Copy to ClipboardCopied!Toggle word wrapToggle overflow
We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.
Making open source more inclusive
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.
About Red Hat
We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.