From 6461d3f432720af8b7a055f15e72430f0ec0aeaf Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 16 Jul 2009 14:41:49 +0000 Subject: [PATCH] CLI-enabled inbound/outbound demo bundles. Removed obsolete components --- ...com.springsource.server.ide.jdt.core.prefs | 3 + .../src/META-INF/MANIFEST.MF | 13 ++- .../src/META-INF/spring/context-osgi-in.xml | 15 ++-- .../inbound/FileCopyDemoBootstrap.java | 42 ---------- .../inbound/InboundDemoBundleActivator.java | 84 +++++++++++++++++++ .../samples/inbound/InboundGateway.java | 29 +++++++ .../src/META-INF/spring/context-osgi-out.xml | 16 ++-- .../samples/filecopy/Exclaimer.java | 44 ---------- .../samples/filecopy/FileCopyDemoCommon.java | 50 ----------- 9 files changed, 137 insertions(+), 159 deletions(-) create mode 100644 spring-integration-samples/inbound-adapter-osgi/.settings/com.springsource.server.ide.jdt.core.prefs delete mode 100644 spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/FileCopyDemoBootstrap.java create mode 100644 spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/InboundDemoBundleActivator.java create mode 100644 spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/InboundGateway.java delete mode 100644 spring-integration-samples/outbound-adapter-osgi/src/org/springframework/integration/samples/filecopy/Exclaimer.java delete mode 100644 spring-integration-samples/outbound-adapter-osgi/src/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java diff --git a/spring-integration-samples/inbound-adapter-osgi/.settings/com.springsource.server.ide.jdt.core.prefs b/spring-integration-samples/inbound-adapter-osgi/.settings/com.springsource.server.ide.jdt.core.prefs new file mode 100644 index 0000000000..78f3e06196 --- /dev/null +++ b/spring-integration-samples/inbound-adapter-osgi/.settings/com.springsource.server.ide.jdt.core.prefs @@ -0,0 +1,3 @@ +#Wed Jul 15 23:31:18 EDT 2009 +com.springsource.server.ide.jdt.core.source.attachment-org.springframework.integration.file-1.0.3.BUILD-20090716030205.jar=/org.springframework.integration.file/src/main/java +eclipse.preferences.version=1 diff --git a/spring-integration-samples/inbound-adapter-osgi/src/META-INF/MANIFEST.MF b/spring-integration-samples/inbound-adapter-osgi/src/META-INF/MANIFEST.MF index b66ed1a0e0..3c9af1f88d 100644 --- a/spring-integration-samples/inbound-adapter-osgi/src/META-INF/MANIFEST.MF +++ b/spring-integration-samples/inbound-adapter-osgi/src/META-INF/MANIFEST.MF @@ -1,10 +1,15 @@ Manifest-Version: 1.0 Bundle-Version: 1.0.3 -Bundle-Name: Input_adapter_osgi +Bundle-Name: Inbound_adapter_osgi Bundle-ManifestVersion: 2 -Bundle-SymbolicName: input_adapter_osgi +Bundle-SymbolicName: inbound_adapter_osgi +Bundle-Activator: org.springframework.integration.samples.inbound.InboundDemoBundleActivator +Import-Package: org.eclipse.osgi.framework.console;version="1.0.0", + org.osgi.framework;version="1.4.0", + org.osgi.service.packageadmin;version="1.2.0", + org.eclipse.osgi.util Import-Library: org.aspectj;version="[1.6.2, 2.0.0)", org.springframework.spring;version="[2.5.6.A, 3.1.0)" -Import-Bundle: org.springframework.integration;version="[1.0.3, 1.0.4)", - org.springframework.integration.file;version="[1.0.3, 1.0.4)" +Import-Bundle: org.springframework.integration;version="[1.0.3,1.0.4)", + org.springframework.integration.file;version="[1.0.3,1.0.4)" diff --git a/spring-integration-samples/inbound-adapter-osgi/src/META-INF/spring/context-osgi-in.xml b/spring-integration-samples/inbound-adapter-osgi/src/META-INF/spring/context-osgi-in.xml index f2edab4fd1..14a076e633 100644 --- a/spring-integration-samples/inbound-adapter-osgi/src/META-INF/spring/context-osgi-in.xml +++ b/spring-integration-samples/inbound-adapter-osgi/src/META-INF/spring/context-osgi-in.xml @@ -2,21 +2,20 @@ - - - - - - - + - + + + diff --git a/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/FileCopyDemoBootstrap.java b/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/FileCopyDemoBootstrap.java deleted file mode 100644 index 8dc3de4d8e..0000000000 --- a/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/FileCopyDemoBootstrap.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.samples.inbound; - -import java.io.File; - -import org.springframework.beans.factory.InitializingBean; - -/** - * Common functionality for the file demo. - * - * @author Oleg Zhurakousky - */ -public class FileCopyDemoBootstrap implements InitializingBean { - - public void afterPropertiesSet() throws Exception { - String tmpDirPath = System.getProperty("java.io.tmpdir"); - File parentDir = new File(tmpDirPath + File.separator + "spring-integration-samples"); - File inDir = new File(parentDir, "input"); - if (inDir.exists() || inDir.mkdirs()) { - System.out.println("input directory is: " + inDir.getAbsolutePath()); - } - else { - System.err.println("failed to create directories within tmp dir: " + tmpDirPath); - } - } - -} diff --git a/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/InboundDemoBundleActivator.java b/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/InboundDemoBundleActivator.java new file mode 100644 index 0000000000..1b660eccae --- /dev/null +++ b/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/InboundDemoBundleActivator.java @@ -0,0 +1,84 @@ +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.samples.inbound; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.eclipse.osgi.framework.console.CommandInterpreter; +import org.eclipse.osgi.framework.console.CommandProvider; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; +import org.springframework.context.ApplicationContext; +import org.springframework.util.Assert; +/** + * Simple BundleActivator which will register ServiceListener which will listen for + * ApplicationContext published event. Once event is received, HelloWorldDemo will be executed. + * + * @author Oleg Zhurakousky + */ +public class InboundDemoBundleActivator implements BundleActivator, CommandProvider, ServiceListener { + private BundleContext context; + private InboundGateway gateway; + + + public void start(BundleContext context) throws Exception { + this.context = context; + this.context.addServiceListener(this); + Dictionary props = new Hashtable(); + context.registerService(CommandProvider.class.getName(), this, props); + } + /** + * + */ + public void stop(BundleContext arg0) throws Exception {} + /** + * + */ + public String getHelp() { + return "\n### Spring Integration CLI-based Demo\n" + + "siSend - will send a message to a reciever which will write the message to a file\n\t" + + "siSend Example: siSend hello foo.txt\n"; + } + /** + * + */ + public void serviceChanged(ServiceEvent serviceEvent) { + ServiceReference sr = serviceEvent.getServiceReference(); + if (context.getBundle().getSymbolicName().equals(sr.getProperty(Constants.BUNDLE_SYMBOLICNAME))){ + ApplicationContext applicationContext = (ApplicationContext) context.getService(sr); + gateway = (InboundGateway) applicationContext.getBean("inboundGateway"); + } + } + /** + * + * @param ci + */ + public void _siSend(CommandInterpreter ci){ + String message = ci.nextArgument(); + String fileName = ci.nextArgument(); + Assert.notNull(message, "You must provide message as first argument"); + Assert.notNull(fileName, "You must proivi a file name as second argument"); + ci.println("Sending message: '" + message + "'"); + gateway.sendMessage(message, fileName); + ci.println("Message sent!"); + } + +} diff --git a/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/InboundGateway.java b/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/InboundGateway.java new file mode 100644 index 0000000000..58d3c8037c --- /dev/null +++ b/spring-integration-samples/inbound-adapter-osgi/src/org/springframework/integration/samples/inbound/InboundGateway.java @@ -0,0 +1,29 @@ +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.samples.inbound; + +import org.springframework.integration.annotation.Header; +import org.springframework.integration.file.FileHeaders; +/** + * Simple BundleActivator which will register ServiceListener which will listen for + * ApplicationContext published event. Once event is received, HelloWorldDemo will be executed. + * + * @author Oleg Zhurakousky + */ +public interface InboundGateway { + + public void sendMessage(String message, @Header(FileHeaders.FILENAME)String fileName); +} diff --git a/spring-integration-samples/outbound-adapter-osgi/src/META-INF/spring/context-osgi-out.xml b/spring-integration-samples/outbound-adapter-osgi/src/META-INF/spring/context-osgi-out.xml index 0cd22ffa10..0182654644 100644 --- a/spring-integration-samples/outbound-adapter-osgi/src/META-INF/spring/context-osgi-out.xml +++ b/spring-integration-samples/outbound-adapter-osgi/src/META-INF/spring/context-osgi-out.xml @@ -2,26 +2,20 @@ - - - - - + - - - - + + diff --git a/spring-integration-samples/outbound-adapter-osgi/src/org/springframework/integration/samples/filecopy/Exclaimer.java b/spring-integration-samples/outbound-adapter-osgi/src/org/springframework/integration/samples/filecopy/Exclaimer.java deleted file mode 100644 index 08963c6507..0000000000 --- a/spring-integration-samples/outbound-adapter-osgi/src/org/springframework/integration/samples/filecopy/Exclaimer.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.samples.filecopy; - -import java.io.File; - -/** - * A class providing several handling methods for different types of payloads. - * - * @author Mark Fisher - * @author Marius Bogoevici - */ -public class Exclaimer { - -// public String exclaim(String input) { -// System.out.println("Copying text: " + input); -// return input.toUpperCase(); -// } - - public File exclaim(File input) { - System.out.println("Copying file: " + input.getAbsolutePath()); - return input; - } - -// public byte[] exclaim(byte[] input) { -// System.out.println("Copying " + input.length + " bytes ..."); -// return new String(input).toUpperCase().getBytes(); -// } - -} diff --git a/spring-integration-samples/outbound-adapter-osgi/src/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java b/spring-integration-samples/outbound-adapter-osgi/src/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java deleted file mode 100644 index 5b5a2f0072..0000000000 --- a/spring-integration-samples/outbound-adapter-osgi/src/org/springframework/integration/samples/filecopy/FileCopyDemoCommon.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.samples.filecopy; - -import java.io.File; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanFactoryPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; - -/** - * Common functionality for the file demo. - * - * @author Oleg Zhurakousky - */ -public class FileCopyDemoCommon implements BeanFactoryPostProcessor { - - public void afterPropertiesSet() { - String tmpDirPath = System.getProperty("java.io.tmpdir"); - File parentDir = new File(tmpDirPath + File.separator + "spring-integration-samples"); - File outDir = new File(parentDir, "output"); - if (outDir.exists() || outDir.mkdirs()) { - System.out.println("output directory is: " + outDir.getAbsolutePath()); - } - else { - System.err.println("failed to create directories within tmp dir: " + tmpDirPath); - } - } - /** - * HACK!!!!! - */ - public void postProcessBeanFactory(ConfigurableListableBeanFactory arg0) - throws BeansException { - this.afterPropertiesSet(); - } -}