public void setUp() throws Exception { JndiRegistry registry = new JndiRegistry(new JndiContext()); RouteBuilder builder = createRouteBuilder(); CamelContext context = new DefaultCamelContext(registry); testConverter = new TestConverter(); testTransformerFactory = TransformerFactory.newInstance(); registry.bind("testConverter", testConverter); registry.bind("testTransformerFactory", testTransformerFactory); ProcessorEndpoint pep1 = context.getEndpoint(TEST_URI_1, ProcessorEndpoint.class); context.addRoutes(builder); context.start(); builder1 = (XsltBuilder)pep1.getProcessor(); }
public void testCamelWithJndi() throws Exception { JndiContext jndi = new JndiContext(); jndi.bind("foo", new MyOtherDummyBean()); CamelContext camel = new DefaultCamelContext(jndi); camel.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").bean("foo"); } }); camel.start(); String reply = camel.createProducerTemplate().requestBody("direct:start", "Camel", String.class); assertEquals("Hello Camel", reply); camel.stop(); }
/** configures camel-drools integration and defines 3 routes: * 1) testing route (connection to drools with JSON command format) * 2) unmarshalling route (for unmarshalling command results) * 3) marshalling route (enables creating commands through API and converting to JSON) */ private CamelContext configure(KieSession session) throws Exception { Context context = new JndiContext(); context.bind("ksession", session); CamelContext camelContext = new DefaultCamelContext(context); camelContext.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:test-session").policy(new KiePolicy()).unmarshal("json").to("kie://ksession").marshal("json"); from("direct:unmarshall").policy(new KiePolicy()).unmarshal("json"); from("direct:marshall").policy(new KiePolicy()).marshal("json"); } }); return camelContext; }
/** configures camel-drools integration and defines 3 routes: * 1) testing route (connection to drools with JAXB command format) * 2) unmarshalling route (for unmarshalling command results) * 3) marshalling route (enables creating commands through API and converting to XML) */ private CamelContext configure(StatefulKnowledgeSession session) throws Exception { Context context = new JndiContext(); context.bind("ksession", session); CamelContext camelContext = new DefaultCamelContext(context); camelContext.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { JaxbDataFormat jdf = new JaxbDataFormat(); jdf.setContextPath("org.kie.camel.testdomain"); jdf.setPrettyPrint(true); from("direct:test-session").policy(new KiePolicy()).unmarshal(jdf).to("kie://ksession").marshal(jdf); from("direct:unmarshall").policy(new KiePolicy()).unmarshal(jdf); from("direct:marshall").policy(new KiePolicy()).marshal(jdf); } }); return camelContext; }
@Test public void testPojoRoutes() throws Exception { JndiContext jndctx = new JndiContext(); jndctx.bind("bye", new SayService("Good Bye!")); CamelContext camelContext = new DefaultCamelContext(jndctx); camelContext.addRoutes(createRouteBuilder(camelContext)); camelContext.start(); try { Endpoint endpoint = camelContext.getEndpoint("direct:hello"); ISay proxy = ProxyHelper.createProxy(endpoint, false, ISay.class); String rc = proxy.say(); Assert.assertEquals("Good Bye!", rc); } finally { camelContext.stop(); } }
public MockJndiContextFactoryRule() { try { this.context = new JndiContext(); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Application entry point * @param args application arguments * @throws Exception */ public static void main(String... args) throws Exception { JndiRegistry reg = new JndiRegistry(new JndiContext()); reg.bind("sslContextParameters",sslParameters()); CamelContext ctx = new DefaultCamelContext(reg); ctx.addRoutes(new WebsocketRouteNoSSL()); ctx.setUseMDCLogging(true); ctx.setTracing(true); ctx.start(); }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind("myBean", new MyBean()); answer.bind("myStrategy", new MyAggregationStrategy()); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind("myBean", myBean); answer.bind("myOtherBean", myOtherBean); return answer; }
protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind("foo", new FooBean()); answer.bind("bar", new BarBean()); answer.bind("baz", new BazBean()); return answer; }
protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind("one", new MyBean("one")); answer.bind("two", new MyBean("two")); answer.bind("three", new MyBean("three")); return answer; }
protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind("b", new B()); answer.bind("p", Proxy.newProxyInstance(I1.class.getClassLoader(), new Class[]{I1.class}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("m1")) { return args[0].toString() + args[1].toString(); } else { return null; } } })); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); // add ActiveMQ with embedded broker ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); JmsComponent amq = jmsComponentAutoAcknowledge(connectionFactory); amq.setCamelContext(context); answer.bind("jms", amq); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); // add ActiveMQ with embedded broker ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); JmsComponent amq = jmsComponentAutoAcknowledge(connectionFactory); amq.setCamelContext(context); answer.bind("activemq", amq); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind("myBean", myBean); // add ActiveMQ with embedded broker ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); JmsComponent amq = jmsComponentAutoAcknowledge(connectionFactory); amq.setCamelContext(context); answer.bind("jms", amq); return answer; }
@Override protected Context createJndiContext() throws Exception { deleteDirectory("activemq-data"); JndiContext answer = new JndiContext(); // add ActiveMQ with embedded broker which must be persistent ConnectionFactory connectionFactory = CamelJmsTestHelper.createPersistentConnectionFactory(); JmsComponent amq = jmsComponentAutoAcknowledge(connectionFactory); amq.setCamelContext(context); answer.bind("jms", amq); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); // add ActiveMQ with embedded broker ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); JmsComponent amq = jmsComponentAutoAcknowledge(connectionFactory); amq.setCamelContext(context); answer.bind("activemq", amq); answer.bind("myBean1", b1); answer.bind("myBean2", b2); answer.bind("myBean3", b3); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind("myBean", new MyBean()); // add AMQ client and make use of connection pooling we depend on because of the (large) number // of the JMS messages we do produce // add ActiveMQ with embedded broker ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); JmsComponent amq = jmsComponentAutoAcknowledge(connectionFactory); amq.setCamelContext(context); answer.bind("activemq", amq); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); // add ActiveMQ with embedded broker ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); JmsComponent amq = jmsComponentAutoAcknowledge(connectionFactory); amq.setCamelContext(context); answer.bind("jms", amq); answer.bind("myBean", new MyBean()); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext jndi = new JndiContext(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); jndi.bind("myDate", df.parse("2007-11-13 14:35:00 +0100")); return jndi; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); // timestamp from the feed to use as base // Fri, 31 Oct 2008 12:02:21 -0500 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT-5:00")); cal.set(2008, Calendar.OCTOBER, 31, 12, 02, 21); answer.bind("myBean", new MyBean(cal.getTime())); return answer; }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); IoFilter myFilter = new TestFilter(); List<IoFilter> myFilters = new ArrayList<IoFilter>(); myFilters.add(myFilter); answer.bind("myFilters", myFilters); answer.bind("myFilter", myFilter); return answer; }
@Test public void testPojoRoutes() throws Exception { if (classPathHasSpaces()) { return; } // Boot up a local RMI registry LocateRegistry.createRegistry(getPort()); // START SNIPPET: register JndiContext context = new JndiContext(); context.bind("bye", new SayService("Good Bye!")); CamelContext camelContext = new DefaultCamelContext(context); // END SNIPPET: register camelContext.addRoutes(getRouteBuilder(camelContext)); camelContext.start(); // START SNIPPET: invoke Endpoint endpoint = camelContext.getEndpoint("direct:hello"); ISay proxy = ProxyHelper.createProxy(endpoint, false, ISay.class); String rc = proxy.say(); assertEquals("Good Bye!", rc); // END SNIPPET: invoke camelContext.stop(); }
/** * Camel简单入门 * @throws Exception */ @Test public void testCamelForBean() throws Exception { JndiContext context = new JndiContext(); CamelLeaveBean leave = new CamelLeaveBean(); context.bind("leave", leave); CamelContext camelContext = new DefaultCamelContext(context); camelContext.addRoutes(new CamelLeaveRoute()); camelContext.start(); ProducerTemplate tpl = camelContext.createProducerTemplate(); // true tpl.sendBody("direct:start", Collections.singletonMap("days", 2)); assertFalse(leave.getResult()); // false tpl.sendBody("direct:start", Collections.singletonMap("days", 5)); assertTrue(leave.getResult()); // Set<LeaveBean> byType = camelContext.getRegistry().findByType(LeaveBean.class); // System.out.println("aa=" + ((LeaveBean)byType.iterator().next()).getResult()); /*tpl.sendBody("direct:forProperty", Collections.singletonMap("days", 2)); String result = System.getProperty("ok"); assertEquals("false", result); tpl.sendBody("direct:forProperty", Collections.singletonMap("days", 5)); result = System.getProperty("ok"); assertEquals("true", result);*/ camelContext.stop(); }
@Override protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind("addTime", new TimerBean()); return answer; }