[jboss-svn-commits] JBL Code SVN: r33310 - in labs/jbossesb/trunk/product: docs and 19 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jun 2 09:50:01 EDT 2010
Author: tfennelly
Date: 2010-06-02 09:49:59 -0400 (Wed, 02 Jun 2010)
New Revision: 33310
Added:
labs/jbossesb/trunk/product/rosetta/src/META-INF/
labs/jbossesb/trunk/product/rosetta/src/META-INF/org/
labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/
labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/
labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/esb/
labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/esb/listeners/
labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/esb/listeners/message/
labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/esb/listeners/message/mime/
labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/esb/listeners/message/mime/decoders.lst
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecodeException.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoder.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeType.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/NullMimeDecoder.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoder.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoderUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoderUnitTest.java
Modified:
labs/jbossesb/trunk/product/.classpath
labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
labs/jbossesb/trunk/product/rosetta/build.xml
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/LocalFileMessageComposer.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/RemoteFileMessageComposer.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/BasicMessageComposer.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ClassUtil.java
labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/src/org/jboss/soa/esb/samples/quickstarts/bpm_orchestration1/composer/GatewayMessageComposer.java
labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml
labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/src/org/jboss/soa/esb/samples/quickstart/helloworldfileaction/MyAction.java
Log:
https://jira.jboss.org/browse/JBESB-2981
Support textual file contents in file and remote gateways
Modified: labs/jbossesb/trunk/product/.classpath
===================================================================
--- labs/jbossesb/trunk/product/.classpath 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/.classpath 2010-06-02 13:49:59 UTC (rev 33310)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/.svn/" kind="src" path="rosetta/src"/>
+ <classpathentry kind="src" path="samples/quickstarts/bpm_orchestration1/src"/>
<classpathentry excluding="**/.svn/" kind="src" path="rosetta/tests/src"/>
<classpathentry excluding="**/.svn/" kind="src" path="rosetta/tests/resources"/>
<classpathentry excluding="**/.svn/" kind="src" path="services/jbossesb/src/main/java"/>
@@ -23,7 +24,7 @@
<classpathentry excluding="**/.svn/" kind="src" path="services/soapui-client/src/test/java"/>
<classpathentry excluding="**/.svn/" kind="src" path="services/spring/src/main/java"/>
<classpathentry excluding="**/.svn/" kind="src" path="services/spring/src/test/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5"/>
<classpathentry kind="lib" path="etc/test/resources/log4j/dev"/>
<classpathentry kind="lib" path="build/jbossesb/lib/jbossesb-config-model-1.0.1.jar"/>
<classpathentry kind="lib" path="build/jbossesb/lib/jbossesb-config-model-1.1.0.jar"/>
Modified: labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
===================================================================
(Binary files differ)
Modified: labs/jbossesb/trunk/product/rosetta/build.xml
===================================================================
--- labs/jbossesb/trunk/product/rosetta/build.xml 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/rosetta/build.xml 2010-06-02 13:49:59 UTC (rev 33310)
@@ -114,6 +114,7 @@
<fileset dir="${org.jboss.esb.rosetta.src.dir}" includes="**/*.groovy"/>
<fileset dir="${org.jboss.esb.rosetta.src.dir}" includes="**/*.properties"/>
<fileset dir="${org.jboss.esb.rosetta.src.dir}" includes="**/*.ftl"/>
+ <fileset dir="${org.jboss.esb.rosetta.src.dir}" includes="META-INF/org/jboss/soa/esb/listeners/message/mime/decoders.lst"/>
<fileset dir="${org.jboss.esb.rosetta.src.dir}" includes="org/jboss/soa/esb/services/security/auth/ws/smooks-ws-security.xml"/>
<fileset dir="${org.jboss.esb.rosetta.src.dir}" includes="org/jboss/soa/esb/services/security/auth/ws/smooks-ws-security-template.xml"/>
<fileset dir="${org.jboss.esb.rosetta.src.dir}" includes="xmldsig-core-schema.xsd"/>
Added: labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/esb/listeners/message/mime/decoders.lst
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/esb/listeners/message/mime/decoders.lst (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/META-INF/org/jboss/soa/esb/listeners/message/mime/decoders.lst 2010-06-02 13:49:59 UTC (rev 33310)
@@ -0,0 +1,11 @@
+##########################################################################
+# Core MimeDecoder implementations.
+#
+# To add decoder implementations for other mime types, just:
+# 1. Implement the MimeDecoder interface (annotated with @MimeType).
+# 2. Define a decoders.lst file for your module (in the same location
+# as this file - or, just add to this file).
+# 3. List the new MimeDecoder implementation in the decoders.lst file.
+##########################################################################
+
+org.jboss.soa.esb.listeners.message.mime.TextPlainMimeDecoder
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/LocalFileMessageComposer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/LocalFileMessageComposer.java 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/LocalFileMessageComposer.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -30,6 +30,9 @@
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.message.mime.MimeDecodeException;
+import org.jboss.soa.esb.listeners.message.mime.MimeDecoder;
+import org.jboss.soa.esb.listeners.message.mime.MimeDecoder.Factory;
import org.jboss.internal.soa.esb.assertion.AssertArgument;
import java.io.File;
@@ -49,11 +52,14 @@
public static final String PROP_FILE_LASTMOD = "in-file-lastmod";
private MessagePayloadProxy payloadProxy;
+ private MimeDecoder mimeDecoder;
public void setConfiguration(ConfigTree config) throws ConfigurationException {
payloadProxy = new MessagePayloadProxy(config,
new String[] {BytesBody.BYTES_LOCATION},
new String[] {BytesBody.BYTES_LOCATION});
+
+ mimeDecoder = MimeDecoder.Factory.getInstanceByConfigTree(config);
}
public Message compose(T inputFile) throws MessageDeliverException {
@@ -68,7 +74,9 @@
payloadProxy.setPayload(message, getPayload( inputFile ) );
} catch (IOException e) {
throw new MessageDeliverException("Error reading input file '" + inputFile.getAbsolutePath() + "'.", e);
- }
+ } catch (MimeDecodeException e) {
+ throw new MessageDeliverException("Error decoding input file '" + inputFile.getAbsolutePath() + "' payload using '" + mimeDecoder.getClass().getName() + "'. Wrong MimeDecoder, or MimeDecoder may require additional configuration.", e);
+ }
// Add some metadata about the file....
message.getProperties().setProperty(PROP_FILE_OBJ, inputFile);
@@ -79,8 +87,8 @@
return message;
}
- protected Object getPayload( T inputFile ) throws IOException {
- return FileUtil.readFile(inputFile);
+ protected Object getPayload( T inputFile ) throws IOException, MimeDecodeException {
+ return mimeDecoder.decode(FileUtil.readFile(inputFile));
}
public Object decompose(Message message, T inputFile) throws MessageDeliverException {
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/RemoteFileMessageComposer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/RemoteFileMessageComposer.java 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/RemoteFileMessageComposer.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -21,6 +21,8 @@
import org.jboss.soa.esb.listeners.message.MessageComposer;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.listeners.message.mime.MimeDecodeException;
+import org.jboss.soa.esb.listeners.message.mime.MimeDecoder;
import org.jboss.soa.esb.listeners.ListenerUtil;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.ConfigurationException;
@@ -49,6 +51,7 @@
private FTPEpr ftpEpr;
private File downloadDir;
private MessagePayloadProxy payloadProxy;
+ private MimeDecoder mimeDecoder;
public void setConfiguration(ConfigTree config) throws ConfigurationException {
EPR epr = ListenerUtil.assembleEpr(config);
@@ -62,6 +65,8 @@
payloadProxy = new MessagePayloadProxy(config,
new String[] {BytesBody.BYTES_LOCATION},
new String[] {BytesBody.BYTES_LOCATION});
+
+ mimeDecoder = MimeDecoder.Factory.getInstanceByConfigTree(config);
}
public Message compose(T inputFile) throws MessageDeliverException {
@@ -74,13 +79,15 @@
throw new MessageDeliverException("Error reading remote input file '" + inputFile.getAbsolutePath() + "'.", e);
} catch (RemoteFileSystemException e) {
throw new MessageDeliverException("Error reading remote input file '" + inputFile.getAbsolutePath() + "'.", e);
- }
+ } catch (MimeDecodeException e) {
+ throw new MessageDeliverException("Error decoding input file '" + inputFile.getAbsolutePath() + "' payload using '" + mimeDecoder.getClass().getName() + "'. Wrong MimeDecoder, or MimeDecoder may require additional configuration.", e);
+ }
return message;
}
- protected Object getPayload( T inputFile ) throws RemoteFileSystemException, IOException {
- return getFileContents(inputFile);
+ protected Object getPayload( T inputFile ) throws RemoteFileSystemException, IOException, MimeDecodeException {
+ return mimeDecoder.decode(getFileContents(inputFile));
}
public Object decompose(Message message, T inputMessage) throws MessageDeliverException {
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/BasicMessageComposer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/BasicMessageComposer.java 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/BasicMessageComposer.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -19,14 +19,10 @@
*/
package org.jboss.soa.esb.listeners.message;
-import org.jboss.soa.esb.actions.ActionUtils;
-import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
/**
* Basic Message Composer.
- * <p/>
- * Sets and gets the ESB unaware payload on the message using {@link ActionUtils}.
*
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecodeException.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecodeException.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecodeException.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message.mime;
+
+/**
+ * Mime decode exception.
+ *
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+public class MimeDecodeException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public MimeDecodeException(String message) {
+ super(message);
+ }
+
+ public MimeDecodeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecodeException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoder.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoder.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoder.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message.mime;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+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;
+
+/**
+ * Mime handler.
+ *
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+public interface MimeDecoder {
+
+ /**
+ * Decode the specified array of bytes based on the {@link MimeType}
+ * annotation on the implementing {@link MimeDecoder}.
+ * @param bytes The bytes to be decoded.
+ * @return The decoded bytes.
+ * @throws MimeDecodeException Error while decoding the byts array.
+ */
+ Object decode(byte[] bytes) throws MimeDecodeException;
+
+ // TODO: Add support for encoding to a byte[] ?
+
+ /**
+ * Factory class.
+ */
+ public static class Factory {
+
+ public static final String MIME_TYPE = "mimeType";
+ public static final String MIME_DECODER = "mimeDecoder";
+ public static final String DECODERS_LST_RESOURCE = "META-INF/org/jboss/soa/esb/listeners/message/mime/decoders.lst";
+
+ private final static Logger logger = Logger.getLogger(MimeDecoder.class) ;
+
+ /**
+ * Get a MimeDecoder instance by mime type.
+ * @param mimeType The mime type.
+ * @return The MimeDecoder for that mime type.
+ * @throws ConfigurationException Error creating MimeDecoder instance.
+ */
+ public static MimeDecoder getInstanceByType(String mimeType) throws ConfigurationException {
+ AssertArgument.isNotNullAndNotEmpty(mimeType, MIME_TYPE);
+ mimeType = mimeType.trim();
+
+ List<URL> decoderListFiles;
+
+ try {
+ decoderListFiles = ClassUtil.getResources(DECODERS_LST_RESOURCE, MimeDecoder.class);
+ } catch (IOException e) {
+ throw new ConfigurationException("Unexpected error locating mime decoder.lst files on classpath (" + DECODERS_LST_RESOURCE + ").", e);
+ }
+
+ for(URL decoderListFile : decoderListFiles) {
+ try {
+ InputStream listFileStream = decoderListFile.openStream();
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(listFileStream, "UTF-8"));
+ String line;
+
+ while((line = reader.readLine()) != null) {
+ line = line.trim();
+ if(line.length() > 0 && !line.startsWith("#")) {
+ Class<?> decoderClass;
+ try {
+ decoderClass = ClassUtil.forName(line, MimeDecoder.class);
+ } catch (ClassNotFoundException e) {
+ logger.error("MimeDecoder class '" + line + "' (listed in decoder.lst file '" + decoderListFile + "') is not available on the classpath.", e);
+ continue;
+ }
+
+ if(MimeDecoder.class.isAssignableFrom(decoderClass)) {
+ MimeType mimeTypeAnno = decoderClass.getAnnotation(MimeType.class);
+ if(mimeTypeAnno == null) {
+ logger.error("MimeDecoder class '" + line + "' (listed in decoder.lst file '" + decoderListFile + "') is not annotated with the MimeType annotation.");
+ continue;
+ }
+ if(mimeTypeAnno.value().trim().equals(mimeType)) {
+ // Found the MimeDecoder...
+ try {
+ return (MimeDecoder) decoderClass.newInstance();
+ } catch (Exception e) {
+ throw new ConfigurationException("Found MimeDecoder class '" + line + "' (listed in decoder.lst file '" + decoderListFile + "') but was unable to instanciate it. Must have a public default constructor.", e);
+ }
+ }
+ } else {
+ logger.error("MimeDecoder class '" + line + "' (listed in decoder.lst file '" + decoderListFile + "') doesn't implement the MimeDecoder interface.");
+ continue;
+ }
+ }
+ }
+ } finally {
+ listFileStream.close();
+ }
+ } catch (IOException e) {
+ throw new ConfigurationException("Unexpected error reading mime decoder.lst files on classpath (" + decoderListFile + ").", e);
+ }
+ }
+
+ throw new ConfigurationException("Failed to find a MimeDecoder implementation for mime type '" + mimeType + "'. MimeDecoders must be listed in a '" + DECODERS_LST_RESOURCE + "' file on the classpath.");
+ }
+
+ /**
+ * Get a MimeDecoder instance by class name.
+ * @param className The MimeDecoder class name.
+ * @return The MimeDecoder instance.
+ * @throws ConfigurationException Error creating MimeDecoder instance.
+ */
+ public static MimeDecoder getInstanceByClassName(String className) throws ConfigurationException {
+ AssertArgument.isNotNullAndNotEmpty(className, "className");
+ className = className.trim();
+
+ Class<?> decoderClass;
+ try {
+ decoderClass = ClassUtil.forName(className, MimeDecoder.class);
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException("MimeDecoder class '" + className + "' is not available on the classpath.", e);
+ }
+
+ if(MimeDecoder.class.isAssignableFrom(decoderClass)) {
+ try {
+ return (MimeDecoder) decoderClass.newInstance();
+ } catch (Exception e) {
+ throw new ConfigurationException("Unable to instanciate MimeDecoder class '" + className + "'. Must have a public default constructor.", e);
+ }
+ } else {
+ throw new ConfigurationException("MimeDecoder class '" + className + "' doesn't implement the MimeDecoder interface.");
+ }
+ }
+
+ /**
+ * Get a MimeDecoder instance by {@link ConfigTree}.
+ * @param config The ConfigTree instance.
+ * @return The MimeDecoder instance.
+ * @throws ConfigurationException Error creating MimeDecoder instance.
+ */
+ public static MimeDecoder getInstanceByConfigTree(ConfigTree config) throws ConfigurationException {
+ AssertArgument.isNotNull(config, "config");
+ MimeDecoder mimeDecoder;
+
+ String mimeType = config.getAttribute(MIME_TYPE);
+ if(mimeType != null) {
+ mimeDecoder = getInstanceByType(mimeType);
+ } else {
+ String mimeDecoderClass = config.getAttribute(MIME_DECODER);
+ if(mimeDecoderClass != null) {
+ mimeDecoder = getInstanceByClassName(mimeDecoderClass);
+ } else {
+ mimeDecoder = new NullMimeDecoder();
+ }
+ }
+
+ if(mimeDecoder instanceof Configurable) {
+ ((Configurable)mimeDecoder).setConfiguration(config);
+ }
+
+ return mimeDecoder;
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeType.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeType.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeType.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message.mime;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Mime type.
+ *
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+ at Documented
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE})
+public @interface MimeType {
+ String value();
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/MimeType.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/NullMimeDecoder.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/NullMimeDecoder.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/NullMimeDecoder.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message.mime;
+
+/**
+ * Null (pass thru) decoder.
+ *
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+public class NullMimeDecoder implements MimeDecoder {
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.message.mime.MimeDecoder#decode(byte[])
+ */
+ public Object decode(byte[] bytes) throws MimeDecodeException {
+ // Just return the bytes...
+ return bytes;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/NullMimeDecoder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoder.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoder.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoder.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message.mime;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.soa.esb.Configurable;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Mime decoder for mime type "text/plain".
+ * <p/>
+ * Decodes the bytes to a simple String.
+ *
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+ at MimeType("text/plain")
+public class TextPlainMimeDecoder implements MimeDecoder, Configurable {
+
+ private Charset encodingCharset;
+ private String decodeTo;
+
+ public void setConfiguration(ConfigTree configTree) throws ConfigurationException {
+ AssertArgument.isNotNull(configTree, "configTree");
+
+ // Encoding config...
+ String encoding = configTree.getAttribute("encoding", "UTF-8");
+ encodingCharset = Charset.forName(encoding);
+
+ // Decode To config...
+ decodeTo = configTree.getAttribute("decodeTo", "STRING");
+ }
+
+ public Object decode(byte[] bytes) throws MimeDecodeException {
+ if(decodeTo.equals("BYTES")) {
+ return bytes;
+ }
+
+ try {
+ String decodedPayload = new String(bytes, encodingCharset.name());
+
+ if(decodeTo.equals("CHARS")) {
+ return decodedPayload.toCharArray();
+ } else {
+ return decodedPayload;
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw new MimeDecodeException("Unexpected character encoding error.", e);
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ClassUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ClassUtil.java 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/ClassUtil.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -227,6 +227,34 @@
return ClassLoader.getSystemResource(resource) ;
}
+
+ public static List<URL> getResources(String resourcePath, Class<?> caller) throws IOException {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+
+ if(resourcePath.startsWith("/")) {
+ resourcePath = resourcePath.substring(1);
+ }
+
+ if (classLoader != null) {
+ return toList(classLoader.getResources(resourcePath));
+ }
+
+ classLoader = caller.getClassLoader();
+ if (classLoader != null) {
+ return toList(classLoader.getResources(resourcePath));
+ }
+
+ return new ArrayList<URL>();
+ }
+
+ private static <T> List<T> toList(Enumeration<T> objects) {
+ List<T> theList = new ArrayList<T>();
+ while(objects.hasMoreElements()) {
+ theList.add(objects.nextElement());
+ }
+ return theList;
+ }
+
/**
* Get a package name and convert it to a path value, so it can be used
* in calls to methods like {@link #getResourceAsStream}.
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoderUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoderUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoderUnitTest.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message.mime;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+public class MimeDecoderUnitTest extends TestCase {
+
+ public void test_by_type_found() throws ConfigurationException {
+ MimeDecoder mimeDecoder = MimeDecoder.Factory.getInstanceByType("text/plain");
+ assertTrue(mimeDecoder instanceof TextPlainMimeDecoder);
+ }
+
+ public void test_by_type_not_found() {
+ try {
+ MimeDecoder.Factory.getInstanceByType("some/blah");
+ fail("Expected ConfigurationException");
+ } catch(ConfigurationException e) {
+ assertEquals("Failed to find a MimeDecoder implementation for mime type 'some/blah'. MimeDecoders must be listed in a 'META-INF/org/jboss/soa/esb/listeners/message/mime/decoders.lst' file on the classpath.", e.getMessage());
+ }
+ }
+
+ public void test_by_classname() throws ConfigurationException {
+ MimeDecoder mimeDecoder = MimeDecoder.Factory.getInstanceByClassName(TextPlainMimeDecoder.class.getName());
+ assertTrue(mimeDecoder instanceof TextPlainMimeDecoder);
+ }
+
+ public void test_by_configtree_mimetype() throws ConfigurationException {
+ ConfigTree config = new ConfigTree("config");
+
+ config.setAttribute(MimeDecoder.Factory.MIME_TYPE, "text/plain");
+
+ MimeDecoder mimeDecoder = MimeDecoder.Factory.getInstanceByConfigTree(config);
+ assertTrue(mimeDecoder instanceof TextPlainMimeDecoder);
+ }
+
+ public void test_by_configtree_mimetype_unknown() throws ConfigurationException {
+ ConfigTree config = new ConfigTree("config");
+
+ config.setAttribute(MimeDecoder.Factory.MIME_TYPE, "some/blah");
+
+ try {
+ MimeDecoder.Factory.getInstanceByConfigTree(config);
+ fail("Expected ConfigurationException");
+ } catch(ConfigurationException e) {
+ assertEquals("Failed to find a MimeDecoder implementation for mime type 'some/blah'. MimeDecoders must be listed in a 'META-INF/org/jboss/soa/esb/listeners/message/mime/decoders.lst' file on the classpath.", e.getMessage());
+ }
+ }
+
+ public void test_by_configtree_classname() throws ConfigurationException {
+ ConfigTree config = new ConfigTree("config");
+
+ config.setAttribute(MimeDecoder.Factory.MIME_DECODER, TextPlainMimeDecoder.class.getName());
+
+ MimeDecoder mimeDecoder = MimeDecoder.Factory.getInstanceByConfigTree(config);
+ assertTrue(mimeDecoder instanceof TextPlainMimeDecoder);
+ }
+
+ public void test_by_configtree_classname_unknown() throws ConfigurationException {
+ ConfigTree config = new ConfigTree("config");
+
+ config.setAttribute(MimeDecoder.Factory.MIME_DECODER, "com.XXX");
+
+ try {
+ MimeDecoder.Factory.getInstanceByConfigTree(config);
+ fail("Expected ConfigurationException");
+ } catch(ConfigurationException e) {
+ assertEquals("MimeDecoder class 'com.XXX' is not available on the classpath.", e.getMessage());
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/MimeDecoderUnitTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoderUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoderUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoderUnitTest.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message.mime;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+public class TextPlainMimeDecoderUnitTest extends TestCase {
+
+ public void test_String() throws ConfigurationException, MimeDecodeException {
+ TextPlainMimeDecoder decoder = new TextPlainMimeDecoder();
+ ConfigTree config = new ConfigTree("conf");
+
+ decoder.setConfiguration(config);
+
+ String decodedRes = (String) decoder.decode("Hello W".getBytes());
+ assertEquals("Hello W", decodedRes);
+ }
+
+ public void test_Chars() throws ConfigurationException, MimeDecodeException {
+ TextPlainMimeDecoder decoder = new TextPlainMimeDecoder();
+ ConfigTree config = new ConfigTree("conf");
+
+ config.setAttribute("decodeTo", "CHARS");
+ decoder.setConfiguration(config);
+
+ char[] decodedRes = (char[]) decoder.decode("Hello W".getBytes());
+ assertEquals("Hello W", new String(decodedRes));
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/mime/TextPlainMimeDecoderUnitTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/src/org/jboss/soa/esb/samples/quickstarts/bpm_orchestration1/composer/GatewayMessageComposer.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/src/org/jboss/soa/esb/samples/quickstarts/bpm_orchestration1/composer/GatewayMessageComposer.java 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/samples/quickstarts/bpm_orchestration1/src/org/jboss/soa/esb/samples/quickstarts/bpm_orchestration1/composer/GatewayMessageComposer.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -25,6 +25,7 @@
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.gateway.LocalFileMessageComposer;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.listeners.message.mime.MimeDecodeException;
import org.jboss.soa.esb.message.Message;
public class GatewayMessageComposer extends LocalFileMessageComposer<File>
@@ -40,7 +41,7 @@
charset = config.getAttribute("encoding", DEFAULT_CHARSET) ;
}
protected Object getPayload(final File inputFile)
- throws IOException
+ throws IOException, MimeDecodeException
{
final Object contents = super.getPayload(inputFile) ;
if (contents instanceof byte[])
Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml 2010-06-02 13:49:59 UTC (rev 33310)
@@ -41,11 +41,10 @@
name="myFileListener"
description="Hello World File Action (esb listener)" >
<listeners>
- <fs-listener name="FileGateway"
- busidref="helloFileChannel"
- is-gateway="true"
- poll-frequency-seconds="10"
- />
+ <fs-listener name="FileGateway" busidref="helloFileChannel" is-gateway="true" poll-frequency-seconds="10">
+ <property name="mimeType" value="text/plain" />
+ <property name="encoding" value="UTF-8" />
+ </fs-listener>
<jms-listener name="helloWorldFileAction"
busidref="quickstartEsbChannel"
/>
Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/src/org/jboss/soa/esb/samples/quickstart/helloworldfileaction/MyAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/src/org/jboss/soa/esb/samples/quickstart/helloworldfileaction/MyAction.java 2010-06-02 13:06:15 UTC (rev 33309)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/src/org/jboss/soa/esb/samples/quickstart/helloworldfileaction/MyAction.java 2010-06-02 13:49:59 UTC (rev 33310)
@@ -35,22 +35,22 @@
public Message noOperation(Message message) { return message; }
public Message displayMessage(Message message) throws Exception{
- logHeader();
- System.out.println("Body: " + new String((byte[])message.getBody().get()));
- logFooter();
- return message;
+ logHeader();
+ System.out.println("Body: " + message.getBody().get());
+ logFooter();
+ return message;
}
-
- public Message playWithMessage(Message message) throws Exception {
+
+ public Message playWithMessage(Message message) throws Exception {
Body msgBody = message.getBody();
- String contents = new String((byte[])msgBody.get());
+ String contents = (String) msgBody.get();
StringBuffer sb = new StringBuffer();
sb.append("\nBEFORE\n");
sb.append(contents);
sb.append("\nAFTER\n");
- msgBody.add(sb.toString().getBytes());
+ msgBody.add(sb.toString());
return message;
- }
+ }
// This makes it easier to read on the console
private void logHeader() {
More information about the jboss-svn-commits
mailing list