0
votes

I am using camel-swagger-java to expose rest APIs.

There is a way to set the base path when configuring a servlet in web.xml:

  <init-param>
    <!-- we specify the base.path using relative notation, that means the actual path will be calculated at runtime as
         http://server:port/contextpath/rest -->
    <param-name>base.path</param-name>
    <param-value>rest</param-value>
  </init-param>

Is there a way to set the base path when using Rest DSL?

1

1 Answers

0
votes

The base path is set via the call .contextPath() when you're configuring rest-dsl. From http://camel.apache.org/swagger-java.html:

public class UserRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
    // configure we want to use servlet as the component for the rest DSL
    // and we enable json binding mode
    restConfiguration().component("netty4-http").bindingMode(RestBindingMode.json)
        // and output using pretty print
        .dataFormatProperty("prettyPrint", "true")
        // setup context path and port number that netty will use
        .contextPath("/my/base/path/").port(8080)
        // add swagger api-doc out of the box
        .apiContextPath("/api-doc")
            .apiProperty("api.title", "User API").apiProperty("api.version", "1.2.3")
            // and enable CORS
            .apiProperty("cors", "true");

    // this user REST service is json only
    rest("/user").description("User rest service")
        .consumes("application/json").produces("application/json")
        .get("/{id}").description("Find user by id").outType(User.class)
            .param().name("id").type(path).description("The id of the user to get").dataType("int").endParam()
            .to("bean:userService?method=getUser(${header.id})")
        .put().description("Updates or create a user").type(User.class)
            .param().name("body").type(body).description("The user to update or create").endParam()
            .to("bean:userService?method=updateUser")
        .get("/findAll").description("Find all users").outTypeList(User.class)
            .to("bean:userService?method=listUsers");
}

}

You configure your base path in .contextPath("/my/base/path/").