2015-08-28 29 views
0

我已經使用rest servlet綁定將路由作爲服務公開。將路由作爲restlet服務公開時處理方案

我已經使用employeeClientBean作爲POJO,將實際的調用包裝到員工REST服務中,基本上扮演了服務客戶端的角色。

因此,基於傳遞的方法名稱,我通過employeeClientBean調用員工REST服務中的相應方法。

我想知道如何處理在代碼塊中添加的方案。

我只是新來的駱駝,但覺得POJO結合比較好,因爲它沒有我們幾個駱駝像交換和處理器特定的API,甚至使用 任何特定組件。

但是,我不知道如何處理上述情況並向路由服務的用戶返回適當的JSON響應。

有人可以幫助我做到這一點。

public void configure() throws Exception { 
     restConfiguration().component("servlet").bindingMode(RestBindingMode.json) 
     .dataFormatProperty("prettyPrint", "true") 
     .contextPath("camelroute/rest").port(8080); 
      rest("/employee").description("Employee Rest Service") 
        .consumes("application/json").produces("application/json") 

     .get("/{id}").description("Find employee by id").outType(Employee.class) 
      .to("bean:employeeClientBean? method=getEmployeeDetails(${header.id})") 


      //How to handle and return response to the user of the route service for the following scenarios for get/{id}" 

       //1.Passed id is not a valid one as per the system 

       //2.Failure to return details due to some issues 



     .post().description("Create a new Employee ").type(Employee.class) 
      .to("bean:employeeClientBean?method=createEmployee"); 


      //How to handle and return correct response to the user of the route service for the following scenarios " 

       //1. Employee being created already exists in the system 

       //2. Some of the fields of employee passed are as not as per constraints on them 

       //3. Failure to create a employee due to some issues in server side (For Eg, DB Failure) 

}

回答

0

我怕你把駱駝不好用 - 按照Apache的documentation的REST模塊支持消費者實現,例如從REST端點讀取,但是不是回寫給調用者。

對於您的用例,您可能需要切換框架。在句法上,Ratpack朝着這個方向發展。

相關問題