CLI-enabled inbound/outbound demo bundles. Removed obsolete components

This commit is contained in:
Oleg Zhurakousky
2009-07-16 14:41:49 +00:00
parent 8f3a3db480
commit 6461d3f432
9 changed files with 137 additions and 159 deletions

View File

@@ -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

View File

@@ -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)"

View File

@@ -2,21 +2,20 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:file="http://www.springframework.org/schema/integration/file">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<bean class="org.springframework.integration.samples.inbound.FileCopyDemoBootstrap"/>
<file:inbound-channel-adapter id="filesIn" directory="file:${java.io.tmpdir}/spring-integration-samples/input">
<integration:poller>
<integration:interval-trigger interval="5000"/>
</integration:poller>
</file:inbound-channel-adapter>
<integration:gateway id="inboundGateway" service-interface="org.springframework.integration.samples.inbound.InboundGateway"
default-request-channel="inChannel"/>
<osgi:service id="filesInService" ref="filesIn" interface="org.springframework.integration.channel.SubscribableChannel"/>
<integration:publish-subscribe-channel id="inChannel"/>
<osgi:service id="inboundService" ref="inChannel" interface="org.springframework.integration.channel.SubscribableChannel"/>
</beans>

View File

@@ -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);
}
}
}

View File

@@ -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 <message> <file name> 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!");
}
}

View File

@@ -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);
}

View File

@@ -2,26 +2,20 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-1.0.xsd"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:file="http://www.springframework.org/schema/integration/file">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<bean class="org.springframework.integration.samples.filecopy.FileCopyDemoCommon"/>
<osgi:reference id="filesInService" interface="org.springframework.integration.channel.SubscribableChannel"/>
<integration:service-activator input-channel="filesInService"
output-channel="filesOut"
ref="exclaimer" method="exclaim"/>
<integration:bridge input-channel="filesInService" output-channel="filesOut"/>
<file:outbound-channel-adapter id="filesOut" directory="${java.io.tmpdir}/spring-integration-samples/output"/>
<bean id="exclaimer" class="org.springframework.integration.samples.filecopy.Exclaimer"/>
<!-- -->
<file:outbound-channel-adapter id="filesOut" directory="${java.io.tmpdir}/spring-integration-samples/output" delete-source-files="true" />
</beans>

View File

@@ -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();
// }
}

View File

@@ -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();
}
}