org.apache.camel.impl.DefaultCamelContext Java Examples
The following examples show how to use
org.apache.camel.impl.DefaultCamelContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OnExceptionHandlerTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testErrorStatusInfoResponse() { String expectedBody = "{\"httpResponseCode\":404,\"category\":\"ENTITY_NOT_FOUND_ERROR\",\"message\":\"entity not found\",\"error\":\"syndesis_connector_error\"}"; Map<String,String> configuredProperties = new HashMap<>(); configuredProperties.put(HTTP_RESPONSE_CODE_PROPERTY , "200"); configuredProperties.put(HTTP_ERROR_RESPONSE_CODES_PROPERTY, ERROR_RESPONSE_CODES); configuredProperties.put(ERROR_RESPONSE_BODY , "true"); Exception e = new SyndesisConnectorException( "ENTITY_NOT_FOUND_ERROR", "entity not found"); Exchange exchange = new ExchangeBuilder(new DefaultCamelContext()).build(); exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e); ApiProviderOnExceptionHandler handler = new ApiProviderOnExceptionHandler(); handler.setProperties(configuredProperties); handler.process(exchange); Message in = exchange.getIn(); Assert.assertEquals(Integer.valueOf(404),in.getHeader(Exchange.HTTP_RESPONSE_CODE)); Assert.assertEquals(expectedBody ,in.getBody()); }
Example #2
Source File: QuartzExample.java From camelinaction with Apache License 2.0 | 6 votes |
public static void main(String args[]) throws Exception { // create CamelContext CamelContext context = new DefaultCamelContext(); // add our route to the CamelContext context.addRoutes(new RouteBuilder() { public void configure() { from("quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1") .setBody().simple("I was fired at ${header.fireTime}") .to("stream:out"); } }); // start the route and let it do its work context.start(); Thread.sleep(10000); // stop the CamelContext context.stop(); }
Example #3
Source File: PropertiesFunctionsConfigurerTest.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@Test public void testKubernetesFunction() { Runtime runtime = Runtime.on(new DefaultCamelContext()); runtime.setProperties("my.property", "{{secret:my-secret/my-property}}"); new PropertiesConfigurer().accept(runtime); assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:my-secret/my-property}}")) .isEqualTo("my-secret-property"); assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:none/my-property:my-default-secret}}")) .isEqualTo("my-default-secret"); assertThatThrownBy(() -> runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:none/my-property}}")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("returned null value which is not allowed, from input"); assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:my-cm/my-property}}")).isEqualTo("my-cm-property"); assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:my-cm/my-property:my-default-cm}}")) .isEqualTo("my-default-cm"); assertThatThrownBy(() -> runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:none/my-property}}")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("returned null value which is not allowed, from input"); assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{my.property}}")).isEqualTo("my-secret-property"); }
Example #4
Source File: HttpServer.java From camelinaction with Apache License 2.0 | 6 votes |
public void server() throws Exception { CamelContext camel = new DefaultCamelContext(); camel.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("jetty:" + url) .process(new Processor() { public void process(Exchange exchange) throws Exception { String body = exchange.getIn().getBody(String.class); System.out.println("Received message: " + body); if (body != null && body.contains("Kabom")) { throw new Exception("ILLEGAL DATA"); } exchange.getOut().setBody("OK"); } }); } }); camel.start(); }
Example #5
Source File: TimerExample.java From camelinaction with Apache License 2.0 | 6 votes |
public static void main(String args[]) throws Exception { // create CamelContext CamelContext context = new DefaultCamelContext(); // add our route to the CamelContext context.addRoutes(new RouteBuilder() { public void configure() { from("timer://myTimer?period=2000") .setBody().simple("Current time is ${header.firedTime}") .to("stream:out"); } }); // start the route and let it do its work context.start(); Thread.sleep(5000); // stop the CamelContext context.stop(); }
Example #6
Source File: SwaggerProxyComponentTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testSwaggerProxyComponent() throws Exception { CamelContext context = new DefaultCamelContext(); ComponentProxyFactory factory = new ConnectorFactory(); ComponentProxyComponent proxy = factory.newInstance("swagger-1", "rest-openapi"); try { proxy.setCamelContext(context); proxy.start(); Endpoint endpoint = proxy.createEndpoint("swagger-1:http://foo.bar"); assertThat(endpoint).isInstanceOfSatisfying(DelegateEndpoint.class, e -> { assertThat(e.getEndpoint()).isInstanceOf(RestOpenApiEndpoint.class); assertThat(e.getEndpoint()).hasFieldOrPropertyWithValue("componentName", SyndesisRestSwaggerComponent.COMPONENT_NAME); }); } finally { proxy.stop(); } }
Example #7
Source File: DirectVmTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Before public void setupContexts() throws Exception { testHarnessContext = new DefaultCamelContext(); testHarnessContext.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:in") .setHeader("harness.threadName", simple("${threadName}")) .to("direct-vm:logMessageToBackendSystem") .log("Completed logging"); } }); testHarnessContext.start(); externalLoggingContext = new DefaultCamelContext(); externalLoggingContext.addRoutes(new ExternalLoggingRoute("direct-vm")); externalLoggingContext.start(); }
Example #8
Source File: NettyIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testNettyTcpSocket() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("netty:tcp://" + SOCKET_HOST + ":" + SOCKET_PORT + "?textline=true") .transform(simple("Hello ${body}")) .inOnly("seda:end"); } }); camelctx.start(); try { PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); Socket socket = new Socket(SOCKET_HOST, SOCKET_PORT); socket.setKeepAlive(true); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); try { out.write("Kermit\n"); } finally { out.close(); socket.close(); } String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example #9
Source File: CassandraIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testConsumeAll() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("cql://localhost/camel_ks?cql=" + CQL).to("seda:end"); } }); camelctx.start(); try { ConsumerTemplate consumer = camelctx.createConsumerTemplate(); List<?> result = consumer.receiveBody("seda:end", 3000, List.class); Assert.assertNotNull("Result not null", result); Assert.assertEquals("Two records selected", 2, result.size()); } finally { camelctx.close(); } }
Example #10
Source File: TenantProcessorTest.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * Test to check that a single lz that is added to the * tenant collection is added by processor. * * @throws Exception */ @Test public void shouldAddNewLz() throws Exception { List<String> testLzPaths = new ArrayList<String>(); testLzPaths.add("."); // this must be a path that exists on all platforms when(mockedTenantDA.getLzPaths()).thenReturn(testLzPaths); // get a test tenantRecord Exchange exchange = new DefaultExchange(new DefaultCamelContext()); tenantProcessor.process(exchange); // check there is no error on the received message assertEquals("Header on exchange should indicate success", TenantProcessor.TENANT_POLL_SUCCESS, exchange .getIn().getHeader(TenantProcessor.TENANT_POLL_HEADER)); }
Example #11
Source File: ProtobufIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testUnmarshall() throws Exception { final ProtobufDataFormat format = new ProtobufDataFormat(Person.getDefaultInstance()); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").unmarshal(format); } }); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); Person person = Person.newBuilder().setId(1).setName("John Doe").build(); person.writeTo(baos); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); Person result = producer.requestBody("direct:start", baos.toByteArray(), Person.class); Assert.assertEquals("John Doe", result.getName().trim()); } finally { camelctx.close(); } }
Example #12
Source File: HttpConnectorVerifierTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testBaseUrlWithScheme() throws Exception { CamelContext context = new DefaultCamelContext(); try { context.disableJMX(); context.start(); Map<String, Object> parameters = new HashMap<>(); parameters.put("baseUrl", "http://" + getLocalServerHostAndPort()); Verifier verifier = new HttpVerifier(); List<VerifierResponse> responses = verifier.verify(context, "http", parameters); assertThat(responses).hasSize(2); assertThat(responses).anyMatch(response -> response.getScope() == Verifier.Scope.CONNECTIVITY); assertThat(responses).anyMatch(response -> response.getScope() == Verifier.Scope.PARAMETERS); assertThat(responses).allMatch(response -> response.getStatus() == Verifier.Status.OK); } finally { context.stop(); } }
Example #13
Source File: UndertowIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void overwriteDeploymentContextPathTest() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("undertow:http://localhost/test-servlet") .setBody(constant("Hello Kermit")); } }); deployer.deploy(TEST_SERVLET_WAR); try { // Context start should fail as the undertow consumer path is already registered by test-servlet.war expectedException.expect(IllegalStateException.class); camelctx.start(); } finally { camelctx.close(); deployer.undeploy(TEST_SERVLET_WAR); } }
Example #14
Source File: PurchaseOrderUnmarshalBindyTest.java From camelinaction2 with Apache License 2.0 | 6 votes |
@Test public void testUnmarshalBindy() throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(createRoute()); context.start(); MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:toObject", "Camel in Action,39.95,1"); mock.assertIsSatisfied(); // bindy returns the order directly (not in a list) if there is only one element PurchaseOrder order = mock.getReceivedExchanges().get(0).getIn().getBody(PurchaseOrder.class); assertNotNull(order); // assert the order contains the expected data assertEquals("Camel in Action", order.getName()); assertEquals("39.95", order.getPrice().toString()); assertEquals(1, order.getAmount()); }
Example #15
Source File: SignaturesDynamicTest.java From camel-cookbook-examples with Apache License 2.0 | 6 votes |
@Override protected CamelContext createCamelContext() throws Exception { final String keyStorePassword = "keystorePassword"; final String trustStorePassword = "truststorePassword"; SimpleRegistry registry = new SimpleRegistry(); KeyStore keyStore = KeyStore.getInstance("JKS"); // Java keystore ClassLoader classLoader = getClass().getClassLoader(); log.info("Loading keystore from [{}]", classLoader.getResource("keystore.jks").toString()); keyStore.load(classLoader.getResourceAsStream("keystore.jks"), keyStorePassword.toCharArray()); registry.put("keyStore", keyStore); KeyStore trustStore = KeyStore.getInstance("JKS"); // Java keystore trustStore.load(classLoader.getResourceAsStream("truststore.jks"), trustStorePassword.toCharArray()); registry.put("trustStore", trustStore); return new DefaultCamelContext(registry); }
Example #16
Source File: SimpleTransformTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSimpleTransform() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").transform(body().prepend("Hello ")); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", "Kermit", String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example #17
Source File: XChangeMarketIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testTicker() throws Exception { try (CamelContext camelctx = new DefaultCamelContext()) { Assume.assumeTrue(checkAPIConnection()); camelctx.addRoutes(createRouteBuilder()); camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); Ticker ticker = template.requestBody("direct:ticker", CurrencyPair.EOS_ETH, Ticker.class); Assert.assertNotNull("Ticker not null", ticker); System.out.println(ticker); ticker = template.requestBodyAndHeader("direct:ticker", null, HEADER_CURRENCY_PAIR, CurrencyPair.EOS_ETH, Ticker.class); Assert.assertNotNull("Ticker not null", ticker); System.out.println(ticker); } }
Example #18
Source File: AhcWSSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testAsyncWssRoute() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("ahc-wss:" + WEBSOCKET_ENDPOINT); from("ahc-wss:" + WEBSOCKET_ENDPOINT).to("seda:end"); } }); WsComponent wsComponent = (WsComponent) camelctx.getComponent("ahc-wss"); wsComponent.setSslContextParameters(defineSSLContextClientParameters()); PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); consumer.start(); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); producer.sendBody("direct:start", "Kermit"); Exchange exchange = consumer.receive(1000); Assert.assertEquals("Hello Kermit", exchange.getIn().getBody(String.class)); } finally { camelctx.close(); } }
Example #19
Source File: Olingo4IntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
private CamelContext createCamelContext() throws Exception { final CamelContext context = new DefaultCamelContext(); Map<String, Object> options = new HashMap<String, Object>(); options.put("serviceUri", getRealServiceUrl(TEST_SERVICE_BASE_URL)); options.put("contentType", "application/json;charset=utf-8"); final Olingo4Configuration configuration = new Olingo4Configuration(); IntrospectionSupport.setProperties(configuration, options); // add OlingoComponent to Camel context final Olingo4Component component = new Olingo4Component(context); component.setConfiguration(configuration); context.addComponent("olingo4", component); return context; }
Example #20
Source File: XStreamIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMarshal() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .marshal().xstream(); } }); String expected = wrapWithType(XML_STRING, Customer.class); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String customer = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class); Assert.assertTrue("Contains " + expected + ": " + customer, customer.contains(expected)); } finally { camelctx.close(); } }
Example #21
Source File: IPFSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void ipfsCat() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("ipfs:cat"); } }); camelctx.start(); try { assumeIPFSAvailable(camelctx); ProducerTemplate producer = camelctx.createProducerTemplate(); InputStream res = producer.requestBody("direct:start", SINGLE_HASH, InputStream.class); verifyFileContent(res); } finally { camelctx.close(); } }
Example #22
Source File: JCacheProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testJCacheLoadsCachingProviderEhcache() throws Exception { try (CamelContext camelctx = new DefaultCamelContext()) { camelctx.addRoutes(new RouteBuilder() { public void configure() { from("jcache://test-cacheB?cachingProvider=org.ehcache.jsr107.EhcacheCachingProvider") .to("mock:resultB"); } }); // Just ensure we can start up without any class loading issues camelctx.start(); } }
Example #23
Source File: XChangeMetadataIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testCurrencies() throws Exception { try (CamelContext camelctx = new DefaultCamelContext()) { Assume.assumeTrue(checkAPIConnection()); camelctx.addRoutes(createRouteBuilder()); camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); List<Currency> currencies = template.requestBody("direct:currencies", null, List.class); Assert.assertNotNull("Currencies not null", currencies); Assert.assertTrue("Contains ETH", currencies.contains(Currency.ETH)); } }
Example #24
Source File: FastHeadersIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSimple() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { public void configure() throws Exception { from("direct:start").to("log:foo").to("log:bar").to("mock:result"); } }); MockEndpoint mockResult = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockResult.expectedBodiesReceived("Hello World"); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); producer.sendBody("direct:start", "Hello World"); mockResult.assertIsSatisfied(); HeadersMapFactory factory = camelctx.adapt(ExtendedCamelContext.class).getHeadersMapFactory(); Assert.assertTrue("Instance of FastHeadersMapFactory", factory instanceof FastHeadersMapFactory); } finally { camelctx.close(); } }
Example #25
Source File: MvelTransformTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSimpleTransformFromModule() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("mvel:template.mvel"); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBody("direct:start", "Kermit", String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example #26
Source File: CamelMailetContainerModuleTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void getProcessortConfigurationShouldReturnEmptyWhenNoContextSection() throws Exception { ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class); when(configurationProvider.getConfiguration("mailetcontainer")) .thenReturn(new BaseHierarchicalConfiguration()); XMLConfiguration defaultConfiguration = FileConfigurationProvider.getConfig(new ByteArrayInputStream(( "<processors>" + " <key>value</key>" + "</processors>") .getBytes(StandardCharsets.UTF_8))); MailetModuleInitializationOperation testee = new MailetModuleInitializationOperation(configurationProvider, mock(CamelCompositeProcessor.class), NO_TRANSPORT_CHECKS, () -> defaultConfiguration, mock(DefaultCamelContext.class)); assertThat(testee.getProcessorConfiguration()) .isEqualTo(defaultConfiguration); }
Example #27
Source File: YamlDataFormatIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMarshalYaml() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .marshal().yaml(YAMLLibrary.SnakeYAML); } }); ClassLoader loader = SnakeYAMLDataFormat.class.getClassLoader(); loader = loader.loadClass("org.yaml.snakeyaml.Yaml").getClassLoader(); System.out.println(loader); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); String result = template.requestBody("direct:start", new Customer("John", "Doe"), String.class); Assert.assertEquals(CUSTOMER_YAML, result.trim()); } finally { camelctx.close(); } }
Example #28
Source File: IPFSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void ipfsAddSingle() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("ipfs:add"); } }); camelctx.start(); try { assumeIPFSAvailable(camelctx); Path path = Paths.get("src/test/resources/ipfs/etc/userfile.txt"); ProducerTemplate producer = camelctx.createProducerTemplate(); String res = producer.requestBody("direct:start", path, String.class); Assert.assertEquals(SINGLE_HASH, res); } finally { camelctx.close(); } }
Example #29
Source File: FtpToJMSExample.java From camelinaction with Apache License 2.0 | 6 votes |
public static void main(String args[]) throws Exception { // create CamelContext CamelContext context = new DefaultCamelContext(); // connect to embedded ActiveMQ JMS broker ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); // add our route to the CamelContext context.addRoutes(new RouteBuilder() { @Override public void configure() { from("ftp://rider.com/orders?username=rider&password=secret").to("jms:incomingOrders"); } }); // start the route and let it do its work context.start(); Thread.sleep(10000); // stop the CamelContext context.stop(); }
Example #30
Source File: SAPNetweaverIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testSAPNetweaverEndpointJsonResponse() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("sap-netweaver:http://localhost:8080/sap/api"); from("undertow:http://localhost:8080/sap/api?matchOnUriPrefix=true") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { String data = TestUtils.getResourceValue(SAPNetweaverIntegrationTest.class, "/flight-data.json"); exchange.getMessage().setBody(data); } }); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); String result = producer.requestBodyAndHeader("direct:start", null, NetWeaverConstants.COMMAND, SAP_COMMAND, String.class); Assert.assertTrue(result.contains("PRICE=422.94, CURRENCY=USD")); } finally { camelctx.close(); } }