Java 类org.apache.camel.builder.ProxyBuilder 实例源码

项目:incubator-tamaya-sandbox    文件:TamayaPropertyResolverTest.java   
@Test
public void testJavaDSLWithCfgResolution() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();
    camelContext.addComponent("properties", new TamayaPropertiesComponent());
    RouteBuilder builder = new RouteBuilder() {
        public void configure() {
            from("direct:hello").transform().simple("{{cfg:message}}");
        }
    };
    camelContext.addRoutes(builder);
    camelContext.start();
    // test configuration is injected right...
    Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class);
    String greetMessage = proxy.greet();
    assertEquals("Good Bye from Apache Tamaya!", greetMessage);
}
项目:incubator-tamaya-sandbox    文件:TamayaPropertyResolverTest.java   
@Test
public void testJavaDSLWithTamayaResolution() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();
    camelContext.addComponent("properties", new TamayaPropertiesComponent());
    RouteBuilder builder = new RouteBuilder() {
        public void configure() {
            from("direct:hello").transform().simple("{{tamaya:message}}");
        }
    };
    camelContext.addRoutes(builder);
    camelContext.start();
    // test configuration is injected right...
    Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class);
    String greetMessage = proxy.greet();
    assertEquals("Good Bye from Apache Tamaya!", greetMessage);
}
项目:incubator-tamaya-sandbox    文件:TamayaPropertyResolverTest.java   
@Test
public void testJavaDSLWithOverrideActive() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();
    TamayaPropertiesComponent props = new TamayaPropertiesComponent();
    props.setTamayaOverrides(true);
    camelContext.addComponent("properties", props);
    RouteBuilder builder = new RouteBuilder() {
        public void configure() {
            from("direct:hello").transform().simple("{{message}}");
        }
    };
    camelContext.addRoutes(builder);
    camelContext.start();
    // test configuration is injected right...
    Greeter proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(Greeter.class);
    String greetMessage = proxy.greet();
    assertEquals("Good Bye from Apache Tamaya!", greetMessage);
}
项目:incubator-tamaya-sandbox    文件:TamayaPropertyResolverTest.java   
@Test
public void testXmlDSL() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();
    // This is normally done by the Spring implemented registry, we keep it simple here...
    TamayaPropertiesComponent props = new TamayaPropertiesComponent();
    props.setTamayaOverrides(true);
    camelContext.addComponent("properties", props);
    // Read routes from XML DSL
    InputStream is = getClass().getResourceAsStream("/META-INF/routes.xml");
    RoutesDefinition routes = camelContext.loadRoutesDefinition(is);
    for(RouteDefinition def: routes.getRoutes()) {
        camelContext.addRouteDefinition(def);
    }
    camelContext.start();
    Greeter greeter = new ProxyBuilder(camelContext).endpoint("direct:hello1").build(Greeter.class);
    assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
    greeter = new ProxyBuilder(camelContext).endpoint("direct:hello2").build(Greeter.class);
    assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
    greeter = new ProxyBuilder(camelContext).endpoint("direct:hello3").build(Greeter.class);
    assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
}
项目:Camel    文件:PojoRouteTest.java   
public void testPojoRoutes() throws Exception {
    CamelContext camelContext = new DefaultCamelContext();

    // START SNIPPET: route
    // lets add simple route
    camelContext.addRoutes(new RouteBuilder() {
        public void configure() {
            from("direct:hello").transform().constant("Good Bye!");
        }
    });
    // END SNIPPET: route

    camelContext.start();

    // START SNIPPET: invoke
    ISay proxy = new ProxyBuilder(camelContext).endpoint("direct:hello").build(ISay.class);
    String rc = proxy.say();
    assertEquals("Good Bye!", rc);
    // END SNIPPET: invoke

    camelContext.stop();
}
项目:openex-worker    文件:WorkerRest.java   
@POST
@Path("worker/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Object executeWorker(@PathParam("id") String id, String jsonRequest) throws Exception {
    DefaultCamelContext context = openexContext.getContext();
    AuditWorker auditWorker = new ProxyBuilder(context).endpoint("direct:remote")
            .build(AuditWorker.class);
    Map jsonToCamelMap = gson.fromJson(jsonRequest, Map.class);
    jsonToCamelMap.put("route-id", id);
    return auditWorker.auditMessage(jsonToCamelMap);
}
项目:Camel    文件:CamelProduceInterfaceTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // we gotta cheat and use proxy builder as ContextTestSupport doesnt do
            // all the IoC wiring we need when using @Produce on an interface
            echo = new ProxyBuilder(context).endpoint("direct:hello").build(Echo.class);

            from("direct:hello").transform(body().prepend("Hello "));
        }
    };
}
项目:Camel    文件:BeanProxyNoBindingTest.java   
public void testProxyBuilderProxyCallAnotherBean() throws Exception {
    // use ProxyBuilder to easily create the proxy
    OrderService service = new ProxyBuilder(context).endpoint("direct:bean").binding(false).build(OrderService.class);

    String reply = service.submitOrderStringReturnString("World");
    assertEquals("Hello World", reply);
}
项目:Camel    文件:BeanProxyNoBindingTest.java   
public void testProxyBuilderProxyCallAnotherBeanWithNoArgs() throws Exception {
    Endpoint endpoint = context.getEndpoint("direct:bean");
    OrderService service = new ProxyBuilder(context).endpoint(endpoint).binding(false).build(OrderService.class);

    String reply = service.doAbsolutelyNothing();
    assertEquals("Hi nobody", reply);
}
项目:Camel    文件:BeanProxyNoBindingTest.java   
public void testProxyBuilderVoidAsInOut() throws Exception {
    // will by default let all exchanges be InOut
    OrderService service = new ProxyBuilder(context).endpoint("seda:delay").binding(false).build(OrderService.class);

    getMockEndpoint("mock:delay").expectedBodiesReceived("Hello World", "Bye World");
    service.doNothing("Hello World");
    template.sendBody("mock:delay", "Bye World");

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:BeanProxyTest.java   
public void testProxyBuilderProxyCallAnotherBean() throws Exception {
    // use ProxyBuilder to easily create the proxy
    OrderService service = new ProxyBuilder(context).endpoint("direct:bean").build(OrderService.class);

    String reply = service.submitOrderStringReturnString("World");
    assertEquals("Hello World", reply);
}
项目:Camel    文件:BeanProxyTest.java   
public void testProxyBuilderProxyCallAnotherBeanWithNoArgs() throws Exception {
    Endpoint endpoint = context.getEndpoint("direct:bean");
    OrderService service = new ProxyBuilder(context).endpoint(endpoint).build(OrderService.class);

    String reply = service.doAbsolutelyNothing();
    assertEquals("Hi nobody", reply);
}
项目:Camel    文件:BeanProxyTest.java   
public void testProxyBuilderVoidAsInOut() throws Exception {
    // will by default let all exchanges be InOut
    OrderService service = new ProxyBuilder(context).endpoint("seda:delay").build(OrderService.class);

    getMockEndpoint("mock:delay").expectedBodiesReceived("Hello World", "Bye World");
    service.doNothing("Hello World");
    template.sendBody("mock:delay", "Bye World");

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:MyAuditServiceProxyTest.java   
public void testMyAuditServiceProxy() throws Exception {
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:result").expectedHeaderReceived("uuid", "1234");

    // must enable binding on proxy
    MyAuditService service = new ProxyBuilder(context).endpoint("direct:proxy").binding(true).build(MyAuditService.class);

    service.auditMessage("1234", "Hello World");

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:JmsProxyTest.java   
protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();

    ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory();
    camelContext.addComponent(componentName, jmsComponentAutoAcknowledge(connectionFactory));

    // create proxy
    calculatorProxy = new ProxyBuilder(camelContext).binding(false).endpoint("direct:calculatorProxy").build(Calculator.class);

    return camelContext;
}
项目:Camel    文件:JmsProxyMEPTest.java   
protected CamelContext createCamelContext() throws Exception {
    CamelContext camelContext = super.createCamelContext();

    ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory();
    camelContext.addComponent(componentName, jmsComponentAutoAcknowledge(connectionFactory));

    // create proxy
    calculatorProxy = new ProxyBuilder(camelContext).binding(false).endpoint("direct:calculatorProxy").build(Calculator.class);

    return camelContext;
}
项目:Camel    文件:HttpClientProxyTransferExceptionTest.java   
@Test
public void testHttpClientProxyOk() throws Exception {
    MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
    String out = proxy.hello("World");

    assertEquals("Hello World", out);
}
项目:Camel    文件:HttpClientProxyTransferExceptionTest.java   
@Test
public void testHttpClientProxyException() throws Exception {
    MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
    try {
        proxy.hello("Kaboom");
        fail("Should have thrown exception");
    } catch (MyAppException e) {
        assertEquals("Kaboom", e.getName());
    }
}
项目:Camel    文件:HttpClientProxyTest.java   
@Test
public void testHttpClientProxyOk() throws Exception {
    MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
    String out = proxy.hello("World");

    assertEquals("Hello World", out);
}
项目:Camel    文件:HttpClientProxyTest.java   
@Test
public void testHttpClientProxyException() throws Exception {
    MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
    try {
        proxy.hello("Kaboom");
        fail("Should have thrown exception");
    } catch (UndeclaredThrowableException e) {
        HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
        assertEquals(500, cause.getStatusCode());
        assertNotNull(cause.getResponseBody());
        assertTrue(cause.getResponseBody().contains("MyAppException"));
    }
}
项目:camelinaction    文件:StarterKitJavaProxyBuilderTest.java   
@Test
public void testProxyBuilder() throws Exception {
    // create the proxy with the help of ProxyBuilder
    RiderService rider = new ProxyBuilder(context).endpoint("seda:rider").build(RiderService.class);

    Inventory inventory = new Inventory("1234", "4444");
    inventory.setName("Bumper");
    inventory.setAmount("57");

    log.info("Sending inventory");
    rider.updateInventory(inventory);
}
项目:t4f-data    文件:StarterKitJavaProxyBuilderTest.java   
@Test
public void testProxyBuilder() throws Exception {
    // create the proxy with the help of ProxyBuilder
    RiderService rider = new ProxyBuilder(context).endpoint("seda:rider").build(RiderService.class);

    Inventory inventory = new Inventory("1234", "4444");
    inventory.setName("Bumper");
    inventory.setAmount("57");

    LOG.info("Sending inventory");
    rider.updateInventory(inventory);
}
项目:lumen    文件:ServicesRouter.java   
@Bean
public FactService factServiceProxy() throws Exception {
    return new ProxyBuilder(camel).binding(false).endpoint("direct:" + LumenChannel.PERSISTENCE_FACT.key()).build(FactService.class);
}