将路由作为重定向服务公开时处理方案

时间:2015-08-28 14:27:06

标签: apache-camel restlet

我使用了rest servlet绑定将路由公开为服务。

我使用employeeClientBean作为POJO,将实际调用包含在其中的员工REST服务中,基本上扮演服务客户端的角色。

因此,根据传递的方法名称,我通过employeeClientBean在员工REST服务中调用相应的方法。

我想知道如何处理代码块中的提交中添加的方案。

我只是Camel的新手,但感觉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)

}

1 个答案:

答案 0 :(得分:0)

我担心你正在使用Camel - 根据Apache documentation,REST模块支持Consumer实现,例如从REST端点读取,但写回呼叫者。

对于您的用例,您可能希望切换框架。从语法上讲,Ratpack就是朝这个方向发展的。