List of usage examples for org.springframework.context.support AbstractApplicationContext getBean
@Override public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException
From source file:org.ivanursul.investigation.CamelClient.java
public static void main(final String[] args) throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml"); ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class); Integer value = 33;//from ww w .ja va 2 s .c om // Sending request and receiving result. int response = (Integer) camelTemplate.sendBody("jms:queue:numbers?requestTimeout=2000000", ExchangePattern.InOut, value); // Sending to votes without receiving any result. camelTemplate.sendBody("jms:queue:votes", response); IOHelper.close(context); }
From source file:example.client.CamelMongoJmsStockClient.java
@SuppressWarnings("resource") public static void main(final String[] args) throws Exception { systemProps = loadProperties();/*w ww. j a v a 2 s . c o m*/ AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml"); ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class); List<Map<String, Object>> stocks = readJsonsFromMongoDB(); for (Map<String, Object> stock : stocks) { stock.remove("_id"); stock.remove("Earnings Date"); camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")), ExchangePattern.InOnly, stock); } new Timer().schedule(new TimerTask() { @Override public void run() { Map<String, Object> aRandomStock = stocks.get(RandomUtils.nextInt(0, stocks.size())); aRandomStock.put("Price", ((Double) aRandomStock.get("Price")) + RandomUtils.nextFloat(0.1f, 9.99f)); camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")), ExchangePattern.InOnly, aRandomStock); } }, 1000, 2000); }
From source file:org.apache.camel.example.client.CamelClientEndpoint.java
public static void main(final String[] args) throws Exception { System.out.println("Notice this client requires that the CamelServer is already running!"); AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml"); CamelContext camel = context.getBean("camel-client", CamelContext.class); // get the endpoint from the camel context Endpoint endpoint = camel.getEndpoint("jms:queue:numbers"); // create the exchange used for the communication // we use the in out pattern for a synchronized exchange where we expect a response Exchange exchange = endpoint.createExchange(ExchangePattern.InOut); // set the input on the in body // must be correct type to match the expected type of an Integer object exchange.getIn().setBody(11);/* www.jav a 2 s . c o m*/ // to send the exchange we need an producer to do it for us Producer producer = endpoint.createProducer(); // start the producer so it can operate producer.start(); // let the producer process the exchange where it does all the work in this oneline of code System.out.println("Invoking the multiply with 11"); producer.process(exchange); // get the response from the out body and cast it to an integer int response = exchange.getOut().getBody(Integer.class); System.out.println("... the result is: " + response); // stopping the JMS producer has the side effect of the "ReplyTo Queue" being properly // closed, making this client not to try any further reads for the replies from the server producer.stop(); // we're done so let's properly close the application context IOHelper.close(context); }
From source file:org.apache.camel.example.CamelFileSizeCBRMain.java
public static void main(String[] args) throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "META-INF/spring/camel-file-size-cbr.xml"); final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class); for (int i = 1; i < SIZE; i++) { producer.sendBodyAndHeader("seda:allFiles", getPayload(i), Exchange.FILE_NAME, i + ".txt"); }//w ww.jav a 2s . c o m Thread.sleep(100000); context.stop(); }
From source file:uk.co.jemos.experiments.integration.HelloWorldApp.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class); MessageChannel inputChannel = context.getBean("podamInputChannel", MessageChannel.class); Message<Object> intMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", int.class.toString()).build(); Message<Object> boolMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", boolean.class.toString()).build(); Message<Object> stringMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", String.class.getName()).build(); MessagingTemplate template = new MessagingTemplate(); Message reply = template.sendAndReceive(inputChannel, intMessage); logger.info(reply.getPayload());/* w w w.j a v a 2 s.c om*/ reply = template.sendAndReceive(inputChannel, boolMessage); logger.info(reply.getPayload()); reply = template.sendAndReceive(inputChannel, stringMessage); logger.info(reply.getPayload()); context.close(); }
From source file:org.apache.camel.example.client.CamelClient.java
public static void main(final String[] args) throws Exception { System.out.println("Notice this client requires that the CamelServer is already running!"); AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml"); // get the camel template for Spring template style sending of messages (= producer) ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class); System.out.println("Invoking the multiply with 22"); // as opposed to the CamelClientRemoting example we need to define the service URI in this java code int response = (Integer) camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22); System.out.println("... the result is: " + response); // we're done so let's properly close the application context IOHelper.close(context);/* w ww .ja v a 2 s. c om*/ }
From source file:org.apache.camel.example.client.CamelFileClient.java
public static void main(final String[] args) throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-file-client.xml"); // get the camel template for Spring template style sending of messages (= producer) final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class); // now send a lot of messages System.out.println("Writing files ..."); for (int i = 0; i < SIZE; i++) { producer.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt"); }/* w ww. j a va 2s.com*/ System.out.println("... Wrote " + SIZE + " files"); // we're done so let's properly close the application context IOHelper.close(context); }
From source file:org.apache.camel.example.mail.MailDslExamples.java
public static void main(final String[] args) throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "META-INF/spring/camel-context.xml"); // get the camel template for Spring template style sending of messages (= producer) final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class); producer.sendBodyAndHeader("direct:sendSmtpMail", "Test mail from smtp", "subject", "First Test Mail with content type"); // send mail with password encrypted in properties file jasypt producer.sendBodyAndHeader("direct:sendSmtpMailEncryptedPassword", "Test mail from smtp", "subject", "First Test Mail with content type"); // Keep running as listener need to be up for receiving messages. Thread.sleep(10000000);//from w ww.j av a2 s.co m // IOHelper.close(context); }
From source file:com.opengamma.masterdb.batch.cmd.BatchRunner.java
public static void main(String[] args) throws Exception { // CSIGNORE if (args.length == 0) { usage();/*from w w w .ja v a2s. c o m*/ System.exit(-1); } CommandLine line = null; try { CommandLineParser parser = new PosixParser(); line = parser.parse(getOptions(), args); initialize(line); } catch (ParseException e) { usage(); System.exit(-1); } AbstractApplicationContext appContext = null; try { appContext = getApplicationContext(); appContext.start(); ViewProcessor viewProcessor = appContext.getBean("viewProcessor", ViewProcessor.class); ViewClient viewClient = viewProcessor.createViewClient(UserPrincipal.getLocalUser()); MarketDataSpecification marketDataSpec = new FixedHistoricalMarketDataSpecification( s_observationDateTime.toLocalDate()); ViewCycleExecutionOptions cycleOptions = ViewCycleExecutionOptions.builder() .setValuationTime(s_valuationInstant).setMarketDataSpecification(marketDataSpec) .setResolverVersionCorrection(VersionCorrection.of(s_versionAsOf, s_correctedTo)).create(); ViewCycleExecutionSequence executionSequence = ArbitraryViewCycleExecutionSequence.of(cycleOptions); ExecutionOptions executionOptions = new ExecutionOptions(executionSequence, ExecutionFlags.none().awaitMarketData().get(), null, null); viewClient.attachToViewProcess(UniqueId.parse(s_viewDefinitionUid), executionOptions); } finally { if (appContext != null) { appContext.close(); } } /*if (failed) { s_logger.error("Batch failed."); System.exit(-1); } else { s_logger.info("Batch succeeded."); System.exit(0); }*/ }
From source file:org.apache.camel.example.client.CamelClientRemoting.java
public static void main(final String[] args) { System.out.println("Notice this client requires that the CamelServer is already running!"); AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client-remoting.xml"); // just get the proxy to the service and we as the client can use the "proxy" as it was // a local object we are invoking. Camel will under the covers do the remote communication // to the remote ActiveMQ server and fetch the response. Multiplier multiplier = context.getBean("multiplierProxy", Multiplier.class); System.out.println("Invoking the multiply with 33"); int response = multiplier.multiply(33); System.out.println("... the result is: " + response); // we're done so let's properly close the application context IOHelper.close(context);/*w ww . j a v a 2 s . com*/ }