CamelExchangeBus implements ExchangeBus { @Override public void init(ServiceDomain domain) { if (_logger.isDebugEnabled()) { _logger.debug("Initialization of CamelExchangeBus for domain " + domain.getName()); } SimpleRegistry registry = _camelContext.getWritebleRegistry(); for (Processors processor : Processors.values()) { registry.put(processor.name(), processor.create(domain)); } _camelContext.setApplicationContextClassLoader(Thread.currentThread().getContextClassLoader()); } CamelExchangeBus(SwitchYardCamelContext context); @Override void init(ServiceDomain domain); @Override synchronized void start(); @Override synchronized void stop(); @Override Dispatcher getDispatcher(ServiceReference reference); @Override ExchangeDispatcher createDispatcher(final ServiceReference reference);  }
@Test public void testBeforeProviderErrorInOut() { ErrorInterceptor interceptor = new ErrorInterceptor(false, ExchangeInterceptor.PROVIDER); _camelContext.getWritebleRegistry().put("interceptor", interceptor); _provider.init(_domain); ServiceReference ref = registerInOutService("inOut"); Exchange exchange = sendMessage(ref, TEST_CONTENT); assertNoCause("Error before on target Provider", exchange); Assert.assertEquals(2, interceptor.getCount()); }
@Test public void testAfterProviderErrorInOut() { ErrorInterceptor interceptor = new ErrorInterceptor(true, ExchangeInterceptor.PROVIDER); _camelContext.getWritebleRegistry().put("interceptor", interceptor); _provider.init(_domain); ServiceReference ref = registerInOutService("inOut"); Exchange exchange = sendMessage(ref, TEST_CONTENT); assertNoCause("Error after on target Provider", exchange); Assert.assertEquals(2, interceptor.getCount()); }
@Test public void testBeforeProviderErrorInOnly() { ErrorInterceptor interceptor = new ErrorInterceptor(false, ExchangeInterceptor.PROVIDER); _camelContext.getWritebleRegistry().put("interceptor", interceptor); _provider.init(_domain); ServiceReference ref = registerInOnlyService("inOnly", new MockHandler()); Exchange exchange = sendMessage(ref, TEST_CONTENT); assertNoCause("Error before on target Provider", exchange); Assert.assertEquals(2, interceptor.getCount()); }
@Test public void testAfterProviderErrorInOnly() { ErrorInterceptor interceptor = new ErrorInterceptor(true, ExchangeInterceptor.PROVIDER); _camelContext.getWritebleRegistry().put("interceptor", interceptor); _provider.init(_domain); ServiceReference ref = registerInOnlyService("inOnly", new MockHandler()); Exchange exchange = sendMessage(ref, TEST_CONTENT); assertNoCause("Error after on target Provider", exchange); Assert.assertEquals(2, interceptor.getCount()); }
@Test public void testInRuntimeFault() { RuntimeErrorInterceptor interceptor = new RuntimeErrorInterceptor( false, ExchangeInterceptor.PROVIDER); _camelContext.getWritebleRegistry().put("interceptor", interceptor); _provider.init(_domain); ServiceReference ref = registerInOutService("inOut"); Exchange exchange = sendMessage(ref, TEST_CONTENT); assertCause("RuntimeException before on target Provider", exchange); Assert.assertEquals(2, interceptor.getCount()); }
@Test public void testOutRuntimeFault() { RuntimeErrorInterceptor interceptor = new RuntimeErrorInterceptor( true, ExchangeInterceptor.PROVIDER); _camelContext.getWritebleRegistry().put("interceptor", interceptor); _provider.init(_domain); ServiceReference ref = registerInOutService("inOut"); Exchange exchange = sendMessage(ref, TEST_CONTENT); assertCause("RuntimeException after on target Provider", exchange); Assert.assertEquals(2, interceptor.getCount()); }
@Test public void testFaultFault() { ErrorInterceptor beforeFault = new ErrorInterceptor(false, ExchangeInterceptor.PROVIDER); ErrorInterceptor afterFault = new ErrorInterceptor(true, ExchangeInterceptor.PROVIDER); _camelContext.getWritebleRegistry().put("beforeFault", beforeFault); _camelContext.getWritebleRegistry().put("afterFault", afterFault); _provider.init(_domain); ServiceReference ref = registerInOutService("inOut"); Exchange exchange = sendMessage(ref, TEST_CONTENT); assertNoCause("Error before on target Provider", exchange); Assert.assertEquals(2, beforeFault.getCount()); Assert.assertEquals(2, afterFault.getCount()); }
@Test public void testContentTypes() throws Exception { TypeInterceptor types = new TypeInterceptor(); _camelContext.getWritebleRegistry().put("types", types); _provider.init(_domain); QName inType = new QName("urn:foo", "in"); QName outType = new QName("urn:bar", "out"); ExchangeHandler handler = new BaseHandler() { @Override public void handleMessage(Exchange exchange) throws HandlerException { exchange.send(exchange.getMessage().copy()); } }; ServiceReference ref = registerInOutServiceWithTypes("typesTest", inType, outType, handler); sendMessage(ref, TEST_CONTENT); Assert.assertEquals(inType, types.getInType()); Assert.assertEquals(outType, types.getOutType()); }