reorganized osgi samples
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-Version: 1.0.3
|
||||
Bundle-Name: org.springframework.integration.samples.osgi.inbound
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-SymbolicName: org.springframework.integration.samples.osgi.inbound
|
||||
Bundle-Activator: org.springframework.integration.samples.osgi.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)"
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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"
|
||||
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">
|
||||
|
||||
<integration:gateway id="inboundGateway"
|
||||
service-interface="org.springframework.integration.samples.osgi.inbound.InboundGateway"
|
||||
default-request-channel="inboundChannel"/>
|
||||
|
||||
<integration:publish-subscribe-channel id="inboundChannel"/>
|
||||
|
||||
<osgi:service id="inboundService" ref="inboundChannel"
|
||||
interface="org.springframework.integration.channel.SubscribableChannel"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.osgi.inbound;
|
||||
|
||||
import java.io.File;
|
||||
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 + "'");
|
||||
File file = gateway.sendMessage(message, fileName);
|
||||
ci.println("Message sent and its contents are written to: " + file.getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.osgi.inbound;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.file.FileHeaders;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public interface InboundGateway {
|
||||
|
||||
public File sendMessage(String message, @Header(FileHeaders.FILENAME)String fileName);
|
||||
}
|
||||
Reference in New Issue
Block a user