INT-729 Added log4j configuration to the Hello World sample.

This commit is contained in:
Mark Fisher
2009-07-16 21:33:18 +00:00
parent b54382efae
commit 0201ae2eef
4 changed files with 48 additions and 15 deletions

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework">
<level value="warn" />
</logger>
<logger name="org.springframework.integration">
<level value="warn" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>

View File

@@ -17,6 +17,8 @@
package org.springframework.integration.samples.helloworld;
/**
* Simple POJO to be referenced from a Service Activator.
*
* @author Mark Fisher
*/
public class HelloService {

View File

@@ -48,12 +48,14 @@ public class HelloWorldDemo {
demo.performDemo(applicationContext);
applicationContext.stop();
}
public void performDemo(ApplicationContext applicationContext){
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("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload());
}
}

View File

@@ -13,6 +13,7 @@
* 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;
@@ -21,35 +22,35 @@ 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.
* An OSGi BundleActivator which will register a ServiceListener to listen
* for an ApplicationContext published event. Once the event is received,
* the HelloWorldDemo will be executed.
*
* @author Oleg Zhurakousky
* @since 1.0.3
*/
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))){
if (context.getBundle().getSymbolicName().equals(sr.getProperty(Constants.BUNDLE_SYMBOLICNAME))) {
ApplicationContext applicationContext = (ApplicationContext) context.getService(sr);
new HelloWorldDemo().performDemo(applicationContext);
}
}
}
}