Java 类org.apache.camel.model.rest.RestParamType 实例源码

项目:Camel    文件:RestApiNettyTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().component("netty4-http").host("localhost").port(getPort()).apiContextPath("/api-doc")
                .apiProperty("cors", "true").apiProperty("api.title", "The hello rest thing").apiProperty("api.version", "1.2.3");

            rest("/hello").consumes("application/json").produces("application/json")
                .get("/hi/{name}").description("Saying hi")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .to("log:hi")
                .get("/bye/{name}").description("Saying bye")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .responseMessage().code(200).message("A reply message").endResponseMessage()
                    .to("log:bye")
                .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml")
                    .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                    .to("log:bye");
        }
    };
}
项目:Camel    文件:RestApiUndertowTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().component("undertow").host("localhost").port(getPort()).apiContextPath("/api-doc")
                .apiProperty("cors", "true").apiProperty("api.title", "The hello rest thing").apiProperty("api.version", "1.2.3");

            rest("/hello").consumes("application/json").produces("application/json")
                .get("/hi/{name}").description("Saying hi")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .to("log:hi")
                .get("/bye/{name}").description("Saying bye")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .responseMessage().code(200).message("A reply message").endResponseMessage()
                    .to("log:bye")
                .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml")
                    .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                    .to("log:bye");
        }
    };
}
项目:Camel    文件:RestSwaggerReaderTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            rest("/hello").consumes("application/json").produces("application/json")
                    .get("/hi/{name}").description("Saying hi")
                        .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                        .to("log:hi")
                    .get("/bye/{name}").description("Saying bye")
                        .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                        .responseMessage().code(200).message("A reply message").endResponseMessage()
                        .to("log:bye")
                    .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml")
                        .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                        .to("log:bye");
        }
    };
}
项目:Camel    文件:RestSwaggerReaderPropertyPlaceholderTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            rest("/{{foo}}").consumes("application/json").produces("application/json")
                    .get("/hi/{name}").description("Saying hi")
                        .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                        .to("log:hi")
                    .get("/{{bar}}/{name}").description("Saying bye")
                        .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                        .responseMessage().code(200).message("A reply message").endResponseMessage()
                        .to("log:bye")
                    .post("/{{bar}}").description("To update the greeting message").consumes("application/xml").produces("application/xml")
                        .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                        .to("log:bye");
        }
    };
}
项目:Camel    文件:RestSwaggerReaderApiDocsOverrideTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            rest("/hello").apiDocs(false).consumes("application/json").produces("application/json")
                    .get("/hi/{name}").description("Saying hi")
                        .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                        .to("log:hi")
                    .get("/bye/{name}").apiDocs(true).description("Saying bye")
                        .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                        .responseMessage().code(200).message("A reply message").endResponseMessage()
                        .to("log:bye")
                    .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml")
                        .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                        .to("log:bye");
        }
    };
}
项目:Camel    文件:RestSwaggerReaderModelTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // this user REST service is json only
            rest("/user").tag("dude").description("User rest service")
                .consumes("application/json").produces("application/json")

                .get("/{id}").description("Find user by id").outType(User.class)
                    .responseMessage().message("The user returned").endResponseMessage()
                    .param().name("id").type(RestParamType.path).description("The id of the user to get").dataType("integer").endParam()
                    .to("bean:userService?method=getUser(${header.id})")

                .put().description("Updates or create a user").type(User.class)
                    .param().name("body").type(RestParamType.body).description("The user to update or create").endParam()
                    .to("bean:userService?method=updateUser")

                .get("/findAll").description("Find all users").outTypeList(User.class)
                    .responseMessage().message("All the found users").endResponseMessage()
                    .to("bean:userService?method=listUsers");
        }
    };
}
项目:Camel    文件:RestSwaggerReaderApiDocsTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            rest("/hello").consumes("application/json").produces("application/json")
                    .get("/hi/{name}").description("Saying hi")
                        .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                        .to("log:hi")
                    .get("/bye/{name}").apiDocs(false).description("Saying bye")
                        .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                        .responseMessage().code(200).message("A reply message").endResponseMessage()
                        .to("log:bye")
                    .post("/bye").apiDocs(false).description("To update the greeting message").consumes("application/xml").produces("application/xml")
                        .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                        .to("log:bye");
        }
    };
}
项目:Camel    文件:RestSwaggerReaderDayOfWeekTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // this user REST service is json only
            rest("/day").tag("dude").description("Day service")
                .consumes("application/json").produces("application/json")

                .get("/week").description("Day of week")
                    .param().name("day").type(RestParamType.query).description("Day of week")
                        .defaultValue("friday")
                        .dataType("string").allowableValues("monday", "tuesday", "wednesday", "thursday", "friday")
                    .endParam()
                    .responseMessage()
                        .code(200).responseModel(DayResponse.class)
                        .header("X-Rate-Limit-Limit").description("The number of allowed requests in the current period").dataType("integer").endHeader()
                    .endResponseMessage()
                    .to("log:week");
        }
    };
}
项目:Camel    文件:RestSwaggerReaderModelBookOrderTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // this user REST service is json only
            rest("/books").tag("dude").description("Book order service")
                .consumes("application/json").produces("application/json")

                .get("/{id}").description("Find order by id").outType(BookOrder.class)
                    .responseMessage().message("The order returned").endResponseMessage()
                    .param().name("id").type(RestParamType.path).description("The id of the order to get").dataType("integer").endParam()
                    .to("bean:bookService?method=getOrder(${header.id})");
        }
    };
}
项目:Camel    文件:RestApiJettyTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().component("jetty").host("localhost").port(getPort()).apiContextPath("/api-doc")
                    .apiProperty("cors", "true").apiProperty("api.title", "The hello rest thing").apiProperty("api.version", "1.2.3");

            rest("/hello").consumes("application/json").produces("application/json")
                .get("/hi/{name}").description("Saying hi")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .to("log:hi")
                .get("/bye/{name}").description("Saying bye")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .responseMessage().code(200).message("A reply message").endResponseMessage()
                    .to("log:bye")
                .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml")
                    .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                    .to("log:bye");
        }
    };
}
项目:Camel    文件:RestApiSparkTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().component("spark-rest").host("localhost").port(getPort()).apiContextPath("/api-doc")
                    .apiProperty("cors", "true").apiProperty("api.title", "The hello rest thing").apiProperty("api.version", "1.2.3");

            rest("/hello").consumes("application/json").produces("application/json")
                .get("/hi/{name}").description("Saying hi")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .to("direct:hello")
                .get("/bye/{name}").description("Saying bye")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .responseMessage().code(200).message("A reply message").endResponseMessage()
                    .to("log:bye")
                .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml")
                    .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                    .to("log:bye");

            from("direct:hello")
                    .transform().constant("Hello World");

        }
    };
}
项目:camel-cookbook-examples    文件:ParamRoute.java   
@Override
public void configure() throws Exception {
    restConfiguration()
        .component("undertow").host("localhost").port(port1);

    rest("/say")
        .get("/hello")
            .route().transform().constant("Hello World").endRest()
        .get("/hello/{name}")
            .route().transform(simple("Hello ${header.name}")).endRest()
        .get("/hello/query/{name}?verbose={verbose}")
            .param().name("verbose").type(RestParamType.query).defaultValue("false").endParam()
            .to("direct:hello")
        .post("/bye/{name}")
            .toD("mock:${header.name}");

    from("direct:hello")
        .choice()
            .when(header("verbose").isEqualTo(true))
                .transform(simple("Hello there ${header.name}! How are you today?")).endChoice()
            .otherwise()
                .transform(simple("Yo ${header.name}"));
}
项目:Camel    文件:ManagedFromRestPlaceholderTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().host("localhost");
            rest("{{foo}}")
                .get().to("direct:hello");

            rest("{{bar}}")
                .get().consumes("application/json")
                    .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues(Arrays.asList("1", "2", "3", "4"))
                        .defaultValue("1").name("header_count").required(true)
                    .endParam().
                    param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues(Arrays.asList("a", "b", "c", "d"))
                        .defaultValue("b").collectionFormat(CollectionFormat.multi).name("header_letter").required(false)
                    .endParam()
                    .responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage()
                    .to("direct:bye")
                .post().to("mock:update");

            from("direct:hello")
                .transform().constant("Hello World");

            from("direct:bye")
                .transform().constant("Bye World");
        }
    };
}
项目:Camel    文件:ManagedFromRestGetTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().host("localhost");
            rest("/say/hello")
                .get().to("direct:hello");

            rest("/say/bye")
                .get().consumes("application/json")
                    .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues(Arrays.asList("1", "2", "3", "4"))
                        .defaultValue("1").name("header_count").required(true)
                    .endParam().
                    param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues(Arrays.asList("a", "b", "c", "d"))
                        .defaultValue("b").collectionFormat(CollectionFormat.multi).name("header_letter").required(false)
                    .endParam()
                    .responseMessage().code(300).message("test msg").responseModel(Integer.class).endResponseMessage()
                    .to("direct:bye")
                .post().to("mock:update");

            from("direct:hello")
                .transform().constant("Hello World");

            from("direct:bye")
                .transform().constant("Bye World");
        }
    };
}
项目:Camel    文件:FromRestDefaultValueTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().host("localhost").enableCORS(true);

            rest("/say/bye").consumes("application/json")
                .get().param().type(RestParamType.query).name("kind").defaultValue("customer").endParam()
                    .to("mock:bye");
        }
    };
}
项目:Camel    文件:FromRestIdAndDescriptionTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().host("localhost");
            rest("/say/hello").id("hello").description("Hello Service")
                    .get().id("get-say").description("Says hello to you").to("direct:hello");

            rest("/say/bye").description("bye", "Bye Service", "en")
                    .get().description("Says bye to you").consumes("application/json")
                    .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4")
                    .defaultValue("1").name("header_count").required(true)
                    .endParam().
                    param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d")
                    .defaultValue("b").collectionFormat(CollectionFormat.multi).name("header_letter").required(false)
                    .endParam()
                    .responseMessage().code(300).message("test msg").responseModel(Integer.class)
                        .header("rate").description("Rate limit").dataType("integer").endHeader()
                    .endResponseMessage()
                    .responseMessage().code("error").message("does not work").endResponseMessage()
                    .to("direct:bye")
                    .post().description("Updates the bye message").to("mock:update");

            from("direct:hello")
                    .transform().constant("Hello World");

            from("direct:bye")
                    .transform().constant("Bye World");
        }
    };
}
项目:Camel    文件:FromRestExplicitComponentTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // configure to use dummy-rest
            restConfiguration().component("dummy-rest").host("localhost");

            rest("/say/hello")
                    .get().to("direct:hello");

            rest("dummy-rest").path("/say/bye")
                    .get().consumes("application/json")
                    .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4")
                    .defaultValue("1").name("header_count").required(true)
                    .endParam().
                    param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d")
                    .defaultValue("b").collectionFormat(CollectionFormat.multi).name("header_letter").required(false)
                    .endParam()
                    .responseMessage().code(300).message("test msg").responseModel(Integer.class)
                        .header("rate").description("Rate limit").dataType("integer").endHeader()
                    .endResponseMessage()
                    .responseMessage().code("error").message("does not work").endResponseMessage()
                    .to("direct:bye")
                    .post().to("mock:update");

            from("direct:hello")
                .transform().constant("Hello World");

            from("direct:bye")
                .transform().constant("Bye World");

        }
    };
}
项目:Camel    文件:FromRestGetTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration().host("localhost");
            rest("/say/hello")
                .get().to("direct:hello");

            rest("/say/bye")
                    .get().consumes("application/json")
                    .param().type(RestParamType.header).description("header param description1").dataType("integer").allowableValues("1", "2", "3", "4")
                    .defaultValue("1").name("header_count").required(true)
                    .endParam().
                    param().type(RestParamType.query).description("header param description2").dataType("string").allowableValues("a", "b", "c", "d")
                    .defaultValue("b").collectionFormat(CollectionFormat.multi).name("header_letter").required(false)
                    .endParam()
                    .responseMessage().code(300).message("test msg").responseModel(Integer.class)
                        .header("rate").description("Rate limit").dataType("integer").endHeader()
                    .endResponseMessage()
                    .responseMessage().code("error").message("does not work").endResponseMessage()
                    .to("direct:bye")
                    .post().to("mock:update");

            from("direct:hello")
                .transform().constant("Hello World");

            from("direct:bye")
                .transform().constant("Bye World");
        }
    };
}
项目:Camel    文件:RestRestletApiTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // configure to use restlet on localhost with the given port
            restConfiguration()
                    .component("restlet").port(portNum)
                    .apiContextPath("/docs")
                    .apiProperty("cors", "true")
                    .apiProperty("api.title", "The hello rest thing")
                    .apiProperty("api.version", "1.2.3");

            rest("/hello").consumes("application/json").produces("application/json")
                    .get("/{name}").description("Saying hi")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .to("log:hi");

            rest("/bye").consumes("application/json").produces("application/json")
                    .get("/{name}").description("Saying bye")
                    .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
                    .responseMessage().code(200).message("A reply message").endResponseMessage()
                    .to("log:bye")

                    .post().description("To update the greeting message")
                    .consumes("application/xml").produces("application/xml")
                    .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
                    .to("log:bye");
        }
    };
}
项目:Camel    文件:RestJettyDefaultValueTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // configure to use jetty on localhost with the given port
            restConfiguration().component("jetty").host("localhost").port(getPort()).endpointProperty("httpBindingRef", "#mybinding");

            // use the rest DSL to define the rest services
            rest("/users/")
                    .get("{id}/basic").param().name("verbose").type(RestParamType.query).defaultValue("false").endParam()
                    .route()
                    .process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            String id = exchange.getIn().getHeader("id", String.class);

                            Object verbose = exchange.getIn().getHeader("verbose");
                            ObjectHelper.notNull(verbose, "verbose");

                            if ("true".equals(verbose)) {
                                exchange.getOut().setBody(id + ";Donald Duck;1113 Quack Street Duckburg");
                            }
                            if ("false".equals(verbose)) {
                                exchange.getOut().setBody(id + ";Donald Duck");
                            }
                        }
                    });
        }
    };
}
项目:Camel    文件:FromRestGetTest.java   
public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());

    assertEquals(2, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/hello", rest.getPath());
    assertEquals(1, rest.getVerbs().size());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:hello", to.getUri());

    rest = context.getRestDefinitions().get(1);
    assertNotNull(rest);
    assertEquals("/say/bye", rest.getPath());
    assertEquals(2, rest.getVerbs().size());
    assertEquals("application/json", rest.getVerbs().get(0).getConsumes());

    assertEquals(2, rest.getVerbs().get(0).getParams().size());
    assertEquals(RestParamType.header, rest.getVerbs().get(0).getParams().get(0).getType());
    assertEquals(RestParamType.query, rest.getVerbs().get(0).getParams().get(1).getType());

    assertEquals("header param description1", rest.getVerbs().get(0).getParams().get(0).getDescription());
    assertEquals("header param description2", rest.getVerbs().get(0).getParams().get(1).getDescription());

    assertEquals("integer", rest.getVerbs().get(0).getParams().get(0).getDataType());
    assertEquals("string", rest.getVerbs().get(0).getParams().get(1).getDataType());
    assertEquals(Arrays.asList("1", "2", "3", "4"), rest.getVerbs().get(0).getParams().get(0).getAllowableValues());
    assertEquals(Arrays.asList("a", "b", "c", "d"), rest.getVerbs().get(0).getParams().get(1).getAllowableValues());
    assertEquals("1", rest.getVerbs().get(0).getParams().get(0).getDefaultValue());
    assertEquals("b", rest.getVerbs().get(0).getParams().get(1).getDefaultValue());

    assertEquals(null, rest.getVerbs().get(0).getParams().get(0).getCollectionFormat());
    assertEquals(CollectionFormat.multi, rest.getVerbs().get(0).getParams().get(1).getCollectionFormat());

    assertEquals("header_count", rest.getVerbs().get(0).getParams().get(0).getName());
    assertEquals("header_letter", rest.getVerbs().get(0).getParams().get(1).getName());
    assertEquals(Boolean.TRUE, rest.getVerbs().get(0).getParams().get(0).getRequired());
    assertEquals(Boolean.FALSE, rest.getVerbs().get(0).getParams().get(1).getRequired());

    assertEquals("300", rest.getVerbs().get(0).getResponseMsgs().get(0).getCode());
    assertEquals("rate", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getName());
    assertEquals("Rate limit", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getDescription());
    assertEquals("integer", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getDataType());
    assertEquals("error", rest.getVerbs().get(0).getResponseMsgs().get(1).getCode());
    assertEquals("test msg", rest.getVerbs().get(0).getResponseMsgs().get(0).getMessage());
    assertEquals(Integer.class.getCanonicalName(), rest.getVerbs().get(0).getResponseMsgs().get(0).getResponseModel());

    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:bye", to.getUri());

    // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
    getMockEndpoint("mock:update").expectedMessageCount(1);
    template.sendBody("seda:post-say-bye", "I was here");
    assertMockEndpointsSatisfied();

    String out = template.requestBody("seda:get-say-hello", "Me", String.class);
    assertEquals("Hello World", out);
    String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
    assertEquals("Bye World", out2);
}
项目:Camel    文件:FromRestGetTest.java   
@Test
public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());

    assertEquals(2, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/hello", rest.getPath());
    assertEquals(1, rest.getVerbs().size());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:hello", to.getUri());

    rest = context.getRestDefinitions().get(1);
    assertNotNull(rest);
    assertEquals("/say/bye", rest.getPath());
    assertEquals(2, rest.getVerbs().size());
    assertEquals("application/json", rest.getVerbs().get(0).getConsumes());

    assertEquals(2, rest.getVerbs().get(0).getParams().size());
    assertEquals(RestParamType.header, rest.getVerbs().get(0).getParams().get(0).getType());
    assertEquals(RestParamType.query, rest.getVerbs().get(0).getParams().get(1).getType());

    assertEquals("header param description1", rest.getVerbs().get(0).getParams().get(0).getDescription());
    assertEquals("header param description2", rest.getVerbs().get(0).getParams().get(1).getDescription());

    assertEquals("integer", rest.getVerbs().get(0).getParams().get(0).getDataType());
    assertEquals("string", rest.getVerbs().get(0).getParams().get(1).getDataType());
    assertEquals(Arrays.asList("1", "2", "3", "4"), rest.getVerbs().get(0).getParams().get(0).getAllowableValues());
    assertEquals(Arrays.asList("a", "b", "c", "d"), rest.getVerbs().get(0).getParams().get(1).getAllowableValues());
    assertEquals("1", rest.getVerbs().get(0).getParams().get(0).getDefaultValue());
    assertEquals("b", rest.getVerbs().get(0).getParams().get(1).getDefaultValue());

    assertEquals(null, rest.getVerbs().get(0).getParams().get(0).getCollectionFormat());
    assertEquals(CollectionFormat.multi, rest.getVerbs().get(0).getParams().get(1).getCollectionFormat());

    assertEquals("header_count", rest.getVerbs().get(0).getParams().get(0).getName());
    assertEquals("header_letter", rest.getVerbs().get(0).getParams().get(1).getName());
    assertEquals(Boolean.TRUE, rest.getVerbs().get(0).getParams().get(0).getRequired());
    assertEquals(Boolean.FALSE, rest.getVerbs().get(0).getParams().get(1).getRequired());

    assertEquals("300", rest.getVerbs().get(0).getResponseMsgs().get(0).getCode());
    assertEquals("rate", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getName());
    assertEquals("Rate limit", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getDescription());
    assertEquals("integer", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getDataType());
    assertEquals("test msg", rest.getVerbs().get(0).getResponseMsgs().get(0).getMessage());
    assertEquals(Integer.class.getCanonicalName(), rest.getVerbs().get(0).getResponseMsgs().get(0).getResponseModel());

    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:bye", to.getUri());

    // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
    getMockEndpoint("mock:update").expectedMessageCount(1);
    template.sendBody("seda:post-say-bye", "I was here");
    assertMockEndpointsSatisfied();

    String out = template.requestBody("seda:get-say-hello", "Me", String.class);
    assertEquals("Hello World", out);
    String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
    assertEquals("Bye World", out2);
}
项目:camel-cookbook-examples    文件:CafeApiRoute.java   
@Override
public void configure() throws Exception {
    onException(MenuItemNotFoundException.class)
        .handled(true)
        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404))
        .setHeader(Exchange.CONTENT_TYPE, constant("text/plain"))
        .setBody().simple("${exception.message}");

    onException(MenuItemInvalidException.class)
        .handled(true)
        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400))
        .setHeader(Exchange.CONTENT_TYPE, constant("text/plain"))
        .setBody().simple("${exception.message}");

    onException(JsonParseException.class)
        .handled(true)
        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400))
        .setHeader(Exchange.CONTENT_TYPE, constant("text/plain"))
        .setBody().constant("Invalid json data");

    restConfiguration()
        .component("undertow").port(port1)
        .bindingMode(RestBindingMode.json)
        .apiContextPath("api-doc")
        .apiProperty("api.title", "Cafe Menu")
        .apiProperty("api.version", "1.0.0")
        .apiProperty("api.description", "Cafe Menu Sample API")
        .apiProperty("api.contact.name", "Camel Cookbook")
        .apiProperty("api.contact.url", "http://www.camelcookbook.org")
        .apiProperty("api.license.name", "Apache 2.0")
        .apiProperty("api.license.url", "http://www.apache.org/licenses/LICENSE-2.0.html")
        .enableCORS(true);

    rest("/cafe/menu").description("Cafe Menu Services")
        .get("/items").description("Returns all menu items").outType(MenuItem[].class)
            .responseMessage().code(200).message("All of the menu items").endResponseMessage()
            .to("bean:menuService?method=getMenuItems")
        .get("/items/{id}").description("Returns menu item with matching id").outType(MenuItem.class)
            .param().name("id").type(RestParamType.path).description("The id of the item").dataType("int").endParam()
            .responseMessage().code(200).message("The requested menu item").endResponseMessage()
            .responseMessage().code(404).message("Menu item not found").endResponseMessage()
            .to("bean:menuService?method=getMenuItem(${header.id})")
        .post("/items").description("Creates a new menu item").type(MenuItem.class)
            .param().name("body").type(RestParamType.body).description("The item to create").endParam()
            .responseMessage().code(201).message("Successfully created menu item").endResponseMessage()
            .responseMessage().code(400).message("Invalid menu item").endResponseMessage()
            .route().to("bean:menuService?method=createMenuItem").setHeader(Exchange.HTTP_RESPONSE_CODE, constant(201)).endRest()
        .put("/items/{id}").description("Updates an existing or creates a new menu item").type(MenuItem.class)
            .param().name("id").type(RestParamType.path).description("The id of the item").dataType("int").endParam()
            .param().name("body").type(RestParamType.body).description("The menu item new contents").endParam()
            .responseMessage().code(200).message("Successfully updated item").endResponseMessage()
            .responseMessage().code(400).message("Invalid menu item").endResponseMessage()
            .to("bean:menuService?method=updateMenuItem(${header.id}, ${body})")
        .delete("/items/{id}").description("Deletes the specified item")
            .param().name("id").type(RestParamType.path).description("The id of the item").dataType("int").endParam()
            .responseMessage().code(200).message("Successfully deleted item").endResponseMessage()
            .to("bean:menuService?method=removeMenuItem(${header.id})");
}