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>
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

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.

© 2024 Red Hat, Inc.