[jboss-svn-commits] JBL Code SVN: r13907 - in labs/jbossesb/workspace/scheduled-file-listener: product/rosetta/src/org/jboss/soa/esb/listeners/gateway and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jul 31 08:02:30 EDT 2007
Author: tfennelly
Date: 2007-07-31 08:02:29 -0400 (Tue, 31 Jul 2007)
New Revision: 13907
Removed:
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/XAbstractFileGateway.java
Modified:
labs/jbossesb/workspace/scheduled-file-listener/
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAwareListener.java
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduledEventListener.java
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/MockCourierFactory.java
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerIntegrationTest.java
labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java
Log:
Property changes on: labs/jbossesb/workspace/scheduled-file-listener
___________________________________________________________________
Name: svn:ignore
- .settings
.classpath
.project
bin
.packaging
build
junit
ObjectToFileWriter.tst
+ .settings
.classpath
.project
bin
.packaging
build
junit
ObjectToFileWriter.tst
runci.bat
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -30,35 +30,26 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
-import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.MalformedEPRException;
-import org.jboss.soa.esb.addressing.util.DefaultReplyTo;
+import org.jboss.soa.esb.schedule.ScheduledEventListener;
+import org.jboss.soa.esb.schedule.SchedulingException;
import org.jboss.soa.esb.common.Environment;
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.filter.FilterManager;
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.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.listeners.ServiceInvoker;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.listeners.lifecycle.*;
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.
@@ -69,8 +60,8 @@
* href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
* @since Version 4.0
*/
-public abstract class AbstractFileGateway extends
- AbstractThreadedManagedLifecycle {
+public abstract class AbstractFileGateway extends AbstractManagedLifecycle implements ScheduledEventListener {
+
abstract File[] getFileList() throws GatewayException;
abstract byte[] getFileContents(File file) throws GatewayException;
@@ -89,7 +80,6 @@
throws ConfigurationException, RegistryException, GatewayException {
super(config);
_config = config;
- _sleepBetweenPolls = 10000; // milliseconds
checkMyParms();
} // __________________________________
@@ -100,241 +90,167 @@
*/
protected void doInitialise() throws ManagedLifecycleException {
try {
- _targetEprs = RegistryUtil.getEprs(_targetServiceCategory,
- _targetServiceName);
- if (null == _targetEprs || _targetEprs.size() < 1)
- throw new ManagedLifecycleException("EPR <"
- + _targetServiceName + "> not found in registry");
+ serviceInvoker = new ServiceInvoker(_targetServiceCategory, _targetServiceName);
+ } catch (final RegistryException re) {
+ throw new ManagedLifecycleException(re);
+ } catch (MessageDeliverException e) {
+ throw new ManagedLifecycleException(e);
}
- catch (final RegistryException re) {
- throw new ManagedLifecycleException(
- "Unexpected registry exception", re);
- }
}
+ protected void doStart() throws ManagedLifecycleException {
+ }
+
+ protected void doStop() throws ManagedLifecycleException {
+ }
+
+ protected void doDestroy() throws ManagedLifecycleException {
+ }
+
/**
- * Execute on the thread.
+ * Execute on trigger from the scheduler.
*/
- protected void doRun() {
+ public void onSchedule() throws SchedulingException {
- EPR replyEpr = null;
- Message replyMsg = null;
-
- if (_logger.isDebugEnabled()) {
- _logger.debug("run() method of " + this.getClass().getSimpleName()
- + " started on thread " + Thread.currentThread().getName());
+ File[] fileList;
+ try {
+ fileList = getFileList();
}
+ catch (GatewayException e) {
+ _logger.error("Can't retrieve file list", e);
+ return;
+ }
- do {
- File[] fileList;
+ for (File fileIn : fileList) {
+
+ // Only continue to process files if we're in a STARTED state...
+ if(getState() != ManagedLifecycleState.STARTED) {
+ break;
+ }
+
+ // Try to rename - if unsuccessful, somebody else got it first
+ File fileWork = getWorkFileName(fileIn, _workingSuffix);
try {
- fileList = getFileList();
+ if (!renameFile(fileIn, fileWork))
+ continue;
}
catch (GatewayException e) {
- _logger.error("Can't retrieve file list", e);
+ _logger.error("Problems renaming file " + fileIn + " to "
+ + fileWork);
continue;
}
- for (File fileIn : fileList) {
- // Try to rename - if unsuccessful, somebody else got it first
- File fileWork = getWorkFileName(fileIn, _workingSuffix);
- try {
- if (!renameFile(fileIn, fileWork))
- continue;
- }
- catch (GatewayException e) {
- _logger.error("Problems renaming file " + fileIn + " to "
- + fileWork);
+ Throwable thrown = null;
+ String text = null;
+ try {
+ Object obj = _processMethod.invoke(_composer, new Object[] {fileWork});
+ if (null == obj) {
+ _logger.warn("Action class method <"
+ + _processMethod.getName()
+ + "> returned a null object");
continue;
}
+ boolean bSent = false;
- Throwable thrown = null;
- String text = null;
- try {
- Object obj = _processMethod.invoke(_composer, new Object[]
- {fileWork});
- if (null == obj) {
- _logger.warn("Action class method <"
- + _processMethod.getName()
- + "> returned a null object");
- continue;
- }
- boolean bSent = false;
+ Message outMessage = (Message) obj;
+ Map<String, Object> params = new HashMap<String, Object>();
- Message outMessage = (Message) obj;
- Map<String, Object> params = new HashMap<String, Object>();
+ params.put(Environment.ORIGINAL_FILE, fileIn);
+ params.put(Environment.GATEWAY_CONFIG, _config);
- params.put(Environment.ORIGINAL_FILE, fileIn);
- params.put(Environment.GATEWAY_CONFIG, _config);
-
- outMessage = FilterManager.getInstance().doOutputWork(outMessage, params);
-
- for (EPR current : _targetEprs) {
- _courier = getCourier(current);
- try {
- replyEpr = null;
- outMessage.getHeader().getCall().setTo(current);
- if (_maxMillisForResponse > 0) {
- replyEpr = DefaultReplyTo
- .getReplyTo(current);
- outMessage.getHeader().getCall().setReplyTo(
- replyEpr);
- }
- if (_courier.deliver(outMessage)) {
- bSent = true;
- break;
- }
- }
- finally {
- CourierUtil.cleanCourier(_courier);
- }
-
+ outMessage = FilterManager.getInstance().doOutputWork(outMessage, params);
+ try {
+ if (_maxMillisForResponse > 0) {
+ Message replyMsg = serviceInvoker.deliverSync(outMessage, _maxMillisForResponse);
+ _responderMethod.invoke(_composer, new Object[] {replyMsg, fileIn});
+ } else {
+ serviceInvoker.deliverAsync(outMessage);
}
- if (!bSent) {
- text = "Target service <" + _targetServiceCategory
- + "," + _targetServiceName
- + "> is not registered";
- thrown = new Exception(text);
- } else if (null != replyEpr) {
- TwoWayCourier replyCourier = CourierFactory
- .getPickupCourier(replyEpr);
- try {
- replyMsg = replyCourier
- .pickup(_maxMillisForResponse);
- _responderMethod.invoke(_composer, new Object[]
- {replyMsg, fileIn});
- }
- catch (CourierTimeoutException e) {
- thrown = e;
- text = "Expected response was not received from invoked service";
- replyMsg = MessageFactory.getInstance()
- .getMessage();
- String timedOut = "Service <"
- + _targetServiceCategory + ","
- + "_targetServiceName"
- + "> timed out without sending response";
- replyMsg.getBody()
- .setByteArray(timedOut.getBytes());
- _responderMethod.invoke(_composer, new Object[]
- {replyMsg, fileIn});
- }
- finally {
- if (null != replyCourier)
- CourierUtil.cleanCourier(replyCourier);
- }
- }
- }
- catch (InvocationTargetException e) {
+ } catch (MessageDeliverException e) {
thrown = e;
- text = "Problems invoking method <"
- + _processMethod.getName() + ">";
-
- }
- catch (IllegalAccessException e) {
+ } catch (RegistryException e) {
thrown = e;
- text = "Problems invoking method <"
- + _processMethod.getName() + ">";
}
- catch (ClassCastException e) {
- thrown = e;
- text = "Action class method <" + _processMethod.getName()
- + "> returned a non Message object";
- }
- catch (CourierException e) {
- thrown = e;
- if (null != _courier)
- text = "Courier <" + _courier.getClass().getName()
- + ".deliverAsync(Message) FAILED";
- else
- text = "NULL courier can't deliverAsync Message";
- }
- catch (MalformedEPRException e) {
- thrown = e;
- if (null != _courier)
- text = "Courier <"
- + _courier.getClass().getName()
- + ".deliverAsync(Message) FAILED with malformed EPR.";
- else
- text = "NULL courier can't deliverAsync Message";
- }
+ }
+ catch (InvocationTargetException e) {
+ thrown = e;
+ text = "Problems invoking method <" + _processMethod.getName() + ">";
- if (null == thrown) {
- File fileOK = new File(_postProcessDirectory, fileIn
- .getName()
- + _postProcessSuffix);
- if (_deleteAfterOK) {
- try {
- deleteFile(fileWork);
- }
- catch (GatewayException e) {
- _logger
- .error(
- "File "
- + fileIn
- + " has been processed and renamed to "
- + fileWork
- + ", but there were problems deleting it from the input directory ",
- e);
- }
- } else {
- try {
- renameFile(fileWork, fileOK);
- }
- catch (GatewayException e) {
- _logger
- .error(
- "File "
- + fileIn
- + " has been processed and renamed to "
- + fileWork
- + ", but there were problems renaming it to "
- + fileOK, e);
- }
- }
- } else {
- thrown.printStackTrace();
- _logger.error(text, thrown);
- File fileError = new File(_errorDirectory, fileIn.getName()
- + _errorSuffix);
+ }
+ catch (IllegalAccessException e) {
+ thrown = e;
+ text = "Problems invoking method <" + _processMethod.getName() + ">";
+ }
+ catch (ClassCastException e) {
+ thrown = e;
+ text = "Action class method <" + _processMethod.getName() + "> returned a non Message object";
+ }
+ catch (CourierException e) {
+ thrown = e;
+ if (null != _courier)
+ text = "Courier <" + _courier.getClass().getName()
+ + ".deliverAsync(Message) FAILED";
+ else
+ text = "NULL courier can't deliverAsync Message";
+ }
+
+ if (null == thrown) {
+ File fileOK = new File(_postProcessDirectory, fileIn.getName() + _postProcessSuffix);
+ if (_deleteAfterOK) {
try {
- deleteFile(fileError);
+ deleteFile(fileWork);
}
catch (GatewayException e) {
- _logger.warn("File : " + fileError + " did not exist.");
+ _logger
+ .error(
+ "File "
+ + fileIn
+ + " has been processed and renamed to "
+ + fileWork
+ + ", but there were problems deleting it from the input directory ",
+ e);
}
+ } else {
try {
- renameFile(fileWork, fileError);
+ renameFile(fileWork, fileOK);
}
catch (GatewayException e) {
- _logger.error("Problems renaming file " + fileWork
- + " to " + fileError, e);
+ _logger
+ .error(
+ "File "
+ + fileIn
+ + " has been processed and renamed to "
+ + fileWork
+ + ", but there were problems renaming it to "
+ + fileOK, e);
}
}
+ } else {
+ thrown.printStackTrace();
+ _logger.error(text, thrown);
+ File fileError = new File(_errorDirectory, fileIn.getName()
+ + _errorSuffix);
+ try {
+ deleteFile(fileError);
+ }
+ catch (GatewayException e) {
+ _logger.warn("File : " + fileError + " did not exist.");
+ }
+ try {
+ renameFile(fileWork, fileError);
+ }
+ catch (GatewayException e) {
+ _logger.error("Problems renaming file " + fileWork
+ + " to " + fileError, e);
+ }
}
}
- while (!waitForRunningStateChange(ManagedLifecycleThreadState.STOPPING,
- _sleepBetweenPolls));
-
- if (_logger.isDebugEnabled()) {
- _logger
- .debug("run() method of " + this.getClass().getSimpleName()
- + " finished on thread "
- + Thread.currentThread().getName());
- }
} // ________________________________
protected File getWorkFileName(File fileIn, String suffix) {
return new File(fileIn.toString() + _workingSuffix);
}
- /*
- * Extracted to simplify testing
- */
- protected Courier getCourier(EPR current) throws CourierException,
- MalformedEPRException {
- return CourierFactory.getCourier(current);
- }
-
/**
* Handle the threaded destroy of the managed instance.
*
@@ -369,24 +285,6 @@
_targetServiceName = ListenerUtil.obtainAtt(_config,
ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
- // Polling interval
- String sAux = _config
- .getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
-
- if (!Util.isNullString(sAux)) {
- try {
- _sleepBetweenPolls = 1000 * Long.parseLong(sAux);
- }
- catch (NumberFormatException e) {
- _logger.warn("Invalid poll latency - keeping default of "
- + (_sleepBetweenPolls / 1000));
- }
- } else {
- _logger.warn("No value specified for: "
- + ListenerTagNames.POLL_LATENCY_SECS_TAG
- + " - Using default of " + (_sleepBetweenPolls / 1000));
- }
-
resolveComposerClass();
boolean hasResponder = _responderMethod != null;
@@ -535,13 +433,11 @@
protected ConfigTree _config;
- protected long _sleepBetweenPolls; // milliseconds
-
protected long _maxMillisForResponse;
protected String _targetServiceCategory, _targetServiceName;
- protected Collection<EPR> _targetEprs;
+ protected ServiceInvoker serviceInvoker;
protected String _composerName;
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListener.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -39,7 +39,7 @@
import org.jboss.soa.esb.util.FileUtil;
import org.jboss.soa.esb.util.Util;
-public class FileGatewayListener extends XAbstractFileGateway {
+public class FileGatewayListener extends AbstractFileGateway {
/**
* serial version uid for this class
*/
Deleted: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/XAbstractFileGateway.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/XAbstractFileGateway.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/XAbstractFileGateway.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -1,542 +0,0 @@
-package org.jboss.soa.esb.listeners.gateway;
-
-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.listeners.RegistryUtil;
-import org.jboss.soa.esb.listeners.ListenerTagNames;
-import org.jboss.soa.esb.listeners.ListenerUtil;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.util.Util;
-import org.jboss.soa.esb.util.ClassUtil;
-import org.jboss.soa.esb.couriers.*;
-import org.jboss.soa.esb.filter.FilterManager;
-import org.jboss.soa.esb.common.Environment;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.MalformedEPRException;
-import org.jboss.soa.esb.addressing.util.DefaultReplyTo;
-import org.jboss.soa.esb.services.registry.RegistryException;
-import org.apache.log4j.Logger;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Collection;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.net.URI;
-
-/**
- * Base class for all file gateways: local filesystem, ftp, sftp and ftps.
- * <p/>Implementations for file manipulation (getFileList, getFileContents,
- * renameFile and deleteFile) must be provided by factory
- *
- * @author <a
- * href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
- * @since Version 4.0
- */
-public abstract class XAbstractFileGateway extends
- AbstractThreadedManagedLifecycle {
- abstract File[] getFileList() throws GatewayException;
-
- abstract byte[] getFileContents(File file) throws GatewayException;
-
- abstract boolean renameFile(File from, File to) throws GatewayException;
-
- abstract boolean deleteFile(File file) throws GatewayException;
-
- abstract void seeIfOkToWorkOnDir(File p_oDir) throws GatewayException;
-
- abstract void getDefaultComposer() throws GatewayException;
-
- abstract void bytesToFile(byte[] bytes, File file) throws GatewayException;
-
- protected XAbstractFileGateway(ConfigTree config)
- throws ConfigurationException, RegistryException, GatewayException {
- super(config);
- _config = config;
- _sleepBetweenPolls = 10000; // milliseconds
- checkMyParms();
- } // __________________________________
-
- /**
- * Handle the initialisation of the managed instance.
- *
- * @throws org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException
- * for errors while initialisation.
- */
- protected void doInitialise() throws ManagedLifecycleException {
- try {
- _targetEprs = RegistryUtil.getEprs(_targetServiceCategory,
- _targetServiceName);
- if (null == _targetEprs || _targetEprs.size() < 1)
- throw new ManagedLifecycleException("EPR <"
- + _targetServiceName + "> not found in registry");
- }
- catch (final RegistryException re) {
- throw new ManagedLifecycleException(
- "Unexpected registry exception", re);
- }
- }
-
- /**
- * Execute on the thread.
- */
- protected void doRun() {
-
- EPR replyEpr = null;
- Message replyMsg = null;
-
- if (_logger.isDebugEnabled()) {
- _logger.debug("run() method of " + this.getClass().getSimpleName()
- + " started on thread " + Thread.currentThread().getName());
- }
-
- do {
- File[] fileList;
- try {
- fileList = getFileList();
- }
- catch (GatewayException e) {
- _logger.error("Can't retrieve file list", e);
- continue;
- }
-
- for (File fileIn : fileList) {
- // Try to rename - if unsuccessful, somebody else got it first
- File fileWork = getWorkFileName(fileIn, _workingSuffix);
- try {
- if (!renameFile(fileIn, fileWork))
- continue;
- }
- catch (GatewayException e) {
- _logger.error("Problems renaming file " + fileIn + " to "
- + fileWork);
- continue;
- }
-
- Throwable thrown = null;
- String text = null;
- try {
- Object obj = _processMethod.invoke(_composer, new Object[]
- {fileWork});
- if (null == obj) {
- _logger.warn("Action class method <"
- + _processMethod.getName()
- + "> returned a null object");
- continue;
- }
- boolean bSent = false;
-
- Message outMessage = (Message) obj;
- Map<String, Object> params = new HashMap<String, Object>();
-
- params.put(Environment.ORIGINAL_FILE, fileIn);
- params.put(Environment.GATEWAY_CONFIG, _config);
-
- outMessage = FilterManager.getInstance().doOutputWork(outMessage, params);
-
- for (EPR current : _targetEprs) {
- _courier = getCourier(current);
- try {
- replyEpr = null;
- outMessage.getHeader().getCall().setTo(current);
- if (_maxMillisForResponse > 0) {
- replyEpr = DefaultReplyTo.getReplyTo(current);
- outMessage.getHeader().getCall().setReplyTo(
- replyEpr);
- }
- if (_courier.deliver(outMessage)) {
- bSent = true;
- break;
- }
- }
- finally {
- CourierUtil.cleanCourier(_courier);
- }
-
- }
- if (!bSent) {
- text = "Target service <" + _targetServiceCategory
- + "," + _targetServiceName
- + "> is not registered";
- thrown = new Exception(text);
- } else if (null != replyEpr) {
- TwoWayCourier replyCourier = CourierFactory
- .getPickupCourier(replyEpr);
- try {
- replyMsg = replyCourier
- .pickup(_maxMillisForResponse);
- _responderMethod.invoke(_composer, new Object[]
- {replyMsg, fileIn});
- }
- catch (CourierTimeoutException e) {
- thrown = e;
- text = "Expected response was not received from invoked service";
- replyMsg = MessageFactory.getInstance()
- .getMessage();
- String timedOut = "Service <"
- + _targetServiceCategory + ","
- + "_targetServiceName"
- + "> timed out without sending response";
- replyMsg.getBody()
- .setByteArray(timedOut.getBytes());
- _responderMethod.invoke(_composer, new Object[]
- {replyMsg, fileIn});
- }
- finally {
- if (null != replyCourier)
- CourierUtil.cleanCourier(replyCourier);
- }
- }
- }
- catch (InvocationTargetException e) {
- thrown = e;
- text = "Problems invoking method <"
- + _processMethod.getName() + ">";
-
- }
- catch (IllegalAccessException e) {
- thrown = e;
- text = "Problems invoking method <"
- + _processMethod.getName() + ">";
- }
- catch (ClassCastException e) {
- thrown = e;
- text = "Action class method <" + _processMethod.getName()
- + "> returned a non Message object";
- }
- catch (CourierException e) {
- thrown = e;
- if (null != _courier)
- text = "Courier <" + _courier.getClass().getName()
- + ".deliverAsync(Message) FAILED";
- else
- text = "NULL courier can't deliverAsync Message";
- }
- catch (MalformedEPRException e) {
- thrown = e;
- if (null != _courier)
- text = "Courier <"
- + _courier.getClass().getName()
- + ".deliverAsync(Message) FAILED with malformed EPR.";
- else
- text = "NULL courier can't deliverAsync Message";
- }
-
- if (null == thrown) {
- File fileOK = new File(_postProcessDirectory, fileIn
- .getName()
- + _postProcessSuffix);
- if (_deleteAfterOK) {
- try {
- deleteFile(fileWork);
- }
- catch (GatewayException e) {
- _logger
- .error(
- "File "
- + fileIn
- + " has been processed and renamed to "
- + fileWork
- + ", but there were problems deleting it from the input directory ",
- e);
- }
- } else {
- try {
- renameFile(fileWork, fileOK);
- }
- catch (GatewayException e) {
- _logger
- .error(
- "File "
- + fileIn
- + " has been processed and renamed to "
- + fileWork
- + ", but there were problems renaming it to "
- + fileOK, e);
- }
- }
- } else {
- thrown.printStackTrace();
- _logger.error(text, thrown);
- File fileError = new File(_errorDirectory, fileIn.getName()
- + _errorSuffix);
- try {
- deleteFile(fileError);
- }
- catch (GatewayException e) {
- _logger.warn("File : " + fileError + " did not exist.");
- }
- try {
- renameFile(fileWork, fileError);
- }
- catch (GatewayException e) {
- _logger.error("Problems renaming file " + fileWork
- + " to " + fileError, e);
- }
- }
- }
- }
- while (!waitForRunningStateChange(ManagedLifecycleThreadState.STOPPING,
- _sleepBetweenPolls));
-
- if (_logger.isDebugEnabled()) {
- _logger
- .debug("run() method of " + this.getClass().getSimpleName()
- + " finished on thread "
- + Thread.currentThread().getName());
- }
- } // ________________________________
-
- protected File getWorkFileName(File fileIn, String suffix) {
- return new File(fileIn.toString() + _workingSuffix);
- }
-
- /*
- * Extracted to simplify testing
- */
- protected Courier getCourier(EPR current) throws CourierException,
- MalformedEPRException {
- return CourierFactory.getCourier(current);
- }
-
- /**
- * Handle the threaded destroy of the managed instance.
- *
- * @throws org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException
- * for errors while destroying.
- */
- protected void doThreadedDestroy() throws ManagedLifecycleException {
- }
-
- /*
- * Is the input suffix valid for this type of gateway?
- */
-
- protected void checkInputSuffix() throws ConfigurationException {
- if (_inputSuffix.length() < 1)
- throw new ConfigurationException("Invalid "
- + ListenerTagNames.FILE_INPUT_SFX_TAG + " attribute");
- }
-
- /**
- * Check for mandatory and optional attributes in parameter tree
- *
- * @throws org.jboss.soa.esb.ConfigurationException
- * -
- * if mandatory atts are not right or actionClass not in
- * classpath
- */
- private void checkMyParms() throws ConfigurationException,
- RegistryException, GatewayException {
- // Third arg is null - Exception will be thrown if attribute is not
- // found
- _targetServiceCategory = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, null);
- _targetServiceName = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
-
- // Polling interval
- String sAux = _config
- .getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
-
- if (!Util.isNullString(sAux)) {
- try {
- _sleepBetweenPolls = 1000 * Long.parseLong(sAux);
- }
- catch (NumberFormatException e) {
- _logger.warn("Invalid poll latency - keeping default of "
- + (_sleepBetweenPolls / 1000));
- }
- } else {
- _logger.warn("No value specified for: "
- + ListenerTagNames.POLL_LATENCY_SECS_TAG
- + " - Using default of " + (_sleepBetweenPolls / 1000));
- }
-
- resolveComposerClass();
-
- boolean hasResponder = _responderMethod != null;
- _maxMillisForResponse = ListenerUtil.getMaxMillisGatewayWait(_config,
- _logger, hasResponder);
- try {
- // INPUT directory and suffix (used for FileFilter)
- String url = _config.getAttribute(ListenerTagNames.URL_TAG);
- String sInpDir = (null != url) ? new URL(url).getFile()
- : ListenerUtil.obtainAtt(_config,
- ListenerTagNames.FILE_INPUT_DIR_TAG, null);
- _inputDirectory = fileFromString(sInpDir);
- seeIfOkToWorkOnDir(_inputDirectory);
-
- _inputSuffix = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.FILE_INPUT_SFX_TAG, null);
- _inputSuffix = _inputSuffix.trim();
-
- checkInputSuffix();
-
- // WORK suffix (will rename in input directory)
- _workingSuffix = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.FILE_WORK_SFX_TAG, ".esbWork").trim();
- if (_workingSuffix.length() < 1)
- throw new ConfigurationException("Invalid "
- + ListenerTagNames.FILE_WORK_SFX_TAG + " attribute");
-
- if (_inputSuffix.equals(_workingSuffix))
- throw new ConfigurationException(
- "Work suffix must differ from input suffix <"
- + _workingSuffix + ">");
-
- // ERROR directory and suffix (defaults to input dir and
- // ".esbError"
- // suffix)
- String sErrDir = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.FILE_ERROR_DIR_TAG, sInpDir);
- _errorDirectory = fileFromString(sErrDir);
- seeIfOkToWorkOnDir(_errorDirectory);
-
- _errorSuffix = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.FILE_ERROR_SFX_TAG, ".esbError").trim();
- if (_errorSuffix.length() < 1)
- throw new ConfigurationException("Invalid "
- + ListenerTagNames.FILE_ERROR_SFX_TAG + " attribute");
- if (_errorDirectory.equals(_inputDirectory)
- && _inputSuffix.equals(_errorSuffix))
- throw new ConfigurationException(
- "Error suffix must differ from input suffix <"
- + _errorSuffix + ">");
-
- // Do users wish to delete files that were processed OK ?
- String sPostDel = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.FILE_POST_DEL_TAG, "false").trim();
- _deleteAfterOK = Boolean.parseBoolean(sPostDel);
- if (_deleteAfterOK)
- return;
-
- // POST (done) directory and suffix (defaults to input dir and
- // ".esbDone" suffix)
- String sPostDir = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.FILE_POST_DIR_TAG, sInpDir);
- _postProcessDirectory = fileFromString(sPostDir);
- seeIfOkToWorkOnDir(_postProcessDirectory);
- _postProcessSuffix = ListenerUtil.obtainAtt(_config,
- ListenerTagNames.FILE_POST_SFX_TAG, ".esbDone").trim();
-
- if (_postProcessDirectory.equals(_inputDirectory)) {
- if (_postProcessSuffix.length() < 1)
- throw new ConfigurationException("Invalid "
- + ListenerTagNames.FILE_POST_SFX_TAG + " attribute");
- if (_postProcessSuffix.equals(_inputSuffix))
- throw new ConfigurationException(
- "Post process suffix must differ from input suffix <"
- + _postProcessSuffix + ">");
- }
- }
- catch (GatewayException ex) {
- throw ex;
- }
- catch (MalformedURLException ex) {
- throw new ConfigurationException(ex);
- }
- } // ________________________________
-
- protected void resolveComposerClass() throws ConfigurationException,
- GatewayException {
- String sProcessMethod = null;
- String sResponderMethod = null;
- try {
- _composerName = _config
- .getAttribute(ListenerTagNames.GATEWAY_COMPOSER_CLASS_TAG);
- if (null != _composerName) { // class attribute
- _composerClass = ClassUtil.forName(_composerName, getClass());
- Constructor oConst = _composerClass.getConstructor(new Class[]
- {ConfigTree.class});
- _composer = oConst.newInstance(_config);
- sProcessMethod = _config
- .getAttribute(
- ListenerTagNames.GATEWAY_COMPOSER_METHOD_TAG,
- "process");
- sResponderMethod = _config
- .getAttribute(ListenerTagNames.GATEWAY_RESPONDER_METHOD_TAG);
- } else {
- getDefaultComposer();
- sProcessMethod = "process";
- sResponderMethod = "respond";
- }
-
- _processMethod = _composerClass.getMethod(sProcessMethod,
- new Class[]
- {Object.class});
-
- _responderMethod = (null == sResponderMethod) ? null
- : _composerClass.getMethod(sResponderMethod, new Class[]
- {Message.class, File.class});
- }
- catch (InvocationTargetException ex) {
- throw new ConfigurationException(ex);
- }
- catch (IllegalAccessException ex) {
- throw new ConfigurationException(ex);
- }
- catch (InstantiationException ex) {
- throw new ConfigurationException(ex);
- }
- catch (NoSuchMethodException ex) {
- throw new ConfigurationException(ex);
- }
- catch (ClassNotFoundException ex) {
- throw new ConfigurationException(ex);
- }
- } // ________________________________
-
- private File fileFromString(String file) {
- try {
- return new File(new URI(file));
- }
- catch (Exception e) {
- return new File(file);
- }
- } // ________________________________
-
- protected final static Logger _logger = Logger
- .getLogger(XAbstractFileGateway.class);
-
- protected ConfigTree _config;
-
- protected long _sleepBetweenPolls; // milliseconds
-
- protected long _maxMillisForResponse;
-
- protected String _targetServiceCategory, _targetServiceName;
-
- protected Collection<EPR> _targetEprs;
-
- protected String _composerName;
-
- protected Class _composerClass;
-
- protected Object _composer;
-
- protected Method _processMethod;
-
- protected Method _responderMethod;
-
- protected Courier _courier;
-
- protected boolean _deleteAfterOK;
-
- protected File _inputDirectory, _errorDirectory, _postProcessDirectory;
-
- protected String _inputSuffix, _postProcessSuffix, _workingSuffix,
- _errorSuffix;
-
- protected FileFilter _fileFilter;
-
-} // ____________________________________________________________________________
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAwareListener.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAwareListener.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAwareListener.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -1,25 +1,22 @@
/*
* 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
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
* full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
*
- * 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.
+ * (C) 2005-2006, JBoss Inc.
*/
-
package org.jboss.soa.esb.listeners.message;
import java.lang.reflect.Method;
@@ -53,7 +50,7 @@
* CourierFactory to obtain an appropriate Courier for the EPR this listener
* will be listening on <br/>Keeps a thread pool to instantiate
* ActionProcessingPipelines whenever a Message is received
- *
+ *
* @author <a
* href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
* @since Version 4.0
@@ -65,7 +62,7 @@
* serial version uid for this class
*/
private static final long serialVersionUID = -9198018611828254359L;
-
+
/**
* The minimum error delay.
*/
@@ -74,20 +71,20 @@
* The maximum error delay.
*/
private static final long MAX_ERROR_DELAY = (MIN_ERROR_DELAY << 5) ;
-
+
/**
* The action pipeline.
*/
private ActionProcessingPipeline pipeline ;
-
+
/**
* The error delay.
*/
private long errorDelay ;
-
+
/**
* public constructor
- *
+ *
* @param config
* ConfigTree - Containing 'static' configuration for this
* instance
@@ -103,7 +100,7 @@
/**
* Check for mandatory and optional attributes in parameter tree
- *
+ *
* @throws ConfigurationException -
* if mandatory atts are not right or actionClass not in
* classpath
@@ -114,7 +111,7 @@
_eprName = _config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
final String maxThreadVal = _config.getAttribute(ListenerTagNames.MAX_THREADS_TAG) ;
-
+
if (!Util.isNullString(maxThreadVal))
{
try
@@ -140,7 +137,7 @@
throw new ConfigurationException(
"Missing or invalid " + ListenerTagNames.EPR_TAG + " element");
_epr = ListenerUtil.assembleEpr(eprElement);
-
+
String latency = _config.getAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG);
long lSeconds = 10;
if (null != latency)
@@ -154,12 +151,12 @@
_logger.warn("Invalid number format <" + latency + "> using default value (" + lSeconds + ")");
}
}
- _latencySecs = lSeconds ;
+ _latencySecs = lSeconds ;
}
-
+
/**
* Handle the initialisation of the managed instance.
- *
+ *
* @throws ManagedLifecycleException for errors while initialisation.
*/
protected void doInitialise()
@@ -204,9 +201,9 @@
{
throw new ManagedLifecycleException("No appropriate courier can be obtained for " + _epr, ce);
}
-
+
_pickUpCourier = pickUpCourier ;
-
+
try
{
RegistryUtil.register(_config, _epr);
@@ -217,22 +214,22 @@
throw new ManagedLifecycleException("Unexpected error during registration for epr " + _epr, re);
}
}
-
+
/**
* Handle the start of the managed instance.
- *
+ *
* @throws ManagedLifecycleException for errors while starting.
*/
protected void doStart()
throws ManagedLifecycleException
{
checkExecutorTermination() ;
-
+
_execService = Executors.newFixedThreadPool(_maxThreads) ;
-
+
super.doStart() ;
}
-
+
/**
* Execute on the thread.
*/
@@ -243,7 +240,7 @@
_logger.debug("doRun() method of " + this.getClass().getSimpleName()
+ " started on thread " + Thread.currentThread().getName());
}
-
+
while (isRunning())
{
// Only pickup a message when a thread is available
@@ -259,7 +256,7 @@
+ " finished on thread " + Thread.currentThread().getName());
}
}
-
+
public void waitForEventAndProcess (long maxWaitMillis)
{
final Message message ;
@@ -289,7 +286,7 @@
return;
}
- if (null != message)
+ if (null != message)
{
final Runnable pipelineRunner = new Runnable() {
public void run() {
@@ -305,10 +302,10 @@
}
} // ________________________________
-
+
/**
* Handle the threaded destroy of the managed instance.
- *
+ *
* @throws ManagedLifecycleException for errors while destroying.
*/
protected void doThreadedDestroy()
@@ -319,15 +316,15 @@
_execService.shutdown() ;
checkExecutorTermination() ;
}
-
+
pipeline.destroy() ;
pipeline = null ;
-
+
CourierUtil.cleanCourier(_pickUpCourier);
-
+
RegistryUtil.unregister(_eprCategoryName, _eprName, _epr) ;
}
-
+
/**
* Check that the existing executor has been closed down.
* @throws ManagedLifecycleException If executor tasks are still active.
@@ -399,18 +396,18 @@
private int _maxThreads;
private int _defaultMaxThreads = 1;
-
+
private long _latencySecs;
-
+
private long _pauseLapseInMillis = 50 ;
private ExecutorService _execService;
private Object _synchThreads = new Short((short) -1);
-
+
private int _qRunningThreads;
private Logger _logger = Logger.getLogger(MessageAwareListener.class);
-
+
private PickUpOnlyCourier _pickUpCourier;
}
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduledEventListener.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduledEventListener.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/src/org/jboss/soa/esb/schedule/ScheduledEventListener.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -36,5 +36,5 @@
*
* @throws SchedulingException Exception processing schedule event.
*/
- public void onSchedule() throws SchedulingException ;
+ public void onSchedule() throws SchedulingException;
}
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/MockCourierFactory.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/MockCourierFactory.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/MockCourierFactory.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -45,7 +45,7 @@
} else if(malformedEPRException != null) {
throw malformedEPRException;
}
-
+
return couriers.get(toEPR);
}
@@ -70,4 +70,6 @@
((MockCourier)entry.getValue()).reset();
}
}
+
+
}
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -111,7 +111,7 @@
fail();
}
- gateway.run();
+ gateway.onSchedule();
PackageFileContents f = gateway.new PackageFileContents();
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/ReadOnlyRemoteGatewayListenerIntegrationTest.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -36,7 +36,11 @@
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.util.embedded.EmbeddableException;
import org.jboss.internal.soa.esb.util.embedded.ftp.FtpTestUtil;
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
+import org.jboss.internal.soa.esb.couriers.MockCourier;
+import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.schedule.SchedulingException;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
@@ -52,6 +56,7 @@
import org.jboss.soa.esb.services.registry.RegistryException;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.AfterClass;
/**
* Unit test for ReadOnlyRemoteGatewayListener that uses an embedded ftp server.
@@ -68,15 +73,26 @@
@BeforeClass
public static void classSetup() throws EmbeddableException, ConfigurationException, GatewayException, RegistryException, MalformedURLException
{
- ftpServer = createFtpServer();
+ MockCourierFactory.install();
+ MockRegistry.install();
+ MockRegistry.register(RemoteGatewayListenerUnitTest.SERVICE_CATEGORY, RemoteGatewayListenerUnitTest.SERVICE_NAME, new MockCourier(true));
+
+ ftpServer = createFtpServer();
ftpServer.start();
createWorkDirectories();
configTree = createConfigTree();
createRemoteGatewayListener( configTree );
}
-
- @Test
+
+ @AfterClass
+ public static void classCleanup() throws EmbeddableException, ConfigurationException, GatewayException, RegistryException, MalformedURLException
+ {
+ MockRegistry.uninstall();
+ MockCourierFactory.uninstall();
+ }
+
+ @Test
public void deleteFile() throws GatewayException
{
File remoteFile = createAbsoluteFromFile();
@@ -109,8 +125,13 @@
File inputDir = ftpServer.getLocalInputDir();
String doneFileName = testFile.getName();
- waitForFile( inputDir, doneFileName );
- stopdoRun( mock );
+ //waitForFile( inputDir, doneFileName );
+ //stopdoRun( mock );
+ try {
+ mock.onSchedule();
+ } catch (SchedulingException e) {
+ fail(e.getMessage());
+ }
File processedFile = new File ( inputDir, doneFileName );
try
@@ -222,90 +243,43 @@
*/
protected RemoteGatewayListenerMock createAndStartListener ( ConfigTree configTree, boolean returnValueForCourier ) throws ConfigurationException, GatewayException, RegistryException
{
- final RemoteGatewayListenerMock mock = new RemoteGatewayListenerMock( configTree , returnValueForCourier );
- mock.doInitialise();
+ final RemoteGatewayListenerMock mock = new RemoteGatewayListenerMock( configTree );
+ try {
+ mock.doInitialise();
+ } catch (ManagedLifecycleException e) {
+ fail(e.getMessage());
+ }
+
+ if(returnValueForCourier) {
+ MockCourierFactory.courierException = null;
+ } else {
+ MockCourierFactory.courierException = new CourierException("Test generated mock exception.");
+ }
+
+ return mock;
- Thread thread = new Thread ( new Runnable () {
- public void run()
- {
- mock.doRun();
- }
- });
- thread.start();
-
- return mock;
-
}
- protected void stopdoRun ( RemoteGatewayListenerMock mock )
- {
- if ( mock == null ) return;
- try
- {
- mock.stop();
- }
- catch ( Exception e )
- {
- if ( ! (e instanceof ManagedLifecycleException ) )
- fail ( e.getMessage() );
- }
- }
-
/**
* Mock impl of RemoteGatewayListener.
*/
class RemoteGatewayListenerMock extends ReadOnlyRemoteGatewayListener
{
private static final long serialVersionUID = 1L;
-
- /* value that will be returned from the getCourier( EPR ) method */
- private boolean returnValueForCourier;
-
+
private boolean finishedOneRun;
/**
* Sole constructor
*
* @param configTree configTree used to configure this RemoteGatewayListener
- * @param returnValueForCourier value to be returned from this objects getCourier( EPR ) method
*
*/
- public RemoteGatewayListenerMock ( ConfigTree configTree, boolean returnValueForCourier) throws ConfigurationException, GatewayException, RegistryException
+ public RemoteGatewayListenerMock ( ConfigTree configTree) throws ConfigurationException, GatewayException, RegistryException
{
super ( configTree );
- this.returnValueForCourier = returnValueForCourier;
- }
-
- /**
- * Will return a Courier instance that returns the value of the
- * field returnValueForCourier.
- */
- @Override
- protected Courier getCourier( EPR current ) throws CourierException, MalformedEPRException
- {
- return new Courier() {
- public boolean deliver( Message message ) throws CourierException, MalformedEPRException
- {
- return returnValueForCourier;
- }
- public void cleanup() { }
- };
- }
-
- @Override
- protected void doInitialise()
- {
- _targetEprs = new ArrayList<EPR>();
- _targetEprs.add( new JMSEpr( new EPR() ) );
- };
-
- @Override
- protected boolean waitForRunningStateChange(final ManagedLifecycleThreadState state, final long terminationPeriod)
- {
- finishedOneRun = true;
- return super.waitForRunningStateChange( state, terminationPeriod );
- }
-
+ }
+
public boolean hasFinishedOneRun()
{
return finishedOneRun;
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerIntegrationTest.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerIntegrationTest.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerIntegrationTest.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -27,10 +27,26 @@
import org.jboss.soa.esb.addressing.eprs.FTPEpr;
import org.jboss.soa.esb.common.tests.BaseTest;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleState;
+import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
+import org.jboss.internal.soa.esb.couriers.MockCourier;
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
public class RemoteGatewayListenerIntegrationTest extends BaseTest
{
- public RemoteGatewayListenerIntegrationTest ()
+
+ protected void setUp() throws Exception {
+ MockCourierFactory.install();
+ MockRegistry.install();
+ MockRegistry.register("Example", "Test", new MockCourier(true));
+ }
+
+ protected void tearDown() throws Exception {
+ MockRegistry.uninstall();
+ MockCourierFactory.uninstall();
+ }
+
+ public RemoteGatewayListenerIntegrationTest ()
{
}
@@ -62,66 +78,74 @@
RemoteGatewayListener gateway = new RemoteGatewayListener(tree);
boolean exception = false;
-
- try
- {
- gateway.deleteFile(new File("foo"));
- }
- catch (GatewayException ex)
- {
- exception = true;
- }
-
- if (!exception)
- fail();
-
- gateway.run();
-
- try
- {
- @SuppressWarnings("unused")
- byte[] contents = gateway.getFileContents(new File("bar"));
-
- fail();
- }
- catch (GatewayException ex)
- {
- }
-
- // TODO this ignores the parameter too!
-
- try
- {
- gateway.getFileList();
- }
- catch (GatewayException ex)
- {
- fail();
- }
-
- exception = false;
-
- try
- {
- gateway.deleteFile(new File("foo"));
- }
- catch (GatewayException ex)
- {
- exception = true;
- }
-
- if (!exception)
- fail();
-
- try
- {
- gateway.renameFile(new File("foo"), new File("bar"));
-
- fail();
- }
- catch (GatewayException ex)
- {
- }
- }
+
+ gateway.initialise();
+ gateway.start();
+
+ try {
+ try
+ {
+ gateway.deleteFile(new File("foo"));
+ }
+ catch (GatewayException ex)
+ {
+ exception = true;
+ }
+
+ if (!exception)
+ fail();
+
+ gateway.onSchedule();
+
+ try
+ {
+ @SuppressWarnings("unused")
+ byte[] contents = gateway.getFileContents(new File("bar"));
+
+ fail();
+ }
+ catch (GatewayException ex)
+ {
+ }
+
+ // TODO this ignores the parameter too!
+
+ try
+ {
+ gateway.getFileList();
+ }
+ catch (GatewayException ex)
+ {
+ fail();
+ }
+
+ exception = false;
+
+ try
+ {
+ gateway.deleteFile(new File("foo"));
+ }
+ catch (GatewayException ex)
+ {
+ exception = true;
+ }
+
+ if (!exception)
+ fail();
+
+ try
+ {
+ gateway.renameFile(new File("foo"), new File("bar"));
+
+ fail();
+ }
+ catch (GatewayException ex)
+ {
+ }
+ } finally {
+ gateway.stop();
+ gateway.destroy();
+ }
+ }
}
Modified: labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java 2007-07-31 10:30:29 UTC (rev 13906)
+++ labs/jbossesb/workspace/scheduled-file-listener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java 2007-07-31 12:02:29 UTC (rev 13907)
@@ -38,7 +38,11 @@
import org.jboss.internal.soa.esb.util.embedded.EmbeddableException;
import org.jboss.internal.soa.esb.util.embedded.ftp.FtpTestUtil;
import org.jboss.internal.soa.esb.util.embedded.ftp.NoConfigFileFtpServer;
+import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
+import org.jboss.internal.soa.esb.couriers.MockCourier;
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.schedule.SchedulingException;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
@@ -88,8 +92,8 @@
/* name of the remote ftp error directory */
protected static String remoteErrorDirName;
- private static final String SERVICE_CATEGORY = "RemoteGWListenerTest";
- private static final String SERVICE_NAME = SERVICE_CATEGORY;
+ protected static final String SERVICE_CATEGORY = "RemoteGWListenerTest";
+ protected static final String SERVICE_NAME = SERVICE_CATEGORY;
private static final String INPUT_SUFFIX = ".txt";
private static final String WORK_SUFFIX = ".esbwork";
protected static final String POST_SUFFIX = ".done";
@@ -106,6 +110,10 @@
@BeforeClass
public static void classSetup() throws EmbeddableException, ConfigurationException, GatewayException, RegistryException, MalformedURLException
{
+ MockCourierFactory.install();
+ MockRegistry.install();
+ MockRegistry.register(RemoteGatewayListenerUnitTest.SERVICE_CATEGORY, RemoteGatewayListenerUnitTest.SERVICE_NAME, new MockCourier(true));
+
ftpServer = createFtpServer();
ftpServer.start();
@@ -116,6 +124,13 @@
}
+ @AfterClass
+ public static void classCleanup() throws EmbeddableException, ConfigurationException, GatewayException, RegistryException, MalformedURLException
+ {
+ MockRegistry.uninstall();
+ MockCourierFactory.uninstall();
+ }
+
protected static void createWorkDirectories()
{
remoteInputDirName = "/" + ftpServer.getLocalInputDir().getName();
@@ -186,18 +201,26 @@
File done = ftpServer.getLocalUploadDir();
String doneFileName = testFile.getName() + POST_SUFFIX;
- waitForFile( done, doneFileName );
- stopdoRun( mock );
-
- File processedFile = new File ( done, doneFileName );
- try
- {
- assertTrue ( processedFile.exists() );
- }
- finally
- {
- FtpTestUtil.deleteFile( processedFile );
- }
+ try {
+ mock.onSchedule();
+ } catch (SchedulingException e) {
+ fail(e.getMessage());
+ }
+
+ try {
+ File processedFile = new File ( done, doneFileName );
+ try
+ {
+ assertTrue ( processedFile.exists() );
+ }
+ finally
+ {
+ FtpTestUtil.deleteFile( processedFile );
+ }
+ } finally {
+ mock.stop();
+ mock.destroy();
+ }
}
/**
@@ -216,19 +239,27 @@
File inputDir = ftpServer.getLocalInputDir();
String doneFileName = testFile.getName() + POST_SUFFIX;
-
- waitForFile( inputDir, doneFileName );
- stopdoRun( mock );
-
- File processedFile = new File ( inputDir, doneFileName );
- try
- {
- assertTrue ( processedFile.exists() );
- }
- finally
- {
- FtpTestUtil.deleteFile( processedFile );
- }
+
+ try {
+ mock.onSchedule();
+ } catch (SchedulingException e) {
+ fail(e.getMessage());
+ }
+
+ try {
+ File processedFile = new File ( inputDir, doneFileName );
+ try
+ {
+ assertTrue ( processedFile.exists() );
+ }
+ finally
+ {
+ FtpTestUtil.deleteFile( processedFile );
+ }
+ } finally {
+ mock.stop();
+ mock.destroy();
+ }
}
/**
@@ -250,19 +281,28 @@
File errorDir = ftpServer.getLocalErrorDir();
String errorFileName = testFile.getName() + POST_ERROR_SUFFIX;
- waitForFile( errorDir, errorFileName );
- stopdoRun( mock );
-
- File errorFile = new File ( errorDir, errorFileName );
- try
- {
- assertTrue ( errorFile.exists() );
- }
- finally
- {
- FtpTestUtil.deleteFile( errorFile );
- }
- }
+
+ try {
+ mock.onSchedule();
+ } catch (SchedulingException e) {
+ fail(e.getMessage());
+ }
+
+ try {
+ File errorFile = new File ( errorDir, errorFileName );
+ try
+ {
+ assertTrue ( errorFile.exists() );
+ }
+ finally
+ {
+ FtpTestUtil.deleteFile( errorFile );
+ }
+ } finally {
+ mock.stop();
+ mock.destroy();
+ }
+ }
@Test
public void renameFile_In_Same_Directory() throws GatewayException
@@ -401,35 +441,23 @@
*/
private RemoteGatewayListenerMock createAndStartListener ( ConfigTree configTree, boolean returnValueForCourier ) throws ConfigurationException, GatewayException, RegistryException
{
- final RemoteGatewayListenerMock mock = new RemoteGatewayListenerMock( configTree , returnValueForCourier );
- mock.doInitialise();
-
- Thread thread = new Thread ( new Runnable () {
- public void run()
- {
- mock.doRun();
- }
- });
- thread.start();
-
- return mock;
-
+ final RemoteGatewayListenerMock mock = new RemoteGatewayListenerMock( configTree );
+ try {
+ mock.initialise();
+ mock.start();
+ } catch (ManagedLifecycleException e) {
+ fail(e.getMessage());
+ }
+
+ if(returnValueForCourier) {
+ MockCourierFactory.courierException = null;
+ } else {
+ MockCourierFactory.courierException = new CourierException("Test generated mock exception.");
+ }
+
+ return mock;
}
- private void stopdoRun ( RemoteGatewayListenerMock mock )
- {
- if ( mock == null ) return;
- try
- {
- mock.stop();
- }
- catch ( Exception e )
- {
- if ( ! (e instanceof ManagedLifecycleException ) )
- fail ( e.getMessage() );
- }
- }
-
protected static void assertFileRemoved( File file)
{
assertFalse( "The file was not removed from the filesystem", file.exists() );
@@ -489,55 +517,20 @@
class RemoteGatewayListenerMock extends RemoteGatewayListener
{
private static final long serialVersionUID = 1L;
-
- /* value that will be returned from the getCourier( EPR ) method */
- private boolean returnValueForCourier;
-
+
private boolean finishedOneRun;
/**
* Sole constructor
*
* @param configTree configTree used to configure this RemoteGatewayListener
- * @param returnValueForCourier value to be returned from this objects getCourier( EPR ) method
*
*/
- public RemoteGatewayListenerMock ( ConfigTree configTree, boolean returnValueForCourier) throws ConfigurationException, GatewayException, RegistryException
+ public RemoteGatewayListenerMock ( ConfigTree configTree) throws ConfigurationException, GatewayException, RegistryException
{
super ( configTree );
- this.returnValueForCourier = returnValueForCourier;
}
-
- /**
- * Will return a Courier instance that returns the value of the
- * field returnValueForCourier.
- */
- @Override
- protected Courier getCourier( EPR current ) throws CourierException, MalformedEPRException
- {
- return new Courier() {
- public boolean deliver( Message message ) throws CourierException, MalformedEPRException
- {
- return returnValueForCourier;
- }
- public void cleanup() { }
- };
- }
-
- @Override
- protected void doInitialise()
- {
- _targetEprs = new ArrayList<EPR>();
- _targetEprs.add( new JMSEpr( new EPR() ) );
- };
-
- @Override
- protected boolean waitForRunningStateChange(final ManagedLifecycleThreadState state, final long terminationPeriod)
- {
- finishedOneRun = true;
- return super.waitForRunningStateChange( state, terminationPeriod );
- }
-
+
public boolean hasFinishedOneRun()
{
return finishedOneRun;
More information about the jboss-svn-commits
mailing list