[jboss-svn-commits] JBL Code SVN: r7712 - in labs/jbossesb/trunk: product/core/listeners/src/org/jboss/soa/esb/actions product/core/rosetta/src/org/jboss/soa/esb/notification qa/junit/src/org/jboss/soa/esb/listeners/gateway
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Nov 19 13:35:25 EST 2006
Author: estebanschifman
Date: 2006-11-19 13:35:10 -0500 (Sun, 19 Nov 2006)
New Revision: 7712
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/Notifier.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyConsole.java
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationList.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/fileEsbListenerConfig.xml
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/fileGatewayConfig.xml
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/jmsEsbListenerConfig.xml
Log:
Add new NotifyConsole as notification target, and Notifier as reusable action
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/Notifier.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/Notifier.java 2006-11-19 17:02:30 UTC (rev 7711)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/Notifier.java 2006-11-19 18:35:10 UTC (rev 7712)
@@ -0,0 +1,76 @@
+package org.jboss.soa.esb.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.notification.NotificationList;
+
+public class Notifier
+{
+ public Notifier(ConfigTree config)
+ {
+ _config = config;
+ if (null==_config)
+ {
+ _notifyOK = _notifyError = new ConfigTree[]{};
+ }
+ else
+ {
+ _notifyOK = getNotificationList("ok");
+ _notifyError= getNotificationList("err");
+ }
+ } //________________________________
+
+ /**
+ * This is equivalent to a No Operation
+ * @param message
+ * @return - this method will always return arg0 unchanged
+ */
+ public Message process (Message message)
+ {
+ return message;
+ } //________________________________
+
+ public void notifyOK (Message message)
+ {
+ NotificationList.notifyAll(_notifyOK, messageAsString(message));
+ } //________________________________
+ public void notifyError (Message message)
+ {
+ NotificationList.notifyAll(_notifyError, messageAsString(message));
+ } //________________________________
+
+ public String messageAsString (Message message)
+ {
+ byte[] ba = null;
+ return (null==message) ? "<null message>"
+ :(null==(ba=message.getBody().getContents())) ? "<null body content>"
+ : new String(ba);
+ } //________________________________
+
+ private ConfigTree[] getNotificationList(String type)
+ {
+ List<ConfigTree> list = new ArrayList<ConfigTree>();
+ if (null!=type)
+ type = type.toLowerCase();
+
+ for (ConfigTree tree : _config.getChildren(NotificationList.ELEMENT))
+ {
+ String sType = tree.getAttribute(NotificationList.TYPE);
+ if (null==sType)
+ continue;
+ if (null==type || sType.toLowerCase().equals(type))
+ list.add(tree);
+ }
+
+ ConfigTree[] array = new ConfigTree[list.size()];
+ return list.toArray(array);
+ } //________________________________
+
+ protected ConfigTree _config;
+ protected ConfigTree[] _notifyOK ,_notifyError;
+ protected static Logger _logger = Logger.getLogger(Notifier.class);
+} //____________________________________________________________________________
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationList.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationList.java 2006-11-19 17:02:30 UTC (rev 7711)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationList.java 2006-11-19 18:35:10 UTC (rev 7712)
@@ -24,6 +24,7 @@
import java.io.Serializable;
+import org.apache.log4j.Logger;
import org.jboss.soa.esb.helpers.ConfigTree;
/**
@@ -60,6 +61,7 @@
public static final String CHILD_TGT = "target";
private String m_sType;
+ protected static Logger _logger = Logger.getLogger(NotificationList.class);
/**
* Instantiate an object according to the contents of <arg 1>
@@ -136,4 +138,24 @@
return (null == m_sType) ? true : m_sType.startsWith("err");
}
+ public static void notifyAll(ConfigTree[]list, Serializable content)
+ {
+ for (ConfigTree tree : list)
+ {
+ ConfigTree[] targets = tree.getChildren(NotificationList.CHILD_TGT);
+ for (ConfigTree curr :targets)
+ {
+ try
+ {
+ NotificationTarget target = NotificationTarget.fromParams(curr);
+ target.sendNotification(content);
+ }
+ catch(Exception e)
+ {
+ _logger.error("Can't instantiate target "+curr.toString(),e);
+ }
+ }
+ }
+ } //________________________________
+
} // ____________________________________________________________________________
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyConsole.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyConsole.java 2006-11-19 17:02:30 UTC (rev 7711)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyConsole.java 2006-11-19 18:35:10 UTC (rev 7712)
@@ -0,0 +1,23 @@
+package org.jboss.soa.esb.notification;
+
+import java.io.Serializable;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.*;
+
+public class NotifyConsole extends NotificationTarget
+{
+
+ public NotifyConsole(ConfigTree tree)
+ {
+ super(tree);
+ }
+
+ @Override
+ public void sendNotification(Serializable content) throws Exception
+ {
+ System.out.println
+ ("ConsoleNotifier "+Util.getStamp()+"<"+content+">");
+ }
+
+}
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java 2006-11-19 17:02:30 UTC (rev 7711)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java 2006-11-19 18:35:10 UTC (rev 7712)
@@ -58,8 +58,8 @@
static String _esbListenerConfig = "fileEsbListenerConfig.xml";
private static final String TMP_DIR = System.getProperty("java.io.tmpdir","/tmp");
- static File _returnFile = new File(TMP_DIR,"fileMessageBack.txt");
- static File _droppedFile = new File(TMP_DIR,"fileLegacy.dat");
+ static File _returnFile = new File("/tmp","fileMessageBack.txt");
+ static File _droppedFile = new File("/tmp","fileLegacy.dat");
static String POST_SUFFIX = ".sentToEsb";
static File _doneFile = new File(_droppedFile.toString()+POST_SUFFIX);
@@ -103,27 +103,23 @@
@Test
public void fileGatewayListener() throws Exception
{
- try
- {
- InputStream inStream = getClass().getResourceAsStream(_esbListenerConfig);
- ConfigTree tree = ConfigTree.fromInputStream(inStream);
- _esbListController = new EsbListenerController(tree);
- new Thread(_esbListController).start();
- Thread.sleep(15000);
+ InputStream inStream = getClass().getResourceAsStream(_esbListenerConfig);
+ ConfigTree tree = ConfigTree.fromInputStream(inStream);
+ _esbListController = new EsbListenerController(tree);
+ new Thread(_esbListController).start();
+ Thread.sleep(15000);
- inStream = getClass().getResourceAsStream(_gatewayConfig);
- tree = ConfigTree.fromInputStream(inStream);
- _gatewayController = new GatewayListenerController(tree);
- new Thread(_gatewayController).start();
- Thread.sleep(4000);
+ inStream = getClass().getResourceAsStream(_gatewayConfig);
+ tree = ConfigTree.fromInputStream(inStream);
+ _gatewayController = new GatewayListenerController(tree);
+ new Thread(_gatewayController).start();
+ Thread.sleep(4000);
- _esbListController.requestEnd();
- _gatewayController.requestEnd();
-
- assertEquals(THE_TEXT, stringFromFile(_returnFile));
- assertEquals(true,_doneFile.exists());
- }
- catch (Exception e) { }
+ _esbListController.requestEnd();
+ _gatewayController.requestEnd();
+
+ assertEquals(THE_TEXT, stringFromFile(_returnFile));
+ assertEquals(true,_doneFile.exists());
}
public static class MockMessageAwareAction
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java 2006-11-19 17:02:30 UTC (rev 7711)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java 2006-11-19 18:35:10 UTC (rev 7712)
@@ -110,26 +110,22 @@
@Test
public void jmsGatewayListener() throws Exception
{
- try
- {
- InputStream inStream = getClass().getResourceAsStream(_esbListenerConfig);
- ConfigTree tree = ConfigTree.fromInputStream(inStream);
- _esbListController = new EsbListenerController(tree);
- new Thread(_esbListController).start();
- Thread.sleep(15000);
+ InputStream inStream = getClass().getResourceAsStream(_esbListenerConfig);
+ ConfigTree tree = ConfigTree.fromInputStream(inStream);
+ _esbListController = new EsbListenerController(tree);
+ new Thread(_esbListController).start();
+ Thread.sleep(15000);
- inStream = getClass().getResourceAsStream(_gatewayConfig);
- tree = ConfigTree.fromInputStream(inStream);
- _gatewayController = new GatewayListenerController(tree);
- new Thread(_gatewayController).start();
- Thread.sleep(4000);
+ inStream = getClass().getResourceAsStream(_gatewayConfig);
+ tree = ConfigTree.fromInputStream(inStream);
+ _gatewayController = new GatewayListenerController(tree);
+ new Thread(_gatewayController).start();
+ Thread.sleep(4000);
- _esbListController.requestEnd();
- _gatewayController.requestEnd();
-
- assertEquals(THE_TEXT, stringFromFile(_returnFile));
- }
- catch (Exception e) { }
+ _esbListController.requestEnd();
+ _gatewayController.requestEnd();
+
+ assertEquals(THE_TEXT, stringFromFile(_returnFile));
}
public static class MockMessageAwareAction
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/fileEsbListenerConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/fileEsbListenerConfig.xml 2006-11-19 17:02:30 UTC (rev 7711)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/fileEsbListenerConfig.xml 2006-11-19 18:35:10 UTC (rev 7712)
@@ -1,6 +1,6 @@
<DummyTester parameterReloadSecs="180">
<DummyActionConfig
- service-category="my category"
+ service-category="myCategory"
service-name="testFileGateway"
service-description="My Dummy Service Name"
epr-description="EPR descriptionnnnnnnnnnnnnnn"
@@ -15,6 +15,11 @@
<action
class="org.jboss.soa.esb.listeners.gateway.FileGatewayListenerUnitTest$MockMessageAwareAction"
process="writeToDisk"
- />
+ />
+ <action class="org.jboss.soa.esb.actions.Notifier" okMethod="notifyOK">
+ <NotificationList type="OK">
+ <target class="NotifyConsole" />
+ </NotificationList>
+ </action>
</DummyActionConfig>
</DummyTester>
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/fileGatewayConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/fileGatewayConfig.xml 2006-11-19 17:02:30 UTC (rev 7711)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/fileGatewayConfig.xml 2006-11-19 18:35:10 UTC (rev 7712)
@@ -1,6 +1,6 @@
<FileGateway parameterReloadSecs="180">
<GatewayConfig
- target-service-category="my category"
+ target-service-category="myCategory"
target-service-name="testFileGateway"
gatewayClass="org.jboss.soa.esb.listeners.gateway.FileGatewayListener"
pollLatencySeconds="5"
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/jmsEsbListenerConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/jmsEsbListenerConfig.xml 2006-11-19 17:02:30 UTC (rev 7711)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/jmsEsbListenerConfig.xml 2006-11-19 18:35:10 UTC (rev 7712)
@@ -12,6 +12,11 @@
jndi-URL="localhost"
message-selector="service='testJmsGateway'"
>
- <action class="org.jboss.soa.esb.listeners.gateway.JmsGatewayListenerUnitTest$MockMessageAwareAction" process="writeToDisk" />
+ <action class="org.jboss.soa.esb.listeners.gateway.JmsGatewayListenerUnitTest$MockMessageAwareAction" process="writeToDisk" />
+ <action class="org.jboss.soa.esb.actions.Notifier" okMethod="notifyOK">
+ <NotificationList type="OK">
+ <target class="NotifyConsole" />
+ </NotificationList>
+ </action>
</DummyActionConfig>
</DummyTester>
More information about the jboss-svn-commits
mailing list