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

项目:drinkwater-java    文件:RestHelper.java   
private static RestDefinition toRestdefinition(RouteBuilder builder,
                                               Method method,
                                               HttpMethod httpMethod,
                                               String restPath) {
    RestDefinition answer = builder.rest();

    String fromPath = restPath;

    if (httpMethod == HttpMethod.GET) {
        answer = answer.get(fromPath);
    } else if (httpMethod == HttpMethod.POST) {
        answer = answer.post(fromPath);
    } else if (httpMethod == HttpMethod.PUT) {
        answer = answer.put(fromPath);
    } else if (httpMethod == HttpMethod.DELETE) {
        answer = answer.delete(fromPath);
    } else if (httpMethod == HttpMethod.PATCH) {
        answer = answer.patch(fromPath);
    } else {
        throw new RuntimeException("method currently not supported in Rest Paths : " + httpMethod);
    }

    answer = setBodyType(answer, method);

    return answer;
}
项目:Camel    文件:AbstractLocalCamelController.java   
@SuppressWarnings("deprecation")
public String getRestModelAsXml(String camelContextName) throws Exception {
    CamelContext context = this.getLocalCamelContext(camelContextName);
    if (context == null) {
        return null;
    }

    List<RestDefinition> rests = context.getRestDefinitions();
    if (rests == null || rests.isEmpty()) {
        return null;
    }
    // use a rests definition to dump the rests
    RestsDefinition def = new RestsDefinition();
    def.setRests(rests);
    return ModelHelper.dumpModelAsXml(null, def);
}
项目:Camel    文件:CamelContextAddRestDefinitionsFromXmlTest.java   
public void testAddRestDefinitionsFromXml() throws Exception {
    RestDefinition rest = loadRest("rest1.xml");
    assertNotNull(rest);

    assertEquals("foo", rest.getId());
    assertEquals(0, context.getRestDefinitions().size());

    context.getRestDefinitions().add(rest);
    assertEquals(1, context.getRestDefinitions().size());

    final List<RouteDefinition> routeDefinitions = rest.asRouteDefinition(context);

    for (final RouteDefinition routeDefinition : routeDefinitions) {
        context.addRouteDefinition(routeDefinition);
    }

    assertEquals(2, context.getRoutes().size());

    assertTrue("Route should be started", context.getRouteStatus("route1").isStarted());

    getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
    template.sendBody("seda:get-say-hello-bar", "Hello World");
    assertMockEndpointsSatisfied();
}
项目:Camel    文件:FromRestOptionsTest.java   
public void testRestOptionsModel() throws Exception {

    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/hello", rest.getPath());
    assertEquals(1, rest.getVerbs().size());
    assertIsInstanceOf(OptionsVerbDefinition.class, rest.getVerbs().get(0));

    Exchange out = template.request("seda:options-say-hello", new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setBody("Me");
            }
        });
    assertMockEndpointsSatisfied();
    assertNotNull(out);
    assertEquals(out.getOut().getHeader("Allow"), ALLOWS);
}
项目:Camel    文件:FromRestUriPrefixTest.java   
public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());

    assertEquals(1, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/", rest.getPath());
    assertEquals(3, rest.getVerbs().size());
    assertEquals("/hello", rest.getVerbs().get(0).getUri());
    assertEquals("/bye", rest.getVerbs().get(1).getUri());
    assertEquals("/hi", rest.getVerbs().get(2).getUri());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:hello", to.getUri());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).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-hi", "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    文件:FromRestIdAndDescriptionTest.java   
public void testFromRestModel() throws Exception {
    super.testFromRestModel();

    RestDefinition rest = context.getRestDefinitions().get(0);
    assertEquals("hello", rest.getId());
    assertEquals("Hello Service", rest.getDescriptionText());

    assertEquals("get-say", rest.getVerbs().get(0).getId());
    assertEquals("Says hello to you", rest.getVerbs().get(0).getDescriptionText());

    RestDefinition rest2 = context.getRestDefinitions().get(1);
    assertEquals("bye", rest2.getId());
    assertEquals("Bye Service", rest2.getDescriptionText());
    assertEquals("en", rest2.getDescription().getLang());

    assertEquals("Says bye to you", rest2.getVerbs().get(0).getDescriptionText());
    assertEquals("Updates the bye message", rest2.getVerbs().get(1).getDescriptionText());
}
项目:Camel    文件:RestSwaggerReaderTest.java   
@Test
public void testReaderRead() throws Exception {
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);

    SwaggerConfig config = new SwaggerConfig();
    config.setBasePath("http://localhost:8080/api");
    RestSwaggerReader reader = new RestSwaggerReader();
    Option<ApiListing> option = reader.read(rest, config);
    assertNotNull(option);
    ApiListing listing = option.get();
    assertNotNull(listing);

    String json = JsonSerializer.asJson(listing);
    log.info(json);

    assertTrue(json.contains("\"basePath\":\"http://localhost:8080/api\""));
    assertTrue(json.contains("\"resourcePath\":\"/hello\""));
    assertTrue(json.contains("\"method\":\"GET\""));
    assertTrue(json.contains("\"nickname\":\"getHelloHi\""));

    context.stop();
}
项目:Camel    文件:DefaultCamelSwaggerServletTest.java   
@Test
public void testServlet() throws Exception {
    DefaultCamelSwaggerServlet servlet = new DefaultCamelSwaggerServlet();

    Buffer<RestDefinition> list = servlet.getRestDefinitions(null);
    assertEquals(1, list.size());
    RestDefinition rest = list.iterator().next();
    checkRestDefinition(rest);

    // get the RestDefinition by using the camel context id
    list = servlet.getRestDefinitions(context.getName());
    assertEquals(1, list.size());
    rest = list.iterator().next();
    checkRestDefinition(rest);

    RestDefinition rest2 = context.getRestDefinitions().get(0);
    checkRestDefinition(rest2);
}
项目:Camel    文件:FromRestIdAndDescriptionTest.java   
@Test
public void testFromRestModel() throws Exception {
    super.testFromRestModel();

    RestDefinition rest = context.getRestDefinitions().get(0);
    assertEquals("hello", rest.getId());
    assertEquals("Hello Service", rest.getDescriptionText());

    assertEquals("get-say", rest.getVerbs().get(0).getId());
    assertEquals("Says hello to you", rest.getVerbs().get(0).getDescriptionText());

    RestDefinition rest2 = context.getRestDefinitions().get(1);
    assertEquals("bye", rest2.getId());
    assertEquals("Bye Service", rest2.getDescriptionText());
    assertEquals("en", rest2.getDescription().getLang());

    assertEquals("Says bye to you", rest2.getVerbs().get(0).getDescriptionText());
    assertEquals("Updates the bye message", rest2.getVerbs().get(1).getDescriptionText());
}
项目:Camel    文件:XmlCdiBeanFactory.java   
private SyntheticBean<?> restContextBean(RestContextDefinition definition, URL url) {
    requireNonNull(definition.getId(),
        () -> format("Missing [%s] attribute for imported bean [%s] from resource [%s]",
            "id", "restContext", url));

    return new SyntheticBean<>(manager,
        new SyntheticAnnotated(List.class,
            Stream.of(List.class, new ListParameterizedType(RestDefinition.class))
                .collect(toSet()),
            ANY, NamedLiteral.of(definition.getId())),
        List.class,
        new SyntheticInjectionTarget<>(definition::getRests), bean ->
            "imported rest context with "
            + "id [" + definition.getId() + "] "
            + "from resource [" + url + "] "
            + "with qualifiers " + bean.getQualifiers());
}
项目:Camel    文件:RestSwaggerReader.java   
/**
 * Read the REST-DSL definition's and parse that as a Swagger model representation
 *
 * @param rests             the rest-dsl
 * @param route             optional route path to filter the rest-dsl to only include from the chose route
 * @param config            the swagger configuration
 * @param classResolver     class resolver to use
 * @return the swagger model
 */
public Swagger read(List<RestDefinition> rests, String route, BeanConfig config, String camelContextId, ClassResolver classResolver) {
    Swagger swagger = new Swagger();

    for (RestDefinition rest : rests) {

        if (ObjectHelper.isNotEmpty(route) && !route.equals("/")) {
            // filter by route
            if (!rest.getPath().equals(route)) {
                continue;
            }
        }

        parse(swagger, rest, camelContextId, classResolver);
    }

    // configure before returning
    swagger = config.configure(swagger);
    return swagger;
}
项目:camel-cdi    文件:XmlCdiBeanFactory.java   
private SyntheticBean<?> restContextBean(RestContextDefinition definition, URL url) {
    requireNonNull(definition.getId(),
        () -> format("Missing [%s] attribute for imported bean [%s] from resource [%s]",
            "id", "restContext", url));

    return new SyntheticBean<>(manager,
        new SyntheticAnnotated(List.class,
            Stream.of(List.class, new UnaryParameterizedType(List.class, RestDefinition.class))
                .collect(toSet()),
            ANY, NamedLiteral.of(definition.getId())),
        List.class,
        new SyntheticInjectionTarget<>(definition::getRests),
        bean -> "imported rest context with "
            + "id [" + definition.getId() + "] "
            + "from resource [" + url + "] "
            + "with qualifiers " + bean.getQualifiers());
}
项目:drinkwater-java    文件:RestHelper.java   
private static RestDefinition toRestdefinition(RouteBuilder builder,
                                               Method method,
                                               HttpMethod httpMethod,
                                               String restPath) {
    RestDefinition answer = builder.rest();

    String fromPath = restPath;

    if (httpMethod == HttpMethod.GET) {
        answer = answer.get(fromPath);
    } else if (httpMethod == HttpMethod.POST) {
        answer = answer.post(fromPath);
    } else if (httpMethod == HttpMethod.PUT) {
        answer = answer.put(fromPath);
    } else if (httpMethod == HttpMethod.DELETE) {
        answer = answer.delete(fromPath);
    } else if (httpMethod == HttpMethod.PATCH) {
        answer = answer.patch(fromPath);
    } else {
        throw new RuntimeException("method currently not supported in Rest Paths : " + httpMethod);
    }

    answer = setBodyType(answer, method);

    return answer;
}
项目:drinkwater-java    文件:RestHelper.java   
private static RestDefinition setBodyType(RestDefinition rd, Method method) {
    //This route necessary for the RestBindings of camel
    if (method.getParameters().length > 0) {

        Class type = method.getParameters()[0].getType();
        if (isMultipartBody(method)) {
            rd.bindingMode(RestBindingMode.off);
            rd.outType(method.getReturnType().getClass());
        }
        rd = rd.type(type);
    }
    return rd;
}
项目:drinkwater-java    文件:RestHelper.java   
private static RestDefinition setBodyType(RestDefinition rd, Method method) {
    //This route necessary for the RestBindings of camel
    if (method.getParameters().length > 0) {

        Class type = method.getParameters()[0].getType();
        if (isMultipartBody(method)) {
            rd.bindingMode(RestBindingMode.off);
            rd.outType(method.getReturnType().getClass());
        }
        rd = rd.type(type);
    }
    return rd;
}
项目:Camel    文件:ProcessorDefinition.java   
/**
 * Ends the current block and returns back to the {@link org.apache.camel.model.rest.RestDefinition rest()} DSL.
 *
 * @return the builder
 */
public RestDefinition endRest() {
    ProcessorDefinition<?> def = this;

    RouteDefinition route = ProcessorDefinitionHelper.getRoute(def);
    if (route != null) {
        return route.getRestDefinition();
    }

    throw new IllegalArgumentException("Cannot find RouteDefinition to allow endRest");
}
项目:Camel    文件:RestContextRefDefinitionHelper.java   
/**
 * Lookup the rests from the {@link org.apache.camel.model.RestContextRefDefinition}.
 * <p/>
 * This implementation must be used to lookup the rests as it performs a deep clone of the rests
 * as a {@link org.apache.camel.model.RestContextRefDefinition} can be re-used with multiple {@link org.apache.camel.model.ModelCamelContext} and each
 * context should have their own instances of the routes. This is to ensure no side-effects and sharing
 * of instances between the contexts. For example such as property placeholders may be context specific
 * so the routes should not use placeholders from another {@link org.apache.camel.model.ModelCamelContext}.
 *
 * @param camelContext the CamelContext
 * @param ref          the id of the {@link org.apache.camel.model.RestContextRefDefinition} to lookup and get the routes.
 * @return the rests.
 */
@SuppressWarnings("unchecked")
public static synchronized List<RestDefinition> lookupRests(ModelCamelContext camelContext, String ref) {
    ObjectHelper.notNull(camelContext, "camelContext");
    ObjectHelper.notNull(ref, "ref");

    List<RestDefinition> answer = CamelContextHelper.lookup(camelContext, ref, List.class);
    if (answer == null) {
        throw new IllegalArgumentException("Cannot find RestContext with id " + ref);
    }

    // must clone the rest definitions as they can be reused with multiple CamelContexts
    // and they would need their own instances of the definitions to not have side effects among
    // the CamelContext - for example property placeholder resolutions etc.
    List<RestDefinition> clones = new ArrayList<RestDefinition>(answer.size());
    try {
        JAXBContext jaxb = getOrCreateJAXBContext(camelContext);
        for (RestDefinition def : answer) {
            RestDefinition clone = cloneRestDefinition(jaxb, def);
            if (clone != null) {
                clones.add(clone);
            }
        }
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }

    return clones;
}
项目:Camel    文件:DefaultCamelContext.java   
public void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception {
    if (restDefinitions == null || restDefinitions.isEmpty()) {
        return;
    }

    this.restDefinitions.addAll(restDefinitions);
}
项目:Camel    文件:RouteBuilder.java   
/**
 * Creates a new REST service
 *
 * @return the builder
 */
public RestDefinition rest() {
    getRestCollection().setCamelContext(getContext());
    RestDefinition answer = getRestCollection().rest();
    configureRest(answer);
    return answer;
}
项目:Camel    文件:RouteBuilder.java   
/**
 * Creates a new REST service
 *
 * @param path  the base path
 * @return the builder
 */
public RestDefinition rest(String path) {
    getRestCollection().setCamelContext(getContext());
    RestDefinition answer = getRestCollection().rest(path);
    configureRest(answer);
    return answer;
}
项目:Camel    文件:XmlRestParseTest.java   
public void testParseSimpleRestXml() throws Exception {
    RestDefinition rest = assertOneRest("simpleRest.xml");
    assertEquals("/users", rest.getPath());

    assertEquals(1, rest.getVerbs().size());
    GetVerbDefinition get = (GetVerbDefinition) rest.getVerbs().get(0);
    assertEquals("/view/{id}", get.getUri());
    assertEquals("direct:getUser", get.getTo().getUri());
}
项目:Camel    文件:XmlRestParseToDTest.java   
public void testParseSimpleRestXml() throws Exception {
    RestDefinition rest = assertOneRest("simpleRestToD.xml");
    assertEquals("/users", rest.getPath());

    assertEquals(1, rest.getVerbs().size());
    GetVerbDefinition get = (GetVerbDefinition) rest.getVerbs().get(0);
    assertEquals("/view/{id}", get.getUri());
    assertEquals("bean:getUser?id=${header.id}", get.getToD().getUri());
}
项目:Camel    文件:LoadRestFromXmlTest.java   
public void testLoadRestFromXml() throws Exception {
    assertNotNull("Existing foo route should be there", context.getRoute("foo"));

    assertEquals(2, context.getRoutes().size());

    // test that existing route works
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedBodiesReceived("Hello World");
    template.sendBody("direct:foo", "Hello World");
    foo.assertIsSatisfied();

    // load rest from XML and add them to the existing camel context
    InputStream is = getClass().getResourceAsStream("barRest.xml");
    RestsDefinition rests = context.loadRestsDefinition(is);
    context.addRestDefinitions(rests.getRests());

    for (final RestDefinition restDefinition : rests.getRests()) {
        List<RouteDefinition> routeDefinitions = restDefinition.asRouteDefinition(context);
        context.addRouteDefinitions(routeDefinitions);
    }

    assertNotNull("Loaded rest route should be there", context.getRoute("route1"));
    assertEquals(3, context.getRoutes().size());

    // test that loaded route works
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedBodiesReceived("Bye World");
    template.sendBody("seda:get-say-hello-bar", "Bye World");
    bar.assertIsSatisfied();
}
项目:Camel    文件:FromRestApiTest.java   
public void testFromRestModel() throws Exception {
    assertEquals(1, 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("log:hello", to.getUri());

    // should be 2 routes
    assertEquals(2, context.getRoutes().size());
}
项目:Camel    文件:FromRestGetEndPathTest.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());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));
    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    文件:FromRestGetEmbeddedRouteTest.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).getRoute().getOutputs().get(1));
    assertEquals("mock: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());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));
    assertEquals("mock: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    文件:AbstractCamelContextFactoryBean.java   
protected void initRestRefs() throws Exception {
    // add rest refs to existing rests
    if (getRestRefs() != null) {
        for (RestContextRefDefinition ref : getRestRefs()) {
            List<RestDefinition> defs = ref.lookupRests(getContext());
            for (RestDefinition def : defs) {
                LOG.debug("Adding rest from {} -> {}", ref, def);
                // add in top as they are most likely to be common/shared
                // which you may want to start first
                getRests().add(0, def);
            }
        }
    }
}
项目:Camel    文件:DefaultCamelSwaggerServletTest.java   
private void checkRestDefinition(RestDefinition rest) {
    assertNotNull(rest);
    assertEquals("/hello", rest.getPath());
    assertEquals("/hi", rest.getVerbs().get(0).getUri());
    assertEquals("get", rest.getVerbs().get(0).asVerb());
    assertEquals("/bye", rest.getVerbs().get(1).getUri());
    assertEquals("get", rest.getVerbs().get(1).asVerb());
    assertEquals("/bye", rest.getVerbs().get(2).getUri());
    assertEquals("post", rest.getVerbs().get(2).asVerb());
}
项目:Camel    文件:FromRestUriPrefixTest.java   
@Test
public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());

    assertEquals(1, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/", rest.getPath());
    assertEquals(3, rest.getVerbs().size());
    assertEquals("/hello", rest.getVerbs().get(0).getUri());
    assertEquals("/bye", rest.getVerbs().get(1).getUri());
    assertEquals("/hi", rest.getVerbs().get(2).getUri());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:hello", to.getUri());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).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-hi", "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    文件:RestRefTest.java   
@Test
public void testRestRefTest() 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());
    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    文件:FromRestGetEmbeddedRouteTest.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).getRoute().getOutputs().get(1));
    assertEquals("mock: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());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));
    assertEquals("mock: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    文件:RestSwaggerReaderPropertyPlaceholderTest.java   
@Test
public void testReaderRead() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[]{"http"});
    config.setBasePath("/api");
    RestSwaggerReader reader = new RestSwaggerReader();

    RestSwaggerSupport support = new RestSwaggerSupport();
    List<RestDefinition> rests = support.getRestDefinitions(context.getName());

    Swagger swagger = reader.read(rests, null, config, context.getName(), new DefaultClassResolver());
    assertNotNull(swagger);

    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    String json = mapper.writeValueAsString(swagger);

    log.info(json);

    assertTrue(json.contains("\"host\" : \"localhost:8080\""));
    assertTrue(json.contains("\"basePath\" : \"/api\""));
    assertTrue(json.contains("\"/hello/bye\""));
    assertTrue(json.contains("\"summary\" : \"To update the greeting message\""));
    assertTrue(json.contains("\"/hello/bye/{name}\""));
    assertTrue(json.contains("\"/hello/hi/{name}\""));
    assertFalse(json.contains("{foo}"));
    assertFalse(json.contains("{bar}"));

    context.stop();
}
项目:Camel    文件:RestRefTest.java   
public void testRestRefTest() throws Exception {
    assertEquals(2 + 3, 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());
    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);
}
项目:drinkwater-java    文件:RestHelper.java   
public static Tuple2<RestDefinition, Method> buildRestRoute(RouteBuilder builder, Method method, ITracer tracer) {

        //builder.interceptFrom().setHeader(BeanOperationName).constant(method).to(ROUTE_serverReceivedEvent);

        HttpMethod httpMethod = httpMethodFor(method);

        String restPath = restPathFor(method);

        RestDefinition restDefinition =
                toRestdefinition(builder, method, httpMethod, restPath);

        //restDefinition.enableCORS(true);

        return Tuple.of(restDefinition, method);

    }
项目:drinkwater-java    文件:RestHelper.java   
private static ProcessorDefinition routeToBeanMethod(
        RestDefinition restDefinition,
        Object bean,
        Method method,
        IDrinkWaterService iDrinkWaterService) {
    String camelMethod = camelMethodBuilder(method);

    ProcessorDefinition routeDefinition =
            addServerReceivedTracing(iDrinkWaterService, restDefinition.route(), method);

    if(iDrinkWaterService.safeLookupProperty(Boolean.class,
            DrinkWaterPropertyConstants.Authenticate_Enabled,
            true)){
        routeDefinition.process(new SecurityProcessor());
    }

    routeDefinition.onException(UnauthorizedException.class)
            .handled(true)
            .setHeader("WWW-Authenticate").constant("TOKEN")
            .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(401))
            .setBody().constant("Unauthorized");

    routeDefinition.setHeader("Access-Control-Allow-Headers", constant("*"));
    routeDefinition.setHeader("Access-Control-Allow-Origin", constant("*"));

    addExceptionTracing(iDrinkWaterService, Exception.class, routeDefinition);


    //TODO create own process
    if (isMultipartBody(method)) {
        routeDefinition.process(new FileUploadProcessor());
    }

    routeDefinition = routeDefinition.bean(bean, camelMethod);
    //if binding is off and returns an object, then serialize as json
    if (isMultipartBody(method) && hasObjectReturnType(method)) {
        routeDefinition.process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                CustomJacksonObjectMapper mapper = new CustomJacksonObjectMapper();
                String s = mapper.writeValueAsString(exchange.getIn().getBody());
                exchange.getIn().setBody(s);
            }
        });
    }

    return addServerSentTracing(iDrinkWaterService, routeDefinition);
}
项目:drinkwater-java    文件:RestHelper.java   
public static Tuple2<RestDefinition, Method> buildRestRoute(RouteBuilder builder, Method method, ITracer tracer) {

        //builder.interceptFrom().setHeader(BeanOperationName).constant(method).to(ROUTE_serverReceivedEvent);

        HttpMethod httpMethod = httpMethodFor(method);

        String restPath = restPathFor(method);

        RestDefinition restDefinition =
                toRestdefinition(builder, method, httpMethod, restPath);

        //restDefinition.enableCORS(true);

        return Tuple.of(restDefinition, method);

    }
项目:drinkwater-java    文件:RestHelper.java   
private static ProcessorDefinition routeToBeanMethod(
        RestDefinition restDefinition,
        Object bean,
        Method method,
        IDrinkWaterService iDrinkWaterService) {
    String camelMethod = camelMethodBuilder(method);

    ProcessorDefinition routeDefinition =
            addServerReceivedTracing(iDrinkWaterService, restDefinition.route(), method);

    if(iDrinkWaterService.safeLookupProperty(Boolean.class,
            DrinkWaterPropertyConstants.Authenticate_Enabled,
            true)){
        routeDefinition.process(new SecurityProcessor());
    }

    routeDefinition.onException(UnauthorizedException.class)
            .handled(true)
            .setHeader("WWW-Authenticate").constant("TOKEN")
            .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(401))
            .setBody().constant("Unauthorized");

    routeDefinition.setHeader("Access-Control-Allow-Headers", constant("*"));
    routeDefinition.setHeader("Access-Control-Allow-Origin", constant("*"));

    addExceptionTracing(iDrinkWaterService, Exception.class, routeDefinition);


    //TODO create own process
    if (isMultipartBody(method)) {
        routeDefinition.process(new FileUploadProcessor());
    }

    routeDefinition = routeDefinition.bean(bean, camelMethod);
    //if binding is off and returns an object, then serialize as json
    if (isMultipartBody(method) && hasObjectReturnType(method)) {
        routeDefinition.process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                CustomJacksonObjectMapper mapper = new CustomJacksonObjectMapper();
                String s = mapper.writeValueAsString(exchange.getIn().getBody());
                exchange.getIn().setBody(s);
            }
        });
    }

    return addServerSentTracing(iDrinkWaterService, routeDefinition);
}
项目:Camel    文件:RouteDefinition.java   
public RestDefinition getRestDefinition() {
    return restDefinition;
}
项目:Camel    文件:RouteDefinition.java   
@XmlTransient
public void setRestDefinition(RestDefinition restDefinition) {
    this.restDefinition = restDefinition;
}
项目:Camel    文件:RestContextRefDefinition.java   
public List<RestDefinition> lookupRests(ModelCamelContext camelContext) {
    return RestContextRefDefinitionHelper.lookupRests(camelContext, ref);
}