Jump to: navigation, search

Difference between revisions of "Stardust/Knowledge Base/Integration/Spring Integration"

Line 57: Line 57:
 
==== IPP Integration Controller  ====
 
==== IPP 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.<br>
+
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.<br>  
 
<pre>&lt;!-- Startdust start process service --&gt;
 
<pre>&lt;!-- Startdust start process service --&gt;
 
&lt;si:service-activator
 
&lt;si:service-activator
Line 63: Line 63:
 
ref="ippIntegrationController"
 
ref="ippIntegrationController"
 
method="startProcessWithDocumentId"/&gt;</pre><pre>&lt;bean id="ippIntegrationController"
 
method="startProcessWithDocumentId"/&gt;</pre><pre>&lt;bean id="ippIntegrationController"
 +
 
class="com.infinity.bpm.spring.integration.IppIntegrationController"&gt;
 
class="com.infinity.bpm.spring.integration.IppIntegrationController"&gt;
 
&lt;property name="startProcessDefinitionId" value="FileDemo"/&gt;
 
&lt;property name="startProcessDefinitionId" value="FileDemo"/&gt;
Line 68: Line 69:
 
&lt;property name="ippServiceController" ref="ippServiceWrapper"/&gt;
 
&lt;property name="ippServiceController" ref="ippServiceWrapper"/&gt;
 
&lt;/bean&gt;
 
&lt;/bean&gt;
 +
 +
 +
</pre>
 +
==== Installation How-To<br>  ====
 +
 +
To install and run this example, follow these steps:<br>
 +
 +
*Create a Stardust Dynamic Web Project in Eclipse<br>
 +
*Create a Spring Integration application context file as below and place it into the directory &lt;your-project-name&gt;/carnot-processportal/WEB-INF/config/ipp/spring<br>
 +
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
 +
&lt;beans xmlns="http://www.springframework.org/schema/beans"
 +
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +
      xmlns:si="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.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"&gt;
 +
&lt;bean id="integrationPropertyConfigurer"
 +
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
 +
&lt;property name="location" value="classpath:ipp-integration.properties" /&gt;
 +
&lt;/bean&gt;
 +
    &lt;!-- Inbound adapter reading files from a directory --&gt;
 +
&lt;file:inbound-channel-adapter
 +
directory="file:${inboundFileAdapter.directory}"
 +
channel="fileMessages"
 +
filter="incomingFileFilter" /&gt;
 +
&lt;!-- Poller for incoming files --&gt;
 +
&lt;si:poller default="true" max-messages-per-poll="10"&gt;
 +
&lt;si:interval-trigger interval="3" time-unit="SECONDS" /&gt;
 +
    &lt;!-- si:transactional transaction-manager="txManager"
 +
                  propagation="REQUIRES_NEW"
 +
                  isolation="REPEATABLE_READ"
 +
                  timeout="10000"
 +
                  read-only="false"/--&gt;
 +
&lt;/si:poller&gt;
 +
&lt;!-- Queue channel for file messages --&gt;
 +
&lt;si:channel id="fileMessages"&gt;
 +
&lt;si:queue capacity="10" /&gt;
 +
&lt;/si:channel&gt;
 +
&lt;!-- Queue channel for archived file messages --&gt;
 +
&lt;si:channel id="jcrFileMessages"&gt;
 +
&lt;si:queue capacity="10" /&gt;
 +
&lt;/si:channel&gt;
 +
&lt;!-- Customized composite filter for incoming files --&gt;
 +
&lt;bean id="incomingFileFilter"
 +
class="org.springframework.integration.file.CompositeFileListFilter"&gt;
 +
&lt;constructor-arg&gt;
 +
&lt;list&gt;
 +
&lt;bean class="org.springframework.integration.file.AcceptOnceFileListFilter" /&gt;
 +
&lt;bean class="org.springframework.integration.file.PatternMatchingFileListFilter"&gt;
 +
&lt;constructor-arg value="^test.*$"/&gt;
 +
&lt;/bean&gt;
 +
&lt;/list&gt;
 +
&lt;/constructor-arg&gt;
 +
&lt;/bean&gt;             
 +
&lt;!-- JCR file archiving service --&gt;
 +
&lt;si:service-activator input-channel="fileMessages"
 +
                      output-channel="jcrFileMessages"
 +
                      ref="jcrFileArchiveService"/&gt;
 +
&lt;!-- IPP start process service --&gt;
 +
&lt;si:service-activator input-channel="jcrFileMessages"
 +
                      ref="ippIntegrationController"
 +
                      method="startProcessWithDocumentId"/&gt;
 +
&lt;!-- Custom Beans --&gt;
 +
&lt;bean id="jcrFileArchiveService"
 +
class="com.infinity.bpm.spring.integration.file.JcrFileArchiveService"&gt;
 +
&lt;property name="archiver" ref="ippDmsFileArchiver" /&gt;
 +
&lt;/bean&gt;
 +
&lt;bean id="ippDmsFileArchiver"
 +
class="com.infinity.bpm.spring.integration.IppDmsFileArchiver"&gt;
 +
&lt;property name="ippServiceWrapper" ref="ippServiceWrapper"/&gt;
 +
&lt;property name="createOperator" value="${ippDmsFileArchiver.createOperator}"/&gt;
 +
&lt;property name="documentType" value="${ippDmsFileArchiver.documentType}"/&gt;
 +
&lt;property name="rootFolderPath" value="${ippDmsFileArchiver.rootFolderPath}" /&gt;
 +
&lt;/bean&gt;
 +
&lt;bean id="ippIntegrationController"
 +
class="com.infinity.bpm.spring.integration.IppIntegrationController"&gt;
 +
&lt;property name="startProcessDefinitionId" value="${ippIntegrationController.startProcessDefinitionId}"/&gt;
 +
&lt;property name="dataIdDocumentId" value="${ippIntegrationController.dataIdDocumentId}"/&gt;
 +
&lt;property name="ippServiceController" ref="ippServiceWrapper"/&gt;
 +
&lt;/bean&gt;
 +
&lt;bean id="ippServiceWrapper" class="com.infinity.bpm.spring.integration.IppServiceWrapper"&gt;
 +
&lt;property name="user" value="${ippServiceWrapper.user}" /&gt;
 +
&lt;property name="password" value="${ippServiceWrapper.password}" /&gt;
 +
&lt;/bean&gt;
 +
&lt;/beans&gt;
 +
 +
</pre><pre>
 
</pre>
 
</pre>
<br>
 

Revision as of 07:24, 27 November 2011

Spring Integration

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 behavior.The following is an example for using Spring Integration with Stardust involving the handling of incoming files and a document repository.

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.

<!-- Inbound adapter reading files from a directory -->
<file:inbound-channel-adapter
	directory="file:C:/temp/incoming"
	channel="fileMessages"
	filter="incomingFileFilter" />
<!-- Poller for incoming files -->

<si:poller default="true" max-messages-per-poll="10"> <si:interval-trigger interval="3" time-unit="SECONDS" />

</si:poller>
<!-- Customized composite filter for incoming files -->

<bean id="incomingFileFilter" class="org.springframework.integration.file.CompositeFileListFilter"> <constructor-arg> <list> <bean class="org.springframework.integration.file.AcceptOnceFileListFilter" /> <bean class="org.springframework.integration.file.PatternMatchingFileListFilter"> <constructor-arg value="^test.*$"/> </bean> </list> </constructor-arg> </bean>

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 (wich 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.

<!-- JCR file archiving service -->
<si:service-activator
	input-channel="fileMessages"
	output-channel="jcrFileMessages"
	ref="jcrFileArchiveService"/>
<bean id="jcrFileArchiveService"

class="com.infinity.bpm.spring.integration.file.JcrFileArchiveService"> <property name="archiver" ref="ippDmsFileArchiver" /> </bean>

<bean id="ippDmsFileArchiver"

class="com.infinity.bpm.spring.integration.IppDmsFileArchiver"> <property name="ippServiceWrapper" ref="ippServiceWrapper"/> <property name="createOperator" value="Automatic Archival"/> <property name="documentType" value="Text File"/> </bean>

IPP 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.

<!-- Startdust start process service -->
<si:service-activator
	input-channel="jcrFileMessages"
	ref="ippIntegrationController"
	method="startProcessWithDocumentId"/>
<bean id="ippIntegrationController"

class="com.infinity.bpm.spring.integration.IppIntegrationController"> <property name="startProcessDefinitionId" value="FileDemo"/> <property name="dataIdDocumentId" value="JCRDocumentID"/> <property name="ippServiceController" ref="ippServiceWrapper"/> </bean>


Installation How-To

To install and run this example, follow these steps:

  • Create a Stardust Dynamic Web Project in Eclipse
  • Create a Spring Integration application context file as below and place it into the directory <your-project-name>/carnot-processportal/WEB-INF/config/ipp/spring
<?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:si="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.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">
	<bean id="integrationPropertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="location" value="classpath:ipp-integration.properties" />
	</bean>
    <!-- Inbound adapter reading files from a directory -->
	<file:inbound-channel-adapter
		directory="file:${inboundFileAdapter.directory}"
		channel="fileMessages"
		filter="incomingFileFilter" />
	<!-- Poller for incoming files -->
	<si:poller default="true" max-messages-per-poll="10">
		<si:interval-trigger interval="3" time-unit="SECONDS" />
	    <!-- si:transactional transaction-manager="txManager"
                  propagation="REQUIRES_NEW"
                  isolation="REPEATABLE_READ"
                  timeout="10000"
                  read-only="false"/-->		
	</si:poller>
	<!-- Queue channel for file messages -->
	<si:channel id="fileMessages">
		<si:queue capacity="10" />
	</si:channel>
	<!-- Queue channel for archived file messages -->
	<si:channel id="jcrFileMessages">
		<si:queue capacity="10" />
	</si:channel>
	<!-- Customized composite filter for incoming files -->
	<bean id="incomingFileFilter"
		class="org.springframework.integration.file.CompositeFileListFilter">
		<constructor-arg>
			<list>
				<bean class="org.springframework.integration.file.AcceptOnceFileListFilter" />
				<bean class="org.springframework.integration.file.PatternMatchingFileListFilter">
					<constructor-arg value="^test.*$"/>
				</bean>
			</list>
		</constructor-arg>
	</bean>              
	<!-- JCR file archiving service -->
	<si:service-activator input-channel="fileMessages"
                      output-channel="jcrFileMessages"
                      ref="jcrFileArchiveService"/>
	<!-- IPP start process service -->
	<si:service-activator input-channel="jcrFileMessages"
                      ref="ippIntegrationController"
                      method="startProcessWithDocumentId"/>
	<!-- Custom Beans -->
	<bean id="jcrFileArchiveService"
		class="com.infinity.bpm.spring.integration.file.JcrFileArchiveService">
		<property name="archiver" ref="ippDmsFileArchiver" />
	</bean>
	<bean id="ippDmsFileArchiver"
		class="com.infinity.bpm.spring.integration.IppDmsFileArchiver">
		<property name="ippServiceWrapper" ref="ippServiceWrapper"/>
		<property name="createOperator" value="${ippDmsFileArchiver.createOperator}"/>
		<property name="documentType" value="${ippDmsFileArchiver.documentType}"/>
		<property name="rootFolderPath" value="${ippDmsFileArchiver.rootFolderPath}" />
	</bean>
	<bean id="ippIntegrationController"
		class="com.infinity.bpm.spring.integration.IppIntegrationController">
		<property name="startProcessDefinitionId" value="${ippIntegrationController.startProcessDefinitionId}"/>
		<property name="dataIdDocumentId" value="${ippIntegrationController.dataIdDocumentId}"/>
		<property name="ippServiceController" ref="ippServiceWrapper"/>
	</bean>
	<bean id="ippServiceWrapper" class="com.infinity.bpm.spring.integration.IppServiceWrapper">
		<property name="user" value="${ippServiceWrapper.user}" />
		<property name="password" value="${ippServiceWrapper.password}" />
	</bean>
</beans>