INT-718. OSGi-enabled the sample. README file is included.
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
@@ -15,9 +20,16 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
||||
17
spring-integration-samples/helloworld/README.txt
Normal file
17
spring-integration-samples/helloworld/README.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
Instructions for running HelloWorldDemo sample
|
||||
-------------------------------------------------------------------------------
|
||||
1. See README.txt of the parent directory
|
||||
|
||||
2. To run this sample as stand alone application simply execute HelloWorldDemo class
|
||||
located in org.springframework.integration.samples.helloworld package
|
||||
|
||||
3. This sample is also configured to be a valid OSGi bundle. This means you can deploy generated JAR
|
||||
into OSGi environment providing that Spring Integration bundles as well as other prerequisites
|
||||
(e.g., Spring Framework were installed).
|
||||
For example: To deploy it on SpringSource dmServer simply drop helloworld-1.0.3.jar file, located
|
||||
in the 'target' directory, to the 'pickup' directory of the dmServer.
|
||||
You should see the following output in the trace file:
|
||||
|
||||
System.out I ==> HelloWorldDemo: Hello World
|
||||
|
||||
Happy integration :-)
|
||||
@@ -1,11 +1,45 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>spring-integration-samples</artifactId>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<version>1.0.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>helloworld</groupId>
|
||||
<artifactId>helloworld</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</project>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>spring-integration-samples</artifactId>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<version>1.0.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>helloworld</groupId>
|
||||
<artifactId>helloworld</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
<version>3.4.2.R34x_v20080826-1230</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>false</filtering>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
<includes>
|
||||
<include>META-INF/spring/*.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.samples.helloworld;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
@@ -37,17 +38,22 @@ import org.springframework.integration.message.StringMessage;
|
||||
* element) in 'helloWorldDemo.xml' within this same package.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class HelloWorldDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("helloWorldDemo.xml", HelloWorldDemo.class);
|
||||
ChannelResolver channelResolver = new BeanFactoryChannelResolver(context);
|
||||
HelloWorldDemo demo = new HelloWorldDemo();
|
||||
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("helloWorldDemo.xml", HelloWorldDemo.class);
|
||||
demo.performDemo(applicationContext);
|
||||
applicationContext.stop();
|
||||
}
|
||||
|
||||
public void performDemo(ApplicationContext applicationContext){
|
||||
ChannelResolver channelResolver = new BeanFactoryChannelResolver(applicationContext);
|
||||
MessageChannel inputChannel = channelResolver.resolveChannelName("inputChannel");
|
||||
PollableChannel outputChannel = (PollableChannel) channelResolver.resolveChannelName("outputChannel");
|
||||
inputChannel.send(new StringMessage("World"));
|
||||
System.out.println(outputChannel.receive(0).getPayload());
|
||||
context.stop();
|
||||
System.out.println("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.helloworld;
|
||||
|
||||
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.integration.samples.helloworld.HelloWorldDemo;
|
||||
/**
|
||||
* 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 HelloWorldBundleActivator implements BundleActivator, ServiceListener{
|
||||
private BundleContext context;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
this.context = context;
|
||||
context.addServiceListener(this);
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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);
|
||||
new HelloWorldDemo().performDemo(applicationContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-Version: 1.0.3
|
||||
Bundle-Name: org.springframework.integration.samples.helloworld
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-SymbolicName: org.springframework.integration.samples.helloworld
|
||||
Bundle-Activator: org.springframework.integration.samples.osgi.helloworld.HelloWorldBundleActivator
|
||||
Import-Package: org.osgi.framework;version="[1.4.0,1.4.0]"
|
||||
Import-Library: org.aspectj;version="[1.6.2.RELEASE,1.6.2.RELEASE]",
|
||||
org.springframework.spring;version="[2.5.6.A,2.5.6.A]"
|
||||
Import-Bundle: org.springframework.integration;version="(1.0.2,1.0.4)"
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<channel id="inputChannel"/>
|
||||
|
||||
<channel id="outputChannel">
|
||||
<queue capacity="10"/>
|
||||
</channel>
|
||||
|
||||
<service-activator input-channel="inputChannel"
|
||||
output-channel="outputChannel"
|
||||
method="sayHello">
|
||||
<beans:bean class="org.springframework.integration.samples.helloworld.HelloService"/>
|
||||
</service-activator>
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user