Spring Integration is a light-weight framework that follows the Spring programming model and aims to implement well-known Enterprise Integration Patterns. It allows you to declaratively create a chain of message consuming and message producing components with capabilities for message routing, filtering, etc.

You can easily use existing POJOs as parts of this 'message bus' without any need to change them or you can extend the framework's adapters to have greater control over the message handling behaviour.The following is an example for using Spring Integration with Stardust involving the handling of incoming files and a document repository.

Contents

File Archiver Example

This example consists of a Spring Integration solution with 3 components: The first is capable of monitoring a directory for incoming files, the second archives the file into a folder inside a JCR content repository (using Stardust's Document Management Service), and the third component starts a process in the Stardust runtime passing in the ID of the archived document to create an attachment.

Inbound File Adapter

This is an out-of-the-box Spring Integration adapter which monitors a directory for new files. Here's a configuration example in which a directory is polled every 3 seconds for new files starting with the name "test*" and every file processed is cached in a filter so it's not picked up a again in the next polling interval.. You can also see that every detected file is sent to the "fileMessages" channel.

JCR File Archive Service

In the below example, first of all, you see how a Spring Integration service-activator is defined to consume messages on the input-channel "fileMessages" using the custom jcrFileArchiveService. The output (which consists merely of the JCR ID of the archived document) is then sent on to the output-channel "jcrFileMessages".The JcrFileArchiveService class is a custom component which provides a thin wrapper around the Stardust DMS File Archiver and is capable of handling a message with a file payload. The wrapped Stardust DMS File Archiver connects to Stardust via Spring Remoting or EJB Remoting and it uses the DocumentManagementService to archive a document in a specific, configurable location.

Stardust Integration Controller

The last service in the sequence is configured to consume the messages on the "jcrFileMessages" channel containing the unique JCR document ID which was the output of the JCR File Archive Service. Since the payload of the message is a String, a simple POJO is used which takes the JCR document ID and passes it into Stardust as an argument when starting a process.

To avoid that Stardust's Spring application context complains about the placeholders that were added via the ipp-integration-context.xml when starting the server, you should add the property <property name="ignoreUnresolvablePlaceholders" value="true" /> to the property placeholder in the file <your-project-name>/carnot-processportal/WEB-INF/config/ipp/spring/carnot-spring-context.xml, so it looks like this

Create an ipp-integration.properties file into the directory <your-project-name>/carnot-processportal/WEB-INF/classes and change properties if you like, for example the location of the incoming directory of the files, as below.

Deploy the FileDemo process model(Attached Project archive) into the Stardust runtime. This model contains a single process definition with a data object called "JCR Document ID" which is used to pass the JCR ID of the archived document into the process. Once you have it in your Stardust process, it can be used to lookup the document handle as shown in the following screenshot.

Drop a file "test1.txt" into the directory configured in the ipp-integration.properties file. You should see log output of how it is picked up and used to start a process in the Eclipse Console.

Download

The complete Eclipse project containing the source code can be downloaded here.

Note: In order to run the JUnit TestCase in this project, you need an existing Stardust server (e.g. Tomcat RAD deployment). You also need to add the config/ directory to the classpath of the test run and configure the contained carnot.properties according to your environment.