Java Code Examples for org.apache.camel.CamelContext#stop()
The following examples show how to use
org.apache.camel.CamelContext#stop() .
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: HttpConnectorVerifierTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testWithNestedPath1() throws Exception { CamelContext context = new DefaultCamelContext(); try { context.disableJMX(); context.start(); Map<String, Object> parameters = new HashMap<>(); parameters.put("baseUrl", getLocalServerHostAndPort() + "/with/nested"); parameters.put("path", "path"); 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 2
Source File: QuartzCronExample.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://report?cron=0/2+*+*+*+*+?") .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: HttpConnectorVerifierTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testWithPath3() throws Exception { CamelContext context = new DefaultCamelContext(); try { context.disableJMX(); context.start(); Map<String, Object> parameters = new HashMap<>(); parameters.put("baseUrl", getLocalServerHostAndPort() + "/"); parameters.put("path", "withPath"); 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 4
Source File: FileCopierWithCamel.java From camelinaction2 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("file:data/inbox?noop=true").to("file:data/outbox"); } }); // start the route and let it do its work context.start(); Thread.sleep(10000); // stop the CamelContext context.stop(); }
Example 5
Source File: ActionDefinitionEndpointTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void shouldMetadata() { final CamelContext context = new DefaultCamelContext(); context.addComponent("petstore", new PetstoreComponent(PAYLOAD)); try { context.start(); final PetstoreMetadataRetrieval adapter = new PetstoreMetadataRetrieval(PAYLOAD, PROPERTIES, INPUT, OUTPUT); final SyndesisMetadata metadata = adapter.fetch(context, "petstore", "dog-food", Collections.emptyMap()); assertThat(metadata.getProperties()).isSameAs(PROPERTIES); assertThat(metadata.inputShape).isSameAs(INPUT); assertThat(metadata.outputShape).isSameAs(OUTPUT); } finally { context.stop(); } }
Example 6
Source File: ActionDefinitionEndpointTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void shouldDynamicProperties() { final CamelContext context = new DefaultCamelContext(); context.addComponent("petstore", new PetstoreComponent(PAYLOAD)); try { context.start(); final PetstoreMetadataRetrieval adapter = new PetstoreMetadataRetrieval(PAYLOAD, PROPERTIES, INPUT, OUTPUT); final SyndesisMetadataProperties metadataProperties = adapter.fetchProperties( context, "petstore", Collections.emptyMap()); assertThat(metadataProperties.getProperties()).isSameAs(PROPERTIES); } finally { context.stop(); } }
Example 7
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 8
Source File: MicroProfileMetricsIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testCounter() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:counter") .to("microprofile-metrics:counter:wfc-counter"); } }); bindMetricRegistry(camelctx); camelctx.start(); try { camelctx.createProducerTemplate().sendBody("direct:counter", null); assertSimpleMetricValue(camelctx, "wfc-counter", 1); } finally { camelctx.stop(); } }
Example 9
Source File: FileSaver.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("stream:in?promptMessage=Enter something:").to("file:data/outbox"); } }); // start the route and let it do its work context.start(); Thread.sleep(10000); // stop the CamelContext context.stop(); }
Example 10
Source File: CamelFirstTest.java From camelinaction2 with Apache License 2.0 | 5 votes |
@Test public void testCamelFirst() throws Exception { LOG.info("Starting RX-Java2 Flowable Camel first"); // create Camel CamelContext camel = new DefaultCamelContext(); // create Reative Camel CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(camel); camel.start(); rsCamel.start(); // create a publisher from Camel seda:words endpoint Publisher<String> publisher = rsCamel.from("seda:words", String.class); Flowable.fromPublisher(publisher) // upper case the word .map(w -> w.toUpperCase()) // log the big number .doOnNext(w -> LOG.info(w)) .subscribe(); // send some words to Camel FluentProducerTemplate template = camel.createFluentProducerTemplate(); template.withBody("Camel").to("seda:words").send(); template.withBody("rocks").to("seda:words").send(); template.withBody("streams").to("seda:words").send(); template.withBody("as").to("seda:words").send(); template.withBody("well").to("seda:words").send(); // sleep a bit for reactive subscriber to complete Thread.sleep(1000); camel.stop(); rsCamel.stop(); }
Example 11
Source File: RouteBuilderExample.java From camelinaction2 with Apache License 2.0 | 5 votes |
public static void main(String args[]) throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { @Override public void configure() { // try auto complete in your IDE on the line below } }); context.start(); Thread.sleep(10000); context.stop(); }
Example 12
Source File: CharacterInfoParserTest.java From eveapi with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void parserTestWithFullAPI() throws Exception { final CamelContext context = new DefaultCamelContext(); context.addRoutes(fullApiRoute); context.start(); final CharacterInfoParser parser = new CharacterInfoParser(); AbstractApiParser.setConnector(new ApiConnector(MockApi.URL)); final CharacterInfoResponse response = parser.getResponse(fullAPI); assertNotNull(response); assertEquals(1380128241L, response.getCharacterID()); assertEquals("Zy'or Tealon", response.getCharacterName()); assertEquals(Race.AMARR, response.getRace()); assertEquals(Bloodline.NI_KUNNI, response.getBloodline()); assertEquals(217940508L, response.getCorporationID()); assertEquals("Black Mesa", response.getCorporation()); assertDate(2010, 8, 23, 20, 29, 0, response.getCorporationDate()); assertEquals(786554367L, response.getAllianceID().longValue()); assertEquals("Wayfarer Stellar Initiative", response.getAlliance()); assertDate(2010, 11, 22, 00, 57, 0, response.getAllianceDate()); assertEquals(1.74600960835429, response.getSecurityStatus(), 0.00001); assertEquals(88793781, response.getSkillPoints().intValue()); assertEquals("Zy'or", response.getShipName()); assertEquals(24696, response.getShipTypeID().intValue()); assertEquals("Harbinger", response.getShipTypeName()); assertEquals(12, response.getBloodlineID()); assertEquals(35, response.getAncestryID()); assertEquals(Ancestry.SAAN_GO_CASTE, response.getAncestry()); assertDate(2016, 11, 10, 00, 50, 11, response.getNextTrainingEnds()); assertEquals(37040036.46, response.getAccountBalance().doubleValue(), 0.01); assertEquals("OC The Revolving Door", response.getLastKnownLocation()); context.stop(); }
Example 13
Source File: FtpToJMSWithProcessorExample.java From camelinaction2 with Apache License 2.0 | 5 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"). process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("We just downloaded: " + exchange.getIn().getHeader("CamelFileName")); } }). to("jms:incomingOrders"); } }); // start the route and let it do its work context.start(); Thread.sleep(10000); // stop the CamelContext context.stop(); }
Example 14
Source File: ComponentProxyWithCustomComponentTest.java From syndesis with Apache License 2.0 | 5 votes |
private void validate(Registry registry) throws Exception { final CamelContext context = new DefaultCamelContext(registry); try { context.setAutoStartup(false); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("my-sql-proxy") .to("mock:result"); } }); context.start(); Collection<String> names = context.getComponentNames(); assertThat(names).contains("my-sql-proxy"); assertThat(names).contains("sql-my-sql-proxy"); SqlComponent sqlComponent = context.getComponent("sql-my-sql-proxy", SqlComponent.class); DataSource sqlDatasource = sqlComponent.getDataSource(); assertThat(sqlDatasource).isEqualTo(this.ds); Map<String, Endpoint> endpoints = context.getEndpointMap(); assertThat(endpoints).containsKey("sql-my-sql-proxy://select%20from%20dual"); } finally { context.stop(); } }
Example 15
Source File: PlatformHttpServiceCustomizerTest.java From camel-k-runtime with Apache License 2.0 | 5 votes |
@Test public void testPlatformHttpComponentCORS() throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("platform-http:/") .transform().constant("cors"); } }); PlatformHttpServiceContextCustomizer httpService = new PlatformHttpServiceContextCustomizer(); httpService.setBindPort(AvailablePortFinder.getNextAvailable()); httpService.getCors().setEnabled(true); httpService.getCors().setMethods(Arrays.asList("GET", "POST")); httpService.apply(context); try { context.start(); String origin = "http://custom.origin.quarkus"; String methods = "GET,POST"; String headers = "X-Custom"; given() .port(httpService.getBindPort()) .header("Origin", origin) .header("Access-Control-Request-Method", methods) .header("Access-Control-Request-Headers", headers) .when() .get("/") .then() .statusCode(200) .header("Access-Control-Allow-Origin", origin) .header("Access-Control-Allow-Methods", methods) .header("Access-Control-Allow-Headers", headers); } finally { context.stop(); } }
Example 16
Source File: OrderRouterWithWireTap.java From camelinaction with Apache License 2.0 | 5 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() { // load file orders from src/data into the JMS queue from("file:src/data?noop=true").to("jms:incomingOrders"); // content-based router from("jms:incomingOrders") .wireTap("jms:orderAudit") .choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:xmlOrders") .when(header("CamelFileName").regex("^.*(csv|csl)$")) .to("jms:csvOrders") .otherwise() .to("jms:badOrders"); } }); // start the route and let it do its work context.start(); Thread.sleep(2000); // stop the CamelContext context.stop(); }
Example 17
Source File: CharacterInfoParserTest.java From eveapi with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void parserTestWithoutAuth() throws Exception { final CamelContext context = new DefaultCamelContext(); context.addRoutes(noAPI); context.start(); AbstractApiParser.setConnector(new ApiConnector(MockApi.URL)); final CharacterInfoParser parser = new CharacterInfoParser(); final CharacterInfoResponse response = parser.getResponse(1380128241); assertNotNull(response); assertEquals(1380128241L, response.getCharacterID()); assertEquals("Zy'or Tealon", response.getCharacterName()); assertEquals(Race.CALDARI, response.getRace()); assertEquals(Bloodline.DETEIS, response.getBloodline()); assertEquals(217940508L, response.getCorporationID()); assertEquals("Black Mesa", response.getCorporation()); assertDate(2010, 8, 23, 20, 29, 0, response.getCorporationDate()); assertEquals(786554367L, response.getAllianceID().longValue()); assertEquals("Wayfarer Stellar Initiative", response.getAlliance()); assertDate(2010, 11, 22, 00, 57, 0, response.getAllianceDate()); assertEquals(1.74600960835429, response.getSecurityStatus(), 0.00001); assertEquals(5, response.getEmploymentHistory().size()); assertEquals(12, response.getBloodlineID()); assertEquals(35, response.getAncestryID()); assertEquals(Ancestry.SAAN_GO_CASTE, response.getAncestry()); assertNull(response.getSkillPoints()); assertNull(response.getShipName()); assertNull(response.getShipTypeID()); assertNull(response.getShipTypeName()); assertNull(response.getNextTrainingEnds()); assertNull(response.getAccountBalance()); assertNull(response.getLastKnownLocation()); context.stop(); }
Example 18
Source File: JmxConfigureCamelApplication.java From camel-cookbook-examples with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { final CamelContext context = new DefaultCamelContext(); // Configure JMX settings final ManagementStrategy managementStrategy = context.getManagementStrategy(); /* managementStrategy.setStatisticsLevel(ManagementStatisticsLevel.All); managementStrategy.setLoadStatisticsEnabled(true); */ // TODO: double check this is right way to get and configure Management Agent final ManagementAgent managementAgent = managementStrategy.getManagementAgent(); managementAgent.setConnectorPort(1099); managementAgent.setServiceUrlPath("/jmxrmi/camel"); managementAgent.setCreateConnector(false); managementAgent.setUsePlatformMBeanServer(true); // TODO: check that level Extended is same/better as ALL managementAgent.setStatisticsLevel(ManagementStatisticsLevel.Extended); managementAgent.setLoadStatisticsEnabled(true); // Add a simple test route context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .log("${body}") .to("mock:result"); } }); // Start the context context.start(); // Send a couple of messages to get some route statistics final ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:start", "Hello Camel"); template.sendBody("direct:start", "Camel Rocks!"); // let the Camel runtime do its job for a while Thread.sleep(60000); // shutdown context.stop(); }
Example 19
Source File: OrderRouterWithFilter.java From camelinaction with Apache License 2.0 | 4 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() { // load file orders from src/data into the JMS queue from("file:src/data?noop=true").to("jms:incomingOrders"); // content-based router from("jms:incomingOrders") .choice() .when(header("CamelFileName").endsWith(".xml")) .to("jms:xmlOrders") .when(header("CamelFileName").regex("^.*(csv|csl)$")) .to("jms:csvOrders") .otherwise() .to("jms:badOrders"); // lets filter out the test messages from("jms:xmlOrders").filter(xpath("/order[not(@test)]")) .process(new Processor() { public void process(Exchange exchange) throws Exception { System.out.println("Received XML order: " + exchange.getIn().getHeader("CamelFileName")); } }); } }); // start the route and let it do its work context.start(); Thread.sleep(10000); // stop the CamelContext context.stop(); }
Example 20
Source File: RestOrderServer.java From camelinaction2 with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { // create dummy backend DummyOrderService dummy = new DummyOrderService(); dummy.setupDummyOrders(); // create a Camel route that routes the REST services OrderRoute route = new OrderRoute(); route.setOrderService(dummy); // create CamelContext and add the route CamelContext camel = new DefaultCamelContext(); camel.addRoutes(route); // create a ProducerTemplate that the CXF REST service will use to integrate with Camel ProducerTemplate producer = camel.createProducerTemplate(); // create CXF REST service and inject the Camel ProducerTemplate // which we use to call the Camel route RestOrderService rest = new RestOrderService(); rest.setProducerTemplate(producer); // setup Apache CXF REST server on port 9000 JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(RestOrderService.class); sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest)); // to use jackson for json sf.setProvider(JacksonJsonProvider.class); sf.setAddress("http://localhost:9000/"); // create the CXF server Server server = sf.create(); // start Camel and CXF (non blocking) camel.start(); server.start(); // keep the JVM running Console console = System.console(); System.out.println("Server started on http://localhost:9000/"); System.out.println(""); // If you run the main class from IDEA/Eclipse then you may not have a console, which is null) if (console != null) { System.out.println(" Press ENTER to stop server"); console.readLine(); } else { System.out.println(" Stopping after 5 minutes or press ctrl + C to stop"); Thread.sleep(5 * 60 * 1000); } // stop Camel and CXF server camel.stop(); server.stop(); System.exit(0); }