2017-02-10 80 views
0

我使用camel-swagger-java來公開其餘的API。在Camel Swagger中設置基路徑Java Rest DSL

有一種方法來設置在web.xml配置Servlet時的基本路徑:

<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> 

有沒有辦法使用REST DSL時設置的基本路徑?

回答

0

當您配置rest-dsl時,通過調用.contextPath()設置基本路徑。從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"); 
} 

}

您配置.contextPath("/my/base/path/")你的基本路徑。