@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); }
@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); }
@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); }
@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()); }
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(); }
@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); }
@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 ")); } }; }
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); }
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); }
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(); }
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); }
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); }
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(); }
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(); }
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; }
@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); }
@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()); } }
@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")); } }
@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); }
@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); }
@Bean public FactService factServiceProxy() throws Exception { return new ProxyBuilder(camel).binding(false).endpoint("direct:" + LumenChannel.PERSISTENCE_FACT.key()).build(FactService.class); }