jazzmann
Sep 30th, 2009, 06:03 AM
Hi,
our standalone application uses Spring Integration.
It listens to a directory in interval.
New files are read and a bean will create some entities in a database rest upon the content of these files.
There is a main application, where the system is started.
package org.foo.solarintegration.main;
import org.springframework.context.support.AbstractApplic ationContext;
import org.springframework.context.support.ClassPathXmlAp plicationContext;
public class App {
static AbstractApplicationContext context;
public static void main(String[] args) {
context = new ClassPathXmlApplicationContext("beans.xml");
}
public static AbstractApplicationContext getContext() {
return context;
}
}
Now with OSGI, in the Spring DM Server, the Web bundle should start the work in the Integration bundle.
First try was: the web bundle calls a method in the integration bundle, wich creates the new context like in the upper code.
But this won't work.
I need something like the following.
The web bundle uses a gateway to the integration bundle.
Via this gateway the integration work should be started.
Here is a good example how to use Spring Integration in OSGI with gateways:
http://blog.springsource.com/2009/07/28/spring-integration-103-samples-just-add-osgi/
The inbound uses a gateway to the outbound wich offers a file:outbound-gateway to write files containing messages send by the inbound.
Here is the XML configuration file in the META-INF/spring folder which is similar to the configuration in the Spring Integration standalone application:
<?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:p="http://www.springframework.org/schema/p"
xmlns:integration="http://www.springframework.org/schema/integration" xmlns:file="http://www.springframework.org/schema/integration/file"
xmlns:osgi="http://www.springframework.org/schema/osgi"
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/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
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<!--
SPRING INTEGRATION
-->
<!-- process property placeholders using a property file -->
<context:property-placeholder location="META-INF/spring/net-env.properties" />
<file:inbound-channel-adapter directory="file:${incoming.directory}" auto-startup="true"
filename-pattern="${incoming.pattern}" id="incoming" channel="files" />
<integration:channel id="files" datatype="java.io.File">
<integration:queue capacity="10" />
</integration:channel>
<!-- Gateway which creates new jobs in the database -->
<bean id="registerJob" class="org.foo.integration.RegisterSample" />
<!-- Call the specified bean with message payloads of the input channel -->
<integration:service-activator input-channel="files" ref="registerJob" method="register" />
<!-- -->
<integration:poller id="poller" default="true" max-messages-per-poll="3">
<integration:interval-trigger interval="2000" />
</integration:poller>
<!-- -->
<osgi:reference id="hibernateSampleDAOImpl" interface="org.foo.SampleDAO" />
</beans>
Is the application context created automativally by DM Server?
This code snippet --auto-startup="true"-- has no effect.
So, how to solve this? :)
King regards
Alex
our standalone application uses Spring Integration.
It listens to a directory in interval.
New files are read and a bean will create some entities in a database rest upon the content of these files.
There is a main application, where the system is started.
package org.foo.solarintegration.main;
import org.springframework.context.support.AbstractApplic ationContext;
import org.springframework.context.support.ClassPathXmlAp plicationContext;
public class App {
static AbstractApplicationContext context;
public static void main(String[] args) {
context = new ClassPathXmlApplicationContext("beans.xml");
}
public static AbstractApplicationContext getContext() {
return context;
}
}
Now with OSGI, in the Spring DM Server, the Web bundle should start the work in the Integration bundle.
First try was: the web bundle calls a method in the integration bundle, wich creates the new context like in the upper code.
But this won't work.
I need something like the following.
The web bundle uses a gateway to the integration bundle.
Via this gateway the integration work should be started.
Here is a good example how to use Spring Integration in OSGI with gateways:
http://blog.springsource.com/2009/07/28/spring-integration-103-samples-just-add-osgi/
The inbound uses a gateway to the outbound wich offers a file:outbound-gateway to write files containing messages send by the inbound.
Here is the XML configuration file in the META-INF/spring folder which is similar to the configuration in the Spring Integration standalone application:
<?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:p="http://www.springframework.org/schema/p"
xmlns:integration="http://www.springframework.org/schema/integration" xmlns:file="http://www.springframework.org/schema/integration/file"
xmlns:osgi="http://www.springframework.org/schema/osgi"
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/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
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<!--
SPRING INTEGRATION
-->
<!-- process property placeholders using a property file -->
<context:property-placeholder location="META-INF/spring/net-env.properties" />
<file:inbound-channel-adapter directory="file:${incoming.directory}" auto-startup="true"
filename-pattern="${incoming.pattern}" id="incoming" channel="files" />
<integration:channel id="files" datatype="java.io.File">
<integration:queue capacity="10" />
</integration:channel>
<!-- Gateway which creates new jobs in the database -->
<bean id="registerJob" class="org.foo.integration.RegisterSample" />
<!-- Call the specified bean with message payloads of the input channel -->
<integration:service-activator input-channel="files" ref="registerJob" method="register" />
<!-- -->
<integration:poller id="poller" default="true" max-messages-per-poll="3">
<integration:interval-trigger interval="2000" />
</integration:poller>
<!-- -->
<osgi:reference id="hibernateSampleDAOImpl" interface="org.foo.SampleDAO" />
</beans>
Is the application context created automativally by DM Server?
This code snippet --auto-startup="true"-- has no effect.
So, how to solve this? :)
King regards
Alex