[jboss-svn-commits] JBL Code SVN: r20138 - in labs/jbossesb/workspace/sandbox: jbossesb-ext and 26 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri May 23 10:35:29 EDT 2008
Author: tfennelly
Date: 2008-05-23 10:35:29 -0400 (Fri, 23 May 2008)
New Revision: 20138
Added:
labs/jbossesb/workspace/sandbox/jbossesb-ext/
labs/jbossesb/workspace/sandbox/jbossesb-ext/README.txt
labs/jbossesb/workspace/sandbox/jbossesb-ext/build.properties
labs/jbossesb/workspace/sandbox/jbossesb-ext/build.xml
labs/jbossesb/workspace/sandbox/jbossesb-ext/lib/
labs/jbossesb/workspace/sandbox/jbossesb-ext/lib/ext/
labs/jbossesb/workspace/sandbox/jbossesb-ext/lib/ext/build-time/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/FileListener.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/AbstractFileMessageComposer.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileBytesMessageComposer.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileReaderMessageComposer.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileStreamMessageComposer.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparator.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/FileSelector.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilter.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelector.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycle.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleFactory.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycle.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleConfig.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleFactory.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/deployment.xml
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/jboss-esb.xml
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileListenerUnitTest.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileTestAction.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparatorUnitTest.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilterUnitTest.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelectorUnitTest.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/lifecycle/
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleUnitTest.java
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/listener-config-01.xml
labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/resources/
Removed:
labs/jbossesb/workspace/sandbox/HttpRouter/
Log:
Added FileListener stuff.
Deleted the HttpRouter - it's in the main codebase now.
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/README.txt
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/README.txt (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/README.txt 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,14 @@
+To Build
+========
+Drop the entire folder into the product/services folder of your local
+JBoss ESB source SVN checkout. Run "ant clean test". This will compile and
+assemble the "jbossesb-est.esb" service.
+
+To Use
+======
+Drop the "jbossesb-est.esb" service into your ESB/AS "server/<server>/deploy"
+directory.
+
+Documentation
+=============
+Just run "ant javadoc" to generate the javadoc to the "build/javadoc" dir.
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/build.properties
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/build.properties (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/build.properties 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,3 @@
+esb.product.lib.dir=../../build/jbossesb/lib
+esb.product.lib.ext=../../lib/ext
+services.base.build=../base-project-build.xml
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/build.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/build.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/build.xml (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/build.xml 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,14 @@
+<project name="jbossesb-ext" default="test" basedir=".">
+
+ <property file="build.properties"/>
+ <!-- Import the base Ant build script... -->
+ <import file="${services.base.build}"/>
+
+ <target name="test" depends="base.test"/>
+
+ <target name="javadoc" depends="compile" description="Build Javadoc">
+ <mkdir dir="build/javadoc" />
+ <javadoc sourcepath="src/main/java" packagenames="org.jboss.*" destdir="build/javadoc" classpathref="classpath" />
+ </target>
+
+</project>
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/build.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/FileListener.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/FileListener.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/FileListener.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.ScheduledEventMessageComposer;
+import org.jboss.soa.esb.listeners.file.composers.FileBytesMessageComposer;
+import org.jboss.soa.esb.listeners.file.composers.FileReaderMessageComposer;
+import org.jboss.soa.esb.listeners.file.filtering.FileSelector;
+import org.jboss.soa.esb.listeners.file.filtering.WildcardFileSelector;
+import org.jboss.soa.esb.listeners.file.lifecycle.DefaultFileLifecycleFactory;
+import org.jboss.soa.esb.listeners.file.lifecycle.FileLifecycle;
+import org.jboss.soa.esb.listeners.file.lifecycle.FileLifecycleFactory;
+import org.jboss.soa.esb.listeners.message.MessageComposer;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.schedule.SchedulingException;
+
+import java.io.File;
+
+/**
+ * Simple schedule based file listener.
+ * <p/>
+ * Example config:<br/>
+ * <pre>
+ * <scheduled-listener name="service-01-listener" scheduleidref="1-sec-trigger" event-processor="org.jboss.soa.esb.listeners.file.FileListener">
+ * <property name="composer-class" value="FileReaderMessageComposer" /> <!-- (Optional) Default is {@link FileBytesMessageComposer}. -->
+ * <property name="fileDir" value="./target/filesin" />
+ * <property name="matchPattern" value="*.input" />
+ * <property name="workingRenamePattern" value="${prefix}.${suffix}.working" /> <!-- (Optional) Default is "${prefix}.${suffix}.working" -->
+ * <property name="processedRenamePattern" value="${prefix}.processed" /> <!-- (Optional) File deleted if unspecified. -->
+ * <property name="errorRenamePattern" value="${prefix}.error" /> <!-- (Optional) Default is "${prefix}.${suffix}.error" -->
+ * <property name="fileSelector" value="<class-name>" /> <!-- (Optional) Default {@link WildcardFileSelector} -->
+ * <property name="fileLifecycleFactory" value="<class-name>" /> <!-- (Optional) Default {@link DefaultFileLifecycleFactory} -->
+ * </scheduled-listener>
+ * </pre>
+ * <p/>
+ * Note how this listener supports abbreviated "composer-class" property values for
+ * composer implementations defined in the {@link org.jboss.soa.esb.listeners.file.composers}
+ * package.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class FileListener implements ScheduledEventMessageComposer {
+
+ private static Logger logger = Logger.getLogger(FileListener.class);
+
+ // Have to use a threadlocal to store the lifecycle. Would be nicer to store this
+ // in a pipeline context, but the ESB doesn't have such a construct.
+ public static ThreadLocal<FileLifecycle> fileLifecycleTL = new ThreadLocal<FileLifecycle>();
+
+ public static final String FILE_DIR = "fileDir";
+ public static final String FILE_SELECTOR = "fileSelector";
+ public static final String FILE_LIFECYCLE = "fileLifecycleFactory";
+
+ private File dir;
+ private FileSelector fileSelector;
+ private FileLifecycleFactory fileLifecycleFactory;
+ private MessageComposer<FileLifecycle> messageComposer;
+
+ public void initialize(ConfigTree configTree) throws ConfigurationException {
+ // Config the file listen directory...
+ dir = new File(configTree.getRequiredAttribute(FILE_DIR));
+ if(!dir.exists()) {
+ throw new ConfigurationException("Directory '" + dir.getAbsolutePath() + "' doesn't exist.");
+ }
+ if(!dir.isDirectory()) {
+ throw new ConfigurationException("File '" + dir.getAbsolutePath() + "' is not a directory.");
+ }
+ if(!dir.canRead() || !dir.canWrite()) {
+ throw new ConfigurationException("Directory '" + dir.getAbsolutePath() + "' must be readable and writeable.");
+ }
+
+ // Config the file selector...
+ fileSelector = FileSelector.Factory.newInstance(configTree.getAttribute(FILE_SELECTOR, WildcardFileSelector.class.getName()), configTree);
+
+ // Config the file lifecycle factory...
+ String fileLifecycleFactoryName = configTree.getAttribute(FILE_LIFECYCLE, DefaultFileLifecycleFactory.class.getName());
+ fileLifecycleFactory = FileLifecycleFactory.Factory.newInstance(fileLifecycleFactoryName, configTree);
+
+ // Config the message composer...
+ String composerClassName = getMessageComposerClassName(configTree);
+ try {
+ messageComposer = MessageComposer.Factory.getInstance(composerClassName, configTree);
+ } catch (MessageDeliverException e) {
+ throw new ConfigurationException("Unable to instantiate composer class '" + composerClassName + "'.", e);
+ }
+ }
+
+ public Message composeMessage() throws SchedulingException {
+ fileLifecycleTL.remove();
+
+ File[] files = fileSelector.select(dir);
+
+ if(files.length > 0) {
+ FileLifecycle fileLifecycle = fileLifecycleFactory.newInstance();
+
+ fileLifecycleTL.set(fileLifecycle);
+ for (int i = 0; i < files.length; i++) {
+ File file = files[i];
+
+ fileLifecycle.setFile(file);
+ if(fileLifecycle.toWorking() != null) {
+ break;
+ } else if(i == files.length - 1) {
+ // No more file. Just return and come back in again onSchedule ...
+ return null;
+ } else{
+ // Another listener has already transitioned the file to working (in between calls). Try the next file...
+ }
+ }
+
+ try {
+ return messageComposer.compose(fileLifecycle);
+ } catch (MessageDeliverException e) {
+ throw new SchedulingException("Unable to compose message from file '" + files[0].getAbsolutePath() + "'.", e);
+ }
+ }
+
+ return null;
+ }
+
+ public Message onProcessingComplete(Message message) throws SchedulingException {
+ FileLifecycle fileLifecycle = fileLifecycleTL.get();
+
+ try {
+ // The composer can decide whether or not to write out a response...
+ if(message != null) {
+ messageComposer.decompose(message, fileLifecycle);
+ }
+ } catch (MessageDeliverException e) {
+ throw new SchedulingException("Unable to decompose message from file '" + fileLifecycle.getFile().getAbsolutePath() + "'.", e);
+ } finally {
+ if(fileLifecycle != null) {
+ // We've no way of knowing whether there was an error or not in the pipeline.
+ // The pipeline needs a context of some sort that's available to the components
+ // around it (such as this component). Always transitioning to
+ // "processed" for now. Need to make a change to the ScheduleListener to get it
+ // check the return from the pipeline processor...
+ fileLifecycle.toProcessed();
+ }
+ }
+
+ return null;
+ }
+
+ private String getMessageComposerClassName(ConfigTree configTree) throws ConfigurationException {
+ String composerClassName = configTree.getAttribute(ListenerTagNames.GATEWAY_COMPOSER_CLASS_TAG, FileBytesMessageComposer.class.getName());
+
+ // We may need to expand the classname...
+ if(composerClassName.indexOf('.') == -1) {
+ composerClassName = FileBytesMessageComposer.class.getPackage().getName() + "." + composerClassName;
+ }
+
+ return composerClassName;
+ }
+
+ public void uninitialize() {
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/FileListener.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/AbstractFileMessageComposer.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/AbstractFileMessageComposer.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/AbstractFileMessageComposer.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.composers;
+
+import org.jboss.soa.esb.listeners.file.lifecycle.FileLifecycle;
+import org.jboss.soa.esb.listeners.message.MessageComposer;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.apache.log4j.Logger;
+
+import java.io.*;
+
+/**
+ * Abstract File MessageComposer.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class AbstractFileMessageComposer<T extends FileLifecycle> implements MessageComposer<T> {
+ private static Logger logger = Logger.getLogger(FileBytesMessageComposer.class);
+ public static final String PROP_FILE_LIFECYCLE = "in-file-lifecycle";
+ public static final String PROP_FILE_OBJ = "in-file-obj";
+ public static final String PROP_FILE_PATH = "in-file-path";
+ public static final String PROP_FILE_LENGTH = "in-file-length";
+ public static final String PROP_FILE_LASTMOD = "in-file-lastmod";
+
+ public Message compose(T fileLifecycle) throws MessageDeliverException {
+ AssertArgument.isNotNull(fileLifecycle, "fileLifecycle");
+
+ File currentFile = fileLifecycle.getFile();
+ if(!currentFile.exists()) {
+ throw new MessageDeliverException("Invalid File payload. File '" + currentFile.getAbsolutePath() + "' doesn't exist.");
+ }
+
+ Message message;
+ try {
+ Object payload = getPayload(currentFile);
+
+ message = MessageFactory.getInstance().getMessage();
+ message.getBody().add(payload);
+
+ // We store the original payload on the lifecycle. Might be needed during cleanup...
+ fileLifecycle.setPayload(payload);
+ } catch (IOException e) {
+ throw new MessageDeliverException("Error reading input file '" + currentFile.getAbsolutePath() + "'.", e);
+ } catch(Throwable t) {
+ throw new MessageDeliverException("Error creating message from input file '" + currentFile.getAbsolutePath() + "'.", t);
+ }
+
+ // Add some metadate about the file....
+ message.getProperties().setProperty(PROP_FILE_LIFECYCLE, fileLifecycle);
+ message.getProperties().setProperty(PROP_FILE_OBJ, currentFile);
+ message.getProperties().setProperty(PROP_FILE_PATH, currentFile.getAbsolutePath());
+ message.getProperties().setProperty(PROP_FILE_LENGTH, currentFile.length());
+ message.getProperties().setProperty(PROP_FILE_LASTMOD, currentFile.lastModified());
+
+ return message;
+ }
+
+ protected abstract Object getPayload(File file) throws IOException;
+
+ public Object decompose(Message message, T fileLifecycle) throws MessageDeliverException {
+ Object initialPayload = fileLifecycle.getPayload();
+ Object payload = message.getBody().get();
+
+ // If the compose step opened a stream, reader etc... make sure it's closed...
+ if(initialPayload instanceof Closeable) {
+ try {
+ ((Closeable)initialPayload).close();
+ } catch (Throwable e) {
+ if(logger.isDebugEnabled()) {
+ logger.debug("File '" + fileLifecycle.getFile().getAbsolutePath() + "' already closed.");
+ }
+ }
+ }
+
+ if(payload != null) {
+ writeResultPayload(payload.toString(), fileLifecycle.getFile());
+ }
+
+ return payload;
+ }
+
+ protected void writeResultPayload(Object payload, File file) throws MessageDeliverException {
+ OutputStream outputStream = null;
+ try {
+ outputStream = new FileOutputStream(file);
+ if(payload instanceof String) {
+ outputStream.write(((String)payload).getBytes());
+ } else if(payload instanceof byte[]) {
+ outputStream.write((byte[])payload);
+ } else {
+ throw new MessageDeliverException("Failed to write to output file '" + file.getAbsolutePath() + "'. Pipeline must produce either a String or byte[] payload.");
+ }
+ } catch (FileNotFoundException e) {
+ throw new MessageDeliverException("Failed to write to output file '" + file.getAbsolutePath() + "'.", e);
+ } catch (IOException e) {
+ throw new MessageDeliverException("Failed to write to output file '" + file.getAbsolutePath() + "'.", e);
+ } finally {
+ if(outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (IOException e) {
+ logger.error("Exception while closing output stream to file '" + file.getAbsolutePath() + "'.", e);
+ }
+ }
+ }
+ }
+
+ public static FileLifecycle getFileLifecycle(Message message) {
+ return (FileLifecycle) message.getProperties().getProperty(PROP_FILE_LIFECYCLE);
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/AbstractFileMessageComposer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileBytesMessageComposer.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileBytesMessageComposer.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileBytesMessageComposer.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.composers;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.MessageComposer;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.listeners.file.lifecycle.FileLifecycle;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.util.FileUtil;
+
+import java.io.*;
+
+/**
+ * Local file byte[] message composer.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class FileBytesMessageComposer<T extends FileLifecycle> extends AbstractFileMessageComposer<T> {
+
+ public void setConfiguration(ConfigTree config) throws ConfigurationException {
+ }
+
+ protected Object getPayload(File file) throws IOException {
+ return FileUtil.readFile(file);
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileBytesMessageComposer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileReaderMessageComposer.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileReaderMessageComposer.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileReaderMessageComposer.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.composers;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.listeners.file.lifecycle.FileLifecycle;
+import org.jboss.soa.esb.message.Message;
+
+import java.io.*;
+
+/**
+ * Local file {@link Reader} message composer.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class FileReaderMessageComposer<T extends FileLifecycle> extends AbstractFileMessageComposer<T> {
+
+ private String encoding;
+
+ public void setConfiguration(ConfigTree config) throws ConfigurationException {
+ encoding = config.getAttribute("encoding", "UTF-8");
+ }
+
+ protected Object getPayload(File file) throws IOException {
+ return new InputStreamReader(new FileInputStream(file), encoding);
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileReaderMessageComposer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileStreamMessageComposer.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileStreamMessageComposer.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileStreamMessageComposer.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.composers;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.listeners.file.lifecycle.FileLifecycle;
+import org.jboss.soa.esb.message.Message;
+
+import java.io.*;
+
+/**
+ * Local file {@link java.io.InputStream} message composer.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class FileStreamMessageComposer<T extends FileLifecycle> extends AbstractFileMessageComposer<T> {
+
+ public void setConfiguration(ConfigTree config) throws ConfigurationException {
+ }
+
+ protected Object getPayload(File file) throws IOException {
+ return new FileInputStream(file);
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/composers/FileStreamMessageComposer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparator.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparator.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparator.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.filtering;
+
+import java.io.File;
+import java.util.Comparator;
+
+/**
+ * Comparator for use in alphabetic sorting of file lists based on the file names.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class AlphabeticFileComparator<T extends File> implements Comparator<T> {
+
+ public int compare(T file1, T file2) {
+ return file1.getName().compareTo(file2.getName());
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparator.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/FileSelector.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/FileSelector.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/FileSelector.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.filtering;
+
+import org.jboss.soa.esb.Configurable;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.ClassUtil;
+
+import java.io.File;
+
+/**
+ * File Selector.
+ * <p/>
+ * This interface is very similar to the {@link java.io.FileFilter} interface. The difference
+ * is that you have more control over the resultant File list because implementations of this class
+ * can see the full list of files before returning the list, whereas {@link java.io.FileFilter}
+ * implementations can only see one file at a time. Implemenations of this interface can be used
+ * as a layer on top of the {@link java.io.FileFilter} based filtering.
+ * <p/>
+ * This is useful because it allows you to (for example) truncate the List to a fixed size,
+ * or perform secondary filtering based on the contents of the list, or sort the list in some way.
+ * Implementations of this class may actually use a {@link java.io.FileFilter}
+ * implementation to produce an initial list that's filtered further by the implementation
+ * itself.
+ * <p/>
+ * Implementation are useful to the likes of the {@link org.jboss.soa.esb.listeners.file.FileListener} because
+ * if means that more controled filtering can be injected.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface FileSelector extends Configurable {
+
+ /**
+ * Select (aka "filter") a list of files from the supplied directory.
+ * @param dir Directory to filer files from.
+ * @return The list of filtered files. An empty array should be returned where no matching
+ * files are found in the target directory.
+ */
+ public File[] select(File dir);
+
+ /**
+ * FileSelector factory.
+ */
+ public static class Factory {
+ public static FileSelector newInstance(String className, ConfigTree config) throws ConfigurationException {
+ try {
+ FileSelector selector = (FileSelector) ClassUtil.forName(className, FileSelector.class).newInstance();
+ selector.setConfiguration(config);
+ return selector;
+ } catch (ClassCastException e) {
+ throw new ConfigurationException("Class '" + className + "' must implement '" + FileSelector.class.getName() + "'.");
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException("Class '" + className + "' not found.");
+ } catch (IllegalAccessException e) {
+ throw new ConfigurationException("Cannot instantiate class '" + className + "'.", e);
+ } catch (InstantiationException e) {
+ throw new ConfigurationException("Cannot instantiate class '" + className + "'.", e);
+ }
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/FileSelector.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilter.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilter.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilter.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.filtering;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.Configurable;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+/**
+ * Wildcard file filter.
+ * <p/>
+ * Supports file filtering using the standard "*.xml", "a?b.xml" type notation.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class WildcardFileFilter implements Configurable, FileFilter {
+
+ public static final String MATCH_PATTERN = "matchPattern";
+
+ private Pattern matchPattern;
+
+ public void setConfiguration(ConfigTree configTree) throws ConfigurationException {
+ String matchPatternConfig = configTree.getRequiredAttribute(MATCH_PATTERN);
+
+ matchPatternConfig = matchPatternConfig.replace(".", "\\.");
+ matchPatternConfig = matchPatternConfig.replace("*", ".*");
+ matchPatternConfig = matchPatternConfig.replace("?", ".?");
+ matchPattern = Pattern.compile(matchPatternConfig);
+ }
+
+ public boolean accept(File file) {
+ if(matchPattern == null) {
+ throw new IllegalStateException("Illegal call to accept(). Filter not yet configured (via setConfiguration()).");
+ }
+
+ Matcher matcher = matchPattern.matcher(file.getName());
+ return matcher.matches();
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilter.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelector.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelector.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelector.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.filtering;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.ConfigurationException;
+
+import java.io.File;
+import java.util.Arrays;
+
+/**
+ * Wildcard file selector.
+ * <p/>
+ * This is just a basic file selector that uses the {@link WildcardFileFilter}.
+ * It adds additional guaranteed sorting (assending alphabetic) of the resultant File list.
+ * <p/>
+ * Extend this class and override the {@link #select(java.io.File)} method
+ * if secondary filtering is required. Create a new {@link FileSelector}
+ * implementation that uses an overriden version of {@link WildcardFileFilter}
+ * if more fine grained control over wildcard based filtering is required.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class WildcardFileSelector implements FileSelector {
+
+ private WildcardFileFilter filter = new WildcardFileFilter();
+ private AlphabeticFileComparator sortComparator = new AlphabeticFileComparator();
+
+ public WildcardFileSelector() {
+ }
+
+ public WildcardFileSelector(ConfigTree configTree) throws ConfigurationException {
+ setConfiguration(configTree);
+ }
+
+ public void setConfiguration(ConfigTree configTree) throws ConfigurationException {
+ filter.setConfiguration(configTree);
+ }
+
+ public File[] select(File dir) {
+ File[] files = dir.listFiles(filter);
+ Arrays.sort(files, sortComparator);
+ return files;
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelector.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycle.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycle.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycle.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.lifecycle;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Default file lifecycle.
+ * <p/>
+ * If the "processedRenamePattern" property is not specified, the file is deleted.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class DefaultFileLifecycle implements FileLifecycle {
+
+ private String fileName;
+ private String prefix;
+ private String suffix;
+ private FileLifecycleConfig config;
+ private List<File> fileHistory = new ArrayList<File>();
+ private String lifecycleId = UUID.randomUUID().toString();
+ private Object payload;
+
+ public void setFile(File file) {
+ fileName = file.getName();
+ int lastDotIndex = fileName.lastIndexOf('.');
+ if(lastDotIndex != -1 && lastDotIndex != (fileName.length() - 1)) {
+ prefix = fileName.substring(0, lastDotIndex);
+ suffix = fileName.substring(lastDotIndex + 1);
+ }
+
+ fileHistory.clear();
+ fileHistory.add(file);
+ }
+
+ public File getFile() {
+ return fileHistory.get(fileHistory.size() - 1);
+ }
+
+ public void setPayload(Object payload) {
+ this.payload = payload;
+ }
+
+ public Object getPayload() {
+ return payload;
+ }
+
+ public List<File> getFileHistory() {
+ return fileHistory;
+ }
+
+ public void setConfiguration(FileLifecycleConfig config) {
+ this.config = config;
+ }
+
+ public File toWorking() {
+ return renameFile(config.getWorkingRenamePattern());
+ }
+
+ public File toError() {
+ return renameFile(config.getErrorRenamePattern());
+ }
+
+ public File toProcessed() {
+ if(config.getProcessedRenamePattern() != null) {
+ return renameFile(config.getProcessedRenamePattern());
+ } else {
+ fileHistory.get(fileHistory.size() - 1).delete();
+ return null;
+ }
+ }
+
+ private File renameFile(String renameExpression) {
+ File currentRevision = getFile();
+ String newName = evalNameExpression(renameExpression);
+
+ File dir = currentRevision.getParentFile();
+ if(dir != null) {
+ File toFile = new File(dir, newName);
+
+ if(!toFile.exists()) {
+ dir.mkdirs();
+ currentRevision.renameTo(toFile);
+ if(toFile.exists()) {
+ fileHistory.add(toFile);
+ return toFile;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public String evalNameExpression(String renameExpression) {
+ String newName = renameExpression;
+
+ newName = newName.replace(FILE_NAME, fileName);
+ newName = newName.replace(LIFECYCLE_ID_TOKEN, lifecycleId);
+ if(prefix != null) {
+ newName = newName.replace(PREFIX_TOKEN, prefix);
+ }
+ if(suffix != null) {
+ newName = newName.replace(SUFFIX_TOKEN, suffix);
+ }
+ return newName;
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycle.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleFactory.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleFactory.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleFactory.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.lifecycle;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.ConfigurationException;
+
+/**
+ * Default FileLifecycleFactory.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class DefaultFileLifecycleFactory implements FileLifecycleFactory {
+
+ private FileLifecycleConfig lifecycleConfig;
+
+ public void setConfiguration(ConfigTree configTree) throws ConfigurationException {
+ lifecycleConfig = new FileLifecycleConfig();
+ lifecycleConfig.setConfiguration(configTree);
+ }
+
+ public FileLifecycle newInstance() {
+ DefaultFileLifecycle lifecycle = new DefaultFileLifecycle();
+ lifecycle.setConfiguration(lifecycleConfig);
+ return lifecycle;
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleFactory.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycle.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycle.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycle.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.lifecycle;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.util.ClassUtil;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * File lifecycle interface.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface FileLifecycle extends Serializable {
+
+ public static final String WORKING_RENAME_PATTERN = "workingRenamePattern";
+ public static final String ERROR_RENAME_PATTERN = "errorRenamePattern";
+ public static final String PROCESSED_RENAME_PATTERN = "processedRenamePattern";
+ public static final String FILE_NAME = "${name}";
+ public static final String PREFIX_TOKEN = "${prefix}";
+ public static final String SUFFIX_TOKEN = "${suffix}";
+ public static final String LIFECYCLE_ID_TOKEN = "${lifecycleid}";
+
+ public void setFile(File file);
+
+ public File getFile();
+
+ public void setPayload(Object payload);
+
+ public Object getPayload();
+
+ public List<File> getFileHistory();
+
+ public void setConfiguration(FileLifecycleConfig config);
+
+ public File toWorking();
+
+ public File toError();
+
+ public File toProcessed();
+
+ public String evalNameExpression(String renameExpression);
+
+ public static class Factory {
+
+ public static FileLifecycle newInstance(String className, FileLifecycleConfig lifecycleConfig) throws ConfigurationException {
+ try {
+ FileLifecycle lifecycle = (FileLifecycle) ClassUtil.forName(className, FileLifecycle.class).newInstance();
+ lifecycle.setConfiguration(lifecycleConfig);
+ return lifecycle;
+ } catch (ClassCastException e) {
+ throw new ConfigurationException("Class '" + className + "' must implement '" + FileLifecycle.class.getName() + "'.");
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException("Class '" + className + "' not found.");
+ } catch (IllegalAccessException e) {
+ throw new ConfigurationException("Cannot instantiate class '" + className + "'.", e);
+ } catch (InstantiationException e) {
+ throw new ConfigurationException("Cannot instantiate class '" + className + "'.", e);
+ }
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycle.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleConfig.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleConfig.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleConfig.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.lifecycle;
+
+import org.jboss.soa.esb.Configurable;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * File Lifecycle Configuration.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class FileLifecycleConfig implements Configurable {
+
+ private ConfigTree config;
+ private String workingRenamePattern;
+ private String errorRenamePattern;
+ private String processedRenamePattern;
+
+ public void setConfiguration(ConfigTree config) throws ConfigurationException {
+ this.config = config;
+ workingRenamePattern = config.getAttribute(FileLifecycle.WORKING_RENAME_PATTERN, FileLifecycle.PREFIX_TOKEN + "." + FileLifecycle.SUFFIX_TOKEN + ".working");
+ errorRenamePattern = config.getAttribute(FileLifecycle.ERROR_RENAME_PATTERN, FileLifecycle.PREFIX_TOKEN + "." + FileLifecycle.SUFFIX_TOKEN + ".error");
+ processedRenamePattern = config.getAttribute(FileLifecycle.PROCESSED_RENAME_PATTERN);
+ }
+
+ public ConfigTree getConfig() {
+ return config;
+ }
+
+ public String getWorkingRenamePattern() {
+ return workingRenamePattern;
+ }
+
+ public String getErrorRenamePattern() {
+ return errorRenamePattern;
+ }
+
+ public String getProcessedRenamePattern() {
+ return processedRenamePattern;
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleConfig.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleFactory.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleFactory.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleFactory.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.lifecycle;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.Configurable;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * FileLifecycle Factory.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface FileLifecycleFactory extends Configurable {
+
+ public FileLifecycle newInstance();
+
+ public static class Factory {
+
+ public static FileLifecycleFactory newInstance(String className, ConfigTree config) throws ConfigurationException {
+ try {
+ FileLifecycleFactory factory = (FileLifecycleFactory) ClassUtil.forName(className, FileLifecycleFactory.class).newInstance();
+ factory.setConfiguration(config);
+ return factory;
+ } catch (ClassCastException e) {
+ throw new ConfigurationException("Class '" + className + "' must implement '" + FileLifecycleFactory.class.getName() + "'.");
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException("Class '" + className + "' not found.");
+ } catch (IllegalAccessException e) {
+ throw new ConfigurationException("Cannot instantiate class '" + className + "'.", e);
+ } catch (InstantiationException e) {
+ throw new ConfigurationException("Cannot instantiate class '" + className + "'.", e);
+ }
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/java/org/jboss/soa/esb/listeners/file/lifecycle/FileLifecycleFactory.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/deployment.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/deployment.xml (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/deployment.xml 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jbossesb-deployment>
+ <depends>jboss.esb:deployment=jbossesb.esb</depends>
+</jbossesb-deployment>
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/deployment.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/jboss-esb.xml (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/jboss-esb.xml 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,6 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" parameterReloadSecs="5">
+ <!--
+ jbossesb internal services
+ -->
+</jbossesb>
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/main/resources/META-INF/jboss-esb.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileListenerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileListenerUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileListenerUnitTest.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file;
+
+import junit.framework.TestCase;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+import org.jboss.soa.esb.testutils.ESBConfigUtil;
+import org.jboss.soa.esb.testutils.FileUtil;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileWriter;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class FileListenerUnitTest extends TestCase {
+
+ private File filesDir = new File("./build/filesin");
+ private ESBConfigUtil configUtil;
+
+ protected void setUp() throws Exception {
+ File cwd = new File(System.getProperty("user.dir"));
+ assertEquals("This test must be run with the Current Working Dir set to the root of the 'jbossesb-ext' module.", "jbossesb-ext", cwd.getName());
+
+ if(filesDir.exists()) {
+ File[] files = filesDir.listFiles();
+ for(File file : files) {
+ file.delete();
+ }
+ filesDir.delete();
+ }
+ filesDir.mkdirs();
+ }
+
+ protected void tearDown() throws Exception {
+ stopConfig();
+ FileTestAction.messages.clear();
+ FileTestAction.throwable = null;
+ }
+
+ public void test_OK() throws IOException, ManagedLifecycleException, SAXException, ParamRepositoryException, ConfigurationException, InterruptedException {
+ createTestFile("testfile.1.input", "testfile 1 payload");
+ createTestFile("testfile.2.input", "testfile 2 payload");
+
+ startConfig("listener-config-01.xml");
+ Thread.sleep(6000);
+ stopConfig();
+
+ assertEquals("testfile 1 payload - done", FileUtil.readTextFile(new File(filesDir, "testfile.1.output")));
+ assertEquals("testfile 2 payload - done", FileUtil.readTextFile(new File(filesDir, "testfile.2.output")));
+ }
+
+ /**
+ * Disabled... we've now way of knowing that the Action Pipeline was in error.
+ * Needs a mod to the ScheduleListener to check the return on the pipeline processor.
+ */
+ public void x_test_RuntimeException() throws IOException, ManagedLifecycleException, SAXException, ParamRepositoryException, ConfigurationException, InterruptedException {
+ createTestFile("testfile.1.input", "testfile 1 payload");
+ createTestFile("testfile.2.input", "testfile 2 payload");
+
+ FileTestAction.throwable = new RuntimeException("Runtime...");
+ startConfig("listener-config-01.xml");
+ Thread.sleep(3000);
+ stopConfig();
+
+ assertEquals("testfile 1 payload", FileUtil.readTextFile(new File(filesDir, "testfile.1.input.error")));
+ assertEquals("testfile 2 payload", FileUtil.readTextFile(new File(filesDir, "testfile.2.input.error")));
+ }
+
+ /**
+ * Disabled... we've now way of knowing that the Action Pipeline was in error.
+ * Needs a mod to the ScheduleListener to check the return on the pipeline processor.
+ */
+ public void x_test_ActionProcessingException() throws IOException, ManagedLifecycleException, SAXException, ParamRepositoryException, ConfigurationException, InterruptedException {
+ createTestFile("testfile.1.input", "testfile 1 payload");
+ createTestFile("testfile.2.input", "testfile 2 payload");
+
+ FileTestAction.throwable = new ActionProcessingException("ActionProcessingException...");
+ startConfig("listener-config-01.xml");
+ Thread.sleep(3000);
+ stopConfig();
+
+ assertEquals("testfile 1 payload", FileUtil.readTextFile(new File(filesDir, "testfile.1.input.error")));
+ assertEquals("testfile 2 payload", FileUtil.readTextFile(new File(filesDir, "testfile.2.input.error")));
+ }
+
+ private void createTestFile(String fileName, String payload) throws IOException {
+ FileWriter writer = new FileWriter(new File(filesDir, fileName));
+ writer.write(payload);
+ writer.flush();
+ writer.close();
+ }
+
+ private void startConfig(String configName) throws ParamRepositoryException, ConfigurationException, ManagedLifecycleException, SAXException, InterruptedException, IOException {
+ configUtil = new ESBConfigUtil(getClass().getResourceAsStream(configName));
+ configUtil.startController();
+ }
+
+ private void stopConfig() {
+ if(configUtil != null) {
+ configUtil.stopController();
+ configUtil = null;
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileListenerUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileTestAction.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileTestAction.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileTestAction.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file;
+
+import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class FileTestAction extends AbstractActionPipelineProcessor {
+
+ public static List<Message> messages = new ArrayList<Message>();
+ public static Throwable throwable = null;
+
+ public FileTestAction(ConfigTree config) {
+ }
+
+ public Message process(Message message) throws ActionProcessingException {
+ if(throwable instanceof RuntimeException) {
+ throw (RuntimeException) throwable;
+ } else if(throwable != null) {
+ throw new ActionProcessingException("Throwing something...", throwable);
+ }
+ if(message != null) {
+ messages.add(message);
+ String payload = new String((byte[])message.getBody().get());
+ message.getBody().add(payload + " - done");
+ }
+
+ return message;
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/FileTestAction.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparatorUnitTest.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparatorUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparatorUnitTest.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.filtering;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.Arrays;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class AlphabeticFileComparatorUnitTest extends TestCase {
+
+ public void test() {
+ File cwd = new File(System.getProperty("user.dir"));
+ assertEquals("This test must be run with the Current Working Dir set to the root of the 'jbossesb-ext' module.", "jbossesb-ext", cwd.getName());
+ File[] files = cwd.listFiles(new TestFilter());
+ File build_dot_properties = getFile("build.properties", files);
+ File build_dot_xml = getFile("build.xml", files);
+
+ // Ensure they're in dessending order first...
+ files[0] = build_dot_xml;
+ files[1] = build_dot_properties;
+
+ // Now resort them...
+ AlphabeticFileComparator comparator = new AlphabeticFileComparator();
+ Arrays.sort(files, comparator);
+ assertEquals(build_dot_properties, files[0]);
+ assertEquals(build_dot_xml, files[1]);
+ }
+
+ private File getFile(String fileName, File[] files) {
+ for (File file : files) {
+ if(file.getName().equals(fileName)) {
+ return file;
+ }
+ }
+ fail("File '" + fileName + "' not in list of files: " + Arrays.asList(files));
+ return null;
+ }
+
+ private class TestFilter implements FileFilter {
+ public boolean accept(File file) {
+ return (file.getName().equals("build.properties") || file.getName().equals("build.xml"));
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/AlphabeticFileComparatorUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilterUnitTest.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilterUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilterUnitTest.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.filtering;
+
+import junit.framework.TestCase;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class WildcardFileFilterUnitTest extends TestCase {
+
+ public void test_select() throws ConfigurationException {
+ WildcardFileFilter filter = new WildcardFileFilter();
+ ConfigTree config = new ConfigTree("config");
+
+ config.setAttribute(WildcardFileFilter.MATCH_PATTERN, "*.xml");
+ filter.setConfiguration(config);
+ assertTrue(filter.accept(new File("x/y/zzzzz.xml")));
+ assertTrue(!filter.accept(new File("x/y/zzzzz.cxml")));
+ assertTrue(!filter.accept(new File("x/y/xml")));
+
+ config.setAttribute(WildcardFileFilter.MATCH_PATTERN, "blah.*");
+ filter.setConfiguration(config);
+ assertTrue(filter.accept(new File("x/y/blah.xml")));
+ assertTrue(!filter.accept(new File("x/y/zzzzz.cxml")));
+ assertTrue(!filter.accept(new File("x/y/xml")));
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileFilterUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelectorUnitTest.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelectorUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelectorUnitTest.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,46 @@
+package org.jboss.soa.esb.listeners.file.filtering;/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+
+import junit.framework.TestCase;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class WildcardFileSelectorUnitTest extends TestCase {
+
+ public void test() throws ConfigurationException {
+ WildcardFileSelector selector = new WildcardFileSelector();
+ ConfigTree config = new ConfigTree("config");
+
+ config.setAttribute(WildcardFileFilter.MATCH_PATTERN, "build.*");
+ selector.setConfiguration(config);
+
+ File cwd = new File(System.getProperty("user.dir"));
+ assertEquals("This test must be run with the Current Working Dir set to the root of the 'jbossesb-ext' module.", "jbossesb-ext", cwd.getName());
+ File[] files = selector.select(cwd);
+ assertEquals(2, files.length);
+ assertEquals("build.properties", files[0].getName());
+ assertEquals("build.xml", files[1].getName());
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/filtering/WildcardFileSelectorUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleUnitTest.java
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleUnitTest.java 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.file.lifecycle;
+
+import junit.framework.TestCase;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.file.lifecycle.DefaultFileLifecycle;
+import org.jboss.soa.esb.listeners.file.lifecycle.FileLifecycle;
+import org.jboss.soa.esb.listeners.file.lifecycle.FileLifecycleConfig;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class DefaultFileLifecycleUnitTest extends TestCase {
+
+ public void test_defaults() throws ConfigurationException, IOException {
+ DefaultFileLifecycle processor = new DefaultFileLifecycle();
+ FileLifecycleConfig config = new FileLifecycleConfig();
+ File file = new File("build/testfile.xxx");
+
+ file.createNewFile();
+ assertTrue(file.exists());
+ config.setConfiguration(new ConfigTree("config"));
+
+ processor.setConfiguration(config);
+ processor.setFile(file);
+
+ file = processor.toWorking();
+ assertTrue(file.exists());
+ assertEquals("testfile.xxx.working", file.getName());
+
+ file = processor.toError();
+ assertTrue(file.exists());
+ assertEquals("testfile.xxx.error", file.getName());
+
+ file = processor.toProcessed();
+ assertNull(file);
+ }
+
+ public void test_non_defaults() throws ConfigurationException, IOException {
+ DefaultFileLifecycle processor = new DefaultFileLifecycle();
+ FileLifecycleConfig config = new FileLifecycleConfig();
+ File file = new File("build/testfile.a.xxx");
+
+ file.createNewFile();
+ assertTrue(file.exists());
+
+ ConfigTree configTree = new ConfigTree("config");
+ configTree.setAttribute(FileLifecycle.WORKING_RENAME_PATTERN, FileLifecycle.PREFIX_TOKEN + ".working");
+ configTree.setAttribute(FileLifecycle.ERROR_RENAME_PATTERN, FileLifecycle.PREFIX_TOKEN + ".error");
+ configTree.setAttribute(FileLifecycle.PROCESSED_RENAME_PATTERN, FileLifecycle.PREFIX_TOKEN + ".done");
+ config.setConfiguration(configTree);
+
+ processor.setConfiguration(config);
+ processor.setFile(file);
+
+ file = processor.toWorking();
+ assertTrue(file.exists());
+ assertEquals("testfile.a.working", file.getName());
+
+ file = processor.toError();
+ assertTrue(file.exists());
+ assertEquals("testfile.a.error", file.getName());
+
+ file = processor.toProcessed();
+ assertTrue(file.exists());
+ assertEquals("testfile.a.done", file.getName());
+ }
+}
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/lifecycle/DefaultFileLifecycleUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/listener-config-01.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/listener-config-01.xml (rev 0)
+++ labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/listener-config-01.xml 2008-05-23 14:35:29 UTC (rev 20138)
@@ -0,0 +1,27 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
+
+ <providers>
+ <schedule-provider name="schedule">
+ <simple-schedule scheduleid="fileread-trigger" frequency="500" frequencyUnits="milliseconds" />
+ </schedule-provider>
+ </providers>
+
+ <services>
+ <service category="ServiceCat" name="ServiceName-01" description="Test Service">
+
+ <listeners>
+ <scheduled-listener name="service-01-listener" scheduleidref="fileread-trigger" event-processor="org.jboss.soa.esb.listeners.file.FileListener">
+ <property name="fileDir" value="./build/filesin" />
+ <property name="matchPattern" value="*.input" />
+ <property name="processedRenamePattern" value="${prefix}.output" />
+ </scheduled-listener>
+ </listeners>
+
+ <actions>
+ <action name="action" class="org.jboss.soa.esb.listeners.file.FileTestAction" />
+ </actions>
+ </service>
+ </services>
+
+</jbossesb>
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/sandbox/jbossesb-ext/src/test/java/org/jboss/soa/esb/listeners/file/listener-config-01.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list