[jboss-svn-commits] JBL Code SVN: r13393 - in labs/jbossesb/workspace/dbevenius/wslistener/product: rosetta/src/org/jboss/soa/esb/listeners/gateway and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 12 02:51:42 EDT 2007
Author: beve
Date: 2007-07-12 02:51:42 -0400 (Thu, 12 Jul 2007)
New Revision: 13393
Added:
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapper.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapperException.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapperIntegrationTest.java
Removed:
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCache.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheException.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheIntegrationTest.java
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/WSGateway.java
Modified:
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListener.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/ReadOnlyRemoteFileSystemStrategy.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/RemoteFileSystemStrategy.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java
labs/jbossesb/workspace/dbevenius/wslistener/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGateway.java
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGatewayUnitTest.java
Log:
Modified implementation of FtpFileCache, which has been renamed to CacheWrapper.
Added javadoc to PackageJmsMessageContent and JMSRouter.
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -168,8 +168,20 @@
}
}
+ /**
+ * Set JMS Header fields on the outgoing JMS Message.
+ * </p>
+ * This implementation will simply set the JMSCorrelationID to
+ * the MessageID of the Message object.<br>
+ * Subclasses may override this method set other properties.
+ * </p>
+ *
+ * @param jmsMessage the out-going JMSMessage object
+ * @param esbMsg the Message object from the ESB
+ * @throws JMSException
+ */
protected void setJMSProperties( Message jmsMessage, org.jboss.soa.esb.message.Message esbMsg ) throws JMSException {
- jmsMessage.setJMSCorrelationID( esbMsg.getHeader().getCall().getRelatesTo().toString() );
+ jmsMessage.setJMSCorrelationID( esbMsg.getHeader().getCall().getMessageID().toString() );
}
private Message createObjectMessage(Object message) throws JMSException {
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -51,14 +51,11 @@
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.listeners.ListenerUtil;
import org.jboss.soa.esb.listeners.RegistryUtil;
-import org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
-import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleThreadState;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.util.ClassUtil;
-import org.jboss.soa.esb.util.Util;
/**
* Base class for all file gateways: local filesystem, ftp, sftp and ftps.
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -43,11 +43,18 @@
import org.jboss.soa.esb.message.format.MessageFactory;
/**
- * Default gateway action for plain jms messages <p/>It will just drop the
+* Default gateway action for plain jms messages <p/>It will just drop the
* jms message contents into a esb Message
+* </p>
+* The following is the mapping of JMS Header fields to Message fields:
+* <ul>
+* <li>JMSMessageID -> Message.getCall().setMessageID </li>
+* <li>JMSCorrelationID -> Message.getCall().setRelatesTo </li>
+* <li>JMSReplyTo -> Message.getCall().setReplyTo </li>
+* </ul>
*
-* @author <a
-* href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+* @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+* @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
* @since Version 4.0
*
*/
@@ -55,6 +62,14 @@
{
private Logger log = Logger.getLogger( PackageJmsMessageContents.class );
+ /**
+ * Will package the passes in Object into a Message object.
+ *
+ * @param obj
+ * @return
+ * @throws JMSException
+ * @throws IOException
+ */
@SuppressWarnings("unchecked")
public Message process (Object obj) throws JMSException, IOException
{
@@ -121,29 +136,27 @@
return message;
}
-private byte[] getMessageContent (javax.jms.Message jMess) throws JMSException, IOException
-{
-if (jMess instanceof TextMessage)
-return ((TextMessage) jMess).getText().getBytes();
+ private byte[] getMessageContent (javax.jms.Message jMess) throws JMSException, IOException
+ {
+ if (jMess instanceof TextMessage)
+ return ((TextMessage) jMess).getText().getBytes();
-if (jMess instanceof BytesMessage)
-{
-BytesMessage jBytes = (BytesMessage) jMess;
-ByteArrayOutputStream out = new ByteArrayOutputStream();
-byte[] ba = new byte[1000];
-int iQread;
-while (-1 != (iQread = jBytes.readBytes(ba)))
-if (iQread > 0) out.write(ba, 0, iQread);
-out.close();
-return out.toByteArray();
-}
+ if (jMess instanceof BytesMessage)
+ {
+ BytesMessage jBytes = (BytesMessage) jMess;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] ba = new byte[1000];
+ int iQread;
+ while (-1 != (iQread = jBytes.readBytes(ba)))
+ if (iQread > 0) out.write(ba, 0, iQread);
+ out.close();
+ return out.toByteArray();
+ }
-if (jMess instanceof ObjectMessage)
-return ((ObjectMessage) jMess).getObject().toString()
-.getBytes();
-JmsGatewayListener._logger
-.warn("Message type " + jMess.getClass().getSimpleName() + " not supported - Message is ignored");
-return null;
-}
+ if (jMess instanceof ObjectMessage)
+ return ((ObjectMessage) jMess).getObject().toString().getBytes();
+ log.warn("Message type " + jMess.getClass().getSimpleName() + " not supported - Message is ignored");
+ return null;
+ }
} // ____________________________________________________
\ No newline at end of file
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListener.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListener.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -62,10 +62,6 @@
*/
public static final String REMOTE_FILE_SYSTEM_STRATEGY_CLASS = "remoteFileSystemStrategy-class";
/**
- * Property to specify a configuration file for {@link #REMOTE_FILE_SYSTEM_STRATEGY_CLASS}
- */
- public static final String REMOTE_FILE_SYSTEM_STRATEGY_CONFIG_FILE = "remoteFileSystemStrategy-configFile";
- /**
* Property to specify if a the TreeCacheListener should be used. See {@link DeleteOnEvictTreeCacheListener}
*/
public static final String REMOTE_FILE_SYSTEM_STRATEGY_CACHE_LISTENER = "remoteFileSystemStrategy-cacheListener";
@@ -199,10 +195,9 @@
remotefileSystemStrategy = strategy != null ? strategy : new ReadOnlyRemoteFileSystemStrategy();
- String configFile = _config.getAttribute( REMOTE_FILE_SYSTEM_STRATEGY_CONFIG_FILE );
try
{
- remotefileSystemStrategy.init( configFile );
+ remotefileSystemStrategy.init( _config );
if ( remotefileSystemStrategy instanceof ReadOnlyRemoteFileSystemStrategy )
{
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/ReadOnlyRemoteFileSystemStrategy.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/ReadOnlyRemoteFileSystemStrategy.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/ReadOnlyRemoteFileSystemStrategy.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -28,8 +28,9 @@
import org.apache.log4j.Logger;
import org.jboss.cache.CacheException;
-import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.FtpFileCache;
-import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.FtpFileCacheException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.CacheWrapper;
+import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.CacheWrapperException;
/**
* Read-only implementation of {@link RemoteFileSystemStrategy}.
@@ -45,20 +46,24 @@
{
private Logger log = Logger .getLogger( ReadOnlyRemoteFileSystemStrategy.class );
- private FtpFileCache ftpFileCache;
+ private CacheWrapper ftpFileCache;
+ public void init( String configFile ) throws RemoteFileSystemStrategyException
+ {
+
+ }
/**
* Configures and starts the underlying FtpFileCache
*/
- public void init( String configFile ) throws RemoteFileSystemStrategyException
+ public void init( ConfigTree configTree ) throws RemoteFileSystemStrategyException
{
try
{
- ftpFileCache = new FtpFileCache( configFile );
+ ftpFileCache = new CacheWrapper( configTree );
ftpFileCache.start();
}
- catch ( FtpFileCacheException e )
+ catch ( CacheWrapperException e )
{
throw new RemoteFileSystemStrategyException ( e );
}
@@ -113,11 +118,11 @@
for ( File file : files )
{
String fileName = file.getName();
- if ( !ftpFileCache.containsFile( fileName ) )
+ if ( !ftpFileCache.containsObject( fileName ) )
{
try
{
- ftpFileCache.putFileName( fileName );
+ ftpFileCache.putObject( fileName, fileName );
newFileList.add( file );
}
catch (CacheException e)
@@ -161,7 +166,7 @@
{
ftpFileCache.setCacheListener( cacheListenerClass );
}
- catch (FtpFileCacheException e)
+ catch (CacheWrapperException e)
{
throw new RemoteFileSystemStrategyException( e );
}
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/RemoteFileSystemStrategy.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/RemoteFileSystemStrategy.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/RemoteFileSystemStrategy.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -1,6 +1,8 @@
package org.jboss.soa.esb.listeners.gateway.remotestrategies;
import java.io.File;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.gateway.GatewayException;
/**
@@ -18,6 +20,7 @@
* @throws Exception
*/
void init( String configFile ) throws RemoteFileSystemStrategyException;
+ void init( ConfigTree configTree ) throws RemoteFileSystemStrategyException;
/**
* filters the file array passed in.
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapper.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapper.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapper.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -0,0 +1,339 @@
+package org.jboss.soa.esb.listeners.gateway.remotestrategies.cache;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.PropertyConfigurator;
+import org.jboss.cache.TreeCache;
+import org.jboss.cache.TreeCacheListener;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.ClassUtil;
+
+/**
+ * Implements a cache which can be replicated in a cluster.
+ *
+ * See the <a href="http://labs.jboss.com/jbosscache">JBoss Cache</a> docs
+ * for details on configuring the cache.
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class CacheWrapper
+{
+ @SuppressWarnings("unused")
+ private Logger log = Logger.getLogger( CacheWrapper.class );
+
+ public static final String CACHE_CONFIG_FILE = "cache-configFile";
+ public static final String CACHE_FQN = "cache-fqn";
+
+ /**
+ * Default configuration file for jboss cache.
+ * Used if no config is specified upon calling the constructor.
+ * Note that this file must then exist on the classpath
+ */
+ private static final String DEFAULT_CONFIG_FILE = "/cache-config.xml";
+ /**
+ * The fqn to use.
+ */
+ private String fqn;
+ /**
+ * The configuration file used to configure the tree cache
+ */
+ private String config;
+ /**
+ * The JBoss TreeCache instance
+ */
+ private TreeCache treeCache;
+
+ /**
+ *
+ * @param config either an absolute path of a relative path
+ * @throws Exception
+ */
+ public CacheWrapper ( ConfigTree configTree ) throws CacheWrapperException
+ {
+ setFqn( configTree );
+
+ setConfig( configTree );
+
+ createTreeCache();
+
+ }
+
+ private void createTreeCache() throws CacheWrapperException
+ {
+ InputStream in = null;
+ try
+ {
+ treeCache = new TreeCache();
+ in = getConfigInputStream( this.config );
+ PropertyConfigurator configurator = new PropertyConfigurator();
+ configurator.configure( treeCache, in );
+ }
+ catch ( Exception e )
+ {
+ log.error( e );
+ throw new CacheWrapperException ( e );
+ }
+ finally
+ {
+ close( in );
+ }
+ }
+
+ private void setConfig( ConfigTree configTree )
+ {
+ config = configTree.getAttribute( CACHE_CONFIG_FILE );
+ if ( config == null )
+ config = DEFAULT_CONFIG_FILE;
+ }
+
+ private void setFqn( ConfigTree configTree ) throws CacheWrapperException
+ {
+ try
+ {
+ fqn = configTree.getRequiredAttribute( CACHE_FQN );
+ }
+ catch (ConfigurationException e )
+ {
+ log.error ( e );
+ throw new CacheWrapperException( e );
+ }
+ }
+
+ /**
+ * Gets an input stream from the specified path.
+ *
+ * If the path denotes a file on the filesystem, that file
+ * will be used.
+ * If a file is not found in the filesystem, this method will look
+ * for the file on the classpath.
+ *
+ * @param path the path to the JBossCache configuration file
+ * @return InputStream the inputstream for the passed-in path
+ */
+ protected InputStream getConfigInputStream( final String path )
+ {
+ InputStream in = null;
+ File configFile = new File( path );
+ if ( configFile.exists() )
+ {
+ log.debug("Reading jboss cache configuration from : " + path );
+
+ try
+ {
+ in = new FileInputStream ( path );
+ }
+ catch (FileNotFoundException e)
+ {
+ log.error( e );
+ }
+ }
+ else
+ {
+ log.debug("Reading jgroups configuration classpath : " + path );
+ in = ClassUtil.getResourceAsStream( path, getClass() );
+ }
+ return in;
+ }
+
+ /**
+ * Start the cache
+ * @throws Exception
+ */
+ public void start() throws CacheWrapperException
+ {
+ try
+ {
+ treeCache.startService();
+ }
+ catch (Exception e)
+ {
+ log.error( e );
+ throw new CacheWrapperException( e );
+ }
+ }
+
+ /**
+ * Stops the cache
+ *
+ */
+ public void stop()
+ {
+ treeCache.stopService();
+ }
+
+ /**
+ * Will add the filename to the cache.
+ *
+ * @param fileName
+ * @throws CacheException
+ */
+ public void putObject( final String nodeName, final Object object) throws CacheException
+ {
+ treeCache.put ( fqn, nodeName, object );
+ }
+
+ /**
+ * Will get the filename if it exists in the cache.
+ *
+ * @param fileName
+ * @throws CacheException
+ */
+ public Object getObject( final String nodeName ) throws CacheException
+ {
+ return treeCache.get ( fqn, nodeName );
+ }
+
+ /**
+ * Removed the fileName from the cache if it exist there
+ *
+ * @param fileName
+ * @return Object the value of the removed object
+ * @throws CacheException
+ */
+ public Object deleteObject( final String nodeName ) throws CacheException
+ {
+ return treeCache.remove( fqn, nodeName );
+ }
+
+ /**
+ * Checks to see if the filename exists in the cache
+ *
+ * @param fileName the filename to look for
+ * @return true if the file exists in the cache
+ */
+ public boolean containsObject( final String nodeName )
+ {
+ return treeCache.exists( fqn, nodeName );
+ }
+
+ /**
+ * Gets the a string of all files in the cache
+ * @return String
+ */
+ public String getCache()
+ {
+ return treeCache.print( fqn );
+ }
+
+ public String getFqn()
+ {
+ return fqn;
+ }
+
+ public void setFqn(String fqn)
+ {
+ this.fqn = fqn;
+ }
+
+ public String getConfigFile( )
+ {
+ return config;
+ }
+
+ /**
+ * Removes all data under the fqn, but not the fqn
+ * itself
+ *
+ * @throws CacheException
+ */
+ public void removeAll() throws CacheException
+ {
+ treeCache.removeData( fqn );
+ }
+
+ public void setDeleteOnEviction()
+ {
+ treeCache.addTreeCacheListener( new DeleteOnEvictTreeCacheListener( treeCache) );
+ }
+
+ public void addCacheListener( final TreeCacheListener listener )
+ {
+ if ( listener != null )
+ treeCache.addTreeCacheListener( listener );
+ }
+
+ public Map getCacheListeners()
+ {
+ return treeCache.getTreeCacheListeners();
+ }
+
+ public void setCacheListener( final Class cacheListenerClass ) throws CacheWrapperException
+ {
+ if ( cacheListenerClass == null )
+ return;
+ try
+ {
+ Constructor constructor = cacheListenerClass.getConstructor( TreeCache.class );
+ Object object = constructor.newInstance( treeCache );
+ if ( object instanceof TreeCacheListener )
+ {
+ TreeCacheListener listener = ( TreeCacheListener ) object;
+ treeCache.addTreeCacheListener( listener );
+ }
+ }
+ catch (SecurityException e)
+ {
+ throw createFtpFileCacheException( "SecurityException while trying set the CacheListener:", e );
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw createFtpFileCacheException( "NoSuchMethodException while trying set the CacheListener:", e );
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw createFtpFileCacheException( "IllegalArgumentException while trying set the CacheListener:", e );
+ }
+ catch (InstantiationException e)
+ {
+ throw createFtpFileCacheException( "InstantiationException while trying set the CacheListener:", e );
+ }
+ catch (IllegalAccessException e)
+ {
+ throw createFtpFileCacheException( "IllegalAccessException while trying set the CacheListener:", e );
+ }
+ catch (InvocationTargetException e)
+ {
+ throw createFtpFileCacheException( "InvocationTargetException while trying set the CacheListener:", e );
+ }
+ }
+
+ private CacheWrapperException createFtpFileCacheException( final String msg, Exception e )
+ {
+ log.error( msg, e );
+ return new CacheWrapperException( e );
+ }
+
+ private void close( Closeable c )
+ {
+ if ( c == null )
+ return;
+
+ try
+ {
+ c.close();
+ }
+ catch ( IOException e )
+ {
+ log.warn( "Error while trying to close Closable", e);
+ }
+ }
+
+ public void destroy()
+ {
+ log.info( "destroy method of FtpFileCache called" );
+ treeCache.destroy();
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapperException.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapperException.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapperException.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -0,0 +1,57 @@
+/*
+ * 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.gateway.remotestrategies.cache;
+
+/**
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class CacheWrapperException extends Exception
+{
+
+ public CacheWrapperException()
+ {
+ super();
+ }
+
+ public CacheWrapperException(String message, Throwable cause)
+ {
+ super( message, cause );
+ }
+
+ public CacheWrapperException(String message)
+ {
+ super( message );
+ }
+
+ public CacheWrapperException(Throwable cause)
+ {
+ super( cause );
+ }
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+}
Deleted: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCache.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCache.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCache.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -1,311 +0,0 @@
-package org.jboss.soa.esb.listeners.gateway.remotestrategies.cache;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.PropertyConfigurator;
-import org.jboss.cache.TreeCache;
-import org.jboss.cache.TreeCacheListener;
-import org.jboss.soa.esb.util.ClassUtil;
-
-/**
- * Implements a cache of file names which can be replicated in a cluster.
- *
- * See the <a href="http://labs.jboss.com/jbosscache">JBoss Cache</a> docs
- * for details on configuring the cache.
- *
- * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
- *
- */
-public class FtpFileCache
-{
- @SuppressWarnings("unused")
- private Logger log = Logger.getLogger( FtpFileCache.class );
-
- /**
- * Default configuration file for jboss cache.
- * Used if no config is specified upon calling the constructor.
- * Note that this file must then exist on the classpath
- */
- private static final String DEFAULT_CONFIG_FILE = "/ftpfile-cache-config.xml";
- /**
- * The fqn to use.
- */
- private String fqn = "/ftp/cache/";
- /**
- * The configuration file used to configure the tree cache
- */
- private String config;
- /**
- * The JBoss TreeCache instance
- */
- private TreeCache treeCache;
-
- /**
- *
- * @param config either an absolute path of a relative path
- * @throws Exception
- */
- public FtpFileCache ( String config ) throws FtpFileCacheException
- {
- if ( config == null )
- config = DEFAULT_CONFIG_FILE;
-
- this.config = config;
-
- InputStream in = null;
- try
- {
- treeCache = new TreeCache();
- in = getConfigInputStream( this.config );
- PropertyConfigurator configurator = new PropertyConfigurator();
- configurator.configure( treeCache, in );
- }
- catch ( Exception e )
- {
- log.error( e );
- throw new FtpFileCacheException ( e );
- }
- finally
- {
- close( in );
- }
-
-
- }
-
- /**
- * Gets an input stream from the specified path.
- *
- * If the path denotes a file on the filesystem, that file
- * will be used.
- * If a file is not found in the filesystem, this method will look
- * for the file on the classpath.
- *
- * @param path the path to the JBossCache configuration file
- * @return InputStream the inputstream for the passed-in path
- */
- protected InputStream getConfigInputStream( final String path )
- {
- InputStream in = null;
- File configFile = new File( path );
- if ( configFile.exists() )
- {
- log.debug("Reading jboss cache configuration from : " + path );
-
- try
- {
- in = new FileInputStream ( path );
- }
- catch (FileNotFoundException e)
- {
- log.error( e );
- }
- }
- else
- {
- log.debug("Reading jgroups configuration classpath : " + path );
- in = ClassUtil.getResourceAsStream( path, getClass() );
- }
- return in;
- }
-
- /**
- * Start the cache
- * @throws Exception
- */
- public void start() throws FtpFileCacheException
- {
- try
- {
- treeCache.startService();
- }
- catch (Exception e)
- {
- log.error( e );
- throw new FtpFileCacheException( e );
- }
- }
-
- /**
- * Stops the cache
- *
- */
- public void stop()
- {
- treeCache.stopService();
- }
-
- /**
- * Will add the filename to the cache.
- *
- * @param fileName
- * @throws CacheException
- */
- public void putFileName( final String fileName) throws CacheException
- {
- treeCache.put ( fqn, fileName, fileName );
- }
-
- /**
- * Will get the filename if it exists in the cache.
- *
- * @param fileName
- * @throws CacheException
- */
- public Object getFileName( final String fileName) throws CacheException
- {
- return treeCache.get ( fqn, fileName );
- }
-
- /**
- * Removed the fileName from the cache if it exist there
- *
- * @param fileName
- * @return Object the value of the removed object
- * @throws CacheException
- */
- public Object deleteFile( final String fileName ) throws CacheException
- {
- return treeCache.remove( fqn, fileName );
- }
-
- /**
- * Checks to see if the filename exists in the cache
- *
- * @param fileName the filename to look for
- * @return true if the file exists in the cache
- */
- public boolean containsFile( final String fileName )
- {
- return treeCache.exists( fqn, fileName );
- }
-
- /**
- * Gets the a string of all files in the cache
- * @return String
- */
- public String getCache()
- {
- return treeCache.print( fqn );
- }
-
- public String getFqn()
- {
- return fqn;
- }
-
- public void setFqn(String fqn)
- {
- this.fqn = fqn;
- }
-
- public String getConfigFile( )
- {
- return config;
- }
-
- /**
- * Removes all data under the fqn, but not the fqn
- * itself
- *
- * @throws CacheException
- */
- public void removeAll() throws CacheException
- {
- treeCache.removeData( fqn );
- }
-
- public void setDeleteOnEviction()
- {
- treeCache.addTreeCacheListener( new DeleteOnEvictTreeCacheListener( treeCache) );
- }
-
- public void addCacheListener( final TreeCacheListener listener )
- {
- if ( listener != null )
- treeCache.addTreeCacheListener( listener );
- }
-
- public Map getCacheListeners()
- {
- return treeCache.getTreeCacheListeners();
- }
-
- public void setCacheListener( final Class cacheListenerClass ) throws FtpFileCacheException
- {
- if ( cacheListenerClass == null )
- return;
- try
- {
- Constructor constructor = cacheListenerClass.getConstructor( TreeCache.class );
- Object object = constructor.newInstance( treeCache );
- if ( object instanceof TreeCacheListener )
- {
- TreeCacheListener listener = ( TreeCacheListener ) object;
- treeCache.addTreeCacheListener( listener );
- }
- }
- catch (SecurityException e)
- {
- throw createFtpFileCacheException( "SecurityException while trying set the CacheListener:", e );
- }
- catch (NoSuchMethodException e)
- {
- throw createFtpFileCacheException( "NoSuchMethodException while trying set the CacheListener:", e );
- }
- catch (IllegalArgumentException e)
- {
- throw createFtpFileCacheException( "IllegalArgumentException while trying set the CacheListener:", e );
- }
- catch (InstantiationException e)
- {
- throw createFtpFileCacheException( "InstantiationException while trying set the CacheListener:", e );
- }
- catch (IllegalAccessException e)
- {
- throw createFtpFileCacheException( "IllegalAccessException while trying set the CacheListener:", e );
- }
- catch (InvocationTargetException e)
- {
- throw createFtpFileCacheException( "InvocationTargetException while trying set the CacheListener:", e );
- }
- }
-
- private FtpFileCacheException createFtpFileCacheException( final String msg, Exception e )
- {
- log.error( msg, e );
- return new FtpFileCacheException( e );
- }
-
- private void close( Closeable c )
- {
- if ( c == null )
- return;
-
- try
- {
- c.close();
- }
- catch ( IOException e )
- {
- log.warn( "Error while trying to close Closable", e);
- }
- }
-
- public void destroy()
- {
- log.info( "destroy method of FtpFileCache called" );
- treeCache.destroy();
- }
-
-}
\ No newline at end of file
Deleted: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheException.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheException.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheException.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -1,57 +0,0 @@
-/*
- * 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.gateway.remotestrategies.cache;
-
-/**
- *
- * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
- *
- */
-public class FtpFileCacheException extends Exception
-{
-
- public FtpFileCacheException()
- {
- super();
- }
-
- public FtpFileCacheException(String message, Throwable cause)
- {
- super( message, cause );
- }
-
- public FtpFileCacheException(String message)
- {
- super( message );
- }
-
- public FtpFileCacheException(Throwable cause)
- {
- super( cause );
- }
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
-}
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -44,6 +44,7 @@
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.gateway.remotestrategies.ReadOnlyRemoteFileSystemStrategy;
+import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.CacheWrapper;
import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.DeleteOnEvictTreeCacheListener;
import org.jboss.soa.esb.listeners.gateway.remotestrategies.cache.FtpFileCacheTestUtil;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
@@ -201,7 +202,7 @@
{
ConfigTree configTree = RemoteGatewayListenerUnitTest.createConfigTree();
configTree.setAttribute( ReadOnlyRemoteGatewayListener.REMOTE_FILE_SYSTEM_STRATEGY_CLASS, ReadOnlyRemoteFileSystemStrategy.class.getName() );
- configTree.setAttribute( ReadOnlyRemoteGatewayListener.REMOTE_FILE_SYSTEM_STRATEGY_CONFIG_FILE, FtpFileCacheTestUtil.getCacheConfigFile() );
+ configTree.setAttribute( CacheWrapper.CACHE_CONFIG_FILE, FtpFileCacheTestUtil.getCacheConfigFile() );
configTree.setAttribute( ReadOnlyRemoteGatewayListener.REMOTE_FILE_SYSTEM_STRATEGY_CACHE_LISTENER, DeleteOnEvictTreeCacheListener.class.getName() );
return configTree;
}
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapperIntegrationTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapperIntegrationTest.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/CacheWrapperIntegrationTest.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -0,0 +1,130 @@
+package org.jboss.soa.esb.listeners.gateway.remotestrategies.cache;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.InputStream;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.jboss.cache.CacheException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * Test class CacheWrapper
+ *
+ * @author Daniel Bevenius
+ *
+ */
+public class CacheWrapperIntegrationTest
+{
+ private static Logger log = Logger.getLogger( CacheWrapperIntegrationTest.class );
+
+ private static CacheWrapper cacheWrapper;
+
+ @Test
+ public void getConfigInputStream_From_Classpath() throws Exception
+ {
+ String configPath_CP = "/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/ftpfile_cache_test.xml";
+ InputStream configInputStream = cacheWrapper.getConfigInputStream( configPath_CP );
+ assertNotNull( "InputStream was null", configInputStream );
+ }
+
+ @Test
+ public void getPutAndRemove()
+ {
+ String fileName = "testfile1";
+ try
+ {
+ cacheWrapper.putObject( fileName, fileName );
+
+ Object obj = cacheWrapper.getObject( fileName );
+ assertTrue( obj instanceof String );
+
+ String actualFileName = (String) obj;
+ assertEquals( fileName, actualFileName );
+ }
+ catch (CacheException e)
+ {
+ fail ( e.getMessage() );
+ }
+ finally
+ {
+ try { cacheWrapper.deleteObject( fileName ); } catch (CacheException e) { log.error( e.getMessage() ); }
+ }
+ }
+
+ @Test
+ public void addCacheListenerNegative()
+ {
+ try
+ {
+ cacheWrapper.addCacheListener( null );
+ }
+ catch ( Exception e )
+ {
+ fail("Should be ok to pass a null listener! Exception was : "+ e.getMessage() );
+ }
+ }
+
+ @Test
+ public void fileExists() throws CacheException
+ {
+ String fileName = "testfile1";
+
+ cacheWrapper.putObject( fileName, fileName );
+
+ boolean fileExistsInCache = cacheWrapper.containsObject( fileName );
+ assertTrue ( fileExistsInCache );
+ }
+
+ @Test
+ public void removeAll() throws CacheException
+ {
+ String fileName = "testfile3";
+ cacheWrapper.putObject( fileName, fileName );
+ cacheWrapper.removeAll();
+ assertNull ( cacheWrapper.getObject( fileName ));
+
+ }
+
+ @BeforeClass
+ public static void classSetup() throws Exception
+ {
+ FtpFileCacheTestUtil.startDB();
+ String cacheConfigFile = FtpFileCacheTestUtil.getCacheConfigFile();
+
+ cacheWrapper = new CacheWrapper ( createConfigTree( cacheConfigFile ) );
+ cacheWrapper.start();
+ }
+
+
+ @AfterClass
+ public static void classTearDown() throws Exception
+ {
+ cacheWrapper.stop();
+ FtpFileCacheTestUtil.stopDB();
+ }
+
+ public static ConfigTree createConfigTree( String configFile )
+ {
+ final ConfigTree configTree = new ConfigTree( "cache-wrapper-integration-test");
+ configTree.setAttribute( CacheWrapper.CACHE_CONFIG_FILE , configFile );
+ configTree.setAttribute( CacheWrapper.CACHE_FQN , "/ftp/cache/" );
+ return configTree;
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter( CacheWrapperIntegrationTest.class );
+ }
+
+}
Deleted: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheIntegrationTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheIntegrationTest.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/FtpFileCacheIntegrationTest.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -1,120 +0,0 @@
-package org.jboss.soa.esb.listeners.gateway.remotestrategies.cache;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.InputStream;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.Logger;
-import org.jboss.cache.CacheException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-
-/**
- * Test class FtpFileCache
- *
- * @author Daniel Bevenius
- *
- */
-public class FtpFileCacheIntegrationTest
-{
- private static Logger log = Logger.getLogger(FtpFileCacheIntegrationTest.class);
-
- private static FtpFileCache ftpfileCache;
-
- @Test
- public void getConfigInputStream_From_Classpath() throws Exception
- {
- String configPath_CP = "/org/jboss/soa/esb/listeners/gateway/remotestrategies/cache/ftpfile_cache_test.xml";
- InputStream configInputStream = ftpfileCache.getConfigInputStream( configPath_CP );
- assertNotNull( "InputStream was null", configInputStream );
- }
-
- @Test
- public void getPutAndRemove()
- {
- String fileName = "testfile1";
- try
- {
- ftpfileCache.putFileName( fileName );
-
- Object obj = ftpfileCache.getFileName( fileName );
- assertTrue( obj instanceof String );
-
- String actualFileName = (String) obj;
- assertEquals( fileName, actualFileName );
- }
- catch (CacheException e)
- {
- fail ( e.getMessage() );
- }
- finally
- {
- try { ftpfileCache.deleteFile( fileName ); } catch (CacheException e) { log.error( e.getMessage() ); }
- }
- }
-
- @Test
- public void addCacheListenerNegative()
- {
- try
- {
- ftpfileCache.addCacheListener( null );
- }
- catch ( Exception e )
- {
- fail("Should be ok to pass a null listener! Exception was : "+ e.getMessage() );
- }
- }
-
- @Test
- public void fileExists() throws CacheException
- {
- String fileName = "testfile1";
-
- ftpfileCache.putFileName( fileName );
-
- boolean fileExistsInCache = ftpfileCache.containsFile( fileName );
- assertTrue ( fileExistsInCache );
- }
-
- @Test
- public void removeAll() throws CacheException
- {
- String fileName = "testfile3";
- ftpfileCache.putFileName( fileName );
- ftpfileCache.removeAll();
- assertNull ( ftpfileCache.getFileName( fileName ));
-
- }
-
- @BeforeClass
- public static void classSetup() throws Exception
- {
- FtpFileCacheTestUtil.startDB();
-
- ftpfileCache = new FtpFileCache ( FtpFileCacheTestUtil.getCacheConfigFile() );
- ftpfileCache.start();
- }
-
-
- @AfterClass
- public static void classTearDown() throws Exception
- {
- ftpfileCache.stop();
- FtpFileCacheTestUtil.stopDB();
- }
-
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter( FtpFileCacheIntegrationTest.class );
- }
-
-}
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml 2007-07-12 06:51:42 UTC (rev 13393)
@@ -45,13 +45,13 @@
busidref="helloFileChannel"
maxThreads="1"
is-gateway="true">
+ <property name="cronExpression" value="0/30 * * * * ?" />
+ <property name="startDate" value="07-07-08 19:17:00" />
+ <property name="endDate" value="07-07-08 19:20:00" />
<!--
- <property name="cronExpression" value="0/30 * * * * ?" />
- <property name="startDate" value="07-07-08 14:25:00" />
- <property name="endDate" value="07-07-08 14:27:00" />
- -->
<property name="pollLatencySeconds" value="10" />
<property name="repeatCount" value="6" />
+ -->
</fs-listener>
<jms-listener name="helloWorldFileAction"
busidref="quickstartEsbChannel"
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGateway.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGateway.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGateway.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -23,7 +23,11 @@
import static org.jboss.soa.esb.listeners.ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG;
import static org.jboss.soa.esb.listeners.ListenerTagNames.TARGET_SERVICE_NAME_TAG;
-
+import static org.jboss.soa.esb.listeners.ListenerTagNames.GATEWAY_RESPONDER_METHOD_TAG;
+import static org.jboss.soa.esb.listeners.ListenerTagNames.GATEWAY_COMPOSER_CLASS_TAG;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -38,7 +42,9 @@
import org.jboss.soa.esb.couriers.Courier;
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.couriers.TwoWayCourier;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerUtil;
import org.jboss.soa.esb.listeners.RegistryUtil;
@@ -46,6 +52,7 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.ClassUtil;
/**
* Abstract Web Service Gateway
@@ -103,6 +110,15 @@
/* EPRs for calling ESB services */
protected Collection<EPR> targetEprs;
+
+ /* Class which will contain the response method. */
+ protected Class responseClass;
+ /* method to be called after the action processing pipeline executed. */
+ protected Method responseMethod;
+ /* The actual object ( will be an instance of repsonseClass ) */
+ protected Object responseObject;
+ /* the max millis seconds to wait for a response from the action pipeline */
+ private long maxMillisForResponse;
/* Location in the Message object body */
protected static final String ATTR_SOAP_PARAMETERS = "soapParameters";
@@ -112,6 +128,11 @@
protected static final String ATTR_WSDL = "wsdl";
protected static final String ATTR_OPERATION = "operation";
+ /**
+ *
+ * @param configTree configuration properties from jboss-esb.xml
+ * @throws ConfigurationException
+ */
public AbstractWSGateway( final ConfigTree configTree) throws ConfigurationException
{
super( configTree );
@@ -143,6 +164,19 @@
protected abstract void postESBServiceProcessing( final Message soapResponseMessage );
/**
+ * Default no-op method for subclasses to override.
+ * If the configuration property "max-millis-for-response has been
+ * set, then this method will be executed after a response has
+ * been retrieved from the ESB.
+ *
+ * @param messge Message returned from action processing pipeline.
+ */
+ public void responseMethod( final Message message )
+ {
+ log.debug( "Default no-op response method called..." );
+ }
+
+ /**
* Templete method that will :
* <lu>
* <li> invoke the target Web Service,
@@ -187,6 +221,10 @@
catch ( final ActionProcessingException e)
{
log.error( e );
+ }
+ catch (CourierTimeoutException e)
+ {
+ log.error( e );
}
finally
{
@@ -202,24 +240,66 @@
*
* @throws CourierException
* @throws MalformedEPRException
+ * @throws CourierTimeoutException
*/
- protected void sendToService ( final Message message ) throws CourierException, MalformedEPRException
+ protected void sendToService ( final Message message ) throws CourierException, MalformedEPRException, CourierTimeoutException
{
- Courier courier = null;
+ Courier sendCourier = null;
+
+ EPR replyEpr = null;
for (EPR current : targetEprs)
{
- courier = getCourier(current);
- try
+ sendCourier = getCourier( current );
+ log.debug( "send Courier : " + sendCourier );
+ try
+ {
+ message.getHeader().getCall().setTo( current );
+ log.debug( "maxMillisForResponse : " + maxMillisForResponse );
+ if ( maxMillisForResponse > 0)
+ {
+ replyEpr = CourierUtil.getDefaultReplyToEpr( current );
+ message.getHeader().getCall().setReplyTo( replyEpr );
+ }
+ if (sendCourier.deliver( message ))
+ {
+ break;
+ }
+ }
+ finally
{
- message.getHeader().getCall().setTo(current);
- if ( courier.deliver( message ))
- break;
+ CourierUtil.cleanCourier( sendCourier ) ;
}
+ }
+
+ log.debug( " replyEpr : " + replyEpr );
+ if ( replyEpr != null )
+ {
+ TwoWayCourier replyCourier = CourierFactory.getPickupCourier( replyEpr );
+ try
+ {
+ Message replyMessage = replyCourier.pickup( maxMillisForResponse );
+ responseMethod.invoke( responseObject, new Object[] { replyMessage });
+ }
+ catch (IllegalArgumentException e)
+ {
+ log.error ( e );
+ throw new CourierException ( e );
+ }
+ catch (IllegalAccessException e)
+ {
+ log.error ( e );
+ throw new CourierException ( e );
+ }
+ catch (InvocationTargetException e)
+ {
+ log.error ( e );
+ throw new CourierException ( e );
+ }
finally
{
- CourierUtil.cleanCourier( courier ) ;
+ CourierUtil.cleanCourier( replyCourier ) ;
}
- }
+ }
}
/**
@@ -310,16 +390,93 @@
*/
private void checkMyParms( final ConfigTree configTree ) throws ConfigurationException
{
- log.debug( "WSGateway configtree : " + configTree );
targetServiceCategory = ListenerUtil.obtainAtt( configTree, TARGET_SERVICE_CATEGORY_TAG, null);
targetServiceName = ListenerUtil.obtainAtt( configTree, TARGET_SERVICE_NAME_TAG, null);
soapHeaders = getHeaders( configTree );
soapParameters = getParameters( configTree );
+ resolveRepsonseClass( configTree );
+ maxMillisForResponse = ListenerUtil.getMaxMillisGatewayWait( configTree, log, responseMethod != null );
+ log.debug( "maxMillisForResponse : " + maxMillisForResponse );
+ }
+
+ protected void resolveRepsonseClass(final ConfigTree configTree ) throws ConfigurationException
+ {
+ createResponseClass( configTree );
- log.debug( "SoapHeaders :" + soapHeaders );
- log.debug( "SoapParameters :" + soapParameters );
+ createResponseMethod( configTree );
+
}
+
+ private void createResponseMethod( final ConfigTree configTree ) throws ConfigurationException
+ {
+ String responseMethodAttr = configTree.getAttribute( GATEWAY_RESPONDER_METHOD_TAG );
+ if ( responseMethodAttr == null )
+ responseMethodAttr = "responseMethod";
+
+ try
+ {
+ responseMethod = responseObject.getClass().getMethod( responseMethodAttr, new Class[] { Message.class });
+ }
+ catch (SecurityException e)
+ {
+ logAndThrowConfException( e );
+ }
+ catch (NoSuchMethodException e)
+ {
+ logAndThrowConfException( e );
+ }
+ }
+
+ private void createResponseClass( final ConfigTree configTree ) throws ConfigurationException
+ {
+ String responseClassName = configTree.getAttribute( GATEWAY_COMPOSER_CLASS_TAG );
+ if ( responseClassName != null )
+ {
+ try
+ {
+ responseClass = ClassUtil.forName( responseClassName, getClass());
+ Constructor cinit = responseClass.getConstructor(new Class[] { ConfigTree.class });
+ responseObject = cinit.newInstance( configTree );
+ }
+ catch (ClassNotFoundException e)
+ {
+ logAndThrowConfException( e );
+ }
+ catch (SecurityException e)
+ {
+ logAndThrowConfException( e );
+ }
+ catch (NoSuchMethodException e)
+ {
+ logAndThrowConfException( e );
+ }
+ catch (IllegalArgumentException e)
+ {
+ logAndThrowConfException( e );
+ }
+ catch (InstantiationException e)
+ {
+ logAndThrowConfException( e );
+ }
+ catch (IllegalAccessException e)
+ {
+ logAndThrowConfException( e );
+ }
+ catch (InvocationTargetException e)
+ {
+ logAndThrowConfException( e );
+ }
+ }
+ else
+ responseObject = this;
+ }
+ private void logAndThrowConfException( final Exception e ) throws ConfigurationException
+ {
+ log.error( e );
+ throw new ConfigurationException ( e );
+ }
+
/**
* Will extract the SOAP parameters from the ConfigTree and put
* them into a Map which is returned.
@@ -344,17 +501,22 @@
return getParameters( configTree, ATTR_SOAP_HEADER );
}
- protected Map<String,String> getParameters( final ConfigTree configTree, String childName )
+ protected Map<String,String> getParameters( final ConfigTree configTree, final String childName )
{
final Map<String,String> parameters = new HashMap<String,String>();
+ log.debug( "look for " + childName );
final ConfigTree[] children = configTree.getChildren( childName );
+ log.debug( "children " + children.length );
if ( children != null )
for ( ConfigTree child : children )
{
- parameters.put( child.getAttribute( "name" ), child.getAttribute( "value" ) );
- log.debug ( "put child into map; " + child );
+ if ( child.getAttribute( childName ) == null )
+ {
+ parameters.put( child.getAttribute( "name" ), child.getAttribute( "value" ) );
+ log.debug ( "put child into map; " + child );
+ }
}
return parameters;
Deleted: labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/WSGateway.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/WSGateway.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/WSGateway.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -1,87 +0,0 @@
-/*
- * 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.gateway;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Message;
-
-/**
- * Web Service Gateway
- * </p>
- *
- * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
- *
- */
-public class WSGateway extends AbstractWSGateway
-{
- private static final long serialVersionUID = 1L;
-
- private Logger log = Logger.getLogger( WSGateway.class );
-
- public WSGateway( final ConfigTree configTree) throws ConfigurationException
- {
- super( configTree );
- }
-
- private static int counter = 0;
-
- /**
- * Gets the SOAP parameters. If using document style this might simply be
- * one parameter that is an xml string.
- *
- * @return <code>Map</code> map of parameters used to invoke the web service
- */
- protected Map<String, String> getWebServiceArguments()
- {
- log.debug( "counter ; " + counter );
- HashMap<String, String> params = new HashMap<String,String>();
- params.put( "api:afterItemId", String.valueOf( counter ));
- counter++;
- return params;
- }
-
- /**
- * Perform action prior to invoking the target service.
- *
- * @param soapResponseMessage The message that will be sent to the target service
- */
- protected void preESBServiceProcessing( final Message soapResponseMessage )
- {
- log.debug( "preESBServiceProcessing..." );
- }
-
- /**
- * Perform action after invoking the target service.
- *
- * @param soapResponseMessage The message that was sent to the target service
- */
- protected void postESBServiceProcessing( final Message soapResponseMessage )
- {
- log.debug( "postESBServiceProcessing..." );
- }
-
-}
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGatewayUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGatewayUnitTest.java 2007-07-12 06:29:40 UTC (rev 13392)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGatewayUnitTest.java 2007-07-12 06:51:42 UTC (rev 13393)
@@ -24,9 +24,14 @@
import static org.jboss.soa.esb.listeners.ListenerTagNames.POLL_LATENCY_SECS_TAG;
import static org.jboss.soa.esb.listeners.ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG;
import static org.jboss.soa.esb.listeners.ListenerTagNames.TARGET_SERVICE_NAME_TAG;
+import static org.jboss.soa.esb.listeners.ListenerTagNames.GATEWAY_COMPOSER_CLASS_TAG;
+import static org.jboss.soa.esb.listeners.ListenerTagNames.GATEWAY_WAIT_MILLIS_TAG;
+import static org.jboss.soa.esb.listeners.ListenerTagNames.GATEWAY_RESPONDER_METHOD_TAG;
import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_OPERATION;
import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_SOAP_HEADER;
+import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_SOAP_HEADERS;
import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_SOAP_PARAMETER;
+import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_SOAP_PARAMETERS;
import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_WSDL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -37,6 +42,8 @@
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.ListenerUtil;
import org.jboss.soa.esb.message.Message;
import org.junit.Test;
@@ -81,7 +88,6 @@
public void getSOAPParameters() throws ConfigurationException
{
ConfigTree tree = createSoapParametersConfigTree();
- log.debug ( tree );
MockWSGateway gateway = new MockWSGateway( tree );
Map<String, String> parameters = gateway.getParameters( tree );
@@ -93,7 +99,6 @@
public void getSOAPHeaders() throws ConfigurationException
{
ConfigTree tree = createSoapHeaderConfigTree();
- log.debug ( tree );
MockWSGateway gateway = new MockWSGateway( tree );
Map<String, String> headers = gateway.getHeaders( tree );
@@ -101,6 +106,38 @@
assertEquals( 2, headers.size() );
}
+ @Test
+ public void resolveComposerDefault() throws ConfigurationException
+ {
+ ConfigTree tree = createSoapParametersConfigTree();
+ MockWSGateway gateway = new MockWSGateway( tree );
+ gateway.resolveRepsonseClass( tree );
+ }
+
+ @Test
+ public void resolveComposer_with_composerclass_and_responderMethod() throws ConfigurationException
+ {
+ ConfigTree tree = createSoapParametersConfigTree();
+ tree.setAttribute( GATEWAY_COMPOSER_CLASS_TAG, "org.jboss.soa.esb.listeners.gateway.AbstractWSGatewayUnitTest$MockRespond");
+ tree.setAttribute( GATEWAY_RESPONDER_METHOD_TAG, "afterProcess");
+ tree.setAttribute( GATEWAY_WAIT_MILLIS_TAG, "10000" );
+
+ MockWSGateway gateway = new MockWSGateway( tree );
+ gateway.resolveRepsonseClass( tree );
+ }
+
+ @Test
+ public void resolveComposer_with_responderMethod() throws ConfigurationException
+ {
+ ConfigTree tree = createSoapParametersConfigTree();
+ tree.setAttribute( GATEWAY_RESPONDER_METHOD_TAG, "doit");
+ tree.setAttribute( GATEWAY_WAIT_MILLIS_TAG, "10000" );
+
+ MockWSGateway gateway = new MockWSGateway( tree );
+ gateway.resolveRepsonseClass( tree );
+ }
+
+
/**
* Produces the following ConfigTree:
*
@@ -111,7 +148,7 @@
* </AbstractPollingGatewayUnitTest>
*
*/
- private ConfigTree createConfigTree( final long pollInterval )
+ public static ConfigTree createConfigTree( final long pollInterval )
{
final ConfigTree tree = new ConfigTree("AbstractPollingGatewayUnitTest");
tree.setAttribute( POLL_LATENCY_SECS_TAG, String.valueOf( pollInterval ) );
@@ -138,23 +175,21 @@
* </AbstractPollingGatewayUnitTest>
*
*/
- private ConfigTree createSoapHeaderConfigTree()
+ public static ConfigTree createSoapHeaderConfigTree()
{
ConfigTree tree = createConfigTree( 10 );
- ConfigTree property1 = new ConfigTree( ATTR_SOAP_HEADER , tree );
- property1.setAttribute( "name", "user");
- property1.setAttribute( "value", "beve" );
+ ConfigTree property1 = new ConfigTree( ATTR_SOAP_HEADER, tree );
+ property1.setAttribute( "name", "param1");
+ property1.setAttribute( "value", "value1" );
- ConfigTree property2 = new ConfigTree( ATTR_SOAP_HEADER , tree );
- property2.setAttribute( "name", "password");
- property2.setAttribute( "value", "letmein" );
-
+ ConfigTree property2 = new ConfigTree( ATTR_SOAP_HEADER, tree );
+ property2.setAttribute( "name", "param2");
+ property2.setAttribute( "value", "2" );
+
return tree;
}
-
-
/**
* Produces the following ConfigTree:
*
@@ -170,17 +205,19 @@
*
* @return
*/
- private ConfigTree createSoapParametersConfigTree()
+ public static ConfigTree createSoapParametersConfigTree()
{
ConfigTree tree = createConfigTree( 10 );
+ // even though this might look wrong this is how the configtree
+ // looks like when passed to the constructor at runtime
ConfigTree property1 = new ConfigTree( ATTR_SOAP_PARAMETER, tree );
property1.setAttribute( "name", "param1");
property1.setAttribute( "value", "value1" );
ConfigTree property2 = new ConfigTree( ATTR_SOAP_PARAMETER, tree );
property2.setAttribute( "name", "param2");
- property2.setAttribute( "value", "value2" );
+ property2.setAttribute( "value", "2" );
return tree;
}
@@ -210,5 +247,23 @@
return null;
}
+ public void doit( final Message message )
+ {
+ log.debug( "doit in MockWSGateway" );
+ }
}
+
+ private static class MockRespond
+ {
+ private Logger log = Logger.getLogger( MockRespond.class );
+
+ public MockRespond( final ConfigTree configTree ) {}
+
+
+ public void afterProcess( final Message message )
+ {
+ log.debug( "afterProcess in MockRespond" );
+ }
+
+ }
}
More information about the jboss-svn-commits
mailing list