[jboss-svn-commits] JBL Code SVN: r7416 - in labs/jbossesb/workspace/b_georges/product/core: . listeners listeners/src listeners/src/org listeners/src/org/jboss listeners/src/org/jboss/internal listeners/src/org/jboss/internal/soa listeners/src/org/jboss/internal/soa/esb listeners/src/org/jboss/internal/soa/esb/couriers listeners/src/org/jboss/soa listeners/src/org/jboss/soa/esb listeners/src/org/jboss/soa/esb/actions listeners/src/org/jboss/soa/esb/actions/converters listeners/src/org/jboss/soa/esb/actions/routing listeners/src/org/jboss/soa/esb/actions/templates listeners/src/org/jboss/soa/esb/couriers listeners/src/org/jboss/soa/esb/listeners listeners/src/org/jboss/soa/esb/listeners/gateway listeners/src/org/jboss/soa/esb/listeners/message listeners/src/org/jboss/soa/esb/listeners/old listeners/src/org/jboss/soa/esb/nagios listeners/src/org/jboss/soa/esb/nagios/monitor listeners/src/org/jboss/soa/esb/nagios/transport listeners/src/org/jboss/soa/esb/nagios/util listeners/tests list! eners/tests/resources listeners/tests/resources/conf listeners/tests/src listeners/tests/src/org listeners/tests/src/org/jboss listeners/tests/src/org/jboss/soa listeners/tests/src/org/jboss/soa/esb listeners/tests/src/org/jboss/soa/esb/actions listeners/tests/src/org/jboss/soa/esb/actions/converters listeners/tests/src/org/jboss/soa/esb/listeners listeners/tests/src/org/jboss/soa/esb/listeners/old listeners/tests/src/org/jboss/soa/esb/util rosetta rosetta/src rosetta/src/org rosetta/src/org/jboss rosetta/src/org/jboss/internal rosetta/src/org/jboss/internal/soa rosetta/src/org/jboss/internal/soa/esb rosetta/src/org/jboss/internal/soa/esb/addressing rosetta/src/org/jboss/internal/soa/esb/command rosetta/src/org/jboss/internal/soa/esb/message rosetta/src/org/jboss/internal/soa/esb/message/format rosetta/src/org/jboss/internal/soa/esb/message/format/serialized rosetta/src/org/jboss/internal/soa/esb/message/format/xml rosetta/src/org/jboss/internal/soa/esb/message/format/xml/m! arshal rosetta/src/org/jboss/internal/soa/esb/notification rosetta/src/org/jboss/internal/soa/esb/parameters rosetta/src/org/jboss/internal/soa/esb/persistence rosetta/src/org/jboss/internal/soa/esb/thirdparty rosetta/src/org/jboss/internal/soa/esb/util rosetta/src/org/jboss/soa rosetta/src/org/jboss/soa/esb rosetta/src/org/
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Nov 6 09:49:46 EST 2006
Author: b_georges
Date: 2006-11-06 09:45:54 -0500 (Mon, 06 Nov 2006)
New Revision: 7416
Added:
labs/jbossesb/workspace/b_georges/product/core/listeners/
labs/jbossesb/workspace/b_georges/product/core/listeners/build.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/src/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/log4j.properties
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/internal/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/internal/soa/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/internal/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/internal/soa/esb/couriers/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractFileAction.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractSqlRowAction.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionDefinition.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionDefinitionFactory.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessingException.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessor.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionUtils.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/FtpDownloader.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/FtpUploader.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ByteArrayToString.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/FileToByteArray.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ObjectToCSVString.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ObjectToXStream.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/FileCopier.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/ObjectToFileWriter.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockAction.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockComposer.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockFileAction.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockMessageAction.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockSqlRowAction.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/Courier.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierException.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierFactory.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/gatewayExample.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/easier2ReadExample.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/example.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractPoller.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/DirectoryPoller.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/GpListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/JmsQueueListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/RemoteDirectoryPoller.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/SqlTablePoller.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/Constants.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/MonitorManager.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/NagiosAgent.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/NagiosAgentMBean.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/Runner.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/ServiceResponse.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/HeartbeatMonitor.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/MemoryMonitor.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/ServiceMonitor.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/NagiosNSCAPacket.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/NagiosNSCATransport.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/ByteOps.java
labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/CRC32.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/build.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/resources/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/resources/conf/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/resources/conf/log4j.properties
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/device-profile.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-01.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-02.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-03.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-04.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-05.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-06.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-07.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-08.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-09.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-10.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-11.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinitionFactoryUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/BaseTestActionProcessor.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor1.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor2.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor3.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestBean.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ToNowhereRouter.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ByteArrayToStringUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/FileToByteArrayUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/LongToDateConverter.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToCSVStringUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToFileWriterUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToXStreamUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/StringToLongConverter.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/smooks-test.cdrl
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListenerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListener_ActionConfig.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/DirectoryPollerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListener-Config-01.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListenerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.xml
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/AbstractMockListner.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/ListenersManagerExecThread.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockNonblockingListener.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockNotificationTarget.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockPoller.java
labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/smooks-cdr.lst
labs/jbossesb/workspace/b_georges/product/core/rosetta/
labs/jbossesb/workspace/b_georges/product/core/rosetta/ant.bat
labs/jbossesb/workspace/b_georges/product/core/rosetta/build.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/EPRHelper.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/PortReferenceHelper.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/CommandQueue.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/CommandQueueException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/InMemoryCommandQueue.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/JmsCommandQueue.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/MessageFactoryImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/AttachmentImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/ContextImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/FaultImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/PropertiesImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/SerializedMessagePlugin.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/ContextImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/FaultImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/PropertiesImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLMessagePlugin.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/MarshalUnmarshalManager.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/MarshalUnmarshalPlugin.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/SerializedMarshalUnmarshalPlugin.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/notification/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/notification/MacroExpander.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/parameters/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/parameters/ParamFileRepository.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/persistence/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/persistence/format/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/thirdparty/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/thirdparty/Base64.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/util/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/util/StreamUtils.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/BaseException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/ConfigurationException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/MarshalException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/ProtocolNotSupportedException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/SendFailedException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/UnmarshalException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/Call.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/EPR.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/PortReference.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/XMLUtil.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/EmailEpr.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/FTPEpr.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/HTTPEpr.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JDBCEpr.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JMSEpr.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Address.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/BankAcct.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/BatchProcess.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/OneValue.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Person.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Telephone.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/AbandonedConnectionTimerTask.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionFactory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionPool.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionPoolFactory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionProperties.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionWrapper.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/DefaultConnectionPoolImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/DriverConnectionFactory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/FreeConnectionPoolResources.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/PasswordDecoder.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/PoolDataSource.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/exception/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/exception/ConnectionException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/AppServerContext.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/Email.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/KeyValuePair.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SqlField.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Attachment.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Body.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Context.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Fault.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Header.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Message.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Properties.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessageFactory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessagePlugin.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessageType.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationList.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationTarget.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyEmail.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyFiles.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyQueues.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifySqlTable.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyTopics.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyUtil.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepository.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepositoryException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepositoryFactory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/BatchManager.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/DefaultEncryptionFactory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/Encryption.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/NotificationManager.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/PersistManager.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStore.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreFactory.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/TransformationException.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/TransformationService.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/BaseBusinessObject.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/BobjStdDTO.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/NagiosStandaloneHeartbeat.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/ObjLocator.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/ObjLocatorSorter.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/build.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/default.persistence.properties
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/ejb3-deployment.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/ejb3-interceptors-aop.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/embedded-jboss-beans.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/jboss-jms-beans.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/jndi.properties
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/log4j.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/login-config.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/security-beans.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/device-profile.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/etc/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/etc/jbossesb-test-properties.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/StreamUtils.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/StringUtils.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/W3CDomUtils.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/CallUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/EPRUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/command/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/command/InMemoryCommandQueueUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/bizclasses/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/bizclasses/BatchProcessUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/BaseTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/EJBContainerSetup.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/HsqldbUtil.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/MockDataSource.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/TestUtil.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/AddressUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/PersonUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/propertymanager/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/propertymanager/PropertyManagerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/utils/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/utils/DrainQueuesAndTopics.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/AbandonedConnectionFuncTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/ConnectionPoolFuncTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/PasswordDecoderFuncTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/PasswordDecoderTestImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/esb/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/esb/persistence/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/AppServerContextUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/ConfigTreeUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/EmailUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/KeyValuePairUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_01.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_02.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_03.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile1.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile2.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile3.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile4.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessageImpl.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessagePlugin.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/FaultUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/PropertiesUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest_expected1.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotificationListUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotificationListUnitTest_testfile1.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyEmailUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyFilesUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifySqlTableUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifySqlTable_testfile1.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/TestNotificationTarget1.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/TestNotificationTarget2.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/ParamRepositoryFactoryUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/ParamsFileRepositoryUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/TestParamRepo.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest_testfile1.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest_testfile1.xml
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/StreamUtilsUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/TestBob.java
labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/UtilUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/
labs/jbossesb/workspace/b_georges/product/core/services/ant.bat
labs/jbossesb/workspace/b_georges/product/core/services/build.xml
labs/jbossesb/workspace/b_georges/product/core/services/src/
labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/
labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/application.xml
labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/manifest.server
labs/jbossesb/workspace/b_georges/product/core/services/src/org/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/esb/persistence/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/BobjStore.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoBatchTable.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoIndexTable.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoSnapTable.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoUidTable.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/RowBatch.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/Storable.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerBsDelegateLocal.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerBsDelegateRemote.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerFactory.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotifHandlerBsDelegateLocal.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotifHandlerBsDelegateRemote.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotificationHandlerFactory.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerBsDelegateLocal.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerBsDelegateRemote.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerFactory.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreFactoryImpl.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStorePlugin.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreType.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBConnectionManager.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBConnectionManagerDBCP.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBMessageStorePlugin.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/MessageStoreImpl.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/JAXRRegistryImpl.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryException.java
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryFactory.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/
labs/jbossesb/workspace/b_georges/product/core/services/tests/application.xml
labs/jbossesb/workspace/b_georges/product/core/services/tests/build.xml
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/BobjStoreUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/BobjStoreUnitTest_config1.xml
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/DaoUidTableUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/DummyUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/NotificationUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/PersistHandlerUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/JAXRRegistryUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/juddi-unittest.properties
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/tests/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/tests/objectstore/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/tests/objectstore/ObjectStoreFuncTest.java
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/util/
labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/util/FileUtil.java
Log:
Added latest version
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/build.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/build.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,95 @@
+<?xml version="1.0"?>
+<project name="BuildJbossEsbListeners" default="org.jboss.esb.listeners.compile" basedir=".">
+
+ <property name="org.jboss.esb.listeners.jar.name" value="jbossesb-listeners"/>
+ <property name="org.jboss.esb.listeners.distrib.dir" value="${org.jboss.esb.internal.dest}/dist"/>
+ <property name="org.jboss.esb.listeners.classes.dir" value="${org.jboss.esb.internal.dest}/classes/listeners"/>
+ <property name="org.jboss.esb.listeners.src.dir" value="${basedir}/src"/>
+ <property name="org.jboss.esb.root.dir" value="../.."/>
+ <property environment="env"/>
+
+ <property name="org.jboss.esb.ext.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext"/>
+ <property name="org.jboss.esb.ejb3.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext/ejb3"/>
+ <condition property="org.jboss.esb.ext.lib.dir" value="{org.jboss.esb.jboss.home}/client">
+ <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
+ </condition>
+
+ <path id="org.jboss.esb.listeners.base.classpath">
+ <fileset dir="${org.jboss.esb.ext.lib.dir}" includes="*.jar"/>
+ </path>
+
+ <path id="org.jboss.esb.listeners.default.classpath">
+ <path refid="org.jboss.esb.listeners.base.classpath"/>
+ <pathelement location="${org.jboss.esb.classes.dir}"/>
+ <pathelement location="${org.jboss.esb.internal.dest}/classes/rosetta"/>
+ <pathelement location="${org.jboss.esb.internal.dest}/classes/services"/>
+ <fileset dir="${org.jboss.esb.ejb3.lib.dir}" includes="*.jar,*.zip"/>
+ </path>
+
+ <target name="org.jboss.esb.listeners.init">
+ <tstamp>
+ <format property="TODAY" pattern="d-MM-yy"/>
+ </tstamp>
+ </target>
+
+ <target name="org.jboss.esb.listeners.prepare" depends="org.jboss.esb.listeners.init">
+ <mkdir dir="${org.jboss.esb.listeners.classes.dir}"/>
+ <mkdir dir="${org.jboss.esb.listeners.distrib.dir}"/>
+ <mkdir dir="${org.jboss.esb.listeners.distrib.dir}/lib"/>
+ </target>
+
+ <target name="clean" description="Remove classes directory">
+ <delete dir="${org.jboss.esb.listeners.classes.dir}"/>
+ </target>
+
+ <target name="purge" depends="clean">
+ </target>
+
+
+
+ <target name="org.jboss.esb.listeners.compile">
+ <!-- Compile listeners -->
+ <antcall target="org.jboss.esb.listeners.internal.compile"/>
+ <!-- Compile listener tests -->
+ <ant inheritAll="true" dir="tests" target="org.jboss.esb.listeners.tests.compile"/>
+ </target>
+
+
+
+ <target name="org.jboss.esb.listeners.internal.compile" depends="org.jboss.esb.listeners.prepare"
+ description="Compile all classes">
+
+ <javac
+ destdir="${org.jboss.esb.listeners.classes.dir}"
+ classpathref="org.jboss.esb.listeners.default.classpath"
+ debug="${org.jboss.esb.debug}"
+ optimize="${org.jboss.esb.optimize}"
+ >
+ <src path="${org.jboss.esb.listeners.src.dir}"/>
+ </javac>
+
+ </target>
+
+ <target name="recompile" depends="clean,org.jboss.esb.listeners.compile"
+ description="Clean and compile"/>
+
+ <target name="jar" depends="org.jboss.esb.listeners.compile" description="Assemble jar files">
+ <delete file="${org.jboss.esb.listeners.distrib.dir}/lib/${org.jboss.esb.listeners.jar.name}.jar" />
+ <jar destfile="${org.jboss.esb.listeners.distrib.dir}/lib/${org.jboss.esb.listeners.jar.name}.jar"
+ basedir="${org.jboss.esb.listeners.classes.dir}"
+ includes="**/*.class"
+ excludes="test/**"
+ />
+ </target>
+
+
+
+ <target name="org.jboss.esb.listeners.test" description="Run tests for this module">
+ <!-- Compile listener tests -->
+ <ant dir="tests" target="org.jboss.esb.listeners.internal.test"/>
+ </target>
+
+
+ <target name="all" depends="recompile,jar" />
+
+</project>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/log4j.properties
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/log4j.properties 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/log4j.properties 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,7 @@
+### direct log messages to stdout ###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+### set log levels - for more verbose logging change 'info' to 'debug' ###
+log4j.rootLogger=info, stdout
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,173 @@
+/*
+ * 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.internal.soa.esb.couriers;
+
+import java.util.*;
+import javax.jms.*;
+import javax.naming.Context;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.helpers.AppServerContext;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.Util;
+import org.jboss.soa.esb.helpers.*;
+
+public class JmsCourier implements Courier
+{
+ /**
+ * disable default constructor
+ */
+ private JmsCourier() { }
+ /**
+ * package protected constructor - Objects of Courier should only be instantiated by the Factory
+ * @param epr
+ */
+ public JmsCourier(EPR epr) throws CourierException
+ {
+ _sleepForRetries = 3000;
+
+ try
+ {
+ _messageProperties = Util.propertiesFromSelector(_epr.getMessageSelector());
+ createMessageProducer();
+ }
+ catch (Exception e) { throw new CourierException(e); }
+
+ } //________________________________
+
+ /**
+ * package the ESB message in a javax.jms.ObjectMessage, and send it
+ * @param message Message - the message to deliver
+ * @return boolean - the result of the delivery
+ * @throws CourierException - if problems were encountered
+ */
+ public boolean deliver(Message message) throws CourierException
+ {
+ if (null==message)
+ return false;
+ while (null!=_messageProducer)
+ {
+ try
+ {
+ // obtain Serializable version of arg0 and package it in a jms ObjectMessage
+ sendMessage(_jmsSession.createObjectMessage(Util.serialize(message)));
+ return true;
+ }
+ catch (JMSException e) { jmsRetry(e); }
+ catch (Exception e) { throw new CourierException(e);}
+ }
+ return false;
+ } //________________________________
+
+ /**
+ * send/publish a javax.jms.ObjectMessage (that will contain the serialized ESB Message)
+ * @param jmsMessage
+ */
+ protected void sendMessage(javax.jms.Message jmsMessage) throws JMSException
+ {
+ if (_messageProducer instanceof TopicPublisher)
+ ((TopicPublisher)_messageProducer).publish(jmsMessage);
+ else
+ _messageProducer.send(jmsMessage);
+ } //________________________________
+
+ private void jmsRetry(Exception exc)
+ {
+ _logger.error("JMS error. Attempting JMS reconnect.", exc);
+ _jmsConnection = null;
+ _jmsSession = null;
+ _messageProducer= null;
+
+ for (int i1 = 0; i1 < 5; i1++)
+ {
+ // try to reconnect to the queue
+ try { createMessageProducer(); }
+ catch (Exception e)
+ {
+ _logger.error("Reconnecting to JMS", e);
+ try { Thread.sleep(_sleepForRetries); }
+ catch (InterruptedException e1)
+ { // Just return after logging
+ _logger.error("Unexpected thread interupt exception.", e);
+ break;
+ }
+ }
+ }
+ }
+
+ protected void createMessageProducer() throws Exception
+ {
+
+ String sJndiType = _epr.getJndiType();
+ if (Util.isNullString(sJndiType))
+ sJndiType = "jboss";
+ String sJndiURL = _epr.getJndiURL();
+ if (Util.isNullString(sJndiURL))
+ sJndiURL = "localhost";
+ Context oJndiCtx = AppServerContext.getServerContext(sJndiType,sJndiURL);
+
+ String sFactoryClass = _epr.getConnectionFactory();
+ if (Util.isNullString(sFactoryClass))
+ sFactoryClass = "ConnectionFactory";
+
+ Object tmp = oJndiCtx.lookup(sFactoryClass);
+
+ String sType = _epr.getDestinationType();
+ if (JMSEpr.QUEUE_TYPE.equals(sType))
+ {
+ javax.jms.Queue queue = (javax.jms.Queue) oJndiCtx.lookup(_epr.getDestinationName());
+ QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+ QueueConnection qConn = qcf.createQueueConnection();
+ QueueSession qSess = qConn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
+ _jmsConnection = qConn;
+ _jmsSession = qSess;
+ _messageProducer = qSess.createProducer(queue);
+ }
+ else if(JMSEpr.TOPIC_TYPE.equals(sType))
+ {
+ Topic topic = (Topic) oJndiCtx.lookup(_epr.getDestinationName());
+ TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
+ TopicConnection tConn = tcf.createTopicConnection();
+ TopicSession tSess = tConn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
+ _jmsConnection = tConn;
+ _jmsSession = tSess;
+ _messageProducer = tSess.createPublisher(topic);
+ }
+ else
+ throw new CourierException("Unknown destination type");
+
+ } //________________________________
+
+ protected JMSEpr _epr;
+ protected Logger _logger = Logger.getLogger(JmsCourier.class);
+ protected String _messageSelector;
+ protected Connection _jmsConnection;
+ protected Session _jmsSession;
+ protected MessageProducer _messageProducer;
+ protected long _sleepForRetries = 3000; // milliseconds
+ protected List<KeyValuePair> _messageProperties;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractFileAction.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractFileAction.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractFileAction.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,77 @@
+/*
+ * 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.actions;
+
+import java.io.File;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * <p/>
+ * Extend this class if you need to implement an action class intended to process one file at a time.
+ * <p/>
+ * See {@link org.jboss.soa.esb.actions.routing.FileCopier} as an example.
+ * <p/>
+ * This class are stateful.
+ * @author Esteban.
+ */
+public abstract class AbstractFileAction implements ActionProcessor {
+
+ /**
+ * Files processed by action classes
+ * need to be renamed during processing to disable other listeners (or other
+ * threads launched by the same listener that started this thread) to pick
+ * up the same file <br/>Once processing ends a suffix will be added to the
+ * name of the original file that has been processed. The suffix will be
+ * different according to the result of processing (OK or Exception). Files
+ * could be moved to different directories as well <br/> Parameters for
+ * these options can be provided at run time in the ConfigTree (arg 0 in
+ * constructor)
+ * @param message The message payload to be processed.
+ * @return The processing result.
+ * @throws ActionProcessingException Exception during payload processing.
+ */
+ public final Message process(Message message) throws ActionProcessingException {
+
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if(!(oCurr instanceof File)) {
+ throw new ActionProcessingException
+ ("Message current object for processing by " + getClass().getName()
+ + " should have been preprocessed to a " + File.class.getName()
+ + " instance.");
+ }
+
+ // Call the implementing class to process the file message...
+ ActionUtils.setTaskObject(message,process((File)oCurr));
+ return message;
+ }
+
+ /**
+ * Process the file message object.
+ * @param file The file to be processed.
+ * @return The processing result.
+ * @throws ActionProcessingException Exception while processing file.
+ */
+ protected abstract Object process(File file) throws ActionProcessingException;
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractSqlRowAction.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractSqlRowAction.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractSqlRowAction.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,51 @@
+package org.jboss.soa.esb.actions;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Abstract SQL Row action.
+ * <p/>
+ * Convienience class for processing messages from the {@link org.jboss.soa.esb.listeners.old.SqlTablePoller} listener.
+ * Implementing classes receive a single row resultset through their implementation of the {@link #process(Map)}
+ * method.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public abstract class AbstractSqlRowAction implements ActionProcessor {
+
+ protected Logger logger;
+
+ protected AbstractSqlRowAction(String actionName,
+ List<KeyValuePair> properties) throws Exception {
+
+ logger = Logger.getLogger(getClass());
+ }
+
+ public final Message process(Message message) throws ActionProcessingException {
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if (!(oCurr instanceof Map)) {
+ throw new ActionProcessingException(
+ "Message object for processing by "
+ + getClass().getName()
+ + " should have been preprocessed and supplied as a "
+ + Map.class.getName() + " instance.");
+ }
+ ActionUtils.setTaskObject(message,process((Map)oCurr));
+ return message;
+ } // ________________________________
+
+ /**
+ * Process the SQL poll resultset.
+ *
+ * @param resultSet SQL Poller resultset.
+ * @return Processing result.
+ */
+ protected abstract Object process(Map resultSet) throws ActionProcessingException;
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionDefinition.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionDefinition.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionDefinition.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,106 @@
+package org.jboss.soa.esb.actions;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+/**
+ * Action Definition.
+ * <p/>
+ * An Action is defined by "name", an action "processor" instance to perform the processing action, plus
+ * properties to the processing action to be supplued to the processor instance.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ActionDefinition {
+
+ private String name;
+ private String processor;
+ private List<KeyValuePair> properties;
+ private boolean isSingleton = true;
+ private ActionProcessor singletonInstance = null;
+
+ /**
+ * Private constructor.
+ * @param name The action name.
+ * @param processor The action processor runtime class.
+ * @param properties Action properties list. An empty list for an action with no defined properties.
+ */
+ protected ActionDefinition(String name, String processor, List<KeyValuePair> properties) {
+ this.name = name;
+ this.processor = processor;
+ this.properties = properties;
+
+ String isSingletonProp = KeyValuePair.getValue("singleton", properties);
+ isSingleton = (isSingletonProp == null || !isSingletonProp.equals("false"));
+ }
+
+ /**
+ * Get the action name.
+ * @return The action name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the action processor instance.
+ * @return The Action Processor.
+ */
+ public ActionProcessor getProcessor() {
+ if(!isSingleton) {
+ return createActionProcessor();
+ } else {
+ if(singletonInstance == null) {
+ singletonInstance = createActionProcessor();
+ }
+ return singletonInstance;
+ }
+ }
+
+ /**
+ * Get the action properties to be supplied to the action processor.
+ * @return The configured action properties. An empty list for an action with no defined properties.
+ */
+ public List<KeyValuePair> getProperties() {
+ return properties;
+ }
+
+ /**
+ * Create the action processor instance.
+ * <p/>
+ * See the {@link ActionProcessor} regarding reflective construction rules.
+ * @return The action processor instance.
+ */
+ private ActionProcessor createActionProcessor() {
+ Class<? extends ActionProcessor> runtimeClass;
+ Class[] NONDEFAULT_SIG = new Class[] {String.class, List.class};
+ Constructor nonDefaultConstructor;
+
+ // Get the runtime class...
+ try {
+ runtimeClass = Class.forName(processor).asSubclass(ActionProcessor.class);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalStateException("Action Processor class " + processor + " not found in classpath.", e);
+ } catch (ClassCastException e) {
+ throw new IllegalStateException("Action Processor class " + processor + " does not implement " + ActionProcessor.class.getName(), e);
+ }
+
+ // Construct it...
+ try {
+ nonDefaultConstructor = runtimeClass.getConstructor(NONDEFAULT_SIG);
+ return (ActionProcessor) nonDefaultConstructor.newInstance(new Object[] {name, properties});
+ } catch (NoSuchMethodException e1) {
+ try {
+ return runtimeClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new IllegalStateException("No appropriate constructor found on processor class [" + processor + "]. See " + ActionProcessor.class.getName() + " Javadoc.", e);
+ } catch (Exception e) {
+ throw new IllegalStateException("Unexpected exception. Unable to construct processor class instance [" + processor + "] using default constructor.", e);
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException("Unexpected exception. Unable to construct processor class instance [" + processor + "] using non-default constructor.", e);
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionDefinitionFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionDefinitionFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionDefinitionFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,189 @@
+/*
+ * 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.actions;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+/**
+ * Action Definition Factory.
+ * <p/>
+ * Note, much of the logic in this class could easily be replaced through the use of an IoC container.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ActionDefinitionFactory {
+
+ /**
+ * Class Logger.
+ */
+ private static Logger logger = Logger.getLogger(ActionDefinitionFactory.class);
+ /**
+ * Action Definition table.
+ */
+ private Hashtable<String, ActionDefinition> actionDefinitions = new Hashtable<String, ActionDefinition>();
+
+ /**
+ * Construct a factory instance.
+ * @param config ActionDefinition configuration.
+ * @throws ConfigurationException Invalid configuration.
+ */
+ public ActionDefinitionFactory(ConfigTree config) throws ConfigurationException {
+ if(config == null || !config.getName().equals("Actions")) {
+ throw new ConfigurationException("No 'Actions' configuration.");
+ }
+
+ // Read the processor alias and action def configurations from the XML configuration...
+ ConfigTree processorAliasConfig = config.getFirstChild("ProcessorAliases");
+ ConfigTree[] actions = config.getChildren("Action");
+ if(processorAliasConfig == null) {
+ throw new ConfigurationException("No 'Actions/ProcessorAliases' configuration.");
+ }
+ if(actions == null || actions.length == 0) {
+ throw new ConfigurationException("No 'Actions/Action' configurations.");
+ }
+
+ // Initialise the Action Definition table..
+ Hashtable<String, String> processorClasses = getProcessorClasses(processorAliasConfig);
+ initialiseActionDefinitions(actions, processorClasses);
+ logger.info("ActionDefinition Factory initialisation complete.");
+ }
+
+ /**
+ * Get the action definition for the specified action name.
+ * @param actionName The action name.
+ * @return The action definition.
+ */
+ public ActionDefinition getInstance(String actionName) {
+ if(actionName == null || actionName.trim().equals("")) {
+ throw new IllegalArgumentException("Null or empty 'actionName' arg in method call.");
+ }
+
+ return actionDefinitions.get(actionName);
+ }
+
+ /**
+ * Initialise the Action Definitions.
+ * @param actions Action Definition configurations.
+ * @param processorClasses Processor classes keyed by alias name.
+ * @throws ConfigurationException
+ */
+ private void initialiseActionDefinitions(ConfigTree[] actions, Hashtable<String, String> processorClasses) throws ConfigurationException {
+ if(processorClasses == null || processorClasses.isEmpty()) {
+ throw new ConfigurationException("No action processor classes defined.");
+ }
+
+ for(ConfigTree action : actions) {
+ String name = action.getAttribute("name");
+ String processorAlias = action.getAttribute("processor");
+ String processorClass;
+ List<KeyValuePair> properties;
+
+ // Check the required attributes...
+ if(name == null || name.trim().equals("")) {
+ throw new ConfigurationException("Actions/Action has no 'name' defined.");
+ }
+ if(processorAlias == null || processorAlias.trim().equals("")) {
+ throw new ConfigurationException("Actions/Action [" + name + "] has no 'processor' defined.");
+ }
+ processorClass = processorClasses.get(processorAlias);
+ if(processorClass == null) {
+ throw new ConfigurationException("No action processor class defined for processor alias [" + processorAlias + "] set on action [" + name + "].");
+ }
+
+ // Get any properties defined on the action...
+ properties = getProperties(action);
+
+ // Create the action definition and store it against it's name...
+ actionDefinitions.put(name, new ActionDefinition(name, processorClass, properties));
+ logger.info("Added ActionDefinition [" + name + "] for processor [" + processorAlias + ":" + processorClass + "]. Num properties: " + properties.size());
+ }
+ }
+
+ /**
+ * Get the processor runtime classes.
+ * @param processorAliasConfig Alias configs.
+ * @return Processor runtime classs
+ * @throws ConfigurationException Bad configuration.
+ */
+ private Hashtable<String, String> getProcessorClasses(ConfigTree processorAliasConfig) throws ConfigurationException {
+ ConfigTree[] aliases = processorAliasConfig.getChildren("Alias");
+ Hashtable<String, String> processorClasses = new Hashtable<String, String>();
+
+ if(aliases == null) {
+ throw new ConfigurationException("No 'Actions/ProcessorAliases/Alias' configurations.");
+ }
+
+ for(ConfigTree alias : aliases) {
+ String name = alias.getAttribute("name");
+ String className = alias.getAttribute("class");
+
+ // Check the required attributes...
+ if(name == null || name.trim().equals("")) {
+ throw new ConfigurationException("Actions/ProcessorAliases/Alias has no 'name' defined.");
+ }
+ if(className == null || className.trim().equals("")) {
+ throw new ConfigurationException("Actions/ProcessorAliases/Alias [" + name + "] has no 'class' defined.");
+ }
+ processorClasses.put(name, className);
+ logger.info("Added alias [" + name + "] for ActionProcessor class [" + className + "].");
+ }
+
+ return processorClasses;
+ }
+
+ /**
+ * Get the properties defined on the supplied 'Action' configuration.
+ * @param action The action configuration element.
+ * @return A list of property {@link KeyValuePair} instances. An empty list list is returned
+ * if no properties are defined on the action.
+ * @throws ConfigurationException A property name or value is empty or undefined.
+ */
+ private List<KeyValuePair> getProperties(ConfigTree action) throws ConfigurationException {
+ ConfigTree[] properties = action.getChildren("property");
+ List<KeyValuePair> propertyList = new ArrayList<KeyValuePair>();
+
+ for(ConfigTree property : properties) {
+ String name = property.getAttribute("name");
+ String value = property.getAttribute("value");
+
+ // Check the required attributes...
+ if(name == null || name.trim().equals("")) {
+ throw new ConfigurationException("Actions/Action/property has no 'name' defined. Action [" + action.getAttribute("name") + "].");
+ }
+ if(value == null || value.trim().equals("")) {
+ throw new ConfigurationException("Actions/Action/property has no 'value' defined. Action [" + action.getAttribute("name") + "], Property [" + name + "].");
+ }
+
+ propertyList.add(new KeyValuePair(name, value));
+ }
+
+ return propertyList;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessingException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessingException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessingException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,61 @@
+/*
+ * 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.actions;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * Exception while processing message payload processing action.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ActionProcessingException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Public constructor.
+ * @param message Exception message.
+ */
+ public ActionProcessingException(String message) {
+ super(message);
+ }
+
+ /**
+ * Public constructor.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public ActionProcessingException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Public constructor.
+ * @param cause Exception cause.
+ */
+ public ActionProcessingException(Throwable cause) {
+ super(cause);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessor.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessor.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessor.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,67 @@
+/*
+ * 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.actions;
+
+import java.io.Serializable;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Action Processor Interface Definition.
+ * <p/>
+ * An "Action Processor" performs a processing action on a message payload and returns the processing
+ * result.
+ * <p/>
+ * Implementations are constructed based on the following public constructor order precedence:
+ * <ol>
+ * <li><b>(String actionName, List<{@link org.jboss.soa.esb.helpers.KeyValuePair}> properties)</b></li>
+ * <li><b>default constructor</b>.</li>
+ * </ol>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public interface ActionProcessor {
+
+
+ /**
+ * Perform the processing action on the message
+ * @param message The message to be processed.
+ * @return Message - result of process
+ * @throws ActionProcessingException Exception during payload processing.
+ */
+ public Message process(Message message) throws ActionProcessingException;
+
+ /**
+ * Get the "OK" notification message for this processor.
+ * @param message The message Object.
+ * @return The OK message.
+ */
+ public abstract Serializable getOkNotification(Message message);
+
+ /**
+ * Get the "Error" notification message for this processor.
+ * @param message The message Object.
+ * @return The Error message.
+ */
+ public abstract Serializable getErrorNotification(Message message);
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionUtils.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionUtils.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/ActionUtils.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,125 @@
+/*
+ * 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.actions;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.notification.NotificationList;
+
+/**
+ * Contains utility methods for actions
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ */
+public class ActionUtils
+{
+ public static final String BEFORE_ACTION="org.jboss.soa.esb.actions.current.before";
+ private static final String CURRENT_OBJECT="org.jboss.soa.esb.actions.current.after";
+ private static final String CONFIG_TREE ="org.jboss.soa.esb.helpers.ConfigTree";
+
+ /**
+ * Obtain the current object from standard spot within message
+ * @param message - from where to obtain the 'current object'
+ * @return Object stored in Body with key ActionProcessor.CURRENT_OBJECT
+ */
+ public static Object getTaskObject(Message message)
+ {
+ return (null==message)? null : message.getBody().get(CURRENT_OBJECT);
+ }
+ /**
+ * Obtain previous 'current object' from standard spot within message
+ * @param message - from where to obtain the value
+ * @return Object stored in Body with key ActionProcessor.BEFORE_ACTION
+ */
+ public static Object getTaskBeforeObject(Message message)
+ {
+ return (null==message)? null : message.getBody().get(BEFORE_ACTION);
+ }
+ /**
+ * Copy 'current object' to a temporary holder within message
+ * @param message
+ */
+ public static void copyCurrentToPrevious(Message message)
+ {
+ Body body = message.getBody();
+ body.remove(BEFORE_ACTION);
+ body.add(BEFORE_ACTION,body.get(CURRENT_OBJECT));
+ }
+ /**
+ * Put current object in standard spot within message
+ * <br/>NULL values are not stored
+ * @param message - to operate on
+ * @param obj - Object to store - Won't be stored if <null>
+ * @return Object previous 'current object'
+ */
+ public static Object setTaskObject(Message message, Object obj)
+ {
+ Object oRet = message.getBody().remove(CURRENT_OBJECT);
+ if (null!=obj)
+ message.getBody().add(CURRENT_OBJECT,obj);
+ return oRet;
+ }
+
+ /**
+ * Put a Config tree in predefined spot for it in 'this'
+ * <br/>NULL values are not stored
+ * @param message - to operate on
+ * @param tree - ConfigTree to store - Won't be stored if <null>
+ * @return ConfigTree previously stored
+ */
+ public static ConfigTree setConfigTree(Message message, ConfigTree tree)
+ {
+ ConfigTree oRet = (ConfigTree)message.getBody().remove(CONFIG_TREE);
+ if (null!=tree)
+ message.getBody().add(CONFIG_TREE,tree);
+ return oRet;
+ }
+ /**
+ * Put a Config tree in predefined spot for it in 'this'
+ * <br/>NULL values are not stored
+ * @param message - to operate on
+ * @param tree - ConfigTree to store - Won't be stored if <null>
+ * @return ConfigTree previously stored
+ */
+ public static ConfigTree getConfigTree(Message message)
+ {
+ ConfigTree oRet = (ConfigTree)message.getBody().get(CONFIG_TREE);
+ return (null==oRet)?new ConfigTree("mock"):oRet;
+ }
+
+ public static NotificationList getNotifyList(ConfigTree tree, String type)
+ {
+ ConfigTree[] array = tree.getChildren("NotificationList");
+ for (ConfigTree curr : array)
+ {
+ String sType = curr.getAttribute(NotificationList.TYPE);
+ if (null==sType)
+ continue;
+ if (type.toLowerCase().startsWith(sType.toLowerCase()))
+ return new NotificationList(curr);
+ }
+ return null;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/FtpDownloader.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/FtpDownloader.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/FtpDownloader.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,123 @@
+/*
+* 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.actions;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.listeners.old.GpListener;
+import org.jboss.soa.esb.listeners.old.RemoteDirectoryPoller;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.FtpClientUtil;
+
+public class FtpDownloader extends AbstractFileAction
+{
+ ConfigTree _parms;
+ FtpClientUtil _ftpClient;
+ String _localDir;
+ RemoteDirectoryPoller.WorkingFile _workFile;
+ Logger _logger = Logger.getLogger(this.getClass());
+
+ /**
+ * Public constructor.
+ * @param actionName Action name.
+ * @param properties Action Properties.
+ * @throws ConfigurationException Action not properly configured.
+ */
+ public FtpDownloader(String actionName, List<KeyValuePair> properties)
+ { _parms = new ConfigTree("fromProps");
+ for (KeyValuePair oCurr : properties)
+ _parms.setAttribute(oCurr.getKey(),oCurr.getValue());
+ } //________________________________
+
+ @Override
+ public Object process(File obj) throws ActionProcessingException
+ {
+ try { _workFile = (RemoteDirectoryPoller.WorkingFile)obj; }
+ catch(ClassCastException e)
+ {
+ throw new ActionProcessingException
+ ("Argument must be an instance of "+ _workFile.getClass().getName(),e);
+ }
+
+ try
+ {
+ // Kludge to obtain ftp arguments from message - not quite nice... (ES)
+ if (null!=_workFile.getFtpProps())
+ for (KeyValuePair kvp : _workFile.getFtpProps())
+ {
+ String sVal = kvp.getValue();
+ _parms.setAttribute(kvp.getKey(),(null==sVal)?"":sVal);
+ }
+ // end of kludge
+// System.out.println("Downloading "+_workFile);
+ _ftpClient = new FtpClientUtil(_parms,true);
+ _localDir = _parms.getAttribute(FtpClientUtil.PARMS_LOCAL_DIR);
+ String sFrom = FtpClientUtil.fileToFtpString(_workFile);
+ _ftpClient.downloadFile(sFrom,_workFile.getInputFile().getName());
+
+ if (_workFile.isPostDelete())
+ _ftpClient.remoteDelete(_workFile);
+ else
+ _workFile.remoteRenameToOutput(_ftpClient);
+
+ GpListener.notifyOK(_parms,getOkNotification(null));
+ return _workFile;
+ }
+ catch (Exception e)
+ {
+ GpListener.notifyError(_parms,e,getErrorNotification(null));
+ try { _workFile.remoteRenameToInput(_ftpClient); }
+ catch (Exception e2) { /* not much we can do if can't rename back to input */}
+ throw new ActionProcessingException(e);
+ }
+ finally
+ {
+ if (null!=_ftpClient)
+ _ftpClient.quit();
+ _ftpClient = null;
+ }
+ } //________________________________
+
+ public Serializable getOkNotification(Message message)
+ {
+ return new StringBuilder()
+ .append(_workFile.getInputFile().toString())
+ .append("successfully downloaded to ").append(_localDir)
+ .toString();
+ } //________________________________
+
+ public Serializable getErrorNotification(Message message)
+ {
+ return new StringBuilder()
+ .append("Failed to download ").append(_workFile.getInputFile().toString())
+ .append(" to ").append(_localDir)
+ .toString();
+ } //________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/FtpUploader.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/FtpUploader.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/FtpUploader.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,115 @@
+/*
+* 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.actions;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.listeners.old.DirectoryPoller;
+import org.jboss.soa.esb.listeners.old.GpListener;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.FtpClientUtil;
+
+public class FtpUploader extends AbstractFileAction
+{
+ ConfigTree _parms;
+ FtpClientUtil _ftpClient;
+ String _remoteDir;
+ DirectoryPoller.WorkingFile _workFile;
+ Logger _logger = Logger.getLogger(this.getClass());
+
+ /**
+ * Public constructor.
+ * @param actionName String - Action name.
+ * @param properties List<KeyValuePair> - Action Properties.
+ * @throws ConfigurationException Action not properly configured.
+ */
+ public FtpUploader(String actionName, List<KeyValuePair> properties)
+ { _parms = new ConfigTree("fromProps");
+ for (KeyValuePair oCurr : properties)
+ _parms.setAttribute(oCurr.getKey(),oCurr.getValue());
+ } //________________________________
+
+ @Override
+ public Object process(File obj) throws ActionProcessingException
+ {
+ try { _workFile = (DirectoryPoller.WorkingFile)obj; }
+ catch(ClassCastException e)
+ {
+ throw new ActionProcessingException
+ ("Argument must be an instance of "+ _workFile.getClass().getName(),e);
+ }
+
+ try
+ {
+ System.out.println("FTP uploading "+obj);
+ _ftpClient = new FtpClientUtil(_parms,true);
+ _remoteDir = _parms.getAttribute(FtpClientUtil.PARMS_REMOTE_DIR);
+ _ftpClient.uploadFile(_workFile,_workFile.getInputFile().getName());
+
+ if (_workFile.isPostDelete())
+ _workFile.delete();
+ else
+ _workFile.renameToOutputFile();
+
+ GpListener.notifyOK(_parms,getOkNotification(null));
+ return _workFile;
+ }
+ catch (Exception e)
+ {
+ GpListener.notifyError(_parms,e,getErrorNotification(null));
+ _workFile.renameToError();
+ throw new ActionProcessingException(e);
+ }
+ finally
+ {
+ if (null!=_ftpClient)
+ _ftpClient.quit();
+ _ftpClient = null;
+ }
+ } //________________________________
+
+ public Serializable getOkNotification(Message message)
+ {
+ return new StringBuilder()
+ .append(_workFile.getInputFile().toString())
+ .append("successfully uploaded to ").append(_remoteDir)
+ .append(" on ").append(_parms.getAttribute(FtpClientUtil.PARMS_FTP_SERVER))
+ .toString();
+ } //________________________________
+
+ public Serializable getErrorNotification(Message message)
+ {
+ return new StringBuilder()
+ .append("Failed to upload ").append(_workFile.getInputFile().toString())
+ .append(" to ").append(_remoteDir)
+ .append(" on ").append(_parms.getAttribute(FtpClientUtil.PARMS_FTP_SERVER))
+ .toString();
+ } //________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ByteArrayToString.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ByteArrayToString.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ByteArrayToString.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,96 @@
+/*
+ * 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.actions.converters;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Byte Array to String processor.
+ * <p/>
+ * Sample Action Configuration:
+ * <pre>
+ * <Action name="Bytes-To-UTF-8-String" processor="ByteArrayToString">
+ * <property name="encoding" value="UTF-8" /> <!-- Default of "UTF-8". -->
+ * </Action>
+ * </pre>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ByteArrayToString implements ActionProcessor {
+
+ private String encoding;
+
+ /**
+ * Public constructor.
+ * @param actionName Processing action name.
+ * @param properties Action properties.
+ */
+ public ByteArrayToString(String actionName, List<KeyValuePair> properties) {
+ encoding = KeyValuePair.getValue("encoding", properties, "UTF-8");
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ byte[] bytes;
+
+ try {
+ bytes = (byte[])ActionUtils.getTaskObject(message);
+ } catch(ClassCastException e) {
+ throw new ActionProcessingException("Message must be an array of bytes. Is " + message.getClass().getName());
+ }
+
+ try {
+ ActionUtils.setTaskObject(message,new String(bytes, encoding));
+ return message;
+ } catch (UnsupportedEncodingException e) {
+ throw new ActionProcessingException("Unable to decode byte[] to String. Unsupported character encoding configuration: " + encoding, e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(Message)
+ */
+ public Serializable getOkNotification(Message message) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(Message)
+ */
+ public Serializable getErrorNotification(Message message) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/FileToByteArray.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/FileToByteArray.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/FileToByteArray.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions.converters;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.Serializable;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.AbstractFileAction;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * File data to byte array reader {@link org.jboss.soa.esb.actions.ActionProcessor}.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class FileToByteArray extends AbstractFileAction {
+
+ /**
+ * Logger.
+ */
+ private static Logger logger = Logger.getLogger(FileToByteArray.class);
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.AbstractFileAction#process(java.io.File)
+ */
+ @Override
+ protected Object process(File file) throws ActionProcessingException {
+ ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream();
+ FileInputStream fileInputStream = null;
+
+ try {
+ fileInputStream = new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ throw new ActionProcessingException("IOException reading file contents. File not found.", e);
+ }
+
+ try {
+ byte[] readBuffer = new byte[512];
+ int readCount = 0;
+
+ while((readCount = fileInputStream.read(readBuffer)) != -1) {
+ outputBuffer.write(readBuffer, 0, readCount);
+ }
+ } catch (IOException e) {
+ throw new ActionProcessingException("IOException reading file contents.", e);
+ } finally {
+ try {
+ fileInputStream.close();
+ } catch (IOException e) {
+ logger.warn("Error closing input file.", e);
+ }
+ }
+
+ return outputBuffer.toByteArray();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(Message message) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(Message message) {
+ return null;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ObjectToCSVString.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ObjectToCSVString.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ObjectToCSVString.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,158 @@
+/*
+ * 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.actions.converters;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Object to CSV String processor.
+ * <p/>
+ * Returns a CSV string based on the supplied message object and a comma-separated "bean-properties"
+ * action property that specifies a list of bean property names.
+ * <p/>
+ * Sample Action Configuration:
+ * <pre>
+ * <Action name="Customer-To-CSV" processor="ObjectToCSVString">
+ * <property name="bean-properties" value="name,address1,address2,phone" />
+ * <property name="fail-on-missing-property" value="true" /> <!-- (Optional) Default of false. -->
+ * </Action>
+ * </pre>
+ * <p/>
+ * TODO: Add support for arrays ala producing the contents of a CSV file.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToCSVString implements ActionProcessor {
+
+ public static final String BEAN_PROPERTIES_PROP = "bean-properties";
+ public static final String FAIL_ON_MISSING_PROPERTY = "fail-on-missing-property";
+ private static Logger logger = Logger.getLogger(ObjectToCSVString.class);
+ private List<String> propertyMethodNames = new ArrayList<String>();
+ private boolean failOnMissingProperty;
+
+ /**
+ * Public constructor.
+ * @param actionName Action name.
+ * @param properties Action Properties.
+ * @throws ConfigurationException Action not properly configured.
+ */
+ public ObjectToCSVString(String actionName, List<KeyValuePair> properties) throws ConfigurationException {
+ String objectProps = KeyValuePair.getValue(BEAN_PROPERTIES_PROP, properties);
+
+ if(objectProps == null || objectProps.trim().equals("")) {
+ throw new ConfigurationException("Action [" + actionName + "] must specify a comma seperated object bean property list via a '" + BEAN_PROPERTIES_PROP + "' property setting.");
+ }
+
+ // Construct a bean method name list from the configured property name list...
+ String[] propertyNames = objectProps.split(",");
+ StringBuffer methodNameConstructionBuffer = new StringBuffer();
+ for(String propertyName : propertyNames) {
+ propertyName = propertyName.trim();
+
+ if(propertyName.equals("")) {
+ continue;
+ }
+
+ methodNameConstructionBuffer.setLength(0);
+ methodNameConstructionBuffer.append("get");
+ methodNameConstructionBuffer.append(propertyName);
+
+ // Capitalise the 4th char to make it a proper bean method....
+ methodNameConstructionBuffer.setCharAt(3, Character.toUpperCase(methodNameConstructionBuffer.charAt(3)));
+
+ // Add to the set...
+ propertyMethodNames.add(methodNameConstructionBuffer.toString());
+ }
+
+ failOnMissingProperty = KeyValuePair.getBooleanValue(FAIL_ON_MISSING_PROPERTY, properties, false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+
+ Object oCurr = ActionUtils.getTaskObject(message);
+ Class oCurrClass = (null==oCurr) ? null : oCurr.getClass();
+ StringBuffer csv = new StringBuffer();
+ boolean hasAppendStarted = false; // Have we appended a value yet?
+
+ for(String methodName : propertyMethodNames) {
+ Method method;
+
+ if(hasAppendStarted) {
+ csv.append(",");
+ }
+ hasAppendStarted = true;
+
+ // Get the bean method....
+ try {
+ method = oCurrClass.getMethod(methodName, new Class[] {});
+ } catch (Exception e) {
+ String exceptionMessage = "Bean method: " + methodName + " not found/accessible on message object " + oCurr.getClass().getName();
+ logger.error(exceptionMessage, e);
+ if(failOnMissingProperty) {
+ throw new ActionProcessingException(exceptionMessage, e);
+ }
+ csv.append("<no-such-property>");
+ continue;
+ }
+
+ // Call the bean method and add the toString of the return to the CSV string....
+ try {
+ Object value = method.invoke(oCurr, new Object[] {});
+ // TODO: Some sort of encoding is required here to make a proper CSV string...
+ csv.append(value != null?value.toString():"");
+ } catch (Exception e) {
+ logger.error("Exception calling bean method: " + methodName, e);
+ }
+ }
+ ActionUtils.setTaskObject(message,csv.toString());
+ return message;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(Message message) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(Message message) {
+ return null;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ObjectToXStream.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ObjectToXStream.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/ObjectToXStream.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,107 @@
+/*
+ * 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.actions.converters;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+
+import com.thoughtworks.xstream.XStream;
+
+/**
+ * Object to XML processor.
+ * <p/>
+ * Uses the <a href="http://xstream.codehaus.org/">XStream</a> processor to generate an XML message String from the supplied object.
+ * <p/>
+ * Sample Action Configuration:
+ * <pre>
+ * <Action name="Customer-To-XML" processor="ObjectToXStream">
+ * <property name="class-alias" value="Customer" /> <!-- Class alias used in call to <a href="http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/XStream.html">XStream.alias(String, Class)</a> prior to serialisation. -->
+ * <property name="exclude-package" value="false" /> <!-- Default "true". Not applicable if a "class-alias" is specified. -->
+ * </Action>
+ * </pre>
+ * <p/>
+ * The XML root element is either set from the "class-alias" property or the classes full name. In the later case, the class package is
+ * excluded unless "exclude-package" is set to "false"/"no".
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToXStream implements ActionProcessor {
+
+ private String classAlias;
+ private boolean excludePackage;
+
+ /**
+ * Public constructor.
+ * @param actionName Action name.
+ * @param properties Action Properties.
+ * @throws ConfigurationException Action not properly configured.
+ */
+ public ObjectToXStream(String actionName, List<KeyValuePair> properties) {
+ classAlias = KeyValuePair.getValue("class-alias", properties);
+ excludePackage = KeyValuePair.getBooleanValue("exclude-package", properties, true);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+
+ Object object = ActionUtils.getTaskObject(message);
+ XStream xstream = new XStream();
+
+ if(classAlias == null) {
+ if(excludePackage) {
+ xstream.alias(object.getClass().getSimpleName(), object.getClass());
+ } else {
+ xstream.alias(object.getClass().getName(), object.getClass());
+ }
+ } else {
+ xstream.alias(classAlias, object.getClass());
+ }
+
+ ActionUtils.setTaskObject(message,xstream.toXML(object));
+ return message;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(Message message) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(Message message) {
+ return null;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/converters/SmooksTransformer.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,232 @@
+/*
+ * 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.actions.converters;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.transform.TransformationException;
+import org.jboss.soa.esb.services.transform.TransformationService;
+import org.milyn.SmooksStandalone;
+
+/**
+ * Smooks Transformer.
+ * <p/>
+ * This processor hooks the <a href="http://milyn.codehaus.org/Smooks">Milyn Smooks</a>
+ * XML Transformation/Processing Engine into a message processing pipeline to support
+ * XML message transformations.
+ * <p/>
+ * Sample Action Configuration:
+ * <pre>
+ * <Action name="Order_Xml-FROM_Acme-TO_AcmePartner" processor="SmooksTransformer">
+ * <property name="message-type" value="Order" /> <!-- REQUIRED. -->
+ * <property name="message-from" value="Acme" /> <!-- REQUIRED. -->
+ * <property name="message-to" value="AcmePartner" /> <!-- REQUIRED. -->
+ * <property name="message-encoding" value="UTF-8" /> <!-- OPTIONAL. Default "UTF-8" -->
+ * </Action>
+ * </pre>
+ * Eventually, all the message properties defined on the action will come from the message metadata. This will
+ * happen once we have a proper "normalized" message format with message headers etc.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+
+public class SmooksTransformer implements TransformationService, ActionProcessor {
+
+ private static Logger logger = Logger.getLogger(SmooksTransformer.class);
+ private static final String SMOOKS_CDR_LST = "smooks-cdr.lst";
+ private static SmooksStandalone smooks;
+ private String messageType;
+ private String messageFrom;
+ private String messageTo;
+ private String messageEnc;
+ private String messageUseragent;
+ private String cpPrefix;
+
+ /**
+ * Public constructor.
+ * @param actionName Action name.
+ * @param properties Action Properties.
+ * @throws ConfigurationException
+ * @throws ConfigurationException Action not properly configured.
+ */
+ public SmooksTransformer(String name, List<KeyValuePair> properties) throws ConfigurationException {
+ messageType = KeyValuePair.getValue("message-type", properties);
+ if(messageType == null || messageType.equals("")) {
+ throw new ConfigurationException("Action configuration 'message-type' not specified.");
+ }
+ messageFrom = KeyValuePair.getValue("message-from", properties);
+ if(messageFrom == null || messageFrom.equals("")) {
+ throw new ConfigurationException("Action configuration 'message-from' not specified.");
+ }
+ messageTo = KeyValuePair.getValue("message-to", properties);
+ if(messageTo == null || messageTo.equals("")) {
+ throw new ConfigurationException("Action configuration 'message-to' not specified.");
+ }
+ messageEnc = KeyValuePair.getValue("message-encoding", properties, "UTF-8");
+ // Test the configured encoding
+ try {
+ "astring".getBytes(messageEnc);
+ } catch (UnsupportedEncodingException e) {
+ throw new ConfigurationException("Invalid character encoding [" + messageEnc + "] on action configuration [" + name + "].", e);
+ }
+
+ // The "cpPrefix" property is "private" and only here in order to make unit testing easier.
+ // It allows us to force a "bad" config location for the smooks-cdr.lst file....
+ cpPrefix = KeyValuePair.getValue("smooks-cdr.list-classpath-prefix", properties, "/");
+ if(!cpPrefix.startsWith("/")) {
+ cpPrefix = "/" + cpPrefix;
+ }
+
+ initSmooks();
+
+ // In the context of the ESB, the Smooks useragent will be defined by the message "type", where it's
+ // coming "from" and where it's going "to"...
+ messageUseragent = messageType + "-" + messageFrom + "-" + messageTo;
+ // Register the message metadata as "profiles" within the Smooks context. These profiles ("type",
+ // "from" and "to") should expand out inside Smooks based on subprofiles that are
+ // statically configured against these profiles in the device-profiles.xml file. This is a bit
+ // of a hack but is fine for now just to get the ball rolling...
+ smooks.registerUseragent(messageUseragent, new String[] {"type:" + messageType, "from:" + messageFrom, "to:" + messageTo});
+ // TODO: Recurcively expand out the profiles supplied here using smooks.getContext().getProfileStore(). Do this inside SmooksStandalone
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.transform.TransformationService#transform(org.jboss.soa.esb.message.Message)
+ */
+ public Message transform(Message message) throws TransformationException {
+ try {
+ return process(message);
+ } catch (ActionProcessingException e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ Object oCurr = ActionUtils.getTaskObject(message);
+ try {
+ if(oCurr instanceof String) {
+ byte[] messageBytes = null;
+ String transformedMessage;
+
+ try {
+ messageBytes = ((String)oCurr).getBytes(messageEnc);
+ } catch (UnsupportedEncodingException e) {
+ // Can't happen - encoding was already tested in the constructor.
+ }
+
+ // TODO: Cater for more message input types e.g. InputStream, DOM Document...
+ // TODO: Cater for more message output types e.g. InputStream, DOM Document...
+
+ long start = System.currentTimeMillis();
+ transformedMessage = smooks.filterAndSerialize(messageUseragent, new ByteArrayInputStream(messageBytes));
+ if(logger.isDebugEnabled()) {
+ long timeTaken = System.currentTimeMillis() - start;
+ logger.debug("Transformed message for useragent [" + messageUseragent + "]. Time taken: "
+ + timeTaken + ". Message in:\n[" + oCurr.toString()+ "]. \nMessage out:\n[" + transformedMessage + "].");
+ }
+ ActionUtils.setTaskObject(message,transformedMessage);
+ } else {
+ String sClass = (null==oCurr) ? "<null>" : oCurr.getClass().getName();
+ logger.warn("String message types only supported. Input message was ["
+ + sClass + "]. Returning message untransformed.");
+ }
+ } catch(Throwable thrown) {
+ throw new ActionProcessingException("Message transformation failed.", thrown);
+ }
+ return message;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(Message message) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(Message message) {
+ return null;
+ }
+
+ /**
+ * Initialise the static SmooksStandalone instance.
+ * <p/>
+ * We may need to write a Smooks Container implementation specifically for JBossESB's needs. SmooksStandalone is
+ * fine for a start though.
+ * @throws ConfigurationException Failed to load Smooks configurations.
+ */
+ protected void initSmooks() throws ConfigurationException {
+ synchronized (SmooksTransformer.class) {
+ if(smooks == null) {
+ InputStream configListStream = getClass().getResourceAsStream(cpPrefix + SMOOKS_CDR_LST);
+
+ if(configListStream == null) {
+ throw new ConfigurationException("Failed to locate Smooks configuration list file [" + SMOOKS_CDR_LST + "]. The folder containing this file must be located at " + cpPrefix + " relative to the root of the classpath.");
+ }
+
+ // TODO: There's a potential issue here if two SmooksTransformer action configs specify and require
+ // different encodings. This is because they're all sharing the same static SmooksStandalone instance!!
+ // This should eventually be solveable by creating a proper Smooks container impl for the ESB.
+ smooks = new SmooksStandalone(messageEnc);
+
+ try {
+ BufferedReader configReader = new BufferedReader(new InputStreamReader(configListStream));
+ smooks.getContext().getStore().load(configReader);
+ } catch (Exception e) {
+ smooks = null;
+ throw new ConfigurationException("Smooks configuration load failed.", e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Reset the transformer.
+ * <p/>
+ * Clears the internal static smooks instance.
+ */
+ public static void reset() {
+ synchronized (SmooksTransformer.class) {
+ smooks = null;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/FileCopier.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/FileCopier.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/FileCopier.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,150 @@
+/*
+ * 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.actions.routing;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.AbstractFileAction;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.listeners.old.DirectoryPoller.WorkingFile;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * File copy action.
+ * <p/>
+ * Copy the file specified by the "fileParams" arg in {@link #process(File)} to the location specified by the
+ * action config properties.
+ * <p/>
+ * Sample Action Configuration:
+ * <pre>
+ * <Action name="Copy-To-XXX" processor="FileCopier">
+ * <property name="copyToDirURI" value="file:///..." />
+ * <property name="copyToSuffix" value=".fileCopierOutput" />
+ * </Action>
+ * </pre>
+ *
+ * @author Esteban
+ */
+public class FileCopier extends AbstractFileAction {
+
+ private static Logger logger = Logger.getLogger(FileCopier.class);
+
+ private static final String TMP_SUFFIX = ".notReady";
+
+ private static final String PARMS_OUTDIR = "copyToDirURI";
+
+ private static final String PARMS_OUTSFX = "copyToSuffix";
+
+ private File outputDir;
+ private String copyToSuffix;
+
+ /**
+ * Public constructor.
+ * @param actionName Action name.
+ * @param properties Action Properties.
+ * @throws ConfigurationException Action not properly configured.
+ */
+ public FileCopier(String actionName, List<KeyValuePair> properties) throws URISyntaxException {
+ String outputDirParam = KeyValuePair.getValue(PARMS_OUTDIR, properties);
+
+ try {
+ outputDir = new File(new URI(outputDirParam));
+ } catch(Exception e) {
+ outputDir = new File(outputDirParam);
+ }
+ copyToSuffix = KeyValuePair.getValue(PARMS_OUTSFX, properties, ".copy");
+ } // __________________________________
+
+ public Object process(File file) throws ActionProcessingException {
+ WorkingFile workingFile;
+
+ try {
+ workingFile = (WorkingFile)file;
+ } catch(ClassCastException e) {
+ throw new ActionProcessingException("File must be an instance of " + WorkingFile.class.getName());
+ }
+
+ File outputFile = new File(outputDir, workingFile.getInputFile().getName() + copyToSuffix);
+
+ try {
+ File tempFile = File.createTempFile(workingFile.getName(), TMP_SUFFIX, outputDir);
+ FileInputStream inputFileStream = new FileInputStream(workingFile);
+ FileOutputStream outputFileStream;
+
+ outputFileStream = new FileOutputStream(tempFile);
+
+ // Perform Copy
+ byte[] ba = new byte[1024];
+ while (true) {
+ int iQ = inputFileStream.read(ba);
+
+ if (iQ < 0) {
+ break;
+ }
+
+ outputFileStream.write(ba, 0, iQ);
+ }
+ // Close
+ inputFileStream.close();
+ outputFileStream.close();
+
+ // Rename
+ outputFile.delete();
+ tempFile.renameTo(outputFile);
+
+ if(logger.isDebugEnabled()) {
+ logger.debug("Successfully copied file " + workingFile.getAbsolutePath() + " to file " + outputFile.getAbsolutePath());
+ }
+ } catch(IOException e) {
+ throw new ActionProcessingException("IOException copying " + workingFile.getAbsolutePath() + " to " + outputFile.getAbsolutePath(), e);
+ }
+
+ return workingFile;
+ } // __________________________________
+
+ public Serializable getOkNotification(Message message) {
+ Object currentObject = ActionUtils.getTaskObject(message);
+
+ return "File " + ((WorkingFile)currentObject).getInputFile().getAbsolutePath()
+ + " successfully copied to all destination";
+ }
+
+ public Serializable getErrorNotification(Message message) {
+ Object currentObject = ActionUtils.getTaskObject(message);
+
+ return "File " + ((WorkingFile)currentObject).getInputFile().getAbsolutePath()
+ + " to configured destination";
+ }
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,202 @@
+/*
+ * 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.actions.routing;
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.helpers.AppServerContext;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+/**
+ * JSM Routing Action Processor.
+ * <p/>
+ * Sample Action Configuration:
+ * <pre>
+ * <Action name="Route-To-Invoicing" processor="JMSRouter">
+ * <property name="jndiName" value="queue/A" />
+ * <property name="message-prop:jms-selector" value="incoming-invoice" />
+ * </Action>
+ * </pre>
+ * Note how properties to be set on the message are prefixed with "message-prop:".
+ * <p/>
+ * TODO: Add support for JMS Topic destinations.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class JMSRouter implements ActionProcessor {
+ /**
+ * Logger.
+ */
+ private static Logger logger = Logger.getLogger(JMSRouter.class);
+ /**
+ * Routing properties.
+ */
+ private List<KeyValuePair> properties;
+ /**
+ * JMS Queue setup.
+ */
+ private JMSSendQueueSetup queueSetup;
+
+ /**
+ * Public constructor.
+ * @param actionName Action name.
+ * @param properties Action properties.
+ * @throws ConfigurationException Queue name not configured.
+ * @throws JMSException Unable to configure JMS destination.
+ * @throws NamingException Unable to configure JMS destination.
+ */
+ public JMSRouter(String actionName, List<KeyValuePair> properties) throws ConfigurationException, NamingException, JMSException {
+ this.properties = properties;
+
+ String queueName = KeyValuePair.getValue("jndiName", properties);
+ if(queueName == null) {
+ throw new ConfigurationException("JMSRouter must specify a 'jndiName' property.");
+ }
+ queueSetup = new JMSSendQueueSetup(queueName);
+ this.properties = properties;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public org.jboss.soa.esb.message.Message
+ process(org.jboss.soa.esb.message.Message message) throws ActionProcessingException {
+
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if(!(oCurr instanceof Serializable)) {
+ throw new ActionProcessingException("Cannot send Object [" + oCurr.getClass().getName() + "] to destination [" + queueSetup.queueName + "]. Object must be serializable.");
+ }
+
+ try {
+ // Send a Text or Object message to the queue...
+ if (oCurr instanceof String) {
+ TextMessage oMsg = queueSetup.jmsSession.createTextMessage();
+
+ if(logger.isDebugEnabled()) {
+ logger.debug("Sending Text message: [" + oCurr + "] to destination [" + queueSetup.queueName + "].");
+ }
+ oMsg.setText((String)oCurr);
+ setStringProperties(oMsg);
+ queueSetup.jmsProducer.send(oMsg);
+ } else {
+ ObjectMessage oMsg = queueSetup.jmsSession.createObjectMessage();
+
+ if(logger.isDebugEnabled()) {
+ logger.debug("Sending Object message: [" + oCurr + "] to destination [" + queueSetup.queueName + "].");
+ }
+ oMsg.setObject((Serializable) oCurr);
+ setStringProperties(oMsg);
+ queueSetup.jmsProducer.send(oMsg);
+ }
+ return message;
+ } catch(Exception e) {
+ String errorMessage = "Exception while sending message [" + oCurr + "] to destination [" + queueSetup.queueName + "].";
+ logger.error(errorMessage, e);
+ throw new ActionProcessingException(errorMessage, e);
+ }
+ }
+
+ private void setStringProperties(Message msg) throws JMSException {
+ String messagePropPrefix = "message-prop:";
+
+ for(KeyValuePair property : properties) {
+ String key = property.getKey();
+
+ if(key.startsWith(messagePropPrefix) && key.length() > messagePropPrefix.length()) {
+ msg.setStringProperty(key.substring(messagePropPrefix.length()), property.getValue());
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(org.jboss.soa.esb.message.Message message) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(org.jboss.soa.esb.message.Message message) {
+ return null;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ queueSetup.close();
+ super.finalize();
+ }
+
+ private static class JMSSendQueueSetup {
+ QueueSession jmsSession;
+ Queue jmsQueue;
+ MessageProducer jmsProducer;
+ String queueName;
+
+ // TODO: Modify to support topic destinations too
+
+ private JMSSendQueueSetup(String queueName) throws NamingException, JMSException {
+ Context m_oCtx = AppServerContext.getServerContext(
+ Configuration.getJndiServerType(),
+ Configuration.getJndiServerURL());
+ QueueConnectionFactory qcf = (QueueConnectionFactory) m_oCtx.lookup("ConnectionFactory");
+ QueueConnection oQconn = qcf.createQueueConnection();
+
+ this.queueName = queueName;
+
+ jmsSession = oQconn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ jmsQueue = (Queue) m_oCtx.lookup(queueName);
+ jmsProducer = jmsSession.createSender(jmsQueue);
+ }
+
+ private void close() {
+ try {
+ jmsProducer.close();
+ jmsSession.close();
+ } catch (Exception e) {
+ logger.error("Unable to close JMS Queue Setup.", e);
+ }
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/ObjectToFileWriter.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/ObjectToFileWriter.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/routing/ObjectToFileWriter.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,177 @@
+/*
+ * 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.actions.routing;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URI;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Object to file writing processor.
+ * <p/>
+ * Writes an Object to a file based on the "file" property specified by the action configuration. This "file"
+ * property can specify a file or directory. If the file is a directory, the class generates a file name based
+ * on the return from a call to {@link java.util.UUID#randomUUID()} and the file extension value specified in
+ * the "ext" property (default of "obj").
+ * <p/>
+ * If the message is a byte array it's writen to the file as is, otherwise the toString method is called on the
+ * message object and the resulting String bytes are writen to the file based on the "encoding" specified in the action
+ * configuration (see below).
+ * <p/>
+ * Sample Action Configuration:
+ * <pre>
+ * <Action name="Write-To-X-File" processor="ObjectToFileWriter">
+ * <property name="file" value="file:///..." /> <!-- File/Directory name. Supports URI or non-URI based names. -->
+ * <property name="append" value="true/false" /> <!-- Only relevant if the file is not a directory. Default of "false". -->
+ * <property name="ext" value="dat" /> <!-- Only relevant if the file is a directory. Default of "obj". -->
+ * <property name="encoding" value="UTF-8" /> <!-- Default of "UTF-8". -->
+ * </Action>
+ * </pre>
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToFileWriter implements ActionProcessor {
+
+ public static final String FILE_NAME = "file";
+ public static final String FILE_APPEND = "append";
+ public static final String FILE_EXT = "ext";
+ public static final String FILE_ENC = "encoding";
+ private static Logger logger = Logger.getLogger(ObjectToFileWriter.class);
+
+ private String actionName;
+ private File file;
+ private boolean append;
+ private String ext;
+ private String encoding;
+
+ /**
+ * Public constructor.
+ * @param actionName Action name.
+ * @param properties Action Properties.
+ * @throws ConfigurationException Action not properly configured.
+ */
+ public ObjectToFileWriter(String actionName, List<KeyValuePair> properties) throws ConfigurationException {
+ String fileName = KeyValuePair.getValue(FILE_NAME, properties);
+
+ this.actionName = actionName;
+
+ if(fileName == null || fileName.trim().equals("")) {
+ throw new ConfigurationException("Action [" + actionName + "] must specify a '" + FILE_NAME + "' property specifying the name of the output file.");
+ }
+ try {
+ // try it as a URI first...
+ file = new File(new URI(fileName));
+ } catch (Exception e) {
+ // ok, just interpret it as being relative to the cwd...
+ file = new File(fileName);
+ }
+ append = KeyValuePair.getBooleanValue(FILE_APPEND, properties, false);
+ ext = KeyValuePair.getValue(FILE_EXT, properties, "obj");
+ encoding = KeyValuePair.getValue(FILE_ENC, properties, "UTF-8");
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ synchronized(file) {
+ File outputFile = getOutputFile();
+ FileOutputStream fileOutputStream = null;
+ FileWriter fileWriter = null;
+
+ try {
+ fileWriter = new FileWriter(outputFile, append);
+ fileOutputStream = new FileOutputStream(outputFile, append);
+ } catch (IOException e) {
+ throw new ActionProcessingException("Action " + actionName + " failed. Unable to open output file " + outputFile.getAbsolutePath());
+ }
+
+ Object oCurr = ActionUtils.getTaskObject(message);
+ try {
+ if(oCurr instanceof byte[]) {
+ fileOutputStream.write((byte[])oCurr);
+ } else {
+ fileOutputStream.write(oCurr.toString().getBytes(encoding));
+ }
+ fileOutputStream.flush();
+ } catch (IOException e) {
+ throw new ActionProcessingException("Action " + actionName + " failed. Unable to write to output file " + outputFile.getAbsolutePath(), e);
+ } finally {
+ try {
+ fileWriter.close();
+ } catch (IOException e) {
+ logger.warn("Exception on closing file " + file.getAbsolutePath(), e);
+ }
+ }
+ }
+ return message;
+ }
+
+ /**
+ * Get the output file.
+ * @return Output file.
+ */
+ private File getOutputFile() {
+ if(file.isDirectory()) {
+ UUID randomUUID = UUID.randomUUID();
+ File randomFile = new File(file, randomUUID.toString() + "." + ext);
+
+ if(randomFile.exists()) {
+ return getOutputFile();
+ }
+
+ return randomFile;
+ } else {
+ return file;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(Message message) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(Message message) {
+ return null;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockAction.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockAction.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockAction.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,75 @@
+/*
+ * 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.actions.templates;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.message.Message;
+
+
+/**
+ * Use this class to tune your XML configurations <p/>Once your config works
+ * with this dummy class, you can switch to your own action class <p/>You will
+ * have to implement these three methods in your own action class
+ *
+ * @author Esteban
+ *
+ */
+public class MockAction implements ActionProcessor {
+ /**
+ * Class Logger.
+ */
+ private static Logger logger = Logger.getLogger(MockAction.class);
+
+ public Message process(Message message) {
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if (null==oCurr)
+ oCurr = "null";
+ logger.info("process was called with <<" + oCurr.toString() + ">>");
+ return message;
+ } // ________________________________
+
+ private SimpleDateFormat s_oTS = new SimpleDateFormat(
+ "yyyy/MM/dd hh:mm:ss.SSS");
+
+ private String getStamp() {
+ return s_oTS.format(new java.util.Date(System.currentTimeMillis()));
+ }
+
+ public Serializable getOkNotification(Message message) {
+ Object oCurr = ActionUtils.getTaskObject(message);
+ return getStamp() + " Notif OK - <"
+ + ((null == oCurr) ? "null" : oCurr.toString()) + ">";
+ } // ________________________________
+
+ public Serializable getErrorNotification(Message message) {
+ Object oCurr = ActionUtils.getTaskObject(message);
+ return getStamp() + " Notif ERROR - <"
+ + ((null == oCurr) ? "null" : message.toString()) + ">";
+ } // ________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockComposer.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockComposer.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockComposer.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,62 @@
+/*
+ * 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.actions.templates;
+
+import java.text.SimpleDateFormat;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.jboss.soa.esb.message.Message;
+
+
+/**
+ * Use this class to tune your XML configurations <p/>Once your config works
+ * with this dummy class, you can switch to your own action class
+ *
+ * @author Esteban
+ *
+ */
+public class MockComposer
+{
+ private static Logger _logger = Logger.getLogger(MockComposer.class);
+
+ public Message composeEmptyMessage(Object obj)
+ {
+ _logger.info(getLogMessage("process was called with <<" + obj.toString() + ">>"));
+ MessageImpl message = new MessageImpl();
+ return message;
+ } // ________________________________
+
+ private SimpleDateFormat s_oTS = new SimpleDateFormat(
+ "yyyy/MM/dd hh:mm:ss.SSS");
+
+ private String getLogMessage(String text)
+ {
+ return new StringBuilder()
+ .append(s_oTS.format(new java.util.Date(System.currentTimeMillis())))
+ .append(" ").append(text)
+ .toString()
+ ;
+ }
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockFileAction.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockFileAction.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockFileAction.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,74 @@
+/*
+ * 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.actions.templates;
+
+import java.io.File;
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.AbstractFileAction;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Use this class to tune your XML configurations
+ * <p/>Once your config works with this dummy class, you can
+ * switch to your own action class
+ * <p/>You will have to implement these three methods
+ * in your own action class
+ *
+ * @author Esteban
+ *
+ */
+public class MockFileAction extends AbstractFileAction
+{
+ private static Logger logger = Logger.getLogger(MockFileAction.class);
+
+ @Override
+ public Object process(File file) throws ActionProcessingException
+ {
+ logger.info("processObject was called with <<" + file.getAbsolutePath() + ">>");
+ return file;
+ } //________________________________
+
+ private SimpleDateFormat s_oTS = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss.SSS");
+ private String getStamp()
+ { return s_oTS.format(new java.util.Date(System.currentTimeMillis())); }
+
+ public Serializable getOkNotification(Message message)
+ {
+ return getStamp()+" Notif OK - <"
+ +ActionUtils.getTaskObject(message)
+ +">";
+ } //________________________________
+
+ public Serializable getErrorNotification(Message message)
+ {
+ return getStamp()+" Notif ERROR - <"
+ +ActionUtils.getTaskObject(message)
+ +">";
+ } //________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockMessageAction.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockMessageAction.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockMessageAction.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,137 @@
+/*
+ * 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.actions.templates;
+
+import java.text.*;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.helpers.*;
+import org.jboss.soa.esb.notification.*;
+
+
+/**
+ * Use this class to tune your XML configurations <p/>Once your config works
+ * with this dummy class, you can switch to your own action class <p/>You will
+ * have to implement these three methods in your own action class
+ *
+ * @author Esteban
+ *
+ */
+public class MockMessageAction
+{
+ protected Message _message;
+ protected ConfigTree _config;
+
+ public MockMessageAction(ConfigTree config) { _config = config; }
+ public Message noOperation(Message message) { return message; }
+
+ public Message process(Message message)
+ {
+ _message = message;
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if (null==oCurr)
+ oCurr = "null";
+ _logger.info(getStamp()+" process was called with <<" + oCurr.toString() + ">>");
+ return message;
+ } // ________________________________
+
+
+ public Message process222(Message message)
+ {
+ _message = message;
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if (null==oCurr)
+ oCurr = "null";
+ _logger.info(getStamp()+" process222 was called with <<" + oCurr.toString() + ">>");
+ return message;
+ } // ________________________________
+
+ private static final SimpleDateFormat s_oTS
+ = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss.SSS");
+
+ private String getStamp()
+ { return s_oTS.format(new java.util.Date(System.currentTimeMillis())); }
+
+ private static Logger _logger = Logger.getLogger(MockMessageAction.class);
+
+ public void myOkMethod1()
+ {
+ String sMsg = new StringBuilder(getStamp())
+ .append(" MockAction.myOkMethod1 was called ")
+ .append(_message)
+ .toString();
+ _logger.info(sMsg);
+ @SuppressWarnings("unused")
+ NotificationList nl = ActionUtils.getNotifyList(_config,"ok");
+ // Here you can send notifications to everybody
+ }
+
+ public void myMethod2()
+ {
+ String sMsg = new StringBuilder(getStamp())
+ .append(" Method2 Method2 Method2 Method2 Method2 CALLED ")
+ .append(_message)
+ .toString();
+ _logger.info(sMsg);
+ @SuppressWarnings("unused")
+ NotificationList nl = ActionUtils.getNotifyList(_config,"ok");
+ // Here you can send notifications to everybody
+ }
+
+ public void endOfChainNotification()
+ {
+ String sMsg = new StringBuilder(getStamp())
+ .append(" End of action chain reached - Bye bye")
+ .toString();
+ _logger.info(sMsg);
+ @SuppressWarnings("unused")
+ NotificationList nl = ActionUtils.getNotifyList(_config,"ok");
+ // Here you can send notifications to everybody
+ }
+
+ public Message justThrow(Message message) throws Exception
+ {
+ throw new MockException("Mock exception thrown at "+getStamp());
+ } // ________________________________
+
+ @SuppressWarnings("serial")
+ private class MockException extends Exception
+ {
+ MockException(String str) { super(str); }
+ }
+
+ public void exceptionCallback1(Exception e)
+ {
+ String sMsg = new StringBuilder(getStamp())
+ .append(" MockExceptionTrower.exceptionCallback1 CALLED ")
+ .append(_message)
+ .toString();
+ _logger.fatal(sMsg,e);
+ @SuppressWarnings("unused")
+ NotificationList nl = ActionUtils.getNotifyList(_config,"err");
+ // Here you can send notifications to everybody
+ }
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockSqlRowAction.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockSqlRowAction.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/actions/templates/MockSqlRowAction.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,84 @@
+/*
+ * 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.actions.templates;
+
+import java.io.Serializable;
+import java.text.SimpleDateFormat;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.jboss.soa.esb.actions.AbstractSqlRowAction;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Use this class to tune your XML configurations
+ * <p/>Once your config works with this dummy class, you can
+ * switch to your own action class
+ * <p/>You will have to implement these three methods
+ * in your own action class
+ *
+ * @author Esteban
+ *
+ */
+public class MockSqlRowAction extends AbstractSqlRowAction
+{
+
+ public static List<Map> params = new Vector<Map>();
+
+ public MockSqlRowAction(String actionName, List<KeyValuePair> properties) throws Exception {
+ super(actionName, properties);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.AbstractSqlRowAction#processSQL()
+ */
+ @Override
+ protected Object process(Map resultSet) {
+ logger.info("processResultset was called with <<"
+ + resultSet.toString()+">>");
+ params.add(resultSet);
+
+ return resultSet;
+ }
+
+ private SimpleDateFormat s_oTS = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss.SSS");
+ private String getStamp()
+ { return s_oTS.format(new java.util.Date(System.currentTimeMillis())); }
+
+ public Serializable getOkNotification(Message message)
+ {
+ return getStamp()+" Notif OK - <"
+ +ActionUtils.getTaskObject(message)
+ +">";
+ } //________________________________
+
+ public Serializable getErrorNotification(Message message)
+ {
+ return getStamp()+" Notif ERROR - <"
+ +ActionUtils.getTaskObject(message)
+ +">";
+ } //________________________________
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/Courier.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/Courier.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/Courier.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,36 @@
+/*
+ * 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.couriers;
+
+import org.jboss.soa.esb.message.Message;
+
+public interface Courier
+{
+/**
+ * try to deliver an ESB message
+ * @param message Message - the message to deliver
+ * @return boolean - the result of the delivery
+ * @throws CourierException - if problems were encountered
+ */
+ public abstract boolean deliver(Message message) throws CourierException;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.couriers;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * Dispatch Exception.
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ */
+public class CourierException extends BaseException
+{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct an exception instance.
+ * @param message Exception message.
+ */
+ public CourierException(String message) { super(message); }
+
+ /**
+ * Construct an exception instance.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public CourierException(String message, Throwable cause) { super(message, cause); }
+
+ /**
+ * Construct an exception instance.
+ * @param cause Exception cause.
+ */
+ public CourierException(Throwable cause) { super(cause); }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,54 @@
+/*
+ * 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.couriers;
+
+import java.net.URISyntaxException;
+
+import org.jboss.internal.soa.esb.couriers.JmsCourier;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.helpers.*;
+
+public class CourierFactory
+{
+ // private default constructor
+ private CourierFactory() {}
+
+ public static CourierFactory getInstance(Object obj)
+ {
+ return _instance;
+ }
+
+ public static Courier getCourier(EPR epr) throws CourierException
+ {
+ try
+ {
+ String address = epr.getAddr().getAddress();
+ if (address.startsWith(JMSEpr.JMS_PROTOCOL))
+ return new JmsCourier(epr);
+ }
+ catch (URISyntaxException e) { throw new CourierException(e); }
+ throw new CourierException("Unknown protocol");
+ }
+
+ private static final CourierFactory _instance = new CourierFactory();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,13 @@
+package org.jboss.soa.esb.listeners;
+
+public class ListenerTagNames
+{
+ public static final String SERVICE_NAME_TAG = "service-name";
+ public static final String TARGET_SERVICE_NAME_TAG = "target-service-name";
+
+ public static final String ACTION_ELEMENT_TAG = "action";
+ public static final String ACTION_CLASS_TAG = "class";
+ public static final String PROCESS_METHOD_TAG = "process";
+ public static final String NORMAL_COMPLETION_METHOD_TAG = "okMethod";
+ public static final String EXCEPTION_METHOD_TAG = "exceptionMethod";
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/GatewayListenerController.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,549 @@
+/*
+ * 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.io.IOException;
+import java.lang.reflect.Constructor;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.command.CommandQueue;
+import org.jboss.internal.soa.esb.command.CommandQueueException;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.util.EPRManager;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.jboss.soa.esb.util.Util;
+import org.xml.sax.SAXException;
+
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
+public class GatewayListenerController implements Runnable
+{
+
+ public static void main(String[] args) throws Exception
+ {
+ GatewayListenerController oProc = new GatewayListenerController(args[0]);
+ oProc.run();
+ GatewayListenerController.State oS = oProc.getState();
+
+ if (null != oS.getException()) {
+ _logger.error("GatewayListener <" + args[0] + "> FAILED\n", oS
+ .getException());
+ }
+ System.exit(oS.getCompletionCode());
+ } // ________________________________
+
+ public static final String RELOAD_SECONDS_TAG = "parameterReloadSecs";
+ public static final String END_TIME_TAG = "endTime";
+
+ // Attribute name that denotes listener class to be instantiated in a child thread
+ // This attribute is not in the root node but in first level child ConfigTrees
+ public static final String GATEWAY_CLASS_TAG = "gatewayClass";
+
+ /**
+ * Obtain a shallow copy of needed atributes in this object's last loaded
+ * parameter tree <p/>The local bject is cloned so child threads can use it
+ * as they choose to without interfering with the environment
+ * <p />
+ * Listener processes controlled by this object should keep a reference to
+ * this object at construction time, and not call this method again unless
+ * they specifically need updated values. Parameter reload could have
+ * happened since last call
+ *
+ * @return Map - a shallow copy of the attributes Map
+ */
+ @SuppressWarnings("unchecked")
+ public Map<String, Object> getControllerAttributes()
+ {
+ return (Map<String, Object>) _attributes.clone();
+ }
+
+ public State getState() { return _status; }
+
+ public static enum State
+ {
+ Loading_parameters, Running, Shutting_down, Done_OK, Exception_thrown;
+ int m_iCompletionCode = 0;
+
+ Exception m_oException = null;
+
+ public int getCompletionCode() {
+ return m_iCompletionCode;
+ };
+
+ public Exception getException() {
+ return m_oException;
+ }
+ };
+
+ private ActionDefinitionFactory actionDefinitionFactory;
+
+ /**
+ * Package pivate default constructor.
+ */
+ protected GatewayListenerController() { }
+
+ /**
+ * Construct a Listener Manager from the named repository based
+ * configuration.
+ *
+ * @param p_sParameterName
+ * Name of the Repository entry containing the configuration.
+ * @throws Exception
+ * Unable to load/use the named configuration.
+ */
+ public GatewayListenerController(String p_sParameterName) throws Exception {
+ this(GatewayListenerController.getListenerConfig(p_sParameterName));
+ _sParametersName = p_sParameterName;
+ }
+
+ /**
+ * Construct a Listener Manager using the specified listener configuration.
+ *
+ * @param config
+ * The configuration.
+ * @throws Exception
+ * Unable to load/use the supplied configuration.
+ */
+ public GatewayListenerController(ConfigTree config) throws Exception {
+ _config = config;
+ _status = State.Loading_parameters;
+
+ try { checkParms(_config); }
+ catch (Exception e)
+ {
+ String configSource = config.getAttribute("configSource");
+ _status = State.Exception_thrown;
+ _status.m_oException = e;
+ _logger.fatal("Listener configuration and startup error. Config Source: "
+ + (configSource != null ? configSource
+ : "unknown"), e);
+ throw e;
+ }
+ }
+
+ /**
+ * Load the named listener configuration from the configured parameter
+ * repository.
+ *
+ * @param reposParam
+ * The name of the repository entry containing the Listener
+ * configuration.
+ * @return Listener Configuration as {@link ConfigTree}.
+ * @throws IOException
+ * Unable to access the repository.
+ * @throws ParamRepositoryException
+ * Unable to access the configuration in the repository.
+ * @throws SAXException
+ * Unable to parse the configuration.
+ */
+ private static ConfigTree getListenerConfig(String reposParam)
+ throws IOException, ParamRepositoryException, SAXException {
+ String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
+ ConfigTree config = ConfigTree.fromXml(sXml);
+
+ config.setAttribute("configSource", "param-repository:" + reposParam);
+
+ return config;
+ }
+
+ /**
+ * Check to see if all needed parameters are there, and assign default
+ * values to some of them
+ *
+ * @param p_oP
+ * ConfigTree - Where to look for the mandatory/optional
+ * configuration attributes
+ * @throws Exception -
+ * If attributes are wrong or not enough for a proper runtime
+ * configuration
+ */
+ public void checkParms(ConfigTree p_oP) throws Exception {
+ // We've just loaded - set to false until next reload requested
+ _reloadRequested = false;
+ _commandQueue = createCommandQueue(p_oP);
+
+ // Open the command queue...
+ if (null!=_commandQueue)
+ _commandQueue.open(p_oP);
+
+ // if RELOAD_SECONDS_TAG not set, and no command queue
+ // then reload every 10 minutes
+ // If there is a command queue, run until command is received
+ String sRldSecs = p_oP.getAttribute(RELOAD_SECONDS_TAG);
+ _nextReload = (null != sRldSecs)
+ ? System.currentTimeMillis() + 1000 * Long.parseLong(sRldSecs)
+ : (null == _commandQueue)
+ ? Long.MAX_VALUE
+ : System.currentTimeMillis() + _defaultReloadMillis;
+
+ // if END_TIME_TAG not set try to run forever
+ // not a good practice if command queue is not set
+ // Expected date format is "yyyyMMdd hh:mm:ss"
+ String sEndT = p_oP.getAttribute(END_TIME_TAG);
+ _endTime = (null == sEndT) ? Long.MAX_VALUE : _dateFormat.parse(
+ sEndT).getTime();
+
+ // Read and initialise the action definitions...
+ ConfigTree actionConfig = p_oP.getFirstChild("Actions");
+ if(actionConfig == null) {
+ throw new ConfigurationException("No 'Actions' configuration.");
+ }
+ actionDefinitionFactory = new ActionDefinitionFactory(actionConfig);
+
+ } // ________________________________
+
+ /**
+ * Factory method for creating the command queue.
+ * @param config GatewayListener config.
+ * @return GatewayListener CommandQueue instance.
+ */
+ private CommandQueue createCommandQueue(ConfigTree config) {
+ String commandQueueClass = config.getAttribute("command-queue-class");
+
+ if(commandQueueClass != null) {
+ try {
+ return (CommandQueue) Class.forName(commandQueueClass).newInstance();
+ } catch (Exception e) {
+ _logger.error("Failed to instantiate CommandQueue ["+ commandQueueClass + "]. Defaulting to no Command Queue", e);
+ }
+ }
+
+ return _defaultCommandQueue;
+ }
+
+ /**
+ * Allows a default command queue to be set statically for all GatewayListener instances.
+ * @param defaultCommandQueue The defaultCommandQueue to set.
+ */
+ public static void setDefaultCommandQueue(CommandQueue defaultCommandQueue) {
+ GatewayListenerController._defaultCommandQueue = defaultCommandQueue;
+ }
+
+ /**
+ * Main execution loop <p/> Will continue to run until either <p/>a) run
+ * time is expired <p/>b) quiesce command is received in command queue
+ * <p/>For every child element that contains a PARM_LISTENER_CLASS
+ * attribute, this method will try to launch a child thread instantiating an
+ * object of that class, and will call it's run() method <p/>Once all child
+ * processes are trigered, the main thread will either <p/>1) wait for a
+ * message in the command queue (if one was configured) until next reload or
+ * end of run period expired <p/>or 2) Just sleep if there's no command
+ * queue to listen on
+ */
+ public void run()
+ {
+ while (endNotRequested())
+ {
+ _status = State.Running;
+ for (ConfigTree oCurr : _config.getAllChildren()) {
+ String sClass = oCurr.getAttribute(GATEWAY_CLASS_TAG);
+ if (Util.isNullString(sClass))
+ continue;
+ tryToLaunchGateway(oCurr, sClass);
+ }
+
+ waitForCmdOrSleep();
+
+ if (endRequested()) {
+ break;
+ }
+ if (_sParametersName != null && timeToReload())
+ {
+ try
+ {
+ _status = State.Loading_parameters;
+ _logger
+ .info("Reloading parameters _____________________________________________________");
+ ConfigTree oNew = GatewayListenerController.getListenerConfig(_sParametersName);
+ checkParms(oNew);
+ _config = oNew;
+ } catch (Exception e) {
+ _logger.error("Failed to reload parameters"
+ + " - Continuing with cached version", e);
+ }
+ }
+ }
+ // _status = State.Shutting_down;
+
+ _status = State.Done_OK;
+ _status.m_iCompletionCode = 0;
+ _logger
+ .info("Finishing_____________________________________________________");
+
+ // Close the command queue...
+ try {
+ _commandQueue.close();
+ } catch (CommandQueueException e) {
+ _logger.error("Error closing Command Queue.", e);
+ }
+ } // ________________________________
+
+ private void tryToLaunchGateway(ConfigTree p_oP, String p_sClassName)
+ {
+ try {
+ Class oListener = Class.forName(p_sClassName);
+ Constructor oConst = oListener.getConstructor(new Class[] {
+ this.getClass(), ConfigTree.class, ActionDefinitionFactory.class });
+ Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this,
+ p_oP, actionDefinitionFactory });
+ new Thread(oRun).start();
+ } catch (Exception e) {
+ _logger.error("Cannot launch <" + p_sClassName + ">\n", e);
+ }
+ } // ________________________________
+
+ long millisToWait() {
+ return Math.min(_nextReload, _endTime) - System.currentTimeMillis();
+ } // ________________________________
+
+ private void waitForCmdOrSleep() {
+ long lToGo = millisToWait();
+
+ if (null == _commandQueue) {
+ _logger.debug("About to sleep " + lToGo);
+ // No command queue nor topic - Just sleep until time
+ // exhausted, or thread interrupted
+ try {
+ if (lToGo > 0)
+ Thread.sleep(lToGo);
+ } catch (InterruptedException e) {
+ _endTime = 0; // mark as end requested and return
+ }
+ return;
+ }
+
+ // Wait for commands until time exhausted or command received
+ // Note that received commands might change time variables (reload/end)
+ // that's why time to go is recalculated on each cycle
+ while ((lToGo = millisToWait()) > 0) {
+ try {
+ _logger.info("Waiting for command ... timeout=" + lToGo + " millis");
+
+ String oM = _commandQueue.receiveCommand(lToGo);
+ if (null == oM) {
+ return;
+ }
+ processCommand(oM);
+ if (endRequested() || timeToReload()) {
+ break;
+ }
+ } catch (CommandQueueException eJ) {
+ _logger.info("receive on command queue failed", eJ);
+ }
+ }
+ } // ________________________________
+
+ /**
+ * Processes the command that has been received in the command queue (or
+ * topic) <p/>_endRequested, _reloadRequested, and _endTime could be
+ * changed
+ *
+ * <p/> <p/><TABLE border="1"> <COLGROUP> <COL width="200"/> <COL
+ * width="400"/> </COLGROUP>
+ * <TR>
+ * <TD align="center">message text</TD>
+ * <TD align="center">effect</TD>
+ * </TR>
+ * <TR>
+ * <TD>shutdown*</TD>
+ * <TD>End time will be immediately set to 'now' - quiesce process will
+ * start - Child threads will be allowed to finish normally</TD>
+ * </TR>
+ * <TR>
+ * <TD>reload param*</TD>
+ * <TD>Parameters will be immediately reloaded, and listener reconfigured
+ * with new values</TD>
+ * </TR>
+ * <TR>
+ * <TD>endTime yyyyMMdd hh:mm:ss</TD>
+ * <TD>End time will be set to new value. If hh:mm:ss is not supplied =>
+ * end of day assumed (23:59:59)</TD>
+ * </TR>
+ * </TABLE> * startsWith() <p/>
+ *
+ * @param p_oMsg
+ * Message received from the command queue.
+ *
+ */
+ private void processCommand(String sTxt) {
+ if (null == sTxt)
+ return;
+
+ String sLow = sTxt.trim().toLowerCase();
+ if (sLow.startsWith("shutdown")) {
+ _endRequested = true;
+ _logger.info("Shutdown has been requested");
+ return;
+ }
+ if (sLow.startsWith("reload param")) {
+ _reloadRequested = true;
+ _logger
+ .info("Request for parameter reload has been received");
+ return;
+ }
+ String[] sa = sLow.split("\\s+");
+ if (sa.length > 1 && "endtime".equals(sa[0])) {
+ try {
+ String sDate = sa[1];
+ String sTime = (sa.length < 3 || null == sa[2]) ? "23:59:59"
+ : sa[2];
+ Date oEnd = _dateFormat.parse(sDate + " " + sTime);
+ _logger.info("New end date set to : " + oEnd);
+ _endTime = oEnd.getTime();
+ } catch (Exception eDat) {
+ _logger.info("Problems with endTime command", eDat);
+ }
+ }
+ } // ________________________________
+
+ /**
+ * Accessor to determine if execution time is expired or shutdown requested
+ *
+ * @return boolean if processing has to stop (all child threads will be
+ * allowed to finish)
+ */
+ public boolean endRequested() {
+ return _endRequested || System.currentTimeMillis() >= _endTime;
+ }
+
+ /**
+ * Accessor to determine if execution time is not expired, and no shutdown
+ * request received
+ *
+ * @return boolean - true if run time has not expired and quiesce has not
+ * been requested
+ */
+ public boolean endNotRequested() {
+ return !endRequested();
+ }
+
+ /**
+ * Provide a common accessor to determine if parameters have to be reloaded
+ * <p/> For child threads this means thread execution has to end
+ * </p>
+ * Child processes should only call this method when they are idle (as
+ * opposed to in the middle of executing a unit of work)
+ *
+ * @return boolean - true if it's time to reload parameters
+ */
+ public boolean timeToReload() {
+ return _reloadRequested
+ || System.currentTimeMillis() >= _nextReload;
+ }
+
+ /**
+ * Helper accessor for child processes that provides info to determine if
+ * they can continue with yet another execution cycle
+ *
+ * @return boolean - true if runtime is not expired and not time yet to
+ * reload parameters
+ */
+ public boolean continueLooping() {
+ return (endNotRequested() && !timeToReload());
+ } // ________________________________
+
+ /**
+ * Find an attribute in the tree (arg 0) or assign default value (arg 2)
+ *
+ * @param p_oP
+ * ConfigTree - look for attributes in this Element only
+ * @param p_sAtt
+ * String - Name of attribute to find
+ * @param p_sDefault
+ * String -default value if requested attribute is not there
+ * @return String - value of attribute, or default value (if null)
+ * @throws Exception -
+ * If requested attribute not found and no default value
+ * supplied by invoker
+ */
+ public String obtainAtt(ConfigTree p_oP, String p_sAtt, String p_sDefault)
+ throws ConfigurationException {
+ String sVal = p_oP.getAttribute(p_sAtt);
+ if ((null == sVal) && (null == p_sDefault))
+ throw new ConfigurationException("Missing or invalid <" + p_sAtt + "> attribute");
+
+ return (null != sVal) ? sVal : p_sDefault;
+ } // ________________________________
+
+ private static EPRManager getEprManager()
+ {
+ PropertyManager manager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE);
+ String sDir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR,".");
+ return EPRManager.getInstance(sDir);
+ }
+
+ public EPR getEprByName (String serviceName) throws IOException
+ {
+ return getEprManager().loadEPR(serviceName);
+ } // ________________________________
+
+ public void register (String serviceName, EPR address)
+ {
+ try { getEprManager().saveEPR(serviceName,address); }
+ catch (IOException e)
+ {
+ _logger.fatal("Cannot register service",e);
+ }
+ } // ________________________________
+
+ public void unRegister (String serviceName, EPR address)
+ {
+ try { getEprManager().removeEPR(serviceName); }
+ catch (IOException e)
+ {
+ _logger.fatal("Cannot un-register service",e);
+ }
+ } // ________________________________
+
+
+ private CommandQueue _commandQueue;
+ private static CommandQueue _defaultCommandQueue = null;
+
+ private static Logger _logger = Logger.getLogger(GatewayListenerController.class);
+ private String _sParametersName;
+ private ConfigTree _config;
+ private boolean _reloadRequested;
+ private boolean _endRequested;
+ private long _nextReload = Long.MAX_VALUE;
+ private long _endTime = Long.MAX_VALUE;
+ protected int _defaultReloadMillis = 180000; // default interval between parameter reloads
+
+
+ public static final SimpleDateFormat _dateFormat
+ = new SimpleDateFormat("yyyyMMdd hh:mm:ss");
+
+ private State _status = null;
+
+
+ private HashMap<String, Object> _attributes;
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,241 @@
+/*
+ * 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.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.naming.Context;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+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.helpers.AppServerContext;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+
+public class JmsGatewayListener implements Runnable
+{
+
+ public JmsGatewayListener(GatewayListenerController commandListener, ConfigTree listenerConfig)
+ throws Exception
+ {
+ _config = listenerConfig;
+ _controller = commandListener;
+ _sleepForRetries = 3000; // milliseconds
+ checkMyParms();
+ } // __________________________________
+
+ public void run()
+ {
+ if (null!=_serviceName)
+ _controller.register(_serviceName,_myEpr);
+
+ while (_controller.continueLooping())
+ {
+ javax.jms.Message msgIn = receiveOne();
+ if (null!=msgIn)
+ try
+ {
+ Object obj = _processMethod.invoke(_composer,new Object[] {msgIn} );
+ if (null==obj)
+ {
+ _logger.warn("Action class method <"+_processMethod.getName()+"> returned a null object");
+ continue;
+ }
+ // try to deliver the composed message, using the appropriate courier
+ // to the target service
+ try
+ {
+ _courier.deliver((org.jboss.soa.esb.message.Message)obj);
+ }
+ catch (ClassCastException e)
+ {
+ _logger.error("Action class method <"+_processMethod.getName()+"> returned a non Message object");
+ continue;
+ }
+ catch (CourierException e)
+ {
+ _logger.error("Courier <"+_courier.getClass().getName()+".deliver(Message) FAILED");
+ continue;
+ }
+ continue;
+ }
+ catch (InvocationTargetException e)
+ {
+ _logger.error("Problems invoking method <"+_processMethod.getName()+">",e);
+ }
+ catch (IllegalAccessException e)
+ {
+ _logger.error("Problems invoking method <"+_processMethod.getName()+">",e);
+ }
+ catch (Exception e)
+ {
+ _logger.error("Unexpected problem",e);
+ }
+ }
+
+ if (null!=_serviceName)
+ _controller.unRegister(_serviceName,_myEpr);
+
+ if (null != _queueSession)
+ try { _queueSession.close(); }
+ catch (Exception e1) {/* Tried my best - Just continue */ }
+ if (null != _queueConnection)
+ try { _queueConnection.close(); }
+ catch (Exception e2) {/* Tried my best - Just continue */ }
+ } // ________________________________
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ *
+ * @throws Exception -
+ * if mandatory atts are not right or actionClass not in
+ * classpath
+ */
+ protected void checkMyParms() throws Exception
+ {
+ // Third arg is null - Exception will be thrown if attribute is not found
+ _targetServiceName = _controller.obtainAtt(_config, ListenerTagNames.TARGET_SERVICE_NAME_TAG, null);
+ _targetEpr = _controller.getEprByName(_targetServiceName);
+ if (null==_targetEpr)
+ throw new ConfigurationException("EPR <"+_targetServiceName+"> not found in registry");
+
+ _queueName = _controller.obtainAtt(_config, JMSEpr.DESTINATION_NAME_TAG, null);
+
+ // Look for first "action" element - only first one will be used
+ String tagName = ListenerTagNames.ACTION_ELEMENT_TAG;
+ ConfigTree actionElement = _config.getFirstChild(tagName);
+ if (null==actionElement)
+ throw new ConfigurationException("Missing <"+tagName+"> element");
+ // class attribute
+ _composerName = _controller.obtainAtt(actionElement,ListenerTagNames.ACTION_CLASS_TAG,null);
+ _composerClass = Class.forName(_composerName);
+ Constructor oConst = _composerClass.getConstructor(new Class[] {ConfigTree.class});
+ _composer= oConst.newInstance(_config);
+
+ // From here onwards, all attributes have a default value
+ // process attribute
+ tagName = ListenerTagNames.PROCESS_METHOD_TAG;
+ String sProcessMethod = _controller.obtainAtt(_config,tagName,tagName);
+ _processMethod = _composerClass.getMethod(sProcessMethod,new Class[] {Message.class});
+
+ // No problem if selector is null - everything in queue will be returned
+ _messageSelector = _config.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG);
+
+ _courier = CourierFactory.getCourier(_targetEpr);
+
+ prepareMessageReceiver();
+ } // ________________________________
+
+ private void prepareMessageReceiver() throws Exception
+ {
+ _queueConnection = null;
+ _queueSession = null;
+ _queue = null;
+
+ String sJndiType = _controller.obtainAtt(_config, JMSEpr.JNDI_TYPE_TAG,"jboss");
+ String sJndiURL = _controller.obtainAtt(_config, JMSEpr.JNDI_URL_TAG,"localhost");
+ Context oJndiCtx = AppServerContext.getServerContext(sJndiType,sJndiURL);
+
+ String sFactClass = _controller.obtainAtt(_config,JMSEpr.CONNECTION_FACTORY_TAG, "ConnectionFactory");
+ _serviceName = _config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ _myEpr = (null==_serviceName) ? null
+ : new JMSEpr(JMSEpr.QUEUE_TYPE,_queueName,sFactClass,sJndiType,sJndiURL,_messageSelector);
+
+ Object tmp = oJndiCtx.lookup(sFactClass);
+ QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+
+ _queueConnection = qcf.createQueueConnection();
+ _queue = (Queue) oJndiCtx.lookup(_queueName);
+ _queueSession = _queueConnection.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
+ _queueConnection.start();
+
+ _messageReceiver = _queueSession.createReceiver(_queue, _messageSelector);
+
+ } // ________________________________
+
+ /**
+ * Receive one message and retry if connection
+ * @return javax.jms.Message - One input message, or null
+ */
+ protected javax.jms.Message receiveOne()
+ {
+ while (_controller.endRequested())
+ try
+ {
+ return _messageReceiver.receive(_controller.millisToWait());
+ }
+ catch (JMSException oJ)
+ {
+ _logger.error("JMS error on receive. Attempting JMS Destination reconnect.", oJ);
+ try { prepareMessageReceiver(); }
+ // try to reconnect to the queue
+ catch (Exception e)
+ {
+ _logger.error("Reconnecting to Queue", e);
+ try { Thread.sleep(_sleepForRetries); }
+ catch (InterruptedException e1)
+ { // Just return
+ _logger.error("Unexpected thread interupt exception.", e);
+ return null;
+ }
+ }
+ }
+ return null;
+ } //________________________________
+
+ protected final static Logger _logger = Logger.getLogger(JmsGatewayListener.class);
+
+ protected String _queueName;
+ protected QueueConnection _queueConnection;
+ protected QueueSession _queueSession;
+ protected Queue _queue;
+ protected MessageConsumer _messageReceiver;
+ protected String _messageSelector;
+ protected ConfigTree _config;
+ protected GatewayListenerController _controller;
+ protected final long _sleepForRetries; // milliseconds
+
+ protected String _serviceName,_targetServiceName;
+ protected EPR _myEpr ,_targetEpr;
+
+ protected String _composerName;
+ protected Class _composerClass;
+ protected Object _composer;
+ protected Method _processMethod;
+
+ protected Courier _courier;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/gatewayExample.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/gatewayExample.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/gatewayExample.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,18 @@
+<GatewayListenerControllerExample
+ parameterReloadSecs="180"
+>
+ <JmsGatewayExample
+ target-service-name="your target service name"
+ service-name="JmsGatewayService"
+ listenerClass="org.jboss.soa.esb.listeners.gateway.JmsGatewayListener"
+ connection-factory="ConnectionFactory"
+ destination-type="queue"
+ destination-name="queue/A"
+ jndi-type="jboss"
+ jndi-URL="localhost"
+ message-selector="service='composeExampleService'"
+ >
+ <action class="org.jboss.soa.esb.message.listeners.MockComposer" process="composeEmptyMessage" />
+ </JmsGatewayExample>
+
+</GatewayListenerControllerExample>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,199 @@
+package org.jboss.soa.esb.listeners.message;
+
+import java.lang.reflect.*;
+
+import org.apache.log4j.Logger;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+
+/**
+ * Action Processing Pipeline.
+ * <p/>
+ * Runs a list of action classes on a message
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ */
+class ActionProcessingPipeline implements Runnable
+{
+
+ /**
+ * public constructor
+ * @param message Message - The initial message to be run through the whole action
+ * class chain
+ */
+ public ActionProcessingPipeline(Message message)
+ throws ConfigurationException
+ {
+ if (null==_message)
+ throw new IllegalArgumentException("Message must be not null");
+ _message = message;
+ _config = ActionUtils.getConfigTree(_message);
+ if (null==_config)
+ throw new IllegalArgumentException("Configuration needed for action classes");
+ _actionList = _config.getChildren(ListenerTagNames.ACTION_ELEMENT_TAG);
+ if (null==_actionList || _actionList.length<1)
+ throw new ConfigurationException("No actions in list");
+ }
+
+ /**
+ *
+ * @return Message - current Message of this action chain processor
+ */
+ public Message getMessage() { return _message; }
+
+ /**
+ * Implement Runnable Interface
+ * <p/>Uses reflection to instantiate action classes that must have a public constructor
+ * that takes a single ConfigTree as argument
+ * <p/>Requires each action class to have a public method that takes a Message and returns a Message
+ * <br/>Default name for it is 'process' but can optionally be defined in the 'process' attribute
+ * of the corresponding <action> element of the ConfigTree
+ * <p/>Each <action> element can optionally define a method (taking a Message argument) to be
+ * called upon successful completion of the action class (that step of the chain)
+ * <br/>Default name for it is 'process' but can optionally be defined in the 'process' attribute
+ * <p/>See actionClassException and actionClassFinishedOk
+ * */
+ public void run()
+ {
+ try
+ {
+ // Run the message through each ActionProcessor...
+ _currentIndex = -1;
+ for(ConfigTree oCurr : _actionList)
+ {
+ _currentIndex++;
+ String attrName = ListenerTagNames.ACTION_CLASS_TAG;
+ _currentAction = oCurr.getAttribute(attrName);
+
+ attrName = ListenerTagNames.PROCESS_METHOD_TAG;
+ String sProcessMethod = obtainAttribute(oCurr,attrName,attrName);
+
+ _currentClass = Class.forName(_currentAction);
+ Constructor oConst = _currentClass.getConstructor(new Class[] {ConfigTree.class});
+ _currentProcessor = oConst.newInstance(_config);
+ Method method = _currentClass.getMethod(sProcessMethod,new Class[] {Message.class});
+
+ // The processing result of each action feeds into the processing of the next action...
+ try
+ {
+ // copy currentObject in Message body to 'previous' currentObject
+ ActionUtils.copyCurrentToPrevious(_message);
+ Message next = (Message)method.invoke(_currentProcessor,new Object[] {_message} );
+
+ actionClassFinishedOk(oCurr);
+ if(next==null)
+ {
+ _logger.error(prematureTermination("returned <null> - Cannot continue"));
+ return;
+ }
+ }
+ catch (ClassCastException eCast)
+ {
+ // If action class returns non Message, log and abort chain
+ _logger.error(prematureTermination("returned a non Message Object)"));
+ return;
+ }
+ catch (Exception e)
+ {
+ // If action class threw exception, log and abort chain
+ actionClassException(oCurr,e);
+ return;
+ }
+ }
+ // notification of action chain end can be done with a no-operation action class
+ // with a proper ListenerPropertyNames.ACTION_NORMAL_COMPLETION_CALLBACK method
+ // Same idea when some interaction needed with the 'esb unaware' world
+ }
+ catch(ClassNotFoundException e)
+ { _logger.error(prematureTermination("action class is not in path"),e); }
+ catch(NoSuchMethodException e)
+ { _logger.error(prematureTermination("method not found"),e); }
+ catch(InstantiationException e)
+ { _logger.error(prematureTermination("cannot instantiate action class"),e); }
+ catch(InvocationTargetException e)
+ { _logger.error(prematureTermination("method not found"),e); }
+ catch(IllegalAccessException e)
+ { _logger.error(prematureTermination("unable to access method"),e); }
+ catch (IllegalArgumentException e) {}
+ }
+
+ protected String prematureTermination(String s)
+ {
+ return new StringBuilder("Premature termination of action processing pipeline ")
+ .append(getActionNames())
+ .append("]. ActionProcessor [").append(_currentAction)
+ .append("] ").append(s)
+ .toString()
+ ;
+ }
+
+ /**
+ * If 'current' action step was configured with a 'exceptionMethod' attribute
+ * that method will be called with a single argument of type Exception
+ * @param tree ConfigTree - where to look for the exceptionMetod attribute
+ * @param thr Exception - to be used in invocation to method (if found)
+ */
+ protected void actionClassException(ConfigTree tree, Exception thr)
+ {
+ thr.printStackTrace();
+ String sMethod = obtainAttribute(tree,ListenerTagNames.EXCEPTION_METHOD_TAG,null);
+ if (null!=sMethod)
+ try
+ {
+ Method method = _currentClass.getMethod(sMethod,new Class[] {Exception.class});
+ method.invoke(_currentProcessor,new Object[] {thr} );
+ }
+ catch (NoSuchMethodException e) {_logger.error(e); }
+ catch (InvocationTargetException e) {_logger.error(e); }
+ catch (IllegalAccessException e) {_logger.error(e); }
+ }
+
+ /**
+ * If 'current' action step was configured with an 'okMethod' attribute
+ * that method will be called with no arguments
+ * @param tree ConfigTree - where to look for the okMetod attribute
+ */
+ protected void actionClassFinishedOk(ConfigTree tree)
+ {
+ String sMethod = obtainAttribute(tree,ListenerTagNames.NORMAL_COMPLETION_METHOD_TAG,null);
+ if (null!=sMethod)
+ try
+ {
+ Method method = _currentClass.getMethod(sMethod,new Class[] {});
+ method.invoke(_currentProcessor,new Object[] {} );
+ }
+ catch (NoSuchMethodException e) {_logger.error(e); }
+ catch (InvocationTargetException e) {_logger.error(e); }
+ catch (IllegalAccessException e) {_logger.error(e); }
+ }
+
+ protected String[] getActionNames()
+ {
+ String[] sa = new String[_actionList.length];
+ int i1=0;
+ for (ConfigTree oCurr : _actionList)
+ sa[i1++]=obtainAttribute(oCurr,ListenerTagNames.ACTION_CLASS_TAG,"NO_CLASSNAME");
+ return sa;
+ }
+
+ private static String obtainAttribute(ConfigTree tree,String p_sAtt, String p_sDefault)
+ {
+ String sVal = tree.getAttribute(p_sAtt);
+ return (null != sVal) ? sVal : p_sDefault;
+ } // ________________________________
+
+ protected ConfigTree[] _actionList;
+ protected int _currentIndex;
+ protected String _currentAction;
+ protected Class _currentClass;
+ protected Object _currentProcessor;
+ protected Message _message;
+ protected ConfigTree _config;
+ protected Logger _logger = Logger.getLogger(this.getClass());
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,540 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners.message;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.command.CommandQueue;
+import org.jboss.internal.soa.esb.command.CommandQueueException;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.util.EPRManager;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.jboss.soa.esb.util.Util;
+import org.xml.sax.SAXException;
+
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
+/**
+ * Controlling class that will launch 'message aware' listener child threads for supported
+ * transport listener classes, as indicated in the configuration XML tree used in the constructor
+ * If you use the 'main' method, configuration file is expected in arg[0]
+ *
+ * <p />
+ * Can be launched as uppermost controller (it has a main(args) method)
+ * <p />
+ * Also implements Runnable, and can thus be launched in a child thread from an
+ * upper controlling process
+ * <p />
+ * Listens on a JMS queue (with an optional message selector) for commands (e.g.
+ * Quiesce, Reload Parameters, Set End Time, etc.)
+ * <p />
+ * Parameter reloading can also be set using the PARM_RELOAD_SECS attribute
+ * <p />
+ * End time for this instance can also be set using the PARM_END_TIME attribute
+ * <p />
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ */
+public class EsbListenerController implements Runnable {
+
+ private static Logger _logger = Logger.getLogger(EsbListenerController.class);
+
+ public static void main(String[] args) throws Exception {
+ EsbListenerController oProc = new EsbListenerController(args[0]);
+ oProc.run();
+ EsbListenerController.State oS = oProc.getState();
+
+ if (null != oS.getException()) {
+ _logger.error("EsbListenerController <" + args[0] + "> FAILED\n", oS
+ .getException());
+ }
+ System.exit(oS.getCompletionCode());
+ } // ________________________________
+
+ protected int m_iDfltReloadMillis = 180000 // default interval between
+ // parameter reloads
+ ;
+
+ public static final String PARM_RELOAD_SECS = "parameterReloadSecs";
+ public static final String PARM_END_TIME = "endTime";
+
+ // Attribute name that denotes listener class to be instantiated in a child
+ // thread
+ // This attribute is not in the root node but in first level child
+ // ConfigTrees
+ public static final String PARM_LISTENER_CLASS = "listenerClass";
+
+ private String m_sParmsName;
+ private ConfigTree m_oParms;
+
+ private HashMap<String, Object> m_oAtts;
+
+ /**
+ * Obtain a shallow copy of needed atributes in this object's last loaded
+ * parameter tree <p/>The local bject is cloned so child threads can use it
+ * as they choose to without interfering with the environment
+ * <p />
+ * Listener processes controlled by this object should keep a reference to
+ * this object at construction time, and not call this method again unless
+ * they specifically need updated values. Parameter reload could have
+ * happened since last call
+ *
+ * @return Map - a shallow copy of the attributes Map
+ */
+ @SuppressWarnings("unchecked")
+ public Map<String, Object> getControllerAttributes() {
+ return (Map<String, Object>) m_oAtts.clone();
+ }
+
+ private boolean m_bReloadRequested, m_bEndRequested;
+
+ private long m_lNextReload = Long.MAX_VALUE;
+
+ private long m_lEndTime = Long.MAX_VALUE;
+
+ public static final SimpleDateFormat s_oDateParse = new SimpleDateFormat(
+ "yyyyMMdd hh:mm:ss");
+
+ private State m_oState = null;
+
+ public State getState() {
+ return m_oState;
+ }
+
+ public static enum State {
+ Loading_parameters, Running, Shutting_down, Done_OK, Exception_thrown;
+ int m_iCompletionCode = 0;
+
+ Exception m_oException = null;
+
+ public int getCompletionCode() {
+ return m_iCompletionCode;
+ };
+
+ public Exception getException() {
+ return m_oException;
+ }
+ };
+
+ private CommandQueue commandQueue;
+ private static CommandQueue defaultCommandQueue = null;
+
+ /**
+ * No default constructor - only for child classes
+ */
+ protected EsbListenerController() { }
+
+ /**
+ * Construct a Listener Manager from the named repository based
+ * configuration.
+ *
+ * @param p_sParameterName
+ * Name of the Repository entry containing the configuration.
+ * @throws Exception
+ * Unable to load/use the named configuration.
+ */
+ public EsbListenerController(String p_sParameterName) throws Exception {
+ this(EsbListenerController.getListenerConfig(p_sParameterName));
+ m_sParmsName = p_sParameterName;
+ }
+
+ /**
+ * Construct a Listener Controller using the specified listener configuration.
+ *
+ * @param config
+ * The configuration.
+ * @throws Exception
+ * Unable to load/use the supplied configuration.
+ */
+ public EsbListenerController(ConfigTree config) throws Exception {
+ m_oParms = config;
+ m_oState = State.Loading_parameters;
+
+ try { checkParms(m_oParms); }
+ catch (Exception e)
+ {
+ String configSource = config.getAttribute("configSource");
+
+ m_oState = State.Exception_thrown;
+ m_oState.m_oException = e;
+ _logger.fatal("Listener configuration and startup error. Config Source: "
+ + (configSource != null ? configSource
+ : "unknown"), e);
+
+ throw e;
+ }
+ }
+
+ /**
+ * Load the named listener configuration from the configured parameter
+ * repository.
+ *
+ * @param reposParam
+ * The name of the repository entry containing the Listener
+ * configuration.
+ * @return Listener Configuration as {@link ConfigTree}.
+ * @throws IOException
+ * Unable to access the repository.
+ * @throws ParamRepositoryException
+ * Unable to access the configuration in the repository.
+ * @throws SAXException
+ * Unable to parse the configuration.
+ */
+ private static ConfigTree getListenerConfig(String reposParam)
+ throws IOException, ParamRepositoryException, SAXException {
+ String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
+ ConfigTree config = ConfigTree.fromXml(sXml);
+
+ config.setAttribute("configSource", "param-repository:" + reposParam);
+
+ return config;
+ }
+
+ /**
+ * Check to see if all needed parameters are there, and assign default
+ * values to some of them
+ *
+ * @param p_oP
+ * ConfigTree - Where to look for the mandatory/optional
+ * configuration attributes
+ * @throws Exception -
+ * If attributes are wrong or not enough for a proper runtime
+ * configuration
+ */
+ public void checkParms(ConfigTree p_oP) throws Exception {
+ // We've just loaded - set to false until next reload requested
+ m_bReloadRequested = false;
+ commandQueue = createCommandQueue(p_oP);
+
+ // Open the command queue...
+ if (null!=commandQueue)
+ commandQueue.open(p_oP);
+
+ // if PARM_RELOAD_SECS not set, and no command queue
+ // then reload every 10 minutes
+ // If there is a command queue, run until command is received
+ String sRldSecs = p_oP.getAttribute(PARM_RELOAD_SECS);
+ m_lNextReload = (null != sRldSecs)
+ ? System.currentTimeMillis() + 1000 * Long.parseLong(sRldSecs)
+ : (null == commandQueue)
+ ? Long.MAX_VALUE
+ : System.currentTimeMillis() + m_iDfltReloadMillis;
+
+ // if PARM_END_TIME not set try to run forever
+ // not a good practice if command queue is not set
+ // Expected date format is "yyyyMMdd hh:mm:ss"
+ String sEndT = p_oP.getAttribute(PARM_END_TIME);
+ m_lEndTime = (null == sEndT) ? Long.MAX_VALUE : s_oDateParse.parse(
+ sEndT).getTime();
+
+ // Read and initialise the action definitions...
+ ConfigTree actionConfig = p_oP.getFirstChild("Actions");
+ if(actionConfig == null) {
+ throw new ConfigurationException("No 'Actions' configuration.");
+ }
+ } // ________________________________
+
+ /**
+ * Factory method for creating the command queue.
+ * @param config EsbListenerController config.
+ * @return EsbListenerController CommandQueue instance.
+ */
+ private CommandQueue createCommandQueue(ConfigTree config) {
+ String commandQueueClass = config.getAttribute("command-queue-class");
+
+ if(commandQueueClass != null) {
+ try {
+ return (CommandQueue) Class.forName(commandQueueClass).newInstance();
+ } catch (Exception e) {
+ _logger.error("Failed to instantiate CommandQueue ["+ commandQueueClass + "]. Defaulting to no Command Queue", e);
+ }
+ }
+
+ return defaultCommandQueue;
+ }
+
+ /**
+ * Allows a default command queue to be set statically for all EsbListenerController instances.
+ * @param defaultCommandQueue The defaultCommandQueue to set.
+ */
+ public static void setDefaultCommandQueue(CommandQueue defaultCommandQueue) {
+ EsbListenerController.defaultCommandQueue = defaultCommandQueue;
+ }
+
+ /**
+ * Main execution loop <p/> Will continue to run until either <p/>a) run
+ * time is expired <p/>b) quiesce command is received in command queue
+ * <p/>For every child element that contains a PARM_LISTENER_CLASS
+ * attribute, this method will try to launch a child thread instantiating an
+ * object of that class, and will call it's run() method <p/>Once all child
+ * processes are trigered, the main thread will either <p/>1) wait for a
+ * message in the command queue (if one was configured) until next reload or
+ * end of run period expired <p/>or 2) Just sleep if there's no command
+ * queue to listen on
+ */
+ public void run() {
+ while (endNotRequested()) {
+ m_oState = State.Running;
+ for (ConfigTree oCurr : m_oParms.getAllChildren()) {
+ String sClass = oCurr.getAttribute(PARM_LISTENER_CLASS);
+ if (Util.isNullString(sClass))
+ continue;
+ tryToLaunchChildListener(oCurr, sClass);
+ }
+
+ waitForCmdOrSleep();
+
+ if (endRequested()) {
+ break;
+ }
+ if (m_sParmsName != null && timeToReload()) {
+ try {
+ m_oState = State.Loading_parameters;
+ _logger
+ .info("Reloading parameters _____________________________________________________");
+ ConfigTree oNew = EsbListenerController.getListenerConfig(m_sParmsName);
+ checkParms(oNew);
+ m_oParms = oNew;
+ } catch (Exception e) {
+ _logger.error("Failed to reload parameters"
+ + " - Continuing with cached version", e);
+ }
+ }
+ }
+ // m_oState = State.Shutting_down;
+
+ m_oState = State.Done_OK;
+ m_oState.m_iCompletionCode = 0;
+ _logger
+ .info("Finishing_____________________________________________________");
+
+ // Close the command queue...
+ try {
+ commandQueue.close();
+ } catch (CommandQueueException e) {
+ _logger.error("Error closing Command Queue.", e);
+ }
+ } // ________________________________
+
+ private void tryToLaunchChildListener(ConfigTree p_oP, String p_sClassName) {
+ try
+ {
+ Class oListener = Class.forName(p_sClassName);
+ Constructor oConst = oListener.getConstructor(new Class[] {this.getClass(), ConfigTree.class});
+ Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this,p_oP});
+ new Thread(oRun).start();
+ }
+ catch (Exception e)
+ {
+ _logger.error("Cannot launch <" + p_sClassName + ">\n", e);
+ }
+ } // ________________________________
+
+ long millisToWait() {
+ return Math.min(m_lNextReload, m_lEndTime) - System.currentTimeMillis();
+ } // ________________________________
+
+ private void waitForCmdOrSleep() {
+ long lToGo = millisToWait();
+
+ if (null == commandQueue) {
+ _logger.debug("About to sleep " + lToGo);
+ // No command queue nor topic - Just sleep until time
+ // exhausted, or thread interrupted
+ try {
+ if (lToGo > 0)
+ Thread.sleep(lToGo);
+ } catch (InterruptedException e) {
+ m_lEndTime = 0; // mark as end requested and return
+ }
+ return;
+ }
+
+ // Wait for commands until time exhausted or command received
+ // Note that received commands might change time variables (reload/end)
+ // that's why time to go is recalculated on each cycle
+ while ((lToGo = millisToWait()) > 0) {
+ try {
+ _logger.info("Waiting for command ... timeout=" + lToGo + " millis");
+
+ String oM = commandQueue.receiveCommand(lToGo);
+ if (null == oM) {
+ return;
+ }
+ processCommand(oM);
+ if (endRequested() || timeToReload()) {
+ break;
+ }
+ } catch (CommandQueueException eJ) {
+ _logger.info("receive on command queue failed", eJ);
+ }
+ }
+ } // ________________________________
+
+ /**
+ * Processes the command that has been received in the command queue (or
+ * topic) <p/>m_bEndRequested, m_bReloadRequested, and m_lEndTime could be
+ * changed
+ *
+ * <p/> <p/><TABLE border="1"> <COLGROUP> <COL width="200"/> <COL
+ * width="400"/> </COLGROUP>
+ * <TR>
+ * <TD align="center">message text</TD>
+ * <TD align="center">effect</TD>
+ * </TR>
+ * <TR>
+ * <TD>shutdown*</TD>
+ * <TD>End time will be immediately set to 'now' - quiesce process will
+ * start - Child threads will be allowed to finish normally</TD>
+ * </TR>
+ * <TR>
+ * <TD>reload param*</TD>
+ * <TD>Parameters will be immediately reloaded, and listener reconfigured
+ * with new values</TD>
+ * </TR>
+ * <TR>
+ * <TD>endTime yyyyMMdd hh:mm:ss</TD>
+ * <TD>End time will be set to new value. If hh:mm:ss is not supplied =>
+ * end of day assumed (23:59:59)</TD>
+ * </TR>
+ * </TABLE> * startsWith() <p/>
+ *
+ * @param p_oMsg
+ * Message received from the command queue.
+ *
+ */
+ private void processCommand(String sTxt) {
+ if (null == sTxt)
+ return;
+
+ String sLow = sTxt.trim().toLowerCase();
+ if (sLow.startsWith("shutdown")) {
+ m_bEndRequested = true;
+ _logger.info("Shutdown has been requested");
+ return;
+ }
+ if (sLow.startsWith("reload param")) {
+ m_bReloadRequested = true;
+ _logger
+ .info("Request for parameter reload has been received");
+ return;
+ }
+ String[] sa = sLow.split("\\s+");
+ if (sa.length > 1 && "endtime".equals(sa[0])) {
+ try {
+ String sDate = sa[1];
+ String sTime = (sa.length < 3 || null == sa[2]) ? "23:59:59"
+ : sa[2];
+ Date oEnd = s_oDateParse.parse(sDate + " " + sTime);
+ _logger.info("New end date set to : " + oEnd);
+ m_lEndTime = oEnd.getTime();
+ } catch (Exception eDat) {
+ _logger.info("Problems with endTime command", eDat);
+ }
+ }
+ } // ________________________________
+
+ /**
+ * Accessor to determine if execution time is expired or shutdown requested
+ *
+ * @return boolean if processing has to stop (all child threads will be
+ * allowed to finish)
+ */
+ public boolean endRequested() {
+ return m_bEndRequested || System.currentTimeMillis() >= m_lEndTime;
+ }
+
+ /**
+ * Accessor to determine if execution time is not expired, and no shutdown
+ * request received
+ *
+ * @return boolean - true if run time has not expired and quiesce has not
+ * been requested
+ */
+ public boolean endNotRequested() {
+ return !endRequested();
+ }
+
+ /**
+ * Provide a common accessor to determine if parameters have to be reloaded
+ * <p/> For child threads this means thread execution has to end
+ * </p>
+ * Child processes should only call this method when they are idle (as
+ * opposed to in the middle of executing a unit of work)
+ *
+ * @return boolean - true if it's time to reload parameters
+ */
+ public boolean timeToReload() {
+ return m_bReloadRequested
+ || System.currentTimeMillis() >= m_lNextReload;
+ }
+
+ /**
+ * Helper accessor for child processes that provides info to determine if
+ * they can continue with yet another execution cycle
+ *
+ * @return boolean - true if runtime is not expired and not time yet to
+ * reload parameters
+ */
+ public boolean continueLooping() {
+ return (endNotRequested() && !timeToReload());
+ } // ________________________________
+
+ private static EPRManager getEprManager()
+ {
+ PropertyManager manager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE);
+ String sDir = manager.getProperty(Environment.REGISTRY_FILE_HELPER_DIR,".");
+ return EPRManager.getInstance(sDir);
+ }
+
+ public void register (String name, EPR address)
+ {
+ try { getEprManager().saveEPR(name,address); }
+ catch (IOException e)
+ {
+ _logger.fatal("Cannot register service",e);
+ }
+ } // ________________________________
+
+ public void unRegister (String name)
+ {
+ try { getEprManager().removeEPR(name); }
+ catch (IOException e)
+ {
+ _logger.fatal("Cannot un-register service",e);
+ }
+ } // ________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,233 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners.message;
+
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.TopicSession;
+import javax.naming.Context;
+
+import org.apache.log4j.Logger;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.AppServerContext;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+
+/**
+ * Esb Message aware JMS queue listener.
+ * <p/> Expects an Object message whose getObject() method returns an org.jboss.soa.esb.message.Message
+ * <br/>Clones the 'static' ConfigTree with which this listener was created, and stores the cloned tree
+ * inside the Message (to enable all actions in the chain to use the configuration)
+ * <br/>Instantiates and runs a new ActionProcessingPipeline on the received esb Message (augmented with
+ * ConfigTree) that will in turn instantiate and run all action classes in the chain
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ */
+
+public class JmsQueueListener implements Runnable
+{
+ /**
+ * public constructor
+ * @param controller EsbListenerController - the controlling process
+ * @param config ConfigTree - Containing 'static' configuration for this instance
+ * @throws Exception
+ */
+ public JmsQueueListener(EsbListenerController controller, ConfigTree config)
+ throws ConfigurationException
+ {
+ _controller = controller;
+ _config = config;
+ _iSleepForRetry = 3;
+ checkMyParms();
+ } // _______________________________
+
+ /**
+ * Loops until controlling process determines
+ * <br/>Waits for JMS Object messages containing ESB messages
+ * <br/>When one is received, instantiates an action processing pipeline to process it
+ * <br/>Pipeline is started in new Thread
+ */
+ public void run()
+ {
+ _controller.register(_eprName,_epr);
+
+ while (_controller.continueLooping())
+ {
+ org.jboss.soa.esb.message.Message message = receiveEsbMessage(_controller.millisToWait());
+ if (null!=message)
+ {
+ ActionUtils.setConfigTree(message,_config);
+ ActionProcessingPipeline chain = null;
+
+ try { chain = new ActionProcessingPipeline(message); }
+ catch (IllegalArgumentException e)
+ { _logger.error(e); continue; }
+ catch (ConfigurationException e)
+ { _logger.error(e); continue; }
+
+ // TODO Take care of thread pooling and (eventually) maximum child threads
+ new Thread(chain).start();
+ }
+ }
+
+ _controller.unRegister(_eprName);
+ cleanup();
+ } // _______________________________
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ *
+ * @throws Exception -
+ * if mandatory atts are not right or actionClass not in
+ * classpath
+ */
+ protected void checkMyParms() throws ConfigurationException
+ {
+ // Default value of obtainAttribute is null - Exception will be thrown
+ String sQueue = obtainAttribute(JMSEpr.DESTINATION_NAME_TAG, null);
+
+ _eprName = obtainAttribute(ListenerTagNames.SERVICE_NAME_TAG,null);
+
+ // No problem if selector is null - everything in queue will be returned
+ _sSelector = _config.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG);
+
+ _oQconn = null;
+ _oQsess = null;
+ _oQueue = null;
+
+ String sJndiType = obtainAttribute (JMSEpr.JNDI_TYPE_TAG ,"jboss");
+ String sJndiURL = obtainAttribute (JMSEpr.JNDI_URL_TAG ,"localhost");
+ Context oJndiCtx = AppServerContext.getServerContext(sJndiType,sJndiURL);
+
+ String sFactClass = obtainAttribute(JMSEpr.CONNECTION_FACTORY_TAG, "ConnectionFactory");
+ _epr = new JMSEpr(JMSEpr.QUEUE_TYPE,sQueue,sFactClass
+ ,sJndiType,sJndiURL,_sSelector);
+
+ Exception thrown = null;
+ try
+ {
+ Object tmp = oJndiCtx.lookup(sFactClass);
+ QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+
+ _oQconn = qcf.createQueueConnection();
+ _oQueue = (Queue) oJndiCtx.lookup(sQueue);
+ _oQsess = _oQconn.createQueueSession(false,TopicSession.AUTO_ACKNOWLEDGE);
+ _oQconn.start();
+ _receiver = _oQsess.createReceiver(_oQueue, _sSelector);
+ }
+ catch (javax.naming.NamingException e) { thrown = e; }
+ catch (JMSException e) { thrown = e; }
+ throw new ConfigurationException(thrown);
+
+ } // ________________________________
+
+ protected org.jboss.soa.esb.message.Message receiveEsbMessage(long millis)
+ {
+ javax.jms.Message jmsMessage = null;
+ try { jmsMessage = _receiver.receive(millis); }
+ catch (JMSException oJ)
+ {
+ _logger.error("JMS error on receive. Attempting JMS Destination reconnect.", oJ);
+ for (int i1 = 0; i1 < 3; i1++)
+ // try to reconnect to the queue
+ try { checkMyParms(); }
+ catch (Exception e)
+ {
+ _logger.error("Reconnecting to Queue", e);
+ try { Thread.sleep(_iSleepForRetry); }
+ catch (InterruptedException e1)
+ { // Just return after logging
+ _logger.error("Unexpected thread interupt exception.", e);
+ return null;
+ }
+ }
+ }
+ if (null == jmsMessage)
+ return null;
+
+ if (!(jmsMessage instanceof ObjectMessage))
+ {
+ _logger.error("Unsupported JMS message type: " + jmsMessage.getClass().getName());
+ return null;
+ }
+ try
+ {
+ return (org.jboss.soa.esb.message.Message)((ObjectMessage)jmsMessage).getObject();
+ }
+ catch (JMSException e1)
+ { _logger.error("Failed to read Serialized Object from JMS message.", e1);
+ return null;
+ }
+ catch (ClassCastException e2)
+ { _logger.error("Object in JMS message is not a org.jboss.soa.esb.message.Message", e2);
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#close()
+ */
+
+ protected void cleanup()
+ {
+ if (null != _oQsess)
+ try { _oQsess.close(); }
+ catch (Exception e1) {/* Tried my best - Just continue */ }
+ if (null != _oQconn)
+ try { _oQconn.close(); }
+ catch (Exception e2) {/* Tried my best - Just continue */ }
+ }
+
+ protected String obtainAttribute(String p_sAtt, String p_sDefault)
+ throws ConfigurationException
+ {
+ String sVal = _config.getAttribute(p_sAtt);
+ if ((null == sVal) && (null == p_sDefault))
+ throw new ConfigurationException("Missing or invalid <" + p_sAtt + "> attribute");
+
+ return (null != sVal) ? sVal : p_sDefault;
+ } // ________________________________
+
+ protected EsbListenerController _controller;
+ protected ConfigTree _config;
+ protected String _eprName;
+ protected JMSEpr _epr;
+ protected MessageConsumer _receiver;
+ protected boolean _bError = false;
+ protected QueueConnection _oQconn;
+ protected QueueSession _oQsess;
+ protected Queue _oQueue;
+ protected String _sSelector;
+ protected int _iSleepForRetry;
+
+ protected static transient Logger _logger = Logger.getLogger(JmsQueueListener.class);
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/easier2ReadExample.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/easier2ReadExample.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/easier2ReadExample.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,36 @@
+<EsbListenerControllerExample
+ parameterReloadSecs="180"
+>
+ <ListenJmsQueueExample
+ epr-name="myEprMnemonicName"
+ listenerClass="org.jboss.soa.esb.message.listeners.JmsQueueListener"
+ connection-factory="ConnectionFactory"
+ destination-type="queue"
+ destination-name="queue/A"
+ jndi-type="jboss"
+ jndi-URL="localhost"
+ message-selector="service='handOfGod'"
+ >
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction" />
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction" process="process222" />
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction"
+ process="noOperation" okMethod="endOfChainNotification"/>
+
+ <NotificationList type="OK">
+ <target class="NotifyFiles">
+ <file URI="file:///E:/tmp/jbossEsb/notifyDir/GpListenerExample.notifOK"
+ append="true"
+ />
+ </target>
+ </NotificationList>
+
+ <NotificationList type="err">
+ <target class="NotifyFiles">
+ <file URI="file:///E:/tmp/jbossEsb/notifyDir/GpListenerExample.notifErr"
+ append="true"
+ />
+ </target>
+ </NotificationList>
+ </ListenJmsQueueExample>
+
+</EsbListenerControllerExample>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/example.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/example.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/message/example.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,44 @@
+<EsbListenerControllerExample
+ parameterReloadSecs="180"
+>
+ <ListenJmsQueueExample
+ service-name="myServiceName"
+ listenerClass="org.jboss.soa.esb.message.listeners.JmsQueueListener"
+ connection-factory="ConnectionFactory"
+ destination-type="queue"
+ destination-name="queue/A"
+ jndi-type="jboss"
+ jndi-URL="localhost"
+ message-selector="service='maradona'"
+ >
+ <!-- next line will call (default) process(Message) method with no notification for step -->
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction" />
+ <!-- next line will call process222(Message) method with no notification for step -->
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction" process="process222" />
+ <!-- next line will call (default) process(Message) - on success=>invoke myOkMethod1 -->
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction" okMethod="myOkMethod1" />
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction" process="process222"
+ okMethod="myMethod2" />
+ <!-- next line would be useful to notify end of action chain process=noOperation (see class)-->
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction" process="noOperation" />
+ <!-- example of a method that will always throw an Exception -->
+ <action class="org.jboss.soa.esb.actions.templates.MockMessageAction" process="justThrow" exceptionMethod="exceptionCallback1"/>
+
+ <NotificationList type="OK">
+ <target class="NotifyFiles">
+ <file URI="file:///E:/tmp/jbossEsb/notifyDir/GpListenerExample.notifOK"
+ append="true"
+ />
+ </target>
+ </NotificationList>
+
+ <NotificationList type="err">
+ <target class="NotifyFiles">
+ <file URI="file:///E:/tmp/jbossEsb/notifyDir/GpListenerExample.notifErr"
+ append="true"
+ />
+ </target>
+ </NotificationList>
+ </ListenJmsQueueExample>
+
+</EsbListenerControllerExample>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractListener.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractListener.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,293 @@
+/*
+ * 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.old;
+
+import java.util.Arrays;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionDefinition;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+ * Base abstract listener implementation.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public abstract class AbstractListener implements Runnable {
+
+ /**
+ * Name constant def for the Message attachemnt carrying the list of actions to be applied to the
+ * incomming message. This allows the configured processing pipeline to be overridden by the Message
+ * producer.
+ */
+ public static final String MESSAGE_PROCESSING_ACTIONS_LIST = "MESSAGE_PROCESSING_ACTIONS_LIST";
+
+ // You can override these values at constructor time of your
+ // derived class after calling super(GpListener,ConfigTree)
+ protected int m_iSleepForThreads = 3000; // default sleep if no threads available
+ protected int m_iUpperThreadLimit = 10; // just in case - override if you wish
+
+ protected int m_iQthr = 0, m_iMaxThr;
+
+ protected ThreadGroup m_oThrGrp = null;
+ protected Logger logger;
+ protected GpListener m_oDad;
+ protected ConfigTree listenerConfig;
+ protected String[] m_oActions;
+ protected ActionDefinitionFactory m_oActionDefinitionFactory;
+ protected MessageFactory m_oMsgFactory;
+
+ protected AbstractListener(GpListener p_oDad, ConfigTree p_oParms, ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+
+ logger = Logger.getLogger(this.getClass());
+ m_oDad = p_oDad;
+ listenerConfig = p_oParms.cloneObj();
+ m_oActionDefinitionFactory = actionDefinitionFactory;
+ m_oMsgFactory = MessageFactory.getInstance();
+ m_oThrGrp = new ThreadGroup(listenerConfig.getName());
+
+ String sAtt = GpListener.obtainAtt(listenerConfig, GpListener.PARM_ACTIONS, "");
+ if(!sAtt.trim().equals("")) {
+ m_oActions = sAtt.split(",");
+ }
+
+ sAtt = GpListener.obtainAtt(listenerConfig, GpListener.PARM_MAX_THREADS, "1");
+ int iMax = Integer.parseInt(sAtt);
+ m_iMaxThr = Math.min(iMax, m_iUpperThreadLimit);
+ } // __________________________________
+
+ /**
+ * Implement run method for this Runnable <p/> Will continue to run until
+ * controlling class (ref in m_oDad) indicates no more looping allowed for
+ * all child classes <p/> This condition will not prevent child processes to
+ * finish normally
+ */
+ public void run() {
+ while (m_oDad.continueLooping()) {
+ Object[] processList = receive();
+ if (null==processList) {
+ try { Thread.sleep(500); }
+ catch(InterruptedException e) {/* ok do nothing */}
+ } else {
+ for (Object currentObj : processList) {
+ if (m_iQthr >= m_iMaxThr) {
+ logger.info("Waiting for available threads...(max=" + m_iMaxThr + ")");
+ try {
+ Thread.sleep(m_iSleepForThreads);
+ } catch (InterruptedException e) {
+ return;
+ }
+ break;
+ }
+
+ // Spawn a thread and push the message message through the pipeline...
+ ActionProcessingPipeline runner = new ActionProcessingPipeline(currentObj);
+ new Thread(runner).start();
+ incThreads();
+ }
+ }
+ }
+
+ // Wait for all the processing pipelines to complete before closing the listener and existing...
+ while(m_iQthr > 0) {
+ logger.info("Waiting for all processing pipelines to complete.");
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ logger.warn("Thread interrupted while waiting for all processing pipelines to complete.", e);
+ }
+ }
+
+ logger.info("All processing pipelines complete. Closing listener now.");
+
+ close();
+ }
+
+ /**
+ * Receive message from underlying channel implementation.
+ * <p/>
+ * Implementations must perform a blocking receive.
+ * @return An array of Objects received on the channel.
+ */
+ protected abstract Object[] receive();
+
+ /**
+ * Called on the listener implementation when pipeline processing error has occured.
+ * @param initialMsg The message that was initialy supplied to the pipeline.
+ * @param processor The processor that raised the error. Can be null where the error was raised before
+ * pipeline processing of the message.
+ * @param error The error. Can be null.
+ */
+ protected abstract void processingError(Object initialMsg, ActionProcessor processor, Throwable error);
+
+ /**
+ * Called on the listener implementation when pipeline processing of a message is complete.
+ * @param initialMsg The message that was initialy supplied to the pipeline.
+ */
+ protected abstract void processingComplete(Object initialMsg);
+
+ /**
+ * Close the listener implemenation.
+ * <p/>
+ * Allows the listener to perform relevant close/cleanup tasks.
+ */
+ protected abstract void close();
+
+ /**
+ * Increment the active thread count.
+ */
+ private void incThreads() {
+ m_iQthr++;
+ }
+
+ /**
+ * Decrement the active thread count.
+ */
+ private void decThreads() {
+ m_iQthr--;
+ }
+
+ /**
+ * Action Processing Pipeline.
+ * <p/>
+ * Runs the actions in a listeners "actions" config on a message payload message received
+ * by the listener implementation.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+ private class ActionProcessingPipeline implements Runnable {
+
+ private Object initialObject;
+
+ /**
+ * Private constructor.
+ * @param pMessage The inital processing target message.
+ */
+ private ActionProcessingPipeline(Object obj) {
+ initialObject = obj;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ String currentAction = null;
+ ActionProcessor currentProcessor = null;
+
+ try {
+ Message message;
+ String[] actions;
+
+ if(initialObject instanceof Message) {
+ message = (Message)initialObject;
+ } else {
+ message = m_oMsgFactory.getMessage();
+ ActionUtils.setTaskObject(message,initialObject);
+ }
+
+ actions = getActions(message);
+
+ // Run the message through each ActionProcessor...
+ for(String action : actions) {
+ ActionDefinition actionDefinition;
+
+ currentAction = action.trim();
+ actionDefinition = m_oActionDefinitionFactory.getInstance(currentAction);
+ if(actionDefinition == null) {
+ throw new java.lang.IllegalStateException("Bad Listener Configuration. No 'Actions/Action' definition for action [" + currentAction + "].");
+ }
+
+ // The processing result of each action feeds into the processing of the next action...
+ currentProcessor = actionDefinition.getProcessor();
+ try {
+ ActionUtils.copyCurrentToPrevious(message);
+ message = currentProcessor.process(message);
+ } catch (Exception e) {
+ GpListener.notifyError(listenerConfig, e, currentProcessor.getErrorNotification(message));
+ throw e;
+ }
+
+ if(message == null && action != m_oActions[m_oActions.length - 1]) {
+ String exceptionMessage = "Premature termination of action processing pipeline [" + Arrays.asList(m_oActions) + "]. ActionProcessor [" + currentProcessor.getClass().getName() + "] returned a null message result on processing of action [" + currentAction + "].";
+ processingError(initialObject, currentProcessor, new ActionProcessingException(exceptionMessage));
+ logger.warn(exceptionMessage);
+ return;
+ }
+ // Notify on all processors. May want to do this differently in the future i.e. more selectively ...
+ GpListener.notifyOK(listenerConfig, currentProcessor.getOkNotification(message));
+
+ // Setup the message for processing by the next processor...
+ if(message != null) {
+ message.getBody().remove(ActionUtils.BEFORE_ACTION);
+ }
+ }
+
+ processingComplete(initialObject);
+ } catch(Throwable thrown) {
+ processingError(initialObject, currentProcessor, thrown);
+ logger.error("Premature termination of action processing pipeline [" + (m_oActions != null?Arrays.asList(m_oActions):"") + "]. Action [" + currentAction + "] threw an exception.", thrown);
+ } finally {
+ // Decrement the active thread count for the listener on completion...
+ decThreads();
+ }
+ }
+
+ /**
+ * Get the list of actions to be applied to the supplied message.
+ * @param message The message to be processed.
+ * @return The set of processing actions to be performed on the message.
+ * @throws ActionProcessingException Invalid actions list attachment setting.
+ */
+ private String[] getActions(Message message) throws ActionProcessingException {
+ // Check is there an attachment specifying an override pipeline config...
+ Object overrideActionsAttachment = message.getAttachment().get(MESSAGE_PROCESSING_ACTIONS_LIST);
+ if(overrideActionsAttachment != null) {
+ if(overrideActionsAttachment instanceof String) {
+ String overrideActions = (String)overrideActionsAttachment;
+
+ if(overrideActions.trim().equals("")) {
+ throw new ActionProcessingException("Message attachement [" + MESSAGE_PROCESSING_ACTIONS_LIST + "] was specified but with an empty value. Aborting message processing.");
+ }
+
+ return overrideActions.split(",");
+ } else {
+ throw new ActionProcessingException("Message attachement [" + MESSAGE_PROCESSING_ACTIONS_LIST + "] must be of type java.lang.String. Received [" + overrideActionsAttachment.getClass().getName() + "]. Aborting message processing.");
+ }
+ } else {
+ // Otherwise use the actions configured on the listener...
+ if(m_oActions == null || m_oActions.length == 0) {
+ throw new ActionProcessingException("No actions configuration specified either on the listener or as a Message attachement [" + MESSAGE_PROCESSING_ACTIONS_LIST + "]. Aborting message processing.");
+ }
+ return m_oActions;
+ }
+ }
+ }
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractPoller.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractPoller.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/AbstractPoller.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,111 @@
+/*
+ * 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.old;
+
+import java.util.List;
+
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Abstract Polling Listener.
+ * <p/>
+ * Polling listeners are listener implementations that periodically poll for message objects
+ * that require processing. This type of listener implementation is required where the underlying
+ * message channel doesn't support a blocking receive operation.
+ *
+ * @author Esteban
+ */
+public abstract class AbstractPoller extends AbstractListener {
+
+ // You can override these values at constructor time of your
+ // derived class after calling super(GpListener,ConfigTree)
+ protected int m_iMinPollMillis = 3000 // minimum polling interval
+ , m_iDfltPollMillis = 20000 // default polling interval
+ ;
+
+ public static final String PARM_POLL_LTCY = "pollLatencySecs";
+
+ protected int m_iPollMillis;
+
+ /**
+ * Construct an abstract polling listener.
+ * @param commandListener The command listener.
+ * @param listenerConfig The configuration for this polling listener.
+ * @param actionDefinitionFactory The action definition factory for the bus.
+ * @throws Exception
+ */
+ protected AbstractPoller(GpListener commandListener, ConfigTree listenerConfig, ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+ super(commandListener, listenerConfig, actionDefinitionFactory);
+
+ String sAtt = listenerConfig.getAttribute(PARM_POLL_LTCY);
+ m_iPollMillis = (null == sAtt) ? m_iDfltPollMillis : 1000 * Integer.parseInt(sAtt);
+ if (m_iPollMillis < m_iMinPollMillis) {
+ m_iPollMillis = m_iMinPollMillis;
+ }
+ }
+
+ /**
+ * Polling listener receive implementation.
+ * @return An array of objects polled from the concrete Poller implementation.
+ */
+ protected Object[] receive() {
+ while (m_oDad.continueLooping()) {
+ List<Object> olPending = pollForCandidates();
+
+ if (olPending == null || olPending.isEmpty()) {
+ try {
+ Thread.sleep(m_iPollMillis);
+ } catch (InterruptedException e) {
+ logger.error("Unexpected thread interupt exception. Not terminating blocking receive!!", e);
+ }
+ continue;
+ } else {
+ Object[] objForProcessing = new Object[olPending.size()];
+
+ // Preprocess all the message objects.
+ // TODO: I really think this is no longer required or a good idea!!
+ for(int i = 0; i < olPending.size(); i++) {
+ objForProcessing[i] = preProcess(olPending.get(i));
+ }
+ return objForProcessing;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Poll for message objects.
+ * @return A list of message objects, or an empty list if there are no message objects.
+ */
+ protected abstract List<Object> pollForCandidates();
+
+ /**
+ * Preprocess the message object before returning for pipeline processing.
+ * @param message Message object for preprocessing.
+ * @return The preprocessed message object, or the supplied message unmodified.
+ */
+ protected abstract Object preProcess(Object message);
+ // TODO: Is this "preprocessing" step needed now that we have processing pipelines on listeners???
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/DirectoryPoller.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/DirectoryPoller.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/DirectoryPoller.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,263 @@
+/*
+* 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.old;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.Util;
+
+public class DirectoryPoller extends AbstractPoller
+{
+ public static final String FILE_INPUT_DIR = "inputDirURI";
+ public static final String FILE_INPUT_SFX = "inputSuffix";
+ public static final String FILE_WORK_SFX = "workSuffix";
+ public static final String FILE_ERROR_DIR = "errorDirURI";
+ public static final String FILE_ERROR_SFX = "errorSuffix";
+ public static final String FILE_POST_DIR = "postDirURI";
+ public static final String FILE_POST_SFX = "postSuffix";
+ public static final String FILE_POST_DEL = "postDelete";
+
+ public DirectoryPoller(GpListener p_oDad, ConfigTree p_oParms, ActionDefinitionFactory actionDefinitionFactory) throws Exception
+ {
+ super(p_oDad, p_oParms, actionDefinitionFactory);
+ checkMyParms();
+ } //__________________________________
+
+
+ protected File m_oInpDir ,m_oErrorDir ,m_oPostDir;
+ protected FileFilter m_oFFilt;
+ protected String m_sInpSfx ,m_sWrkSfx ,m_sErrSfx ,m_sPostSfx;
+ protected boolean m_bPostDel;
+
+ /**
+ *
+ * @param inputObject Object - Must be a File representing the file that has to be processed
+ * @return Object - an array of 3 Files containing:
+ * <p/>[0] renamed file (workSuffix appended to input file name)
+ * <p/>[1] target file name in case actionClass is unable to complete successfuly
+ * <p/>[2] target file name in case actionClass finishes successfuly
+ */
+ @Override
+ public Object preProcess(Object inputObject)
+ {
+ if (!(inputObject instanceof File)) {
+ return null;
+ }
+
+ File inputFile = (File)inputObject;
+ WorkingFile workingFile = new WorkingFile(inputFile.getParentFile(), inputFile.getName() + m_sWrkSfx);
+
+ if (!inputFile.renameTo(workingFile)) {
+ return null;
+ }
+
+ workingFile.postDelete = m_bPostDel;
+ workingFile.inputFile = inputFile;
+ workingFile.errorFile = new File (m_oErrorDir ,inputFile.getName()+m_sErrSfx);
+ workingFile.outputFile = new File (m_oPostDir ,inputFile.getName()+m_sPostSfx);
+
+ return workingFile;
+ } //________________________________
+
+ @Override
+ protected List<Object> pollForCandidates()
+ {
+ File[] oaF = m_oInpDir.listFiles(m_oFFilt);
+ return Arrays.asList((Object[])oaF);
+ } //________________________________
+
+ private void checkMyParms() throws Exception
+ {
+ // INPUT directory and suffix (used for FileFilter)
+ String sInpDir = GpListener.obtainAtt(listenerConfig,FILE_INPUT_DIR,null);
+ m_oInpDir = getFile(sInpDir);
+ seeIfOkToWorkOnDir(m_oInpDir);
+
+ m_sInpSfx = GpListener.obtainAtt(listenerConfig,FILE_INPUT_SFX,null);
+ m_sInpSfx = m_sInpSfx.trim();
+ if (m_sInpSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_INPUT_SFX+" attribute");
+ m_oFFilt = new FileEndsWith(m_sInpSfx);
+
+ // WORK suffix (will rename in input directory)
+ m_sWrkSfx = GpListener.obtainAtt(listenerConfig,FILE_WORK_SFX,".esbWork").trim();
+ if (m_sWrkSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_WORK_SFX+" attribute");
+ if (m_sInpSfx.equals(m_sWrkSfx))
+ throw new Exception("Work suffix must differ from input suffix <"+m_sWrkSfx+">");
+
+ // ERROR directory and suffix (defaults to input dir and ".esbError" suffix)
+ String sErrDir = GpListener.obtainAtt(listenerConfig,FILE_ERROR_DIR,sInpDir);
+ m_oErrorDir = getFile(sErrDir);
+ seeIfOkToWorkOnDir(m_oErrorDir);
+
+ m_sErrSfx = GpListener.obtainAtt(listenerConfig,FILE_ERROR_SFX,".esbError").trim();
+ if (m_sErrSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_ERROR_SFX+" attribute");
+ if (m_oErrorDir.equals(m_oInpDir) && m_sInpSfx.equals(m_sErrSfx))
+ throw new Exception("Error suffix must differ from input suffix <"+m_sErrSfx+">");
+
+
+ // Do users wish to delete files that were processed OK ?
+ String sPostDel = GpListener.obtainAtt(listenerConfig,FILE_POST_DEL,"false").trim();
+ m_bPostDel = Boolean.parseBoolean(sPostDel);
+ if (m_bPostDel)
+ return;
+
+ // POST (done) directory and suffix (defaults to input dir and ".esbDone" suffix)
+ String sPostDir = GpListener.obtainAtt(listenerConfig,FILE_POST_DIR,sInpDir);
+ m_oPostDir = getFile(sPostDir);
+ seeIfOkToWorkOnDir(m_oPostDir);
+ m_sPostSfx = GpListener.obtainAtt(listenerConfig,FILE_POST_SFX,".esbDone").trim();
+ if (m_oPostDir.equals(m_oInpDir))
+ { if (m_sPostSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_POST_SFX+" attribute");
+ if (m_sPostSfx.equals(m_sInpSfx))
+ throw new Exception("Post process suffix must differ from input suffix <"+m_sPostSfx+">");
+ }
+
+ } //________________________________
+
+ private File getFile(String file) {
+ try {
+ return new File(new URI(file));
+ } catch(Exception e) {
+ return new File(file);
+ }
+ }
+
+ protected void seeIfOkToWorkOnDir (File p_oDir) throws Exception
+ {
+ if (! p_oDir.exists())
+ throw new Exception ("Directory "+p_oDir.toString()+" not found");
+ if (!p_oDir.isDirectory())
+ throw new Exception(p_oDir.toString()+" is not a directory");
+ if (!p_oDir.canRead())
+ throw new Exception("Can't read directory "+p_oDir.toString());
+ if (! p_oDir.canWrite())
+ throw new Exception ("Can't write/rename in directory "+p_oDir.toString());
+ } //________________________________
+
+
+ private class FileEndsWith implements FileFilter
+ {
+ String m_sSuffix;
+ FileEndsWith(String p_sEnd) throws Exception
+ {
+ m_sSuffix = p_sEnd;
+ if (Util.isNullString(m_sSuffix))
+ throw new Exception("Must specify file extension");
+ } //______________________________
+
+ public boolean accept(File p_f)
+ { return (p_f.isFile())
+ ? p_f.toString().endsWith(m_sSuffix)
+ : false;
+ } //______________________________
+ } //____________________________________________________
+
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#close()
+ */
+ @Override
+ protected void close() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingError(java.lang.Object, org.jboss.soa.esb.actions.ActionProcessor, java.lang.Throwable)
+ */
+ @Override
+ protected void processingError(Object currentObject, ActionProcessor processor, Throwable error) {
+
+ if (null!=currentObject)
+ { WorkingFile workingFile = (WorkingFile) currentObject;
+ workingFile.renameToError();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingComplete(java.lang.Object)
+ */
+ @Override
+ protected void processingComplete(Object currentObject) {
+ WorkingFile workingFile = (WorkingFile) currentObject;
+
+ // Delete or rename the file...
+ if (workingFile.postDelete) {
+ workingFile.delete();
+ } else {
+ workingFile.renameToOutputFile();
+ }
+ }
+
+ /**
+ * Working file.
+ * <p/>
+ * Once the directory poller picks up on an input file, it immediately renames it to a working file
+ * in order to avoid a situation where the file gets processed again.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+ public static class WorkingFile extends File {
+ private static final long serialVersionUID = 1L;
+
+ private boolean postDelete;
+ public boolean isPostDelete() { return postDelete; }
+
+ private File inputFile, errorFile, outputFile;
+
+ public WorkingFile(String filename) {
+ super(filename);
+ }
+
+ public WorkingFile(File parentFile, String filename) {
+ super(parentFile, filename);
+ }
+
+ public boolean renameToError() {
+ return renameTo(errorFile);
+ }
+
+ public boolean renameToOutputFile() {
+ return renameTo(outputFile);
+ }
+
+ /**
+ * Get the File instance representing the original input file.
+ * @return Original input file.
+ */
+ public File getInputFile() {
+ return inputFile;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/GpListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/GpListener.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/GpListener.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,660 @@
+/*
+ * 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.old;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.command.CommandQueue;
+import org.jboss.internal.soa.esb.command.CommandQueueException;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.notification.NotificationList;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.jboss.soa.esb.services.NotificationHandlerFactory;
+import org.jboss.soa.esb.services.NotificationManager;
+import org.jboss.soa.esb.util.Util;
+import org.xml.sax.SAXException;
+
+/**
+ * Controlling class that will launch listener child threads for supported
+ * transport listener classes, as indicated in the configuration XML tree
+ * pointed by arg[0]
+ *
+ * <p />
+ * Can be launched as uppermost controller (it has a main(args) method)
+ * <p />
+ * Also implements Runnable, and can thus be launched in a child thread from an
+ * upper controlling process
+ * <p />
+ * Listens on a JMS queue (with an optional message selector) for commands (e.g.
+ * Quiesce, Reload Parameters, Set End Time, etc.)
+ * <p />
+ * Parameter reloading can also be set using the PARM_RELOAD_SECS attribute
+ * <p />
+ * End time for this instance can also be set using the PARM_END_TIME attribute
+ * <p />
+ *
+ * @author Esteban
+ *
+ */
+public class GpListener implements Runnable {
+
+ private static Logger m_oLogger = Logger.getLogger(GpListener.class);
+
+ public static void main(String[] args) throws Exception {
+ GpListener oProc = new GpListener(args[0]);
+ oProc.run();
+ GpListener.State oS = oProc.getState();
+
+ if (null != oS.getException()) {
+ m_oLogger.error("GpListener <" + args[0] + "> FAILED\n", oS
+ .getException());
+ }
+ System.exit(oS.getCompletionCode());
+ } // ________________________________
+
+ protected int m_iDfltReloadMillis = 180000 // default interval between
+ // parameter reloads
+ ;
+
+ public static final String PARM_RELOAD_SECS = "parameterReloadSecs";
+ public static final String PARM_END_TIME = "endTime";
+
+ // Attribute name that denotes listener class to be instantiated in a child
+ // thread
+ // This attribute is not in the root node but in first level child
+ // ConfigTrees
+ public static final String PARM_LISTENER_CLASS = "listenerClass";
+ public static final String PARM_ACTIONS = "actions";
+ public static final String PARM_MAX_THREADS = "maxThreads";
+ public static final String CHLD_EMAIL_PARMS = "EmailProperties";
+
+ private String m_sParmsName;
+ private ConfigTree m_oParms;
+
+ private HashMap<String, Object> m_oAtts;
+
+ /**
+ * Obtain a shallow copy of needed atributes in this object's last loaded
+ * parameter tree <p/>The local bject is cloned so child threads can use it
+ * as they choose to without interfering with the environment
+ * <p />
+ * Listener processes controlled by this object should keep a reference to
+ * this object at construction time, and not call this method again unless
+ * they specifically need updated values. Parameter reload could have
+ * happened since last call
+ *
+ * @return Map - a shallow copy of the attributes Map
+ */
+ @SuppressWarnings("unchecked")
+ public Map<String, Object> getControllerAttributes() {
+ return (Map<String, Object>) m_oAtts.clone();
+ }
+
+ private boolean m_bReloadRequested, m_bEndRequested;
+
+ private long m_lNextReload = Long.MAX_VALUE;
+
+ private long m_lEndTime = Long.MAX_VALUE;
+
+ public static final SimpleDateFormat s_oDateParse = new SimpleDateFormat(
+ "yyyyMMdd hh:mm:ss");
+
+ private State m_oState = null;
+
+ public State getState() {
+ return m_oState;
+ }
+
+ public static enum State {
+ Loading_parameters, Running, Shutting_down, Done_OK, Exception_thrown;
+ int m_iCompletionCode = 0;
+
+ Exception m_oException = null;
+
+ public int getCompletionCode() {
+ return m_iCompletionCode;
+ };
+
+ public Exception getException() {
+ return m_oException;
+ }
+ };
+
+ private CommandQueue commandQueue;
+
+ private ActionDefinitionFactory actionDefinitionFactory;
+
+ private static CommandQueue defaultCommandQueue = null;
+
+ /**
+ * Package pivate default constructor.
+ */
+ protected GpListener() {
+ }
+
+ /**
+ * Construct a Listener Manager from the named repository based
+ * configuration.
+ *
+ * @param p_sParameterName
+ * Name of the Repository entry containing the configuration.
+ * @throws Exception
+ * Unable to load/use the named configuration.
+ */
+ public GpListener(String p_sParameterName) throws Exception {
+ this(GpListener.getListenerConfig(p_sParameterName));
+ m_sParmsName = p_sParameterName;
+ }
+
+ /**
+ * Construct a Listener Manager using the specified listener configuration.
+ *
+ * @param config
+ * The configuration.
+ * @throws Exception
+ * Unable to load/use the supplied configuration.
+ */
+ public GpListener(ConfigTree config) throws Exception {
+ m_oParms = config;
+ m_oState = State.Loading_parameters;
+
+ try {
+ checkParms(m_oParms);
+ setEmailSystemProperties();
+ } catch (Exception e) {
+ String configSource = config.getAttribute("configSource");
+
+ m_oState = State.Exception_thrown;
+ m_oState.m_oException = e;
+ m_oLogger.fatal("Listener configuration and startup error. Config Source: "
+ + (configSource != null ? configSource
+ : "unknown"), e);
+
+ throw e;
+ }
+ }
+
+ /**
+ * Load the named listener configuration from the configured parameter
+ * repository.
+ *
+ * @param reposParam
+ * The name of the repository entry containing the Listener
+ * configuration.
+ * @return Listener Configuration as {@link ConfigTree}.
+ * @throws IOException
+ * Unable to access the repository.
+ * @throws ParamRepositoryException
+ * Unable to access the configuration in the repository.
+ * @throws SAXException
+ * Unable to parse the configuration.
+ */
+ private static ConfigTree getListenerConfig(String reposParam)
+ throws IOException, ParamRepositoryException, SAXException {
+ String sXml = ParamRepositoryFactory.getInstance().get(reposParam);
+ ConfigTree config = ConfigTree.fromXml(sXml);
+
+ config.setAttribute("configSource", "param-repository:" + reposParam);
+
+ return config;
+ }
+
+ /**
+ * Check to see if all needed parameters are there, and assign default
+ * values to some of them
+ *
+ * @param p_oP
+ * ConfigTree - Where to look for the mandatory/optional
+ * configuration attributes
+ * @throws Exception -
+ * If attributes are wrong or not enough for a proper runtime
+ * configuration
+ */
+ public void checkParms(ConfigTree p_oP) throws Exception {
+ // We've just loaded - set to false until next reload requested
+ m_bReloadRequested = false;
+ commandQueue = createCommandQueue(p_oP);
+
+ // Open the command queue...
+ if (null!=commandQueue)
+ commandQueue.open(p_oP);
+
+ // if PARM_RELOAD_SECS not set, and no command queue
+ // then reload every 10 minutes
+ // If there is a command queue, run until command is received
+ String sRldSecs = p_oP.getAttribute(PARM_RELOAD_SECS);
+ m_lNextReload = (null != sRldSecs)
+ ? System.currentTimeMillis() + 1000 * Long.parseLong(sRldSecs)
+ : (null == commandQueue)
+ ? Long.MAX_VALUE
+ : System.currentTimeMillis() + m_iDfltReloadMillis;
+
+ // if PARM_END_TIME not set try to run forever
+ // not a good practice if command queue is not set
+ // Expected date format is "yyyyMMdd hh:mm:ss"
+ String sEndT = p_oP.getAttribute(PARM_END_TIME);
+ m_lEndTime = (null == sEndT) ? Long.MAX_VALUE : s_oDateParse.parse(
+ sEndT).getTime();
+
+ // Read and initialise the action definitions...
+ ConfigTree actionConfig = p_oP.getFirstChild("Actions");
+ if(actionConfig == null) {
+ throw new ConfigurationException("No 'Actions' configuration.");
+ }
+ actionDefinitionFactory = new ActionDefinitionFactory(actionConfig);
+
+ } // ________________________________
+
+ /**
+ * Factory method for creating the command queue.
+ * @param config GpListener config.
+ * @return GpListener CommandQueue instance.
+ */
+ private CommandQueue createCommandQueue(ConfigTree config) {
+ String commandQueueClass = config.getAttribute("command-queue-class");
+
+ if(commandQueueClass != null) {
+ try {
+ return (CommandQueue) Class.forName(commandQueueClass).newInstance();
+ } catch (Exception e) {
+ m_oLogger.error("Failed to instantiate CommandQueue ["+ commandQueueClass + "]. Defaulting to no Command Queue", e);
+ }
+ }
+
+ return defaultCommandQueue;
+ }
+
+ /**
+ * Allows a default command queue to be set statically for all GpListener instances.
+ * @param defaultCommandQueue The defaultCommandQueue to set.
+ */
+ public static void setDefaultCommandQueue(CommandQueue defaultCommandQueue) {
+ GpListener.defaultCommandQueue = defaultCommandQueue;
+ }
+
+ /**
+ * Main execution loop <p/> Will continue to run until either <p/>a) run
+ * time is expired <p/>b) quiesce command is received in command queue
+ * <p/>For every child element that contains a PARM_LISTENER_CLASS
+ * attribute, this method will try to launch a child thread instantiating an
+ * object of that class, and will call it's run() method <p/>Once all child
+ * processes are trigered, the main thread will either <p/>1) wait for a
+ * message in the command queue (if one was configured) until next reload or
+ * end of run period expired <p/>or 2) Just sleep if there's no command
+ * queue to listen on
+ */
+ public void run() {
+ while (endNotRequested()) {
+ m_oState = State.Running;
+ for (ConfigTree oCurr : m_oParms.getAllChildren()) {
+ String sClass = oCurr.getAttribute(PARM_LISTENER_CLASS);
+ if (Util.isNullString(sClass))
+ continue;
+ tryToLaunchChildListener(oCurr, sClass);
+ }
+
+ waitForCmdOrSleep();
+
+ if (endRequested()) {
+ break;
+ }
+ if (m_sParmsName != null && timeToReload()) {
+ try {
+ m_oState = State.Loading_parameters;
+ m_oLogger
+ .info("Reloading parameters _____________________________________________________");
+ ConfigTree oNew = GpListener.getListenerConfig(m_sParmsName);
+ checkParms(oNew);
+ m_oParms = oNew;
+ setEmailSystemProperties();
+ } catch (Exception e) {
+ m_oLogger.error("Failed to reload parameters"
+ + " - Continuing with cached version", e);
+ }
+ }
+ }
+ // m_oState = State.Shutting_down;
+
+ m_oState = State.Done_OK;
+ m_oState.m_iCompletionCode = 0;
+ m_oLogger
+ .info("Finishing_____________________________________________________");
+
+ // Close the command queue...
+ try {
+ commandQueue.close();
+ } catch (CommandQueueException e) {
+ m_oLogger.error("Error closing Command Queue.", e);
+ }
+ } // ________________________________
+
+ private void tryToLaunchChildListener(ConfigTree p_oP, String p_sClassName) {
+ try {
+ Class oListener = Class.forName(p_sClassName);
+ Constructor oConst = oListener.getConstructor(new Class[] {
+ this.getClass(), ConfigTree.class, ActionDefinitionFactory.class });
+ Runnable oRun = (Runnable) oConst.newInstance(new Object[] { this,
+ p_oP, actionDefinitionFactory });
+ new Thread(oRun).start();
+ } catch (Exception e) {
+ m_oLogger.error("Cannot launch <" + p_sClassName + ">\n", e);
+ }
+ } // ________________________________
+
+ long millisToWait() {
+ return Math.min(m_lNextReload, m_lEndTime) - System.currentTimeMillis();
+ } // ________________________________
+
+ private void waitForCmdOrSleep() {
+ long lToGo = millisToWait();
+
+ if (null == commandQueue) {
+ m_oLogger.debug("About to sleep " + lToGo);
+ // No command queue nor topic - Just sleep until time
+ // exhausted, or thread interrupted
+ try {
+ if (lToGo > 0)
+ Thread.sleep(lToGo);
+ } catch (InterruptedException e) {
+ m_lEndTime = 0; // mark as end requested and return
+ }
+ return;
+ }
+
+ // Wait for commands until time exhausted or command received
+ // Note that received commands might change time variables (reload/end)
+ // that's why time to go is recalculated on each cycle
+ while ((lToGo = millisToWait()) > 0) {
+ try {
+ m_oLogger.info("Waiting for command ... timeout=" + lToGo + " millis");
+
+ String oM = commandQueue.receiveCommand(lToGo);
+ if (null == oM) {
+ return;
+ }
+ processCommand(oM);
+ if (endRequested() || timeToReload()) {
+ break;
+ }
+ } catch (CommandQueueException eJ) {
+ m_oLogger.info("receive on command queue failed", eJ);
+ }
+ }
+ } // ________________________________
+
+ /**
+ * Processes the command that has been received in the command queue (or
+ * topic) <p/>m_bEndRequested, m_bReloadRequested, and m_lEndTime could be
+ * changed
+ *
+ * <p/> <p/><TABLE border="1"> <COLGROUP> <COL width="200"/> <COL
+ * width="400"/> </COLGROUP>
+ * <TR>
+ * <TD align="center">message text</TD>
+ * <TD align="center">effect</TD>
+ * </TR>
+ * <TR>
+ * <TD>shutdown*</TD>
+ * <TD>End time will be immediately set to 'now' - quiesce process will
+ * start - Child threads will be allowed to finish normally</TD>
+ * </TR>
+ * <TR>
+ * <TD>reload param*</TD>
+ * <TD>Parameters will be immediately reloaded, and listener reconfigured
+ * with new values</TD>
+ * </TR>
+ * <TR>
+ * <TD>endTime yyyyMMdd hh:mm:ss</TD>
+ * <TD>End time will be set to new value. If hh:mm:ss is not supplied =>
+ * end of day assumed (23:59:59)</TD>
+ * </TR>
+ * </TABLE> * startsWith() <p/>
+ *
+ * @param p_oMsg
+ * Message received from the command queue.
+ *
+ */
+ private void processCommand(String sTxt) {
+ if (null == sTxt)
+ return;
+
+ String sLow = sTxt.trim().toLowerCase();
+ if (sLow.startsWith("shutdown")) {
+ m_bEndRequested = true;
+ m_oLogger.info("Shutdown has been requested");
+ return;
+ }
+ if (sLow.startsWith("reload param")) {
+ m_bReloadRequested = true;
+ m_oLogger
+ .info("Request for parameter reload has been received");
+ return;
+ }
+ String[] sa = sLow.split("\\s+");
+ if (sa.length > 1 && "endtime".equals(sa[0])) {
+ try {
+ String sDate = sa[1];
+ String sTime = (sa.length < 3 || null == sa[2]) ? "23:59:59"
+ : sa[2];
+ Date oEnd = s_oDateParse.parse(sDate + " " + sTime);
+ m_oLogger.info("New end date set to : " + oEnd);
+ m_lEndTime = oEnd.getTime();
+ } catch (Exception eDat) {
+ m_oLogger.info("Problems with endTime command", eDat);
+ }
+ }
+ } // ________________________________
+
+ /**
+ * Accessor to determine if execution time is expired or shutdown requested
+ *
+ * @return boolean if processing has to stop (all child threads will be
+ * allowed to finish)
+ */
+ public boolean endRequested() {
+ return m_bEndRequested || System.currentTimeMillis() >= m_lEndTime;
+ }
+
+ /**
+ * Accessor to determine if execution time is not expired, and no shutdown
+ * request received
+ *
+ * @return boolean - true if run time has not expired and quiesce has not
+ * been requested
+ */
+ public boolean endNotRequested() {
+ return !endRequested();
+ }
+
+ /**
+ * Provide a common accessor to determine if parameters have to be reloaded
+ * <p/> For child threads this means thread execution has to end
+ * </p>
+ * Child processes should only call this method when they are idle (as
+ * opposed to in the middle of executing a unit of work)
+ *
+ * @return boolean - true if it's time to reload parameters
+ */
+ public boolean timeToReload() {
+ return m_bReloadRequested
+ || System.currentTimeMillis() >= m_lNextReload;
+ }
+
+ /**
+ * Helper accessor for child processes that provides info to determine if
+ * they can continue with yet another execution cycle
+ *
+ * @return boolean - true if runtime is not expired and not time yet to
+ * reload parameters
+ */
+ public boolean continueLooping() {
+ return (endNotRequested() && !timeToReload());
+ } // ________________________________
+
+ private static final String[] s_saMailProps = { Environment.SMTP_HOST,
+ Environment.SMTP_USERNAME, Environment.SMTP_PASSWORD,
+ Environment.SMTP_PORT, Environment.SMTP_FROM,
+ Environment.SMTP_AUTH };
+
+ private void setEmailSystemProperties() {
+ ConfigTree oEmail = m_oParms.getFirstChild(CHLD_EMAIL_PARMS);
+ if (null != oEmail)
+ for (String sCurr : s_saMailProps) {
+ String sProp = oEmail.getAttribute(sCurr);
+ if (null != sProp)
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).setProperty(sCurr, sProp);
+ }
+ } // ________________________________
+
+ /**
+ * Find an attribute in the tree (arg 0) or assign default value (arg 2)
+ *
+ * @param p_oP
+ * ConfigTree - look for attributes in this Element only
+ * @param p_sAtt
+ * String - Name of attribute to find
+ * @param p_sDefault
+ * String -default value if requested attribute is not there
+ * @return String - value of attribute, or default value (if null)
+ * @throws Exception -
+ * If requested attribute not found and no default value
+ * supplied by invoker
+ */
+ public static String obtainAtt(ConfigTree p_oP, String p_sAtt, String p_sDefault)
+ throws ConfigurationException {
+ String sVal = p_oP.getAttribute(p_sAtt);
+ if ((null == sVal) && (null == p_sDefault))
+ throw new ConfigurationException("Missing or invalid <" + p_sAtt + "> attribute");
+
+ return (null != sVal) ? sVal : p_sDefault;
+ } // ________________________________
+
+ /**
+ * Find child nodes named "NotificationList" that contain an attribute
+ * 'type' that starts with "ok" (case insensitive)
+ *
+ * @param p_oP -
+ * ConfigTree to search for "NotificationList" child Elements
+ * @param p_oSer
+ * Serializable - Will constitute the body of the notification
+ */
+ public static void notifyOK(ConfigTree p_oP, Serializable p_oSer) {
+ if(p_oSer == null) {
+ return;
+ }
+
+ try {
+ Serializable oNotif = p_oSer;
+ for (ConfigTree oCurr : p_oP
+ .getChildren(NotificationList.ELEMENT)) {
+ NotificationList oNL = new NotificationList(oCurr);
+ if (!oNL.isOK())
+ continue;
+ getNotifHandler().sendNotifications(oCurr, oNotif);
+ }
+ } catch (Exception e) {
+ }
+ } // __________________________________
+
+ /**
+ * Find child nodes named "NotificationList" that contain an attribute
+ * 'type' that starts with "err" (case insensitive) or no 'type' attribute
+ * set
+ *
+ * @param p_oP -
+ * ConfigTree to search for "NotificationList" child Elements
+ * @param p_e -
+ * Exception if not null, will be appended to the body
+ * @param p_oSer
+ * Serializable - Will be included at the beginning of the body
+ * of the notification
+ */
+ public static void notifyError(ConfigTree p_oP, Exception p_e, Serializable p_oSer) {
+ if(p_oSer == null) {
+ return;
+ }
+
+ Serializable oNotif = p_oSer;
+ ByteArrayOutputStream oBO = new ByteArrayOutputStream();
+ PrintStream oPS = new PrintStream(oBO);
+ try {
+ oPS.println(oNotif.toString());
+ if (null != p_e)
+ p_e.printStackTrace(oPS);
+ oPS.close();
+
+ String sMsg = oBO.toString();
+ for (ConfigTree oCurr : p_oP
+ .getChildren(NotificationList.ELEMENT)) {
+ NotificationList oNL = new NotificationList(oCurr);
+ if (!oNL.isErr())
+ continue;
+ getNotifHandler().sendNotifications(oNL, sMsg);
+ }
+ } catch (Exception e) {
+ }
+ } // ________________________________
+
+ private static NotificationManager s_oNH;
+
+ private static final Object s_oSync = new Integer(0);
+
+ /**
+ * Lazy instantiator of a InotificationHandler
+ *
+ * @return - a reference to an implementation of the interface or null if it
+ * can't be instantiated
+ */
+ protected static NotificationManager getNotifHandler() {
+ if (null != s_oNH)
+ return s_oNH;
+ synchronized (s_oSync) {
+ if (null == s_oNH)
+ try {
+ s_oNH = NotificationHandlerFactory.getNotifHandler(
+ "remote", Configuration.getJndiServerType(),
+ Configuration.getJndiServerURL());
+ } catch (Exception e) {
+ Logger.getLogger(GpListener.class).error(
+ "Notification FAILED", e);
+ }
+ }
+ return s_oNH;
+ } // ______________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/JmsQueueListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/JmsQueueListener.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/JmsQueueListener.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,187 @@
+/*
+ * 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.old;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.jms.TopicSession;
+import javax.naming.Context;
+
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.AppServerContext;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+public class JmsQueueListener extends AbstractListener {
+
+ public static final String LISTEN_QUEUE_CONN_FACT = "queueConnFactoryClass";
+ public static final String LISTEN_JNDI_TYPE = "listenJndiType";
+ public static final String LISTEN_JNDI_URL = "listenJndiURL";
+ public static final String LISTEN_QUEUE = "listenQueue";
+ public static final String LISTEN_MSG_SELECTOR = "listenMsgSelector";
+
+ protected boolean m_bError = false;
+ protected QueueConnection m_oQconn;
+ protected QueueSession m_oQsess;
+ protected Queue m_oQueue;
+ protected String m_sSelector;
+
+ protected MessageConsumer jmsMessageReceiver;
+
+
+ public JmsQueueListener(GpListener commandListener, ConfigTree listenerConfig, ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+ super(commandListener, listenerConfig, actionDefinitionFactory);
+ checkMyParms();
+ } // __________________________________
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ *
+ * @throws Exception -
+ * if mandatory atts are not right or actionClass not in
+ * classpath
+ */
+ protected void checkMyParms() throws Exception {
+ // Third arg is null - Exception will br thrown if listenQueue is not
+ // found
+ String sQueue = GpListener.obtainAtt(listenerConfig, LISTEN_QUEUE, null);
+
+ // No problem if selector is null - everything in queue will be returned
+ m_sSelector = listenerConfig.getAttribute(LISTEN_MSG_SELECTOR);
+
+ m_oQconn = null;
+ m_oQsess = null;
+ m_oQueue = null;
+
+ String sJndiType = GpListener.obtainAtt(listenerConfig, LISTEN_JNDI_TYPE,
+ "jboss");
+ String sJndiURL = GpListener.obtainAtt(listenerConfig, LISTEN_JNDI_URL,
+ "localhost");
+ Context oJndiCtx = AppServerContext.getServerContext(sJndiType,
+ sJndiURL);
+
+ String sFactClass = GpListener.obtainAtt(listenerConfig,
+ LISTEN_QUEUE_CONN_FACT, "ConnectionFactory");
+ Object tmp = oJndiCtx.lookup(sFactClass);
+ QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+
+ m_oQconn = qcf.createQueueConnection();
+ m_oQueue = (Queue) oJndiCtx.lookup(sQueue);
+ m_oQsess = m_oQconn.createQueueSession(false,
+ TopicSession.AUTO_ACKNOWLEDGE);
+ m_oQconn.start();
+ jmsMessageReceiver = m_oQsess.createReceiver(m_oQueue, m_sSelector);
+
+ } // ________________________________
+
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#receive()
+ */
+ @Override
+ protected Object[] receive() {
+ while (m_oDad.continueLooping()) {
+ Message jmsMessage = null;
+ try {
+ jmsMessage = jmsMessageReceiver.receive(m_oDad.millisToWait());
+ } catch (JMSException oJ) {
+ logger.error("JMS error on receive. Attempting JMS Destination reconnect.", oJ);
+ for (int i1 = 0; i1 < 3; i1++)
+ try {
+ checkMyParms();
+ } // try to reconnect to the queue
+ catch (Exception e) {
+ logger.error("Reconnecting to Queue", e);
+ try {
+ Thread.sleep(m_iSleepForThreads);
+ } catch (InterruptedException e1) { // Just return
+ logger.error("Unexpected thread interupt exception.", e);
+ return null;
+ }
+ }
+ }
+ if (null == jmsMessage) {
+ // REVIEW: Can this really happen i.e. the JMS
+ continue;
+ }
+
+ if (jmsMessage instanceof ObjectMessage) {
+ try {
+ return new Object[] {((ObjectMessage)jmsMessage).getObject()};
+ } catch (JMSException e) {
+ logger.error("Failed to read Serialized Object from JMS message.", e);
+ }
+ } else if (jmsMessage instanceof TextMessage) {
+ try {
+ return new Object[] {((TextMessage)jmsMessage).getText()};
+ } catch (JMSException e) {
+ logger.error("Failed to read Serialized Object from JMS message.", e);
+ }
+ } else {
+ logger.error("Unsupported JMS message type: " + jmsMessage.getClass().getName());
+ }
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#close()
+ */
+ @Override
+ protected void close() {
+ if (null != m_oQsess) {
+ try {
+ m_oQsess.close();
+ } catch (Exception e1) {/* Tried my best - Just continue */
+ }
+ }
+ if (null != m_oQconn) {
+ try {
+ m_oQconn.close();
+ } catch (Exception e2) {/* Tried my best - Just continue */
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingError(java.lang.Object, org.jboss.soa.esb.actions.ActionProcessor, java.lang.Throwable)
+ */
+ @Override
+ protected void processingError(Object initialMessage, ActionProcessor processor, Throwable error) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingComplete(java.lang.Object)
+ */
+ @Override
+ protected void processingComplete(Object initialMessage) {
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/RemoteDirectoryPoller.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/RemoteDirectoryPoller.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/RemoteDirectoryPoller.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,284 @@
+/*
+* 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.old;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.util.FtpClientUtil;
+import org.jboss.soa.esb.util.Util;
+
+public class RemoteDirectoryPoller extends AbstractPoller
+{
+ public static final String FILE_INPUT_DIR = "inputDir";
+ public static final String FILE_INPUT_SFX = "inputSuffix";
+ public static final String FILE_WORK_SFX = "workSuffix";
+ public static final String FILE_ERROR_DIR = "errorDir";
+ public static final String FILE_ERROR_SFX = "errorSuffix";
+ public static final String FILE_POST_DIR = "postDir";
+ public static final String FILE_POST_SFX = "postSuffix";
+ public static final String FILE_POST_DEL = "postDelete";
+
+ private ConfigTree _params;
+ private Logger _logger = Logger.getLogger(this.getClass());
+ FtpClientUtil _ftpClient;
+
+ public RemoteDirectoryPoller(GpListener p_oDad, ConfigTree p_oParms,ActionDefinitionFactory actionDF)
+ throws Exception
+ {
+ super(p_oDad,p_oParms,actionDF);
+ _params = p_oParms;
+ checkMyParms();
+ } //__________________________________
+
+
+ protected File m_oInpDir ,m_oErrorDir ,m_oPostDir;
+ protected String m_sInpSfx ,m_sWrkSfx ,m_sErrSfx ,m_sPostSfx;
+ protected boolean m_bPostDel;
+ private List <KeyValuePair> m_ftpProps = new ArrayList<KeyValuePair>();
+
+ /**
+ *
+ * @param p_o Object - Must be a File representing the file that has to be processed
+ * @return Object - an instance of the internal WorkingFile class
+ */
+ @Override
+ public Object preProcess(Object p_o)
+ {
+ if (!(p_o instanceof File))
+ return null;
+ File oF = (File)p_o;
+ WorkingFile oCurr = new WorkingFile(oF,m_sWrkSfx,m_bPostDel);
+ oCurr.errorFile = new File (m_oErrorDir ,oF.getName()+m_sErrSfx);
+ oCurr.outputFile = new File (m_oPostDir ,oF.getName()+m_sPostSfx);
+ oCurr.setFtpProps(m_ftpProps);
+
+ try
+ {
+ _ftpClient = new FtpClientUtil(_params,true);
+ _ftpClient.remoteRename(oF,oCurr);
+ }
+ catch (Exception e)
+ {
+ _logger.error("Can't FTP rename",e);
+ return null;
+ }
+ finally
+ {
+ if (null!=_ftpClient)
+ _ftpClient.quit();
+ _ftpClient = null;
+ }
+
+ return oCurr;
+ } //________________________________
+
+ @Override
+ protected List<Object> pollForCandidates()
+ {
+ List<Object> oRet = new ArrayList<Object>();
+ FtpClientUtil _ftpClient = null;
+ try
+ {
+ _ftpClient = new FtpClientUtil(_params,true);
+ _ftpClient.setRemoteDir(FtpClientUtil.fileToFtpString(m_oInpDir));
+ String[] sa = _ftpClient.getFileListFromRemoteDir(m_sInpSfx);
+ if (null!=sa)
+ for (String sCurr : sa)
+ oRet.add(new File(m_oInpDir,sCurr));
+ }
+ catch (Exception e)
+ {
+ _logger.error("Problems with FTP",e);
+ }
+ finally
+ {
+ if (null!=_ftpClient)
+ _ftpClient.quit();
+ _ftpClient = null;
+ }
+ return oRet;
+
+ } //________________________________
+
+ protected void checkMyParms() throws Exception
+ {
+ // INPUT directory and suffix (used for FileFilter)
+ String sInpDir = GpListener.obtainAtt(_params,FILE_INPUT_DIR,null);
+ m_oInpDir = new File(sInpDir);
+
+ m_sInpSfx = GpListener.obtainAtt(_params,FILE_INPUT_SFX,null);
+ m_sInpSfx = m_sInpSfx.trim();
+ if (m_sInpSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_INPUT_SFX+" attribute");
+
+ // WORK suffix (will rename in input directory)
+ m_sWrkSfx = GpListener.obtainAtt(_params,FILE_WORK_SFX,".esbWork").trim();
+ if (m_sWrkSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_WORK_SFX+" attribute");
+ if (m_sInpSfx.equals(m_sWrkSfx))
+ throw new Exception("Work suffix must differ from input suffix <"+m_sWrkSfx+">");
+
+ // ERROR directory and suffix (defaults to input dir and ".esbError" suffix)
+ String sErrDir = GpListener.obtainAtt(_params,FILE_ERROR_DIR,sInpDir);
+ m_oErrorDir = new File(sErrDir);
+
+ m_sErrSfx = GpListener.obtainAtt(_params,FILE_ERROR_SFX,".esbError").trim();
+ if (m_sErrSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_ERROR_SFX+" attribute");
+ if (m_oErrorDir.equals(m_oInpDir) && m_sInpSfx.equals(m_sErrSfx))
+ throw new Exception("Error suffix must differ from input suffix <"+m_sErrSfx+">");
+
+
+ // Do users wish to delete files that were processed OK ?
+ String sPostDel = GpListener.obtainAtt(_params,FILE_POST_DEL,"false").trim();
+ m_bPostDel = Boolean.parseBoolean(sPostDel);
+ if (m_bPostDel)
+ return;
+
+ // POST (done) directory and suffix (defaults to input dir and ".esbDone" suffix)
+ String sPostDir = GpListener.obtainAtt(_params,FILE_POST_DIR,sInpDir);
+ m_oPostDir = new File(sPostDir);
+ m_sPostSfx = GpListener.obtainAtt(_params,FILE_POST_SFX,".esbDone").trim();
+ if (m_oPostDir.equals(m_oInpDir))
+ { if (m_sPostSfx.length()<1)
+ throw new Exception ("Invalid "+FILE_POST_SFX+" attribute");
+ if (m_sPostSfx.equals(m_sInpSfx))
+ throw new Exception("Post process suffix must differ from input suffix <"+m_sPostSfx+">");
+ }
+
+
+ FtpClientUtil _ftpClient = new FtpClientUtil(_params,false);
+ _ftpClient.quit();
+
+ // Copy FTP parameters to be passed to the action class (inside the WorkingFile class)
+ // This is a kludge - we have to get back to this (ES)
+ String[] sa = new String[]
+ {FtpClientUtil.PARMS_FTP_SERVER
+ ,FtpClientUtil.PARMS_USER
+ ,FtpClientUtil.PARMS_PASSWD
+ ,FtpClientUtil.PARMS_PASSIVE
+ ,FtpClientUtil.PARMS_PORT
+ };
+ for (String sProp : sa)
+ {
+ String sVal = _params.getAttribute(sProp);
+ if (!Util.isNullString(sVal))
+ m_ftpProps.add(new KeyValuePair(sProp,sVal));
+ }
+
+ } //________________________________
+
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#close()
+ */
+ @Override
+ protected void close() { }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingError(java.lang.Object, org.jboss.soa.esb.actions.ActionProcessor, java.lang.Throwable)
+ */
+ @Override
+ protected void processingError(Object initialMessage, ActionProcessor processor, Throwable error)
+ {
+ @SuppressWarnings("unused")
+ WorkingFile workingFile = (WorkingFile) initialMessage;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingComplete(java.lang.Object)
+ */
+ @Override
+ protected void processingComplete(Object initialMessage)
+ {
+ @SuppressWarnings("unused")
+ WorkingFile workingFile = (WorkingFile) initialMessage;
+ }
+
+ /**
+ * Working file.
+ * <p/>
+ * Once the remote directory poller picks up on an input file, it immediately tries to rename
+ * it to a working file in order to avoid a situation where the file gets processed again.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+ public static class WorkingFile extends File
+ {
+ private static final long serialVersionUID = 1L;
+
+ private boolean postDelete;
+ private File inputFile, errorFile, outputFile;
+ private List <KeyValuePair> ftpProps;
+ public void setFtpProps(List <KeyValuePair>props) {ftpProps = props; }
+ public List <KeyValuePair >getFtpProps() {return ftpProps; }
+
+ private WorkingFile(File pFile,String pWrkSfx, boolean pPostDelete)
+ {
+ super(pFile.getParentFile(), pFile.getName() + pWrkSfx);
+ inputFile = pFile;
+ }
+ /**
+ * Get the File instance representing the original input file.
+ * @return Original input file.
+ */
+ public File getInputFile() { return inputFile; }
+ /**
+ * is this working file to be deleted after successful processing ?
+ * @return boolean - true if this file can be deleted
+ */
+ public boolean isPostDelete() { return postDelete; }
+
+ public boolean localRenameToInput() { return super.renameTo(inputFile); }
+ public void remoteRenameToInput(FtpClientUtil util) throws Exception
+ {
+ util.remoteRename(this,inputFile);
+ }
+
+ public boolean localRenameToError() { return super.renameTo(errorFile); }
+ public void remoteRenameToError(FtpClientUtil util) throws Exception
+ {
+ util.remoteRename(this,errorFile);
+ }
+
+ public boolean localRenameToOutput() { return renameTo(outputFile); }
+ public void remoteRenameToOutput(FtpClientUtil util) throws Exception
+ {
+ util.remoteRename(this,outputFile);
+ }
+
+ public boolean localDelete() {return delete(); }
+ public void remoteDelete(FtpClientUtil util) throws Exception
+ {util.deleteRemoteFile(this.toString()); }
+
+ }
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/SqlTablePoller.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/SqlTablePoller.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/listeners/old/SqlTablePoller.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,505 @@
+/*
+* 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.old;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.sql.DataSource;
+
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.helpers.persist.SimpleDataSource;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * SqlTablePoller class
+ *
+ * The SQL table that is polled should have
+ * 1) a unique key (see "keyFields" parameter) that will be used to update status
+ * 2) a column to indicate the "processing status" of this trigger row (see ROW_STATE enum)
+ *
+ * Each retrieved row (see OPTIONAL_ATT.whereCondition) should be considered as a trigger
+ * that is intended to instantiate an object of "actionClass". The new instance will
+ * receive the full ConfigTree (level 1 for each child group)
+ *
+ * @author Esteban Schifman
+ */
+public class SqlTablePoller extends AbstractPoller
+{
+/* ___________________ Example XML configuration file for a SqlTablePoller_______________
+ *
+<DocumentElementName>
+ <ExampleListenChapter
+ maxThreads="2"
+ listenerClass="org.jboss.soa.esb.listeners.SqlTablePoller"
+ actionClass="org.jboss.soa.esb.actions.templates.MockSqlRowAction"
+
+ driver-class="org.postgresql.Driver"
+ connection-url="jdbc:postgresql://myhost:5432/myDB"
+ user-name="postgres"
+ password=""
+
+ tableName="test_notif_table"
+ selectFields="oid,ref,msg"
+ keyFields="oid,ref"
+ inProcessField="statusCol"
+ whereCondition="src='pepe'"
+ orderBy="oid desc"
+ >
+ <NotificationList type="OK">
+ <target class="NotifyFiles">
+ <file URI="file:///tmp/jbossEsb/notifyDir/ListenOnNotifTable.notifOK"
+ append="true"
+ />
+ </target>
+ </NotificationList>
+
+ <NotificationList type="err">
+ <target class="NotifyFiles">
+ <file URI="file:///tmp/jbossEsb/notifyDir/ListenOnNotifTable.notifErr"
+ append="true"
+ />
+ </target>
+ </NotificationList>
+ </ExampleListenChapter>
+</DocumentElementName>
+ *
+ */
+
+ /**
+ * Mandatory attributes needed for SqlTablePoller
+ * 1) Table name
+ * 2) Comma separated list of fields needed in the ResultSet
+ * 3) Comma separated list of fields that constitute a unique ID of the working row
+ * all fields in this list MUST also be in the "selectFields" list
+ * these fields will be used in the "where" clause of update statements
+ * 4) Name of table field used as indicator/semaphore to avoid concurrent update
+ *
+ */
+ public static enum TABLE_ATT
+ {
+ tableName
+ ,selectFields
+ ,keyFields
+ ,inProcessField
+ };
+
+ /**
+ * Optional fields that can be included in your parameter tree as attributes in the
+ * upper Element
+ * 1) 4 character long String that indicate status of each row for this poller
+ * 1st: Character that indicates "Pending" state = available for processing
+ * 2nd: "Working" : some poller is working on the row (or ab-ended while working)
+ * 3rd: "Error" : some poller tried to process, and found an error during processing
+ * 4th: "Done" : this row has already been processed successfully
+ * 2) if you wish to further filter your ResultSet, you can add an optional list of
+ * conditions that will be included in the "scan" SQL statement (without "where")
+ * 3) Comma separated list of fields to order ResultSet (without "order by")
+ *
+ */
+ public static enum OPTIONAL_ATT
+ {
+ inProcessVals
+ ,whereCondition
+ ,orderBy
+ };
+
+ /**
+ * First character of these values are the default states of a table row trigger
+ * the "inProcessVals" parameter can override these (if that were ever necessary)
+ * this is why the default value for that parameter is "PWED" (see below)
+ * The poller will only process rows that have the "inProcessField" first character
+ * equal to the first character of whatever the "Pending" state is (typically "P")
+ *
+ */
+ public static enum ROW_STATE
+ {Pending
+ ,Working
+ ,Error
+ ,Done
+ };
+ public static final String DEFAULT_STATES = "PWED";
+
+ protected Map<String,String> m_oVals = new HashMap<String,String>();
+ protected String[] m_saCols ,m_saKeys;
+ protected String m_sUpdStates;
+
+ /**
+ * In this constructor you can override default values for the following protected base class values:
+ * <br/>
+ * <p/>m_iMinPollMillis : minimum polling interval (default 3000)
+ * <br/>m_iDfltPollMillis : default polling interval (default 20000)
+ * <br/>m_iSleepForThreads : how long to sleep if all configured threads are in use (default 3000)
+ * <br/>m_iUpperThreadLimit : max number of threads allowed (default 10)
+ * @param p_oDad GpListener - The controlling process
+ * @param p_oParms ConfigTree - Sub tree that corresponds to this instance
+ * @throws Exception
+ */
+ public SqlTablePoller(GpListener p_oDad, ConfigTree p_oParms, ActionDefinitionFactory actionDefinitionFactory) throws Exception
+ {
+ super(p_oDad, p_oParms, actionDefinitionFactory);
+ try { checkMyParms(); }
+ catch (Exception e)
+ {
+ logger.error("checkMyParms() FAILED",e);
+ throw e;
+ }
+ } //__________________________________
+
+ private void checkAndStoreAtt(ConfigTree p_oP, String p_sName, String p_sDflt)
+ throws Exception
+ {
+ m_oVals.put(p_sName,GpListener.obtainAtt(p_oP,p_sName,p_sDflt));
+ } //________________________________
+
+ protected void checkMyParms() throws Exception
+ {
+ checkAndStoreAtt(listenerConfig,SimpleDataSource.DRIVER ,null);
+ checkAndStoreAtt(listenerConfig,SimpleDataSource.URL ,null);
+ checkAndStoreAtt(listenerConfig,SimpleDataSource.USER ,"");
+ checkAndStoreAtt(listenerConfig,SimpleDataSource.PASSWORD ,"");
+
+ for (TABLE_ATT oCurr : TABLE_ATT.values())
+ checkAndStoreAtt(listenerConfig,oCurr.toString(),null);
+
+ checkAndStoreAtt(listenerConfig,OPTIONAL_ATT.whereCondition.toString(),"");
+ checkAndStoreAtt(listenerConfig,OPTIONAL_ATT.orderBy.toString(),"");
+
+ String sAtt = OPTIONAL_ATT.inProcessVals.toString();
+ checkAndStoreAtt(listenerConfig,sAtt,DEFAULT_STATES);
+ m_sUpdStates = m_oVals.get(sAtt);
+ if (m_sUpdStates.length()<4)
+ throw new Exception("Parameter <"+sAtt+"> must be at least 4 characters long (PWED)");
+
+ StringTokenizer ST = new StringTokenizer
+ (m_oVals.get(TABLE_ATT.selectFields.toString()),",");
+ m_saCols = new String[ST.countTokens()];
+ Set<String> oSelFlds = new HashSet<String>();
+ int iCurr = 0;
+ while (ST.hasMoreElements())
+ {
+ String sColName = ST.nextToken().trim();
+ m_saCols[iCurr++] = sColName;
+ oSelFlds.add(sColName);
+ }
+
+ ST = new StringTokenizer
+ (m_oVals.get(TABLE_ATT.keyFields.toString()),",");
+ m_saKeys = new String[ST.countTokens()];
+ if (m_saKeys.length < 1)
+ throw new Exception("Empty list of keyFields");
+
+ for (iCurr = 0; ST.hasMoreTokens(); iCurr++)
+ { String sKeyCol = ST.nextToken().trim();
+ if (! oSelFlds.contains(sKeyCol))
+ throw new Exception("Key field <"+ sKeyCol + "> must also be in select list");
+ m_saKeys[iCurr] = sKeyCol;
+ }
+
+ } //________________________________
+
+ @Override
+ protected Object preProcess(Object p_o)
+ {
+ return p_o;
+ } //________________________________
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected List<Object> pollForCandidates()
+ {
+ String sSel4U = selectForUpdStatement();
+ String sUpdStmt = updateStatement();
+ JdbcCleanConn oConn = null;
+ List<Object> oResults = new ArrayList<Object>();
+ try
+ {
+ oConn = newDbConn();
+ String sScan = scanStatement();
+
+ PreparedStatement PS = oConn.prepareStatement(sScan);
+ ResultSet RS = oConn.execQueryWait(PS,1);
+ while (RS.next()) {
+ SQLPollResult rowParams = new SQLPollResult(sSel4U, sUpdStmt);
+ int iCurr = 0;
+
+ for (String sColName : m_saCols) {
+ rowParams.put(sColName,RS.getObject(++iCurr));
+ }
+
+ // Set up the parameter object for the SqlRowAction
+ rowParams.sUpdStates = m_sUpdStates;
+ rowParams.saKeys = m_saKeys;
+ rowParams.sSel4Upd = sSel4U;
+ rowParams.sUpdate = sUpdStmt;
+
+ // Mark the row as "working"...
+ rowParams.changeStatusToWorking();
+
+ oResults.add(rowParams);
+ }
+ }
+ catch (Exception e)
+ {
+ logger.warn("Some triggers might not have been returned",e);
+ }
+ finally
+ {
+ if (null!=oConn)
+ oConn.release();
+ }
+
+ logger.info("Returning " + oResults.size() + " rows.");
+ return oResults;
+ } //________________________________
+
+ /**
+ * Obtain a new database connection with parameter info
+ * @return A new connection
+ * @throws Exception - if problems are encountered
+ */
+ protected JdbcCleanConn newDbConn() throws Exception
+ { DataSource oDS = new SimpleDataSource
+ (m_oVals.get(SimpleDataSource.DRIVER)
+ ,m_oVals.get(SimpleDataSource.URL)
+ ,m_oVals.get(SimpleDataSource.USER)
+ ,m_oVals.get(SimpleDataSource.PASSWORD)
+ );
+ return new JdbcCleanConn(oDS);
+ } //________________________________
+
+ /**
+ * Assemble the SQL statement to scan (poll) the table
+ * @return - The resulting SQL statement
+ */
+ protected String scanStatement()
+ {
+ StringBuilder sb = new StringBuilder ()
+ .append("select ").append(m_oVals.get(TABLE_ATT.selectFields.toString()))
+ .append(" from ") .append(m_oVals.get(TABLE_ATT.tableName.toString()));
+
+ String sAux = m_oVals.get(OPTIONAL_ATT.whereCondition.toString());
+ boolean bWhere = ! Util.isNullString(sAux);
+ if (bWhere)
+ sb.append(" where ").append(sAux);
+ sb.append((bWhere) ? " and " : " where ");
+
+ String sLike = m_oVals.get(OPTIONAL_ATT.inProcessVals.toString())
+ .substring(0,1).toUpperCase();
+ sb.append(" upper(").append(m_oVals.get(TABLE_ATT.inProcessField.toString()))
+ .append(") like '").append(sLike).append("%'");
+
+
+ sAux = m_oVals.get(OPTIONAL_ATT.orderBy);
+ if (! Util.isNullString(sAux))
+ sb.append(" order by ").append(sAux);
+ return sb.toString();
+ } //________________________________
+
+ /**
+ * Assemble the SQL statement to update the field
+ * in the "inProcessField" parameter
+ *
+ * in the table row uniquely identified by the list of fields
+ * in the "keyFields" parameter
+ *
+ * @return - The resulting SQL statement
+ */
+ protected String updateStatement()
+ {
+ StringBuilder sb = new StringBuilder ()
+ .append("update ").append(m_oVals.get(TABLE_ATT.tableName.toString()))
+ .append(" set ") .append(m_oVals.get(TABLE_ATT.inProcessField.toString()))
+ .append(" = ? where ")
+ ;
+ int iCurr = 0;
+ for(String sCurr : m_saKeys)
+ { if (iCurr++ > 0)
+ sb.append(" and ");
+ sb.append(sCurr).append(" = ?");
+ }
+ return sb.toString();
+ } //________________________________
+
+ /**
+ * Assemble the SQL "select for update" statement
+ * for the "inProcessField" parameter
+ *
+ * in the table row uniquely identified by the list of fields
+ * in the "keyFields" parameter
+ *
+ * @return - The resulting SQL statement
+ */
+ protected String selectForUpdStatement()
+ {
+ StringBuilder sb = new StringBuilder ()
+ .append("select ").append(m_oVals.get(TABLE_ATT.inProcessField.toString()))
+ .append(" from ") .append(m_oVals.get(TABLE_ATT.tableName.toString()))
+ .append(" where ")
+ ;
+ int iCurr = 0;
+ for(String sCurr : m_saKeys)
+ { if (iCurr++ > 0)
+ sb.append(" and ");
+ sb.append(sCurr).append(" = ?");
+ }
+ return sb.append(" for update").toString();
+ } //________________________________
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#close()
+ */
+ @Override
+ protected void close() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingError(java.lang.Object, org.jboss.soa.esb.actions.ActionProcessor, java.lang.Throwable)
+ */
+ @Override
+ protected void processingError(Object initialMessage, ActionProcessor processor, Throwable error) {
+ // Mark the row as "error"...
+ ((SQLPollResult)initialMessage).changeStatusToError();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingComplete(java.lang.Object)
+ */
+ @Override
+ protected void processingComplete(Object initialMessage) {
+ // Mark the row as "working"...
+ ((SQLPollResult)initialMessage).changeStatusToDone();
+ }
+
+ private class SQLPollResult extends LinkedHashMap implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String sUpdStates;
+
+ private String[] saKeys;
+
+ private String sSel4Upd, sUpdate;
+
+ private SQLPollResult(String sSel4Upd, String sUpdate) throws Exception {
+ this.sSel4Upd = sSel4Upd;
+ this.sUpdate = sUpdate;
+ }
+
+ private String getStatus(ROW_STATE p_oState) {
+ int iPos = p_oState.ordinal();
+ return sUpdStates.substring(iPos, ++iPos);
+ }
+
+ private boolean changeStatusToWorking() {
+ return changeStatus(ROW_STATE.Pending, ROW_STATE.Working);
+ }
+
+ private boolean changeStatusToDone() {
+ return changeStatus(ROW_STATE.Working, ROW_STATE.Done);
+ }
+
+ private boolean changeStatusToError() {
+ return changeStatus(ROW_STATE.Working, ROW_STATE.Error);
+ }
+
+ private boolean changeStatus(ROW_STATE fromState, ROW_STATE toState) {
+ JdbcCleanConn dbConnection = null;
+
+ try {
+ // This is expensive at the moment but will be OK once we get proper connection pooling enabled!
+ dbConnection = newDbConn();
+ } catch (Exception e) {
+ logger.error("Unable to get DB connection.", e);
+ throw new IllegalStateException("Unable to get DB connection.", e);
+ }
+
+ try {
+ PreparedStatement m_PSsel4U;
+ PreparedStatement m_PSupd;
+
+ m_PSsel4U = dbConnection.prepareStatement(sSel4Upd);
+ m_PSupd = dbConnection.prepareStatement(sUpdate);
+
+ int iParm=1;
+ for (String sColName : saKeys) {
+ Object oVal = get(sColName);
+ m_PSsel4U.setObject (iParm ,oVal);
+ // parameters are +1 in update statement
+ // autoincrement leaves things ready for next SQL parameter
+ m_PSupd.setObject (++iParm,oVal);
+ }
+
+ try {
+ ResultSet resultSet = dbConnection.execQueryWait(m_PSsel4U, 5);
+
+ if (resultSet.next()) {
+ String sOldStatus = resultSet.getString(1).substring(0, 1);
+
+ if (sOldStatus.equalsIgnoreCase(getStatus(fromState))) {
+ m_PSupd.setString(1, getStatus(toState));
+ dbConnection.execUpdWait(m_PSupd, 5);
+ dbConnection.commit();
+
+ if(logger.isDebugEnabled()) {
+ logger.debug("Successfully changed row state from " + fromState + " to " + toState + ".");
+ }
+
+ return true;
+ } else {
+ logger.warn("Cannot change row state from " + fromState + " to " + toState + ". Row not in state " + fromState);
+ return false;
+ }
+ }
+ logger.error("Row status change to " + toState + " has failed. Rolling back!!");
+ } catch(Exception e) {
+ logger.error("Row status change to " + toState + " has failed. Rolling back!!", e);
+ }
+
+ try {
+ dbConnection.rollback();
+ } catch (Exception e) {
+ logger.error("Unable to rollback row status change to " + fromState.name(), e);
+ }
+ } catch (Exception e) {
+ logger.error("Unexpected exception.", e);
+ } finally {
+ dbConnection.release();
+ }
+
+ return false;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/Constants.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/Constants.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/Constants.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,41 @@
+/*
+* 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.nagios;
+
+/**
+ * A few constant values synchronized from the C NSCA client/server source.
+ */
+public class Constants {
+
+ public static final int TRANSMITTED_IV_SIZE = 128;
+
+ public static final int MAX_HOSTNAME_LENGTH = 64;
+ public static final int MAX_DESCRIPTION_LENGTH = 128;
+ public static final int MAX_PLUGINOUTPUT_LENGTH = 512;
+
+ public static final int NSCA_PACKET_VERSION_3 = 3;
+
+ public static final String FICTICIOUS_TEST_HOST = "ficticious.test.host";
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/MonitorManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/MonitorManager.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/MonitorManager.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,206 @@
+/*
+* 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.nagios;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
+
+import org.jboss.soa.esb.nagios.monitor.ServiceMonitor;
+import org.jboss.soa.esb.nagios.transport.NagiosNSCAPacket;
+import org.jboss.soa.esb.nagios.transport.NagiosNSCATransport;
+
+/**
+ * The MonitorManager is the core of the Java Nagios client software. It provides
+ * the infrastructure for reporting information and the background process for sending
+ * those reports to the NSCA daemon process on the Nagios server.
+ *
+ * When instantiated without a valid nagiosHost, it will sit and do nothing until a
+ * host has been provided - at which point it will begin cycling to send information
+ * to that Nagios server.
+ *
+ * The no-argument constructer is used in JMX environments where JMX systems aren't
+ * able to initialize the MonitorManager except through calling Setter methods for
+ * the core parameters such as nagiosHost.
+ *
+ * Typical usage in stand-alone applications:
+ *
+ * MonitorManager mm = new MonitorManager("XXXXXXXXXXXX", 5667);
+ * ServiceMonitor heartbeat = new HeartbeatMonitor("hostname", "servicename");
+ * mm.addMonitor(heartbeat);
+ * mm.start();
+ */
+public class MonitorManager {
+
+ // LOCK object for synchronization
+ private final Object LOCK = new Object();
+
+ private final Logger logger_
+ = Logger.getLogger(MonitorManager.class.getName());
+ private final List monitors_ = new ArrayList();
+ private final BackgroundTask backgroundTask_ = new BackgroundTask();
+ private Thread backgroundThread_ = null;
+
+ private String nagiosHost = null;
+ private int nagiosPort = 0;
+
+ private long SLEEP_INTERVAL = 5000; // millisecond sleep time between checks
+
+ public MonitorManager() {
+ init();
+ }
+
+ public MonitorManager(String nagiosHost, int nagiosPort) {
+ this.nagiosHost = nagiosHost;
+ this.nagiosPort = nagiosPort;
+ init();
+ }
+
+ private void init() {
+ logger_.setLevel(Level.ALL);
+ ConsoleHandler conh = new ConsoleHandler();
+ SimpleFormatter form = new SimpleFormatter();
+ conh.setFormatter(form);
+ logger_.addHandler(conh);
+ }
+
+ public String getStatus() {
+ if (backgroundTask_.running) {
+ return "Running - cycle "+backgroundTask_.CYCLE;
+ } else {
+ return "Stopped";
+ }
+ }
+
+ public String getNagiosHost() {
+ return nagiosHost;
+ }
+
+ public void setNagiosHost(String nagiosHost) {
+ this.nagiosHost = nagiosHost;
+ }
+
+ public int getNagiosPort() {
+ return nagiosPort;
+ }
+
+ public void setNagiosPort(int nagiosPort) {
+ this.nagiosPort = nagiosPort;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void addMonitor(ServiceMonitor monitor) {
+ monitors_.add(monitor);
+ }
+
+ public void removeMonitor(ServiceMonitor monitor) {
+ monitors_.remove(monitor);
+ }
+
+ public void start() {
+ synchronized (LOCK) {
+ if (backgroundThread_ == null) {
+ backgroundThread_ = new Thread(backgroundTask_);
+ }
+ }
+ if (!backgroundThread_.isAlive()) {
+ backgroundTask_.running = true;
+ backgroundTask_.CYCLE = 0;
+ backgroundThread_.start();
+ }
+ }
+
+ public void stop() {
+ if (backgroundThread_ != null && backgroundThread_.isAlive()) {
+ backgroundTask_.stop();
+ }
+ try {
+ backgroundThread_.join();
+ backgroundThread_ = null;
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public long getInterval() {
+ return SLEEP_INTERVAL;
+ }
+
+ public void setInterval(long interval) {
+ SLEEP_INTERVAL = interval;
+ }
+
+ protected class BackgroundTask implements Runnable {
+
+ private boolean running = true;
+ private int CYCLE = 0;
+
+ public void run() {
+
+ System.out.println("Nagios Background Monitor thread started.");
+
+ while (running) {
+ try {
+
+ Thread.sleep(SLEEP_INTERVAL);
+ CYCLE++;
+
+ if (nagiosHost != null) {
+
+ final Iterator iter = monitors_.iterator();
+
+ while (iter.hasNext()) {
+ final ServiceMonitor monitor = (ServiceMonitor) iter.next();
+ @SuppressWarnings("unused")
+ final ServiceResponse response = monitor.getResponse();
+ final NagiosNSCAPacket packet =
+ new NagiosNSCAPacket(monitor.getHost()
+ , monitor.getService()
+ , monitor.getResponse());
+ if (nagiosHost != Constants.FICTICIOUS_TEST_HOST)
+ NagiosNSCATransport.send(nagiosHost, nagiosPort, packet);
+ }
+
+ }
+
+ } catch (InterruptedException e) {
+ // ok if interrupted
+ }
+ }
+
+ running = false;
+ System.out.println("Nagios Background Monitor thread exiting.");
+
+ }
+
+ public void stop() {
+ running = false;
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/NagiosAgent.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/NagiosAgent.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/NagiosAgent.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,97 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+
+package org.jboss.soa.esb.nagios;
+
+import org.jboss.soa.esb.nagios.monitor.MemoryMonitor;
+import org.jboss.soa.esb.nagios.monitor.ServiceMonitor;
+
+public class NagiosAgent implements NagiosAgentMBean {
+
+ private static final MonitorManager monitor_ = new MonitorManager();
+ private ServiceMonitor service_ = null;
+
+ private static final String DEFAULT_HOST = "javatest";
+ private static final String DEFAULT_SERVICE = "java-heartbeat-service";
+
+ private String host = DEFAULT_HOST;
+ private String service = DEFAULT_SERVICE;
+
+ public NagiosAgent() {
+ service_ = new MemoryMonitor(host, service);
+ monitor_.addMonitor(service_);
+ }
+
+ public void start() {
+ monitor_.start();
+ }
+
+ public void stop() {
+ monitor_.stop();
+ }
+
+ public int getPort() {
+ return monitor_.getNagiosPort();
+ }
+
+ public void setPort(int port) {
+ monitor_.setNagiosPort(port);
+ }
+
+ public String getServer() {
+ return monitor_.getNagiosHost();
+ }
+
+ public void setServer(String host) {
+ monitor_.setNagiosHost(host);
+ }
+
+ public long getInterval() {
+ return monitor_.getInterval();
+ }
+
+ public void setInterval(long interval) {
+ monitor_.setInterval(interval);
+ }
+
+ public String getStatus() {
+ return monitor_.getStatus();
+ }
+
+ public String getHost() {
+ return service_.getHost();
+ }
+
+ public void setHost(String host) {
+ service_.setHost(host);
+ }
+
+ public String getService() {
+ return service_.getService();
+ }
+
+ public void setService(String service) {
+ service_.setService(service);
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/NagiosAgentMBean.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/NagiosAgentMBean.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/NagiosAgentMBean.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,48 @@
+/*
+* 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.nagios;
+
+public interface NagiosAgentMBean {
+
+ public void start();
+ public void stop();
+
+ public String getHost();
+ public void setHost(String host);
+
+ public String getService();
+ public void setService(String service);
+
+ public String getServer();
+ public void setServer(String server);
+
+ public int getPort();
+ public void setPort(int port);
+
+ public long getInterval();
+ public void setInterval(long interval);
+
+ public String getStatus();
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/Runner.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/Runner.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/Runner.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,58 @@
+/*
+ * 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.nagios;
+
+import org.jboss.soa.esb.common.ModulePropertyManager;
+
+/*
+ * Do we still need this stuff?
+ *
+ * TODO
+ */
+
+public class Runner
+{
+ /*
+ * Leave properties here until we determine their utility.
+ */
+
+ private static final String MONITOR_PROP = "org.jboss.soa.esb.nagios.monitor.host";
+
+ private static final String DEFAULT_HOST = "localhost";
+
+ public static void main(String[] args)
+ {
+
+ NagiosAgent agent = new NagiosAgent();
+ agent.setInterval(5000);
+ String sNagiosMonitor = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(
+ MONITOR_PROP, DEFAULT_HOST);
+ agent.setHost(sNagiosMonitor);
+ agent.setPort(5667);
+
+ agent.start();
+
+ while (true)
+ ;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/ServiceResponse.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/ServiceResponse.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/ServiceResponse.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,56 @@
+/*
+* 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.nagios;
+
+/**
+ * Holder class for response information from a monitored service
+ */
+public class ServiceResponse {
+
+ private int returncode = 0;
+ private String message = null;
+
+ public ServiceResponse(int returncode, String message) {
+ this.returncode = returncode;
+ this.message = message;
+ }
+
+ public ServiceResponse() {}
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public int getReturncode() {
+ return returncode;
+ }
+
+ public void setReturncode(int returncode) {
+ this.returncode = returncode;
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/HeartbeatMonitor.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/HeartbeatMonitor.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/HeartbeatMonitor.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,64 @@
+/*
+* 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.nagios.monitor;
+
+import org.jboss.soa.esb.nagios.ServiceResponse;
+
+public class HeartbeatMonitor implements ServiceMonitor {
+
+ private static int CYCLE = 0;
+
+ private String host;
+ private String service;
+
+ public HeartbeatMonitor(String host, String service) {
+ this.host = host;
+ this.service = service;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getService() {
+ return service;
+ }
+
+ public void setService(String service) {
+ this.service = service;
+ }
+
+ public ServiceResponse getResponse() {
+ ServiceResponse sr = new ServiceResponse();
+ sr.setReturncode(0);
+ sr.setMessage("Service heartbeat - index " + (++CYCLE));
+ return sr;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/MemoryMonitor.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/MemoryMonitor.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/MemoryMonitor.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,66 @@
+/*
+* 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.nagios.monitor;
+
+import org.jboss.soa.esb.nagios.ServiceResponse;
+
+public class MemoryMonitor implements ServiceMonitor {
+
+// private static int CYCLE = 0;
+
+ private String host;
+ private String service;
+
+ public MemoryMonitor(String host, String service) {
+ this.host = host;
+ this.service = service;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getService() {
+ return service;
+ }
+
+ public void setService(String service) {
+ this.service = service;
+ }
+
+ public ServiceResponse getResponse() {
+ ServiceResponse sr = new ServiceResponse();
+ sr.setReturncode(0);
+ long free = Runtime.getRuntime().freeMemory();
+ long total = Runtime.getRuntime().totalMemory();
+ long max = Runtime.getRuntime().maxMemory();
+ sr.setMessage("Java Memory Status (free/total/max) = "+free+"/"+total+"/"+max);
+ return sr;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/ServiceMonitor.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/ServiceMonitor.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/monitor/ServiceMonitor.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+
+package org.jboss.soa.esb.nagios.monitor;
+
+import org.jboss.soa.esb.nagios.ServiceResponse;
+
+public interface ServiceMonitor
+{
+ public ServiceResponse getResponse();
+
+ public String getHost();
+ public void setHost(String host);
+
+ public String getService();
+ public void setService(String service);
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/NagiosNSCAPacket.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/NagiosNSCAPacket.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/NagiosNSCAPacket.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,161 @@
+/*
+* 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.nagios.transport;
+
+
+import org.jboss.soa.esb.nagios.Constants;
+import org.jboss.soa.esb.nagios.ServiceResponse;
+import org.jboss.soa.esb.nagios.util.ByteOps;
+
+
+/**
+ * Representation of a Nagios NSCA data packet. The C implementation of Nagios NSCA uses a struct to represent this data. This class
+ * constructs a byte array that mirrors that struct. There are some tricky bits here that may need adjustment for new versions of
+ * Java, new versions of GCC, or different versions of the Nagios NSCA daemon process compiled on different hardware architectures.
+ */
+public class NagiosNSCAPacket {
+
+ private long timestamp;
+ private int returncode;
+ private String host;
+ private String servicename;
+ private String message;
+
+ /**
+ * Construct a new packet with the provided information
+ *
+ * @param timestamp
+ * use the one provided upon first connection unless time on server and client are accurately synchronized
+ * @param returncode
+ * the returncode of the check
+ * @param host
+ * the Nagios host name we are reporting for
+ * @param servicename
+ * the Nagios service name we are reporting for
+ * @param message
+ * a message to Nagios from the monitor
+ */
+ public NagiosNSCAPacket(long timestamp, int returncode, String host, String servicename, String message) {
+ this.timestamp = timestamp;
+ this.returncode = returncode;
+ this.host = host;
+ this.servicename = servicename;
+ this.message = message;
+ }
+
+ public NagiosNSCAPacket(String host, String servicename, ServiceResponse response) {
+ this.host = host;
+ this.servicename = servicename;
+ this.returncode = response.getReturncode();
+ this.message = response.getMessage();
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public int getReturncode() {
+ return returncode;
+ }
+
+ public void setReturncode(int returncode) {
+ this.returncode = returncode;
+ }
+
+ public String getServicename() {
+ return servicename;
+ }
+
+ public void setServicename(String servicename) {
+ this.servicename = servicename;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public byte[] getData() {
+ // 16 bit version
+ // 32 bit crc
+ // 32 bit timestamp
+ // 16 bit returncode
+ // 64 byte hostname
+ // 128 byte description
+ // 512 byte plugin output
+
+ byte[] data = new byte[4 + 4 + 4 + 4 + 64 + 128 + 512];
+
+ // 16 bit version (padded to 32 for C typedef?)
+ ByteOps.copyIntoArray(ByteOps.intToBytes(Constants.NSCA_PACKET_VERSION_3, 2, null, 0), data, 0, 4, false);
+
+ // 32 bit crc goes in last
+
+ // 32 bit timestamp (in Unix epoch format)
+ int epoch = (int) (timestamp / 1000);
+ ByteOps.copyIntoArray(ByteOps.intToBytes(epoch, 4, null, 0), data, 8, 4, false);
+
+ // 16 bit returncode (padded to 32 for C typedef?)
+ ByteOps.copyIntoArray(ByteOps.intToBytes(returncode, 2, null, 0), data, 12, 4, false);
+
+ // 64 byte hostname
+ ByteOps.copyIntoArray(host.getBytes(), data, 14, Constants.MAX_HOSTNAME_LENGTH, true);
+
+ // 128 byte description
+ ByteOps.copyIntoArray(servicename.getBytes(), data, 14 + 64, Constants.MAX_DESCRIPTION_LENGTH, true);
+
+ // 512 byte plugin output
+ ByteOps.copyIntoArray(message.getBytes(), data, 14 + 64 + 128, Constants.MAX_PLUGINOUTPUT_LENGTH, true);
+
+ // 32 bit crc
+ clearChecksumInPacket(data);
+ long crc = org.jboss.soa.esb.nagios.util.CRC32.calculate(data);
+ ByteOps.copyIntoArray(ByteOps.longToBytes(crc, 4, null, 0), data, 4, 4, false);
+
+ return data;
+
+ }
+
+ public static void clearChecksumInPacket(byte[] packet) {
+ packet[4] = 0;
+ packet[5] = 0;
+ packet[6] = 0;
+ packet[7] = 0;
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/NagiosNSCATransport.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/NagiosNSCATransport.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/transport/NagiosNSCATransport.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,115 @@
+/*
+* 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.nagios.transport;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.util.logging.Logger;
+
+import org.jboss.soa.esb.nagios.Constants;
+import org.jboss.soa.esb.nagios.util.ByteOps;
+
+/**
+ * Transport class sends the data string from the monitor into the Nagios NSCA
+ * monitor
+ */
+public class NagiosNSCATransport {
+
+ private static final Logger logger_
+ = Logger.getLogger(NagiosNSCATransport.class.getName());
+
+ /**
+ * Transport a packet to the Nagios server
+ *
+ * @param host
+ * @param port
+ * @param message
+ */
+ public static void send(String host, int port, NagiosNSCAPacket packet) {
+
+ Socket socket = null;
+
+ try {
+
+ logger_.fine("Connecting to " + host + " : " + port);
+
+ socket = new Socket(host, port);
+ InputStream in = socket.getInputStream();
+
+ // Read IV data from socket on initial connect
+ byte[] data = new byte[Constants.TRANSMITTED_IV_SIZE];
+ readBytes(data, in);
+
+ // Read timestamp data from socket
+ byte[] tsdata = new byte[4];
+ readBytes(tsdata, in);
+
+ long timestamp = (long) ByteOps.bytesToInt(tsdata, 0, 4) * 1000;
+
+ logger_.finest("Got timestamp " + timestamp);
+ packet.setTimestamp(timestamp);
+
+ OutputStream out = socket.getOutputStream();
+
+ byte[] pdata = packet.getData();
+
+ logger_.finest("Writing packet length " + pdata.length
+ + " with message: " + packet.getMessage());
+
+ out.write(pdata);
+
+ out.flush();
+
+ out.close();
+ socket.close();
+
+ logger_.finest("Done.");
+
+ } catch (Exception e) {
+ logger_.severe("Failure transmitting packet to Nagios (host="+host+", port="+port+" - " + e.getMessage());
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Fills the provided byte array with bytes from the InputStream
+ *
+ * @param data array to fill
+ * @param in input stream
+ * @throws IOException
+ */
+ public static void readBytes(byte[] data, InputStream in)
+ throws IOException {
+ int total = 0;
+ while (total < data.length) {
+ int readlen = in.read(data, total, data.length - total);
+ if (readlen == -1) throw new IOException("Unable to read!");
+ total += readlen;
+ }
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/ByteOps.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/ByteOps.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/ByteOps.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,123 @@
+/*
+* 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.nagios.util;
+
+/**
+ * Byte manipulation utility methods
+ */
+public class ByteOps {
+
+ /**
+ * Convert portion of an array of bytes into an int
+ *
+ * @param b byte array containing data
+ * @param offset offset into array to start conversion
+ * @param size number of bytes in array to use for conversion
+ * @return the int value
+ */
+ public static int bytesToInt(byte[] b, int offset, int size) {
+ int num = 0;
+ int sw = 8 * (size - 1);
+
+ for (int loop = 0; loop < size; loop++) {
+ num |= ((int) b[offset + loop] & 0x00ff) << sw;
+ sw -= 8;
+ }
+
+ return num;
+ }
+
+ /**
+ * Convert an int to some number of bytes and store them in an array.
+ * If no array is provided (ie null) a new one will be allocated.
+ *
+ * @param num number to convert
+ * @param len length of bytes to use
+ * @param b array to store value into (optional, if null one will be created)
+ * @param offset position in array to store into
+ * @return original array provided, or new array created (if none provided)
+ */
+ public static byte[] intToBytes(int num, int len, byte[] b, int offset) {
+
+ if (b == null) {
+ b = new byte[len];
+ offset = 0;
+ }
+ int sw = ((len - 1) * 8);
+ int mask = (0xff << sw);
+
+ for (int l = 0; l < len; l++) {
+ b[offset + l] = (byte) ((num & mask) >>> sw);
+
+ sw -= 8;
+ mask >>>= 8;
+ }
+
+ return b;
+ }
+
+ public static final byte[] longToBytes(long num, int len, byte[] b,
+ int offset) {
+
+ if (b == null) {
+ b = new byte[len];
+ offset = 0;
+ }
+ long sw = ((len - 1) * 8);
+ long mask = (0xffL << sw);
+
+ for (int l = 0; l < len; l++) {
+ b[offset + l] = (byte) ((num & mask) >>> sw);
+
+ sw -= 8;
+ mask >>>= 8;
+ }
+
+ return b;
+ }
+
+ /**
+ * Convert a long to some number of bytes and store them in an array.
+ * If no array is provided (ie null) a new one will be allocated.
+ *
+ * @param num number to convert
+ * @param len length of bytes to use
+ * @param b array to store value into (optional, if null one will be created)
+ * @param offset position in array to store into
+ * @return original array provided, or new array created (if none provided)
+ */
+ public static void copyIntoArray(byte[] src, byte[] dst, int offset,
+ int length, boolean terminator) {
+
+ for (int i = 0; i < length && i < src.length && i + offset < dst.length; i++) {
+ if (i + offset < dst.length)
+ dst[i + offset] = src[i];
+ }
+
+ if (terminator && offset + length + 1 < dst.length)
+ dst[offset + length + 1] = 0;
+
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/CRC32.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/CRC32.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/src/org/jboss/soa/esb/nagios/util/CRC32.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,89 @@
+/*
+* 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.nagios.util;
+
+/**
+ * CRC32 Implementation
+ *
+ * Uses lazy-initialization technique, and pre-built value table
+ * for accelerating calculations.
+ */
+public class CRC32 {
+
+ /**
+ * Internal use only, initialization locking.
+ */
+ private static final Object LOCK = new Object();
+
+ /**
+ * Internal use only, pre-computed value table.
+ */
+ private static long[] crc32_table = null;
+
+ /**
+ * Internal use only, initialize pre-computed value table. There is no
+ * need to call this directly.
+ */
+ private static void init() {
+ synchronized (LOCK) {
+ if (crc32_table == null) {
+ // Initialize CRC value table
+ crc32_table = new long[256];
+ long crc, poly;
+ int i, j;
+ poly = 0xEDB88320L;
+ for (i = 0; i < 256; i++) {
+ crc = i;
+ for (j = 8; j > 0; j--) {
+ if ((crc & 1) > 0) {
+ crc = (crc >> 1) ^ poly;
+ } else {
+ crc >>= 1;
+ }
+ }
+ crc32_table[i] = crc;
+ }
+ }
+ }
+ }
+
+ /**
+ * Compute the CRC32 checksum of the provided byte array buffer.
+ * @param buffer - the buffer on which to do the computation
+ * @return the calculated CRC32 checksum
+ */
+ public static long calculate(byte[] buffer) {
+ init();
+ long crc;
+ int this_char;
+ int current_index;
+ crc = 0xFFFFFFFF;
+ for (current_index = 0; current_index < buffer.length; current_index++) {
+ this_char = (int) buffer[current_index];
+ crc = ((crc >> 8) & 0x00FFFFFF)
+ ^ crc32_table[((int)crc ^ this_char) & 0xFF];
+ }
+ return (crc ^ 0xFFFFFFFF);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/build.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/build.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,130 @@
+<?xml version="1.0"?>
+<project name="build.listeners.tests" default="org.jboss.esb.listeners.tests.compile" basedir=".">
+
+ <property name="org.jboss.esb.module.src.dir" value="../src"/>
+ <property name="org.jboss.esb.module.classes.root.dir" value="${org.jboss.esb.internal.dest}/classes"/>
+ <property name="org.jboss.esb.module.classes.dir" value="${org.jboss.esb.internal.dest}/classes/listeners"/>
+ <property name="org.jboss.esb.module.tests.src.dir" value="${basedir}/src"/>
+ <property name="org.jboss.esb.tests.classes.dir" value="${org.jboss.esb.internal.dest}/tests"/>
+ <property name="org.jboss.esb.tests.report.dir" value="${org.jboss.esb.internal.dest}/tests/junit"/>
+ <property name="org.jboss.esb.root.dir" value="../.."/>
+ <property name="org.jboss.esb.ejb3_embedded.lib.dir" value="${org.jboss.esb.root.dir}/../lib/ext/ejb3_embedded"/>
+ <property name="org.jboss.esb.module.tests.conf.dir" value="${org.jboss.esb.root.dir}/listeners/tests/resources/conf"/>
+
+ <property environment="env"/>
+
+ <property name="org.jboss.esb.ext.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext"/>
+
+ <condition property="org.jboss.esb.ext.lib.dir" value="{org.jboss.esb.jboss.home}/client">
+ <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
+ </condition>
+
+ <path id="org.jboss.esb.tests.base.classpath">
+
+ <fileset dir="../${org.jboss.esb.ext.lib.dir}" includes="*.jar"/>
+ <pathelement location="${org.jboss.esb.module.classes.root.dir}/rosetta"/>
+ <pathelement location="${org.jboss.esb.module.classes.root.dir}/services"/>
+ <pathelement location="${org.jboss.esb.module.classes.dir}"/>
+ <pathelement location="${org.jboss.esb.module.tests.conf.dir}"/>
+ <!-- Needed as the listeners import javax.jms.* -->
+ <fileset dir="${org.jboss.esb.ejb3_embedded.lib.dir}" includes="jboss-ejb3-all.jar hibernate-all.jar thirdparty-all.jar"/>
+
+ <!--
+ <fileset dir="../${org.jboss.esb.ext.lib.dir}"
+ includes="activation.jar jbossall-client.jar log4j.jar mail.jar junit.jar emma.jar emma_ant.jar"/>
+ <pathelement location="${org.jboss.esb.module.classes.dir}"/>
+ -->
+ </path>
+
+ <target name="org.jboss.esb.tests.init">
+ <tstamp>
+ <format property="TODAY" pattern="d-MM-yy"/>
+ </tstamp>
+
+ <mkdir dir="${org.jboss.esb.tests.classes.dir}"/>
+ <mkdir dir="${org.jboss.esb.tests.report.dir}"/>
+ </target>
+
+ <target name="clean"/>
+
+ <target name="purge" depends="clean">
+ <delete dir="${org.jboss.esb.tests.classes.dir}"/>
+ </target>
+
+ <target name="org.jboss.esb.listeners.tests.compile" if="org.jboss.esb.buildtests" depends="org.jboss.esb.tests.init">
+
+ <javac
+ destdir="${org.jboss.esb.tests.classes.dir}"
+ classpathref="org.jboss.esb.tests.base.classpath"
+ debug="${org.jboss.esb.debug}"
+ optimize="${org.jboss.esb.optimize}"
+ >
+ <src path="${org.jboss.esb.module.tests.src.dir}"/>
+ </javac>
+
+ </target>
+
+ <!-- ====================================================================== -->
+ <!-- T E S T -->
+ <!-- ====================================================================== -->
+ <target name="org.jboss.esb.listeners.internal.test">
+ <property name="org.jboss.esb.module.tests.coverage.dir" value="${org.jboss.esb.internal.dest}/tests/coverage/listeners"/>
+ <property name="org.jboss.esb.module.classes.instr.dir" value="${org.jboss.esb.module.tests.coverage.dir}/instr" />
+
+ <!-- Instrument the code for code coverage - using emma... -->
+ <delete dir="${org.jboss.esb.module.tests.coverage.dir}" />
+ <mkdir dir="${org.jboss.esb.module.tests.coverage.dir}" />
+ <emma>
+ <instr instrpath="${org.jboss.esb.module.classes.dir}"
+ destdir="${org.jboss.esb.module.classes.instr.dir}"
+ metadatafile="${org.jboss.esb.module.tests.coverage.dir}/coverage.emma" />
+ </emma>
+ <!-- Run the tests -->
+ <antcall target="org.jboss.esb.services.internal.test.exec"/>
+
+ <!-- Generate the coverage report -->
+ <emma>
+ <report sourcepath="${org.jboss.esb.module.src.dir}" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">
+ <fileset dir="${org.jboss.esb.module.tests.coverage.dir}" >
+ <include name="*.emma" />
+ </fileset>
+ <html outfile="${org.jboss.esb.module.tests.coverage.dir}/index.html" depth="method" columns="name,line,class,method,block"/>
+ </report>
+ </emma>
+ </target>
+
+ <!-- ====================================================================== -->
+ <!-- U N I T A N D F U N C T I O N A L T E S T S -->
+ <!-- ====================================================================== -->
+ <target name="org.jboss.esb.services.internal.test.exec">
+ <echo message="Running tests for module"/>
+ <junit printsummary="yes" haltonerror="yes" haltonfailure="yes" showoutput="no" fork="true">
+ <formatter type="plain" usefile="false"/>
+ <formatter type="xml"/>
+ <batchtest todir="${org.jboss.esb.tests.report.dir}">
+ <fileset dir="${org.jboss.esb.module.tests.src.dir}">
+ <include name="**/**UnitTest.java"/>
+ <include name="**/**FuncTest.java"/>
+ </fileset>
+ </batchtest>
+ <classpath>
+ <!-- using instrumented code for code coverage -->
+ <pathelement location="${org.jboss.esb.module.classes.instr.dir}"/>
+ <pathelement location="${org.jboss.esb.tests.classes.dir}"/>
+ <!-- Need the tests src folder because there may be non-compiled test resources -->
+ <pathelement location="${org.jboss.esb.module.tests.src.dir}"/>
+ <path refid="org.jboss.esb.tests.base.classpath"/>
+ </classpath>
+ <!-- emma jvm args -->
+ <jvmarg value="-Demma.coverage.out.file=${org.jboss.esb.module.tests.coverage.dir}/coverage.emma" />
+ <jvmarg value="-Demma.coverage.out.merge=true" />
+ </junit>
+ <junitreport>
+ <fileset dir="${org.jboss.esb.tests.report.dir}">
+ <include name="*.xml"/>
+ </fileset>
+ <report format="frames" todir="${org.jboss.esb.tests.report.dir}"/>
+ <report format="noframes" todir="${org.jboss.esb.tests.report.dir}"/>
+ </junitreport>
+ </target>
+</project>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/resources/conf/log4j.properties
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/resources/conf/log4j.properties 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/resources/conf/log4j.properties 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,7 @@
+### direct log messages to stdout ###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+### set log levels - for more verbose logging change 'info' to 'debug' ###
+log4j.rootLogger=info, stdout
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/device-profile.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/device-profile.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/device-profile.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE device-profiles PUBLIC "-//MILYN//DTD TINAK 1.0//EN" "http://www.milyn.org/dtd/device-profile-1.0.dtd">
+
+<device-profiles>
+ <device-profile name="type:Acme-Order-XML" list="profile1,profile2"/>
+ <device-profile name="from:Acme" list="profile23,profile24"/>
+ <device-profile name="to:AcmePartner" list="profile55,profile56"/>
+
+ <device-profile name="profile1" list="A"/>
+ <device-profile name="profile2" list="B"/>
+ <device-profile name="profile23" list="C"/>
+ <device-profile name="profile24" list="D"/>
+ <device-profile name="profile55" list="E"/>
+ <device-profile name="profile56" list="E"/>
+</device-profiles>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-01.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-01.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-01.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,16 @@
+ <Actions>
+ <Action name="ActionA" processor="TestActionProcessor1">
+ <property name="param1" value="val1" />
+ <property name="param2" value="val2" />
+ <property name="param3" value="val3" />
+ </Action>
+ <Action name="ActionB" processor="TestActionProcessor1">
+ <property name="param1" value="val2" />
+ </Action>
+ <Action name="ActionC" processor="TestActionProcessor2" />
+
+ <ProcessorAliases>
+ <Alias name="TestActionProcessor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ <Alias name="TestActionProcessor2" class="org.jboss.soa.esb.actions.TestActionProcessor2" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-02.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-02.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-02.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,9 @@
+ <Actions>
+ <Action name="" processor="TestActionProcessor1">
+ <property name="param1" value="val1" />
+ </Action>
+
+ <ProcessorAliases>
+ <Alias name="TestActionProcessor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-03.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-03.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-03.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,9 @@
+ <Actions>
+ <Action name="ActionA" processor="">
+ <property name="param1" value="val1" />
+ </Action>
+
+ <ProcessorAliases>
+ <Alias name="TestActionProcessor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-04.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-04.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-04.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,9 @@
+ <Actions>
+ <Action name="ActionA" processor="TestActionProcessor1">
+ <property name="" value="val1" />
+ </Action>
+
+ <ProcessorAliases>
+ <Alias name="TestActionProcessor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-05.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-05.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-05.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,9 @@
+ <Actions>
+ <Action name="ActionA" processor="TestActionProcessor1">
+ <property name="param1" value="" />
+ </Action>
+
+ <ProcessorAliases>
+ <Alias name="TestActionProcessor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-06.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-06.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-06.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,9 @@
+ <Actions>
+ <Action name="ActionA" processor="UnknownHandle1">
+ <property name="param1" value="val1" />
+ </Action>
+
+ <ProcessorAliases>
+ <Alias name="TestActionProcessor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-07.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-07.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-07.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,9 @@
+ <Actions>
+ <Action name="ActionA" processor="TestActionProcessor1">
+ <property name="param1" value="val1" />
+ </Action>
+
+ <ProcessorAliases>
+ <Alias name="" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-08.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-08.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-08.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,6 @@
+ <Actions>
+
+ <ProcessorAliases>
+ <Alias name="TestActionProcessor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-09.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-09.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-09.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,5 @@
+ <Actions>
+ <Action name="ActionA" processor="TestActionProcessor1">
+ <property name="param1" value="val1" />
+ </Action>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-10.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-10.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-10.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,8 @@
+ <Actions>
+ <Action name="ActionA" processor="TestActionProcessor1">
+ <property name="param1" value="val1" />
+ </Action>
+
+ <ProcessorAliases>
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-11.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-11.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinition-Config-11.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,9 @@
+ <Actions>
+ <Action name="ActionA" processor="TestActionProcessor1">
+ <property name="param1" value="val1" />
+ </Action>
+
+ <ProcessorAliases>
+ <Alias name="TestActionProcessor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinitionFactoryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinitionFactoryUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ActionDefinitionFactoryUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,90 @@
+/*
+ * 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.actions;
+
+import java.io.IOException;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.xml.sax.SAXException;
+
+/**
+ * Unit tests for the ActionDefinitionFactory class.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ActionDefinitionFactoryUnitTest extends TestCase {
+
+ public void test_good_config() throws SAXException, IOException, ConfigurationException {
+ ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("ActionDefinition-Config-01.xml"));
+ ActionDefinitionFactory factory = new ActionDefinitionFactory(config);
+
+ // ActionProcessor Impl with a non-default public constructor
+ ActionDefinition actionDef = factory.getInstance("ActionA");
+ assertEquals("ActionA", actionDef.getName());
+ List<KeyValuePair> properties = actionDef.getProperties();
+ assertEquals(3, properties.size());
+ TestActionProcessor1 processor1 = (TestActionProcessor1) actionDef.getProcessor();
+ assertEquals(actionDef.getName(), processor1.name);
+ assertEquals(properties, processor1.properties);
+
+ actionDef = factory.getInstance("ActionB");
+ assertEquals("ActionB", actionDef.getName());
+ properties = actionDef.getProperties();
+ assertEquals(1, properties.size());
+ processor1 = (TestActionProcessor1) actionDef.getProcessor();
+ assertEquals(actionDef.getName(), processor1.name);
+ assertEquals(properties, processor1.properties);
+
+ // ActionProcessor Impl with a non-default public constructor
+ actionDef = factory.getInstance("ActionC");
+ assertEquals("ActionC", actionDef.getName());
+ //TestActionProcessor2 processor2 = (TestActionProcessor2) actionDef.getProcessor();
+ }
+
+ public void test_bad_config() throws SAXException, IOException, ConfigurationException {
+ test_bad_config("ActionDefinition-Config-02.xml", "Actions/Action has no 'name' defined.");
+ test_bad_config("ActionDefinition-Config-03.xml", "Actions/Action [ActionA] has no 'processor' defined.");
+ test_bad_config("ActionDefinition-Config-04.xml", "Actions/Action/property has no 'name' defined. Action [ActionA]");
+ test_bad_config("ActionDefinition-Config-05.xml", "Actions/Action/property has no 'value' defined. Action [ActionA]");
+ test_bad_config("ActionDefinition-Config-06.xml", "No action processor class defined for processor alias");
+ test_bad_config("ActionDefinition-Config-07.xml", "Actions/ProcessorAliases/Alias has no 'name' defined");
+ test_bad_config("ActionDefinition-Config-08.xml", "No 'Actions/Action' configurations");
+ test_bad_config("ActionDefinition-Config-09.xml", "No 'Actions/ProcessorAliases' configuration");
+ test_bad_config("ActionDefinition-Config-10.xml", "No action processor classes defined");
+ }
+
+ private void test_bad_config(String configName, String exceptionMsg) throws SAXException, IOException, ConfigurationException {
+ ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream(configName));
+ try {
+ new ActionDefinitionFactory(config);
+ fail("Expected ConfigurationException");
+ } catch(ConfigurationException e) {
+ assertTrue("Expected config exception statrting with [" + exceptionMsg + "]. Instead, go [" + e.getMessage() + "]", e.getMessage().startsWith(exceptionMsg));
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/BaseTestActionProcessor.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/BaseTestActionProcessor.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/BaseTestActionProcessor.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Vector;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public abstract class BaseTestActionProcessor implements ActionProcessor {
+
+ public ActionProcessingException exception;
+ public List<Message> processedMessages = new Vector<Message>();
+ public boolean returnNull = false;
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ if(exception != null) {
+ throw exception;
+ }
+
+ processedMessages.add(message);
+
+ if(returnNull) {
+ return null;
+ }
+
+ return message;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(Message message) {
+ return "OK: " + message;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(Message message) {
+ return "ERROR: " + message;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/SmooksTransformerUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,110 @@
+/*
+ * 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.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.converters.SmooksTransformer;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+ * SmooksTransformer unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class SmooksTransformerUnitTest extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ SmooksTransformer.reset();
+ }
+
+ public void test_bad_config() {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ // Should get exceptions where required configs are missing...
+ assertConfigException(properties, "Action configuration 'message-type' not specified");
+ properties.add(new KeyValuePair("message-type", "111"));
+ assertConfigException(properties, "Action configuration 'message-from' not specified");
+ properties.add(new KeyValuePair("message-from", "AAA"));
+ assertConfigException(properties, "Action configuration 'message-to' not specified");
+ properties.add(new KeyValuePair("message-to", "BBB"));
+
+ // Should get an exception where the smooks-cdr.lst file is missing....
+ properties.add(new KeyValuePair("smooks-cdr.list-classpath-prefix", "/some/bad/cp/location/"));
+ assertConfigException(properties, "Failed to locate Smooks configuration list file [smooks-cdr.lst]. The folder containing this file must be located at");
+ }
+
+ public void test_trans() throws ActionProcessingException, ConfigurationException {
+ String stringMessage;
+ String transRes;
+
+ // Very basic test! Just illustrates profile based resource selection.
+ // Read the smooks-test.cdrl config file in this package!!
+
+ // Initialise the acme order message...
+ stringMessage = "<a><ddd>value</ddd></a>";
+
+ // Transform the order message going to "AcmePartner1"...
+ transRes = transform(stringMessage, "Acme-Order-XML", "Acme", "AcmePartner1");
+ assertEquals("<x><b>value</b></x>", transRes);
+
+ // Transform the order message going to "AcmePartner2"...
+ transRes = transform(stringMessage, "Acme-Order-XML", "Acme", "AcmePartner2");
+ assertEquals("<x><c>value</c></x>", transRes);
+ }
+
+ private String transform(String stringMessage, String type, String from, String to) throws ActionProcessingException, ConfigurationException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ // Set the message properties in order to trigger the appropriate transformations
+ // on the message...
+ properties.add(new KeyValuePair("message-type", type));
+ properties.add(new KeyValuePair("message-from", from));
+ properties.add(new KeyValuePair("message-to", to));
+
+ // The smooks-cdr.lst and device-profile.xml files are located in the root of the
+ // test src folder...
+ SmooksTransformer transformer = new SmooksTransformer("trans", properties);
+
+ Message oMsg = MessageFactory.getInstance().getMessage();
+ ActionUtils.setTaskObject(oMsg,stringMessage);
+ oMsg = transformer.process(oMsg);
+ return (String) ActionUtils.getTaskObject(oMsg);
+ }
+
+ private void assertConfigException(List<KeyValuePair> properties, String expectedException) {
+ try {
+ new SmooksTransformer("trans", properties);
+ fail("Expected ConfigurationException: [" + expectedException + "...]");
+ } catch(ConfigurationException e) {
+ assertTrue("Expected exception message to start with [" + expectedException + "]. Was [" + e.getMessage() + "]", e.getMessage().startsWith(expectedException));
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor1.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor1.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor1.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+
+public class TestActionProcessor1 extends BaseTestActionProcessor {
+
+ private static Logger logger = Logger.getLogger(TestActionProcessor1.class);
+ public String name;
+ public List<KeyValuePair> properties;
+
+ public TestActionProcessor1(String name, List<KeyValuePair> properties) {
+ this.name = name;
+ this.properties = properties;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#processAction(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ logger.info("Processing action [" + name + "]: " + ActionUtils.getTaskObject(message));
+ return super.process(message);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor2.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor2.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor2.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,45 @@
+/*
+ * 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.actions;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+
+public class TestActionProcessor2 extends BaseTestActionProcessor {
+
+ private static Logger logger = Logger.getLogger(TestActionProcessor2.class);
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#processAction(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ logger.info("Processing action: " + ActionUtils.getTaskObject(message));
+ return super.process(message);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor3.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor3.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestActionProcessor3.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,45 @@
+/*
+ * 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.actions;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+
+public class TestActionProcessor3 extends BaseTestActionProcessor {
+
+ public TestActionProcessor3(String name) {
+ System.out.println("Instantiate action handler: " + name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#processAction(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ System.out.println("processAction: " + ActionUtils.getTaskObject(message));
+ return super.process(message);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestBean.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestBean.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/TestBean.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions;
+
+/**
+ * Just a simple test JavaBean class.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class TestBean implements java.io.Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private String name;
+ private String phone;
+
+ public TestBean() {
+ }
+ public TestBean(String name, String phone) {
+ this.name = name;
+ this.phone = phone;
+ }
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getPhone() {
+ return phone;
+ }
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ToNowhereRouter.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ToNowhereRouter.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ToNowhereRouter.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,49 @@
+/*
+ * 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.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ToNowhereRouter extends BaseTestActionProcessor {
+
+ public static List<Object> objects = new ArrayList<Object>();
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#processAction(java.lang.Object)
+ */
+ public Message process(Message msg) throws ActionProcessingException {
+ objects.add(ActionUtils.getTaskObject(msg));
+
+ System.out.println("ToNowhereRouter");
+ return msg;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ByteArrayToStringUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ByteArrayToStringUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ByteArrayToStringUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,60 @@
+/*
+ * 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.actions.converters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+ * ByteArrayToString unit tests.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ByteArrayToStringUnitTest extends TestCase
+{
+
+ public void test() throws ActionProcessingException
+ {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ properties.add(new KeyValuePair("encoding", "UTF-8"));
+ ByteArrayToString byteArrayToString = new ByteArrayToString(
+ "actionName", properties);
+
+ String sTest = "TestString";
+ Message msg = MessageFactory.getInstance().getMessage();
+ ActionUtils.setTaskObject(msg,sTest.getBytes());
+ byteArrayToString.process(msg);
+ String decodedBytes = (String)ActionUtils.getTaskObject(msg);
+ assertEquals(sTest, decodedBytes);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/FileToByteArrayUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/FileToByteArrayUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/FileToByteArrayUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,66 @@
+/*
+ * 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.actions.converters;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.actions.ActionProcessingException;
+
+/**
+ * FileToByteArray unit tests.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class FileToByteArrayUnitTest extends TestCase {
+
+ private File testFile = null;
+ private String FILE_CONTENTS = "this is the file contents!";
+
+ @Override
+ protected void setUp() throws Exception {
+ testFile = new File("FileToByteArrayUnitTest.tst");
+
+ FileWriter fileWriter = new FileWriter(testFile);
+
+ fileWriter.write(FILE_CONTENTS);
+ fileWriter.flush();
+ fileWriter.close();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ testFile.delete();
+ }
+
+ public void test() throws IOException, ActionProcessingException {
+ FileToByteArray fileToByteArray = new FileToByteArray();
+ byte[] fileContent = (byte[])fileToByteArray.process(testFile);
+
+ assertEquals(FILE_CONTENTS, new String(fileContent));
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/LongToDateConverter.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/LongToDateConverter.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/LongToDateConverter.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,61 @@
+/*
+ * 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.actions.converters;
+
+import java.util.Date;
+
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.actions.BaseTestActionProcessor;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * LongToDate Converter Test Action Handler.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class LongToDateConverter extends BaseTestActionProcessor
+{
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.soa.esb.actions.ActionProcessor#processAction(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException
+ {
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if (!(oCurr instanceof Long))
+ {
+ throw new ActionProcessingException(
+ "This action handler only accepts Long object instances.");
+ }
+ System.out.println("LongToDateConverter");
+
+ try { ActionUtils.setTaskObject(message,new Date((Long)oCurr)); }
+ catch (Exception e)
+ { throw new ActionProcessingException(e); }
+ return message;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToCSVStringUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToCSVStringUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToCSVStringUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,107 @@
+/*
+ * 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.actions.converters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+ * ObjectToCSVString unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToCSVStringUnitTest extends TestCase {
+
+ public void test() throws ConfigurationException, ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+ Message oMsg = MessageFactory.getInstance().getMessage();
+
+ // Single value - property exist on bean...
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "name"));
+ ObjectToCSVString processor = new ObjectToCSVString("ObjectToCSVString", properties);
+
+ ActionUtils.setTaskObject(oMsg,new TestBean());
+ oMsg = processor.process(oMsg);
+ assertEquals("Tom Fennelly", ActionUtils.getTaskObject(oMsg));
+
+ // Multi value - properties all exist on bean...
+ properties.clear();
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "name,age"));
+ processor = new ObjectToCSVString("ObjectToCSVString", properties);
+ ActionUtils.setTaskObject(oMsg,new TestBean());
+ processor.process(oMsg);
+ assertEquals("Tom Fennelly,21", ActionUtils.getTaskObject(oMsg));
+
+ // Multi value - some properties exist on bean and some don't...
+ properties.clear();
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "id,name,phone,age"));
+ processor = new ObjectToCSVString("ObjectToCSVString", properties);
+ ActionUtils.setTaskObject(oMsg,new TestBean());
+ processor.process(oMsg);
+ assertEquals("<no-such-property>,Tom Fennelly,<no-such-property>,21", ActionUtils.getTaskObject(oMsg));
+
+ // Single value - property doesn't exist on bean...
+ properties.clear();
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "id"));
+ processor = new ObjectToCSVString("ObjectToCSVString", properties);
+ ActionUtils.setTaskObject(oMsg,new TestBean());
+ processor.process(oMsg);
+ assertEquals("<no-such-property>", ActionUtils.getTaskObject(oMsg));
+
+ // Single value - property doesn't exist on bean and "fail-on-missing-property" action config is set on...
+ properties.clear();
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "id"));
+ properties.add(new KeyValuePair(ObjectToCSVString.FAIL_ON_MISSING_PROPERTY, "true"));
+ processor = new ObjectToCSVString("ObjectToCSVString", properties);
+ ActionUtils.setTaskObject(oMsg,new TestBean());
+ try {
+ processor.process(oMsg);
+ fail("Expected ActionProcessingException");
+ } catch(ActionProcessingException e) {
+ assertEquals("Bean method: getId not found/accessible on message object org.jboss.soa.esb.actions.converters.ObjectToCSVStringUnitTest$TestBean", e.getMessage());
+ }
+ }
+
+ public static class TestBean implements java.io.Serializable
+ {
+ private static final long serialVersionUID = 1L;
+ private String name = "Tom Fennelly";
+ private int age = 21; // hehehehe
+
+ public int getAge() {
+ return age;
+ }
+ public String getName() {
+ return name;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToFileWriterUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToFileWriterUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToFileWriterUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,112 @@
+/*
+ * 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.actions.converters;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.actions.routing.ObjectToFileWriter;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+ * Unit tests for ObjectToFileWriter.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToFileWriterUnitTest extends TestCase {
+
+ private static final String A_STRING = "write something to file";
+ private File file = new File("./ObjectToFileWriter.tst");
+ private List<KeyValuePair> properties;
+
+ @Override
+ protected void setUp() throws Exception {
+ properties = new ArrayList<KeyValuePair>();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ file.delete();
+ }
+
+ public void test_writeWithNoAppend() throws ConfigurationException, ActionProcessingException {
+ properties.add(new KeyValuePair("file", file.getPath()));
+
+ // Write something fo file and check it was written..
+ writeAndCheck(A_STRING, A_STRING);
+ // And do it all again to make sure the contents are not appended i.e. the file is overwritten...
+ writeAndCheck(A_STRING, A_STRING);
+ }
+
+ public void test_writeWithBytes() throws ConfigurationException, ActionProcessingException, UnsupportedEncodingException {
+ properties.add(new KeyValuePair("file", file.getPath()));
+
+ // Write bytes to the file...
+ writeAndCheck(A_STRING.getBytes("UTF-8"), A_STRING);
+ }
+
+ public void test_writeWithAppend() throws ConfigurationException, ActionProcessingException {
+ properties.add(new KeyValuePair("file", file.getPath()));
+ properties.add(new KeyValuePair("append", "true"));
+
+ //On windows the file does not get deleted sometimes. Let's clean it out
+ //in that case.
+ try { new FileOutputStream(file).close();}
+ catch (IOException e) { }
+
+ // Write something to file and check it was written..
+ writeAndCheck(A_STRING, A_STRING);
+ // And do it all again to make sure the contents are appended i.e. the file is not overwritten...
+ writeAndCheck(A_STRING, A_STRING + A_STRING);
+ }
+
+
+ private void writeAndCheck(Object objectToWrite, String expected) throws ConfigurationException, ActionProcessingException {
+ // Use the ObjectToFileWriter to write something to file...
+ ObjectToFileWriter fileWriter = new ObjectToFileWriter("ObjectToFileWriter-Test", properties);
+ Message oMsg = MessageFactory.getInstance().getMessage();
+ ActionUtils.setTaskObject(oMsg,objectToWrite);
+ fileWriter.process(oMsg);
+
+ // Use the FileToByteArray processor to read the file contents back...
+ oMsg = MessageFactory.getInstance().getMessage();
+ ActionUtils.setTaskObject(oMsg,file);
+ new FileToByteArray().process(oMsg);
+ byte[] fileContent = (byte[])ActionUtils.getTaskObject(oMsg);
+
+ // Make sure the contents are as expected...
+ String fileContentString = new String(fileContent);
+ assertEquals(expected, fileContentString);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToXStreamUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToXStreamUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/ObjectToXStreamUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,109 @@
+/*
+ * 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.actions.converters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.actions.TestBean;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
+/**
+ * ObjectToXStream unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToXStreamUnitTest extends TestCase {
+
+ public void test_default() throws ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ ObjectToXStream objectToXStream = new ObjectToXStream("TestBean-Serialiser", properties);
+
+ Message oMsg = MessageFactory.getInstance().getMessage();
+ ActionUtils.setTaskObject(oMsg,new TestBean("Tom", "1234"));
+ oMsg = objectToXStream.process(oMsg);
+ String xml = (String)ActionUtils.getTaskObject(oMsg);
+ XStream xstream = new XStream(new DomDriver());
+ TestBean bean = new TestBean();
+
+ assertTrue("Expected [<TestBean>]. Got [" + xml + "]", xml.startsWith("<TestBean>"));
+ xstream.alias("TestBean", TestBean.class);
+ xstream.fromXML(xml, bean);
+
+ assertEquals("Tom", bean.getName());
+ assertEquals("1234", bean.getPhone());
+ }
+
+ public void test_with_package() throws ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ properties.add(new KeyValuePair("exclude-package", "false"));
+ ObjectToXStream objectToXStream = new ObjectToXStream("TestBean-Serialiser", properties);
+
+ Message oMsg = MessageFactory.getInstance().getMessage();
+ ActionUtils.setTaskObject(oMsg,new TestBean("Tom", "1234"));
+ objectToXStream.process(oMsg);
+ String xml = (String)ActionUtils.getTaskObject(oMsg);
+
+ XStream xstream = new XStream(new DomDriver());
+ TestBean bean = new TestBean();
+
+ assertTrue("Expected start with [<" + TestBean.class.getName() + ">]. Got [" + xml + "]", xml.startsWith("<" + TestBean.class.getName() + ">"));
+ xstream.fromXML(xml, bean);
+
+ assertEquals("Tom", bean.getName());
+ assertEquals("1234", bean.getPhone());
+ }
+
+ public void test_with_alias() throws ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ properties.add(new KeyValuePair("class-alias", "TomsClass"));
+ ObjectToXStream objectToXStream = new ObjectToXStream("TestBean-Serialiser", properties);
+
+ Message oMsg = MessageFactory.getInstance().getMessage();
+ ActionUtils.setTaskObject(oMsg,new TestBean("Tom", "1234"));
+ objectToXStream.process(oMsg);
+ String xml = (String)ActionUtils.getTaskObject(oMsg);
+
+ XStream xstream = new XStream(new DomDriver());
+ xstream.alias("TomsClass", TestBean.class);
+ TestBean bean = new TestBean();
+
+ assertTrue("Expected start with [<TomsClass>]. Got [" + xml + "]", xml.startsWith("<TomsClass>"));
+ xstream.fromXML(xml, bean);
+
+ assertEquals("Tom", bean.getName());
+ assertEquals("1234", bean.getPhone());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/StringToLongConverter.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/StringToLongConverter.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/converters/StringToLongConverter.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,52 @@
+/*
+ * 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.actions.converters;
+
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.actions.BaseTestActionProcessor;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * StringToLong Converter Test Action Handler.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class StringToLongConverter extends BaseTestActionProcessor {
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#processAction(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if(!(oCurr instanceof String)) {
+ throw new ActionProcessingException("This action handler only accepts String object instances.");
+ }
+
+ System.out.println("StringToLongConverter");
+ try { ActionUtils.setTaskObject(message,new Long((String)oCurr)); }
+ catch (Exception e)
+ { throw new ActionProcessingException(e); }
+ return message;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/smooks-test.cdrl
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/smooks-test.cdrl 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/actions/smooks-test.cdrl 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,28 @@
+<?xml version='1.0'?>
+<!DOCTYPE smooks-resource-list PUBLIC '-//MILYN//DTD SMOOKS 1.0//EN' 'http://milyn.org/dtd/smooksres-list-1.0.dtd'>
+
+<smooks-resource-list>
+
+ <!--
+ "Acme-Order-XML" messages going from "Acme" to "AcmePartner1"
+ -->
+ <smooks-resource useragent="type:Acme-Order-XML AND from:Acme AND to:AcmePartner1" selector="ddd" path="org.milyn.cdres.trans.RenameElementTU">
+ <param name="replacementElement">b</param>
+ </smooks-resource>
+
+ <!--
+ "Acme-Order-XML" messages going from "Acme" to "AcmePartner2"
+ -->
+ <smooks-resource useragent="type:Acme-Order-XML AND from:Acme AND to:AcmePartner2" selector="ddd" path="org.milyn.cdres.trans.RenameElementTU">
+ <param name="replacementElement">c</param>
+ </smooks-resource>
+
+ <!--
+ "Acme-Order-XML" messages going from "Acme" to anywhere
+ -->
+ <smooks-resource useragent="type:Acme-Order-XML AND from:Acme" selector="a" path="org.milyn.cdres.trans.RenameElementTU">
+ <param name="replacementElement">x</param>
+ </smooks-resource>
+
+</smooks-resource-list>
+
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListenerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListenerUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListenerUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,198 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+
+package org.jboss.soa.esb.listeners.old;
+
+import org.jboss.soa.esb.actions.ActionDefinition;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.actions.BaseTestActionProcessor;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.old.AbstractListener;
+import org.jboss.soa.esb.listeners.old.GpListener;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.util.MockNonblockingListener;
+
+import junit.framework.TestCase;
+
+/**
+ * AbstractListener tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class AbstractListenerUnitTest extends TestCase {
+
+ private MockGpListener gpListener;
+ private ActionDefinitionFactory factory;
+ private ConfigTree listenerConfig;
+ private ActionDefinition action_ActionA;
+ private ActionDefinition action_ActionB;
+ private ActionDefinition action_ActionC;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ gpListener = new MockGpListener();
+ listenerConfig = new ConfigTree("listenerConfig");
+
+ ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("AbstractListener_ActionConfig.xml"));
+ factory = new ActionDefinitionFactory(config);
+ action_ActionA = factory.getInstance("ActionA");
+ action_ActionB = factory.getInstance("ActionB");
+ action_ActionC = factory.getInstance("ActionC");
+ assertNotNull(action_ActionA);
+ assertNotNull(action_ActionB);
+ assertNotNull(action_ActionC);
+ }
+
+ public void test_BadActionsConfig() throws Exception {
+ // Not action config of any description...
+ assertActionsConfigException("message1", "No actions configuration specified either on the listener or as a Message attachement [MESSAGE_PROCESSING_ACTIONS_LIST]. Aborting message processing.");
+
+ // Bad actions config as an override attachment - wrong type...
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getAttachment().put(AbstractListener.MESSAGE_PROCESSING_ACTIONS_LIST, new Long(1));
+ assertActionsConfigException(message, "Message attachement [MESSAGE_PROCESSING_ACTIONS_LIST] must be of type java.lang.String. Received [java.lang.Long]. Aborting message processing.");
+
+ // Bad actions config as an override attachment - empty...
+ message = MessageFactory.getInstance().getMessage();
+ message.getAttachment().put(AbstractListener.MESSAGE_PROCESSING_ACTIONS_LIST, " ");
+ assertActionsConfigException(message, "Message attachement [MESSAGE_PROCESSING_ACTIONS_LIST] was specified but with an empty value. Aborting message processing.");
+
+ // Bad actions config as an override attachment - unknown action...
+ listenerConfig.setAttribute(GpListener.PARM_ACTIONS, "ActionX");
+ assertActionsConfigException("message1", "Bad Listener Configuration. No 'Actions/Action' definition for action [ActionX].");
+ }
+
+ public void test_ActionsListenerConfig() throws Exception {
+ listenerConfig.setAttribute(GpListener.PARM_ACTIONS, "ActionA, ActionB");
+
+ // Run the listener and check that the proper actions were run...
+ runListener("message1", null);
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionA.getProcessor()).processedMessages.size());
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionB.getProcessor()).processedMessages.size());
+ assertEquals(0, ((BaseTestActionProcessor)action_ActionC.getProcessor()).processedMessages.size());
+ }
+
+ public void test_ActionsOverrideConfig() throws Exception {
+ Message message = MessageFactory.getInstance().getMessage();
+
+ // Set the actions on both the listener config and on the message as an attachment...
+ listenerConfig.setAttribute(GpListener.PARM_ACTIONS, "ActionA, ActionB");
+ message.getAttachment().put(AbstractListener.MESSAGE_PROCESSING_ACTIONS_LIST, "ActionA, ActionC");
+ ActionUtils.setTaskObject(message, "message1");
+
+ // Run the listener and check that it was the attachment actions config that was used...
+ runListener(message, null);
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionA.getProcessor()).processedMessages.size());
+ assertEquals(0, ((BaseTestActionProcessor)action_ActionB.getProcessor()).processedMessages.size());
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionC.getProcessor()).processedMessages.size());
+ }
+
+ public void test_PrematureTermination_By_Exception() throws Exception {
+ listenerConfig.setAttribute(GpListener.PARM_ACTIONS, "ActionA, ActionB, ActionC");
+
+ ((BaseTestActionProcessor)action_ActionB.getProcessor()).exception = new ActionProcessingException("Premature termination by Exception!");
+
+ // Run the listener and check that it failed and raised an appropriate error on the listener...
+ runListener("message1", "Premature termination by Exception!");
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionA.getProcessor()).processedMessages.size());
+ assertEquals(0, ((BaseTestActionProcessor)action_ActionB.getProcessor()).processedMessages.size());
+ assertEquals(0, ((BaseTestActionProcessor)action_ActionC.getProcessor()).processedMessages.size());
+ }
+
+ public void test_PrematureTermination_By_Null() throws Exception {
+ listenerConfig.setAttribute(GpListener.PARM_ACTIONS, "ActionA, ActionB, ActionC");
+
+ ((BaseTestActionProcessor)action_ActionB.getProcessor()).returnNull = true;
+
+ // Run the listener and check that it failed and raised an appropriate error on the listener...
+ runListener("message1", "Premature termination of action processing pipeline [[ActionA, ActionB, ActionC]]. ActionProcessor [org.jboss.soa.esb.actions.TestActionProcessor1] returned a null message result on processing of action [ActionB].");
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionA.getProcessor()).processedMessages.size());
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionB.getProcessor()).processedMessages.size());
+ assertEquals(0, ((BaseTestActionProcessor)action_ActionC.getProcessor()).processedMessages.size());
+ }
+
+ public void test_Last_Action_Returning_Null_OK() throws Exception {
+ listenerConfig.setAttribute(GpListener.PARM_ACTIONS, "ActionA, ActionB, ActionC");
+
+ ((BaseTestActionProcessor)action_ActionC.getProcessor()).returnNull = true;
+
+ runListener("message1", null);
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionA.getProcessor()).processedMessages.size());
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionB.getProcessor()).processedMessages.size());
+ assertEquals(1, ((BaseTestActionProcessor)action_ActionC.getProcessor()).processedMessages.size());
+ }
+
+ private void assertActionsConfigException(Object message, String expectedException) throws Exception {
+ MockNonblockingListener listener = new MockNonblockingListener(gpListener, listenerConfig, factory);
+
+ listener.messages = new Object[] {message};
+ gpListener.continueLooping = true;
+ listener.run();
+
+ assertEquals(0, listener.messagesCompleted.size());
+ assertEquals(1, listener.messagesInError.size());
+ assertEquals(message, listener.messagesInError.get(0).initialMsg);
+ assertEquals(null, listener.messagesInError.get(0).processor);
+ assertEquals(expectedException, listener.messagesInError.get(0).error.getMessage());
+ }
+
+ private MockNonblockingListener runListener(Object message, String expectedException) throws Exception {
+ MockNonblockingListener listener = new MockNonblockingListener(gpListener, listenerConfig, factory);
+
+ listener.messages = new Object[] {message};
+ gpListener.continueLooping = true;
+ listener.run();
+
+ if(expectedException == null) {
+ assertEquals(1, listener.messagesCompleted.size());
+ assertEquals(0, listener.messagesInError.size());
+ assertEquals(message, listener.messagesCompleted.get(0));
+ } else {
+ assertEquals(0, listener.messagesCompleted.size());
+ assertEquals(1, listener.messagesInError.size());
+ assertEquals(message, listener.messagesInError.get(0).initialMsg);
+ assertEquals(expectedException, listener.messagesInError.get(0).error.getMessage());
+ }
+
+ return listener;
+ }
+
+ /**
+ * Overriding the GpListener to get control over the continueLooping method.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+ private class MockGpListener extends GpListener {
+ private boolean continueLooping = true;
+
+ public boolean continueLooping() {
+ try {
+ return continueLooping;
+ } finally {
+ continueLooping = false;
+ }
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListener_ActionConfig.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListener_ActionConfig.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/AbstractListener_ActionConfig.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,11 @@
+ <Actions>
+ <Action name="ActionA" processor="Processor1" />
+ <Action name="ActionB" processor="Processor2" />
+ <Action name="ActionC" processor="Processor3" />
+
+ <ProcessorAliases>
+ <Alias name="Processor1" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ <Alias name="Processor2" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ <Alias name="Processor3" class="org.jboss.soa.esb.actions.TestActionProcessor1" />
+ </ProcessorAliases>
+ </Actions>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/DirectoryPollerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/DirectoryPollerUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/DirectoryPollerUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,58 @@
+/*
+* 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.old;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.listeners.old.DirectoryPoller;
+
+/**
+ * Test the DirectoryPoller
+ *
+ * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
+ * @version <tt>$Revision:$</tt>
+ * $Id:$
+ */
+public class DirectoryPollerUnitTest extends BaseTest {
+
+
+ /**
+ * Basic construction test
+ * @throws Exception
+ */
+ public void test_Empty_Construction() throws Exception {
+ log.info("Constructing instance of DirectoryPoller");
+ // This should fail
+ try {
+ @SuppressWarnings("unused")
+ DirectoryPoller dirPoller = new DirectoryPoller(null,null, null);
+ fail("GpListener should fail with empty constructor string");
+ } catch (Exception e) {
+ }
+ }
+
+
+
+
+
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListener-Config-01.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListener-Config-01.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListener-Config-01.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,31 @@
+<EsbConfig
+ command-queue-class="org.jboss.internal.soa.esb.command.InMemoryCommandQueue"
+ command-queue-name="test-queue"
+>
+
+ <ListenerConfig
+ listenerClass="org.jboss.soa.esb.util.MockPoller"
+ actions="String-To-Long, Long-To-Date, Route-To-Nowhere"
+ maxThreads="1"
+ >
+ </ListenerConfig>
+
+ <Actions>
+ <!--
+ Under the new architecture I think these will be equivalent to "Contracts Definitions"?
+ -->
+ <Action name="String-To-Long" processor="StringToLongConverter" />
+ <Action name="Long-To-Date" processor="LongToDateConverter" />
+ <Action name="Route-To-Nowhere" processor="ToNowhereRouter" />
+
+ <ProcessorAliases>
+ <!--
+ Under the new architecture I think these will be equivalent to "Services"? The alias "name" being like the Service URN.
+ -->
+ <Alias name="StringToLongConverter" class="org.jboss.soa.esb.actions.converters.StringToLongConverter" />
+ <Alias name="LongToDateConverter" class="org.jboss.soa.esb.actions.converters.LongToDateConverter" />
+ <Alias name="ToNowhereRouter" class="org.jboss.soa.esb.actions.ToNowhereRouter" />
+ </ProcessorAliases>
+ </Actions>
+
+</EsbConfig>
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListenerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListenerUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/GpListenerUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,92 @@
+/*
+* 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.old;
+
+import java.util.Date;
+
+import org.jboss.internal.soa.esb.command.InMemoryCommandQueue;
+import org.jboss.soa.esb.actions.ToNowhereRouter;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.old.GpListener;
+import org.jboss.soa.esb.util.ListenersManagerExecThread;
+import org.jboss.soa.esb.util.MockPoller;
+
+/**
+ * Test the GpListener
+ *
+ * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
+ * @version <tt>$Revision:$</tt>
+ * $Id:$
+ */
+public class GpListenerUnitTest extends BaseTest {
+
+
+ /**
+ * Basic construction test
+ * @throws Exception
+ */
+ public void test_Empty_Construction() throws Exception {
+ log.info("Constructing instance of GpListener");
+ // This should fail
+ @SuppressWarnings("unused")
+ GpListener gpListener = null;
+ try {
+ gpListener = new GpListener("");
+ fail("GpListener should fail with empty constructor string");
+ } catch (Exception e) {
+ }
+ }
+
+
+
+ public void test_newGpListener() throws Exception {
+ ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("GpListener-Config-01.xml"));
+ GpListener listenerManager = new GpListener(config);
+ ListenersManagerExecThread execThread = new ListenersManagerExecThread(listenerManager);
+ long currentTimeInMillis = System.currentTimeMillis();
+
+ // Clear the routing processor at the end of the pipeline...
+ ToNowhereRouter.objects.clear();
+
+ // Start the GpListener command thread...
+ execThread.start();
+
+ // Stick the current time into the poller as a String...
+ MockPoller.addToQueue("" + currentTimeInMillis);
+
+ // The message has been pulled from the poller in-queue at this stage because MockPoller.addToQueue blocks.
+ // Wait for a few milliseconds to allow the processor pipeline do it's thing...
+ Thread.sleep(200);
+
+ // Check did the "payload" get processed. The String containing the time should have been processed down the
+ // pileline and into a Date object in the ToNowhereRouter (mock routing processor) at the end of the pipeline...
+ assertEquals(1, ToNowhereRouter.objects.size());
+ Object date = ToNowhereRouter.objects.get(0);
+ assertTrue(date instanceof Date);
+ assertEquals(new Date(currentTimeInMillis), date);
+
+ // Send a shutdown command to the GpListener...
+ InMemoryCommandQueue.getQueue("test-queue").addCommand("shutdown");
+ execThread.assertShutdownOK(10000);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,74 @@
+/*
+* 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.old;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.listeners.old.SqlTablePoller;
+
+/**
+ * Test the SqlTablePoller
+ *
+ * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
+ * @version <tt>$Revision:$</tt>
+ * $Id:$
+ */
+public class SqlTablePollerUnitTest extends BaseTest {
+
+ /**
+ * Test basic construction.
+ * @throws Exception
+ */
+ public void test_Empty_Construction() throws Exception {
+ log.info("Constructing instance of SqlTablePoller");
+ // This should fail
+ @SuppressWarnings("unused")
+ SqlTablePoller sqlPoller = null;
+ try {
+ sqlPoller = new SqlTablePoller(null, null, null);
+ fail("SqlTablePoller should fail with empty constructor string");
+ } catch (Exception e) {
+ }
+ }
+
+
+ /*
+ public void test_Construction() throws Exception {
+
+ ConfigTree domElement = ConfigTree.fromInputStream(
+ getClass().getResourceAsStream("SqlTablePollerUnitTest.xml"));
+
+
+ log.info("Loaded - " + domElement.toXml());
+ }
+ */
+
+
+
+
+
+
+
+
+
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/old/SqlTablePollerUnitTest.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,35 @@
+<DocumentElementName>
+ <ExampleListenChapter
+ maxThreads="2"
+ listenerClass="org.jboss.soa.esb.listeners.old.SqlTablePoller"
+ actionClass="org.jboss.soa.esb.actions.templates.MockSqlRowAction"
+
+ driver-class="org.hsqldb.jdbcDriver"
+ connection-url="jdbc:hsqldb:."
+ user-name="sa"
+ password=""
+
+ tableName="test_notif_table"
+ selectFields="oid,ref,msg"
+ keyFields="oid,ref"
+ inProcessField="statusCol"
+ whereCondition="src='pepe'"
+ orderBy="oid desc"
+ >
+ <NotificationList type="OK">
+ <target class="NotifyFiles">
+ <file URI="file:///tmp/jbossEsb/notifyDir/ListenOnNotifTable.notifOK"
+ append="true"
+ />
+ </target>
+ </NotificationList>
+
+ <NotificationList type="err">
+ <target class="NotifyFiles">
+ <file URI="file:///tmp/jbossEsb/notifyDir/ListenOnNotifTable.notifErr"
+ append="true"
+ />
+ </target>
+ </NotificationList>
+ </ExampleListenChapter>
+</DocumentElementName>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/AbstractMockListner.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/AbstractMockListner.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/AbstractMockListner.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+
+package org.jboss.soa.esb.util;
+
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.old.AbstractListener;
+import org.jboss.soa.esb.listeners.old.GpListener;
+
+/**
+ * Abstract Mock Listener implementation.
+ * <p/>
+ * Leaves you to implement the receive method in whatever way suits.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class AbstractMockListner extends AbstractListener {
+
+ private static Logger logger = Logger.getLogger(AbstractMockListner.class);
+ public List<MessageInError> messagesInError = new Vector<MessageInError>();
+ public List<Object> messagesCompleted = new Vector<Object>();
+
+ public AbstractMockListner(GpListener p_oDad, ConfigTree p_oParms, ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+ super(p_oDad, p_oParms, actionDefinitionFactory);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingError(java.lang.Object, org.jboss.soa.esb.actions.ActionProcessor, java.lang.Throwable)
+ */
+ @Override
+ protected void processingError(Object initialMsg, ActionProcessor processor, Throwable error) {
+ logger.info("Received 'processingError' event. Message [" + initialMsg + "], ActionProcessor [" + processor + "], Throwable [" + error + "]", error);
+ messagesInError.add(new MessageInError(initialMsg, processor, error));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingComplete(java.lang.Object)
+ */
+ @Override
+ protected void processingComplete(Object initialMsg) {
+ logger.info("Received 'processingComplete' event. Message [" + initialMsg + "]");
+ messagesCompleted.add(initialMsg);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#close()
+ */
+ @Override
+ protected void close() {
+ }
+
+ public class MessageInError {
+ public Object initialMsg;
+ public ActionProcessor processor;
+ public Throwable error;
+ public MessageInError(Object initialMsg, ActionProcessor processor, Throwable error) {
+ this.initialMsg = initialMsg;
+ this.processor = processor;
+ this.error = error;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/ListenersManagerExecThread.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/ListenersManagerExecThread.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/ListenersManagerExecThread.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,90 @@
+package org.jboss.soa.esb.util;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.listeners.old.GpListener;
+
+public class ListenersManagerExecThread extends Thread {
+
+ private static Logger logger = Logger.getLogger(ListenersManagerExecThread.class);
+ private GpListener listenersManager;
+
+ public ListenersManagerExecThread(GpListener listenersManager) {
+ super(listenersManager);
+ this.listenersManager = listenersManager;
+ }
+
+ @Override
+ public synchronized void start() {
+ logger.info("Waiting on Listener Manager the start...");
+ super.start();
+ while(listenersManager.getState() != GpListener.State.Running) {
+ try {
+ sleep(50);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException("Unexpected Thread Interrupt exception.", e);
+ }
+ if(listenersManager.getState() == GpListener.State.Exception_thrown) {
+ Exception e = listenersManager.getState().getException();
+ logger.error("Failed to start the Listener Manager!", e);
+ TestCase.fail(e.getMessage());
+ }
+ }
+ logger.info("Listener Manager running (Thread: " + getName() + ")! Note this does not mean all the Listeners are up and running!");
+ }
+
+
+ /**
+ * Get the {@link GpListener} Listeners Manager class executing in this thread.
+ * @return The listenersManager property value.
+ */
+ public GpListener getListenersManager() {
+ return listenersManager;
+ }
+
+ /**
+ * Assert that the listener Manager is in an Exception state..
+ */
+ public void asserttInException() {
+ if(listenersManager.getState() != GpListener.State.Exception_thrown) {
+ String errorMsg = "GpListener not in Exception state. Listener Manager Thread: " + this.getName();
+ logger.error(errorMsg);
+ TestCase.fail(errorMsg);
+ }
+ }
+
+ /**
+ * Assert that the listener Manager is not in an Exception state..
+ */
+ public void assertNotInException() {
+ if(listenersManager.getState() == GpListener.State.Exception_thrown) {
+ String errorMsg = "GpListener in Exception state. See log. Listener Manager Thread: " + this.getName();
+ logger.error(errorMsg, listenersManager.getState().getException());
+ TestCase.fail(errorMsg);
+ }
+ }
+
+ /**
+ * Assert that the listener Manager has shutdown.
+ * @param maxWait The maximum length of time (ms) to wait for shutdown before failing the test.
+ */
+ public void assertShutdownOK(long maxWait) {
+ long endTime = System.currentTimeMillis() + maxWait;
+
+ while(System.currentTimeMillis() < endTime) {
+ if(listenersManager.getState() == GpListener.State.Done_OK) {
+ logger.info("Shutdown was successful. Listener Manager Thread: " + this.getName());
+ return;
+ }
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ logger.error("Thread interupt...", e);
+ }
+ }
+ String errorMsg = "GpListener failed to shutdown as requested. Waited for " + maxWait + "ms. Listener Manager Thread: " + this.getName();
+ logger.error(errorMsg);
+ TestCase.fail(errorMsg);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockNonblockingListener.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockNonblockingListener.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockNonblockingListener.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+
+package org.jboss.soa.esb.util;
+
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.old.GpListener;
+
+/**
+ * Non blocking mock Listener implementation.
+ * <p/>
+ * "Real" listener implementations need to perform blocking receives. This can make testing
+ * a little awkward, especially where the listener is just one of thee test fixtures.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MockNonblockingListener extends AbstractMockListner {
+
+ public Object[] messages;
+
+ public MockNonblockingListener(GpListener p_oDad, ConfigTree p_oParms,
+ ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+ super(p_oDad, p_oParms, actionDefinitionFactory);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#receive()
+ */
+ @Override
+ protected Object[] receive() {
+ return messages;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockNotificationTarget.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockNotificationTarget.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockNotificationTarget.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,68 @@
+package org.jboss.soa.esb.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.notification.NotificationTarget;
+
+/**
+ * Mock NotificationTarget Implementation.
+ * <p/>
+ * Configured by giving the target output list a 'name'. Notifications are statically accessed via the static
+ * {@link #getTargetList(String)} method, supplying the target list name.
+ * <p/>
+ * Sample config:
+ * <pre>
+ * <NotificationList type="OK">
+ * <target class="org.jboss.soa.esb.util.MockNotificationTarget" <b>name="ok-target"</b> />
+ * </NotificationList>
+ * </pre>
+ * @author tfennelly
+ */
+public class MockNotificationTarget extends NotificationTarget {
+
+ private static Hashtable<String, List<Serializable>> targetLists = new Hashtable<String, List<Serializable>>();
+ private List<Serializable> targetList;
+
+ public MockNotificationTarget(ConfigTree config) {
+ super(config);
+
+ String name = config.getAttribute("name");
+
+ if(name == null || name.trim().equals("")) {
+ TestCase.fail("Mock NotificationTarget configured incorrectly. Must specify a 'name' attribute on the NotificationList/target element.");
+ }
+
+ targetList = getTargetList(name);
+ }
+
+ public static List<Serializable> getTargetList(String name) {
+ synchronized (targetLists) {
+ List<Serializable> notificationList = targetLists.get(name);
+
+ // Never return a null list.
+ if(notificationList == null) {
+ notificationList = new ArrayList<Serializable>();
+ targetLists.put(name, notificationList);
+ }
+
+ return notificationList;
+ }
+ }
+
+ public static void clearNotifications() {
+ synchronized (targetLists) {
+ targetLists.clear();
+ }
+ }
+
+ @Override
+ public void sendNotification(Serializable notificationObject) throws Exception {
+ targetList.add(notificationObject);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockPoller.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockPoller.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/org/jboss/soa/esb/util/MockPoller.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,107 @@
+package org.jboss.soa.esb.util;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Queue;
+import java.util.Vector;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.old.AbstractPoller;
+import org.jboss.soa.esb.listeners.old.GpListener;
+
+/**
+ * Simple Mock {@link org.jboss.soa.esb.listeners.old.AbstractPoller} implementation that can be used for testing.
+ * <p/>
+ * Maintains a static in-memory queue into which objects can be dropped for processing by the configured action handler.
+ * @author tfennelly
+ */
+public class MockPoller extends AbstractPoller {
+
+ private static Queue<Object> queue = new ConcurrentLinkedQueue<Object>();
+ public List<MessageInError> messagesInError = new Vector<MessageInError>();
+ public List<Object> messagesCompleted = new Vector<Object>();
+
+ public MockPoller(GpListener p_oDad, ConfigTree p_oParms, ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+ super(p_oDad, p_oParms, actionDefinitionFactory);
+ m_iPollMillis = 250;
+ }
+
+ /**
+ * Add an object for processing by the configured action handler.
+ * <p/>
+ * Blocks indefinitely until the message is consumed.
+ * @param actionObject The Object instance for processing.
+ */
+ public static void addToQueue(Object actionObject) {
+ synchronized (queue) {
+ queue.add(actionObject);
+ }
+ while(!queue.isEmpty()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException("Unexpected thread interupt.", e);
+ }
+ }
+ }
+
+ public static void clearQueue() {
+ synchronized (queue) {
+ queue.clear();
+ }
+ }
+
+ @Override
+ protected List<Object> pollForCandidates() {
+ // This method is called periodically by the AbstractPoller.
+ synchronized (queue) {
+ List<Object> actionObjects = Arrays.asList(queue.toArray());
+ queue.clear();
+ return actionObjects;
+ }
+ }
+
+ @Override
+ protected Object preProcess(Object actionObject) {
+ // Called by the AbstractPoller for each of the objects returned to it be the above pollForCandidates method.
+ // Just return the object to be processed by the action class that's configured on the listener.
+ return actionObject;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#close()
+ */
+ @Override
+ protected void close() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingError(java.lang.Object, org.jboss.soa.esb.actions.ActionProcessor, java.lang.Throwable)
+ */
+ @Override
+ protected void processingError(Object initialMsg, ActionProcessor processor, Throwable error) {
+ messagesInError.add(new MessageInError(initialMsg, processor, error));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.listeners.AbstractListener#processingComplete(java.lang.Object)
+ */
+ @Override
+ protected void processingComplete(Object initialMsg) {
+ messagesCompleted.add(initialMsg);
+ }
+
+ public class MessageInError {
+ public Object initialMsg;
+ public ActionProcessor processor;
+ public Throwable error;
+ public MessageInError(Object initialMsg, ActionProcessor processor, Throwable error) {
+ this.initialMsg = initialMsg;
+ this.processor = processor;
+ this.error = error;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/smooks-cdr.lst
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/smooks-cdr.lst 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/listeners/tests/src/smooks-cdr.lst 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1 @@
+/org/jboss/soa/esb/actions/smooks-test.cdrl
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/ant.bat
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/ant.bat 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/ant.bat 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,12 @@
+ at echo off
+set ANT_CMD_LINE_ARGS=%1
+if ""%1""=="""" goto doneStart
+shift
+:setupArgs
+if ""%1""=="""" goto doneStart
+set ANT_CMD_LINE_ARGS=%ANT_CMD_LINE_ARGS% %1
+shift
+goto setupArgs
+:doneStart
+%ANT_HOME%\bin\ant %ANT_CMD_LINE_ARGS%
+
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/build.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/build.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+<project name="BuildJbossEsbRosetta" default="org.jboss.esb.rosetta.compile" basedir=".">
+
+ <property name="org.jboss.esb.rosetta.jar.name" value="jbossesb-rosetta"/>
+ <property name="org.jboss.esb.rosetta.distrib.dir" value="${org.jboss.esb.internal.dest}/dist"/>
+ <property name="org.jboss.esb.rosetta.classes.dir" value="${org.jboss.esb.internal.dest}/classes/rosetta"/>
+ <property name="org.jboss.esb.rosetta.src.dir" value="${basedir}/src"/>
+ <property name="org.jboss.esb.root.dir" value="../.."/>
+ <property environment="env"/>
+
+ <property name="org.jboss.esb.ext.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext"/>
+ <property name="org.jboss.esb.ejb3.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext/ejb3"/>
+ <condition property="org.jboss.esb.ext.lib.dir" value="{org.jboss.esb.jboss.home}/client">
+ <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
+ </condition>
+
+ <path id="org.jboss.esb.rosetta.base.classpath">
+ <fileset dir="${org.jboss.esb.ext.lib.dir}" includes="*.jar"/>
+ <fileset dir="${org.jboss.esb.ejb3.lib.dir}" includes="*.jar,*.zip"/>
+ </path>
+
+ <target name="org.jboss.esb.rosetta.init">
+ <tstamp>
+ <format property="TODAY" pattern="dd-MM-yy"/>
+ </tstamp>
+ </target>
+
+ <target name="org.jboss.esb.rosetta.prepare" depends="org.jboss.esb.rosetta.init">
+ <mkdir dir="${org.jboss.esb.rosetta.classes.dir}"/>
+ <mkdir dir="${org.jboss.esb.rosetta.distrib.dir}"/>
+ <mkdir dir="${org.jboss.esb.rosetta.distrib.dir}/lib"/>
+ </target>
+
+ <target name="clean" description="Remove classes directory">
+ <delete dir="${org.jboss.esb.rosetta.classes.dir}"/>
+ </target>
+
+ <target name="purge" depends="clean">
+ </target>
+
+
+ <target name="org.jboss.esb.rosetta.compile">
+ <!-- Compile common -->
+ <antcall target="org.jboss.esb.rosetta.internal.compile"/>
+ <!-- Compile common tests -->
+ <ant inheritAll="true" dir="tests" target="org.jboss.esb.rosetta.tests.compile"/>
+ </target>
+
+
+ <target name="org.jboss.esb.rosetta.internal.compile" depends="org.jboss.esb.rosetta.prepare"
+ description="Compile all classes">
+
+ <javac
+ destdir="${org.jboss.esb.rosetta.classes.dir}"
+ classpathref="org.jboss.esb.rosetta.base.classpath"
+ debug="${org.jboss.esb.debug}"
+ optimize="${org.jboss.esb.optimize}"
+ >
+ <src path="${org.jboss.esb.rosetta.src.dir}"/>
+ </javac>
+
+ </target>
+
+ <target name="recompile" depends="clean,org.jboss.esb.rosetta.compile"
+ description="Clean and compile"/>
+
+ <target name="jar" depends="org.jboss.esb.rosetta.compile" description="Assemble jar files">
+ <delete file="${org.jboss.esb.rosetta.distrib.dir}/lib/${org.jboss.esb.rosetta.jar.name}.jar" />
+ <jar destfile="${org.jboss.esb.rosetta.distrib.dir}/lib/${org.jboss.esb.rosetta.jar.name}.jar"
+ basedir="${org.jboss.esb.rosetta.classes.dir}"
+ includes="**/*.class"
+ excludes="test/**"
+ />
+ </target>
+
+
+
+ <target name="org.jboss.esb.rosetta.test" description="Run tests for this module">
+ <!-- Compile common tests -->
+ <ant dir="tests" target="org.jboss.esb.rosetta.internal.test"/>
+ </target>
+
+
+
+
+ <target name="all" depends="recompile,jar" />
+
+</project>
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/CallHelper.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,215 @@
+package org.jboss.internal.soa.esb.addressing;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import java.net.URI;
+import java.security.InvalidParameterException;
+
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.XMLUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class CallHelper
+{
+
+ public static Element toXML (Call call, Document doc, Element header)
+ {
+ if (call == null)
+ throw new InvalidParameterException();
+
+ try
+ {
+ if (call.getTo() != null)
+ {
+ Element toElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG);
+ PortReferenceHelper.toXML(header, doc, toElement, call.getTo().getAddr(), true);
+ header.appendChild(toElement);
+ }
+
+ if (call.getFrom() != null)
+ {
+ Element fromElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FROM_TAG);
+ PortReferenceHelper.toXML(header, doc, fromElement, call.getFrom().getAddr(), false);
+ header.appendChild(fromElement);
+ }
+
+ if (call.getReplyTo() != null)
+ {
+ Element replyToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.REPLY_TO_TAG);
+ PortReferenceHelper.toXML(header, doc, replyToElement, call.getReplyTo().getAddr(), false);
+ header.appendChild(replyToElement);
+ }
+
+ if (call.getRelatesTo() != null)
+ {
+ Element relatesToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.RELATES_TO_TAG);
+ relatesToElement.setNodeValue(call.getRelatesTo().toString());
+ header.appendChild(relatesToElement);
+ }
+
+ if (call.getFaultTo() != null)
+ {
+ Element faultToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FAULT_TO_TAG);
+ PortReferenceHelper.toXML(header, doc, faultToElement, call.getFaultTo().getAddr(), false);
+ header.appendChild(faultToElement);
+ }
+
+ if (call.getAction() != null)
+ {
+ Element actionElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.ACTION_TAG);
+ actionElement.setNodeValue(call.getAction().toString());
+ header.appendChild(actionElement);
+ }
+
+ if (call.getMessageID() != null)
+ {
+ Element messageIDElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.MESSAGE_IDENTIFIER_TAG);
+ messageIDElement.setNodeValue(call.getMessageID().toString());
+ header.appendChild(messageIDElement);
+ }
+
+ return header;
+ }
+ catch (Exception ex)
+ {
+ // TODO improve error handling.
+
+ ex.printStackTrace();
+
+ throw new InvalidParameterException(ex.toString());
+ }
+ }
+
+ public static Call fromXML (Element header)
+ {
+ Call call = null;
+
+ try
+ {
+ call = new Call();
+
+ NodeList nl = header.getChildNodes();
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ Node n = nl.item(i);
+
+ if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG))
+ {
+ try
+ {
+ call.setTo(new EPR(PortReferenceHelper.fromXML((Element) n, true)));
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+
+ if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.FROM_TAG))
+ {
+ try
+ {
+ call.setFrom(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+
+ if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.REPLY_TO_TAG))
+ {
+ try
+ {
+ call.setReplyTo(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+
+ if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.RELATES_TO_TAG))
+ {
+ try
+ {
+ call.setRelatesTo(new URI(n.getNodeValue()));
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+
+ if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.FAULT_TO_TAG))
+ {
+ try
+ {
+ call.setFaultTo(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+
+ if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.ACTION_TAG))
+ {
+ try
+ {
+ call.setAction(new URI(n.getNodeValue()));
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+
+ if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.MESSAGE_IDENTIFIER_TAG))
+ {
+ try
+ {
+ call.setMessageID(new URI(n.getNodeValue()));
+ }
+ catch (Exception ex)
+ {
+
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ // TODO error checking!!
+
+ ex.printStackTrace();
+ }
+
+ return call;
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/EPRHelper.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/EPRHelper.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/EPRHelper.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,173 @@
+package org.jboss.internal.soa.esb.addressing;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.net.URISyntaxException;
+import java.security.InvalidParameterException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.soa.esb.MarshalException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+public class EPRHelper
+{
+ public static final String ELEMENT_NAME = "EPR";
+
+ public static final Element toXML (EPR epr, Document doc, Element header)
+ {
+ if (epr == null)
+ throw new InvalidParameterException();
+
+ try
+ {
+ PortReferenceHelper.toXML(null, doc, header, epr.getAddr(), false);
+
+ return header;
+ }
+ catch (URISyntaxException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ catch (MarshalException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+
+ public static final String toXMLString (EPR epr)
+ {
+ if (epr == null)
+ throw new InvalidParameterException();
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ Element portReferenceElement = doc.createElement(ELEMENT_NAME);
+
+ doc.appendChild(portReferenceElement);
+
+ toXML(epr, doc, portReferenceElement);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ return sWriter.toString();
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ catch (ParserConfigurationException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+
+ public static final EPR fromXML (Element header)
+ {
+ if (header == null)
+ throw new InvalidParameterException();
+
+ try
+ {
+ if (header.getNodeName().equals(ELEMENT_NAME))
+ return new EPR(PortReferenceHelper.fromXML(header, false));
+ else
+ return null;
+ }
+ catch (MarshalException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+
+ public static final EPR fromXMLString (String xml)
+ {
+ if (xml == null)
+ throw new InvalidParameterException();
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+ Element rootElement = doc.getDocumentElement();
+
+ return new EPR(PortReferenceHelper.fromXML(rootElement, false));
+ }
+ catch (MarshalException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ catch (SAXException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ catch (ParserConfigurationException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/PortReferenceHelper.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/PortReferenceHelper.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/PortReferenceHelper.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,430 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/*
+ * Copyright (c) 2002, 2003, Arjuna Technologies Limited.
+ *
+ * PortReferenceHelper.java
+ */
+
+package org.jboss.internal.soa.esb.addressing;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.jboss.soa.esb.MarshalException;
+import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.XMLUtil;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/*
+ * This should pack the PortReference into an ERP.
+ *
+ * It would be better if PortReference had a packToXML and unpackFromXML.
+ *
+ * This needs rewriting after the interoperability workshop!
+ */
+
+public class PortReferenceHelper
+{
+ /**
+ * WS-Addressing is broken in that the To field is a URI, even if the From
+ * field was an EPR! You have to use the EPR bits separately. So, the
+ * toField is used to indicate whether we are packing this address as a To
+ * field (when we need to treat it differently) or as an EPR.
+ */
+
+ /** ************************************************** */
+ public static void toXML(org.w3c.dom.Element header,
+ org.w3c.dom.Document document,
+ org.w3c.dom.Element portReferenceElement,
+ PortReference portReference, boolean toField)
+ throws MarshalException
+ {
+ try
+ {
+ if (!toField)
+ {
+ Element addressElement = document.createElementNS(
+ XMLUtil.WSA_NAMESPACE_URI, XMLUtil.ADDRESS_TAG);
+ addressElement.setPrefix(XMLUtil.WSA_PREFIX);
+ addressElement.appendChild(document
+ .createTextNode(portReference.getAddress()));
+ portReferenceElement.appendChild(addressElement);
+ }
+ else
+ {
+ portReferenceElement.appendChild(document
+ .createTextNode(portReference.getAddress()));
+ }
+
+ Iterator extensions = portReference.getExtensions();
+ Element referenceProperties = null;
+
+ while (extensions.hasNext())
+ {
+ PortReference.Extension extension = (PortReference.Extension) extensions
+ .next();
+
+ /*
+ * WS-Addressing is broken in that the To field is a URI, even
+ * if the From field was an EPR! You have to use the EPR bits
+ * separately. Doh!
+ */
+
+ if (!toField)
+ {
+ if (referenceProperties == null)
+ {
+ referenceProperties = document.createElementNS(
+ XMLUtil.WSA_NAMESPACE_URI,
+ XMLUtil.REFERENCE_PROPERTIES_TAG);
+ referenceProperties.setPrefix(XMLUtil.WSA_PREFIX);
+ portReferenceElement.appendChild(referenceProperties);
+ }
+ }
+ else
+ referenceProperties = header;
+
+ extensionToXML(referenceProperties, document, extension);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace();
+ throw new MarshalException("Marshal failure: " + exception);
+ }
+ }
+
+ /** **************************** */
+ public static PortReference fromXML(
+ org.w3c.dom.Element portReferenceElement, boolean toField)
+ throws MarshalException
+ {
+ PortReference portReference = new PortReference();
+
+ if (toField)
+ portReference.setAddress(portReferenceElement.getTextContent());
+
+ org.w3c.dom.NodeList elements = portReferenceElement.getChildNodes();
+
+ for (int i = 1; i < elements.getLength(); i++)
+ {
+ final Object extensionObject = elements.item(i);
+
+ if (extensionObject instanceof Element)
+ {
+ int parentNodeType = PortReference.Extension.NEITHER;
+ Element extensionElement = (Element) extensionObject;
+ NodeList children = extensionElement.getChildNodes();
+ String parentName = extensionElement.getNodeName();
+ boolean haveChildren = false;
+
+ if (parentName.equals(XMLUtil.REFERENCE_PROPERTIES_TAG))
+ parentNodeType = PortReference.Extension.REFERENCE_PROPERTIES;
+ else
+ {
+ if (parentName.equals(XMLUtil.REFERENCE_PARAMETERS_TAG))
+ parentNodeType = PortReference.Extension.REFERENCE_PARAMETERS;
+ else
+ {
+ if (!toField
+ && parentName.equals(XMLUtil.WSA_PREFIX + ":"
+ + XMLUtil.ADDRESS_TAG))
+ {
+ portReference.setAddress(extensionElement
+ .getTextContent());
+ }
+ }
+ }
+
+ final int numChildren = children.getLength();
+
+ for (int count = 0; count < numChildren; count++)
+ {
+ final Object childObject = children.item(count);
+
+ if (childObject instanceof Element)
+ {
+ Element childElement = (Element) childObject;
+
+ portReference
+ .addExtension(childrenFromXML(childElement));
+ haveChildren = true;
+ }
+ }
+
+ if (!haveChildren && !parentName.equals(XMLUtil.WSA_PREFIX + ":"+ XMLUtil.ADDRESS_TAG))
+ {
+ PortReference.Extension ext = new PortReference.Extension(
+ extensionElement.getNodeName(), null, null,
+ extensionElement.getNodeValue(), parentNodeType);
+
+ portReference.addExtension(ext);
+
+ final NamedNodeMap attrs = extensionElement.getAttributes();
+ final int numAttrs = attrs.getLength();
+ if (numAttrs > 0)
+ {
+ final HashMap<ArjunaName, String> p = new HashMap<ArjunaName, String>();
+ for (int count = 0; count < numAttrs; count++)
+ {
+ final Attr attr = (Attr) attrs.item(count);
+ if (!"http://www.w3.org/2000/xmlns/".equals(attr
+ .getNamespaceURI()))
+ {
+ final ArjunaName name = generateName(attr);
+ p.put(name, attr.getValue());
+ }
+ }
+
+ ext.addAttributes(p);
+ }
+ }
+ }
+ }
+
+ return portReference;
+ }
+
+ private final static PortReference.Extension childrenFromXML(
+ Element childRoot)
+ {
+ final NodeList children = childRoot.getChildNodes();
+ final int numChildNodes = children.getLength();
+
+ final PortReference.Extension extension;
+ if (numChildNodes > 0)
+ {
+ Object childObject = children.item(0);
+ if (childObject instanceof Element)
+ {
+ extension = new PortReference.Extension(
+ childRoot.getNodeName(), childRoot.getPrefix(),
+ childRoot.getNamespaceURI());
+
+ for (int count = 1; count < numChildNodes; count++)
+ {
+ extension.addChild(childrenFromXML((Element) childObject));
+ childObject = children.item(count);
+ }
+ }
+ else
+ {
+ extension = new PortReference.Extension(
+ childRoot.getNodeName(), childRoot.getPrefix(),
+ childRoot.getNamespaceURI(), ((Node) childObject)
+ .getNodeValue());
+ }
+ }
+ else
+ {
+ extension = new PortReference.Extension(childRoot.getNodeName(),
+ childRoot.getPrefix(), childRoot.getNamespaceURI(),
+ childRoot.getNodeValue());
+ }
+
+ final NamedNodeMap attrs = childRoot.getAttributes();
+ final int numAttrs = attrs.getLength();
+ if (numAttrs > 0)
+ {
+ final HashMap<ArjunaName, String> p = new HashMap<ArjunaName, String>();
+ for (int count = 0; count < numAttrs; count++)
+ {
+ final Attr attr = (Attr) attrs.item(count);
+ if (!"http://www.w3.org/2000/xmlns/".equals(attr
+ .getNamespaceURI()))
+ {
+ final ArjunaName name = generateName(attr);
+ p.put(name, attr.getValue());
+ }
+ }
+
+ extension.addAttributes(p);
+ }
+ return extension;
+ }
+
+ private final static Element extensionToXML(Element packInto,
+ org.w3c.dom.Document document, PortReference.Extension toPack)
+ throws MarshalException
+ {
+ final String uri = toPack.getURI();
+ final Element element;
+ if (uri == null)
+ {
+ element = document.createElement(toPack.getTag());
+ }
+ else
+ {
+ final String prefix = toPack.getPrefix();
+ element = document.createElementNS(uri, toPack.getTag());
+ element.setPrefix(prefix);
+ element.setAttributeNS(XMLUtil.XMLNS_URI, XMLUtil.XMLNS_PREFIX
+ + toPack.getPrefix(), uri);
+ }
+ packInto.appendChild(element);
+
+ if (toPack.getValue() != null)
+ {
+ final Text text = document.createTextNode(toPack.getValue());
+ element.appendChild(text);
+ }
+
+ LinkedList extensions = toPack.getChildren();
+
+ if (extensions != null)
+ {
+ for (int i = 0; i < extensions.size(); i++)
+ {
+ PortReference.Extension ext = (PortReference.Extension) extensions
+ .get(i);
+
+ extensionToXML(element, document, ext);
+ }
+ }
+
+ HashMap attrs = toPack.getAttributes();
+
+ if (attrs != null)
+ {
+ Iterator names = attrs.entrySet().iterator();
+
+ while (names.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) names.next();
+ ArjunaName name = (ArjunaName) entry.getKey();
+ final String value = (String) entry.getValue();
+ final String attrURI = name.toString();
+ if (attrURI != null)
+ {
+ element.setAttributeNS(attrURI, name.getQualifiedName(),
+ value);
+ }
+ else
+ {
+ element.setAttribute(name.getQualifiedName(), value);
+ }
+ }
+ }
+
+ return element;
+ }
+
+ /**
+ * Generate a name based on the attribute.
+ *
+ * @param attr
+ * The current attribute.
+ * @return The name
+ */
+ private static ArjunaName generateName(final Attr attr)
+ {
+ final String localName = attr.getNodeName();
+ final String uri = attr.getNamespaceURI();
+ final String prefix = attr.getPrefix();
+
+ return new ArjunaName(uri, prefix, localName);
+ }
+
+ private static class ArjunaName
+ {
+ /**
+ * The uri.
+ */
+ private final String uri;
+
+ /**
+ * The prefix.
+ */
+ private final String prefix;
+
+ /**
+ * The local name.
+ */
+ private final String localName;
+
+ /**
+ * Construct the name.
+ *
+ * @param uri
+ * The uri.
+ * @param prefix
+ * The prefix.
+ * @param localName
+ * The local name.
+ */
+ public ArjunaName(final String uri, final String prefix,
+ final String localName)
+ {
+ this.uri = uri;
+ this.prefix = prefix;
+ this.localName = localName;
+ }
+
+ /**
+ * Get the uri.
+ *
+ * @return the uri.
+ */
+ public String getURI()
+ {
+ return uri;
+ }
+
+ /**
+ * Get the prefix.
+ *
+ * @return the prefix.
+ */
+ public String getPrefix()
+ {
+ return prefix;
+ }
+
+ /**
+ * Get the local name.
+ *
+ * @return the local name.
+ */
+ public String getLocalName()
+ {
+ return localName;
+ }
+
+ /**
+ * Get the qualified name.
+ *
+ * @return the qualified name.
+ */
+ public String getQualifiedName()
+ {
+ return (prefix == null ? localName : prefix + ":" + localName);
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/CommandQueue.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/CommandQueue.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/CommandQueue.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,34 @@
+package org.jboss.internal.soa.esb.command;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Command queue abstraction.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public interface CommandQueue {
+
+ /**
+ * Open the command queue.
+ * @param config Command queue configuration.
+ * @throws CommandQueueException Queue exception. Check for probable chained cause exceptions.
+ */
+ public void open(ConfigTree config) throws CommandQueueException;
+
+ /**
+ * Receive a message from the underlying queue implementation.
+ * <p/>
+ * Performs a blocking receive on the command queue, controled by the receive timeout.
+ * @param timeout The receive block timeout. Zero to block indefinitely.
+ * @return The command message from the queue.
+ * @throws CommandQueueException Queue exception. Check for probable chained cause exceptions.
+ */
+ public String receiveCommand(long timeout) throws CommandQueueException;
+
+ /**
+ * Close the command queue.
+ * @throws CommandQueueException Queue exception. Check for probable chained cause exceptions.
+ */
+ public void close() throws CommandQueueException;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/CommandQueueException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/CommandQueueException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/CommandQueueException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,29 @@
+package org.jboss.internal.soa.esb.command;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * Command queue exception.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class CommandQueueException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ public CommandQueueException() {
+ super();
+ }
+
+ public CommandQueueException(String message) {
+ super(message);
+ }
+
+ public CommandQueueException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public CommandQueueException(Throwable cause) {
+ super(cause);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/InMemoryCommandQueue.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/InMemoryCommandQueue.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/InMemoryCommandQueue.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,86 @@
+package org.jboss.internal.soa.esb.command;
+
+import java.util.Hashtable;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * In Memory Blocking Command Queue.
+ * <p/>
+ * Suitable for testing or any other purpose.
+ * <p/>
+ * The command queue's configuration needs to specify the
+ * queue name via a "command-queue-name" attribute supplied in the configuration to the
+ * {@link #open(ConfigTree)} method. The queues are stored statically and can be accessed via the
+ * {@link #getQueue(String)} method using the queue name.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class InMemoryCommandQueue implements CommandQueue {
+
+ /**
+ * Command queue name attribute name.
+ */
+ public static final String COMMAND_QUEUE_NAME = "command-queue-name";
+
+ private static Hashtable<String, InMemoryCommandQueue> commandQueues = new Hashtable<String, InMemoryCommandQueue>();
+
+ private String name;
+ private BlockingQueue<String> queue = new LinkedBlockingQueue<String>();
+
+ public void open(ConfigTree config) throws CommandQueueException {
+ if(config == null) {
+ throw new IllegalArgumentException("null 'config' arg in method call.");
+ }
+
+ name = config.getAttribute(COMMAND_QUEUE_NAME);
+ if(name == null) {
+ throw new CommandQueueException("Attribute 'command-queue-name' must be specified on the command queue configuration.");
+ }
+ commandQueues.put(name, this);
+ }
+
+ /**
+ * Add a command to the in-memory command queue.
+ * <p/>
+ * Blocks until the command has been consumed.
+ * @param command The command string.
+ */
+ public void addCommand(String command) {
+ queue.add(command);
+ while(!queue.isEmpty()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public String receiveCommand(long timeout) throws CommandQueueException {
+ if(name == null || !commandQueues.containsKey(name)) {
+ throw new CommandQueueException("Sorry. Invalid call to 'receiveCommand' method. Queue is not open!");
+ }
+
+ try {
+ return queue.take();
+ } catch (InterruptedException e) {
+ throw new CommandQueueException("Error taking command message from command queue.", e);
+ }
+ }
+
+ public void close() throws CommandQueueException {
+ commandQueues.remove(name);
+ }
+
+ /**
+ * Get the command queue based on the name supplied in the configuration ("command-queue-name").
+ * @param name The name of the queue ala the "command-queue-name" attribute on the queue configuration.
+ * @return The MockCommandQueue instance, or null if no such queue exists.
+ */
+ public static InMemoryCommandQueue getQueue(String name) {
+ return commandQueues.get(name);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/JmsCommandQueue.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/JmsCommandQueue.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/command/JmsCommandQueue.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,172 @@
+package org.jboss.internal.soa.esb.command;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+import javax.naming.Context;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.AppServerContext;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * JMS based Command Queue implementation.
+ * <p/>
+ * This code was simply pulled from the GpListener.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class JmsCommandQueue implements CommandQueue {
+
+ private static Logger logger = Logger.getLogger(JmsCommandQueue.class);
+
+ public static final String COMMAND_CONN_FACTORY = "commandConnFactoryClass";
+
+ public static final String COMMAND_JNDI_TYPE = "commandJndiType";
+
+ public static final String COMMAND_JNDI_URL = "commandJndiURL";
+
+ public static final String COMMAND_IS_TOPIC = "commandIsTopic";
+
+ public static final String COMMAND_JNDI_NAME = "commandJndiName";
+
+ public static final String COMMAND_MSG_SELECTOR = "messageSelector";
+
+ private MessageConsumer m_oCmdSrc;
+
+ private Session m_oJmsSess;
+
+ private Connection m_oJmsConn;
+
+ public void open(ConfigTree config) throws CommandQueueException {
+ try {
+ initialiseJMS(config);
+ } catch (Exception e) {
+ throw new CommandQueueException("Failed to initialise JMS Command Queue.", e);
+ }
+ }
+
+ public void close() throws CommandQueueException {
+ if (null != m_oJmsSess) {
+ try {
+ m_oJmsSess.close();
+ } catch (JMSException eS) {/* Tried my best - Just continue */
+ }
+ }
+ if (null != m_oJmsConn) {
+ try {
+ m_oJmsConn.close();
+ } catch (JMSException eC) {/* Tried my best - Just continue */
+ }
+ }
+ }
+
+ public String receiveCommand(long timeout) throws CommandQueueException {
+ try {
+ Message jmsMessage = m_oCmdSrc.receive(timeout);
+
+ if (null == jmsMessage)
+ return null;
+ if (jmsMessage instanceof TextMessage) {
+ return ((TextMessage)jmsMessage).getText();
+ } else {
+ logger.warn("Message in command queue IGNORED - should be instanceof TextMessage");
+ }
+ } catch(Exception e) {
+ throw new CommandQueueException("Exception receiving message from JMS Command Queue.", e);
+ }
+
+ return null;
+ }
+
+ private void initialiseJMS(ConfigTree p_oP) throws Exception {
+ // Only check for JMS attributes if a queue JNDI name was specified
+ String sJndiName = p_oP.getAttribute(COMMAND_JNDI_NAME);
+ if (!Util.isNullString(sJndiName)) {
+ Map<String, Object> oNewAtts = new HashMap<String, Object>();
+
+ oNewAtts.put(COMMAND_JNDI_NAME, sJndiName);
+
+ String sJndiType = obtainAtt(p_oP, COMMAND_JNDI_TYPE, "jboss");
+ oNewAtts.put(COMMAND_JNDI_TYPE, sJndiType);
+ String sJndiURL = obtainAtt(p_oP, COMMAND_JNDI_URL, "localhost");
+ oNewAtts.put(COMMAND_JNDI_URL, sJndiURL);
+ Context oJndiCtx = AppServerContext.getServerContext(sJndiType,
+ sJndiURL);
+
+ String sFactClass = obtainAtt(p_oP, COMMAND_CONN_FACTORY,
+ "ConnectionFactory");
+ oNewAtts.put(COMMAND_CONN_FACTORY, sFactClass);
+ if (Util.isNullString(sFactClass))
+ sFactClass = "ConnectionFactory";
+ Object oFactCls = oJndiCtx.lookup(sFactClass);
+
+ String sMsgSelector = p_oP.getAttribute(COMMAND_MSG_SELECTOR);
+ if (null != sMsgSelector)
+ oNewAtts.put(COMMAND_MSG_SELECTOR, sMsgSelector);
+
+ boolean bIsTopic = Boolean.parseBoolean(obtainAtt(p_oP,
+ COMMAND_IS_TOPIC, "false"));
+ if (bIsTopic) {
+ TopicConnectionFactory tcf = (TopicConnectionFactory) oFactCls;
+ TopicConnection oTC = tcf.createTopicConnection();
+ Topic oTopic = (Topic) oJndiCtx.lookup(sJndiName);
+ TopicSession oSess = oTC.createTopicSession(false,
+ TopicSession.AUTO_ACKNOWLEDGE);
+ m_oJmsConn = oTC;
+ m_oJmsSess = oSess;
+ oTC.start();
+ m_oCmdSrc = oSess.createSubscriber(oTopic, sMsgSelector, true);
+ } else {
+ QueueConnectionFactory qcf = (QueueConnectionFactory) oFactCls;
+ QueueConnection oQC = qcf.createQueueConnection();
+ javax.jms.Queue oQ = (javax.jms.Queue) oJndiCtx
+ .lookup(sJndiName);
+ QueueSession oSess = oQC.createQueueSession(false,
+ TopicSession.AUTO_ACKNOWLEDGE);
+ oQC.start();
+ m_oJmsConn = oQC;
+ m_oJmsSess = oSess;
+ m_oCmdSrc = oSess.createReceiver(oQ, sMsgSelector);
+ }
+ }
+ }
+
+ /**
+ * Find an attribute in the tree (arg 0) or assign default value (arg 2)
+ *
+ * @param p_oP
+ * ConfigTree - look for attributes in this Element only
+ * @param p_sAtt
+ * String - Name of attribute to find
+ * @param p_sDefault
+ * String -default value if requested attribute is not there
+ * @return String - value of attribute, or default value (if null)
+ * @throws Exception -
+ * If requested attribute not found and no default value
+ * supplied by invoker
+ */
+ private String obtainAtt(ConfigTree p_oP, String p_sAtt, String p_sDefault)
+ throws ConfigurationException {
+ String sVal = p_oP.getAttribute(p_sAtt);
+ if ((null == sVal) && (null == p_sDefault))
+ throw new ConfigurationException("Missing or invalid <" + p_sAtt + "> attribute");
+
+ return (null != sVal) ? sVal : p_sDefault;
+ } // ________________________________
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/MessageFactoryImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/MessageFactoryImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/MessageFactoryImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,136 @@
+package org.jboss.internal.soa.esb.message.format;
+
+import java.net.URI;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import org.jboss.internal.soa.esb.message.format.serialized.SerializedMessagePlugin;
+import org.jboss.internal.soa.esb.message.format.xml.XMLMessagePlugin;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessagePlugin;
+import org.jboss.soa.esb.message.format.MessageType;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Messages may contain attachments that do not appear in the main payload body.
+ * For example, binary document formats, zip files etc.
+ *
+ * @author Mark Little
+ */
+
+public class MessageFactoryImpl extends MessageFactory
+{
+
+ public MessageFactoryImpl ()
+ {
+ reset();
+ }
+
+ public void reset ()
+ {
+ messageFormats.clear();
+
+ /*
+ * Go through the properties loaded from the property file. Anything
+ * starting with MessagePlugin.MESSAGE_PLUGIN is assumed to be a plugin
+ * that we load and add to the list.
+ */
+
+ Properties properties = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperties();
+
+ if (properties != null)
+ {
+ Enumeration names = properties.propertyNames();
+
+ while (names.hasMoreElements())
+ {
+ String attrName = (String) names.nextElement();
+
+ if (attrName.startsWith(MessagePlugin.MESSAGE_PLUGIN))
+ {
+ try
+ {
+ String pluginName = properties.getProperty(attrName);
+ Class c = Class.forName(pluginName);
+ MessagePlugin thePlugin = (MessagePlugin) c.newInstance();
+
+ messageFormats.put(thePlugin.getType(), thePlugin);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch (InstantiationException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /*
+ * Now add the default(s).
+ */
+
+ messageFormats.put(MessageType.JBOSS_XML, new XMLMessagePlugin());
+ messageFormats.put(MessageType.JAVA_SERIALIZED, new SerializedMessagePlugin());
+ }
+
+ public Message getMessage() // returns some default implementation.
+ {
+ return ((MessagePlugin) messageFormats.get(MessageType.DEFAULT_TYPE)).getMessage();
+ }
+
+ public Message getMessage(URI type) // returns a message of a specific type.
+ {
+ if (type == null)
+ throw new IllegalArgumentException();
+
+ MessagePlugin plugin = messageFormats.get(type);
+
+ if (plugin != null)
+ return plugin.getMessage();
+ else
+ return null;
+ }
+
+ public Message getMessage(Message msg, URI type) // convert a message
+ // from one form to
+ // another.
+ {
+ if ((msg == null) || (type == null))
+ throw new IllegalArgumentException();
+
+ return null;
+ }
+
+ private final Hashtable<URI, MessagePlugin> messageFormats = new Hashtable<URI, MessagePlugin>();
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/AttachmentImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/AttachmentImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/AttachmentImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.jboss.soa.esb.message.Attachment;
+
+/**
+ * Messages may contain attachments that do not appear in the main payload body.
+ * For example, binary document formats, zip files etc.
+ *
+ * @author Mark Little
+ */
+
+public class AttachmentImpl implements Attachment, java.io.Serializable
+{
+ private static final long serialVersionUID = 0x0;
+
+ public Object get(String name)
+ {
+ return _table.get(name);
+ }
+
+ public Object put(String name, Object value)
+ {
+ if (value instanceof Serializable)
+ return _table.put(name,(Serializable)value);
+ throw new IllegalArgumentException("value must be Serializable");
+ }
+
+ public Object remove(String name)
+ {
+ return _table.remove(name);
+ }
+
+ public String[] getNames()
+ {
+ return _table.keySet().toArray(new String[_table.size()]);
+ }
+
+ public Object itemAt(int index) throws IndexOutOfBoundsException
+ {
+ return _list.get(index);
+ }
+
+ public Object removeItemAt(int index) throws IndexOutOfBoundsException
+ {
+ return _list.remove(index);
+ }
+
+ public Object replaceItemAt(int index, Object value) throws IndexOutOfBoundsException
+ {
+ if (value instanceof Serializable)
+ return _list.set(index,(Serializable)value);
+ throw new IllegalArgumentException("value must be Serializable");
+ }
+
+ public void addItem(Object value)
+ {
+ if (value instanceof Serializable)
+ _list.add((Serializable)value);
+ else
+ throw new IllegalArgumentException("value must be Serializable");
+ }
+
+ public void addItemAt(int index, Object value) throws IndexOutOfBoundsException
+ {
+ if (value instanceof Serializable)
+ _list.add(index,(Serializable)value);
+ else
+ throw new IllegalArgumentException("value must be Serializable");
+ }
+
+ public int getNamedCount()
+ {
+ return _table.size();
+ }
+ public int getUnnamedCount()
+ {
+ return _list.size();
+ }
+ public String toString()
+ { return new StringBuilder()
+ .append("Attachment - Named:").append(_table.toString())
+ .append(" Unnamed:").append(_list.toString())
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object arg)
+ {
+ if (! (arg instanceof Attachment))
+ return false;
+ Attachment other = (Attachment)arg;
+
+ if (other.getNamedCount() != _table.size())
+ return false;
+ for(Map.Entry<String,Serializable>oCurr : _table.entrySet())
+ {
+ Object val = other.get(oCurr.getKey());
+ if (null==oCurr.getValue())
+ if (null==val)
+ continue;
+ else
+ return false;
+ if (!oCurr.getValue().equals(val))
+ return false;
+ }
+
+ if (other.getUnnamedCount() != _list.size())
+ return false;
+ int index = 0;
+ for (Serializable oCurr : _list)
+ {
+ Object val = other.itemAt(index++);
+ if (null==oCurr)
+ if (null==val)
+ continue;
+ else
+ return false;
+ if (!oCurr.equals(val))
+ return false;
+ }
+ return true;
+ }
+
+ ArrayList<Serializable> _list = new ArrayList<Serializable>();
+ Hashtable<String,Serializable> _table = new Hashtable<String,Serializable>();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/BodyImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,124 @@
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import java.io.Serializable;
+import java.util.Hashtable;
+
+import org.jboss.soa.esb.message.Body;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/*
+ * This implementation requires that all contents are serializable.
+ */
+
+public class BodyImpl implements Body, java.io.Serializable
+{
+ private static final long serialVersionUID = 0x0;
+
+ public BodyImpl ()
+ {
+ _content = null;
+ _objects = new Hashtable<String, Serializable>();
+ }
+
+ public void setContents (byte[] content)
+ {
+ _content = content;
+ }
+
+ public byte[] getContents ()
+ {
+ return _content;
+ }
+
+ public void add (String name, Object value)
+ {
+ if ((name == null) || (value == null))
+ throw new IllegalArgumentException();
+
+ if (value instanceof Serializable)
+ {
+ synchronized (_objects)
+ {
+ _objects.put(name, (Serializable) value);
+ }
+ }
+ else
+ throw new IllegalArgumentException("Object must be Serializable.");
+ }
+
+ public Object get (String name)
+ {
+ synchronized (_objects)
+ {
+ return _objects.get(name);
+ }
+ }
+
+ public Object remove (String name)
+ {
+ synchronized (_objects)
+ {
+ return _objects.remove(name);
+ }
+ }
+
+ public void replace (Body b)
+ {
+ if (b == null)
+ throw new IllegalArgumentException();
+
+ setContents(b.getContents());
+
+ _objects = ((BodyImpl) b)._objects;
+ }
+
+ public void merge (Body b)
+ {
+ if (b == null)
+ throw new IllegalArgumentException();
+
+ byte[] toAdd = b.getContents();
+
+ if ((toAdd != null) && (toAdd.length > 0))
+ {
+ if ((_content == null) || (_content.length == 0))
+ {
+ _content = toAdd;
+ }
+ else
+ {
+ int newSize = _content.length + toAdd.length;
+ byte[] buffer = new byte[newSize];
+
+ System.arraycopy(_content, 0, buffer, 0, _content.length);
+ System.arraycopy(toAdd, 0, buffer, _content.length, toAdd.length);
+
+ _content = buffer;
+ }
+ }
+ }
+
+ private byte[] _content;
+ private Hashtable<String, Serializable> _objects;
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/ContextImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/ContextImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/ContextImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,29 @@
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import org.jboss.soa.esb.message.Context;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+public class ContextImpl implements Context, java.io.Serializable
+{
+ private static final long serialVersionUID = 0x0;
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/FaultImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/FaultImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/FaultImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,55 @@
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Fault;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+public class FaultImpl implements Fault, java.io.Serializable
+{
+ private static final long serialVersionUID = 0x0;
+
+ public URI getCode ()
+ {
+ return _code;
+ }
+
+ public void setCode (URI code)
+ {
+ _code = code;
+ }
+
+ public String getReason ()
+ {
+ return _reason;
+ }
+
+ public void setReason (String reason)
+ {
+ _reason = reason;
+ }
+
+ private URI _code = null;
+ private String _reason = null;
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/HeaderImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,58 @@
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import java.io.Serializable;
+
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.message.Header;
+
+/**
+ * The message header. Contains such things as routing information.
+ */
+
+public class HeaderImpl implements Header, Serializable
+{
+ private static final long serialVersionUID = 0x0;
+
+ public HeaderImpl ()
+ {
+ _call = null;
+ }
+
+ // TODO add other setters/getters for artibitrary attributes
+
+ public Call getCall ()
+ {
+ return _call;
+ }
+
+ public void setCall (Call call)
+ {
+ if (call == null)
+ throw new IllegalArgumentException();
+
+ _call = call;
+ }
+
+ private Call _call;
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import java.io.Serializable;
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Attachment;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Context;
+import org.jboss.soa.esb.message.Fault;
+import org.jboss.soa.esb.message.Header;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
+import org.jboss.soa.esb.message.format.MessageType;
+
+
+/**
+ * This is the basic internal core message abstraction. A message consists of the following
+ * components:
+ *
+ * Header: the header information contains information such as the destination EPR, the
+ * sender EPR, where the reply goes etc, i.e., general message-level functional information.
+ * Context: additional information to contextualise the message; for example, transaction or
+ * security data, the identity of the ultimate receiver, or HTTP-cookie like information.
+ * Body: the actual payload of the message.
+ * Fault: any fault information associated with the message.
+ * Attachment: any attachments associated with the message.
+ *
+ * Each message, once created, has a corresponding element for these 5 components. That element
+ * may be empty (<b>NOT NULL</b>). The object representing the element can then be used to act
+ * on the corresponding data item in the message.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class MessageImpl implements Message, Serializable
+{
+ private static final long serialVersionUID = 0x0;
+
+ /**
+ * @return get the header component of the message.
+ */
+
+ public Header getHeader ()
+ {
+ return _theHeader;
+ }
+
+ /**
+ * @return get the context component of the message.
+ */
+
+ public Context getContext ()
+ {
+ return _theContext;
+ }
+
+ /**
+ * @return get the body component of the message.
+ */
+
+ public Body getBody ()
+ {
+ return _theBody;
+ }
+
+ /**
+ * @return get any faults associated with the message. These should not
+ * be application level faults, but comms level.
+ */
+
+ public Fault getFault ()
+ {
+ return _theFault;
+ }
+
+ /**
+ * @return get any message attachments.
+ */
+
+ public Attachment getAttachment ()
+ {
+ return _theAttachment;
+ }
+
+ /**
+ * @return the type of this message format.
+ */
+
+ public URI getType ()
+ {
+ return MessageType.JAVA_SERIALIZED;
+ }
+
+ /**
+ * @return Map<String,Object> - any message properties.
+ */
+ public Properties getProperties()
+ {
+ return _properties;
+ }
+
+ private HeaderImpl _theHeader = new HeaderImpl();
+ private ContextImpl _theContext = new ContextImpl();
+ private BodyImpl _theBody = new BodyImpl();
+ private FaultImpl _theFault = new FaultImpl();
+ private AttachmentImpl _theAttachment = new AttachmentImpl();
+ private Properties _properties = new PropertiesImpl();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/PropertiesImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/PropertiesImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/PropertiesImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author schifest at heuristica.com.ar
+ */
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import java.io.Serializable;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.jboss.soa.esb.message.Properties;
+
+public class PropertiesImpl implements Properties, Serializable
+{
+ private static final long serialVersionUID = 0x0;
+
+ public Object getProperty(String name)
+ {
+ return _table.get(name);
+ }
+
+ public Object getProperty(String name, Object defaultVal)
+ {
+ Object oRet = getProperty(name);
+ return (null == oRet) ? defaultVal : oRet;
+ }
+
+ public Object setProperty(String name, Object value)
+ {
+ if (value instanceof Serializable)
+ return _table.put(name, (Serializable) value);
+ else
+ throw new IllegalArgumentException("Value must be serializable");
+ }
+
+ public Object remove(String name)
+ {
+ return _table.remove(name);
+ }
+
+ public int size() {return _table.size(); }
+
+ public String[] getNames()
+ {
+ return _table.keySet().toArray(new String[_table.size()]);
+ }
+
+ public String toString()
+ {
+ return _table.toString();
+ }
+
+ @Override
+ public boolean equals(Object arg)
+ {
+ if (! (arg instanceof Properties))
+ return false;
+ Properties other = (Properties)arg;
+ if (other.size() != _table.size())
+ return false;
+ for(Map.Entry<String,Serializable>oCurr : _table.entrySet())
+ {
+ Object val = other.getProperty(oCurr.getKey());
+ if (null==oCurr.getValue())
+ if (null==val)
+ continue;
+ else
+ return false;
+ if (!oCurr.getValue().equals(val))
+ return false;
+ }
+ return true;
+ }
+
+ Hashtable<String, Serializable> _table = new Hashtable<String, Serializable>();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/SerializedMessagePlugin.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/SerializedMessagePlugin.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/SerializedMessagePlugin.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,48 @@
+package org.jboss.internal.soa.esb.message.format.serialized;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessagePlugin;
+import org.jboss.soa.esb.message.format.MessageType;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new message formats dynamically.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class SerializedMessagePlugin implements MessagePlugin
+{
+ public Message getMessage ()
+ {
+ return new MessageImpl();
+ }
+
+ public URI getType ()
+ {
+ return MessageType.JAVA_SERIALIZED;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/AttachmentImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,270 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.message.Attachment;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Messages may contain attachments that do not appear in the main payload body.
+ * For example, binary document formats, zip files etc.
+ *
+ * @author Mark Little
+ */
+
+public class AttachmentImpl implements Attachment, java.io.Serializable
+{
+ public static final String ATTACHMENT_TAG = "Attachment";
+ public static final String NAME_ATTR = "name";
+ public static final String NAMED_TAG = "Named";
+ public static final String UNNAMED_TAG = "UnNamed";
+
+ private static final long serialVersionUID = 0x0;
+
+ public Object get(String name)
+ {
+ return _table.get(name);
+ }
+
+ public Object put(String name, Object value)
+ {
+ if (value instanceof Serializable)
+ return _table.put(name, (Serializable) value);
+ throw new IllegalArgumentException("value must be Serializable");
+ }
+
+ public Object remove(String name)
+ {
+ return _table.remove(name);
+ }
+
+ public String[] getNames()
+ {
+ return _table.keySet().toArray(new String[_table.size()]);
+ }
+
+ public Object itemAt(int index) throws IndexOutOfBoundsException
+ {
+ return _list.get(index);
+ }
+
+ public Object removeItemAt(int index) throws IndexOutOfBoundsException
+ {
+ return _list.remove(index);
+ }
+
+ public Object replaceItemAt(int index, Object value)
+ throws IndexOutOfBoundsException
+ {
+ if (value instanceof Serializable)
+ return _list.set(index, (Serializable) value);
+ throw new IllegalArgumentException("value must be Serializable");
+ }
+
+ public void addItem(Object value)
+ {
+ if (value instanceof Serializable)
+ _list.add((Serializable) value);
+ else
+ throw new IllegalArgumentException("value must be Serializable");
+ }
+
+ public void addItemAt(int index, Object value)
+ throws IndexOutOfBoundsException
+ {
+ if (value instanceof Serializable)
+ _list.add(index, (Serializable) value);
+ else
+ throw new IllegalArgumentException("value must be Serializable");
+ }
+
+ public int getNamedCount()
+ {
+ return _table.size();
+ }
+
+ public int getUnnamedCount()
+ {
+ return _list.size();
+ }
+
+ public String toString()
+ {
+ return new StringBuilder().append("Attachment - Named:").append(
+ _table.toString()).append(" Unnamed:").append(_list.toString())
+ .toString();
+ }
+
+ /**
+ * toXML(elem) - Will build a child element with appropriate values and
+ * append it to arg0
+ *
+ * @param elem
+ * Element - where to add 'this' as a child node
+ * @return Element - 'this' as the added Element, or <null> if no
+ * properties in table and nothing was appended to arg0
+ * @see XMLUtil.ATTACHMENT_TAG
+ */
+ public Element toXML(Element elem)
+ {
+ if (_table.size() < 1 && _list.size() < 1)
+ return null;
+
+ Document doc = elem.getOwnerDocument();
+ Element thisElement = doc.createElement(ATTACHMENT_TAG);
+
+ listToXml(doc, thisElement);
+ tableToXml(doc, thisElement);
+
+ elem.appendChild(thisElement);
+ return thisElement;
+ }
+
+ private void tableToXml(Document doc, Element elem)
+ {
+ for (Map.Entry<String, Serializable> oCurr : _table.entrySet())
+ {
+ Element named = doc.createElement(NAMED_TAG);
+ named.setAttribute(NAME_ATTR, oCurr.getKey());
+ named.appendChild(doc.createCDATASection(Base64.encodeObject(oCurr
+ .getValue())));
+ elem.appendChild(named);
+ }
+ }
+
+ private void listToXml(Document doc, Element elem)
+ {
+ for (Serializable oCurr : _list)
+ {
+ Element anonymous = doc.createElement(UNNAMED_TAG);
+ anonymous.appendChild(doc.createCDATASection(Base64
+ .encodeObject(oCurr)));
+ elem.appendChild(anonymous);
+ }
+ }
+
+ /**
+ * fromXml(elem) - Populate properties found in appropriate child element
+ *
+ * @see XMLUtil.ATTACHMENT_TAG
+ * @param elem -
+ * Element where to look for child nodes
+ */
+ public void fromXML(Element elem)
+ {
+ _table.clear();
+ _list.clear();
+
+ NodeList NL = elem.getElementsByTagName(ATTACHMENT_TAG);
+ for (int i1 = 0; i1 < NL.getLength(); i1++)
+ {
+ Node oCurr = NL.item(i1);
+ if ((oCurr instanceof Element))
+ {
+ listFromXml((Element) oCurr);
+ tableFromXml((Element) oCurr);
+ }
+ }
+ }
+
+ private void listFromXml(Element elem)
+ {
+ NodeList anonymous = elem.getElementsByTagName(UNNAMED_TAG);
+ for (int i1 = 0; i1 < anonymous.getLength(); i1++)
+ {
+ Node oCurr = anonymous.item(i1);
+ if (oCurr instanceof Element)
+ {
+ CDATASection cdata = (CDATASection) oCurr.getFirstChild();
+ Object value = Base64.decodeToObject(cdata.getWholeText());
+ _list.add((Serializable) value);
+ }
+ }
+ }
+
+ private void tableFromXml(Element elem)
+ {
+ NodeList named = elem.getElementsByTagName(NAMED_TAG);
+ for (int i1 = 0; i1 < named.getLength(); i1++)
+ {
+ Node oCurr = named.item(i1);
+ if (oCurr instanceof Element)
+ {
+ CDATASection cdata = (CDATASection) oCurr.getFirstChild();
+ String name = ((Element) oCurr).getAttribute(NAME_ATTR);
+ Object value = Base64.decodeToObject(cdata.getWholeText());
+ _table.put(name, (Serializable) value);
+ }
+ }
+ }
+
+ @Override
+ public boolean equals(Object arg)
+ {
+ if (! (arg instanceof Attachment))
+ return false;
+ Attachment other = (Attachment)arg;
+
+ if (other.getNamedCount() != _table.size())
+ return false;
+ for(Map.Entry<String,Serializable>oCurr : _table.entrySet())
+ {
+ Object val = other.get(oCurr.getKey());
+ if (null==oCurr.getValue())
+ if (null==val)
+ continue;
+ else
+ return false;
+ if (!oCurr.getValue().equals(val))
+ return false;
+ }
+
+ if (other.getUnnamedCount() != _list.size())
+ return false;
+ int index = 0;
+ for (Serializable oCurr : _list)
+ {
+ Object val = other.itemAt(index++);
+ if (null==oCurr)
+ if (null==val)
+ continue;
+ else
+ return false;
+ if (!oCurr.equals(val))
+ return false;
+ }
+ return true;
+ }
+
+ ArrayList<Serializable> _list = new ArrayList<Serializable>();
+ Hashtable<String, Serializable> _table = new Hashtable<String, Serializable>();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/BodyImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,217 @@
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.jboss.internal.soa.esb.message.format.xml.marshal.MarshalUnmarshalManager;
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.MarshalException;
+import org.jboss.soa.esb.UnmarshalException;
+import org.jboss.soa.esb.message.Body;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/*
+ * A Body implementation that serializes to XML.
+ */
+
+public class BodyImpl implements Body
+{
+ public static final String BODY_TAG = "Body";
+
+ public static final String BYTES_TAG = "Bytes";
+
+ public BodyImpl()
+ {
+ _content = null;
+ _objects = new Hashtable<String, Object>();
+ }
+
+ public void add(String name, Object value)
+ {
+ if ((name == null) || (value == null))
+ throw new IllegalArgumentException();
+
+ synchronized (_objects)
+ {
+ _objects.put(name, value);
+ }
+ }
+
+ public Object get(String name)
+ {
+ synchronized (_objects)
+ {
+ return _objects.get(name);
+ }
+ }
+
+ public Object remove(String name)
+ {
+ synchronized (_objects)
+ {
+ return _objects.remove(name);
+ }
+ }
+
+ public Element toXML(Element envelope) throws MarshalException
+ {
+ Document doc = envelope.getOwnerDocument();
+ Element bodyElement = doc.createElement(BODY_TAG);
+
+ envelope.appendChild(bodyElement);
+
+ if (_content != null)
+ {
+ Element byteElement = doc.createElement(BYTES_TAG);
+
+ byteElement.appendChild(doc.createCDATASection(Base64
+ .encodeBytes(_content)));
+
+ bodyElement.appendChild(byteElement);
+ }
+
+ /*
+ * This would normally be handled by an external adapter.
+ */
+
+ Enumeration<String> keys = _objects.keys();
+
+ while (keys.hasMoreElements())
+ {
+ String key = keys.nextElement();
+ Object value = _objects.get(key);
+
+ Element objElement = doc.createElement(key);
+
+ if (MarshalUnmarshalManager.getInstance().marshal(objElement, value))
+ bodyElement.appendChild(objElement);
+ else
+ throw new MarshalException("Cannot pack object "+key);
+ }
+
+ return bodyElement;
+ }
+
+ public void fromXML(Element envelope) throws UnmarshalException
+ {
+ NodeList nl = envelope.getChildNodes();
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ /*
+ * TODO
+ *
+ * In the past, bugs in certain Dom implementations mean that
+ * getElementsByName did not always work. Still the case? Plus this
+ * way is quicker.
+ */
+
+ if (nl.item(i).getNodeName().equals(BODY_TAG))
+ {
+ NodeList children = nl.item(i).getChildNodes();
+
+ for (int j = 0; j < children.getLength(); j++)
+ {
+ Object xxx = children.item(j);
+ if (!(xxx instanceof Element))
+ continue;
+ Element child = (Element) xxx;
+
+ if (child.getNodeName().equals(BYTES_TAG))
+ {
+ CDATASection cdata = (CDATASection) child.getFirstChild();
+
+ _content = Base64.decode(cdata.getWholeText());
+ }
+ else
+ {
+ Object value = MarshalUnmarshalManager.getInstance().unmarshal((Element) child.getFirstChild());
+
+ if (value == null)
+ throw new UnmarshalException("Cannot unpack object "+child.getNodeName());
+ else
+ _objects.put(child.getNodeName(), value);
+ }
+ }
+ }
+ }
+ }
+
+ public void setContents(byte[] content)
+ {
+ _content = content;
+ }
+
+ public byte[] getContents()
+ {
+ return _content;
+ }
+
+ public void replace(Body b)
+ {
+ if (b == null)
+ throw new IllegalArgumentException();
+
+ setContents(b.getContents());
+
+ _objects = ((BodyImpl) b)._objects;
+ }
+
+ public void merge(Body b)
+ {
+ if (b == null)
+ throw new IllegalArgumentException();
+
+ byte[] toAdd = b.getContents();
+
+ if ((toAdd != null) && (toAdd.length > 0))
+ {
+ if ((_content == null) || (_content.length == 0))
+ {
+ _content = toAdd;
+ }
+ else
+ {
+ int newSize = _content.length + toAdd.length;
+ byte[] buffer = new byte[newSize];
+
+ System.arraycopy(_content, 0, buffer, 0, _content.length);
+ System.arraycopy(toAdd, 0, buffer, _content.length,
+ toAdd.length);
+
+ _content = buffer;
+ }
+ }
+
+ _objects.putAll(((BodyImpl) b)._objects);
+ }
+
+ private byte[] _content;
+
+ private Hashtable<String, Object> _objects;
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/ContextImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/ContextImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/ContextImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,45 @@
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import org.jboss.soa.esb.message.Context;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+public class ContextImpl implements Context
+{
+ public static final String CONTEXT_TAG = "Context";
+
+ public Element toXML (Element envelope)
+ {
+ Document doc = envelope.getOwnerDocument();
+ Element contextElement = doc.createElement(CONTEXT_TAG);
+
+ envelope.appendChild(contextElement);
+
+ return contextElement;
+ }
+
+ public void fromXML (Element envelope)
+ {
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/FaultImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/FaultImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/FaultImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,134 @@
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Fault;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+public class FaultImpl implements Fault
+{
+ public static final String FAULT_TAG = "Fault";
+
+ public static final String CODE_TAG = "Code";
+
+ public static final String REASON_TAG = "Reason";
+
+ public URI getCode()
+ {
+ return _code;
+ }
+
+ public void setCode(URI code)
+ {
+ _code = code;
+ }
+
+ public String getReason()
+ {
+ return _reason;
+ }
+
+ public void setReason(String reason)
+ {
+ _reason = reason;
+ }
+
+ public Element toXML(Element envelope)
+ {
+ Document doc = envelope.getOwnerDocument();
+ Element faultElement = doc.createElement(FAULT_TAG);
+
+ if (_code != null)
+ {
+ Element codeElement = doc.createElement(CODE_TAG);
+ Text content = doc.createTextNode(_code.toString());
+
+ codeElement.appendChild(content);
+
+ faultElement.appendChild(codeElement);
+ }
+
+ if (_reason != null)
+ {
+ Element reasonElement = doc.createElement(REASON_TAG);
+ Text content = doc.createTextNode(_reason);
+
+ reasonElement.appendChild(content);
+
+ faultElement.appendChild(reasonElement);
+ }
+
+ if ((_code != null) || (_reason != null))
+ {
+ envelope.appendChild(faultElement);
+
+ return faultElement;
+ }
+ else
+ return envelope;
+ }
+
+ public void fromXML (Element envelope)
+ {
+ NodeList nl = envelope.getChildNodes();
+
+ _code = null;
+ _reason = null;
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ if (nl.item(i).getNodeName().equals(FAULT_TAG))
+ {
+ NodeList children = nl.item(i).getChildNodes();
+
+ for (int j = 0; j < children.getLength(); j++)
+ {
+ Element child = (Element) children.item(j);
+
+ if (child.getNodeName().equals(CODE_TAG))
+ {
+ try
+ {
+ _code = new URI(child.getFirstChild().getNodeValue());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ if (child.getNodeName().equals(REASON_TAG))
+ _reason = child.getFirstChild().getNodeValue();
+ }
+ }
+ }
+ }
+
+ private URI _code = null;
+ private String _reason = null;
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/HeaderImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,101 @@
+package org.jboss.internal.soa.esb.message.format.xml;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import org.jboss.internal.soa.esb.addressing.CallHelper;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.message.Header;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * The message header. Contains such things as routing information.
+ */
+
+public class HeaderImpl implements Header
+{
+ public static final String HEADER_TAG = "Header";
+
+ public HeaderImpl ()
+ {
+ _call = null;
+ }
+
+ // TODO add other setters/getters for artibitrary attributes
+
+ public Call getCall ()
+ {
+ return _call;
+ }
+
+ public void setCall (Call call)
+ {
+ if (call == null)
+ throw new IllegalArgumentException();
+
+ _call = call;
+ }
+
+ public Element toXML (Element envelope)
+ {
+ Document doc = envelope.getOwnerDocument();
+
+ // TODO remove MAGIC strings!!
+
+ Element headerElement = doc.createElement(HEADER_TAG);
+
+ envelope.appendChild(headerElement);
+
+ if (_call != null)
+ return CallHelper.toXML(_call, doc, headerElement);
+ else
+ return headerElement;
+ }
+
+ public void fromXML (Element envelope)
+ {
+ _call = new Call();
+
+ NodeList nl = envelope.getChildNodes();
+ Element headerElement = null;
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ Node n = nl.item(i);
+
+ if (n.getNodeName().equals(HEADER_TAG))
+ {
+ headerElement = (Element) n;
+ break;
+ }
+ }
+
+ // TODO error handling!!
+
+ if (headerElement != null)
+ _call = CallHelper.fromXML(headerElement);
+ }
+
+ private Call _call;
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,197 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Attachment;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Context;
+import org.jboss.soa.esb.message.Fault;
+import org.jboss.soa.esb.message.Header;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * This is the basic internal core message abstraction. A message consists of the following
+ * components:
+ *
+ * Header: the header information contains information such as the destination EPR, the
+ * sender EPR, where the reply goes etc, i.e., general message-level functional information.
+ * Context: additional information to contextualise the message; for example, transaction or
+ * security data, the identity of the ultimate receiver, or HTTP-cookie like information.
+ * Body: the actual payload of the message.
+ * Fault: any fault information associated with the message.
+ * Attachment: any attachments associated with the message.
+ * Properties: any properties associated with the message.
+ *
+ * Each message, once created, has a corresponding element for these 5 components. That element
+ * may be empty (<b>NOT NULL</b>). The object representing the element can then be used to act
+ * on the corresponding data item in the message.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class MessageImpl implements Message
+{
+ public static final String ENVELOPE_TAG = "Envelope";
+
+ /**
+ * @return get the header component of the message.
+ */
+
+ public Header getHeader ()
+ {
+ return _theHeader;
+ }
+
+ /**
+ * @return get the context component of the message.
+ */
+
+ public Context getContext ()
+ {
+ return _theContext;
+ }
+
+ /**
+ * @return get the body component of the message.
+ */
+
+ public Body getBody ()
+ {
+ return _theBody;
+ }
+
+ /**
+ * @return get any faults associated with the message. These should not
+ * be application level faults, but comms level.
+ */
+
+ public Fault getFault ()
+ {
+ return _theFault;
+ }
+
+ /**
+ * @return get any message attachments.
+ */
+
+ public Attachment getAttachment ()
+ {
+ return _theAttachment;
+ }
+
+ /**
+ * @return the type of this message format.
+ */
+
+ public URI getType ()
+ {
+ return MessageType.JBOSS_XML;
+ }
+ /**
+ * getProperties()
+ * @return org.jboss.soa.esb.message.Properties - any message properties.
+ */
+ public Properties getProperties()
+ {
+ return _theProperties;
+ }
+
+ // to/from XML here, rather than on individual elements
+
+ public Document toXML (Document doc)
+ {
+ try
+ {
+ // TODO remove magic strings!
+
+ Element envelope = doc.createElement(ENVELOPE_TAG);
+
+ doc.appendChild(envelope);
+
+ _theHeader.toXML(envelope);
+ _theContext.toXML(envelope);
+ _theBody.toXML(envelope);
+ _theFault.toXML(envelope);
+ _theAttachment.toXML(envelope);
+ _theProperties.toXML(envelope);
+
+ return doc;
+ }
+ catch (Exception ex)
+ {
+ // TODO error handling
+
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+
+ public void fromXML (Document doc)
+ {
+ try
+ {
+ NodeList nl = doc.getChildNodes();
+ Element envelope = null;
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ Node n = nl.item(i);
+
+ if (n.getNodeName().equals(ENVELOPE_TAG))
+ {
+ envelope = (Element) n;
+ break;
+ }
+ }
+
+ _theHeader.fromXML(envelope);
+ _theContext.fromXML(envelope);
+ _theBody.fromXML(envelope);
+ _theFault.fromXML(envelope);
+ _theAttachment.fromXML(envelope);
+ _theProperties.fromXML(envelope);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ // TODO add equality operator(s)
+
+ private HeaderImpl _theHeader = new HeaderImpl();
+ private ContextImpl _theContext = new ContextImpl();
+ private BodyImpl _theBody = new BodyImpl();
+ private FaultImpl _theFault = new FaultImpl();
+ private AttachmentImpl _theAttachment = new AttachmentImpl();
+ private PropertiesImpl _theProperties = new PropertiesImpl();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/PropertiesImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/PropertiesImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/PropertiesImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,165 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author schifest at heuristica.com.ar
+ */
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import java.io.Serializable;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.message.Properties;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class PropertiesImpl implements Properties
+{
+ public static final String PROPERTIES_TAG = "Properties";
+
+ public Object getProperty(String name)
+ {
+ return _table.get(name);
+ }
+
+ public Object getProperty(String name, Object defaultVal)
+ {
+ Object oRet = getProperty(name);
+ return (null == oRet) ? defaultVal : oRet;
+ }
+
+ public Object setProperty(String name, Object value)
+ {
+ if (value instanceof Serializable)
+ return _table.put(name, (Serializable) value);
+ else
+ throw new IllegalArgumentException("value must be XmlSerializable");
+ }
+
+ public Object remove(String name)
+ {
+ return _table.remove(name);
+ }
+
+ public int size() {return _table.size(); }
+
+ public String[] getNames()
+ {
+ return _table.keySet().toArray(new String[_table.size()]);
+ }
+
+ /**
+ * toXML(elem) - Will build a child element with appropriate values and
+ * append it to arg0
+ *
+ * @param elem
+ * Element - where to add 'this' as a child node
+ * @return Element - 'this' as the added Element, or <null> if no
+ * properties in table and nothing was appended to arg0
+ */
+ public Element toXML(Element elem)
+ {
+ if (_table.size() < 1)
+ return null;
+
+ Document doc = elem.getOwnerDocument();
+ Element thisElement = doc.createElement(PROPERTIES_TAG);
+
+ boolean bAdd = false;
+ for (Map.Entry<String, Serializable> oCurr : _table.entrySet())
+ {
+ Element oProp = doc.createElement(oCurr.getKey());
+ oProp.appendChild(doc.createCDATASection(Base64.encodeObject(oCurr
+ .getValue())));
+ thisElement.appendChild(oProp);
+ bAdd = true;
+ }
+ if (bAdd)
+ {
+ elem.appendChild(thisElement);
+ return thisElement;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * fromXml(elem) - Populate properties found in appropriate child element
+ *
+ * @see XMLUtil.PROPERTIES_TAG
+ * @param elem -
+ * Element where to look for child nodes
+ */
+ public void fromXML(Element elem)
+ {
+ _table.clear();
+
+ NodeList NL = elem.getElementsByTagName(PROPERTIES_TAG);
+ for (int i1 = 0; i1 < NL.getLength(); i1++)
+ {
+ Node oCurr = NL.item(i1);
+ if (!(oCurr instanceof Element))
+ continue;
+ NodeList props = oCurr.getChildNodes();
+ for (int i2 = 0; i2 < props.getLength(); i2++)
+ {
+ Node oProp = props.item(i2);
+ if (oProp instanceof Element)
+ {
+ CDATASection cdata = (CDATASection) oProp.getFirstChild();
+ Object value = Base64.decodeToObject(cdata.getWholeText());
+ _table.put(oProp.getNodeName(), (Serializable) value);
+ }
+ }
+ }
+ }
+
+ public String toString()
+ {
+ return _table.toString();
+ }
+
+ @Override
+ public boolean equals(Object arg)
+ {
+ if (! (arg instanceof Properties))
+ return false;
+ Properties other = (Properties)arg;
+ if (other.size() != _table.size())
+ return false;
+ for(Map.Entry<String,Serializable>oCurr : _table.entrySet())
+ {
+ Object val = other.getProperty(oCurr.getKey());
+ if (null==oCurr.getValue())
+ if (null==val)
+ continue;
+ else
+ return false;
+ if (!oCurr.getValue().equals(val))
+ return false;
+ }
+ return true;
+ }
+
+ Hashtable<String, Serializable> _table = new Hashtable<String, Serializable>();
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLMessagePlugin.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLMessagePlugin.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLMessagePlugin.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,48 @@
+package org.jboss.internal.soa.esb.message.format.xml;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessagePlugin;
+import org.jboss.soa.esb.message.format.MessageType;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new message formats dynamically.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class XMLMessagePlugin implements MessagePlugin
+{
+ public Message getMessage ()
+ {
+ return new MessageImpl();
+ }
+
+ public URI getType ()
+ {
+ return MessageType.JBOSS_XML;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/*
+ * Copyright (c) 2002, 2003, Arjuna Technologies Limited.
+ *
+ * XMLUtil.java
+ */
+
+package org.jboss.internal.soa.esb.message.format.xml;
+
+public class XMLUtil
+{
+ public static final String ESB_PREFIX = "jbesb";
+ public static final String ESB_NAMESPACE_URI = "http://www.jboss.org/ws/2006/09/esb";
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/MarshalUnmarshalManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/MarshalUnmarshalManager.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/MarshalUnmarshalManager.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,157 @@
+package org.jboss.internal.soa.esb.message.format.xml.marshal;
+
+import java.net.URI;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import org.jboss.soa.esb.MarshalException;
+import org.jboss.soa.esb.UnmarshalException;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.w3c.dom.Element;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new Object marshal/unmarshal formats dynamically. When packing
+ * objects in XML, the system runs through the list of registered plug-ins until it
+ * finds one that can deal with the object type (or faults). When packing, the name (type)
+ * of the plug-in that packed the object is also attached to facilitate unpacking.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class MarshalUnmarshalManager
+{
+ public static MarshalUnmarshalManager getInstance ()
+ {
+ return _instance;
+ }
+
+ private MarshalUnmarshalManager ()
+ {
+ /*
+ * Go through the properties loaded from the property file. Anything
+ * starting with MessagePlugin.MESSAGE_PLUGIN is assumed to be a plugin
+ * that we load and add to the list.
+ */
+
+ Properties properties = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperties();
+
+ if (properties != null)
+ {
+ Enumeration names = properties.propertyNames();
+
+ while (names.hasMoreElements())
+ {
+ String attrName = (String) names.nextElement();
+
+ if (attrName.startsWith(MarshalUnmarshalPlugin.MARSHAL_UNMARSHAL_PLUGIN))
+ {
+ try
+ {
+ String pluginName = properties.getProperty(attrName);
+ Class c = Class.forName(pluginName);
+ MarshalUnmarshalPlugin thePlugin = (MarshalUnmarshalPlugin) c.newInstance();
+
+ _plugins.put(thePlugin.type(), thePlugin);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch (InstantiationException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ /*
+ * Add in the default plugin.
+ */
+
+ SerializedMarshalUnmarshalPlugin defaultPlugin = new SerializedMarshalUnmarshalPlugin();
+
+ _plugins.put(defaultPlugin.type(), defaultPlugin);
+ }
+ }
+
+ /**
+ * Pack the provided object into the document.
+ *
+ * @param doc the XML document.
+ * @param param the object to pack.
+ *
+ * @return <code>true</code> if the object was packed, <code>false</code> otherwise.
+ * @throws MarshalException thrown if there is a problem packing.
+ */
+
+ public boolean marshal (Element doc, Object param) throws MarshalException
+ {
+ Enumeration<URI> keys = _plugins.keys();
+
+ while (keys.hasMoreElements())
+ {
+ if (_plugins.get(keys.nextElement()).marshal(doc, param))
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Unpack the object from the document.
+ *
+ * @param doc the document.
+ *
+ * @return the object, or <code>null</code> if this implementation cannot deal with the
+ * format.
+ * @throws UnmarshalException thrown if there is a problem unpacking.
+ */
+
+ public Object unmarshal (Element doc) throws UnmarshalException
+ {
+ Enumeration<URI> keys = _plugins.keys();
+
+ while (keys.hasMoreElements())
+ {
+ URI uri = keys.nextElement();
+
+ if (doc.getNodeName().equals(uri.toString()))
+ {
+ return _plugins.get(uri).unmarshal(doc);
+ }
+ }
+
+ return null;
+ }
+
+ private Hashtable<URI,MarshalUnmarshalPlugin> _plugins = new Hashtable<URI,MarshalUnmarshalPlugin>();
+
+ private static final MarshalUnmarshalManager _instance = new MarshalUnmarshalManager();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/MarshalUnmarshalPlugin.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/MarshalUnmarshalPlugin.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/MarshalUnmarshalPlugin.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,73 @@
+package org.jboss.internal.soa.esb.message.format.xml.marshal;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.MarshalException;
+import org.jboss.soa.esb.UnmarshalException;
+import org.w3c.dom.Element;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new Object marshal/unmarshal formats dynamically. When packing
+ * objects in XML, the system runs through the list of registered plug-ins until it
+ * finds one that can deal with the object type (or faults). When packing, the name (type)
+ * of the plug-in that packed the object is also attached to facilitate unpacking.
+ *
+ * @author Mark Little
+ *
+ */
+
+public interface MarshalUnmarshalPlugin
+{
+ public static final String MARSHAL_UNMARSHAL_PLUGIN = "org.jboss.soa.esb.message.format.xml.plugin";
+
+ /**
+ * Pack the provided object into the document.
+ *
+ * @param doc the XML document.
+ * @param param the object to pack.
+ *
+ * @return <code>true</code> if the object was packed, <code>false</code> otherwise.
+ * @throws MarshalException thrown if there is a problem packing.
+ */
+
+ public boolean marshal (Element doc, Object param) throws MarshalException;
+
+ /**
+ * Unpack the object from the document.
+ *
+ * @param doc the document.
+ *
+ * @return the object, or <code>null</code> if this implementation cannot deal with the
+ * format.
+ * @throws UnmarshalException thrown if there is a problem unpacking.
+ */
+
+ public Object unmarshal (Element doc) throws UnmarshalException;
+
+ /**
+ * @return the unique name for this plugin.
+ */
+
+ public URI type ();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/SerializedMarshalUnmarshalPlugin.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/SerializedMarshalUnmarshalPlugin.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/marshal/SerializedMarshalUnmarshalPlugin.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,126 @@
+package org.jboss.internal.soa.esb.message.format.xml.marshal;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.MarshalException;
+import org.jboss.soa.esb.UnmarshalException;
+import org.w3c.dom.CDATASection;
+import org.w3c.dom.Element;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new Object marshal/unmarshal formats dynamically. When packing
+ * objects in XML, the system runs through the list of registered plug-ins until it
+ * finds one that can deal with the object type (or faults). When packing, the name (type)
+ * of the plug-in that packed the object is also attached to facilitate unpacking.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class SerializedMarshalUnmarshalPlugin implements MarshalUnmarshalPlugin
+{
+ public SerializedMarshalUnmarshalPlugin ()
+ {
+ try
+ {
+ _type = new URI("urn:xml:marshalunmarshal:plugin:serialization");
+ }
+ catch (URISyntaxException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ /**
+ * Pack the provided object into the document.
+ *
+ * @param doc the XML document.
+ * @param param the object to pack.
+ *
+ * @return <code>true</code> if the object was packed, <code>false</code> otherwise.
+ * @throws MarshalException thrown if there is a problem packing.
+ */
+
+ public boolean marshal (Element doc, Object param) throws MarshalException
+ {
+ if (param instanceof Serializable)
+ {
+ // we can deal with this type!
+
+ try
+ {
+ Element nodeElement = doc.getOwnerDocument().createElement(type().toString());
+
+ nodeElement.appendChild(doc.getOwnerDocument().createCDATASection(Base64.encodeObject((Serializable) param)));
+
+ doc.appendChild(nodeElement);
+ }
+ catch (Exception ex)
+ {
+ throw new MarshalException(ex.toString());
+ }
+
+ return true;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Unpack the object from the document.
+ *
+ * @param doc the document.
+ *
+ * @return the object, or <code>null</code> if this implementation cannot deal with the
+ * format.
+ * @throws UnmarshalException thrown if there is a problem unpacking.
+ */
+
+ public Object unmarshal (Element doc) throws UnmarshalException
+ {
+ if (doc.getNodeName().equals(type().toString()))
+ {
+ CDATASection cdata = (CDATASection) doc.getFirstChild();
+
+ return Base64.decodeToObject(cdata.getWholeText());
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @return the unique name for this plugin.
+ */
+
+ public URI type ()
+ {
+ return _type;
+ }
+
+ private URI _type = null;
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/notification/MacroExpander.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/notification/MacroExpander.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/notification/MacroExpander.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,98 @@
+/*
+ * 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.internal.soa.esb.notification;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+
+/**
+ * MacroExpander class.
+ * <p/>
+ * This class takes a DOM and iterates over it, replacing all "macro" tokens in
+ * any attribute values using the values from the supplied Map.
+ *
+ * @author <a href="mailto:schifest at gmail.com">Esteban Shifman</a>
+ */
+public class MacroExpander {
+ private static final String CTX_PREFIX = "@@ctx@@";
+
+ public static final String CTX_BATCH_UID = CTX_PREFIX + "batchUid";
+
+ public static final String CTX_BATCH_NUM = CTX_PREFIX + "batchNum";
+
+ public static final String CTX_INPUT_FILE = CTX_PREFIX + "inputFile";
+
+ public static final String CTX_POST_FILE = CTX_PREFIX + "postFile";
+
+ private static final String[] s_saMacros = {
+ CTX_BATCH_UID, CTX_BATCH_NUM, CTX_INPUT_FILE, CTX_POST_FILE };
+
+ /**
+ * Perform a macro replacement on the DOM tree attribute values
+ * of the supplied ConfigTree using the supplied macro token
+ * replacement map.
+ * @param domTree The DOM Tree to be operated on.
+ * @param replacementTokenMapMap The token replacement map.
+ */
+ public static void replaceMacros(ConfigTree domTree, Map replacementTokenMap) {
+
+ List<KeyValuePair> changed = new ArrayList<KeyValuePair>();
+ for (String currAtt : domTree.getAttributeNames())
+ {
+ String sVal = domTree.getAttribute(currAtt);
+ boolean bSubst = false;
+ int iPos = 0;
+
+ while (0 <= (iPos = sVal.indexOf(CTX_PREFIX, 0))) {
+ String sRest = sVal.substring(iPos);
+ for (int ii = 0; ii < s_saMacros.length; ii++) {
+ String sMac = s_saMacros[ii];
+ if (!sRest.startsWith(sMac)) {
+ continue;
+ }
+ Object oRpl = (null != replacementTokenMap) ? replacementTokenMap.get(sMac) : null;
+ if (null == oRpl) {
+ continue;
+ }
+ bSubst = true;
+ sVal = sVal.substring(0, iPos) + oRpl.toString() + sVal.substring(iPos + sMac.length());
+ break;
+ }
+ }
+ if (bSubst)
+ changed.add(new KeyValuePair(currAtt,sVal));
+ }
+ for (KeyValuePair kvp : changed)
+ domTree.setAttribute(kvp.getKey(),kvp.getValue());
+ changed = null;
+
+ // Iterate over the child elements and recursively call this method...
+ for (ConfigTree child : domTree.getAllChildren())
+ replaceMacros(child, replacementTokenMap);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/parameters/ParamFileRepository.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/parameters/ParamFileRepository.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/parameters/ParamFileRepository.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,277 @@
+package org.jboss.internal.soa.esb.parameters;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.naming.CompoundName;
+import javax.naming.InvalidNameException;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.parameters.ParamRepository;
+import org.jboss.soa.esb.parameters.ParamRepositoryException;
+
+/**
+ * This class provides basic file-based storage/retrieval of parameter trees for
+ * the JBoss ESB. <p/> This class creates a hierarchical parameter file
+ * structure on the file system. E.g. the value for a parameter named
+ * "org/jboss/param1" is stored in a file called "param1" in the folder "<root>/org/jboss",
+ * where "root" is either the working directory (default) or the directory
+ * specified in the "org.jboss.soa.esb.paramsRepository.file.root" System
+ * property.
+ *
+ * @author Esteban
+ *
+ */
+public class ParamFileRepository implements ParamRepository
+{
+
+ /**
+ * System property defining the repository root directory.
+ */
+ public static final String FILE_PARAMS_REPOS_ROOT = "org.jboss.soa.esb.paramsRepository.file.root";
+
+ /**
+ * The repository root dir.
+ */
+ private File root;
+
+ /**
+ * Logger.
+ */
+ private Logger logger = Logger.getLogger(ParamFileRepository.class);
+
+ /**
+ * Public default constructor.
+ */
+ public ParamFileRepository()
+ {
+ String rootDir = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE)
+ .getProperty(FILE_PARAMS_REPOS_ROOT);
+
+ // Set the repository root directory.
+ if (rootDir == null)
+ {
+ // set it to the working dir.
+ root = new File("./");
+ } else
+ {
+ root = new File(rootDir);
+ if (!root.exists())
+ {
+ throw new IllegalStateException(
+ "Nonexistant directory specified in the ["
+ + FILE_PARAMS_REPOS_ROOT
+ + "] System property: "
+ + root.getAbsolutePath());
+ }
+ }
+
+ logger.info("Setting parameter repository root dir to ["
+ + root.getAbsolutePath() + "].");
+ }
+
+ public void add(String name, String value) throws ParamRepositoryException
+ {
+ FileParamName nameParam = asserNameOK(name);
+ if (value == null)
+ {
+ throw new IllegalArgumentException(
+ "null 'value' arg in method call.");
+ }
+
+ synchronized (this)
+ {
+ File paramFile = toParamFile(nameParam);
+
+ paramFile.getParentFile().mkdirs();
+ FileOutputStream fileStream = null;
+ try
+ {
+ fileStream = new FileOutputStream(paramFile);
+ fileStream.write(value.getBytes("UTF-8"));
+ } catch (IOException e)
+ {
+ throw new ParamRepositoryException(
+ "IO Error while storing param [" + nameParam + "].", e);
+ } finally
+ {
+ try
+ {
+ if (fileStream != null)
+ {
+ fileStream.flush();
+ fileStream.close();
+ }
+ } catch (IOException e)
+ {
+ logger.warn("Unable to close param file: "
+ + paramFile.getAbsolutePath(), e);
+ }
+ }
+ }
+ }
+
+ public String get(String name) throws ParamRepositoryException
+ {
+ FileParamName paramName = asserNameOK(name);
+
+ synchronized (this)
+ {
+ File paramFile = new File(name);
+
+ if (!paramFile.exists())
+ {
+ paramFile = toParamFile(paramName);
+ if (!paramFile.exists())
+ {
+ return null;
+ }
+ }
+
+ InputStream fileStream = null;
+ try
+ {
+ fileStream = new FileInputStream(paramFile);
+ byte[] value = StreamUtils.readStream(fileStream);
+ return new String(value, "UTF-8");
+ } catch (Exception e)
+ {
+ throw new ParamRepositoryException(
+ "Unable to load Param Value from file: "
+ + paramFile.getAbsolutePath(), e);
+ } finally
+ {
+ try
+ {
+ if (fileStream != null)
+ {
+ fileStream.close();
+ }
+ } catch (IOException e)
+ {
+ logger.warn("Unable to close param file: "
+ + paramFile.getAbsolutePath(), e);
+ }
+ }
+ }
+ }
+
+ public void remove(String name)
+ {
+ FileParamName paramName = asserNameOK(name);
+
+ synchronized (this)
+ {
+ File paramFile = toParamFile(paramName);
+ if (paramFile.exists())
+ {
+ paramFile.delete();
+ }
+ }
+ }
+
+ /**
+ * Get the repository root directory.
+ *
+ * @return The repository root directory.
+ */
+ public File getRoot()
+ {
+ return root;
+ }
+
+ /**
+ * Get the param file for the specified param name.
+ *
+ * @param paramName
+ * The param name.
+ * @return The param file.
+ */
+ public File toParamFile(String name)
+ {
+ FileParamName paramName = asserNameOK(name);
+ return new File(root, paramName.toString());
+ }
+
+ /**
+ * Get the param file for the specified param name.
+ *
+ * @param paramName
+ * The param name.
+ * @return The param file.
+ */
+ private File toParamFile(FileParamName paramName)
+ {
+ return new File(root, paramName.toString());
+ }
+
+ private FileParamName asserNameOK(String name)
+ {
+ FileParamName paramName;
+
+ if (name == null)
+ {
+ throw new IllegalArgumentException(
+ "null 'name' arg in repository call.");
+ }
+ try
+ {
+ paramName = new FileParamName(name);
+ } catch (InvalidNameException e)
+ {
+ throw new IllegalArgumentException("Invalid 'name' arg: " + name, e);
+ }
+ if (paramName.size() == 0)
+ {
+ throw new IllegalArgumentException(
+ "Invalid 'name' arg. 0 tokens: " + name);
+ }
+
+ return paramName;
+ }
+
+ /**
+ * Parameter Name. <p/> Represents a compound parameter name - from a
+ * hierarchical namespace.
+ * <h4 id="syntax">Parameter Name Format</h4>
+ * The syntax of the parameter name is expected to be in "directory" format,
+ * read from left to right, where the syntax seperator character is '/' e.g.
+ * "com/acme/ParameterX".
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+ private static class FileParamName extends CompoundName
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Properties nameSyntaxProperties = new Properties();
+ static
+ {
+ nameSyntaxProperties.setProperty("jndi.syntax.direction",
+ "left_to_right");
+ nameSyntaxProperties.setProperty("jndi.syntax.separator", "/");
+ };
+
+ /**
+ * Public Constructor.
+ *
+ * @param name
+ * The name of the parameter, specified according to the <a
+ * href="#syntax">defined syntax</a>.
+ * @throws InvalidNameException
+ * The supplied name violates the <a href="#syntax">defined
+ * syntax</a>.
+ */
+ public FileParamName(String name) throws InvalidNameException
+ {
+ super(name, nameSyntaxProperties);
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/thirdparty/Base64.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/thirdparty/Base64.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/thirdparty/Base64.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,1451 @@
+package org.jboss.internal.soa.esb.thirdparty;
+
+/**
+ * Encodes and decodes to and from Base64 notation.
+ *
+ * <p>
+ * Change Log:
+ * </p>
+ * <ul>
+ * <li>v2.1 - Cleaned up javadoc comments and unused variables and methods. Added
+ * some convenience methods for reading and writing to and from files.</li>
+ * <li>v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems
+ * with other encodings (like EBCDIC).</li>
+ * <li>v2.0.1 - Fixed an error when decoding a single byte, that is, when the
+ * encoded data was a single byte.</li>
+ * <li>v2.0 - I got rid of methods that used booleans to set options.
+ * Now everything is more consolidated and cleaner. The code now detects
+ * when data that's being decoded is gzip-compressed and will decompress it
+ * automatically. Generally things are cleaner. You'll probably have to
+ * change some method calls that you were making to support the new
+ * options format (<tt>int</tt>s that you "OR" together).</li>
+ * <li>v1.5.1 - Fixed bug when decompressing and decoding to a
+ * byte[] using <tt>decode( String s, boolean gzipCompressed )</tt>.
+ * Added the ability to "suspend" encoding in the Output Stream so
+ * you can turn on and off the encoding if you need to embed base64
+ * data in an otherwise "normal" stream (like an XML file).</li>
+ * <li>v1.5 - Output stream pases on flush() command but doesn't do anything itself.
+ * This helps when using GZIP streams.
+ * Added the ability to GZip-compress objects before encoding them.</li>
+ * <li>v1.4 - Added helper methods to read/write files.</li>
+ * <li>v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.</li>
+ * <li>v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream
+ * where last buffer being read, if not completely full, was not returned.</li>
+ * <li>v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.</li>
+ * <li>v1.3.3 - Fixed I/O streams which were totally messed up.</li>
+ * </ul>
+ *
+ * <p>
+ * I am placing this code in the Public Domain. Do with it as you will.
+ * This software comes with no guarantees or warranties but with
+ * plenty of well-wishing instead!
+ * Please visit <a href="http://iharder.net/base64">http://iharder.net/base64</a>
+ * periodically to check for updates or to contribute improvements.
+ * </p>
+ *
+ * @author Robert Harder
+ * @author rob at iharder.net
+ * @version 2.1
+ */
+public class Base64
+{
+
+/* ******** P U B L I C F I E L D S ******** */
+
+
+ /** No options specified. Value is zero. */
+ public final static int NO_OPTIONS = 0;
+
+ /** Specify encoding. */
+ public final static int ENCODE = 1;
+
+
+ /** Specify decoding. */
+ public final static int DECODE = 0;
+
+
+ /** Specify that data should be gzip-compressed. */
+ public final static int GZIP = 2;
+
+
+ /** Don't break lines when encoding (violates strict Base64 specification) */
+ public final static int DONT_BREAK_LINES = 8;
+
+
+/* ******** P R I V A T E F I E L D S ******** */
+
+
+ /** Maximum line length (76) of Base64 output. */
+ private final static int MAX_LINE_LENGTH = 76;
+
+
+ /** The equals sign (=) as a byte. */
+ private final static byte EQUALS_SIGN = (byte)'=';
+
+
+ /** The new line character (\n) as a byte. */
+ private final static byte NEW_LINE = (byte)'\n';
+
+
+ /** Preferred encoding. */
+ private final static String PREFERRED_ENCODING = "UTF-8";
+
+
+ /** The 64 valid Base64 values. */
+ private final static byte[] ALPHABET;
+ private final static byte[] _NATIVE_ALPHABET = /* May be something funny like EBCDIC */
+ {
+ (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G',
+ (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N',
+ (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U',
+ (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z',
+ (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g',
+ (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n',
+ (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u',
+ (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z',
+ (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5',
+ (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/'
+ };
+
+ /** Determine which ALPHABET to use. */
+ static
+ {
+ byte[] __bytes;
+ try
+ {
+ __bytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes( PREFERRED_ENCODING );
+ } // end try
+ catch (java.io.UnsupportedEncodingException use)
+ {
+ __bytes = _NATIVE_ALPHABET; // Fall back to native encoding
+ } // end catch
+ ALPHABET = __bytes;
+ } // end static
+
+
+ /**
+ * Translates a Base64 value to either its 6-bit reconstruction value
+ * or a negative number indicating some other meaning.
+ **/
+ private final static byte[] DECODABET =
+ {
+ -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8
+ -5,-5, // Whitespace: Tab and Linefeed
+ -9,-9, // Decimal 11 - 12
+ -5, // Whitespace: Carriage Return
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26
+ -9,-9,-9,-9,-9, // Decimal 27 - 31
+ -5, // Whitespace: Space
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42
+ 62, // Plus sign at decimal 43
+ -9,-9,-9, // Decimal 44 - 46
+ 63, // Slash at decimal 47
+ 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine
+ -9,-9,-9, // Decimal 58 - 60
+ -1, // Equals sign at decimal 61
+ -9,-9,-9, // Decimal 62 - 64
+ 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N'
+ 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z'
+ -9,-9,-9,-9,-9,-9, // Decimal 91 - 96
+ 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm'
+ 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z'
+ -9,-9,-9,-9 // Decimal 123 - 126
+ /*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */
+ };
+
+ // I think I end up not using the BAD_ENCODING indicator.
+ //private final static byte BAD_ENCODING = -9; // Indicates error in encoding
+ private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding
+ private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding
+
+
+ /** Defeats instantiation. */
+ private Base64(){}
+
+
+
+/* ******** E N C O D I N G M E T H O D S ******** */
+
+
+ /**
+ * Encodes up to the first three bytes of array <var>threeBytes</var>
+ * and returns a four-byte array in Base64 notation.
+ * The actual number of significant bytes in your array is
+ * given by <var>numSigBytes</var>.
+ * The array <var>threeBytes</var> needs only be as big as
+ * <var>numSigBytes</var>.
+ * Code can reuse a byte array by passing a four-byte array as <var>b4</var>.
+ *
+ * @param b4 A reusable byte array to reduce array instantiation
+ * @param threeBytes the array to convert
+ * @param numSigBytes the number of significant bytes in your array
+ * @return four byte array in Base64 notation.
+ * @since 1.5.1
+ */
+ private static byte[] encode3to4( byte[] b4, byte[] threeBytes, int numSigBytes )
+ {
+ encode3to4( threeBytes, 0, numSigBytes, b4, 0 );
+ return b4;
+ } // end encode3to4
+
+
+ /**
+ * Encodes up to three bytes of the array <var>source</var>
+ * and writes the resulting four Base64 bytes to <var>destination</var>.
+ * The source and destination arrays can be manipulated
+ * anywhere along their length by specifying
+ * <var>srcOffset</var> and <var>destOffset</var>.
+ * This method does not check to make sure your arrays
+ * are large enough to accomodate <var>srcOffset</var> + 3 for
+ * the <var>source</var> array or <var>destOffset</var> + 4 for
+ * the <var>destination</var> array.
+ * The actual number of significant bytes in your array is
+ * given by <var>numSigBytes</var>.
+ *
+ * @param source the array to convert
+ * @param srcOffset the index where conversion begins
+ * @param numSigBytes the number of significant bytes in your array
+ * @param destination the array to hold the conversion
+ * @param destOffset the index where output will be put
+ * @return the <var>destination</var> array
+ * @since 1.3
+ */
+ private static byte[] encode3to4(
+ byte[] source, int srcOffset, int numSigBytes,
+ byte[] destination, int destOffset )
+ {
+ // 1 2 3
+ // 01234567890123456789012345678901 Bit position
+ // --------000000001111111122222222 Array position from threeBytes
+ // --------| || || || | Six bit groups to index ALPHABET
+ // >>18 >>12 >> 6 >> 0 Right shift necessary
+ // 0x3f 0x3f 0x3f Additional AND
+
+ // Create buffer with zero-padding if there are only one or two
+ // significant bytes passed in the array.
+ // We have to shift left 24 in order to flush out the 1's that appear
+ // when Java treats a value as negative that is cast from a byte to an int.
+ int inBuff = ( numSigBytes > 0 ? ((source[ srcOffset ] << 24) >>> 8) : 0 )
+ | ( numSigBytes > 1 ? ((source[ srcOffset + 1 ] << 24) >>> 16) : 0 )
+ | ( numSigBytes > 2 ? ((source[ srcOffset + 2 ] << 24) >>> 24) : 0 );
+
+ switch( numSigBytes )
+ {
+ case 3:
+ destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ];
+ destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ];
+ destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ];
+ destination[ destOffset + 3 ] = ALPHABET[ (inBuff ) & 0x3f ];
+ return destination;
+
+ case 2:
+ destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ];
+ destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ];
+ destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ];
+ destination[ destOffset + 3 ] = EQUALS_SIGN;
+ return destination;
+
+ case 1:
+ destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ];
+ destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ];
+ destination[ destOffset + 2 ] = EQUALS_SIGN;
+ destination[ destOffset + 3 ] = EQUALS_SIGN;
+ return destination;
+
+ default:
+ return destination;
+ } // end switch
+ } // end encode3to4
+
+
+
+ /**
+ * Serializes an object and returns the Base64-encoded
+ * version of that serialized object. If the object
+ * cannot be serialized or there is another error,
+ * the method will return <tt>null</tt>.
+ * The object is not GZip-compressed before being encoded.
+ *
+ * @param serializableObject The object to encode
+ * @return The Base64-encoded object
+ * @since 1.4
+ */
+ public static String encodeObject( java.io.Serializable serializableObject )
+ {
+ return encodeObject( serializableObject, NO_OPTIONS );
+ } // end encodeObject
+
+
+
+ /**
+ * Serializes an object and returns the Base64-encoded
+ * version of that serialized object. If the object
+ * cannot be serialized or there is another error,
+ * the method will return <tt>null</tt>.
+ * <p>
+ * Valid options:<pre>
+ * GZIP: gzip-compresses object before encoding it.
+ * DONT_BREAK_LINES: don't break lines at 76 characters
+ * <i>Note: Technically, this makes your encoding non-compliant.</i>
+ * </pre>
+ * <p>
+ * Example: <code>encodeObject( myObj, Base64.GZIP )</code> or
+ * <p>
+ * Example: <code>encodeObject( myObj, Base64.GZIP | Base64.DONT_BREAK_LINES )</code>
+ *
+ * @param serializableObject The object to encode
+ * @param options Specified options
+ * @return The Base64-encoded object
+ * @see Base64#GZIP
+ * @see Base64#DONT_BREAK_LINES
+ * @since 2.0
+ */
+ public static String encodeObject( java.io.Serializable serializableObject, int options )
+ {
+ // Streams
+ java.io.ByteArrayOutputStream baos = null;
+ java.io.OutputStream b64os = null;
+ java.io.ObjectOutputStream oos = null;
+ java.util.zip.GZIPOutputStream gzos = null;
+
+ // Isolate options
+ int gzip = (options & GZIP);
+ int dontBreakLines = (options & DONT_BREAK_LINES);
+
+ try
+ {
+ // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream
+ baos = new java.io.ByteArrayOutputStream();
+ b64os = new Base64.OutputStream( baos, ENCODE | dontBreakLines );
+
+ // GZip?
+ if( gzip == GZIP )
+ {
+ gzos = new java.util.zip.GZIPOutputStream( b64os );
+ oos = new java.io.ObjectOutputStream( gzos );
+ } // end if: gzip
+ else
+ oos = new java.io.ObjectOutputStream( b64os );
+
+ oos.writeObject( serializableObject );
+ } // end try
+ catch( java.io.IOException e )
+ {
+ e.printStackTrace();
+ return null;
+ } // end catch
+ finally
+ {
+ try{ oos.close(); } catch( Exception e ){}
+ try{ gzos.close(); } catch( Exception e ){}
+ try{ b64os.close(); } catch( Exception e ){}
+ try{ baos.close(); } catch( Exception e ){}
+ } // end finally
+
+ // Return value according to relevant encoding.
+ try
+ {
+ return new String( baos.toByteArray(), PREFERRED_ENCODING );
+ } // end try
+ catch (java.io.UnsupportedEncodingException uue)
+ {
+ return new String( baos.toByteArray() );
+ } // end catch
+
+ } // end encode
+
+
+
+ /**
+ * Encodes a byte array into Base64 notation.
+ * Does not GZip-compress data.
+ *
+ * @param source The data to convert
+ * @since 1.4
+ */
+ public static String encodeBytes( byte[] source )
+ {
+ return encodeBytes( source, 0, source.length, NO_OPTIONS );
+ } // end encodeBytes
+
+
+
+ /**
+ * Encodes a byte array into Base64 notation.
+ * <p>
+ * Valid options:<pre>
+ * GZIP: gzip-compresses object before encoding it.
+ * DONT_BREAK_LINES: don't break lines at 76 characters
+ * <i>Note: Technically, this makes your encoding non-compliant.</i>
+ * </pre>
+ * <p>
+ * Example: <code>encodeBytes( myData, Base64.GZIP )</code> or
+ * <p>
+ * Example: <code>encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES )</code>
+ *
+ *
+ * @param source The data to convert
+ * @param options Specified options
+ * @see Base64#GZIP
+ * @see Base64#DONT_BREAK_LINES
+ * @since 2.0
+ */
+ public static String encodeBytes( byte[] source, int options )
+ {
+ return encodeBytes( source, 0, source.length, options );
+ } // end encodeBytes
+
+
+ /**
+ * Encodes a byte array into Base64 notation.
+ * Does not GZip-compress data.
+ *
+ * @param source The data to convert
+ * @param off Offset in array where conversion should begin
+ * @param len Length of data to convert
+ * @since 1.4
+ */
+ public static String encodeBytes( byte[] source, int off, int len )
+ {
+ return encodeBytes( source, off, len, NO_OPTIONS );
+ } // end encodeBytes
+
+
+
+ /**
+ * Encodes a byte array into Base64 notation.
+ * <p>
+ * Valid options:<pre>
+ * GZIP: gzip-compresses object before encoding it.
+ * DONT_BREAK_LINES: don't break lines at 76 characters
+ * <i>Note: Technically, this makes your encoding non-compliant.</i>
+ * </pre>
+ * <p>
+ * Example: <code>encodeBytes( myData, Base64.GZIP )</code> or
+ * <p>
+ * Example: <code>encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES )</code>
+ *
+ *
+ * @param source The data to convert
+ * @param off Offset in array where conversion should begin
+ * @param len Length of data to convert
+ * @param options Specified options
+ * @see Base64#GZIP
+ * @see Base64#DONT_BREAK_LINES
+ * @since 2.0
+ */
+ public static String encodeBytes( byte[] source, int off, int len, int options )
+ {
+ // Isolate options
+ int dontBreakLines = ( options & DONT_BREAK_LINES );
+ int gzip = ( options & GZIP );
+
+ // Compress?
+ if( gzip == GZIP )
+ {
+ java.io.ByteArrayOutputStream baos = null;
+ java.util.zip.GZIPOutputStream gzos = null;
+ Base64.OutputStream b64os = null;
+
+
+ try
+ {
+ // GZip -> Base64 -> ByteArray
+ baos = new java.io.ByteArrayOutputStream();
+ b64os = new Base64.OutputStream( baos, ENCODE | dontBreakLines );
+ gzos = new java.util.zip.GZIPOutputStream( b64os );
+
+ gzos.write( source, off, len );
+ gzos.close();
+ } // end try
+ catch( java.io.IOException e )
+ {
+ e.printStackTrace();
+ return null;
+ } // end catch
+ finally
+ {
+ try{ gzos.close(); } catch( Exception e ){}
+ try{ b64os.close(); } catch( Exception e ){}
+ try{ baos.close(); } catch( Exception e ){}
+ } // end finally
+
+ // Return value according to relevant encoding.
+ try
+ {
+ return new String( baos.toByteArray(), PREFERRED_ENCODING );
+ } // end try
+ catch (java.io.UnsupportedEncodingException uue)
+ {
+ return new String( baos.toByteArray() );
+ } // end catch
+ } // end if: compress
+
+ // Else, don't compress. Better not to use streams at all then.
+ else
+ {
+ // Convert option to boolean in way that code likes it.
+ boolean breakLines = dontBreakLines == 0;
+
+ int len43 = len * 4 / 3;
+ byte[] outBuff = new byte[ ( len43 ) // Main 4:3
+ + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding
+ + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines
+ int d = 0;
+ int e = 0;
+ int len2 = len - 2;
+ int lineLength = 0;
+ for( ; d < len2; d+=3, e+=4 )
+ {
+ encode3to4( source, d+off, 3, outBuff, e );
+
+ lineLength += 4;
+ if( breakLines && lineLength == MAX_LINE_LENGTH )
+ {
+ outBuff[e+4] = NEW_LINE;
+ e++;
+ lineLength = 0;
+ } // end if: end of line
+ } // en dfor: each piece of array
+
+ if( d < len )
+ {
+ encode3to4( source, d+off, len - d, outBuff, e );
+ e += 4;
+ } // end if: some padding needed
+
+
+ // Return value according to relevant encoding.
+ try
+ {
+ return new String( outBuff, 0, e, PREFERRED_ENCODING );
+ } // end try
+ catch (java.io.UnsupportedEncodingException uue)
+ {
+ return new String( outBuff, 0, e );
+ } // end catch
+
+ } // end else: don't compress
+
+ } // end encodeBytes
+
+
+
+
+
+/* ******** D E C O D I N G M E T H O D S ******** */
+
+
+ /**
+ * Decodes four bytes from array <var>source</var>
+ * and writes the resulting bytes (up to three of them)
+ * to <var>destination</var>.
+ * The source and destination arrays can be manipulated
+ * anywhere along their length by specifying
+ * <var>srcOffset</var> and <var>destOffset</var>.
+ * This method does not check to make sure your arrays
+ * are large enough to accomodate <var>srcOffset</var> + 4 for
+ * the <var>source</var> array or <var>destOffset</var> + 3 for
+ * the <var>destination</var> array.
+ * This method returns the actual number of bytes that
+ * were converted from the Base64 encoding.
+ *
+ *
+ * @param source the array to convert
+ * @param srcOffset the index where conversion begins
+ * @param destination the array to hold the conversion
+ * @param destOffset the index where output will be put
+ * @return the number of decoded bytes converted
+ * @since 1.3
+ */
+ private static int decode4to3( byte[] source, int srcOffset, byte[] destination, int destOffset )
+ {
+ // Example: Dk==
+ if( source[ srcOffset + 2] == EQUALS_SIGN )
+ {
+ // Two ways to do the same thing. Don't know which way I like best.
+ //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
+ // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 );
+ int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )
+ | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 );
+
+ destination[ destOffset ] = (byte)( outBuff >>> 16 );
+ return 1;
+ }
+
+ // Example: DkL=
+ else if( source[ srcOffset + 3 ] == EQUALS_SIGN )
+ {
+ // Two ways to do the same thing. Don't know which way I like best.
+ //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
+ // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
+ // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 );
+ int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )
+ | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 )
+ | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 );
+
+ destination[ destOffset ] = (byte)( outBuff >>> 16 );
+ destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 );
+ return 2;
+ }
+
+ // Example: DkLE
+ else
+ {
+ try{
+ // Two ways to do the same thing. Don't know which way I like best.
+ //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )
+ // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
+ // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 )
+ // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 );
+ int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )
+ | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 )
+ | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6)
+ | ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) );
+
+
+ destination[ destOffset ] = (byte)( outBuff >> 16 );
+ destination[ destOffset + 1 ] = (byte)( outBuff >> 8 );
+ destination[ destOffset + 2 ] = (byte)( outBuff );
+
+ return 3;
+ }catch( Exception e){
+ System.out.println(""+source[srcOffset]+ ": " + ( DECODABET[ source[ srcOffset ] ] ) );
+ System.out.println(""+source[srcOffset+1]+ ": " + ( DECODABET[ source[ srcOffset + 1 ] ] ) );
+ System.out.println(""+source[srcOffset+2]+ ": " + ( DECODABET[ source[ srcOffset + 2 ] ] ) );
+ System.out.println(""+source[srcOffset+3]+ ": " + ( DECODABET[ source[ srcOffset + 3 ] ] ) );
+ return -1;
+ } //e nd catch
+ }
+ } // end decodeToBytes
+
+
+
+
+ /**
+ * Very low-level access to decoding ASCII characters in
+ * the form of a byte array. Does not support automatically
+ * gunzipping or any other "fancy" features.
+ *
+ * @param source The Base64 encoded data
+ * @param off The offset of where to begin decoding
+ * @param len The length of characters to decode
+ * @return decoded data
+ * @since 1.3
+ */
+ public static byte[] decode( byte[] source, int off, int len )
+ {
+ int len34 = len * 3 / 4;
+ byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output
+ int outBuffPosn = 0;
+
+ byte[] b4 = new byte[4];
+ int b4Posn = 0;
+ int i = 0;
+ byte sbiCrop = 0;
+ byte sbiDecode = 0;
+ for( i = off; i < off+len; i++ )
+ {
+ sbiCrop = (byte)(source[i] & 0x7f); // Only the low seven bits
+ sbiDecode = DECODABET[ sbiCrop ];
+
+ if( sbiDecode >= WHITE_SPACE_ENC ) // White space, Equals sign or better
+ {
+ if( sbiDecode >= EQUALS_SIGN_ENC )
+ {
+ b4[ b4Posn++ ] = sbiCrop;
+ if( b4Posn > 3 )
+ {
+ outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn );
+ b4Posn = 0;
+
+ // If that was the equals sign, break out of 'for' loop
+ if( sbiCrop == EQUALS_SIGN )
+ break;
+ } // end if: quartet built
+
+ } // end if: equals sign or better
+
+ } // end if: white space, equals sign or better
+ else
+ {
+ System.err.println( "Bad Base64 input character at " + i + ": " + source[i] + "(decimal)" );
+ return null;
+ } // end else:
+ } // each input character
+
+ byte[] out = new byte[ outBuffPosn ];
+ System.arraycopy( outBuff, 0, out, 0, outBuffPosn );
+ return out;
+ } // end decode
+
+
+
+
+ /**
+ * Decodes data from Base64 notation, automatically
+ * detecting gzip-compressed data and decompressing it.
+ *
+ * @param s the string to decode
+ * @return the decoded data
+ * @since 1.4
+ */
+ public static byte[] decode( String s )
+ {
+ byte[] bytes;
+ try
+ {
+ bytes = s.getBytes( PREFERRED_ENCODING );
+ } // end try
+ catch( java.io.UnsupportedEncodingException uee )
+ {
+ bytes = s.getBytes();
+ } // end catch
+ //</change>
+
+ // Decode
+ bytes = decode( bytes, 0, bytes.length );
+
+
+ // Check to see if it's gzip-compressed
+ // GZIP Magic Two-Byte Number: 0x8b1f (35615)
+ if( bytes != null && bytes.length >= 4 )
+ {
+
+ int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
+ if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head )
+ {
+ java.io.ByteArrayInputStream bais = null;
+ java.util.zip.GZIPInputStream gzis = null;
+ java.io.ByteArrayOutputStream baos = null;
+ byte[] buffer = new byte[2048];
+ int length = 0;
+
+ try
+ {
+ baos = new java.io.ByteArrayOutputStream();
+ bais = new java.io.ByteArrayInputStream( bytes );
+ gzis = new java.util.zip.GZIPInputStream( bais );
+
+ while( ( length = gzis.read( buffer ) ) >= 0 )
+ {
+ baos.write(buffer,0,length);
+ } // end while: reading input
+
+ // No error? Get new bytes.
+ bytes = baos.toByteArray();
+
+ } // end try
+ catch( java.io.IOException e )
+ {
+ // Just return originally-decoded bytes
+ } // end catch
+ finally
+ {
+ try{ baos.close(); } catch( Exception e ){}
+ try{ gzis.close(); } catch( Exception e ){}
+ try{ bais.close(); } catch( Exception e ){}
+ } // end finally
+
+ } // end if: gzipped
+ } // end if: bytes.length >= 2
+
+ return bytes;
+ } // end decode
+
+
+
+
+ /**
+ * Attempts to decode Base64 data and deserialize a Java
+ * Object within. Returns <tt>null</tt> if there was an error.
+ *
+ * @param encodedObject The Base64 data to decode
+ * @return The decoded and deserialized object
+ * @since 1.5
+ */
+ public static Object decodeToObject( String encodedObject )
+ {
+ // Decode and gunzip if necessary
+ byte[] objBytes = decode( encodedObject );
+
+ java.io.ByteArrayInputStream bais = null;
+ java.io.ObjectInputStream ois = null;
+ Object obj = null;
+
+ try
+ {
+ bais = new java.io.ByteArrayInputStream( objBytes );
+ ois = new java.io.ObjectInputStream( bais );
+
+ obj = ois.readObject();
+ } // end try
+ catch( java.io.IOException e )
+ {
+ e.printStackTrace();
+ obj = null;
+ } // end catch
+ catch( java.lang.ClassNotFoundException e )
+ {
+ e.printStackTrace();
+ obj = null;
+ } // end catch
+ finally
+ {
+ try{ bais.close(); } catch( Exception e ){}
+ try{ ois.close(); } catch( Exception e ){}
+ } // end finally
+
+ return obj;
+ } // end decodeObject
+
+
+
+ /**
+ * Convenience method for encoding data to a file.
+ *
+ * @param dataToEncode byte array of data to encode in base64 form
+ * @param filename Filename for saving encoded data
+ * @return <tt>true</tt> if successful, <tt>false</tt> otherwise
+ *
+ * @since 2.1
+ */
+ public static boolean encodeToFile( byte[] dataToEncode, String filename )
+ {
+ boolean success = false;
+ Base64.OutputStream bos = null;
+ try
+ {
+ bos = new Base64.OutputStream(
+ new java.io.FileOutputStream( filename ), Base64.ENCODE );
+ bos.write( dataToEncode );
+ success = true;
+ } // end try
+ catch( java.io.IOException e )
+ {
+
+ success = false;
+ } // end catch: IOException
+ finally
+ {
+ try{ bos.close(); } catch( Exception e ){}
+ } // end finally
+
+ return success;
+ } // end encodeToFile
+
+
+ /**
+ * Convenience method for decoding data to a file.
+ *
+ * @param dataToDecode Base64-encoded data as a string
+ * @param filename Filename for saving decoded data
+ * @return <tt>true</tt> if successful, <tt>false</tt> otherwise
+ *
+ * @since 2.1
+ */
+ public static boolean decodeToFile( String dataToDecode, String filename )
+ {
+ boolean success = false;
+ Base64.OutputStream bos = null;
+ try
+ {
+ bos = new Base64.OutputStream(
+ new java.io.FileOutputStream( filename ), Base64.DECODE );
+ bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) );
+ success = true;
+ } // end try
+ catch( java.io.IOException e )
+ {
+ success = false;
+ } // end catch: IOException
+ finally
+ {
+ try{ bos.close(); } catch( Exception e ){}
+ } // end finally
+
+ return success;
+ } // end decodeToFile
+
+
+
+
+ /**
+ * Convenience method for reading a base64-encoded
+ * file and decoding it.
+ *
+ * @param filename Filename for reading encoded data
+ * @return decoded byte array or null if unsuccessful
+ *
+ * @since 2.1
+ */
+ public static byte[] decodeFromFile( String filename )
+ {
+ byte[] decodedData = null;
+ Base64.InputStream bis = null;
+ try
+ {
+ // Set up some useful variables
+ java.io.File file = new java.io.File( filename );
+ byte[] buffer = null;
+ int length = 0;
+ int numBytes = 0;
+
+ // Check for size of file
+ if( file.length() > Integer.MAX_VALUE )
+ {
+ System.err.println( "File is too big for this convenience method (" + file.length() + " bytes)." );
+ return null;
+ } // end if: file too big for int index
+ buffer = new byte[ (int)file.length() ];
+
+ // Open a stream
+ bis = new Base64.InputStream(
+ new java.io.BufferedInputStream(
+ new java.io.FileInputStream( file ) ), Base64.DECODE );
+
+ // Read until done
+ while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 )
+ length += numBytes;
+
+ // Save in a variable to return
+ decodedData = new byte[ length ];
+ System.arraycopy( buffer, 0, decodedData, 0, length );
+
+ } // end try
+ catch( java.io.IOException e )
+ {
+ System.err.println( "Error decoding from file " + filename );
+ } // end catch: IOException
+ finally
+ {
+ try{ bis.close(); } catch( Exception e) {}
+ } // end finally
+
+ return decodedData;
+ } // end decodeFromFile
+
+
+
+ /**
+ * Convenience method for reading a binary file
+ * and base64-encoding it.
+ *
+ * @param filename Filename for reading binary data
+ * @return base64-encoded string or null if unsuccessful
+ *
+ * @since 2.1
+ */
+ public static String encodeFromFile( String filename )
+ {
+ String encodedData = null;
+ Base64.InputStream bis = null;
+ try
+ {
+ // Set up some useful variables
+ java.io.File file = new java.io.File( filename );
+ byte[] buffer = new byte[ (int)(file.length() * 1.4) ];
+ int length = 0;
+ int numBytes = 0;
+
+ // Open a stream
+ bis = new Base64.InputStream(
+ new java.io.BufferedInputStream(
+ new java.io.FileInputStream( file ) ), Base64.ENCODE );
+
+ // Read until done
+ while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 )
+ length += numBytes;
+
+ // Save in a variable to return
+ encodedData = new String( buffer, 0, length, Base64.PREFERRED_ENCODING );
+
+ } // end try
+ catch( java.io.IOException e )
+ {
+ System.err.println( "Error encoding from file " + filename );
+ } // end catch: IOException
+ finally
+ {
+ try{ bis.close(); } catch( Exception e) {}
+ } // end finally
+
+ return encodedData;
+ } // end encodeFromFile
+
+
+
+
+ /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */
+
+
+
+ /**
+ * A {@link Base64.InputStream} will read data from another
+ * <tt>java.io.InputStream</tt>, given in the constructor,
+ * and encode/decode to/from Base64 notation on the fly.
+ *
+ * @see Base64
+ * @since 1.3
+ */
+ public static class InputStream extends java.io.FilterInputStream
+ {
+ private boolean encode; // Encoding or decoding
+ private int position; // Current position in the buffer
+ private byte[] buffer; // Small buffer holding converted data
+ private int bufferLength; // Length of buffer (3 or 4)
+ private int numSigBytes; // Number of meaningful bytes in the buffer
+ private int lineLength;
+ private boolean breakLines; // Break lines at less than 80 characters
+
+
+ /**
+ * Constructs a {@link Base64.InputStream} in DECODE mode.
+ *
+ * @param in the <tt>java.io.InputStream</tt> from which to read data.
+ * @since 1.3
+ */
+ public InputStream( java.io.InputStream in )
+ {
+ this( in, DECODE );
+ } // end constructor
+
+
+ /**
+ * Constructs a {@link Base64.InputStream} in
+ * either ENCODE or DECODE mode.
+ * <p>
+ * Valid options:<pre>
+ * ENCODE or DECODE: Encode or Decode as data is read.
+ * DONT_BREAK_LINES: don't break lines at 76 characters
+ * (only meaningful when encoding)
+ * <i>Note: Technically, this makes your encoding non-compliant.</i>
+ * </pre>
+ * <p>
+ * Example: <code>new Base64.InputStream( in, Base64.DECODE )</code>
+ *
+ *
+ * @param in the <tt>java.io.InputStream</tt> from which to read data.
+ * @param options Specified options
+ * @see Base64#ENCODE
+ * @see Base64#DECODE
+ * @see Base64#DONT_BREAK_LINES
+ * @since 2.0
+ */
+ public InputStream( java.io.InputStream in, int options )
+ {
+ super( in );
+ this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES;
+ this.encode = (options & ENCODE) == ENCODE;
+ this.bufferLength = encode ? 4 : 3;
+ this.buffer = new byte[ bufferLength ];
+ this.position = -1;
+ this.lineLength = 0;
+ } // end constructor
+
+ /**
+ * Reads enough of the input stream to convert
+ * to/from Base64 and returns the next byte.
+ *
+ * @return next byte
+ * @since 1.3
+ */
+ public int read() throws java.io.IOException
+ {
+ // Do we need to get data?
+ if( position < 0 )
+ {
+ if( encode )
+ {
+ byte[] b3 = new byte[3];
+ int numBinaryBytes = 0;
+ for( int i = 0; i < 3; i++ )
+ {
+ try
+ {
+ int b = in.read();
+
+ // If end of stream, b is -1.
+ if( b >= 0 )
+ {
+ b3[i] = (byte)b;
+ numBinaryBytes++;
+ } // end if: not end of stream
+
+ } // end try: read
+ catch( java.io.IOException e )
+ {
+ // Only a problem if we got no data at all.
+ if( i == 0 )
+ throw e;
+
+ } // end catch
+ } // end for: each needed input byte
+
+ if( numBinaryBytes > 0 )
+ {
+ encode3to4( b3, 0, numBinaryBytes, buffer, 0 );
+ position = 0;
+ numSigBytes = 4;
+ } // end if: got data
+ else
+ {
+ return -1;
+ } // end else
+ } // end if: encoding
+
+ // Else decoding
+ else
+ {
+ byte[] b4 = new byte[4];
+ int i = 0;
+ for( i = 0; i < 4; i++ )
+ {
+ // Read four "meaningful" bytes:
+ int b = 0;
+ do{ b = in.read(); }
+ while( b >= 0 && DECODABET[ b & 0x7f ] <= WHITE_SPACE_ENC );
+
+ if( b < 0 )
+ break; // Reads a -1 if end of stream
+
+ b4[i] = (byte)b;
+ } // end for: each needed input byte
+
+ if( i == 4 )
+ {
+ numSigBytes = decode4to3( b4, 0, buffer, 0 );
+ position = 0;
+ } // end if: got four characters
+ else if( i == 0 ){
+ return -1;
+ } // end else if: also padded correctly
+ else
+ {
+ // Must have broken out from above.
+ throw new java.io.IOException( "Improperly padded Base64 input." );
+ } // end
+
+ } // end else: decode
+ } // end else: get data
+
+ // Got data?
+ if( position >= 0 )
+ {
+ // End of relevant data?
+ if( /*!encode &&*/ position >= numSigBytes )
+ return -1;
+
+ if( encode && breakLines && lineLength >= MAX_LINE_LENGTH )
+ {
+ lineLength = 0;
+ return '\n';
+ } // end if
+ else
+ {
+ lineLength++; // This isn't important when decoding
+ // but throwing an extra "if" seems
+ // just as wasteful.
+
+ int b = buffer[ position++ ];
+
+ if( position >= bufferLength )
+ position = -1;
+
+ return b & 0xFF; // This is how you "cast" a byte that's
+ // intended to be unsigned.
+ } // end else
+ } // end if: position >= 0
+
+ // Else error
+ else
+ {
+ // When JDK1.4 is more accepted, use an assertion here.
+ throw new java.io.IOException( "Error in Base64 code reading stream." );
+ } // end else
+ } // end read
+
+
+ /**
+ * Calls {@link #read()} repeatedly until the end of stream
+ * is reached or <var>len</var> bytes are read.
+ * Returns number of bytes read into array or -1 if
+ * end of stream is encountered.
+ *
+ * @param dest array to hold values
+ * @param off offset for array
+ * @param len max number of bytes to read into array
+ * @return bytes read into array or -1 if end of stream is encountered.
+ * @since 1.3
+ */
+ public int read( byte[] dest, int off, int len ) throws java.io.IOException
+ {
+ int i;
+ int b;
+ for( i = 0; i < len; i++ )
+ {
+ b = read();
+
+ //if( b < 0 && i == 0 )
+ // return -1;
+
+ if( b >= 0 )
+ dest[off + i] = (byte)b;
+ else if( i == 0 )
+ return -1;
+ else
+ break; // Out of 'for' loop
+ } // end for: each byte read
+ return i;
+ } // end read
+
+ } // end inner class InputStream
+
+
+
+
+
+
+ /* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */
+
+
+
+ /**
+ * A {@link Base64.OutputStream} will write data to another
+ * <tt>java.io.OutputStream</tt>, given in the constructor,
+ * and encode/decode to/from Base64 notation on the fly.
+ *
+ * @see Base64
+ * @since 1.3
+ */
+ public static class OutputStream extends java.io.FilterOutputStream
+ {
+ private boolean encode;
+ private int position;
+ private byte[] buffer;
+ private int bufferLength;
+ private int lineLength;
+ private boolean breakLines;
+ private byte[] b4; // Scratch used in a few places
+ private boolean suspendEncoding;
+
+ /**
+ * Constructs a {@link Base64.OutputStream} in ENCODE mode.
+ *
+ * @param out the <tt>java.io.OutputStream</tt> to which data will be written.
+ * @since 1.3
+ */
+ public OutputStream( java.io.OutputStream out )
+ {
+ this( out, ENCODE );
+ } // end constructor
+
+
+ /**
+ * Constructs a {@link Base64.OutputStream} in
+ * either ENCODE or DECODE mode.
+ * <p>
+ * Valid options:<pre>
+ * ENCODE or DECODE: Encode or Decode as data is read.
+ * DONT_BREAK_LINES: don't break lines at 76 characters
+ * (only meaningful when encoding)
+ * <i>Note: Technically, this makes your encoding non-compliant.</i>
+ * </pre>
+ * <p>
+ * Example: <code>new Base64.OutputStream( out, Base64.ENCODE )</code>
+ *
+ * @param out the <tt>java.io.OutputStream</tt> to which data will be written.
+ * @param options Specified options.
+ * @see Base64#ENCODE
+ * @see Base64#DECODE
+ * @see Base64#DONT_BREAK_LINES
+ * @since 1.3
+ */
+ public OutputStream( java.io.OutputStream out, int options )
+ {
+ super( out );
+ this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES;
+ this.encode = (options & ENCODE) == ENCODE;
+ this.bufferLength = encode ? 3 : 4;
+ this.buffer = new byte[ bufferLength ];
+ this.position = 0;
+ this.lineLength = 0;
+ this.suspendEncoding = false;
+ this.b4 = new byte[4];
+ } // end constructor
+
+
+ /**
+ * Writes the byte to the output stream after
+ * converting to/from Base64 notation.
+ * When encoding, bytes are buffered three
+ * at a time before the output stream actually
+ * gets a write() call.
+ * When decoding, bytes are buffered four
+ * at a time.
+ *
+ * @param theByte the byte to write
+ * @since 1.3
+ */
+ public void write(int theByte) throws java.io.IOException
+ {
+ // Encoding suspended?
+ if( suspendEncoding )
+ {
+ super.out.write( theByte );
+ return;
+ } // end if: supsended
+
+ // Encode?
+ if( encode )
+ {
+ buffer[ position++ ] = (byte)theByte;
+ if( position >= bufferLength ) // Enough to encode.
+ {
+ out.write( encode3to4( b4, buffer, bufferLength ) );
+
+ lineLength += 4;
+ if( breakLines && lineLength >= MAX_LINE_LENGTH )
+ {
+ out.write( NEW_LINE );
+ lineLength = 0;
+ } // end if: end of line
+
+ position = 0;
+ } // end if: enough to output
+ } // end if: encoding
+
+ // Else, Decoding
+ else
+ {
+ // Meaningful Base64 character?
+ if( DECODABET[ theByte & 0x7f ] > WHITE_SPACE_ENC )
+ {
+ buffer[ position++ ] = (byte)theByte;
+ if( position >= bufferLength ) // Enough to output.
+ {
+ int len = Base64.decode4to3( buffer, 0, b4, 0 );
+ out.write( b4, 0, len );
+ //out.write( Base64.decode4to3( buffer ) );
+ position = 0;
+ } // end if: enough to output
+ } // end if: meaningful base64 character
+ else if( DECODABET[ theByte & 0x7f ] != WHITE_SPACE_ENC )
+ {
+ throw new java.io.IOException( "Invalid character in Base64 data." );
+ } // end else: not white space either
+ } // end else: decoding
+ } // end write
+
+
+
+ /**
+ * Calls {@link #write(int)} repeatedly until <var>len</var>
+ * bytes are written.
+ *
+ * @param theBytes array from which to read bytes
+ * @param off offset for array
+ * @param len max number of bytes to read into array
+ * @since 1.3
+ */
+ public void write( byte[] theBytes, int off, int len ) throws java.io.IOException
+ {
+ // Encoding suspended?
+ if( suspendEncoding )
+ {
+ super.out.write( theBytes, off, len );
+ return;
+ } // end if: supsended
+
+ for( int i = 0; i < len; i++ )
+ {
+ write( theBytes[ off + i ] );
+ } // end for: each byte written
+
+ } // end write
+
+
+
+ /**
+ * Method added by PHIL. [Thanks, PHIL. -Rob]
+ * This pads the buffer without closing the stream.
+ */
+ public void flushBase64() throws java.io.IOException
+ {
+ if( position > 0 )
+ {
+ if( encode )
+ {
+ out.write( encode3to4( b4, buffer, position ) );
+ position = 0;
+ } // end if: encoding
+ else
+ {
+ throw new java.io.IOException( "Base64 input not properly padded." );
+ } // end else: decoding
+ } // end if: buffer partially full
+
+ } // end flush
+
+
+ /**
+ * Flushes and closes (I think, in the superclass) the stream.
+ *
+ * @since 1.3
+ */
+ public void close() throws java.io.IOException
+ {
+ // 1. Ensure that pending characters are written
+ flushBase64();
+
+ // 2. Actually close the stream
+ // Base class both flushes and closes.
+ super.close();
+
+ buffer = null;
+ out = null;
+ } // end close
+
+
+
+ /**
+ * Suspends encoding of the stream.
+ * May be helpful if you need to embed a piece of
+ * base640-encoded data in a stream.
+ *
+ * @since 1.5.1
+ */
+ public void suspendEncoding() throws java.io.IOException
+ {
+ flushBase64();
+ this.suspendEncoding = true;
+ } // end suspendEncoding
+
+
+ /**
+ * Resumes encoding of the stream.
+ * May be helpful if you need to embed a piece of
+ * base640-encoded data in a stream.
+ *
+ * @since 1.5.1
+ */
+ public void resumeEncoding()
+ {
+ this.suspendEncoding = false;
+ } // end resumeEncoding
+
+
+
+ } // end inner class OutputStream
+
+
+} // end class Base64
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/util/StreamUtils.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/util/StreamUtils.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/internal/soa/esb/util/StreamUtils.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,58 @@
+/*
+ * 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.internal.soa.esb.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Stream handling utilities.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class StreamUtils {
+
+ /**
+ * Read the supplied InputStream and return as an array of bytes.
+ * @param stream The stream to read.
+ * @return The stream contents in an array of bytes.
+ */
+ public static byte[] readStream(InputStream stream) {
+ if(stream == null) {
+ throw new IllegalArgumentException("null 'stream' arg passed in method call.");
+ }
+
+ ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
+ byte[] buffer = new byte[256];
+ int readCount = 0;
+
+ try {
+ while((readCount = stream.read(buffer)) != -1) {
+ outBuffer.write(buffer, 0, readCount);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Error reading stream.", e);
+ }
+
+ return outBuffer.toByteArray();
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/BaseException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/BaseException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/BaseException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,42 @@
+package org.jboss.soa.esb;
+
+/**
+ * Base ESB Exception.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class BaseException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Public Default Constructor.
+ */
+ public BaseException() {
+ super();
+ }
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ */
+ public BaseException(String message) {
+ super(message);
+ }
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public BaseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Public Constructor.
+ * @param cause Exception cause.
+ */
+ public BaseException(Throwable cause) {
+ super(cause);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/ConfigurationException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/ConfigurationException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/ConfigurationException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+/**
+ * Configuration Exception.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ConfigurationException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct an exception instance.
+ * @param message Exception message.
+ */
+ public ConfigurationException(String message) {
+ super(message);
+ }
+
+ /**
+ * Construct an exception instance.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public ConfigurationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Construct an exception instance.
+ * @param cause Exception cause.
+ */
+ public ConfigurationException(Throwable cause) {
+ super(cause);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/MarshalException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/MarshalException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/MarshalException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,42 @@
+package org.jboss.soa.esb;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Thrown if marshalling failed.
+ */
+
+public class MarshalException extends Exception
+{
+ public static final long serialVersionUID = 0xE;
+
+ public MarshalException()
+ {
+ super();
+ }
+
+ public MarshalException(String s)
+ {
+ super(s);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/ProtocolNotSupportedException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/ProtocolNotSupportedException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/ProtocolNotSupportedException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,39 @@
+package org.jboss.soa.esb;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+public class ProtocolNotSupportedException extends Exception
+{
+ public static final long serialVersionUID = 0xE;
+
+ public ProtocolNotSupportedException()
+ {
+ super();
+ }
+
+ public ProtocolNotSupportedException(String s)
+ {
+ super(s);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/SendFailedException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/SendFailedException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/SendFailedException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,50 @@
+package org.jboss.soa.esb;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+public class SendFailedException extends Exception
+{
+ public static final long serialVersionUID = 0xE;
+
+ public SendFailedException()
+ {
+ super();
+ }
+
+ public SendFailedException(String s)
+ {
+ super(s);
+ }
+
+ public SendFailedException(Exception ex)
+ {
+ _nestedException = ex;
+ }
+
+ public Exception getNestedException()
+ {
+ return _nestedException;
+ }
+
+ private Exception _nestedException;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/UnmarshalException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/UnmarshalException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/UnmarshalException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,42 @@
+package org.jboss.soa.esb;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Thrown if unmarshalling failed.
+ */
+
+public class UnmarshalException extends Exception
+{
+ public static final long serialVersionUID = 0xE;
+
+ public UnmarshalException()
+ {
+ super();
+ }
+
+ public UnmarshalException(String s)
+ {
+ super(s);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/Call.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/Call.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/Call.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,271 @@
+package org.jboss.soa.esb.addressing;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * Represents an interaction pattern for a specific message exchange. When sending a message
+ * the sender application can specify where errors are to be returned, where responses are
+ * to go, along with other interaction information.
+ *
+ * A call represents an exchange pattern for this message. It is built up as the message
+ * flows through the ESB and identifies where the message should go, along with any
+ * routing information for faults, replies etc.
+ *
+ *
+ * To: the destination. MANDATORY.
+ * From: the sender. OPTIONAL. If not defined, then the sender MAY be inferred from the transport.
+ * ReplyTo: the destination for any response. OPTIONAL.
+ * FaultTo: the destination for any error message. OPTIONAL.
+ * RelatesTo: used to indicate that this message is related to another. OPTIONAL.
+ * Action: used by the sender to indicate the semantics of the message. Must be unique. MANDATORY.
+ * MessageID: used to uniquely identify this message. OPTIONAL.
+ *
+ * @author marklittle
+ *
+ */
+
+// TODO maybe this should simply go into the Header interface?
+
+public class Call
+{
+ /**
+ * Create a new (empty) call.
+ */
+
+ public Call ()
+ {
+ }
+
+ /**
+ * Create a new call, whose To field is set to the supplied EPR.
+ *
+ * @param epr the To field.
+ */
+
+ public Call (EPR epr)
+ {
+ _to = epr;
+ }
+
+ /**
+ * Set the To field. Must not be null.
+ *
+ * @param epr the To field value.
+ */
+
+ public void setTo (EPR epr)
+ {
+ if (epr == null)
+ throw new IllegalArgumentException();
+
+ _to = epr;
+ }
+
+ /**
+ * @return the To field.
+ * @throws URISyntaxException thrown if the address is invalid.
+ */
+
+ public EPR getTo () throws URISyntaxException
+ {
+ return _to;
+ }
+
+ /**
+ * Set the From field. May be null.
+ *
+ * @param from the value of the field.
+ */
+
+ public void setFrom (EPR from)
+ {
+ _from = from;
+ }
+
+ /**
+ * @return the From field.
+ * @throws URISyntaxException thrown if the address is invalid.
+ */
+
+ public EPR getFrom () throws URISyntaxException
+ {
+ return _from;
+ }
+
+ /**
+ * Set the ReplyTo field. May be null.
+ *
+ * @param replyTo the value of the field.
+ */
+
+ public void setReplyTo (EPR replyTo)
+ {
+ _replyTo = replyTo;
+ }
+
+ /**
+ * @return the ReplyTo field.
+ * @throws URISyntaxException thrown if the address is invalid.
+ */
+
+ public EPR getReplyTo () throws URISyntaxException
+ {
+ return _replyTo;
+ }
+
+ /**
+ * Set the FaultTo field. May be null.
+ *
+ * @param uri the value of the field.
+ */
+
+ public void setFaultTo (EPR uri)
+ {
+ _faultTo = uri;
+ }
+
+ /**
+ * @return the FaultTo field.
+ * @throws URISyntaxException thrown if the address is invalid.
+ */
+
+ public EPR getFaultTo () throws URISyntaxException
+ {
+ return _faultTo;
+ }
+
+ /**
+ * Set the RelatesTo field.
+ *
+ * @param uri the value to set.
+ */
+
+ public void setRelatesTo (URI uri)
+ {
+ _relatesTo = uri;
+ }
+
+ /**
+ * @return the RelatesTo field.
+ * @throws URISyntaxException thrown if the field is invalid.
+ */
+
+ public URI getRelatesTo () throws URISyntaxException
+ {
+ return _relatesTo;
+ }
+
+ /**
+ * Set the Action field.
+ * @param uri the value to set.
+ */
+
+ public void setAction (URI uri)
+ {
+ _action = uri;
+ }
+
+ /**
+ * @return the Action field.
+ * @throws URISyntaxException thrown if the field is invalid.
+ */
+
+ public URI getAction () throws URISyntaxException
+ {
+ return _action;
+ }
+
+ /**
+ * Set the MessageId for this instance.
+ *
+ * @param uri the value to use.
+ */
+
+ public void setMessageID (URI uri)
+ {
+ _messageID = uri;
+ }
+
+ /**
+ * @return the MessageID field.
+ * @throws URISyntaxException thrown if the value is invalid.
+ */
+
+ public URI getMessageID () throws URISyntaxException
+ {
+ return _messageID;
+ }
+
+ /**
+ * Copy the instance specified.
+ *
+ * @param from the instance to copy.
+ */
+
+ public void copy (Call from)
+ {
+ Call fromImpl = (Call) from;
+
+ _to = fromImpl._to;
+ _from = fromImpl._from;
+ _replyTo = fromImpl._replyTo;
+ _relatesTo = fromImpl._relatesTo;
+ _faultTo = fromImpl._faultTo;
+ _action = fromImpl._action;
+ _messageID = fromImpl._messageID;
+ }
+
+// public void setMetaData (MetaData md);
+// public MetaData getMetaData ();
+// public void addReferenceParameter (...);
+
+ public String toString ()
+ {
+ return "To: "+_to+" From: "+_from+" ReplyTo: "+_replyTo+" FaultTo: "+_faultTo+" Action: "+_action;
+ }
+
+ /**
+ * This instance is valid if all mandatory elements are set.
+ *
+ * @return <code>true</code> if all mandatory elements are set, <code>false</code> otherwise.
+ */
+
+ public boolean valid ()
+ {
+ if ((_to != null) && (_action != null))
+ return true;
+ else
+ return false;
+ }
+
+ private EPR _to = null;
+ private EPR _from = null;
+ private EPR _faultTo = null;
+ private EPR _replyTo = null;
+ private URI _relatesTo = null;
+ private URI _action = null;
+ private URI _messageID = null;
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/EPR.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/EPR.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/EPR.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,135 @@
+package org.jboss.soa.esb.addressing;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * The Endpoint Reference class. All services (and clients) can be represented by
+ * an EPR, which is effectively an address. If using SOA principles then the ultimate
+ * recipient of the message should be addressed in a loosely-coupled manner: the service
+ * should multiplex/demultiplex work across "objects" based on the message content and
+ * the EPR should not address a specific "object".
+ *
+ * @author marklittle
+ *
+ */
+public class EPR
+{
+ /**
+ * Create a new Endpoint Reference with a null address.
+ */
+
+ public EPR ()
+ {
+ _addr = new PortReference();
+ }
+
+ /**
+ * Create a new Endpoint Reference with the specified address.
+ *
+ * @param addr the specified address.
+ */
+
+ public EPR (PortReference addr)
+ {
+ _addr = addr;
+ }
+
+ /**
+ * Create a new Endpoint Reference with the specified address.
+ *
+ * @param uri the specified address.
+ */
+
+ public EPR (URI uri)
+ {
+ _addr = new PortReference(uri.toString());
+ }
+
+ /**
+ * Override the address of this EPR.
+ *
+ * @param uri the new address.
+ */
+
+ public void setAddr (PortReference uri)
+ {
+ _addr = uri;
+ }
+
+ /**
+ * Get the EPR address.
+ *
+ * @return the address.
+ * @throws URISyntaxException thrown if the address is invalid.
+ */
+
+ public PortReference getAddr () throws URISyntaxException
+ {
+ return _addr;
+ }
+
+ /**
+ * Copy the contents of the specified EPR into this instance.
+ *
+ * @param from the instance to copy.
+ */
+
+ public void copy (EPR from)
+ {
+ EPR fromImpl = (EPR) from;
+
+ _addr = fromImpl._addr;
+ }
+
+// public void setMetaData (MetaData md);
+// public MetaData getMetaData ();
+// public void addReferenceParameter (...);
+
+ public String toString ()
+ {
+ return "EPR: "+_addr;
+ }
+
+ public boolean equals (Object obj)
+ {
+ if (obj == this)
+ return true;
+ else
+ {
+ if (obj instanceof EPR)
+ return ((EPR) obj)._addr.equals(_addr);
+ }
+
+ return false;
+ }
+
+ private PortReference _addr;
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/PortReference.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/PortReference.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/PortReference.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,396 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/*
+ * Copyright (c) 2002, 2003, Arjuna Technologies Limited.
+ *
+ * PortReference.java
+ */
+
+package org.jboss.soa.esb.addressing;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * An implementation of a WS-Addressing EPR. It needs completely rewriting after
+ * the interoperability workshop as it is not extensible. It's morphed with the changing WS-C/WS-T and
+ * WS-Addr specifications and their quirks; now that WS-Addr is finalized the
+ * old quirks no longer need to be supported so it's best to rewrite this from
+ * scratch.
+ *
+ * An instance of a PortReference represents a single element in WS-A.
+ */
+
+public class PortReference
+{
+ public PortReference()
+ {
+ }
+
+ public PortReference(String address)
+ {
+ setAddress(address);
+ }
+
+ public void setAddress(String address)
+ {
+ _address = address;
+ }
+
+ public String getAddress()
+ {
+ return _address;
+ }
+
+ public void addExtension(PortReference.Extension extension)
+ {
+ _extensions.add(extension);
+ }
+
+ // all extensions are added as the Arjuna namespace.
+
+ public void addExtension(String value)
+ {
+ addExtension(XMLUtil.INSTANCE_IDENTIFIER_TAG, XMLUtil.WSARJADDR_PREFIX,
+ XMLUtil.WSARJADDR_NAMESPACE_URI, value,
+ Extension.REFERENCE_PROPERTIES);
+ }
+
+ public void addExtension(String tag, String value)
+ {
+ addExtension(tag, XMLUtil.WSARJADDR_PREFIX,
+ XMLUtil.WSARJADDR_NAMESPACE_URI, value,
+ Extension.REFERENCE_PROPERTIES);
+ }
+
+ /**
+ * Define the tag, prefix and namespace URI for the extension value. The
+ * parent is a refProperty.
+ */
+
+ public void addExtension(String tag, String prefix, String uri, String value)
+ {
+ _extensions.add(new Extension(tag, prefix, uri, value,
+ Extension.REFERENCE_PROPERTIES));
+ }
+
+ /**
+ * Define the tag, prefix and namespace URI for the extension value. The
+ * parent field defines whether the attribute has a refParam, refProp or
+ * neither as its parent.
+ */
+
+ public void addExtension(String tag, String prefix, String uri,
+ String value, int parent)
+ {
+ _extensions.add(new Extension(tag, prefix, uri, value, parent));
+ }
+
+ // placeholders only
+
+ public void addPortType(String qName)
+ {
+ }
+
+ public void addServiceName(String portName, String qName)
+ {
+ }
+
+ public void addPolicy()
+ {
+ }
+
+ public String getExtensionValue(String tag)
+ {
+ String extensionValue = null;
+ Iterator iterator = _extensions.iterator();
+
+ while (iterator.hasNext() && (extensionValue == null))
+ {
+ Extension extension = (Extension) iterator.next();
+
+ if (tag.equals(extension.getTag()))
+ extensionValue = extension.getValue();
+ }
+
+ return extensionValue;
+ }
+
+ public Iterator getExtensions()
+ {
+ return _extensions.iterator();
+ }
+
+ public void clearExtensions()
+ {
+ _extensions.clear();
+ }
+
+ public String toString()
+ {
+ return "PortReference < " + _address + " >";
+ }
+
+ public String extendedToString()
+ {
+ String addr = "<" + XMLUtil.WSA_PREFIX + ":Address " + _address + "/>";
+
+ Iterator extensions = getExtensions();
+
+ while (extensions.hasNext())
+ {
+ Extension ext = (Extension) extensions.next();
+
+ addr += ", <" + XMLUtil.WSA_PREFIX + ":"
+ + XMLUtil.REFERENCE_PROPERTIES_TAG + " " + ext.getPrefix()
+ + ":" + ext.getTag() + " : " + ext.getValue() + "/>";
+ }
+
+ return "PortReference : " + addr;
+ }
+
+ /**
+ * Is this object equal to the specified parameter?
+ *
+ * @param rhs
+ * The rhs object.
+ * @return true if the specified object is equal, false otherwise.
+ */
+ public boolean equals(final Object rhs)
+ {
+ if ((rhs != null) && (rhs.getClass() == getClass()))
+ {
+ // This should really only include reference property extensions
+ final PortReference rhsPortReference = (PortReference) rhs;
+ return (equalsObject(_address, rhsPortReference._address)
+ && equalsObject(_extensions, rhsPortReference._extensions)
+ && equalsObject(_portType, rhsPortReference._portType)
+ && equalsObject(_serviceName, rhsPortReference._serviceName) && equalsObject(
+ _policies, rhsPortReference._policies));
+ }
+ return false;
+ }
+
+ /**
+ * Return the hash code for this object.
+ *
+ * @return the hash code value.
+ */
+ public int hashCode()
+ {
+ // Not checked for spread.
+ return (objectHashCode(_address, 0x1)
+ ^ objectHashCode(_extensions, 0x2)
+ ^ objectHashCode(_portType, 0x4)
+ ^ objectHashCode(_serviceName, 0x8) ^ objectHashCode(_policies,
+ 0x10));
+ }
+
+ public static class Extension
+ {
+ public static final int REFERENCE_PROPERTIES = 0;
+ public static final int REFERENCE_PARAMETERS = 1;
+ public static final int NEITHER = 2;
+
+ public Extension(String tag, String prefix, String uri)
+ {
+ this(tag, prefix, uri, null, REFERENCE_PROPERTIES);
+ }
+
+ public Extension(String tag, String prefix, String uri, String value)
+ {
+ this(tag, prefix, uri, value, REFERENCE_PROPERTIES);
+ }
+
+ public Extension(String tag, String prefix, String uri, String value,
+ int parent)
+ {
+ _tag = tag;
+ _prefix = prefix;
+ _uri = uri;
+ _value = value;
+ _parent = parent;
+
+ /*
+ * If XML was loaded via DOM1 then prefix and namespace won't work!
+ */
+
+ if (_uri == null)
+ _uri = XMLUtil.WSARJADDR_NAMESPACE_URI;
+
+ if (_prefix == null)
+ _prefix = XMLUtil.WSARJADDR_PREFIX;
+
+ if (_tag.contains(":"))
+ {
+ int colon = _tag.indexOf(':');
+
+ _tag = _tag.substring(colon+1);
+ }
+ }
+
+ public int getParent()
+ {
+ return _parent;
+ }
+
+ public String getTag()
+ {
+ return _tag;
+ }
+
+ public String getPrefix()
+ {
+ return _prefix;
+ }
+
+ public String getURI()
+ {
+ return _uri;
+ }
+
+ public String getValue()
+ {
+ return _value;
+ }
+
+ public LinkedList getChildren()
+ {
+ return _extensions;
+ }
+
+ public HashMap getAttributes()
+ {
+ return _attributes;
+ }
+
+ public void addAttributes(HashMap props)
+ {
+ _attributes = props;
+ }
+
+ public void addChild(Extension child)
+ {
+ if (_extensions == null)
+ _extensions = new LinkedList<Extension>();
+
+ _extensions.add(child);
+ }
+
+ public String toString()
+ {
+ return new String("< " + _tag + ", " + _prefix + ", " + _uri + ", "
+ + _value + " >");
+ }
+
+ /**
+ * Is this object equal to the specified parameter (ignoring prefix)?
+ *
+ * @param rhs
+ * The rhs object.
+ * @return true if the specified object is equal, false otherwise.
+ */
+ public boolean equals(final Object rhs)
+ {
+ if ((rhs != null) && (rhs.getClass() == getClass()))
+ {
+ final Extension rhsExtension = (Extension) rhs;
+ return (equalsObject(_tag, rhsExtension._tag)
+ && equalsObject(_uri, rhsExtension._uri)
+ && equalsObject(_value, rhsExtension._value)
+ && equalsObject(_extensions, rhsExtension._extensions) && (_parent == rhsExtension._parent));
+ }
+ return false;
+ }
+
+ /**
+ * Return the hash code for this object.
+ *
+ * @return the hash code value.
+ */
+ public int hashCode()
+ {
+ // Not checked for spread.
+ return (_parent ^ objectHashCode(_tag, 0x4)
+ ^ objectHashCode(_uri, 0x8) ^ objectHashCode(_value, 0x10) ^ objectHashCode(
+ _extensions, 0x20));
+ }
+
+ private String _tag = null;
+
+ private String _prefix = null;
+
+ private String _uri = null;
+
+ private String _value = null;
+
+ private int _parent = NEITHER;
+
+ private LinkedList<Extension> _extensions = null;
+
+ private HashMap _attributes = null;
+
+ }
+
+ /**
+ * Get the hash code from the object or use the default if null.
+ *
+ * @param obj
+ * The object.
+ * @param defaultHashCode
+ * The default hash code.
+ * @return The hash code.
+ */
+ static int objectHashCode(final Object obj, final int defaultHashCode)
+ {
+ return (obj == null ? defaultHashCode : obj.hashCode());
+ }
+
+ /**
+ * Are the two objects equal?
+ *
+ * @param lhs
+ * The lhs object.
+ * @param rhs
+ * The rhs object.
+ * @return true if equal or both null, false otherwise.
+ */
+ static boolean equalsObject(final Object lhs, final Object rhs)
+ {
+ if (lhs == null)
+ {
+ return (rhs == null);
+ } else
+ {
+ return lhs.equals(rhs);
+ }
+ }
+
+ private String _address = null;
+ private LinkedList<Extension> _extensions = new LinkedList<Extension>();
+ private Extension _portType = null;
+ private Extension _serviceName = null;
+ private List _policies = null;
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/XMLUtil.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/XMLUtil.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/XMLUtil.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/*
+ * Copyright (c) 2002, 2003, Arjuna Technologies Limited.
+ *
+ * XMLUtil.java
+ */
+
+package org.jboss.soa.esb.addressing;
+
+public class XMLUtil
+{
+ // WS-Addr
+
+ public static final String WSA_PREFIX = "wsa";
+ public static final String WSA_NAMESPACE_URI = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
+
+ public static final String ENDPOINT_REFERENCE_TAG = "EndpointReference";
+ public static final String MESSAGE_IDENTIFIER_TAG = "MessageID";
+ public static final String REFERENCE_PROPERTIES_TAG = "ReferenceProperties";
+ public static final String REFERENCE_PARAMETERS_TAG = "ReferenceParameters";
+ public static final String REPLY_TO_TAG = "ReplyTo";
+ public static final String FROM_TAG = "From";
+
+ public static final String TO_TAG = "To";
+ public static final String ADDRESS_TAG = "Address";
+ public static final String ACTION_TAG = "Action";
+ public static final String RELATES_TO_TAG = "RelatesTo";
+ public static final String FAULT_TO_TAG = "FaultTo";
+
+ // WS-ARJADDR
+
+ public static final String WSARJADDR_PREFIX = "wsarjaddr";
+ public static final String WSARJADDR_NAMESPACE_URI = "http://schemas.arjuna.com/ws/2004/06/wsarjaddr";
+
+ public static final String INSTANCE_IDENTIFIER_TAG = "InstanceIdentifier";
+
+ public static final String UNKNOWNERROR_ERROR_CODE = "UnknownError";
+
+ // XML Namespace
+ public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/" ;
+ public static final String XMLNS_PREFIX = "xmlns:" ;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/EmailEpr.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/EmailEpr.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/EmailEpr.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,169 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using email style EPRs. Simply create and use instances of
+ * this type.
+ *
+ * @author marklittle
+ *
+ */
+public class EmailEpr extends EPR
+{
+ public static final String DEFAULT_PORT = "25";
+ public static final String DEFAULT_USERNAME = "";
+ public static final String DEFAULT_PASSWORD = "";
+
+ public static final String SMTP_PROTOCOL = "smtp";
+ public static final String POP_PROTOCOL = "pop";
+
+ public static final String USERNAME_TAG = "username";
+ public static final String PASSWORD_TAG = "password";
+
+ private static final String PROTOCOL_SEPARATOR = "://";
+ private static final String PORT_SEPARATOR = ":";
+
+ public EmailEpr (EPR epr)
+ {
+ copy(epr);
+ }
+
+ /**
+ * Create a new email EPR. The port number will be assumed to be 25,
+ * and there are no values for username and password.
+ *
+ * @param protocol the protocol to use.
+ * @param host the host name.
+ */
+
+ public EmailEpr (String protocol, String host)
+ {
+ this(protocol, host, DEFAULT_PORT, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+ }
+
+ /**
+ * Create a new email EPR.
+ *
+ * @param protocol the protocol to use.
+ * @param host the host name.
+ * @param port the port to use.
+ * @param username the username for sending/receiving.
+ * @param password the password for sending/receiving.
+ */
+
+ public EmailEpr (String protocol, String host, String port, String username, String password)
+ {
+ // how many of these do we really need? modify accordingly.
+
+ if ((protocol == null) || (host == null) || (port == null))
+ throw new IllegalArgumentException();
+
+ if ((protocol.equals(SMTP_PROTOCOL) || (protocol.equals(POP_PROTOCOL))))
+ {
+ PortReference addr = new PortReference(protocol+PROTOCOL_SEPARATOR+host+PORT_SEPARATOR+port);
+
+ if (username != null)
+ addr.addExtension(USERNAME_TAG, username);
+
+ if (password != null)
+ addr.addExtension(PASSWORD_TAG, password);
+
+ setAddr(addr);
+ }
+ else
+ throw new IllegalArgumentException("Invalid email protocol!");
+ }
+
+ /**
+ * @return the email protocol used.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getProtocol () throws URISyntaxException
+ {
+ URI addr = new URI(getAddr().getAddress());
+
+ return addr.getScheme();
+ }
+
+ /**
+ * @return the email host used.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getHost () throws URISyntaxException
+ {
+ URI addr = new URI(getAddr().getAddress());
+
+ return addr.getHost();
+ }
+
+ /**
+ * @return the email port used, or -1 if not specified.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final int getPort () throws URISyntaxException
+ {
+ URI addr = new URI(getAddr().getAddress());
+
+ return addr.getPort();
+ }
+
+ /*
+ * There are deliberately no setters for the values once the EPR is created.
+ */
+
+ /**
+ * @return the password for this EPR, or <code>null</code> if none is set.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getPassword () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(PASSWORD_TAG);
+ }
+
+ /**
+ * @return the username for this EPR, or <code>null</code> if none is set.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getUserName () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(USERNAME_TAG);
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/FTPEpr.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/FTPEpr.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/FTPEpr.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,149 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using FTP style EPRs. Simply create instances of this
+ * class instead of the base EPR. Since URLs can use FTP, we try to leverage
+ * that as much as possible.
+ *
+ * @author marklittle
+ *
+ */
+public class FTPEpr extends EPR
+{
+ public static final String USERNAME_TAG = "username";
+ public static final String PASSWORD_TAG = "password";
+
+ public FTPEpr (EPR epr)
+ {
+ copy(epr);
+ }
+
+ public FTPEpr (URL url) throws URISyntaxException
+ {
+ super(new URI(url.toString()));
+ }
+
+ public FTPEpr (String url) throws URISyntaxException
+ {
+ super(new URI(url));
+ }
+
+ /**
+ * Set the URL for this endpoint.
+ *
+ * @param url the address.
+ */
+
+ public final void setURL (URL url)
+ {
+ super.setAddr(new PortReference(url.toString()));
+ }
+
+ /**
+ * Get the URL address.
+ *
+ * @return the address.
+ * @throws URISyntaxException thrown if the address is invalid.
+ */
+
+ public final URL getURL () throws MalformedURLException, URISyntaxException
+ {
+ return new URL(super.getAddr().getAddress());
+ }
+
+ /**
+ * Set the username for this FTP EPR.
+ *
+ * @param username the user's name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setUserName (String username) throws URISyntaxException
+ {
+ if (username == null)
+ throw new IllegalArgumentException();
+
+ if (userSet)
+ throw new IllegalStateException("Username already set.");
+
+ getAddr().addExtension(USERNAME_TAG, username);
+ userSet = true;
+ }
+
+ /**
+ * @return the user's name associated with this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getUserName () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(USERNAME_TAG);
+ }
+
+ /**
+ * Set the password for this FTP EPR.
+ *
+ * @param password the user's name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setPassword (String password) throws URISyntaxException
+ {
+ if (password == null)
+ throw new IllegalArgumentException();
+
+ if (passwordSet)
+ throw new IllegalStateException("Cannot change password");
+
+ getAddr().addExtension(PASSWORD_TAG, password);
+ passwordSet = true;
+ }
+
+ /**
+ * @return the password associated with this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getPassword () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(PASSWORD_TAG);
+ }
+
+ private boolean passwordSet = false;
+ private boolean userSet = false;
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/HTTPEpr.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/HTTPEpr.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/HTTPEpr.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,85 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using HTTP style EPRs. Simply create instances of this
+ * class instead of the base EPR.
+ *
+ * @author marklittle
+ *
+ */
+public class HTTPEpr extends EPR
+{
+
+ public HTTPEpr (EPR epr)
+ {
+ copy(epr);
+ }
+
+ public HTTPEpr (URL url) throws URISyntaxException
+ {
+ super(new URI(url.toString()));
+ }
+
+ public HTTPEpr (String url) throws URISyntaxException
+ {
+ super(new URI(url));
+ }
+
+ /**
+ * Set the URL for this endpoint.
+ *
+ * @param url the address.
+ */
+
+ public final void setURL (URL url)
+ {
+ super.setAddr(new PortReference(url.toString()));
+ }
+
+ /**
+ * Get the URL address.
+ *
+ * @return the address.
+ * @throws URISyntaxException thrown if the address is invalid.
+ */
+
+ public final URL getURL () throws MalformedURLException, URISyntaxException
+ {
+ return new URL(super.getAddr().getAddress());
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JDBCEpr.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JDBCEpr.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JDBCEpr.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,208 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using database style EPRs. Simply create instances of this
+ * class instead of the base EPR.
+ *
+ * @author marklittle
+ *
+ */
+
+public class JDBCEpr extends EPR
+{
+ public static final String JDBC_PROTOCOL = "jdbc";
+
+ public static final String USERNAME_TAG = "username";
+ public static final String PASSWORD_TAG = "password";
+ public static final String SQL_TAG = "sql";
+ public static final String DRIVER_TAG = "driver";
+
+ public JDBCEpr (EPR epr)
+ {
+ copy(epr);
+ }
+
+ public JDBCEpr (String url, String sql) throws URISyntaxException
+ {
+ super(new URI(url));
+
+ setSQL(sql);
+ }
+
+ /**
+ * Set the URL for this endpoint.
+ *
+ * @param url the address.
+ */
+
+ public final void setURL (String url)
+ {
+ super.setAddr(new PortReference(url));
+ }
+
+ /**
+ * Get the URL address.
+ *
+ * @return the address.
+ * @throws URISyntaxException thrown if the address is invalid.
+ */
+
+ public final String getURL () throws URISyntaxException
+ {
+ return getAddr().getAddress();
+ }
+
+ /**
+ * Set the username for this FTP EPR.
+ *
+ * @param username the user's name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setUserName (String username) throws URISyntaxException
+ {
+ if (username == null)
+ throw new IllegalArgumentException();
+
+ if (userSet)
+ throw new IllegalStateException("Username already set.");
+
+ getAddr().addExtension(USERNAME_TAG, username);
+ userSet = true;
+ }
+
+ /**
+ * @return the user's name associated with this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getUserName () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(USERNAME_TAG);
+ }
+
+ /**
+ * Set the password for this FTP EPR.
+ *
+ * @param password the user's name.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setPassword (String password) throws URISyntaxException
+ {
+ if (password == null)
+ throw new IllegalArgumentException();
+
+ if (passwordSet)
+ throw new IllegalStateException("Password already set.");
+
+ getAddr().addExtension(PASSWORD_TAG, password);
+ passwordSet = true;
+ }
+
+ /**
+ * @return the password associated with this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getPassword () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(PASSWORD_TAG);
+ }
+
+ /**
+ * Set the SQL command that is used by this EPR.
+ *
+ * @param sql the statement.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setSQL (String sql) throws URISyntaxException
+ {
+ if (sql == null)
+ throw new IllegalArgumentException();
+
+ if (sqlSet)
+ throw new IllegalStateException("SQL already set.");
+
+ getAddr().addExtension(SQL_TAG, sql);
+ sqlSet = true;
+ }
+
+ /**
+ * @return the SQL statement for this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getSQL () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(SQL_TAG);
+ }
+
+ /**
+ * Set the driver that is used by this EPR.
+ *
+ * @param driver the driver.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final void setDriver (String driver) throws URISyntaxException
+ {
+ if (driver == null)
+ throw new IllegalArgumentException();
+
+ if (driverSet)
+ throw new IllegalStateException("Driver already set.");
+
+ getAddr().addExtension(DRIVER_TAG, driver);
+ driverSet = true;
+ }
+
+ /**
+ * @return the driver used by this EPR.
+ * @throws URISyntaxException thrown if this EPR is malformed.
+ */
+
+ public final String getDriver () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(DRIVER_TAG);
+ }
+
+ private boolean userSet = false;
+ private boolean passwordSet = false;
+ private boolean sqlSet = false;
+ private boolean driverSet = false;
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JMSEpr.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JMSEpr.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/helpers/JMSEpr.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,226 @@
+package org.jboss.soa.esb.addressing.helpers;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This class represents the endpoint reference for services.
+ */
+
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * A helper class for using JMS style EPRs. Simply create and use instances of
+ * this type.
+ *
+ * @author marklittle
+ *
+ */
+
+public class JMSEpr extends EPR
+{
+ public static final String JMS_PROTOCOL = "jms";
+ public static final String PROTOCOL_SEPARATOR = "://";
+
+ public static final String ONE_ONE_PROTOCOL = "1.1";
+ public static final String ONE_ZERO_TWO_PROTOCOL = "1.0.2b";
+
+ public static final String SPECIFICATION_VERSION_TAG = "specification-version";
+ public static final String DESTINATION_TYPE_TAG = "destination-type";
+ public static final String DESTINATION_NAME_TAG = "destination-name";
+ public static final String CONNECTION_FACTORY_TAG = "connection-factory";
+ public static final String JNDI_TYPE_TAG = "jndi-type";
+ public static final String JNDI_URL_TAG = "jndi-URL";
+ public static final String MESSAGE_SELECTOR_TAG = "message-selector";
+
+ public static final String QUEUE_TYPE = "queue";
+ public static final String TOPIC_TYPE = "topic";
+
+ public JMSEpr (EPR epr)
+ {
+ copy(epr);
+ }
+
+ /**
+ * Create a new JMS EPR. The protocol version is assumed to be 1.1.
+ * , jndi_type=jboss, jndi_url=localhost, messageSelector=null
+ *
+ * @param destinationType the type of destination (queue/topic).
+ * @param destinationName name of the queue/topic.
+ * @param connection reference to the connection factory.
+ */
+
+ public JMSEpr (String destinationType, String destinationName, String connection)
+ {
+ this(ONE_ONE_PROTOCOL, destinationType, destinationName, connection
+ ,"jboss", "localhost", null);
+ }
+
+ /**
+ * Create a new JMS EPR. The protocol version is assumed to be 1.1.
+ *
+ * @param destinationType the type of destination (queue/topic).
+ * @param destinationName name of the queue/topic.
+ * @param connection reference to the connection factory.
+ * @param jndiType reference to the type of jndi to obtain the JMS objects from
+ * @param jndiUrl reference to the location of the jndi to obtain the JMS objects from
+ * @param messageSelector reference to the connection factory.
+ */
+
+ public JMSEpr (String destinationType, String destinationName, String connection, String jndiType, String jndiUrl, String messageSelector)
+ {
+ this(ONE_ONE_PROTOCOL, destinationType, destinationName, connection,jndiType, jndiUrl, messageSelector);
+ }
+
+ /**
+ * Create a new JMS EPR.
+ *
+ * @param protocol the protocol version.
+ * @param destinationType the type of destination (queue/topic).
+ * @param destinationName name of the queue/topic.
+ * @param connection reference to the connection factory.
+ * @param jndiType reference to the type of jndi to obtain the JMS objects from
+ * @param jndiUrl reference to the location of the jndi to obtain the JMS objects from
+ * @param messageSelector reference to the connection factory.
+ */
+
+ public JMSEpr (String protocol, String destinationType, String destinationName, String connection, String jndiType, String jndiUrl, String messageSelector)
+ {
+ // how many of these do we really need? modify accordingly.
+
+ if ((protocol == null) || (destinationType == null) || (destinationName == null) || (connection == null))
+ throw new IllegalArgumentException();
+
+ if (protocol.equals(ONE_ONE_PROTOCOL) || (protocol.equals(ONE_ZERO_TWO_PROTOCOL)))
+ {
+ if (destinationType.equals(QUEUE_TYPE) || destinationType.equals(TOPIC_TYPE))
+ {
+ PortReference addr = new PortReference(JMS_PROTOCOL+PROTOCOL_SEPARATOR+destinationType);
+
+ addr.addExtension(SPECIFICATION_VERSION_TAG, protocol);
+
+ if (destinationName != null)
+ addr.addExtension(DESTINATION_NAME_TAG, destinationName);
+
+ if (connection != null)
+ addr.addExtension(CONNECTION_FACTORY_TAG, connection);
+
+ if (jndiType != null)
+ addr.addExtension(JNDI_TYPE_TAG, jndiType);
+
+ if (jndiUrl != null)
+ addr.addExtension(JNDI_URL_TAG, jndiUrl);
+
+ if (messageSelector != null)
+ addr.addExtension(MESSAGE_SELECTOR_TAG, messageSelector);
+
+ setAddr(addr);
+ }
+ else
+ throw new IllegalArgumentException("Invalid destination type!");
+ }
+ else
+ throw new IllegalArgumentException("Invalid specification version!");
+ }
+
+ /*
+ * There are deliberately no setters for the values once the EPR is created.
+ */
+
+ /**
+ * @return the destination type used.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getDestinationType () throws URISyntaxException
+ {
+ URI uri = new URI(getAddr().getAddress());
+
+ return uri.getHost(); // ;-)
+ }
+
+ /**
+ * @return the specification version used.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getVersion () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(SPECIFICATION_VERSION_TAG);
+ }
+
+ /**
+ * @return the destination name used.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getDestinationName () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(DESTINATION_NAME_TAG);
+ }
+
+ /**
+ * @return the connection factory for this EPR, or <code>null</code> if none is set.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getConnectionFactory () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(CONNECTION_FACTORY_TAG);
+ }
+
+ /**
+ * @return the jndi type for this EPR, or <code>null</code> if none is set.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getJndiType () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(JNDI_TYPE_TAG);
+ }
+
+ /**
+ * @return the jndi URL for this EPR, or <code>null</code> if none is set.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getJndiURL () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(JNDI_URL_TAG);
+ }
+
+ /**
+ * @return the message selector for this EPR, or <code>null</code> if none is set.
+ * @throws URISyntaxException thrown if the address is malformed.
+ */
+
+ public final String getMessageSelector () throws URISyntaxException
+ {
+ return getAddr().getExtensionValue(MESSAGE_SELECTOR_TAG);
+ }
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/addressing/util/EPRManager.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,219 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.soa.esb.addressing.util;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Hashtable;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.internal.soa.esb.addressing.EPRHelper;
+import org.jboss.soa.esb.addressing.EPR;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+/**
+ * Allows EPRs to be saved to and loaded from files. Mainly for testing
+ * purposes. This version assumes XML as the output format.
+ *
+ * @author marklittle
+ *
+ */
+
+public class EPRManager
+{
+
+ /**
+ * All EPRs are saves in files within the current working directory.
+ *
+ * @return the manager for the cwd.
+ */
+
+ public static final EPRManager getInstance ()
+ {
+ return getInstance("");
+ }
+
+ /**
+ * All EPRs are saves in files within a defined directory. Get the right
+ * manager for that directory.
+ *
+ * @param domain
+ * the name of the directory. If <code>null</code> then
+ * the null String is assumed.
+ * @return the manager for the directory. If it does not exist, then one
+ * will be created.
+ */
+
+ public static final EPRManager getInstance (String domain)
+ {
+ if (domain == null)
+ domain = "";
+
+ synchronized (_instances)
+ {
+ EPRManager theInstance = _instances.get(domain);
+
+ if (theInstance == null)
+ {
+ theInstance = new EPRManager(domain);
+
+ _instances.put(domain, theInstance);
+ }
+
+ return theInstance;
+ }
+ }
+
+ public final String getDomain ()
+ {
+ return _directory;
+ }
+
+ public boolean equals (Object manager)
+ {
+ if (manager instanceof EPRManager)
+ {
+ EPRManager comp = (EPRManager) manager;
+
+ if (_directory.equals(comp.getDomain()))
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Save the EPR into the specified file.
+ *
+ * @param name
+ * the name of the file to use (the logical service
+ * name).
+ * @param address
+ * the EPR to save.
+ *
+ * @throws IOException
+ * thrown if there is an error.
+ */
+
+ public final void saveEPR (String name, EPR address) throws IOException
+ {
+ if ((name == null) || (address == null))
+ throw new IllegalArgumentException();
+
+ try
+ {
+ String documentAsString = EPRHelper.toXMLString(address);
+
+ FileOutputStream output = new FileOutputStream(_directory
+ + File.separator + name);
+
+ output.write(documentAsString.getBytes());
+ output.flush();
+ output.getFD().sync(); // make sure it's on disk!
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ /**
+ * Remove the EPR-to-file association.
+ *
+ * @param name
+ * the logical name for the service.
+ * @throws IOException
+ * thrown if there are any errors.
+ */
+
+ public final void removeEPR (String name) throws IOException
+ {
+ if (name == null)
+ throw new IllegalArgumentException();
+
+ File theFile = new File(_directory + File.separator + name);
+
+ if (theFile.exists())
+ theFile.delete();
+ else
+ throw new FileNotFoundException();
+ }
+
+ /**
+ * Get the EPR specified by the logical name.
+ *
+ * @param name
+ * the service name.
+ * @return the EPR, or <code>null</code> if none exists.
+ * @throws IOException
+ * thrown if there is an error.
+ */
+
+ public final EPR loadEPR (String name) throws IOException
+ {
+ if (name == null)
+ throw new IllegalArgumentException();
+
+ File theFile = new File(_directory + File.separator + name);
+
+ try
+ {
+ if (theFile.exists())
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(theFile);
+ Element rootElement = doc.getDocumentElement();
+
+ return EPRHelper.fromXML(rootElement);
+ }
+ else
+ throw new FileNotFoundException(theFile.toString());
+ }
+ catch (SAXException ex)
+ {
+ throw new IOException(ex.toString());
+ }
+ catch (ParserConfigurationException ex)
+ {
+ throw new IllegalArgumentException(ex.toString());
+ }
+ }
+
+ protected EPRManager(String domain)
+ {
+ _directory = domain;
+ }
+
+ private String _directory;
+
+ private static Hashtable<String, EPRManager> _instances = new Hashtable<String, EPRManager>();
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,273 @@
+/*
+ * 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.common;
+
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+public class Configuration
+{
+ private static KeyValuePair[] s_oaKV = new KeyValuePair[]
+ {
+ new KeyValuePair(Environment.SMTP_HOST, getSmtpHost()),
+ new KeyValuePair(Environment.SMTP_USERNAME, getSmtpUsername()),
+ new KeyValuePair(Environment.SMTP_PASSWORD, getSmtpPassword()),
+ new KeyValuePair(Environment.SMTP_PORT, getSmtpPort()),
+ new KeyValuePair(Environment.SMTP_FROM, getSmtpFrom()),
+ new KeyValuePair(Environment.SMTP_AUTH, getSmtpAuth()),
+ new KeyValuePair(Environment.JNDI_SERVER_TYPE, getJndiServerType()),
+ new KeyValuePair(Environment.JNDI_SERVER_URL, getJndiServerURL()),
+ new KeyValuePair(Environment.REGISTRY_QUERY_MANAGER_URI, getRegistryQueryManageURI()),
+ new KeyValuePair(Environment.REGISTRY_LIFECYCLE_MANAGER_URI,getRegistryLifecycleManagerURI()),
+ new KeyValuePair(Environment.REGISTRY_IMPEMENTATION_CLASS, getRegistryImplementationClass()),
+ new KeyValuePair(Environment.REGISTRY_FACTORY_CLASS, getRegistryFactoryClass()),
+ new KeyValuePair(Environment.REGISTRY_USER, getRegistryUser()),
+ new KeyValuePair(Environment.REGISTRY_PASSWORD, getRegistryPassword()),
+ new KeyValuePair(Environment.REGISTRY_SCOUT_TRANSPORT_CLASS,getRegistryScoutTransportClass()),
+ new KeyValuePair(Environment.PARAMS_REPOS_IMPL_CLASS, getParamRepositoryImplClass()),
+ new KeyValuePair(Environment.OBJECT_STORE_CONFIG_FILE, getObjStoreConfigFile()),
+ new KeyValuePair(Environment.ENCRYPT_FACTORY_CLASS, getEncryptionFactoryClass()),
+ new KeyValuePair(Environment.DB_DRIVER, getDbDriver()),
+ new KeyValuePair(Environment.DB_URL, getDbUrl()),
+ new KeyValuePair(Environment.DB_USER, getDbUser()),
+ new KeyValuePair(Environment.DB_PASSWORD, getDbPassword()),
+ new KeyValuePair(Environment.MSG_STORE_DB_CONNECTION_URL, getStoreUrl()),
+ new KeyValuePair(Environment.MSG_STORE_DB_JDBC_DRIVER, getStoreDriver()),
+ new KeyValuePair(Environment.MSG_STORE_DB_CONNECTION_USER, getStoreUser()),
+ new KeyValuePair(Environment.MSG_STORE_DB_CONNECTION_PWD, getStorePwd()),
+ new KeyValuePair(Environment.MSG_STORE_DB_POOL_MIN_SIZE, getStorePoolMinSize()),
+ new KeyValuePair(Environment.MSG_STORE_DB_POOL_MAX_SIZE, getStorePoolMaxSize()),
+ new KeyValuePair(Environment.MSG_STORE_DB_POOL_INITIAL_SIZE,getStorePoolInitialSize()),
+ new KeyValuePair(Environment.MSG_STORE_DB_POOL_TEST_TABLE, getStorePoolTestTable()),
+ new KeyValuePair(Environment.MSG_STORE_DB_POOL_TIMEOUT_MILLIS,getStorePoolTimeoutMillis()),
+
+
+ };
+
+ public static String dump()
+ {
+ StringBuilder sb = new StringBuilder("Dump of SystemProperties:\n");
+ for (KeyValuePair oCurr : s_oaKV)
+ {
+ sb.append(oCurr.getKey()).append("=").append(oCurr.getValue())
+ .append("\n");
+ }
+ return sb.append("______________________________________").toString();
+ } // ________________________________
+
+ public static String getSmtpHost()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.SMTP_HOST, Environment.DEFAULT_HOST);
+ }
+
+ public static String getSmtpUsername()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.SMTP_USERNAME,
+ Environment.DEFAULT_USERNAME);
+ }
+
+ public static String getSmtpPassword()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.SMTP_PASSWORD,
+ Environment.DEFAULT_PASSWORD);
+ }
+
+ public static String getSmtpPort()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.SMTP_PORT, Environment.DEFAULT_PORT);
+ }
+
+ public static String getSmtpFrom()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.SMTP_FROM);
+ }
+
+ public static String getSmtpAuth()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.SMTP_AUTH);
+ }
+
+ public static String getJndiServerType()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.JNDI_SERVER_TYPE,
+ Environment.DEFAULT_SERVER_TYPE);
+ }
+
+ public static String getJndiServerURL()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.JNDI_SERVER_URL,
+ Environment.DEFAULT_HOST);
+ }
+ /**
+ * The Registry Query Manager URI can be used to obtain information about services and their endPoints.
+ * @return Registry Query Manager URI String
+ */
+ public static String getRegistryQueryManageURI()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.REGISTRY_MODULE).getProperty(Environment.REGISTRY_QUERY_MANAGER_URI);
+ }
+ /**
+ * The Registry Lifecycle Manager URI can be use to publish services.
+ * @return Registry Lifecycle Manager URI String
+ */
+ public static String getRegistryLifecycleManagerURI()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.REGISTRY_MODULE).getProperty(Environment.REGISTRY_LIFECYCLE_MANAGER_URI);
+ }
+ /**
+ * The Registry Factory Class setting specifies which JAXR implementation should be used.
+ * @return Registry Factory Class String
+ */
+ public static String getRegistryFactoryClass()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.REGISTRY_MODULE).getProperty(Environment.REGISTRY_FACTORY_CLASS);
+ }
+ /**
+ * The Registry Implememtation Class defines wrapper class
+ * @return Registry Implementation Class String
+ */
+ public static String getRegistryImplementationClass()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.REGISTRY_MODULE).getProperty(Environment.REGISTRY_IMPEMENTATION_CLASS);
+ }
+ /**
+ * The Registry Scout Transport Class defines which communication protocol Scout should use to communicate
+ * with the UDDI registry. Note that this parameter is Scout specific.
+ * @return Registry Scout Transport Class String
+ */
+ public static String getRegistryScoutTransportClass()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.REGISTRY_MODULE).getProperty(Environment.REGISTRY_SCOUT_TRANSPORT_CLASS);
+ }
+ /**
+ * The Registry User is used to inquire and publish to the Registry.
+ * @return Registry User String
+ */
+ public static String getRegistryUser()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.REGISTRY_MODULE).getProperty(Environment.REGISTRY_USER);
+ }
+ /**
+ * The Registry Password that goes with the Registry User.
+ * @return Registry Password String
+ */
+ public static String getRegistryPassword()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.REGISTRY_MODULE).getProperty(Environment.REGISTRY_PASSWORD);
+ }
+
+ public static String getParamRepositoryImplClass()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.PARAMS_REPOS_IMPL_CLASS);
+ }
+
+ public static String getObjStoreConfigFile()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.OBJECT_STORE_CONFIG_FILE);
+ return property;
+ }
+
+ public static String getEncryptionFactoryClass()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.ENCRYPT_FACTORY_CLASS,
+ org.jboss.soa.esb.services.DefaultEncryptionFactory.class
+ .getName());
+ }
+
+ public static String getDbDriver()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(Environment.DB_DRIVER);
+ return property;
+ }
+
+ public static String getDbUrl()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(Environment.DB_URL);
+ return property;
+ }
+
+ public static String getDbUser()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(Environment.DB_USER);
+ return property;
+ }
+
+ public static String getDbPassword()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(Environment.DB_PASSWORD);
+ return property;
+ }
+
+ public static String getStoreUrl()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_CONNECTION_URL);
+ return property;
+ }
+
+ public static String getStoreDriver()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_JDBC_DRIVER);
+ return property;
+ }
+
+ public static String getStorePwd()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_CONNECTION_PWD);
+ return property;
+ }
+
+ public static String getStoreUser()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_CONNECTION_USER);
+ return property;
+ }
+
+ public static String getStorePoolInitialSize()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_POOL_INITIAL_SIZE);
+ return property;
+ }
+
+ public static String getStorePoolMinSize()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_POOL_MIN_SIZE);
+ return property;
+ }
+
+ public static String getStorePoolMaxSize()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_POOL_MAX_SIZE);
+ return property;
+ }
+
+ public static String getStorePoolTestTable()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_POOL_TEST_TABLE);
+ return property;
+ }
+
+ public static String getStorePoolTimeoutMillis()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_POOL_TIMEOUT_MILLIS);
+ return property;
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,114 @@
+/*
+ * 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.common;
+
+public class Environment
+{
+ public static final String PROPERTIES_FILE = "org.jboss.soa.esb.propertyFile";
+
+ /*
+ * Transport specific properties.
+ */
+
+ public static final String SMTP_HOST = "org.jboss.soa.esb.mail.smtp.host";
+ public static final String SMTP_USERNAME = "org.jboss.soa.esb.mail.smtp.user";
+ public static final String SMTP_PASSWORD = "org.jboss.soa.esb.mail.smtp.password";
+ public static final String SMTP_PORT = "org.jboss.soa.esb.mail.smtp.port";
+ public static final String SMTP_FROM = "org.jboss.soa.esb.mail.smtp.from";
+ public static final String SMTP_AUTH = "org.jboss.soa.esb.mail.smtp.auth";
+
+ /*
+ * Code properties
+ */
+ public static final String JNDI_SERVER_TYPE = "org.jboss.soa.esb.jndi.server.type";
+ public static final String JNDI_SERVER_URL = "org.jboss.soa.esb.jndi.server.url";
+ public static final String PARAMS_REPOS_IMPL_CLASS = "org.jboss.soa.esb.paramsRepository.class";
+ public static final String OBJECT_STORE_CONFIG_FILE = "org.jboss.soa.esb.objStore.configFile";
+ public static final String ENCRYPT_FACTORY_CLASS = "org.jboss.soa.esb.encryption.factory.class";
+ /**
+ * The Registry Query Manager URI defines the endPoint where registry queries can be made.
+ */
+ public static final String REGISTRY_QUERY_MANAGER_URI = "org.jboss.soa.esb.registry.queryManagerURI";
+ /**
+ * The Registry Lifecycle Manager URI defines the endPoint where service information can be published to.
+ */
+ public static final String REGISTRY_LIFECYCLE_MANAGER_URI = "org.jboss.soa.esb.registry.lifeCycleManagerURI";
+ /**
+ * The Registry Implementation class, a light wrapper class.
+ */
+ public static final String REGISTRY_IMPEMENTATION_CLASS = "org.jboss.soa.esb.registry.implementationClass";
+ /**
+ * The Registry Factory Class setting specifies which JAXR implementation should be used.
+ */
+ public static final String REGISTRY_FACTORY_CLASS = "org.jboss.soa.esb.registry.factoryClass";
+ /**
+ * The user used to query and publish to the registry.
+ */
+ public static final String REGISTRY_USER = "org.jboss.soa.esb.registry.user";
+ /**
+ * The password for the registry user.
+ */
+ public static final String REGISTRY_PASSWORD = "org.jboss.soa.esb.registry.password";
+ /**
+ * The Registry Scout Transport Class defines which communication protocol Scout should use to communicate
+ * with the UDDI registry. Note that this parameter is Scout specific.
+ */
+ public static final String REGISTRY_SCOUT_TRANSPORT_CLASS = "org.jboss.soa.esb.scout.proxy.transportClass";
+
+ /**
+ * Property that holds directory to use with the helper EPRManager class.
+ */
+ public static final String REGISTRY_FILE_HELPER_DIR = "org.jboss.soa.esb.registry.file.directory";
+ /*
+ * Connection specific properties
+ */
+ public static String DB_DRIVER = "org.jboss.esb.db.driver";
+ public static String DB_URL = "org.jboss.esb.db.url";
+ public static String DB_USER = "org.jboss.esb.db.user";
+ public static String DB_PASSWORD = "org.jboss.esb.db.password";
+
+ /*
+ * Some default values.
+ */
+ public static final String DEFAULT_PROPERTY_FILE = "jbossesb-properties.xml";
+ public static final String DEFAULT_HOST = "localhost";
+ public static final String DEFAULT_USERNAME = "";
+ public static final String DEFAULT_PASSWORD = "";
+ public static final String DEFAULT_PORT = "25";
+ public static final String DEFAULT_SERVER_TYPE = "jboss";
+
+ /*
+ * DatabaseMessageStore Persistence Store properties.
+ */
+ public static final String MSG_STORE_DB_CONNECTION_URL = "org.jboss.soa.esb.persistence.db.connection.url";
+ public static final String MSG_STORE_DB_CONNECTION_USER = "org.jboss.soa.esb.persistence.db.user";
+ public static final String MSG_STORE_DB_CONNECTION_PWD = "org.jboss.soa.esb.persistence.db.pwd";
+ public static final String MSG_STORE_DB_TABLE_NAME = "org.jboss.soa.esb.persistence.db.table";
+ public static final String MSG_STORE_DB_JDBC_DRIVER = "org.jboss.soa.esb.persistence.db.jdbc.driver";
+ public static final String MSG_STORE_DB_POOL_INITIAL_SIZE = "org.jboss.soa.esb.persistence.db.pool.initial.size";
+ public static final String MSG_STORE_DB_POOL_MIN_SIZE = "org.jboss.soa.esb.persistence.db.pool.min.size";
+ public static final String MSG_STORE_DB_POOL_MAX_SIZE = "org.jboss.soa.esb.persistence.db.pool.max.size";
+ public static final String MSG_STORE_DB_POOL_TEST_TABLE = "org.jboss.soa.esb.persistence.db.pool.test.table";
+ public static final String MSG_STORE_DB_POOL_TIMEOUT_MILLIS = "org.jboss.soa.esb.persistence.db.pool.timeout.millis";
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2002
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: arjPropertyManager.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package org.jboss.soa.esb.common;
+
+import java.util.Hashtable;
+
+import com.arjuna.common.internal.util.propertyservice.plugins.io.XMLFilePlugin;
+import com.arjuna.common.util.propertyservice.PropertyManager;
+import com.arjuna.common.util.propertyservice.PropertyManagerFactory;
+
+/**
+ * The ESB configuration file is split into modules, each concerned with a
+ * specific capability. Each module may also depend upon another module. We use
+ * a PropertyManager per module to manage properties and relationships.
+ *
+ * All properties are grouped within <properties/> sections and individual
+ * properties by <property/>. If you look at some you'll see that they may be
+ * named and may have a depends value, which relates to another section. This
+ * tells the PropertyManager to load the depends section first. A property value
+ * may be overridden by a dependant section, but the PropertyManager remembers
+ * the hierarchy, so if you want to you can inspect and change the lower level
+ * value and the PropertyManager can be used to preserve these changes if the
+ * values are written back out to the source location.
+ *
+ * The way the PropertyManager works means that it builds up a list of dependant
+ * modules in a directed acyclic graph. This means that there is a root, which
+ * can see every property below it, but nodes below cannot see properties above
+ * them: there is a level of isolation.
+ *
+ * When creating PropertyManagers, you need to specify where in the graph it is
+ * to "tie in". This obviously has an affect on what that instance can then see
+ * or do: if it goes in at the wrong level, it won't be able to see properties
+ * it may need (unless they were defined to be "system" properties, and in which
+ * case they are globally accessible.)
+ *
+ * This means that we now have isolated PropertyManagers for each module. It
+ * helps the management side of things a lot, but does mean that we have to
+ * consider where in the graph a property needs to be, or which PropertyManager
+ * we want to use to try to access it.
+ *
+ * @author marklittle
+ *
+ */
+public class ModulePropertyManager
+{
+
+ /*
+ * The names of the various modules in the property file.
+ */
+
+ public static final String CORE_MODULE = "core";
+
+ public static final String CONNECTION_MODULE = "connection";
+
+ public static final String REGISTRY_MODULE = "registry";
+
+ public static final String TRANSPORTS_MODULE = "transports";
+
+ public static final String DBSTORE_MODULE = "dbstore";
+
+
+
+ /**
+ * Get the property manager responsible for the module component in the
+ * file.
+ *
+ * @param name
+ * the name of the module.
+ * @return the relevant property manager.
+ */
+
+ public static PropertyManager getPropertyManager(String name)
+ {
+ synchronized (managers)
+ {
+ PropertyManager theManager = managers.get(name);
+
+ if (theManager == null)
+ {
+ theManager = initialise(name);
+
+ if (theManager != null) {
+ managers.put(name, theManager);
+ }
+ }
+
+ return theManager;
+ }
+ }
+
+ private static final PropertyManager initialise(String name)
+ {
+ /**
+ * Retrieve the property manager from the factory and add the ESB
+ * properties file to it.
+ *
+ * set com.arjuna.common.util.propertyservice.verbosePropertyManager=ON
+ * for verbose output from the PropertyManager.
+ */
+
+ PropertyManager propertyManager = PropertyManagerFactory
+ .getPropertyManager(
+ "org.jboss.soa.esb.propertymanager." + name, name);
+
+ String propertiesFilename = System.getProperty(
+ Environment.PROPERTIES_FILE, Environment.DEFAULT_PROPERTY_FILE);
+
+ /*
+ * Does not cause reloading of the same file over and over. Once it is loaded,
+ * subsequent attempts to reload are ignored internally.
+ */
+
+ try
+ {
+ propertyManager.load(XMLFilePlugin.class.getName(),
+ propertiesFilename);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+
+ return null;
+ }
+
+ return propertyManager;
+ }
+
+ private static Hashtable<String, PropertyManager> managers = new Hashtable<String, PropertyManager>();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Address.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Address.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Address.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,154 @@
+/*
+* 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.common.bizclasses;
+
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+
+public class Address extends BaseBusinessObject
+{
+ public enum ATTRIB
+ {strNum
+ ,strLine1
+ ,strLine2
+ ,suite
+ ,twnCty1
+ ,twnCty2
+ ,postalZip
+ ,provSt
+ ,cntry
+ };
+ private EnumMap<ATTRIB,String>m_oData;
+
+ public enum CHLD_LIST
+ {Lpho
+ };
+ private List<Telephone> m_olPhones;
+
+ public Address(String p_sElem) {super(p_sElem);}
+ public Address(String p_sElem, long p_lUid) {super(p_sElem, p_lUid);}
+
+ @SuppressWarnings("unchecked")
+ public Address(BobjStdDTO p_oDto) throws Exception
+ { super(p_oDto);
+
+ for (ATTRIB oCurr : ATTRIB.values())
+ setField(oCurr,p_oDto.getAttr(oCurr.toString()));
+ m_olPhones = (List<Telephone>)
+ p_oDto.getChildObjList(CHLD_LIST.Lpho.toString() ,Telephone.class);
+ } //__________________________________
+
+ public BobjStdDTO toDTO() throws Exception
+ { BobjStdDTO oRet = super.toDTO();
+
+ for (ATTRIB oCurr : ATTRIB.values())
+ oRet.addAttr(oCurr.toString(), getField(oCurr));
+ oRet.addDto(CHLD_LIST.Lpho.toString() ,getDtoList(Telephone.class ,m_olPhones));
+
+ return oRet;
+ } //__________________________________
+
+ public String setField(ATTRIB pKey, String pVal)
+ { if (null==pKey) return null;
+ String sRet = (null==m_oData)? null : m_oData.remove(pKey);
+ if (! Util.isNullString(pVal))
+ { if (null==m_oData)
+ m_oData = new EnumMap<ATTRIB,String>(ATTRIB.class);
+ m_oData.put(pKey,pVal);
+ }
+ return sRet;
+ } //__________________________________
+
+ public String getField(ATTRIB pKey)
+ { if (null==pKey) return null;
+ if (null==m_oData) return null;
+ return m_oData.get(pKey);
+ } //__________________________________
+
+ // Telephone List handling
+
+ public int getPhoneCount ()
+ { return (null == m_olPhones)? 0 : m_olPhones.size(); }
+
+ public Telephone getPhoneAt (int p_i)
+ { if (null == m_olPhones) return null;
+ if(p_i < 0 || p_i >=m_olPhones.size()) return null;
+ return m_olPhones.get(p_i);
+ }//_____________________________________________
+
+ public void addPhone(Telephone p_oPh)
+ { if(null==p_oPh) return;
+ if(null==m_olPhones)
+ m_olPhones = new ArrayList<Telephone>();
+ m_olPhones.add(p_oPh);
+ }//_____________________________________________
+
+ public Telephone rmvPhoneAt (int p_i)
+ { if (null == m_olPhones) return null;
+ if(p_i < 0 || p_i >=m_olPhones.size()) return null;
+ return m_olPhones.remove(p_i);
+ }//_____________________________________________
+
+ public Telephone getPhoneRole(String p_sRole)
+ { return (Telephone)BaseBusinessObject.getRoleFromList(p_sRole,m_olPhones);
+ }//_____________________________________________
+
+ public String toString()
+ { StringBuilder sb = new StringBuilder();
+ String sCurr = getField(ATTRIB.strNum);
+ if (! Util.isNullString(sCurr))
+ sb.append(sCurr).append(" ");
+
+ ATTRIB [] oa = {ATTRIB.strLine1,ATTRIB.strLine2
+ ,ATTRIB.twnCty1,ATTRIB.twnCty2 };
+ for (ATTRIB oAtt : oa)
+ { sCurr = getField(oAtt);
+ if(! Util.isNullString(sCurr))
+ sb.append(sCurr.trim()).append("\n");
+ }
+ StringBuilder sZprov = new StringBuilder();
+ sCurr = getField(ATTRIB.postalZip);
+ if (! Util.isNullString(sCurr))
+ sZprov.append(sCurr.trim()).append(" ");
+
+ sCurr = getField(ATTRIB.provSt);
+ if (! Util.isNullString(sCurr))
+ sZprov.append(sCurr.trim());
+ if (sb.length()>0 && '\n'!=sb.charAt(-1+sb.length()))
+ sb.append("\n");
+ sb.append(sZprov);
+
+ sCurr = getField(ATTRIB.cntry);
+ if (! Util.isNullString(sCurr))
+ { if (sb.length()>0 && '\n'!=sb.charAt(-1+sb.length()))
+ sb.append("\n");
+ sb.append(sCurr.trim());
+ }
+ return sb.toString();
+ } //__________________________________
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/BankAcct.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/BankAcct.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/BankAcct.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,73 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.soa.esb.common.bizclasses;
+
+import java.util.EnumMap;
+
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+
+public class BankAcct extends BaseBusinessObject
+{
+ public enum ATTRIB
+ {acct
+ ,bank
+ ,branch
+ ,desig
+ };
+ private EnumMap<ATTRIB,String>m_oData;
+
+ public BankAcct(String p_sElem) {super(p_sElem);}
+ public BankAcct(String p_sElem, long p_lUid) {super(p_sElem, p_lUid);}
+
+ public BankAcct(BobjStdDTO p_oDto) throws Exception
+ { super(p_oDto);
+ for (ATTRIB oCurr : ATTRIB.values())
+ setField(oCurr,p_oDto.getAttr(oCurr.toString()));
+ } //__________________________________
+
+ public BobjStdDTO toDTO() throws Exception
+ { BobjStdDTO oRet = super.toDTO();
+ for (ATTRIB oCurr : ATTRIB.values())
+ oRet.addAttr(oCurr.toString(), getField(oCurr));
+ return oRet;
+ } //__________________________________
+
+ public String setField(ATTRIB pKey, String pVal)
+ { if (null==pKey) return null;
+ String sRet = (null==m_oData)? null : m_oData.remove(pKey);
+ if (! Util.isNullString(pVal))
+ { if (null==m_oData)
+ m_oData = new EnumMap<ATTRIB,String>(ATTRIB.class);
+ m_oData.put(pKey,pVal);
+ }
+ return sRet;
+ } //__________________________________
+
+ public String getField(ATTRIB pKey)
+ { if (null==pKey) return null;
+ if (null==m_oData) return null;
+ return m_oData.get(pKey);
+ } //__________________________________
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/BatchProcess.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/BatchProcess.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/BatchProcess.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,265 @@
+/*
+ * 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.common.bizclasses;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.EnumMap;
+import java.util.List;
+
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+
+public class BatchProcess extends BaseBusinessObject {
+
+ public enum ATTRIB {
+ srcApp, batchNum, createStamp, commitStamp
+ };
+
+ private EnumMap<ATTRIB, String> m_oData;
+
+ public enum CHLD_LIST {
+ Hdrs, Itms
+ };
+
+ public List<OneValue> m_olHeaders, m_olItems;
+
+ /**
+ * @param p_sElem
+ * String
+ * @param p_lUid
+ * long
+ * @see BaseBusinessObject#BaseBusinessObject(String,long)
+ */
+ public BatchProcess(String p_sElem, long p_lUid) {
+ super(p_sElem, p_lUid);
+ }
+
+ /**
+ *
+ * @param p_oDto
+ * BobjStdDTO
+ * @throws Exception
+ * @see BaseBusinessObject#BaseBusinessObject(BobjStdDTO)
+ */
+
+ @SuppressWarnings("unchecked")
+ public BatchProcess(BobjStdDTO p_oDto) throws Exception {
+ super(p_oDto);
+ for (ATTRIB oCurr : ATTRIB.values())
+ setField(oCurr, p_oDto.getAttr(oCurr.toString()));
+
+ m_olHeaders = (List<OneValue>) p_oDto.getChildObjList(CHLD_LIST.Hdrs
+ .toString(), OneValue.class);
+ m_olItems = (List<OneValue>) p_oDto.getChildObjList(CHLD_LIST.Itms
+ .toString(), OneValue.class);
+ }// __________________________________________
+
+ /**
+ *
+ * @throws Exception
+ * @return BobjStdDTO
+ * @see BusinessObject#toDTO()
+ */
+ public BobjStdDTO toDTO() throws Exception {
+ BobjStdDTO oRet = super.toDTO();
+ for (ATTRIB oCurr : ATTRIB.values())
+ oRet.addAttr(oCurr.toString(), getField(oCurr));
+
+ oRet.addDto(CHLD_LIST.Hdrs.toString(), getDtoList(OneValue.class,
+ m_olItems));
+ oRet.addDto(CHLD_LIST.Itms.toString(), getDtoList(OneValue.class,
+ m_olHeaders));
+ return oRet;
+
+ }// _________________________________________
+
+ // Setters
+ /**
+ * Add a reference to a BusinessObject (it's UID) to the list of batch
+ * header BusinessObjects
+ *
+ * @param p_l
+ * long - The UID of the BusinessObject to add to the header list
+ * @see BatchProcess#m_olHeaders
+ */
+ public void addHeaderUid(long p_l) {
+ if (null == m_olHeaders)
+ m_olHeaders = new ArrayList<OneValue>();
+ m_olHeaders.add(OneValue.getLongValue(p_l));
+ }// _____________________________________________
+
+ /**
+ * Remove an object from the header list
+ *
+ * @param p_i
+ * int - index of header to remove
+ * @return long - UID of the object removed
+ * @see BatchProcess#addHeaderUid(long)
+ */
+ public long rmvHeaderAt(int p_i) {
+ if (null == m_olHeaders)
+ return -1;
+ if (p_i < 0 || p_i >= m_olHeaders.size())
+ return -1;
+ return Long.parseLong(((OneValue) m_olHeaders.remove(p_i)).m_sVal);
+ }// _____________________________________________
+
+ /**
+ * Add a reference to a BusinessObject (it's UID) to the list of batch items
+ * BusinessObjects
+ *
+ * @param p_l
+ * long - The UID of the BusinessObject to add to the item list
+ * @see BatchProcess#m_olItems
+ */
+ public void addChildUid(long p_l) {
+ if (null == m_olItems)
+ m_olItems = new ArrayList<OneValue>();
+ m_olItems.add(OneValue.getLongValue(p_l));
+ }// _____________________________________________
+
+ /**
+ * Remove an object from the item list
+ *
+ * @param p_i
+ * int - index of item to remove
+ * @return long - UID of the object removed
+ * @see BatchProcess#addChildUid(long)
+ */
+ public long rmvChildAt(int p_i) {
+ if (null == m_olItems)
+ return -1;
+ if (p_i < 0 || p_i >= m_olItems.size())
+ return -1;
+ return Long.parseLong(((OneValue) m_olItems.remove(p_i)).m_sVal);
+ }// _____________________________________________
+
+ // getters
+ /**
+ * Return the number of header objects in this batch
+ *
+ * @return int - The size of the header list
+ * @see BatchProcess#m_olHeaders
+ */
+ public int getHeaderCount() {
+ return (null == m_olHeaders) ? 0 : m_olHeaders.size();
+ }// _______________________________
+
+ /**
+ * Get an object from the header list
+ *
+ * @param p_i
+ * int - index of header object to get
+ * @return long - UID of the object at requested position - or minus 1 (-1)
+ * if invalid index
+ * @see BatchProcess#m_olHeaders
+ */
+ public long getHeaderAt(int p_i) {
+ if (null == m_olHeaders)
+ return -1;
+ if (p_i < 0 || p_i >= m_olHeaders.size())
+ return -1;
+ return Long.parseLong(((OneValue) m_olHeaders.get(p_i)).m_sVal);
+ }// _____________________________________________
+
+ /**
+ * Return the number of item objects in this batch
+ *
+ * @return int - The size of the item list
+ * @see BatchProcess#m_olItems
+ */
+ public int getChildCount() {
+ return (null == m_olItems) ? 0 : m_olItems.size();
+ }// _______________________________
+
+ /**
+ * Get an object from the item list
+ *
+ * @param p_i
+ * int - index of item object to get
+ * @return long - UID of the object at requested position - or minus 1 (-1)
+ * if invalid index
+ * @see BatchProcess#m_olItems
+ */
+ public long getChildAt(int p_i) {
+ if (null == m_olItems)
+ return -1;
+ if (p_i < 0 || p_i >= m_olItems.size())
+ return -1;
+ return Long.parseLong(((OneValue) m_olItems.get(p_i)).m_sVal);
+ }// _____________________________________________
+
+ private static final SimpleDateFormat s_FD = new SimpleDateFormat(
+ "yyyyMMdd HH:mm:ss.S");
+
+ protected final String showStamp(ATTRIB pFld) {
+ long lMillis = Util.parseLong(getField(pFld));
+ if (lMillis < 1)
+ return "";
+ return s_FD.format(new Date(lMillis));
+ }// _____________________________________________
+
+ /**
+ * Obtain a String[] of 'human readable' attributes that will help identify
+ * the BatchProcess object.
+ * <p>
+ * These attributes will be stored in the batch_index table in the Object
+ * store to allow for standard SQL queries. Once the desired object is
+ * identified, we can access the Object table using the Object's that are
+ * referenced in the batch_index table UID
+ * </p>
+ *
+ * @return String[] - Batch number, Creation time, Commit time
+ */
+ public String[] locator() {
+ String sFrom = getField(ATTRIB.srcApp);
+ String sNumber = getField(ATTRIB.batchNum);
+ return new String[] {
+ (null == sFrom) ? "" : sFrom.substring(0, Math.min(50, sFrom
+ .length())), (null == sNumber) ? "" : sNumber,
+ showStamp(ATTRIB.createStamp), showStamp(ATTRIB.commitStamp) };
+ } // __________________________________
+
+ public String setField(ATTRIB pKey, String pVal) {
+ if (null == pKey)
+ return null;
+ String sRet = (null == m_oData) ? null : m_oData.remove(pKey);
+ if (!Util.isNullString(pVal)) {
+ if (null == m_oData)
+ m_oData = new EnumMap<ATTRIB, String>(ATTRIB.class);
+ m_oData.put(pKey, pVal);
+ }
+ return sRet;
+ } // __________________________________
+
+ public String getField(ATTRIB pKey) {
+ if (null == pKey)
+ return null;
+ if (null == m_oData)
+ return null;
+ return m_oData.get(pKey);
+ } // __________________________________
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/OneValue.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/OneValue.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/OneValue.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,99 @@
+/*
+ * 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.common.bizclasses;
+
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+
+/**
+ * Utility class used to serialize a String within a list of child
+ * BusinessObjects It provides no functionality other than allowing the
+ * inclusion of a String (eventually with a role and an element name) in a list
+ * of children
+ */
+
+public class OneValue extends BaseBusinessObject {
+ private static final String A_VAL = "v";
+
+ public String m_sVal;
+
+ /**
+ * @see BaseBusinessObject#BaseBusinessObject(BobjStdDTO)
+ * @param p_sElem
+ * String
+ */
+ public OneValue(String p_sElem) {
+ super(p_sElem);
+ }
+
+ /**
+ * @see BaseBusinessObject#BaseBusinessObject(BobjStdDTO)
+ * @param p_sElem
+ * String
+ * @param p_lUid
+ * long
+ */
+ public OneValue(String p_sElem, long p_lUid) {
+ super(p_sElem, p_lUid);
+ }
+
+ /**
+ * @see BaseBusinessObject#BaseBusinessObject(BobjStdDTO)
+ * @param p_oDto
+ * BobjStdDTO
+ * @throws Exception
+ */
+ public OneValue(BobjStdDTO p_oDto) throws Exception {
+ super(p_oDto);
+ m_sVal = p_oDto.getAttr(A_VAL);
+ } // ___________________________________
+
+ /**
+ * @see BusinessObject#toDTO()
+ * @throws Exception
+ * @return BobjStdDTO
+ */
+ public BobjStdDTO toDTO() throws Exception {
+ BobjStdDTO oRet = super.toDTO();
+ oRet.addAttr(A_VAL, m_sVal);
+ return oRet;
+ } // ___________________________________
+
+ public static final OneValue getLongValue(Long p_l) {
+ OneValue oCurr = new OneValue((String) null);
+ if (null != p_l)
+ oCurr.m_sVal = Long.toString(p_l);
+ return oCurr;
+ } // ___________________________________
+
+ public static final OneValue getStringValue(String p_sVal) {
+ return getStringValue(p_sVal, null);
+ } // ___________________________________
+
+ public static final OneValue getStringValue(String p_sVal, String p_sRole) {
+ OneValue oCurr = new OneValue((String) null);
+ oCurr.m_sVal = p_sVal;
+ oCurr.setRole(p_sRole);
+ return oCurr;
+ } // ___________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Person.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Person.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Person.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,242 @@
+/*
+* 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.common.bizclasses;
+
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+
+public class Person extends BaseBusinessObject
+{
+ public enum ATTRIB
+ {pfx
+ ,givN
+ ,midN
+ ,fmlyN
+ ,sfx
+ ,doB
+ ,gend
+ ,prefLang
+ };
+ private EnumMap<ATTRIB,String>m_oData;
+
+ public enum CHLD_LIST
+ {Laddr
+ ,Lemail
+ ,Lpho
+ };
+ private List<Address> m_olAddr;
+ private List<OneValue> m_olEmail;
+ private List<Telephone> m_olPhones;
+
+ public Person(String p_sElem) {super(p_sElem);}
+ public Person(String p_sElem, long p_lUid) {super(p_sElem, p_lUid);}
+
+ @SuppressWarnings("unchecked")
+ public Person(BobjStdDTO p_oDto) throws Exception
+ {super(p_oDto);
+
+ for (ATTRIB oCurr : ATTRIB.values())
+ setField(oCurr,p_oDto.getAttr(oCurr.toString()));
+
+ m_olPhones = (List<Telephone>)
+ p_oDto.getChildObjList(CHLD_LIST.Lpho.toString() ,Telephone.class);
+ m_olEmail = (List<OneValue>)
+ p_oDto.getChildObjList(CHLD_LIST.Lemail.toString(),OneValue.class);
+ m_olAddr = (List<Address>)
+ p_oDto.getChildObjList(CHLD_LIST.Laddr.toString(),Address.class);
+ } //__________________________________
+
+ public BobjStdDTO toDTO() throws Exception
+ { BobjStdDTO oRet = super.toDTO();
+
+ for (ATTRIB oCurr : ATTRIB.values())
+ oRet.addAttr(oCurr.toString(), getField(oCurr));
+
+ oRet.addDto(CHLD_LIST.Lpho.toString() ,getDtoList(Telephone.class ,m_olPhones));
+ oRet.addDto(CHLD_LIST.Lemail.toString() ,getDtoList(OneValue.class ,m_olEmail));
+ oRet.addDto(CHLD_LIST.Laddr.toString() ,getDtoList(Address.class ,m_olAddr));
+
+ return oRet;
+
+ }//_________________________________________
+
+ public String[] locator()
+ {
+ return new String[]
+ {nameForLocator()
+ ,phoneForLocator()
+ ,addressForLocator()
+ };
+ } //__________________________________
+
+ protected String nameForLocator()
+ {
+ StringBuilder sb = new StringBuilder();
+ String sCurr = getField(ATTRIB.pfx);
+ if (null!=sCurr) sb.append(sCurr).append(" ");
+
+ sCurr = getField(ATTRIB.fmlyN);
+ if (null!=sCurr) sb.append(sCurr).append(", ");
+
+ sCurr = getField(ATTRIB.givN);
+ if (null!=sCurr) sb.append(sCurr).append(" ");
+
+ sCurr = getField(ATTRIB.midN);
+ if (null!=sCurr) sb.append(sCurr).append(" ");
+
+
+ return (sb.length()>0) ? sb.toString() : "UNKNOWN NAME";
+ } //__________________________________
+
+ protected String phoneForLocator()
+ {
+ StringBuilder sb = new StringBuilder();
+ Telephone oPh = getPhoneAt(0);
+
+ if (null==oPh)
+ { Address oAddr = getAddressAt(0);
+ if (null!=oAddr)
+ oPh = oAddr.getPhoneAt(0);
+ }
+
+ if (null!=oPh)
+ sb.append(oPh.toString());
+ return (sb.length()>0) ? sb.toString() : "";
+ } //__________________________________
+
+ protected String addressForLocator()
+ {
+ StringBuilder sb = new StringBuilder();
+ Address oAddr = getAddressAt(0);
+ if (null!=oAddr)
+ sb.append(oAddr.toString());
+ return (sb.length()>0) ? sb.toString() : "";
+ } //__________________________________
+
+ public String setField(ATTRIB pKey, String pVal)
+ { if (null==pKey) return null;
+ String sRet = (null==m_oData)? null : m_oData.remove(pKey);
+ if (! Util.isNullString(pVal))
+ { if (null==m_oData)
+ m_oData = new EnumMap<ATTRIB,String>(ATTRIB.class);
+ m_oData.put(pKey,pVal);
+ }
+ return sRet;
+ } //__________________________________
+
+ public String getField(ATTRIB pKey)
+ { if (null==pKey) return null;
+ if (null==m_oData) return null;
+ return m_oData.get(pKey);
+ } //__________________________________
+
+ // Address List handling
+
+ public int getAddressCount ()
+ { return (null == m_olAddr)? 0 : m_olAddr.size(); }
+
+ public Address getAddressAt (int p_i)
+ { if (null == m_olAddr) return null;
+ if(p_i < 0 || p_i >=m_olAddr.size()) return null;
+ return m_olAddr.get(p_i);
+ }//_____________________________________________
+
+ public void addAddress(Address p_oAddress)
+ { if(null==p_oAddress) return;
+ if(null==m_olAddr)
+ m_olAddr = new ArrayList<Address>();
+ m_olAddr.add(p_oAddress);
+ }//_____________________________________________
+
+ public Address rmvAddressAt (int p_i)
+ { if (null == m_olAddr) return null;
+ if(p_i < 0 || p_i >=m_olAddr.size()) return null;
+ return m_olAddr.remove(p_i);
+ }//_____________________________________________
+
+ public Address getAddressRole(String p_sRole)
+ { return (Address)BaseBusinessObject.getRoleFromList(p_sRole,m_olAddr);
+ }//_____________________________________________
+
+ // Telephone List handling
+
+ public int getPhoneCount ()
+ { return (null == m_olPhones)? 0 : m_olPhones.size(); }
+
+ public Telephone getPhoneAt (int p_i)
+ { if (null == m_olPhones) return null;
+ if(p_i < 0 || p_i >=m_olPhones.size()) return null;
+ return m_olPhones.get(p_i);
+ }//_____________________________________________
+
+ public void addPhone(Telephone p_oPh)
+ { if(null==p_oPh) return;
+ if(null==m_olPhones)
+ m_olPhones = new ArrayList<Telephone>();
+ m_olPhones.add(p_oPh);
+ }//_____________________________________________
+
+ public Telephone rmvPhoneAt (int p_i)
+ { if (null == m_olPhones) return null;
+ if(p_i < 0 || p_i >=m_olPhones.size()) return null;
+ return m_olPhones.remove(p_i);
+ }//_____________________________________________
+
+ public Telephone getPhoneRole(String p_sRole)
+ { return (Telephone)BaseBusinessObject.getRoleFromList(p_sRole,m_olPhones);
+ }//_____________________________________________
+
+ // e-mail List handling
+
+ public int getEmailCount ()
+ { return (null == m_olEmail)? 0 : m_olEmail.size(); }
+
+ public OneValue getEmailAt (int p_i)
+ { if (null == m_olEmail) return null;
+ if(p_i < 0 || p_i >=m_olEmail.size()) return null;
+ return m_olEmail.get(p_i);
+ }//_____________________________________________
+
+ public void addEmail(OneValue p_oEm)
+ { if(null==p_oEm) return;
+ if(null==m_olEmail)
+ m_olEmail = new ArrayList<OneValue>();
+ m_olEmail.add(p_oEm);
+ }//_____________________________________________
+
+ public OneValue rmvEmailAt (int p_i)
+ { if (null == m_olEmail) return null;
+ if(p_i < 0 || p_i >=m_olEmail.size()) return null;
+ return m_olEmail.remove(p_i);
+ }//_____________________________________________
+
+ public String getEmailRole(String p_sRole)
+ { OneValue oEm = (OneValue)BaseBusinessObject.getRoleFromList(p_sRole,m_olEmail);
+ return (null==oEm) ? null : oEm.m_sVal;
+ }//_____________________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Telephone.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Telephone.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/common/bizclasses/Telephone.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,94 @@
+/*
+* 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.common.bizclasses;
+
+import java.util.EnumMap;
+
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+
+public class Telephone extends BaseBusinessObject
+{
+ public enum ATTRIB
+ {cntry
+ ,city
+ ,num
+ ,ext
+ };
+ private EnumMap<ATTRIB,String>m_oData;
+
+ public Telephone(String p_sElem) {super(p_sElem);}
+ public Telephone(String p_sElem, long p_lUid) {super(p_sElem, p_lUid);}
+
+ public Telephone(BobjStdDTO p_oDto) throws Exception
+ { super(p_oDto);
+ for (ATTRIB oCurr : ATTRIB.values())
+ setField(oCurr,p_oDto.getAttr(oCurr.toString()));
+ } //__________________________________
+
+ public BobjStdDTO toDTO() throws Exception
+ { BobjStdDTO oRet = super.toDTO();
+ for (ATTRIB oCurr : ATTRIB.values())
+ oRet.addAttr(oCurr.toString(), getField(oCurr));
+ return oRet;
+ } //__________________________________
+
+ public String setField(ATTRIB pKey, String pVal)
+ { if (null==pKey) return null;
+ if (null==m_oData) m_oData = new EnumMap<ATTRIB,String>(ATTRIB.class);
+ String sRet = m_oData.remove(pKey);
+ if (! Util.isNullString(pVal))
+ m_oData.put(pKey,pVal);
+ return sRet;
+ } //__________________________________
+
+ public String getField(ATTRIB pKey)
+ { if (null==pKey) return null;
+ if (null==m_oData) return null;
+ return m_oData.get(pKey);
+ } //__________________________________
+
+ public String toString()
+ { StringBuilder sb = new StringBuilder();
+ String sCurr = getField(ATTRIB.cntry);
+ if (! Util.isNullString(sCurr))
+ sb.append("+").append(sCurr.trim());
+
+ sCurr = getField(ATTRIB.city);
+ if(Util.isNullString(sCurr)) sb.append(" ");
+ else
+ sb.append("(").append(sCurr.trim()).append(")");
+
+ sCurr = getField(ATTRIB.num);
+ if(! Util.isNullString(sCurr))
+ sb.append(sCurr.trim());
+
+ sCurr = getField(ATTRIB.ext);
+ if(!Util.isNullString(sCurr))
+ sb.append(" Ext ").append(sCurr.trim());
+
+ return sb.toString();
+ } //__________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/AbandonedConnectionTimerTask.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/AbandonedConnectionTimerTask.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/AbandonedConnectionTimerTask.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,50 @@
+/*
+* 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.connection;
+
+import java.util.TimerTask;
+
+/**
+ * Timer task which will run at scheduled times based on the property set by the user.
+ * This task will remove all unused connections which have elapsed a certain period of time
+ * @author MohitK
+ * Date: Jul 26, 2006
+ */
+public class AbandonedConnectionTimerTask extends TimerTask {
+
+ private DefaultConnectionPoolImpl m_oPool;
+
+ /**
+ * Constructor which takes the pool implementation
+ * @param pool
+ */
+ public AbandonedConnectionTimerTask(DefaultConnectionPoolImpl pool){
+ this.m_oPool = pool;
+ }
+
+ public void run() {
+ synchronized(m_oPool){
+ m_oPool.releaseAbandonedConnections();
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.connection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Factory interface for creating connections based on different sources such as Driver, DriverManager or any
+ * third party implementation
+ * @author MohitK
+ * Date: Jul 18, 2006
+ */
+public interface ConnectionFactory {
+ /**
+ * Creates a new JDBC Connection. The implementation is left to the classes.
+ * @return Connection
+ * @throws SQLException
+ */
+ public Connection createConnection() throws SQLException;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionPool.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionPool.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionPool.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,64 @@
+/*
+* 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.connection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.jboss.soa.esb.connection.exception.ConnectionException;
+
+/**
+ * Interface that needs to be implemented to provide pool of connections.
+ * @see DefaultConnectionPoolImpl
+ * Default implementation of Connection Pool
+ * @author MohitK
+ * Date: Jul 18, 2006
+ */
+public interface ConnectionPool {
+ /**
+ * This method is used to create the connection pool and keep it ready
+ * @param prop Properties for the connection pool including connection properties
+ * @throws ConnectionException
+ */
+ public void createPool(ConnectionProperties prop) throws ConnectionException;
+
+ /**
+ * This method is called whenever a connection is needed from the pool.
+ * @return Connection to be used
+ * @throws SQLException
+ */
+ public Connection getConnection() throws SQLException;
+
+ /**
+ * This method closes an open connection and returns the connection to the pool.
+ * @param connectionToClose The connection to be returned to the pool.
+ * @throws SQLException
+ */
+ public void closeConnection(Connection connectionToClose) throws SQLException;
+
+ /**
+ * This method is called when the pool needs to be destroyed effectively closing all open connections
+ * @throws SQLException
+ */
+ public void releasePool() throws SQLException;
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionPoolFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionPoolFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionPoolFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,64 @@
+/*
+* 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.connection;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.connection.exception.ConnectionException;
+
+/**
+ * Factory class which creates a connection pool. The factory also creates a JVM Shutdown hook which is called when
+ * JVM is shutting down which indirectly calls @link ConnectionPool#releasePool
+ *
+ * @author MohitK
+ * Date: Jul 19, 2006
+ */
+public class ConnectionPoolFactory {
+
+
+ private static Logger Log = Logger.getLogger(ConnectionPoolFactory.class);
+
+ /**
+ * Factory method to create and return a connection pool based on the property set for the connection pool
+ * implementation. The factory also registers a shut down hook with the JVM so that the connections in the pool
+ * are closed and released with causing connections leaks.
+ *
+ * @param connProperties Properties for the connection pool
+ * @return Connection Pool
+ * @throws ConnectionException
+ */
+ public static ConnectionPool createPool(ConnectionProperties connProperties) throws ConnectionException {
+ String connectionPoolClassName = connProperties.getConnectionPoolClass();
+ try {
+ ConnectionPool pool = (ConnectionPool) Class.forName(connectionPoolClassName).newInstance();
+ pool.createPool(connProperties);
+ FreeConnectionPoolResources freeResourcesThread = new FreeConnectionPoolResources(pool);
+ Runtime.getRuntime().addShutdownHook(freeResourcesThread);
+ return pool;
+ } catch (ConnectionException e) {
+ Log.error("ConnectionPoolFactory: Error in creating Connection Pool", e);
+ throw e;
+ } catch (Throwable t){
+ Log.error("ConnectionPoolFactory: Error in Connection Pool", t);
+ throw new ConnectionException(t);
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionProperties.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionProperties.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionProperties.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,358 @@
+/*
+ * 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.connection;
+
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+
+/**
+ * Connection Property class which stores all connection and connection pool
+ * properties. It keeps the properties ready so that is can be used by the pool
+ * and connection factory
+ *
+ * @author MohitK Date: Jul 18, 2006
+ */
+public class ConnectionProperties
+{
+
+ private static Logger Log = Logger.getLogger(ConnectionProperties.class);
+
+ private Properties m_oConnectionProperties;
+
+ public static final String DRIVER_CLASSNAME = "driver-class";
+
+ public static final String CONNECTION_URL = "connection-url";
+
+ public static final String USERNAME = "user-name";
+
+ public static final String PASSWORD = "password";
+
+ public static final String AUTO_COMMIT = "auto-commit";
+
+ public static final String ISOLATION_LEVEL = "isolation";
+
+ public static final String MIN_POOL_SIZE = "min-pool-size";
+
+ public static final String MAX_POOL_SIZE = "max-pool-size";
+
+ public static final String BLOCKING_CONNECTION_TIME = "blocking-timeout-millis";
+
+ public static final String CONNECTION_POOL_CLASS = "connection-pool-class";
+
+ public static final String PASSWORD_DECODER = "password-decrypter";
+
+ public static final String ABANDONED_CONNECTION_TIMEOUT = "abandoned-connection-timeout";
+
+ public static final String ABANDONED_CONNECTION_CHECK_INTERVAL = "abandoned-connection-time-interval";
+
+ private boolean m_bAutoCommit;
+
+ private Integer m_iIsolationLvl;
+
+ private int m_iMinPoolSize;
+
+ private int m_iMaxPoolSize;
+
+ private long m_lConnBlockTime;
+
+ private String m_sConnectionPoolClass;
+
+ private String m_sUser;
+
+ private String m_sPassword;
+
+ private String m_sConnectionUrl;
+
+ private long m_lAbandonedConnectionTimeout;
+
+ private long m_lAbandonedConnectionCheckInterval;
+
+ private String m_sDriverClassName;
+
+ public static final String DEFAULT_MIN_POOL_SIZE = "5";
+
+ public static final String DEFAULT_MAX_POOL_SIZE = "10";
+
+ public static final String DEFAULT_CONN_BLOCK_TIME_MILLIS = "5000";
+
+ public static final String DEFAULT_CONNECTION_POOL_CLASS = DefaultConnectionPoolImpl.class
+ .getName();
+
+ public static final String DEFAULT_ABANDONED_CONNECTION_TIMEOUT = "10000";
+
+ public static final String DEFAULT_ABANDONED_CONNECTION_CHECK_INTERVAL = "30000";
+
+ public ConnectionProperties(Properties connectionProperties)
+ {
+ this.m_oConnectionProperties = connectionProperties;
+ setDriverClassName();
+ setConnectionUrl();
+ setUser();
+ setPassword();
+ setConnectionPoolClass();
+ setAutoCommit();
+ setIsolationLevel();
+ setMinPoolSize();
+ setMaxPoolSize();
+ setBlockingConnectionTime();
+ setAbandonedConnectionTimeOut();
+ setAbandonedConnectionCheckInterval();
+ }
+
+ private void setDriverClassName()
+ {
+ m_sDriverClassName = m_oConnectionProperties
+ .getProperty(DRIVER_CLASSNAME);
+ if (m_sDriverClassName == null)
+ {
+ m_sDriverClassName = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(DRIVER_CLASSNAME);
+ }
+ }
+
+ protected String getDriverClassName()
+ {
+ return m_sDriverClassName;
+ }
+
+ protected String getConnectionUrl()
+ {
+ return m_sConnectionUrl;
+ }
+
+ private void setConnectionUrl()
+ {
+ m_sConnectionUrl = m_oConnectionProperties.getProperty(CONNECTION_URL);
+ if (m_sConnectionUrl == null)
+ {
+ m_sConnectionUrl = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(
+ CONNECTION_URL);
+ }
+ }
+
+ protected boolean getAutoCommit()
+ {
+ return m_bAutoCommit;
+ }
+
+ protected Integer getIsolationLevel()
+ {
+ return m_iIsolationLvl;
+ }
+
+ private void setIsolationLevel()
+ {
+ String isolation = (String) m_oConnectionProperties
+ .get(ISOLATION_LEVEL);
+ if (isolation == null)
+ {
+ isolation = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(
+ ISOLATION_LEVEL);
+ }
+ this.m_iIsolationLvl = (isolation != null) ? new Integer(isolation)
+ : null;
+ }
+
+ protected int getMinPoolSize()
+ {
+ return m_iMinPoolSize;
+ }
+
+ protected int getMaxPoolSize()
+ {
+ return m_iMaxPoolSize;
+ }
+
+ private void setMinPoolSize()
+ {
+ String strPoolSize = m_oConnectionProperties.getProperty(MIN_POOL_SIZE);
+ if (strPoolSize == null)
+ {
+ strPoolSize = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(
+ MIN_POOL_SIZE, DEFAULT_MIN_POOL_SIZE);
+ }
+ this.m_iMinPoolSize = Integer.parseInt(strPoolSize);
+ }
+
+ private void setMaxPoolSize()
+ {
+ String strPoolSize = (String) m_oConnectionProperties
+ .get(MAX_POOL_SIZE);
+ if (strPoolSize == null)
+ {
+ strPoolSize = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(
+ MAX_POOL_SIZE, DEFAULT_MAX_POOL_SIZE);
+ }
+ this.m_iMaxPoolSize = Integer.parseInt(strPoolSize);
+ }
+
+ private void setBlockingConnectionTime()
+ {
+ String strBlockTimeMillis = (String) m_oConnectionProperties
+ .get(BLOCKING_CONNECTION_TIME);
+ if (strBlockTimeMillis == null)
+ {
+ strBlockTimeMillis = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(BLOCKING_CONNECTION_TIME,
+ DEFAULT_CONN_BLOCK_TIME_MILLIS);
+ }
+ this.m_lConnBlockTime = Integer.parseInt(strBlockTimeMillis);
+ }
+
+ protected long getConnectionBlockTimeInMillis()
+ {
+ return m_lConnBlockTime;
+ }
+
+ private void setAutoCommit()
+ {
+ String autoCommit = (String) m_oConnectionProperties.get(AUTO_COMMIT);
+ if (autoCommit == null || autoCommit.equals("false"))
+ {
+ m_bAutoCommit = Boolean.FALSE;
+ } else
+ {
+ m_bAutoCommit = Boolean.TRUE;
+ }
+ }
+
+ private void setConnectionPoolClass()
+ {
+ m_sConnectionPoolClass = m_oConnectionProperties
+ .getProperty(CONNECTION_POOL_CLASS);
+ if (m_sConnectionPoolClass == null)
+ {
+ m_sConnectionPoolClass = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(CONNECTION_POOL_CLASS,
+ DEFAULT_CONNECTION_POOL_CLASS);
+ }
+ }
+
+ protected String getUser()
+ {
+ return m_sUser;
+ }
+
+ public void setUser()
+ {
+ this.m_sUser = m_oConnectionProperties.getProperty(USERNAME);
+ if (m_sUser == null)
+ {
+ m_sUser = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(USERNAME);
+ }
+ }
+
+ protected String getPassword()
+ {
+ return m_sPassword;
+ }
+
+ protected void setPassword()
+ {
+ this.m_sPassword = m_oConnectionProperties.getProperty(PASSWORD);
+ if (m_sPassword == null)
+ {
+ m_sPassword = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(
+ PASSWORD);
+ }
+ String strPasswordDecoder = m_oConnectionProperties
+ .getProperty(PASSWORD_DECODER);
+ if (strPasswordDecoder == null)
+ {
+ strPasswordDecoder = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(PASSWORD_DECODER);
+ }
+ if (strPasswordDecoder != null)
+ {
+ try
+ {
+ PasswordDecoder decoder = (PasswordDecoder) Class.forName(
+ strPasswordDecoder).newInstance();
+ this.m_sPassword = decoder.decode(m_sPassword);
+ } catch (InstantiationException e)
+ {
+ Log.error(
+ "Error in creating instance of Password Decoder Class:-"
+ + strPasswordDecoder, e);
+ } catch (IllegalAccessException e)
+ {
+ Log.error(
+ "Error in creating instance of Password Decoder Class:-"
+ + strPasswordDecoder, e);
+ } catch (ClassNotFoundException e)
+ {
+ Log.error("Password Decoder Class:-" + strPasswordDecoder
+ + " not found in Classpath");
+ Log.error("Please check the property:-" + PASSWORD_DECODER);
+ Log.error(e);
+ }
+ }
+ }
+
+ protected String getConnectionPoolClass()
+ {
+ return m_sConnectionPoolClass;
+ }
+
+ private void setAbandonedConnectionTimeOut()
+ {
+ String strAbandonedConnectionTimeout = m_oConnectionProperties
+ .getProperty(ABANDONED_CONNECTION_TIMEOUT);
+ if (strAbandonedConnectionTimeout == null)
+ {
+ strAbandonedConnectionTimeout = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(ABANDONED_CONNECTION_TIMEOUT,
+ DEFAULT_ABANDONED_CONNECTION_TIMEOUT);
+ }
+ this.m_lAbandonedConnectionTimeout = Long
+ .parseLong(strAbandonedConnectionTimeout);
+ }
+
+ private void setAbandonedConnectionCheckInterval()
+ {
+ String strAbandonedConnectionCheckInterval = m_oConnectionProperties
+ .getProperty(ABANDONED_CONNECTION_CHECK_INTERVAL);
+ if (strAbandonedConnectionCheckInterval == null
+ || strAbandonedConnectionCheckInterval.trim().length() == 0)
+ {
+ strAbandonedConnectionCheckInterval = ModulePropertyManager
+ .getPropertyManager(ModulePropertyManager.CONNECTION_MODULE).getProperty(
+ ABANDONED_CONNECTION_CHECK_INTERVAL,
+ DEFAULT_ABANDONED_CONNECTION_CHECK_INTERVAL);
+ }
+ this.m_lAbandonedConnectionCheckInterval = Long
+ .parseLong(strAbandonedConnectionCheckInterval);
+ }
+
+ protected long getAbandonedConnectionTimeOut()
+ {
+ return this.m_lAbandonedConnectionTimeout;
+ }
+
+ protected long getAbandonedConnectionCheckInterval()
+ {
+ return this.m_lAbandonedConnectionCheckInterval;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionWrapper.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionWrapper.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/ConnectionWrapper.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,326 @@
+/*
+* 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.connection;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Savepoint;
+import java.sql.Statement;
+import java.util.Map;
+
+/**
+ * Wrapper class which encapsulates @link Connection
+ * @author MohitK
+ * Date: Jul 18, 2006
+ */
+public class ConnectionWrapper implements Connection {
+
+ private Connection _originalHeavyConnection;
+ private ConnectionPool _connectionPool;
+ private boolean _isClosed = false;
+ private long _activatedTime;
+
+ public ConnectionWrapper(Connection originalHeavyConnection, ConnectionPool pool) throws SQLException {
+ if (originalHeavyConnection == null) {
+ throw new SQLException("Original Connection is Null");
+ }
+ this._originalHeavyConnection = originalHeavyConnection;
+ if (pool == null) {
+ throw new SQLException("Connection Pool is null");
+ }
+ this._connectionPool = pool;
+ }
+
+ public Statement createStatement() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.createStatement();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public PreparedStatement prepareStatement(String sql) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareStatement(sql);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareCall(sql);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public String nativeSQL(String sql) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.nativeSQL(sql);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.setAutoCommit(autoCommit);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+
+ }
+
+ public boolean getAutoCommit() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.getAutoCommit();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void commit() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.commit();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void rollback() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.rollback();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public synchronized void close() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _connectionPool.closeConnection(this);
+ }
+ this._isClosed = true;
+ }
+
+ public boolean isClosed() throws SQLException {
+ return _isClosed;
+ }
+
+ public DatabaseMetaData getMetaData() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.getMetaData();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void setReadOnly(boolean readOnly) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.setReadOnly(readOnly);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public boolean isReadOnly() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.isReadOnly();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void setCatalog(String catalog) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.setCatalog(catalog);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public String getCatalog() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.getCatalog();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void setTransactionIsolation(int level) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.setTransactionIsolation(level);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public int getTransactionIsolation() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.getTransactionIsolation();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public SQLWarning getWarnings() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.getWarnings();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void clearWarnings() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.clearWarnings();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.createStatement(resultSetType, resultSetConcurrency);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareStatement(sql, resultSetType, resultSetConcurrency);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareCall(sql, resultSetType, resultSetConcurrency);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public Map<String, Class<?>> getTypeMap() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.getTypeMap();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.setTypeMap(map);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void setHoldability(int holdability) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.setHoldability(holdability);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public int getHoldability() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.getHoldability();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public Savepoint setSavepoint() throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.setSavepoint();
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public Savepoint setSavepoint(String name) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.setSavepoint(name);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void rollback(Savepoint savepoint) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.rollback(savepoint);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ _originalHeavyConnection.releaseSavepoint(savepoint);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareStatement(sql, autoGeneratedKeys);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareStatement(sql, columnIndexes);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ public PreparedStatement prepareStatement(String sql, String columnNames[]) throws SQLException {
+ if (_originalHeavyConnection != null) {
+ return _originalHeavyConnection.prepareStatement(sql, columnNames);
+ } else
+ throw new SQLException("Connection closed due to inactivity");
+ }
+
+ protected synchronized Connection getActualConnection() {
+ return _originalHeavyConnection;
+ }
+
+ protected long getActivatedTime() {
+ return _activatedTime;
+ }
+
+ protected void setActivatedTime(long activedTime) {
+ this._activatedTime = activedTime;
+ }
+
+ protected String getName() {
+ return _originalHeavyConnection.toString();
+ }
+
+ protected void setOriginalConnection(Connection conn) {
+ this._originalHeavyConnection = conn;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/DefaultConnectionPoolImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/DefaultConnectionPoolImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/DefaultConnectionPoolImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,201 @@
+/*
+* 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.connection;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Stack;
+import java.util.Timer;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.connection.exception.ConnectionException;
+
+/**
+ * Default connection pool implementation class when none is specified by the user in @link ConnectionProperties
+ *
+ * @author MohitK
+ * Date: Jul 18, 2006
+ */
+public class DefaultConnectionPoolImpl implements ConnectionPool {
+
+ private static Logger Log = Logger.getLogger(DefaultConnectionPoolImpl.class);
+
+ private final Stack<ConnectionWrapper> m_oConnectionStack = new Stack<ConnectionWrapper>();
+ private final ConcurrentHashMap<String, ConnectionWrapper> m_oUsedConnectionMap = new ConcurrentHashMap<String, ConnectionWrapper>();
+ private int m_iConnCountInPool;
+ private ConnectionProperties m_oConnProperties;
+ private ConnectionFactory m_oConnectionFactory;
+
+ /**
+ * @see ConnectionPool#createPool(ConnectionProperties)
+ */
+ public void createPool(ConnectionProperties prop) throws ConnectionException {
+ this.m_oConnProperties = prop;
+ try {
+ initPool();
+ AbandonedConnectionTimerTask abandonedConnTask = new AbandonedConnectionTimerTask(this);
+ Timer abandonedTimer = new Timer(":AbandonedConnectionPoolScheduler:@" + this.toString(), true);
+ abandonedTimer.schedule(abandonedConnTask, prop.getAbandonedConnectionCheckInterval(), prop.getAbandonedConnectionCheckInterval());
+ } catch (SQLException e) {
+ Log.error("DefaultConnectionPoolImpl: Error in creating Connection Pool",e);
+ throw new ConnectionException("DefaultConnectionPoolImpl: Error in creating Connection Pool\n Reason:-" + e.getMessage(), e);
+ }
+ }
+
+ private void initPool() throws SQLException {
+
+ if (m_oConnectionFactory == null) {
+ Properties properties = new Properties();
+ properties.put("user", m_oConnProperties.getUser());
+ properties.put("password", m_oConnProperties.getPassword());
+ m_oConnectionFactory = new DriverConnectionFactory(getDriver(m_oConnProperties.getDriverClassName()), m_oConnProperties.getConnectionUrl(), properties);
+ }
+ while (m_iConnCountInPool < m_oConnProperties.getMinPoolSize()) {
+ synchronized (m_oConnectionStack) {
+ m_oConnectionStack.add(new ConnectionWrapper(m_oConnectionFactory.createConnection(), this));
+ m_iConnCountInPool++;
+ }
+ }
+ }
+
+ private Driver getDriver(String driverClassName) throws SQLException {
+ if (driverClassName != null) {
+ try {
+ Class.forName(driverClassName);
+ } catch (Throwable e) {
+ Log.error("DefaultConnectionPoolImpl: Error in loading class " + driverClassName + " to create connection pool", e);
+ throw new SQLException("DefaultConnectionPoolImpl: Error in loading class " + driverClassName + " to create connection pool");
+ }
+ return DriverManager.getDriver(m_oConnProperties.getConnectionUrl());
+ }
+ throw new SQLException("DefaultConnectionPoolImpl: Driver Class could not be loaded");
+ }
+
+ /**
+ * @see ConnectionPool#getConnection()
+ */
+ public synchronized Connection getConnection() throws SQLException {
+ ConnectionWrapper newPoolConnection;
+ if (!m_oConnectionStack.isEmpty()) {
+ newPoolConnection = m_oConnectionStack.pop();
+ m_oUsedConnectionMap.put(newPoolConnection.getName(), newPoolConnection);
+ } else if (m_iConnCountInPool < m_oConnProperties.getMaxPoolSize()) {
+ newPoolConnection = new ConnectionWrapper(m_oConnectionFactory.createConnection(), this);
+ m_oUsedConnectionMap.put(newPoolConnection.getName(), newPoolConnection);
+ m_iConnCountInPool++;
+ } else {
+ try {
+ Thread.sleep(m_oConnProperties.getConnectionBlockTimeInMillis());
+ } catch (InterruptedException e) {
+ //Do Nothing
+ }
+ if (!m_oConnectionStack.empty()) {
+ newPoolConnection = m_oConnectionStack.pop();
+ m_oUsedConnectionMap.put(newPoolConnection.getName(), newPoolConnection);
+ } else {
+ throw new SQLException("Connection Pool exhausted. Please increase number of connections");
+ }
+
+ }
+ Integer isolation = m_oConnProperties.getIsolationLevel();
+ if (isolation != null) newPoolConnection.setTransactionIsolation(isolation);
+ newPoolConnection.setAutoCommit(m_oConnProperties.getAutoCommit());
+ newPoolConnection.setActivatedTime(System.currentTimeMillis());
+ return newPoolConnection;
+ }
+
+ /**
+ * @see ConnectionPool;
+ */
+ public void closeConnection(Connection connectionToClose) {
+ synchronized (m_oConnectionStack) {
+ m_oConnectionStack.push((ConnectionWrapper) connectionToClose);
+ }
+ m_oUsedConnectionMap.remove(connectionToClose);
+ }
+
+ /**
+ * @see ConnectionPool#releasePool()
+ */
+ public void releasePool() {
+ try {
+ synchronized (m_oConnectionStack) {
+ for (ConnectionWrapper connection : m_oConnectionStack) {
+ Connection origConn = connection.getActualConnection();
+ origConn.close();
+ m_iConnCountInPool--;
+ }
+ }
+ Enumeration<ConnectionWrapper> connectionWrapperEnum = m_oUsedConnectionMap.elements();
+ while (connectionWrapperEnum.hasMoreElements()) {
+ ConnectionWrapper connectionWrapper = connectionWrapperEnum.nextElement();
+ Connection con = connectionWrapper.getActualConnection();
+ String name = connectionWrapper.getName();
+ if (con != null && !con.isClosed()) {
+ con.close();
+ }
+ m_iConnCountInPool--;
+ m_oUsedConnectionMap.remove(name);
+ }
+ } catch (SQLException e) {
+ Log.error("DefaultConnectionPoolImpl: Error in closing physical Connection", e);
+ }
+ }
+
+ protected void finalize() throws Throwable {
+ super.finalize();
+ releasePool();
+ }
+
+ /**
+ * This method will release all abandoned connections from the pool.
+ */
+ protected synchronized void releaseAbandonedConnections() {
+
+ Enumeration<ConnectionWrapper> connectionWrapperEnum = m_oUsedConnectionMap.elements();
+ while (connectionWrapperEnum.hasMoreElements()) {
+ ConnectionWrapper connectionWrapper = connectionWrapperEnum.nextElement();
+ long activedTime = connectionWrapper.getActivatedTime();
+ long currentTime = System.currentTimeMillis();
+ if ((currentTime - activedTime) > m_oConnProperties.getAbandonedConnectionTimeOut()) {
+ try {
+ Log.info("Removing abandoned Connection:-" + connectionWrapper);
+ Connection actualConnection = connectionWrapper.getActualConnection();
+ m_oUsedConnectionMap.remove(connectionWrapper.getName());
+ connectionWrapper.setOriginalConnection(null);
+ connectionWrapper = null;
+ connectionWrapper = new ConnectionWrapper(actualConnection, this);
+ synchronized (m_oConnectionStack) {
+ m_oConnectionStack.push(connectionWrapper);
+ }
+ } catch (SQLException e) {
+ Log.error("Error in releasing abandoned connection from Pool", e);
+ }
+ }
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/DriverConnectionFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/DriverConnectionFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/DriverConnectionFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.connection;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * Driver implementation of Connection Factory
+ * @author MohitK
+ * Date: Jul 18, 2006
+ */
+public class DriverConnectionFactory implements ConnectionFactory{
+
+ private Driver _driver;
+ private String _driverUrl;
+ private Properties _properties;
+
+ public DriverConnectionFactory(Driver driver,String driverUrl,Properties connectionProps){
+ this._driver=driver;
+ this._driverUrl=driverUrl;
+ this._properties=connectionProps;
+
+ }
+
+ /**
+ *
+ * @see org.jboss.soa.esb.connection.ConnectionFactory#createConnection()
+ */
+ public Connection createConnection() throws SQLException {
+ return _driver.connect(_driverUrl,_properties);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/FreeConnectionPoolResources.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/FreeConnectionPoolResources.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/FreeConnectionPoolResources.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,52 @@
+/*
+* 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.connection;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Shutdown Hook into the JVM. The class will be invoked by the JVM when JVM is shutting down.
+ * Used to free connection resources and destroy the connection pool.
+ * This class is will guarantee closing of all connections rather than depending on finalize method.
+ *
+ * @author MohitK
+ * Date: Jul 22, 2006
+ */
+public class FreeConnectionPoolResources extends Thread {
+
+ private static Logger Log = Logger.getLogger(FreeConnectionPoolResources.class);
+
+ ConnectionPool pool;
+
+ public FreeConnectionPoolResources(ConnectionPool pool) {
+ this.pool = pool;
+ }
+
+ public void run() {
+ try {
+ pool.releasePool();
+ } catch (Exception e) {
+ Log.error("Error in freeing resources");
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/PasswordDecoder.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/PasswordDecoder.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/PasswordDecoder.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,39 @@
+/*
+* 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.connection;
+
+/**
+ * Interface to be implemented by classes when they need to return the DB password for the connection by using their own
+ * algorithm. Called by the connection pool
+ * @author MohitK
+ * Date: Jul 21, 2006
+ */
+public interface PasswordDecoder {
+ /**
+ * This method decodes the password for JDBC Connection, it will be called when setting JDBC connection properties.
+ * Users who need to decode the password need to implement this interface and write their own
+ * decoding logic to send the actual DB password. If this method returns null
+ * @param encodedPassword The encoded password sent by JDBC framework
+ * @return Decoded password.
+ */
+ public String decode(String encodedPassword);
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/PoolDataSource.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/PoolDataSource.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/PoolDataSource.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,118 @@
+/*
+* 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.connection;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.sql.DataSource;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.connection.exception.ConnectionException;
+
+/**
+ * Implementation if Datasource for getting connections from pool.
+ * @author MohitK
+ * Date: Jul 19, 2006
+ */
+public class PoolDataSource implements DataSource {
+
+ private static Logger Log = Logger.getLogger(PoolDataSource.class);
+
+ private ConnectionPool m_oPool;
+ private PrintWriter m_oLogWriter = new PrintWriter(System.out);
+ private int m_iLoginTimeOut;
+ private final Properties m_oConnProps = new Properties();
+ ConnectionProperties m_oConnectionProperties;
+
+ private synchronized ConnectionPool createConnectionPool() throws SQLException {
+ if (m_oPool == null) {
+ try {
+ if (m_oConnProps != null) {
+ m_oConnectionProperties = new ConnectionProperties(m_oConnProps);
+ m_oPool = ConnectionPoolFactory.createPool(m_oConnectionProperties);
+ }
+ } catch (ConnectionException e) {
+ Log.error("PoolDataSource: Error in creating Connection Pool",e);
+ throw new SQLException(e.getMessage());
+ }
+ }
+ return m_oPool;
+ }
+
+
+ public Properties getConnectionProperties() {
+ return m_oConnProps;
+ }
+
+ public void setConnectionProperties(Properties _connProperties) {
+ m_oConnProps.putAll(_connProperties);
+ }
+
+ /**
+ * @see javax.sql.DataSource#getConnection()
+ */
+ public Connection getConnection() throws SQLException {
+ return createConnectionPool().getConnection();
+ }
+
+ /**
+ * @see javax.sql.DataSource#getConnection(String, String)
+ */
+ public Connection getConnection(String username, String password) throws SQLException {
+ synchronized(m_oConnProps){
+ m_oConnProps.setProperty(ConnectionProperties.USERNAME, username);
+ m_oConnProps.setProperty(ConnectionProperties.PASSWORD, password);
+ }
+ // REVIEW: This class isn't thread safe at this point???
+ return createConnectionPool().getConnection();
+ }
+
+ /**
+ * @see javax.sql.DataSource#getLogWriter()
+ */
+ public PrintWriter getLogWriter() throws SQLException {
+ return this.m_oLogWriter;
+ }
+ /**
+ * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
+ */
+ public void setLogWriter(PrintWriter out) throws SQLException {
+ this.m_oLogWriter = out;
+ }
+ /**
+ * @see javax.sql.DataSource#setLoginTimeout(int)
+ */
+ public void setLoginTimeout(int seconds) throws SQLException {
+ this.m_iLoginTimeOut = seconds;
+ }
+
+ /**
+ * @see javax.sql.DataSource#getLoginTimeout()
+ */
+ public int getLoginTimeout() throws SQLException {
+ return m_iLoginTimeOut;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/exception/ConnectionException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/exception/ConnectionException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/connection/exception/ConnectionException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,50 @@
+/*
+* 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.connection.exception;
+
+/**
+ * This exception is thrown when Connection Pool fails to initialize
+ * @author MohitK
+ * Date: Jul 21, 2006
+ */
+public class ConnectionException extends Exception{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public ConnectionException() {
+ super();
+ }
+
+ public ConnectionException(String message) {
+ super(message);
+ }
+
+ public ConnectionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ConnectionException(Throwable cause) {
+ super(cause);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/AppServerContext.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/AppServerContext.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/AppServerContext.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,108 @@
+/*
+ * 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.helpers;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * Obtains JNDI naming context for a predefined list of 'well known' server
+ * types
+ *
+ */
+public abstract class AppServerContext {
+ /**
+ * Logger for this class
+ */
+ private static final Logger m_oLogger = Logger
+ .getLogger(AppServerContext.class);
+
+ /**
+ * Indicates that a jboss context is requested
+ */
+ public static final String CTX_JBOSS = "jboss";
+
+ public static final int MAX_RETRIES = 10;
+
+ public static final int WAIT_FOR_RETRY = 30;
+
+ public enum SERVER_TYPE {
+ jboss, weblogic, websphere, oracle
+ };
+
+ public static Context getServerContext(String pType, String p_sJndiServer) {
+ return getServerContext(SERVER_TYPE.valueOf(pType), p_sJndiServer);
+ }
+
+ // REVIEW: What is all this about... this class doesn't support anything other than a JBoss Server!!
+
+ /**
+ * Searches a predefined table of 'well known' app server types, and returns
+ * the corresponding naming context
+ *
+ * @param p_sServer:
+ * name or IP of server, and optionally port #
+ */
+ private static Context getServerContext(SERVER_TYPE pType,
+ String p_sJndiServer) {
+ switch (pType) {
+ case jboss:
+ return jbossContext(p_sJndiServer);
+ }
+
+ return null;
+ } // __________________________________
+
+ private static Context jbossContext(String p_sJndiServer) {
+ Properties oPr = new Properties();
+ oPr.setProperty(Context.PROVIDER_URL, p_sJndiServer);
+ oPr.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jnp.interfaces.NamingContextFactory");
+ oPr.setProperty(Context.URL_PKG_PREFIXES,
+ "org.jboss.naming:org.jnp.interfaces");
+
+ boolean bCtxOK = false;
+ Context oCtx = null;
+ for (int i1 = 0; (!bCtxOK) && i1 < MAX_RETRIES; i1++) {
+ // check if context is valid
+ try {
+ oCtx = new InitialContext(oPr);
+ oCtx.list("__dummy2@#$%");
+ bCtxOK = true;
+ } catch (NamingException nex) {
+ bCtxOK = true;
+ }
+ }
+ if (bCtxOK)
+ return oCtx;
+ m_oLogger.error("Can't connect to jndiServer <" + p_sJndiServer + ">");
+ return null;
+
+ } // ________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,553 @@
+package org.jboss.soa.esb.helpers;
+
+import java.util.*;
+import java.io.*;
+import org.apache.log4j.Logger;
+
+import javax.xml.parsers.*;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.*;
+import org.xml.sax.SAXException;
+/**
+ * Objects of this class are to be used for run time configuration of ESB components
+ * <p/> This should gradually replace the ConfigTree class
+ * <br/> It is a subset of Tree that accepts a Map of attributes, and a List of children
+ * <br/> children can only be String values, or objects of this class
+ * <p/> fromXml() and toXml() methods allow 'visible' representations of objects of this class
+ * and run time loading/dumping from/to standard XML documents
+ *
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ *
+ */
+public class ConfigTree implements Serializable, Cloneable
+{
+ private static final long serialVersionUID = 1L;
+/**
+ * Constructor of a root node (an uppermost ConfigTree)
+ * @param name String - the element name of 'this'
+ */
+ public ConfigTree(String name) { this(name,null); }
+/**
+ * Constructor of a ConfigTree as a child of another (second arg)
+ * @param name String - element name of 'this'
+ * @param dad ConfigTree - whom 'this' will be hanging from
+ */
+ public ConfigTree(String name, ConfigTree dad)
+ {
+ setName(name);
+ setParent(dad);
+ } // _______________________________
+/**
+ * protected constructor
+ * @param other - Where to get values for deep copy
+ */
+ protected ConfigTree(ConfigTree other)
+ {
+ copyFrom(other);
+ } // _______________________________
+
+ /**
+ *
+ * @return String - the name of this tree (element name for XML representation)
+ */
+ public String getName() { return _name; }
+ /**
+ * assign a name to 'this'
+ * @param name String - The name for this object
+ */
+ public void setName(String name)
+ {
+ if (null==name)
+ throw new IllegalArgumentException();
+ _name = name;
+ } // _______________________________
+
+ /**
+ * whose child is 'this' (null if root)
+ * @return ConfigTree - the parent tree of 'this'
+ */
+ public ConfigTree getParent() { return _dad; }
+
+ private void setParent(ConfigTree dad)
+ {
+ if (null!=_dad && null!=_dad._childs)
+ _dad._childs.remove(this);
+ if (null!=dad)
+ dad.addChild(this);
+ }
+ /**
+ * assign a value to a named attribute
+ * @param name String - the name (key) for the new attribute
+ * @param value String - the value assigned to the key (if null - old value will be deleted)
+ * @return String - old value assigned to the name (null if there was none)
+ */
+ public String setAttribute(String name,String value)
+ {
+ if (null==name)
+ throw new IllegalArgumentException("Attribute name must be non null");
+ if (null==_attributes)
+ _attributes = new HashMap<String,String>();
+ String oldVal = _attributes.remove(name);
+ if(null!=value)
+ _attributes.put(name,value);
+ return oldVal;
+ } // _______________________________
+ /**
+ *
+ * @return int - the number of non null attributes that this node has been assigned
+ */
+ public int attributeCount()
+ {
+ return (null==_attributes) ? 0 : _attributes.size();
+ } // _______________________________
+ /**
+ * retrieve the value assigned to an attribute key
+ * @param name String - the search key
+ * @return String - the value assigned to the specified key
+ */
+ public String getAttribute(String name)
+ {
+ return (null==_attributes) ? null : _attributes.get(name);
+ } // _______________________________
+ /**
+ * obtain the list of all attribute names
+ * @return Set<String> - the set of keys that have been assigned a non null value
+ */
+ public Set<String>getAttributeNames()
+ { return (null==_attributes)
+ ? new HashSet<String>()
+ : _attributes.keySet();
+ } // _______________________________
+ /**
+ * obtain the list of all attribute as a List<KeyValuePair>
+ * @return List<KeyValuePair> - containing all attributes
+ */
+ public List<KeyValuePair> attributesAsList()
+ {
+ List<KeyValuePair> oRet = new ArrayList<KeyValuePair>();
+ if (null!=_attributes)
+ for (Map.Entry<String,String> oCurr : _attributes.entrySet())
+ oRet.add(new KeyValuePair(oCurr.getKey(),oCurr.getValue()));
+ return oRet;
+ } // _______________________________
+ /**
+ * concatenated values of all child String values that have been added to 'this'
+ * <br/>"" (zero length String) if no String child nodes
+ * @return String - concatenation of all String segments (equivalent to xml text nodes)
+ */
+ public String getWholeText()
+ {
+ if (null==_childs)
+ return "";
+ StringBuilder sb = null;
+ for (Child child : _childs)
+ { if (! (child._obj instanceof String))
+ continue;
+ if (null==sb)
+ sb = new StringBuilder((String)child._obj);
+ else
+ sb.append((String)child._obj);
+ }
+ return sb.toString();
+
+ } // _______________________________
+/**
+ * <b>first</b> child containing only text, with name=arg0
+ * @param name String - the name to filter
+ * @return full text content of first 'pure text' child element under that name - <null> if none
+ */
+ public String getFirstTextChild(String name)
+ {
+ if (null==name)
+ throw new IllegalArgumentException();
+ if (null!=_childs)
+ for (Child oCurr : _childs)
+ {
+ ConfigTree tree = oCurr.getTree();
+ if (null != tree && tree.isPureText() && name.equals(tree.getName()))
+ return tree.getWholeText();
+ }
+ return null;
+ } // _______________________________
+
+ /**
+ * Obtain all String values with the same name
+ * @param name String - filter for child String nodes
+ * @return String[]
+ */
+ public String[] getTextChildren(String name)
+ {
+ if (null==name)
+ throw new IllegalArgumentException();
+ if (null==_childs)
+ return new String[0];
+ List<String>oRet = new ArrayList<String>();
+ for (Child oCurr : _childs)
+ {
+ ConfigTree tree = oCurr.getTree();
+ if (null != tree && tree.isPureText() && name.equals(tree.getName()))
+ oRet.add(tree.getWholeText());
+ }
+ return oRet.toArray(new String[oRet.size()]);
+ } // _______________________________
+/**
+ * add a child element that consists only of the text in arg0
+ * @param value String - the text to assign to the added child node
+ */
+ public void addTextChild (String value) { new Child(value); }
+
+ private void addChild(ConfigTree child)
+ { child._dad = this; new Child(child); }
+/**
+ * retrieve list of child elements of 'this' that are instances of ConfigTree
+ * @return ConfigTree[] - Array containing all child elements of class ConfigTree
+ */
+ public ConfigTree[] getAllChildren()
+ {
+ if (null==_childs)
+ return new ConfigTree[]{};
+ List<ConfigTree>oRet = new ArrayList<ConfigTree>();
+ for (Child oCurr : _childs)
+ if (null != oCurr.getTree())
+ oRet.add(oCurr.getTree());
+ return oRet.toArray(new ConfigTree[oRet.size()]);
+ } // _______________________________
+
+ /**
+ * list of child elements of 'this' that are instances of ConfigTree, with name = arg0
+ * @param name String - the name of child nodes to filter
+ * @return ConfigTree[] - child elements of class ConfigTree with name provided
+ */
+ public ConfigTree[] getChildren(String name)
+ {
+ if (null==name)
+ throw new IllegalArgumentException();
+ if (null==_childs)
+ return new ConfigTree[0];
+ List<ConfigTree>oRet = new ArrayList<ConfigTree>();
+ for (Child oCurr : _childs)
+ if (name.equals(oCurr.getName()))
+ oRet.add(oCurr.getTree());
+ return oRet.toArray(new ConfigTree[oRet.size()]);
+ } // _______________________________
+/**
+ * <b>first</b> child of class ConfigTree with name=arg0
+ * @param name String - the name to filter
+ * @return first child element under that name - <null> if none
+ */
+ public ConfigTree getFirstChild(String name)
+ {
+ if (null==name)
+ throw new IllegalArgumentException();
+ if (null!=_childs)
+ for (Child oCurr : _childs)
+ if (name.equals(oCurr.getName()))
+ return oCurr.getTree();
+ return null;
+ } // _______________________________
+/**
+ * purge the list of children
+ */
+ public void removeAllChildren()
+ {
+ _childs = null;
+ } // _______________________________
+
+ /**
+ * remove children by name
+ * @param name String - only children by that name will be removed
+ */
+ public void removeChildrenByName(String name)
+ {
+ if (null==name)
+ throw new IllegalArgumentException();
+ if (null!=_childs)
+ for (ListIterator<Child> II=_childs.listIterator(); II.hasNext();)
+ if (name.equals(II.next().getName()))
+ II.remove();
+ } // __________________________________
+
+ /**
+ *
+ * @return the number of child nodes (of any type)
+ */
+ public int childCount()
+ {
+ return (null==_childs) ? 0 : _childs.size();
+ } // __________________________________
+
+ @Override
+ public Object clone() { return cloneObj(); }
+
+ /**
+ * instantiate a new ConfigTree with the same topology and contents of 'this'
+ * <br/>Contained ConfigTree child elements will also be cloned
+ * <br/>Transient objects are NOT copied nor cloned
+ * @return ConfigTree - Deep copy of 'this'
+ */
+ public ConfigTree cloneObj() {return cloneSubtree(null); }
+
+ /**
+ * @return ConfigTree - Deep copy of 'this'
+ */
+ private ConfigTree cloneSubtree(ConfigTree dad)
+ {
+ ConfigTree oRet = new ConfigTree(_name, dad);
+ if (null!=_attributes)
+ for (Map.Entry<String,String> oAtt: _attributes.entrySet())
+ oRet.setAttribute(oAtt.getKey(),oAtt.getValue());
+ if (null!= _childs)
+ for (Child oChild : _childs)
+ {
+ ConfigTree tree = oChild.getTree();
+ if (null!=tree)
+ tree.cloneSubtree(oRet);
+ else
+ oRet.addTextChild(oChild._obj.toString());
+ }
+ return oRet;
+ } // __________________________________
+ /**
+ * Deep copy of other tree
+ * @param other - from where to copy values
+ */
+ protected void copyFrom(ConfigTree other)
+ {
+ this.setName(other.getName());
+ this._pureText = other._pureText;
+
+ if (null != other._attributes)
+ for (Map.Entry<String,String> oneAtt : other._attributes.entrySet())
+ setAttribute(oneAtt.getKey(),oneAtt.getValue());
+ if (null != other._childs)
+ for (Child child : other._childs)
+ new Child(child);
+
+ } // __________________________________
+/**
+ * obtain an instance of this class, from a 'normalized' xml format, with the default encoding
+ * <p/> the 'normalized' xml format is the output of the toXml() instance method
+ * @param xml String - what to parse
+ * @return ConfigTree - an object of this class
+ * @throws SAXException - if xml format is invalid
+ */
+ public static ConfigTree fromXml(String xml) throws SAXException
+ {
+ try { return fromXml(xml,java.nio.charset.Charset.defaultCharset().toString()); }
+ catch (UnsupportedEncodingException e)
+ {
+ // This can't happen
+ _logger.fatal("This should not happen",e);
+ return null;
+ }
+ } // __________________________________
+
+ /**
+ * obtain an instance of this class, from a 'normalized' xml format, with the encoding defined in arg1
+ * <p/> the 'normalized' xml format is the output of the toXml() instance method
+ * @param xml String - what to parse
+ * @param encoding String - The encoding of arg 0
+ * @return ConfigTree - an object of this class
+ * @throws SAXException - if xml format is invalid
+ */
+ public static ConfigTree fromXml(String xml, String encoding)
+ throws UnsupportedEncodingException, SAXException
+ {
+ if (null==xml)
+ throw new IllegalArgumentException("Xml source String is null");
+ try { return fromInputStream(new ByteArrayInputStream(xml.getBytes(encoding))); }
+ catch (IOException e)
+ {
+ _logger.fatal("This should NOT happen",e);
+ return null;
+ }
+ } // __________________________________
+
+ /**
+ * obtain an instance of this class, from a 'normalized' xml format contained in an input stream
+ * <p/> the 'normalized' xml format is the output of the toXml() instance method
+ * @param input InputStream - where to parse from
+ * @return ConfigTree - an object of this class
+ * @throws SAXException - if xml format is invalid
+ * @throws IOException - if an input/output error occurs
+ */
+ public static ConfigTree fromInputStream(InputStream input)
+ throws SAXException, IOException
+ {
+ if (null==input)
+ throw new IllegalArgumentException();
+ DocumentBuilder builder = null;
+ try { builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); }
+ catch (ParserConfigurationException e2)
+ { _logger.error("Problems with default Parser Configuration",e2);
+ return null;
+ }
+ Document oDoc = builder.parse(input);
+ oDoc.normalize();
+
+ return fromElement(oDoc.getDocumentElement());
+
+ } // __________________________________
+
+ private static ConfigTree fromElement(Element elem)
+ {
+ ConfigTree tree = new ConfigTree(elem.getNodeName());
+ NamedNodeMap NM = elem.getAttributes();
+ if (null!=NM)
+ for (int i1=0; i1<NM.getLength(); i1++)
+ {
+ Node node = NM.item(i1);
+ tree.setAttribute(node.getNodeName(),node.getNodeValue());
+ }
+ NodeList NL = elem.getChildNodes();
+ if (null!=NL)
+ for (int i1=0; i1<NL.getLength(); i1++)
+ {
+ Node node = NL.item(i1);
+ switch (node.getNodeType())
+ {
+ case Node.ELEMENT_NODE:
+ tree.addChild(ConfigTree.fromElement((Element)node));
+ break;
+ case Node.TEXT_NODE:
+ tree.addTextChild(node.getNodeValue());
+ break;
+ }
+ }
+
+ return tree;
+ } // __________________________________
+
+ private Element toElement(Document doc)
+ {
+ Element elem = doc.createElement(_name);
+ if (null!=_attributes)
+ for (Map.Entry<String,String> oAtt : _attributes.entrySet())
+ elem.setAttribute(oAtt.getKey(),oAtt.getValue());
+ if (null!=_childs)
+ for (Child child : _childs)
+ {
+ ConfigTree tree = child.getTree();
+ if (null!=tree)
+ elem.appendChild(tree.toElement(doc));
+ else
+ elem.appendChild(doc.createTextNode(child._obj.toString()));
+ }
+ return elem;
+ } // __________________________________
+ /**
+ * Equivalent to a call to toXml()
+ * @return String - a String with the 'standard' xml representation of 'this',
+ * using the default encoding
+ */
+ public String toString() { return toXml(); }
+ /**
+ * Equivalent to a call to toXml(encoding)
+ * @param encoding String -
+ * @return String - a String with the 'standard' xml representation of 'this',
+ * using the encoding specified in arg 0
+ */
+
+ public String toString(String encoding) { return toXml(encoding); }
+ /**
+ * @return String - a String with the 'standard' xml representation of 'this',
+ * using the default encoding
+ */
+ public String toXml()
+ {
+ return toXml(java.nio.charset.Charset.defaultCharset().toString());
+ } // __________________________________
+
+ /**
+ * Serialize this object - Transient objects are
+ * @param encoding String - String
+ * @return String - a String with the 'standard' xml representation of 'this',
+ * using encoding specified in arg0
+ */
+ public String toXml(String encoding)
+ {
+ Transformer transf = null;
+ try { transf = TransformerFactory.newInstance().newTransformer(); }
+ catch (TransformerConfigurationException e1)
+ { _logger.error("Cannot obtain transformer to render XML output",e1);
+ return null;
+ }
+ transf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,"yes");
+ transf.setOutputProperty(OutputKeys.INDENT, "no");
+ transf.setOutputProperty(OutputKeys.ENCODING, encoding);
+
+ DocumentBuilder builder = null;
+ try { builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); }
+ catch (ParserConfigurationException e2)
+ { _logger.error("Problems with default Parser Configuration",e2);
+ return null;
+ }
+ Document oDoc = builder.newDocument();
+ oDoc.appendChild(toElement(oDoc));
+ oDoc.normalize();
+ DOMSource src = new DOMSource(oDoc);
+
+ ByteArrayOutputStream oStrm = new ByteArrayOutputStream(5000);
+ StreamResult res = new StreamResult(oStrm);
+
+ try { transf.transform(src, res); }
+ catch (TransformerException e3)
+ { _logger.error("Problems with XML transformation",e3);
+ return null;
+ }
+
+ return oStrm.toString();
+ } // __________________________________
+
+ /**
+ *
+ * @return boolean - indicating if 'this' element has ONLY text children (and consequently no ConfigTree children)
+ */
+ public boolean isPureText() { return _pureText; }
+
+ private class Child
+ {
+ Object _obj;
+ ConfigTree getTree()
+ { return (_obj instanceof ConfigTree)? (ConfigTree) _obj : null;
+ }
+ String getName()
+ { return (_obj instanceof ConfigTree)? ((ConfigTree) _obj)._name : null;
+ }
+ private Child(ConfigTree obj) {addToDad(obj); _pureText = false;}
+ private Child(String obj) {addToDad(obj); }
+ private Child(Child other)
+ {
+ if (other._obj instanceof ConfigTree)
+ {
+ addToDad(((ConfigTree)other._obj).cloneObj());
+ _pureText = false;
+ return;
+ }
+ if (other._obj instanceof String)
+ {
+ addToDad((String)other._obj);
+ return;
+ }
+
+ }
+ private void addToDad(Object obj)
+ { if (null==_childs)
+ _childs = new ArrayList<Child>();
+ _obj = obj;
+ _childs.add(this);
+ }
+
+ }
+
+ private boolean _pureText=true;
+ private ConfigTree _dad;
+ private String _name;
+ private Map<String,String> _attributes;
+ private List<Child> _childs;
+
+ private static transient Logger _logger = Logger.getLogger(ConfigTree.class);
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/Email.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/Email.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/Email.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,439 @@
+/*
+ * 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.helpers;
+
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.mail.Address;
+import javax.mail.Authenticator;
+import javax.mail.BodyPart;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.PasswordAuthentication;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * Simplifies sending of e-mails with attachments from java.
+ * <p/>
+ * The message is sent via a subsequent call to the {@link #sendMessage()}
+ * method.
+ *
+ * <h3 id="p_oMessageParms">Message Parmeters</h3>
+ * The class constructor is supplied the following parameters via a
+ * {@link org.jboss.soa.esb.helpers.ConfigTree} instance:
+ * <ol>
+ * <li><b>FROM</b>: valid e-mail address</li>
+ * <li><b>SENDTO</b>: valid comma separated list of e-mail addresses</li>
+ * <li><b>SUBJECT</b>: free text that will appear as subject of the e-mail</li>
+ * <li><b>MESSAGE</b>: free text that will appear as contents of the e-mail</li>
+ * <li><b>ATTACH</b>: list (as Text children) of valid accessible filenames to
+ * attach to the e-mail</li>
+ * </ol>
+ * All parameters except 'ATTACH' are attributes of the ConfigTree argument. ATTACH
+ * parameters (attachments) are added as child ConfigTrees of the supplied
+ * ConfigTree.
+ *
+ * @author: Heuristica - Buenos Aires - Argentina
+ */
+public class Email {
+
+ /**
+ * Class logger.
+ */
+ private static Logger logger = Logger.getLogger(Email.class);
+ /**
+ * ConfigTree attribute : will be the contents of the From: field in the
+ * outgoing message
+ */
+ public static final String FROM = "from";
+
+ /**
+ * ConfigTree attribute : comma separated list of recipients
+ */
+ public static final String SENDTO = "sendTo";
+
+ /**
+ * ConfigTree attribute : comma separated list of Copy recipients
+ */
+ public static final String COPYTO = "ccTo";
+
+ /**
+ * ConfigTree attribute : will be the contents of the Subject: field in the
+ * outgoing message
+ */
+ public static final String SUBJECT = "subject";
+
+ /**
+ * ConfigTree attribute : Value of this attribute will be the content of the
+ * e-mail's text
+ */
+ public static final String ATTACH = "attachment";
+
+ /**
+ * ConfigTree child Text elements : Each child represents the name of a file
+ * to be attached in the outgoing message
+ */
+ public static final String MESSAGE = "message";
+
+ /**
+ * will be the contents of the From: field in the outgoing message
+ */
+ private String from = null;
+
+ /**
+ * comma separated list of recipients
+ */
+ private String sendTo = null;
+
+ /**
+ * comma separated list of copy recipients
+ */
+ private String copyTo = null;
+
+ /**
+ * This attribute will be the content of the subject of the mail message
+ */
+ private String subject = null;
+
+ /**
+ * Comma separated list of attachment file names
+ */
+ private String[] attachments = null;
+
+ /**
+ * Value of this attribute will be the content of the e-mail's text
+ */
+ private String message = null;
+
+ /**
+ * The message to b sent via a subsequent call to {@link #sendMessage()}.
+ */
+ private MimeMessage mailMessage;
+
+ /**
+ * The mail Session to use
+ */
+ private Session oMailSess = null;
+
+ /**
+ * Public constructor.
+ * <p/>
+ * Initialises the mail server session and creates the mail message using
+ * the information provided in the p_oMessageParms
+ * <a href="p_oMessageParms">listed above</a>.
+ * <p/>
+ * The message is sent via a subsequent call to the {@link #sendMessage()}
+ * method.
+ *
+ * @param p_oMessageParms
+ * A ConfigTree object containing the elements mentioned above
+ * @throws MessagingException
+ * @throws AddressException
+ * @see ConfigTree
+ *
+ */
+ public Email() throws AddressException, MessagingException {
+ // REVIEW: How about typing the parameters a little better??? Looks as though that might have a huge ripple-on effect accross the codebase!!
+ // REVIEW: Does the session need to ne initialised every time???
+ this.oMailSess = initMailServerSession();
+
+ // Message can be "sent" via a subsequent call to the sendMessage method!
+ } // __________________________________
+
+ /**
+ * Send the mail message associated with this instance.
+ * @throws MessagingException Unable to transport the message associated with this
+ * Email instance.
+ */
+ public void sendMessage() throws MessagingException {
+ Transport.send(this.getMailMessage());
+ }
+
+ /**
+ * Get the {@link MimeMessage mail message} associated with this EsbMail
+ * instance.
+ * @return The mailMessage property value.
+ */
+ public MimeMessage getMailMessage() throws MessagingException {
+ if (this.mailMessage == null){
+ this.mailMessage = this.createMailMessage(this.oMailSess);
+ }
+ return mailMessage;
+ }
+
+ /**
+ * @return Returns the attachments.
+ */
+ public String[] getAttachments() {
+ return this.attachments;
+ }
+
+ /**
+ * @param attachments The attachments to set.
+ */
+ public void setAttachments(String[] attachments) {
+ this.attachments = attachments;
+ }
+
+ /**
+ * @return Returns the copyTo.
+ */
+ public String getCopyTo() {
+ return this.copyTo;
+ }
+
+ /**
+ * @param copyTo The copyTo to set.
+ */
+ public void setCopyTo(String copyTo) {
+ this.copyTo = copyTo;
+ }
+
+ /**
+ * @return Returns the from.
+ */
+ public String getFrom() {
+ return this.from;
+ }
+
+ /**
+ * @param from The from to set.
+ */
+ public void setFrom(String from) {
+ this.from = from;
+ }
+
+ /**
+ * @return Returns the sendTo.
+ */
+ public String getSendTo() {
+ return this.sendTo;
+ }
+
+ /**
+ * @param sendTo The sendTo to set.
+ */
+ public void setSendTo(String sendTo) {
+ this.sendTo = sendTo;
+ }
+
+ /**
+ * @return Returns the subject.
+ */
+ public String getSubject() {
+ return this.subject;
+ }
+
+ /**
+ * @param subject The subject to set.
+ */
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ /**
+ * @return Returns the message.
+ */
+ public String getMessage() {
+ return this.message;
+ }
+
+ /**
+ * @param message The message to set.
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
+ * Create the mail message instance to be {@link #sendMessage() sent}.
+ * @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
+ * @param oMailSess Mail session on which the message is to be transported.
+ * @return The message.
+ * @throws AddressException
+ * @throws MessagingException
+ */
+ private MimeMessage createMailMessage(Session oMailSess) throws AddressException, MessagingException {
+ MimeMessage oMessage = new MimeMessage(oMailSess);
+
+ // Populate the message with the data supplied in the p_oMessageParms ConfigTree.
+ addMessageAddressing(oMessage);
+ addMessageSubject( oMessage);
+ addMessageContent(oMessage);
+
+ return oMessage;
+ }
+
+ /**
+ * Add the message addressing information to the message.
+ * @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
+ * @param oMessage The message.
+ * @throws AddressException
+ * @throws MessagingException
+ */
+ private void addMessageAddressing(MimeMessage oMessage) throws AddressException, MessagingException {
+ InternetAddress oFrom = new InternetAddress(this.from);
+
+ oMessage.setFrom(oFrom);
+ oMessage.setReplyTo(new Address[] { oFrom });
+ InternetAddress[] oaTo =
+ InternetAddress.parse(this.sendTo);
+
+ for (int i1 = 0; i1 < oaTo.length; i1++) {
+ oMessage.addRecipient(MimeMessage.RecipientType.TO, oaTo[i1]);
+ }
+
+ if (null != this.copyTo) {
+ oaTo = InternetAddress.parse(this.copyTo);
+ for (int i1 = 0; i1 < oaTo.length; i1++) {
+ oMessage.addRecipient(MimeMessage.RecipientType.CC, oaTo[i1]);
+ }
+ }
+ }
+
+ /**
+ * Add the message Subject to the message.
+ * @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
+ * @param oMessage The message.
+ * @throws MessagingException
+ */
+ private void addMessageSubject(MimeMessage oMessage) throws MessagingException {
+ if (null != this.subject) {
+ oMessage.setSubject(this.subject);
+ }
+ }
+
+ /**
+ * Add the message content (body, attachments etc) to from the
+ * message parameters to the message.
+ * @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
+ * @param oMessage The message.
+ * @throws MessagingException
+ */
+ private void addMessageContent(MimeMessage oMessage) throws MessagingException {
+ BodyPart oBodyP = new MimeBodyPart();
+ Multipart oMultiP = new MimeMultipart();
+
+ oMultiP.addBodyPart(oBodyP);
+ oMessage.setContent(oMultiP);
+ if (null == this.message) {
+ this.message = "";
+ }
+ oBodyP.setText(this.message + "\n");
+
+
+ if (null != attachments) {
+ for (int i1 = 0; i1 < this.attachments.length; i1++) {
+ oMultiP.addBodyPart(oBodyP = new MimeBodyPart());
+ String sFile = this.attachments[i1];
+ oBodyP.setDataHandler(new DataHandler(new FileDataSource(sFile)));
+ oBodyP.setFileName(sFile.substring(1 + sFile.lastIndexOf("\\")));
+ }
+ }
+ }
+
+ /**
+ * Initialise an authenticated {@link javax.mail.Session} with the mail server.
+ * @return The {@link javax.mail.Session}.
+ */
+ private Session initMailServerSession() {
+ Authenticator oAuth = null;
+ String sSmtpUser = Configuration.getSmtpUsername();
+
+ if (! Util.isNullString(sSmtpUser)) {
+ oAuth = new MyAuth(sSmtpUser, Configuration.getSmtpPassword());
+ }
+
+ Properties oMailP = new Properties();
+ oMailP.setProperty("mail.smtp.host", Configuration.getSmtpHost());
+ String sAuth = Configuration.getSmtpAuth();
+ if(sAuth != null) {
+ if(!sAuth.trim().equals("")) {
+ logger.warn("'" + Environment.SMTP_AUTH + "' set to an empty value.");
+ }
+ oMailP.setProperty("mail.smtp.auth", sAuth);
+ }
+
+ try {
+ String sPort = Configuration.getSmtpPort();
+ this.from = Configuration.getSmtpFrom();
+ Integer.parseInt(sPort);
+ oMailP.setProperty("mail.smtp.port", sPort);
+ }
+ catch (Exception e) { /* OK just leave standard port */ }
+
+ logger.info("Initialising mail server sesson. Properties: " + oMailP);
+ javax.mail.Session oMailSess = javax.mail.Session.getDefaultInstance(oMailP, oAuth);
+
+ return oMailSess;
+ }
+
+ /**
+ * Method parsing filename from a string containing a comma separated list of filenames
+ * @param attachments the string containing the comma separated list of filenames
+ * @return a String array containing an entry for every filename in the given comma separated list
+ */
+ @SuppressWarnings("unused")
+ private String[] getFileNamesAsArray(String attachments) {
+ if (attachments.indexOf(',') != -1){
+ StringTokenizer st = new StringTokenizer(attachments,",");
+ String[] attachmentFileNames = new String[st.countTokens()];
+ int index = 0;
+ while (st.hasMoreTokens()) {
+ attachmentFileNames[index] = st.nextToken();
+ index++;
+ }
+ return attachmentFileNames;
+ }
+ return new String[]{attachments};
+ }
+
+ private class MyAuth extends Authenticator {
+ private String m_sUser, m_sPwd;
+
+ private MyAuth(String p_sU, String p_sP) {
+ m_sUser = p_sU;
+ m_sPwd = p_sP;
+ }
+
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(m_sUser, m_sPwd);
+ } // ________________________________
+ } // ______________________________________________________
+
+} // ____________________________________________________________________________
+
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/KeyValuePair.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/KeyValuePair.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/KeyValuePair.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,163 @@
+/*
+ * 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.helpers;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class KeyValuePair implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String mKey, mVal;
+
+ public KeyValuePair(String pKey, String pVal) {
+ if(pKey == null || pKey.trim().equals("")) {
+ throw new IllegalArgumentException("null or empty 'pKey' arg in call.");
+ }
+
+ mKey = pKey;
+ mVal = pVal;
+ }
+
+ public String getKey() {
+ return mKey;
+ }
+
+ public String getValue() {
+ return mVal;
+ }
+
+ public String toString() {
+ return mVal;
+ }
+
+ public String dump() {
+ return "KVpair[" + mKey + "=" + mVal + "]";
+ }
+
+ /**
+ * Get the value associated with the specified key from the supplied list of Key Value Pairs.
+ * <p/>
+ * Returns the value from the first matching key.
+ * @param key The key to search for.
+ * @param list The list of KeyValuePairs to search.
+ * @return The value associated with the supplied key, or null if key not found.
+ */
+ public static String getValue(String key, List<KeyValuePair> list) {
+ if(key == null) {
+ throw new IllegalArgumentException("null 'key' arg in call.");
+ }
+ if(list == null) {
+ throw new IllegalArgumentException("null 'list' arg in call.");
+ }
+
+ for(KeyValuePair kvp : list) {
+ if(kvp.mKey.equals(key)) {
+ return kvp.mVal;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Get the value associated with the specified key from the supplied list of Key Value Pairs.
+ * <p/>
+ * Returns the value from the first matching key.
+ * @param key The key to search for.
+ * @param list The list of KeyValuePairs to search.
+ * @param defaultVal The default value to be returned where there's no value available for the specified key.
+ * @return The value associated with the supplied key, or null if key not found.
+ */
+ public static String getValue(String key, List<KeyValuePair> list, String defaultVal) {
+ String value = getValue(key, list);
+
+ if(value == null) {
+ return defaultVal;
+ }
+
+ return value;
+ }
+
+ /**
+ * Get the boolean equivalent value associated with the specified key
+ * from the supplied list of Key Value Pairs.
+ * <p/>
+ * Returns:
+ * <ul>
+ * <li><b><code>true</code></b>: If value equals "true" or "yes" or "y" (ignoring case).</li>
+ * <li><b><code>false</code></b>: If value equals "false" or "no" or "n" (ignoring case).</li>
+ * <li><b><i>defaultVal</i></b>: If none of the above hold true.</li>
+ * </ul>
+ * <p/>
+ * Returns the value from the first matching key.
+ * @param key The key to search for.
+ * @param list The list of KeyValuePairs to search.
+ * @param defaultVal The default value to be returned where the above listed conditions do not hold
+ * for the associated value, or the value is not specified.
+ * @return The boolean equivalent value associated with the specified key according to the above specified
+ * rules, otherwise the <b><i>defaultVal</i></b> is returned.
+ */
+ public static boolean getBooleanValue(String key, List<KeyValuePair> list, boolean defaultVal) {
+ String value = getValue(key, list);
+
+ if(value == null) {
+ return defaultVal;
+ }
+
+ if(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("y") || value.equalsIgnoreCase("yes")) {
+ return true;
+ } else if(value.equalsIgnoreCase("false") || value.equalsIgnoreCase("n") || value.equalsIgnoreCase("no")) {
+ return false;
+ } else {
+ return defaultVal;
+ }
+ }
+
+ /**
+ * Get the numeric <code>double</code> equivalent value associated with the specified key
+ * from the supplied list of Key Value Pairs.
+ * <p/>
+ * Returns the value from the first matching key.
+ * @param key The key to search for.
+ * @param list The list of KeyValuePairs to search.
+ * @param defaultVal The default value to be returned where the value is not found or is non-numeric.
+ * @return The <code>double</code> equivalent value associated with the specified key if the value is found
+ * and is numeric, otherwise the <b><i>defaultVal</i></b> is returned.
+ */
+ public static double getDoubleValue(String key, List<KeyValuePair> list, double defaultVal) {
+ String value = getValue(key, list);
+
+ if(value == null) {
+ return defaultVal;
+ }
+
+ try {
+ return Double.parseDouble(value);
+ } catch(NumberFormatException e) {
+ // return the default...
+ }
+
+ return defaultVal;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,177 @@
+/*
+ * 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.helpers.persist;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import org.apache.log4j.Logger;
+
+public class JdbcCleanConn {
+ private DataSource m_oDS = null;
+
+ private Connection m_conn = null;
+
+ protected List<PreparedStatement> m_olPrepSt = new ArrayList<PreparedStatement>();
+
+ protected Logger m_oLogger;
+
+ public JdbcCleanConn(DataSource p_oDS) throws Exception {
+ m_oDS = p_oDS;
+ m_oLogger = Logger.getLogger(this.getClass());
+ }
+
+ public void commit() throws Exception {
+ if (null != m_conn) {
+ m_conn.commit();
+ }
+ }
+
+ public void rollback() throws Exception {
+ if (null != m_conn) {
+ m_conn.rollback();
+ }
+ }
+
+ public void release() {
+ if (null != m_conn) {
+ try {
+ m_conn.rollback();
+ } catch (Exception eRoll) {
+ }
+
+ for (PreparedStatement PS : m_olPrepSt)
+ try {
+ PS.close();
+ } catch (Exception e) {
+ }
+ try {
+ m_conn.close();
+ } catch (Exception e1) {
+ }
+ }
+ m_olPrepSt.clear();
+ m_conn = null;
+ } // __________________________________
+
+ public PreparedStatement prepareStatement(String p_sSt, int p_i1, int p_i2)
+ throws Exception {
+ if (null == m_conn) {
+ connect();
+ }
+ PreparedStatement PS = m_conn.prepareStatement(p_sSt, p_i1, p_i2);
+ m_olPrepSt.add(PS);
+ return PS;
+ } // __________________________________
+
+ public PreparedStatement prepareStatement(String p_sSt) throws Exception {
+ if (null == m_conn) {
+ connect();
+ }
+
+ PreparedStatement PS = m_conn.prepareStatement(p_sSt);
+ m_olPrepSt.add(PS);
+ return PS;
+ } // __________________________________
+
+ public ResultSet execQueryWait(PreparedStatement p_PS, int p_iQtry) throws Exception {
+ if (null == m_conn) {
+ connect();
+ }
+
+ Exception eRet = null;
+ int iQtry = (p_iQtry < 1) ? 1 : (p_iQtry < 50) ? p_iQtry : 50;
+ for (int i1 = 0; i1 < iQtry; i1++) {
+ try {
+ return p_PS.executeQuery();
+ } catch (Exception e) {
+ if (null == eRet)
+ eRet = new Exception(e.getMessage());
+ // System.out.println("Retrying "+i1);
+ Thread.sleep(100 + (new Double(100 * Math.random()))
+ .longValue());
+ }
+ }
+ m_oLogger.error("execQueryWait() FAILED", eRet);
+ throw eRet;
+ } // __________________________________
+
+ public void execUpdWait(PreparedStatement p_PS, int p_iQtry) throws Exception {
+ if (null == m_conn) {
+ connect();
+ }
+
+ Exception eRet = null;
+ int iQtry = (p_iQtry < 1) ? 1 : (p_iQtry < 50) ? p_iQtry : 50;
+ for (int i1 = 0; i1 < iQtry; i1++) {
+ try {
+ p_PS.executeUpdate();
+ return;
+ } catch (Exception e) {
+ if (null == eRet)
+ eRet = e;
+ // System.out.println("Retrying "+i1);
+ Thread.sleep(100 + (new Double(100 * Math.random()))
+ .longValue());
+ }
+ }
+ m_oLogger.error("execUpdWait() FAILED", eRet);
+ throw eRet;
+ } // __________________________________
+
+ private void connect() throws Exception {
+ if(m_conn != null) {
+ return;
+ }
+
+ Exception eRet = null;
+ for (int i1 = 0; i1 < 5; i1++) {
+ try {
+ m_conn = m_oDS.getConnection();
+ eRet = null;
+ break;
+ } catch (Exception e) {
+ if (null == eRet)
+ eRet = e;
+ System.out.println("Connecting " + i1);
+ Thread.sleep(2000 + (new Double(100 * Math.random()))
+ .longValue());
+ }
+ }
+ if (null != eRet) {
+ m_oLogger.error("connect() FAILED", eRet);
+ throw eRet;
+ }
+ m_conn.setAutoCommit(false);
+ m_conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+
+ m_olPrepSt.clear();
+
+ } // __________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,142 @@
+/*
+ * 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.helpers.persist;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import javax.sql.DataSource;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * <p>
+ * Obtain a connection that implements the DataSource interface
+ * </p>
+ * <p>
+ * Description: Enable compatible use of JdbcCleanConn from outside a J2EE app
+ * container
+ * </p>
+ *
+ * @version 1.0
+ * @see JdbcCleanConn
+ * @see ConfigTree
+ */
+public class SimpleDataSource implements DataSource {
+ private PrintWriter m_oPW = new PrintWriter(System.out);
+
+ private int m_iTO = 10;
+
+ private String m_sUrl, m_sUsr, m_sPwd;
+
+ private Connection m_oConn;
+
+ public static final String DRIVER = "driver-class";
+
+ public static final String URL = "connection-url";
+
+ public static final String USER = "user-name";
+
+ public static final String PASSWORD = "password";
+
+ private SimpleDataSource() {
+ }
+
+ /**
+ * Obtain a DataSource by providing connection parameters. ConfigTree
+ * argument must contain the following attributes
+ * <p>
+ * <li> driver-class</li>
+ * <li> connection-url</li>
+ * <li> user-name</li>
+ * <li> password</li>
+ * </p>
+ *
+ * @param p_oP
+ * ConfigTree - Parameter tree that contains the 4 attributes
+ * needed
+ * @throws Exception
+ * @see ConfigTree
+ * @see SimpleDataSource#SimpleDataSource(String,String,String,String)
+ * @see javax.sql.DataSource
+ */
+ public SimpleDataSource(ConfigTree p_oP) throws Exception {
+ this(p_oP.getAttribute(DRIVER), p_oP.getAttribute(URL), p_oP.getAttribute(USER), p_oP
+ .getAttribute(PASSWORD));
+ } // ________________________________
+
+ /**
+ * Obtain a connection to a DB using the provided arguments to call
+ *
+ * @param p_sDriver
+ * String - Java class of the JDBC driver to use (e.g.
+ * org.postgresql.Driver)
+ * @param p_sDbURL
+ * String - The URL of the database (e.g.
+ * jdbc:postgresql://chodedb1:5432/cq3)
+ * @param p_sUsr
+ * String - Username
+ * @param p_sPwd
+ * String - Password
+ * @throws Exception
+ * @see DriverManager#getConnection(String,String,String)
+ * @see javax.sql.DataSource
+ */
+ public SimpleDataSource(String p_sDriver, String p_sDbURL, String p_sUsr,
+ String p_sPwd) throws Exception {
+ Class.forName(p_sDriver);
+ m_sUrl = p_sDbURL;
+ getConnection(p_sUsr, p_sPwd);
+ } // ________________________________
+
+ public Connection getConnection() {
+ return m_oConn;
+ }
+
+ public Connection getConnection(String username, String password) {
+ m_sUsr = username;
+ m_sPwd = password;
+ try {
+ m_oConn = DriverManager.getConnection(m_sUrl, m_sUsr, m_sPwd);
+ } catch (Exception e) {
+ m_oConn = null;
+ }
+ return m_oConn;
+ } // ________________________________
+
+ public int getLoginTimeout() {
+ return m_iTO;
+ }
+
+ public PrintWriter getLogWriter() {
+ return m_oPW;
+ }
+
+ public void setLoginTimeout(int seconds) {
+ m_iTO = seconds;
+ }
+
+ public void setLogWriter(PrintWriter out) {
+ m_oPW = out;
+ }
+} // ______________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SqlDbTable.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,180 @@
+/*
+ * 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.helpers.persist;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+public abstract class SqlDbTable {
+ protected String m_sTableName;
+
+ protected SqlField[] m_oaFields;
+
+ protected PreparedStatement[] m_oaPS;
+
+ private JdbcCleanConn m_oConn;
+
+ public JdbcCleanConn getConn() {
+ return m_oConn;
+ }
+
+ public final String getTableName() {
+ return m_sTableName;
+ }
+
+ public final SqlField[] getAllFields() {
+ return m_oaFields;
+ }
+
+ private String m_sInsertSql, m_sUpdateSql, m_sDeleteSql;
+
+ protected String m_sSelectSql;
+
+ public SqlDbTable(JdbcCleanConn p_oC, String p_sTblNm) throws Exception {
+ m_oConn = p_oC;
+ m_sTableName = p_sTblNm;
+ initFields();
+ } // ________________________________
+
+ public abstract int setInsValues(PreparedStatement p_PS, Object bobj)
+ throws Exception;
+
+ public abstract Object getFromRS(ResultSet p_oRS) throws Exception;
+
+ protected abstract String getSelectFields();
+
+ public String getFldName(int p_i) {
+ return (null == m_oaFields) ? null : (p_i < 0) ? null
+ : (p_i >= m_oaFields.length) ? null : m_oaFields[p_i]
+ .getFieldName();
+ } // ________________________________
+
+ public String getSelectStatement() {
+ if (m_sSelectSql != null)
+ return m_sSelectSql;
+ StringBuffer sb = new StringBuffer("select ").append(getSelectFields());
+ m_sSelectSql = sb.append(" from ").append(getTableName()).toString();
+ return m_sSelectSql;
+ } // ________________________________
+
+ public String getInsertStatement() {
+ if (m_sInsertSql != null)
+ return m_sInsertSql;
+
+ StringBuffer sb = new StringBuffer(256);
+ sb.append("insert into ").append(getTableName());
+
+ sb.append(" values (");
+ for (int i = 0; i < m_oaFields.length; i++)
+ ((i < 1) ? sb : sb.append(",")).append('?');
+ sb.append(')');
+
+ return (m_sInsertSql = sb.toString());
+ } // ________________________________
+
+ public String getUpdateStatement() {
+ if (m_sUpdateSql != null)
+ return m_sUpdateSql;
+
+ StringBuffer sb = new StringBuffer(256);
+ sb.append("update ").append(getTableName()).append(" set ");
+
+ StringBuffer sbWhere = new StringBuffer(" where ");
+
+ int iVal = 0;
+ int iWh = 0;
+ for (int i = 0; i < m_oaFields.length; i++) {
+ SqlField oCurr = m_oaFields[i];
+ if (oCurr.isPrimaryKey())
+ ((iWh++ < 1) ? sbWhere : sbWhere.append(" and ")).append(
+ oCurr.getFieldName()).append(" = ?");
+ else
+ ((iVal++ < 1) ? sb : sb.append(",")).append(
+ oCurr.getFieldName()).append(" = ?");
+ }
+ sb.append(sbWhere);
+
+ return (m_sUpdateSql = sb.toString());
+ } // ________________________________
+
+ public String getDeleteStatement() {
+ if (m_sDeleteSql != null)
+ return m_sDeleteSql;
+
+ StringBuffer sb = new StringBuffer(256);
+ sb.append("delete from ").append(getTableName()).append(" where ");
+
+ int iWh = 0;
+ for (int i = 0; i < m_oaFields.length; i++) {
+ SqlField oCurr = m_oaFields[i];
+ if (!oCurr.isPrimaryKey())
+ continue;
+ ((iWh++ < 1) ? sb : sb.append(" and "))
+ .append(oCurr.getFieldName()).append(" = ?");
+ }
+
+ return (m_sDeleteSql = sb.toString());
+ } // ________________________________
+
+ public void setObject(PreparedStatement p_PS, int p_iFld, Object p_sFldVal)
+ throws SQLException {
+ if (null != p_sFldVal)
+ if (p_sFldVal instanceof String) {
+ String sTr = ((String) p_sFldVal).trim();
+ p_sFldVal = (sTr.length() > 0) ? sTr : null;
+ }
+ ;
+ int iSqlIdx = 1 + p_iFld;
+ if (null == p_sFldVal)
+ p_PS.setNull(iSqlIdx, m_oaFields[p_iFld].getSqlType());
+ else
+ p_PS.setObject(iSqlIdx, p_sFldVal);
+ } // ________________________________
+
+ public void setLong(PreparedStatement p_PS, int p_iFld, long p_lVal)
+ throws SQLException {
+ p_PS.setLong(1 + p_iFld, p_lVal);
+ } // ________________________________
+
+ public void setInt(PreparedStatement p_PS, int p_iFld, int p_iVal)
+ throws SQLException {
+ p_PS.setInt(1 + p_iFld, p_iVal);
+ } // ________________________________
+
+ private void initFields() throws Exception {
+ PreparedStatement PS = m_oConn.prepareStatement(getSelectStatement());
+
+ ResultSetMetaData MD = m_oConn.execQueryWait(PS, 3).getMetaData();
+ m_oaFields = new SqlField[MD.getColumnCount()];
+ for (int i1 = 0; i1 < m_oaFields.length; i1++) {
+ int iCol = 1 + i1;
+ String sFN = MD.getColumnName(iCol);
+ Class oCL = Class.forName(MD.getColumnClassName(iCol));
+ int iTP = MD.getColumnType(iCol);
+ int iSZ = MD.getColumnDisplaySize(iCol);
+ m_oaFields[i1] = new SqlField(sFN, oCL, iTP, iSZ, false);
+ }
+ PS.close();
+ } // ________________________________
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SqlField.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SqlField.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/helpers/persist/SqlField.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,83 @@
+/*
+ * 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.helpers.persist;
+
+public class SqlField {
+ private int m_sqlType;
+
+ private Class m_javaType;
+
+ private int m_sqlLength;
+
+ private String m_fieldName;
+
+ private boolean m_primaryKey;
+
+ public SqlField(String pFldName, Class pJavaType, int pSqlType,
+ int pFieldLength, boolean pk) {
+ m_fieldName = pFldName;
+ m_javaType = pJavaType;
+ m_sqlType = pSqlType;
+ m_sqlLength = pFieldLength;
+ m_primaryKey = pk;
+ }
+
+ public int getSqlType() {
+ return m_sqlType;
+ }
+
+ public Class getJavaType() {
+ return m_javaType;
+ }
+
+ public int getSqlLength() {
+ return this.m_sqlLength;
+ }
+
+ public String getFieldName() {
+ return this.m_fieldName;
+ }
+
+ public boolean isPrimaryKey() {
+ return this.m_primaryKey;
+ }
+
+ public void setSqlType(int pSqlType) {
+ m_sqlType = pSqlType;
+ }
+
+ public void setJavaType(Class pJavaType) {
+ m_javaType = pJavaType;
+ }
+
+ public void setSqlLength(int pSqlLength) {
+ m_sqlLength = pSqlLength;
+ }
+
+ public void setFieldName(String pFieldName) {
+ m_fieldName = pFieldName;
+ }
+
+ public void setPrimaryKey(boolean pPrimaryKey) {
+ m_primaryKey = pPrimaryKey;
+ }
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Attachment.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Attachment.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Attachment.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,110 @@
+package org.jboss.soa.esb.message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Messages may contain attachments that do not appear in the main payload body.
+ * For example, binary document formats, zip files etc.
+ * <br/>Handles both 'named' attachment and a list of 'unnamed' attachments
+ *
+ * @author Mark Little
+ */
+
+public interface Attachment
+{
+ /**
+ * Returns the attachment to which this object maps the specified key.
+ * Returns null if the there's no value mapped for this key.
+ * @param name String - The name of the attachment to get
+ * @return Object - the value mapped to arg0 or <null> if none
+ */
+ Object get(String name);
+ /**
+ * Associates the specified value with the specified name
+ * If there was already a mapping for this name, the old value is replaced by
+ * arg1
+ * @param name String - the name for the object to be stored
+ * @param value Object - the object to be associated with the name (arg0)
+ * @return Object - previous value associated with specified name,
+ * or null if there was none
+ */
+ Object put(String name, Object value);
+ /**
+ * Removes the mapping for this name if it was present
+ * @param name String - the name of the object to be removed
+ * @return the value previously associated the name, or null if there was none
+ */
+ Object remove(String name);
+ /**
+ * @return String[] - the list of names of the named Objects
+ */
+ String[] getNames();
+
+ /**
+ * get the item at the specified position in the list of unnamed objects
+ * @param index int - index of element to return
+ * @return Object the element at the specified position in the list of unnamed objects
+ * @throws IndexOutOfBoundsException - if the index is out of range
+ */
+ Object itemAt (int index) throws IndexOutOfBoundsException;
+ /**
+ * Removes the element at the specified position in the list of unnamed objects
+ * Shifts any subsequent elements to the left
+ * @param index int - index of element to remove
+ * @return Object - the element that was removed from the list
+ * @throws IndexOutOfBoundsException - if the index is out of range
+ */
+ Object removeItemAt (int index) throws IndexOutOfBoundsException;
+ /**
+ * Replaces the element at the specified position in the list of unnamed objects
+ * with the value supplied
+ * @param index int - index of element to be replaced
+ * @param value Object - the object to replace the one previously stored at that index
+ * @return Object - previous value at that index
+ * @throws IndexOutOfBoundsException - if the index is out of range
+ */
+ Object replaceItemAt(int index, Object value) throws IndexOutOfBoundsException;
+ /**
+ * Appends the specified element to the end of the list of unnamed objects
+ * <br/>null values are allowed
+ * @param value Object - the object to be appended
+ */
+ void addItem (Object value);
+ /**
+ * Replaces the element at the specified position in the list of unnamed objects
+ * <br/> allows null values
+ * @param index int - index where to insert the value - Shifts any subsequent elements to the right
+ * @param value Object - value to be stored at the specified position
+ * @throws IndexOutOfBoundsException
+ */
+ void addItemAt (int index, Object value) throws IndexOutOfBoundsException;
+ /**
+ * getUnnamedCount()
+ * @return the count of unnamed objects
+ */
+ int getUnnamedCount();
+ /**
+ * getNamedCount()
+ * @return the count of named objects
+ */
+ public int getNamedCount();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Body.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Body.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Body.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,102 @@
+package org.jboss.soa.esb.message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * The message body holds arbitrary information which represents the
+ * payload as far as clients and services are concerned. A body may contain:
+ *
+ * (i) a byte array for arbitrary data. How that array is interpreted by the
+ * service is implementation specific and outside the scope of the ESB to
+ * enforce.
+ *
+ * (ii) a list of Objects of arbitrary types. How these objects are serialized
+ * to/from the message body when it is transmitted is up to the specific
+ * Object type. The plan is to add support for various TYPES of Object and the message
+ * implementation will use external adapters to externalize/internalize the Objects.
+ * Currently we only support Serializable objects.
+ */
+
+public interface Body
+{
+ // TODO error handling exceptions
+
+ /**
+ * Add the specified Object to the body.
+ *
+ * @param name the name of the object. MUST be unique within this body.
+ * @param value the Object to add.
+ */
+
+ public void add (String name, Object value);
+
+ /**
+ * Get the specified Object, or <code>null</code> if not present.
+ *
+ * @param name the name of the Object to retrieve.
+ * @return the Object.
+ */
+
+ public Object get (String name);
+
+ /**
+ * Remove the specified Object and return it, or <code>null</code> if not present.
+ *
+ * @param name the name of the Object to remove.
+ * @return the Object removed.
+ */
+
+ public Object remove (String name);
+
+ /**
+ * Set the byte content of the body.
+ *
+ * @param content the message bytes
+ */
+
+ public void setContents (byte[] content);
+
+ /**
+ * @return the byte content of the body.
+ */
+
+ public byte[] getContents ();
+
+ /**
+ * Replace this body instance with the one given.
+ *
+ * @param b the body to be replaced with.
+ */
+
+ public void replace (Body b);
+
+ /**
+ * Merge two bodies.
+ *
+ * @param b the body to be merged with.
+ */
+
+ public void merge (Body b);
+
+ // TODO replace an entry in the body
+
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Context.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Context.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Context.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,33 @@
+package org.jboss.soa.esb.message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * The context is the section of the message containing information such as session
+ * management, transaction information, security data etc. Entries in the context
+ * may be ordered.
+ */
+
+public interface Context
+{
+ // TODO add some methods!
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Fault.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Fault.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Fault.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,61 @@
+package org.jboss.soa.esb.message;
+
+import java.net.URI;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Faults may be returned from a service in response to receiving and acting upon messages.
+ * A fault consists of a unique code (MANDATORY) and a reason string (OPTIONAL).
+ */
+
+public interface Fault
+{
+ /**
+ * @return the unique code representing this fault.
+ */
+
+ public URI getCode ();
+
+ /**
+ * Set the unique code for this fault.
+ *
+ * @param code the code.
+ */
+
+ public void setCode (URI code);
+
+ /**
+ * @return a String representing the reason for the fault. Typically used for
+ * logging purposes.
+ */
+
+ public String getReason ();
+
+ /**
+ * Set the optional reason for this fault.
+ *
+ * @param reason the reason for the fault.
+ */
+
+ public void setReason (String reason);
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Header.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Header.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Header.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,45 @@
+package org.jboss.soa.esb.message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import org.jboss.soa.esb.addressing.Call;
+
+/**
+ * The message header. Contains such things as routing information.
+ */
+
+public interface Header
+{
+ /**
+ * @return get the Call information for this message.
+ */
+
+ public Call getCall ();
+
+ /**
+ * Set the call information for this message.
+ *
+ * @param call the information.
+ */
+
+ public void setCall (Call call);
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Message.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Message.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Message.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,92 @@
+package org.jboss.soa.esb.message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+import java.net.URI;
+
+/**
+ * This is the basic internal core message abstraction. A message consists of the following
+ * components:
+ *
+ * Header: the header information contains information such as the destination EPR, the
+ * sender EPR, where the reply goes etc, i.e., general message-level functional information.
+ * Context: additional information to contextualise the message; for example, transaction or
+ * security data, the identity of the ultimate receiver, or HTTP-cookie like information.
+ * Body: the actual payload of the message.
+ * Fault: any fault information associated with the message.
+ * Attachment: any attachments associated with the message.
+ * Properties: any message specific properties.
+ *
+ * Each message, once created, has a corresponding element for these 5 components. That element
+ * may be empty (<b>NOT NULL</b>). The object representing the element can then be used to act
+ * on the corresponding data item in the message.
+ *
+ * @author Mark Little
+ *
+ */
+
+public interface Message
+{
+ /**
+ * @return get the header component of the message.
+ */
+
+ public Header getHeader ();
+
+ /**
+ * @return get the context component of the message.
+ */
+
+ public Context getContext ();
+
+ /**
+ * @return get the body component of the message.
+ */
+
+ public Body getBody ();
+
+ /**
+ * @return get any faults associated with the message. These should not
+ * be application level faults, but comms level.
+ */
+
+ public Fault getFault ();
+
+ /**
+ * @return get any message attachments.
+ */
+
+ public Attachment getAttachment ();
+
+ /**
+ * @return the type of this message.
+ */
+
+ public URI getType ();
+
+ /**
+ * @return Properties - any message properties.
+ */
+
+ public Properties getProperties ();
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Properties.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Properties.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/Properties.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author schifest at heuristica.com.ar
+ */
+
+package org.jboss.soa.esb.message;
+
+/**
+ * The message properties hold arbitrary information in the form of
+ * <String,Object> pairs
+ *
+ */
+
+public interface Properties
+{
+ /**
+ * getProperty(name)
+ *
+ * @param name
+ * String - name of property
+ * @return Object - the value stored under the specified name
+ */
+ public Object getProperty(String name);
+
+ /**
+ * getProperty(name,defaultVal)
+ *
+ * @param name
+ * String - name of property
+ * @param defaultVal
+ * Object - value to return if no value found
+ * @return Object - the value stored under the specified name
+ */
+ public Object getProperty(String name, Object defaultVal);
+
+ /**
+ * setProperty(name,value)
+ *
+ * @param name
+ * String - name of property to store
+ * @param value
+ * Object - value of property to store under specified name
+ * @return Object - the previous value of the specified name, or null if it
+ * did not have one
+ */
+ public Object setProperty(String name, Object value);
+
+ /**
+ * remove(name)
+ *
+ * @param name
+ * String - name of property to remove
+ * @return Object - the previous value of the specified name, or null if it
+ * did not have one
+ */
+ public Object remove(String name);
+
+ /**
+ * size()
+ *
+ * @return int - Returns the number of properties in this object
+ */
+ public int size();
+
+ /**
+ * getNames()
+ *
+ * @return String[] - containing the names of all properties
+ */
+ public String[] getNames();
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessageFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessageFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessageFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,76 @@
+package org.jboss.soa.esb.message.format;
+
+import java.net.URI;
+
+import org.jboss.internal.soa.esb.message.format.MessageFactoryImpl;
+import org.jboss.soa.esb.message.Message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * You get a message of a specific type when you need it. Obviously that type may not be
+ * suitable for the service (hopefully you've got that contractual information a priori, but
+ * maybe not) and in which case some translation/transformation may be necessary.
+ *
+ * @author Mark Little
+ *
+ */
+
+public abstract class MessageFactory
+{
+ /**
+ * @return some default implementation.
+ */
+
+ public abstract Message getMessage ();
+
+ /**
+ * @param type the unique identifier representing the type of this message.
+ * @return the message, or <code>null</code> if no suitable plugin is available.
+ */
+
+ public abstract Message getMessage (URI type);
+
+ /**
+ * @param msg the message to convert.
+ * @param type the type of the message we want to convert to.
+ * @return a translated message, or <code>null</code> if no suitable plugin is available.
+ */
+
+ public abstract Message getMessage (Message msg, URI type);
+
+ /**
+ * Reload the plugins.
+ */
+
+ public abstract void reset ();
+
+ // TODO setters/getters for the plugin programmatically too.
+
+ public static MessageFactory getInstance ()
+ {
+ return theFactory;
+ }
+
+ private static final MessageFactory theFactory = new MessageFactoryImpl();
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessagePlugin.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessagePlugin.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessagePlugin.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,52 @@
+package org.jboss.soa.esb.message.format;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new message formats dynamically. Each plugin is responsible for
+ * returning a message implementation that knows how to serialize its state in a
+ * specific manner, e.g., XML or ASN.1.
+ *
+ * @author Mark Little
+ *
+ */
+
+public interface MessagePlugin
+{
+ public static final String MESSAGE_PLUGIN = "org.jboss.soa.esb.message.format.plugin";
+
+ /**
+ * @return the message instance.
+ */
+
+ public Message getMessage ();
+
+ /**
+ * @return the unique identifier for this message plugin.
+ */
+
+ public URI getType ();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessageType.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessageType.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/message/format/MessageType.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,62 @@
+package org.jboss.soa.esb.message.format;
+
+import java.net.URI;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * You get a message of a specific type when you need it. Obviously that type may not be
+ * suitable for the service (hopefully you've got that contractual information a priori, but
+ * maybe not) and in which case some translation/transformation may be necessary.
+ *
+ * @author Mark Little
+ *
+ */
+
+public abstract class MessageType
+{
+ /*
+ * DO NOT reorder this list. New types may be added as required.
+ */
+
+ public static URI JBOSS_XML = null;
+ public static URI JAVA_SERIALIZED = null;
+
+ public static URI DEFAULT_TYPE = null;
+
+ static
+ {
+ try
+ {
+ JBOSS_XML = new URI("urn:jboss:esb:message:type:JBOSS_XML");
+ JAVA_SERIALIZED = new URI("urn:jboss:esb:message:type:JAVA_SERIALIZED");
+
+ DEFAULT_TYPE = JBOSS_XML;
+ }
+ catch (Exception ex)
+ {
+ throw new ExceptionInInitializerError(ex.toString());
+ }
+
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationList.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationList.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationList.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,139 @@
+/*
+ * 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.notification;
+
+import java.io.Serializable;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Holds lists of NotificationTarget objects so that the
+ * NotificationHandler EJB behaviour can be controlled at runtime by
+ * client applications
+ * <p>
+ * Description: Objects of this class will hold a list of objects that extend
+ * the NotificationTarget base class. It's main purpose is to allow Rosetta
+ * users to configure lists of recipients of specific events, and request the
+ * NotificationHandler EJB to take care of triggering the events to each
+ * object specified as a child "target" element
+ * </p>
+ * <p>
+ * Author: Heuristica - Buenos Aires - Argentina
+ * </p>
+ *
+ * @version 1.0
+ */
+public class NotificationList extends ConfigTree {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Mnemonic name for the XML element name for the serialized form of objects
+ * of this class
+ */
+ public static final String ELEMENT = "NotificationList";
+
+ public static final String TYPE = "type";
+
+ public static final String CHILD_TGT = "target";
+
+ private String m_sType;
+
+ /**
+ * Instantiate an object according to the contents of <arg 1>
+ *
+ * @param p_oP
+ * ConfigTree - Parameter object containing the information
+ * needed to instantiate this object, including child elements
+ * named "target" that represent each individual
+ * NotificationTarget object
+ * @throws Exception -
+ * the getMessage() of the Exception explains the problem
+ */
+ public NotificationList(ConfigTree p_oP){
+ super(p_oP);
+ m_sType = p_oP.getAttribute(TYPE);
+ if (null != m_sType)
+ m_sType = m_sType.toLowerCase();
+ } // __________________________________
+
+ private NotificationTarget[] getTargets() throws Exception {
+ ConfigTree[] oaTgts = super.getChildren(CHILD_TGT);
+ NotificationTarget[] oaRet = new NotificationTarget[oaTgts.length];
+
+ for (int i1 = 0; i1 < oaRet.length; i1++) {
+ oaRet[i1] = NotificationTarget.fromParams(oaTgts[i1]);
+ }
+
+ return oaRet;
+ } // __________________________________
+
+ /**
+ * Invoke the sendNotification() method for all targets in the list. The
+ * method iterates along it's NotificationTarget child nodes and invokes the
+ * sendNotification() method with the same object to all of them
+ *
+ * @param p_o
+ * Object - The event to notify to all targets
+ * @throws Exception -
+ * use Exception.getMessage() at runtime
+ */
+ public void sendNotification(Serializable p_o) throws Exception {
+ NotificationTarget[] oaTgt = getTargets();
+
+ for (int i1 = 0; i1 < oaTgt.length; i1++) {
+ oaTgt[i1].sendNotification(p_o);
+ }
+ } // __________________________________
+
+ /**
+ * Is this an OK (success) NotificationList ?
+ *
+ * @return boolean - Yes, Attribute "type" of constructor parameters starts
+ * with "ok", OR there was no "type" attribute in the constructor
+ * <li>A NotificationList can be both OK and Error if no "type"
+ * attribute was specified at constructor time in the ConfigTree
+ * argument</li>
+ * @see ConfigTree#getAttr(String)
+ */
+ public boolean isOK() {
+ return (null == m_sType) ? true : m_sType.startsWith("ok");
+ }
+
+ /**
+ * Is this an Error (failure) NotificationList ?
+ *
+ * @return boolean - Yes, Attribute "type" of constructor parameters starts
+ * with "err", OR there was no "type" attribute in the constructor
+ * <li>A NotificationList can be both OK and Error if no "type"
+ * attribute was specified at constructor time in the ConfigTree
+ * argument</li>
+ * @see ConfigTree#getAttr(String)
+ */
+ public boolean isErr() {
+ return (null == m_sType) ? true : m_sType.startsWith("err");
+ }
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationTarget.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationTarget.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotificationTarget.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,107 @@
+/*
+* 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.notification;
+
+import java.lang.reflect.Constructor;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+/**
+ * Abstract class to define expected behaviour of all NotificationTargets and
+ * provide some common functionality to all of them
+ * <p>Description: </p>
+ * <p>Heuristica - Buenos Aires - Argentina</p>
+ * @version 1.0
+ */
+public abstract class NotificationTarget
+{
+ /**
+ * Derived classes must implement this method to do what has to be done to
+ * trigger that specific type of notification event
+ * @param p_o Object - The toString() method of this object will be the actual
+ * notification content
+ * @throws Exception - invoke Exception.getMessage() at runtime for this object
+ * @see ConfigTree
+ */
+ public abstract void sendNotification(java.io.Serializable p_o) throws Exception;
+
+ private static final String NOTIF_PFX = NotificationTarget.class.getPackage().getName();
+
+ public static final String PRM_NOTIF_CLASS = "class";
+
+ /**
+ * Common object to hold details of object's information - Each derived class
+ * will hold it's own needs
+ */
+ protected ConfigTree m_oParms;
+ /**
+ * Instantiate an empty NotificationTarget object
+ */
+ protected NotificationTarget() {}
+ /**
+ * Instantiate a NotificationTarget object with the information contained
+ * in <arg 1>
+ * @param p_oP ConfigTree - Holds details to instantiate this object
+ */
+ protected NotificationTarget (ConfigTree p_oP)
+ { m_oParms = p_oP;
+ } //__________________________________
+
+ /**
+ * A typical Factory.getInstance() method
+ * @param p_oP ConfigTree - Contents of this argument will determine the
+ * type (derived class) of NotificationTarget returned
+ * @throws Exception - Arg 1 does not contain a valid structure for currently
+ * implemented NotificationTarget subclasses - invoke Exception.getMessage() at
+ * runtime for details
+ * @return NotificationTarget - An object that instantiates the NotificationTarget
+ * abstract class
+ */
+ public static NotificationTarget fromParams (ConfigTree p_oP) throws Exception
+ { String sClass = p_oP.getAttribute(PRM_NOTIF_CLASS);
+ if (null==sClass) throw new Exception("Missing '"+PRM_NOTIF_CLASS
+ +"' attribute in parameters");
+ Class oCls = null;
+ try { oCls = Class.forName(NOTIF_PFX+"."+sClass); }
+ catch (Exception e)
+ { try { oCls = Class.forName(sClass); }
+ catch (Exception e1) {/* oCls will be null */}
+ }
+ if (null==oCls)
+ throw new Exception("Invalid class <"+sClass+">, or missing library");
+
+ Constructor oCons = null;
+ try { oCons = oCls.getConstructor(new Class[] {ConfigTree.class}); }
+ catch (Exception e) {}
+ if (null==oCons)
+ throw new Exception("No valid constructor "+sClass+"(ConfigTree)");
+
+ Object oRet = null;
+ try { oRet = oCons.newInstance(new Object[] {p_oP}); }
+ catch (Exception e) { e.printStackTrace();}
+ if (null==oRet || (! (oRet instanceof NotificationTarget)))
+ throw new Exception(sClass+" does not extend NotificationTarget");
+
+ return (NotificationTarget) oRet;
+ } //__________________________________
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyEmail.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyEmail.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyEmail.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,114 @@
+/*
+ * 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.notification;
+
+import java.io.Serializable;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.Email;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * This class will send an e-mail using the Email class
+ * <p>
+ * Description:
+ * </p>
+ * <p>
+ * Author: Heuristica - Buenos Aires - Argentina
+ * </p>
+ *
+ * @version 1.0
+ */
+public class NotifyEmail extends NotificationTarget {
+ /**
+ * Instantiate a NotifyEmail object using the information contained in
+ * <arg 1>
+ *
+ * @param p_oP
+ * ConfigTree - See attributes and structure needed for the
+ * Email() constructor - The MESSAGE attribute will
+ * be filled in at sendNotification(Serializable) time
+ * @throws Exception
+ * @see NotifyEmail#sendNotification(Serializable)
+ */
+ public NotifyEmail(ConfigTree p_oP) throws Exception {
+ super(p_oP);
+
+ String sAtt = (String) m_oParms.getAttribute(Email.FROM);
+ if (null != sAtt)
+ InternetAddress.parse(sAtt);
+
+ InternetAddress.parse(m_oParms.getAttribute(Email.SENDTO));
+
+ sAtt = (String) m_oParms.getAttribute(Email.COPYTO);
+ if (null != sAtt)
+ InternetAddress.parse(sAtt);
+ } // __________________________________
+
+ /**
+ * Send an Email using Email() using p_o.toString() to fill in the
+ * message text
+ *
+ * @param p_o
+ * Object - This object's toString() method will supply contents
+ * of mail message
+ */
+ public void sendNotification(Serializable p_o) {
+ try {
+ ConfigTree oP = m_oParms.cloneObj();
+ String sMsg = oP.getAttribute(Email.MESSAGE);
+ sMsg = ((null == sMsg) ? p_o.toString() : sMsg + "\n") + p_o.toString();
+ oP.setAttribute(Email.MESSAGE, sMsg);
+ sendEmailNotification(oP);
+ } catch (Exception e) {
+ Util.getDefaultLogger(this.getClass()).error("Send Mail Failed",
+ e);
+ e.printStackTrace();
+ }
+ } // __________________________________
+
+ /**
+ * Send an email notification based on the supplied parameters.
+ * <p/>
+ * This method allows overriding for test purposes.
+ * @param messageParams Message parameters.
+ */
+ protected void sendEmailNotification(ConfigTree messageParams) throws AddressException, MessagingException {
+
+ Email esbMail = new Email();
+ esbMail.setSendTo(messageParams.getAttribute(Email.SENDTO));
+ esbMail.setFrom(messageParams.getAttribute(Email.FROM));
+ esbMail.setCopyTo(messageParams.getAttribute(Email.COPYTO));
+ esbMail.setSubject(messageParams.getAttribute(Email.SUBJECT));
+
+ esbMail.setAttachments(messageParams.getTextChildren(Email.ATTACH));
+ esbMail.setMessage(messageParams.getAttribute(Email.MESSAGE));
+
+ esbMail.sendMessage();
+ }
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyFiles.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyFiles.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyFiles.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,197 @@
+/*
+ * 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.notification;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.net.URI;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Write the notification contents into a list of files specified in the
+ * constructor time parameters.
+ * <p>
+ * Description: The constructor searches for all child elements of the
+ * ConfigTree argument having "file" as element name, that will be used to store
+ * (or append) the contents of the argument to the sendNotification(Object)
+ * method, to each and every one of the files contained in the list
+ * </p>
+ * <p>
+ * Author: Heuristica - Buenos Aires - Argentina
+ * </p>
+ *
+ * @version 1.0
+ */
+public class NotifyFiles extends NotificationTarget {
+ /**
+ * Mnemonic for the child element name that hold the files to write ("file")
+ */
+ public static final String CHILD_FILE = "file";
+
+ /**
+ * Attribute name that will be interpreted as the URI of the file to write
+ * to
+ */
+ public static final String ATT_URI = "URI";
+
+ /**
+ * Attribute name of indicator to append to an existing file
+ *
+ * @see Boolean#valueOf(String)
+ */
+ public static final String ATT_APPEND = "append";
+
+ /**
+ * The NotificationFile[] that holds the output file list.
+ */
+ protected NotificationFile[] m_oaOutF;
+
+ /**
+ * Instantiate a NotifyFiles object according to contents of <arg 1>
+ *
+ * @param p_oP
+ * ConfigTree - Should contain a nonempty set of child elements
+ * with elementName="file". Each child element must have a "URI"
+ * attribute and optionally a "append" element
+ * @throws Exception
+ */
+ public NotifyFiles(ConfigTree p_oP) throws Exception {
+ super(p_oP);
+ setFiles(p_oP.getChildren(CHILD_FILE));
+
+ } // __________________________________
+
+ /**
+ * Sets the value of m_oaOutF[] and m_baAppend[] to contents of each element
+ * of the input argument
+ *
+ * @param p_oaP
+ * ConfigTree[] - Each entry must have a "URI" attribute, and can
+ * have an optional "append" attribute
+ * @throws Exception -
+ * invoke Exception.getMessage() at runtime for details
+ * @see ConfigTree#getAttr(String)
+ */
+ protected void setFiles(ConfigTree[] p_oaP) throws Exception {
+ m_oaOutF = new NotificationFile[p_oaP.length];
+
+ for (int i = 0; i < p_oaP.length; i++) {
+ String fileURI = p_oaP[i].getAttribute(ATT_URI);
+ String append = p_oaP[i].getAttribute(ATT_APPEND);
+
+ if (null == fileURI) {
+ throw new IllegalArgumentException("Bad File Notification Configuration: Missing file URI attribute.");
+ }
+
+ try {
+ m_oaOutF[i] = new NotificationFile(new URI(fileURI), Boolean.valueOf(append));
+ } catch(Exception e) {
+ m_oaOutF[i] = new NotificationFile(fileURI, Boolean.valueOf(append));
+ }
+
+ // Make sure the parent folder exists...
+ if(!m_oaOutF[i].getParentFile().exists()) {
+ throw new IllegalArgumentException("Bad File Notification Configuration: Parent folder for file [" + m_oaOutF[i].getAbsolutePath() + "] doesn't exist.");
+ }
+ }
+ } // __________________________________
+
+ /**
+ * Writes the result of p_o into each one of the File objects contained in
+ * the m_oaOutF array
+ *
+ * @param p_o
+ * Object - This object's toString() results will be written to
+ * (appended to) each one of the files in m_oaOutF
+ * @see NotifyFiles#setFiles(ConfigTree[])
+ * @see NotifyFiles#m_oaOutF
+ */
+ public void sendNotification(Serializable p_o) {
+ FileOutputStream fileOutStream = null;
+ for (NotificationFile notificationFile : m_oaOutF) {
+ try {
+ fileOutStream = new FileOutputStream(notificationFile, notificationFile.append);
+ if (p_o instanceof String) {
+ stringNotification(fileOutStream, (String) p_o);
+ } else {
+ objectNotification(fileOutStream, p_o);
+ }
+ } catch (Exception e) { /* We do nothing here for the time being */
+ } finally {
+ try {
+ fileOutStream.close();
+ } catch (Exception eCl) {/*
+ * Unable to Close - What could we
+ * do
+ */
+ }
+ }
+ }
+ } // __________________________________
+
+ private void stringNotification(FileOutputStream p_oF, String p_s) {
+ try {
+ p_oF.write(p_s.getBytes());
+ if (!p_s.endsWith("\n"))
+ p_oF.write("\n".getBytes());
+ } catch (Exception e) { /* We do nothing here for the time being */
+ }
+ } // __________________________________
+
+ private void objectNotification(FileOutputStream p_oF, Object p_o) {
+ try {
+ ObjectOutputStream OS = new ObjectOutputStream(p_oF);
+ OS.writeObject(p_o);
+ } catch (Exception e) { /* We do nothing here for the time being */
+ }
+ } // __________________________________
+
+ /**
+ * Notification File.
+ * <p/>
+ * Simply adds the "append" property to the file.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+ private class NotificationFile extends File {
+
+ private static final long serialVersionUID = 1L;
+ private boolean append = false;
+
+ private NotificationFile(URI fileURI, boolean append) {
+ super(fileURI);
+ this.append = append;
+ }
+
+ /**
+ * @param file
+ * @param append2
+ */
+ public NotificationFile(String file, boolean append) {
+ super(file);
+ this.append = append;
+ }
+ }
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,186 @@
+/*
+ * 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.notification;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Abstract class that defines the behaviour of NotifyQueues and NotifyTopics
+ * (and in fact any other javax.jms.Destination object), and provides common
+ * methods to derived classes
+ * <p>
+ * Description:
+ * </p>
+ * <p>
+ * Author: Heuristica - Buenos Aires - Argentina
+ * </p>
+ *
+ * @version 1.0
+ */
+public abstract class NotifyJMS extends NotificationTarget {
+ /**
+ * Abstract method - All classes that extend NotifyJMS must implement it
+ * according to their own javax.jms.Destination needs (Queue/Topic)
+ *
+ * @param p_oMsg
+ * Message
+ */
+ protected abstract void sendToAll(Message p_oMsg);
+
+ /**
+ * Element name mnemonic to search for child elements in the ConfigTree at
+ * constructor time, that will hold a "name" "value" pair to be included in
+ * the JMS message header
+ */
+ public static final String CHILD_MSG_PROP = "messageProp";
+
+ /**
+ * Attribute name mnemonic for the name of the message property to fill with
+ * contents of the "value" aattribute
+ */
+ public static final String ATT_PROP_NAME = "name";
+
+ /**
+ * Attribute name mnemonic for the value to assign to the corresponding
+ * message property
+ */
+ public static final String ATT_PROP_VALUE = "value";
+
+ /**
+ * Attribute name mnemonic for the att that will hold the JNDI name of the
+ * destination javax.jms.Destination object
+ */
+ public static final String ATT_DEST_NAME = "jndiName";
+
+ /**
+ * This object holds the JNDI naming context that will be used to obtain a
+ * JMS destination (javax.jms.Destination) to send/publish the notification
+ * at sendNotification() time
+ */
+ protected Context m_oCtx;
+
+ private Properties m_oProps = new Properties();
+
+ /**
+ * The javax.jms.Connection instance used to talk to JMS
+ */
+ protected Connection m_oConn;
+
+ /**
+ * The javax.jms.Session instance used to talk to JMS
+ */
+ protected Session m_oSess;
+
+ /**
+ * Array with an instance of javax.jms.MessageProducer on each entry that
+ * will be used to send the notification at sendNotification() time
+ */
+ protected MessageProducer[] m_oaMssProd;
+
+ /**
+ * Constructor that will be called by child classes to perform
+ * initialization tasks that are common to all derived classes
+ *
+ * @param p_oP
+ * ConfigTree
+ * <p>
+ * Will contain a variable number of "messageProp" child elements
+ * that will be added to messages sent to
+ * </p>
+ * @throws Exception
+ */
+ protected NotifyJMS(ConfigTree p_oP) throws Exception {
+ super(p_oP);
+
+ ConfigTree[] oaMsgP = p_oP.getChildren(CHILD_MSG_PROP);
+ for (int i1 = 0; i1 < oaMsgP.length; i1++) {
+ String sKey = oaMsgP[i1].getAttribute(ATT_PROP_NAME);
+ if (null == sKey)
+ continue;
+ String sVal = oaMsgP[i1].getAttribute(ATT_PROP_VALUE);
+ if (null == sVal)
+ continue;
+
+ m_oProps.setProperty(sKey.trim(), sVal);
+ }
+
+ m_oCtx = new InitialContext();
+
+ } // __________________________________
+
+ /**
+ * Performs an orderly release of all JMS resources utilized - Well behaved
+ * developers should always call this method before unreferencing this
+ * object
+ */
+ public void release() {
+ if (null != m_oSess)
+ try {
+ m_oSess.close();
+ } catch (Exception e1) {
+ }
+ if (null != m_oConn)
+ try {
+ m_oConn.close();
+ } catch (Exception e2) {
+ }
+ } // __________________________________
+
+ /**
+ * Send a JMS message using p_o to fill in the message content and the list
+ * of message properties that will be added to the JMS message header fields
+ *
+ * @param p_o
+ * Object - This object or thie object's toString() method will
+ * supply contents of JMS message
+ * @see NotifyJMS#CHILD_MSG_PROP
+ */
+ public void sendNotification(Serializable p_o) throws Exception {
+ Message oMsg = null;
+
+ if (p_o instanceof String) {
+ oMsg = m_oSess.createTextMessage(p_o.toString());
+ } else {
+ oMsg = m_oSess.createObjectMessage((Serializable) p_o);
+ }
+
+ for (Iterator II = m_oProps.keySet().iterator(); II.hasNext();) {
+ String sKey = (String) II.next();
+ String sVal = m_oProps.getProperty(sKey);
+ oMsg.setStringProperty(sKey, sVal);
+ }
+ sendToAll(oMsg);
+ } // __________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyQueues.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyQueues.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyQueues.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,110 @@
+/*
+ * 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.notification;
+
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.naming.NamingException;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+;
+
+/**
+ * This class that implements abstract methods defined in it's superclass
+ * <p>
+ * Description:
+ * </p>
+ * <p>
+ * Author: Heuristica - Buenos Aires - Argentina
+ * </p>
+ *
+ * @version 1.0
+ */
+public class NotifyQueues extends NotifyJMS {
+ /**
+ * Connection Factory JNDI name.
+ */
+ public static final String CONNECTION_FACTORY = "ConnectionFactory";
+ /**
+ * Element name mnemonic to search for child elements in the ConfigTree at
+ * constructor time, that will hold a "jndiName" attribute specifying the
+ * value to look up in the JNDI context in order to obtain a queue
+ *
+ * @see NotifyJMS#ATT_DEST_NAME
+ */
+ public static final String CHILD_QUEUE = "queue";
+
+ public NotifyQueues(ConfigTree p_oP) throws Exception {
+ super(p_oP);
+ setQueues(p_oP.getChildren(CHILD_QUEUE));
+ } // __________________________________
+
+ protected void setQueues(ConfigTree[] p_oaP) throws Exception {
+ QueueConnectionFactory qcf = lookupQueueConnectionFactory();
+ QueueConnection oQconn = qcf.createQueueConnection();
+ QueueSession oQsess = oQconn.createQueueSession(false,
+ QueueSession.AUTO_ACKNOWLEDGE);
+
+ m_oaMssProd = new MessageProducer[p_oaP.length];
+ for (int i1 = 0; i1 < p_oaP.length; i1++) {
+ String sAtt = p_oaP[i1].getAttribute(ATT_DEST_NAME);
+ if (null == sAtt)
+ throw new Exception("Missing queue jndiName");
+ Queue oQ = (Queue) m_oCtx.lookup(sAtt);
+ m_oaMssProd[i1] = oQsess.createSender(oQ);
+ }
+
+ m_oConn = oQconn;
+ m_oSess = oQsess;
+ // m_oConn.start(); Only for incoming messages ???
+ } // __________________________________
+
+ /**
+ * Get the {@link QueueConnectionFactory} to be used for this instance.
+ * <p/>
+ * Can be overridden for testing.
+ * @return The QueueConnectionFactory fro the JNDI context.
+ * @throws NamingException
+ */
+ protected QueueConnectionFactory lookupQueueConnectionFactory() throws NamingException {
+ // REVIEW: The connection factory name is hardcoded and is the same as that of the topic connection factory.
+ return (QueueConnectionFactory) m_oCtx.lookup(CONNECTION_FACTORY);
+ }
+
+ protected void sendToAll(Message p_oMsg) {
+ for (int i1 = 0; i1 < m_oaMssProd.length; i1++) {
+ QueueSender oCurr = (QueueSender) m_oaMssProd[i1];
+ try {
+ oCurr.send(p_oMsg);
+ } catch (Exception e) {
+ }
+ }
+ } // __________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifySqlTable.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifySqlTable.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifySqlTable.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,124 @@
+/*
+ * 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.notification;
+
+import java.sql.PreparedStatement;
+import java.util.Properties;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.helpers.persist.SimpleDataSource;
+
+public class NotifySqlTable extends NotificationTarget {
+ public static final String CHILD_COLUMN = "column";
+
+ public static final String ATT_TABLE = "table";
+
+ public static final String ATT_DATA = "dataColumn";
+
+ public static final String ATT_NAME = "name";
+
+ public static final String ATT_VALUE = "value";
+
+ protected String m_sDriver, m_sURL, m_sUser, m_sPwd, m_sTable, m_sDataCol;
+
+ protected Properties m_oCols;
+
+ public NotifySqlTable(ConfigTree p_oP) throws Exception {
+ super(p_oP);
+ m_sDriver = getAttr(SimpleDataSource.DRIVER);
+ m_sURL = getAttr(SimpleDataSource.URL);
+ m_sUser = getAttr(SimpleDataSource.USER);
+ m_sPwd = getAttr(SimpleDataSource.PASSWORD);
+ m_sTable = getAttr(ATT_TABLE);
+ m_sDataCol = getAttr(ATT_DATA);
+
+ m_oCols = new Properties();
+ ConfigTree[] oaP = p_oP.getChildren(CHILD_COLUMN);
+ for (int i1 = 0; i1 < oaP.length; i1++) {
+ ConfigTree oCurr = oaP[i1];
+ String sCol = oCurr.getAttribute(ATT_NAME);
+ if (null == sCol) {
+ continue;
+ }
+ sCol = sCol.trim();
+ if (sCol.length() < 1) {
+ continue;
+ }
+ String sVal = oCurr.getAttribute(ATT_VALUE);
+ if (null == sVal) {
+ sVal = "";
+ }
+ m_oCols.setProperty(sCol, sVal);
+ }
+ } // __________________________________
+
+ private String getAttr(String p_sAtt) throws Exception {
+ String sRet = m_oParms.getAttribute(p_sAtt);
+ if (null == sRet) {
+ throw new Exception("Missing " + p_sAtt + " attribute");
+ }
+ sRet = sRet.trim();
+ if (p_sAtt.equals(SimpleDataSource.PASSWORD)) {
+ return sRet;
+ }
+ if (sRet.length() < 1) {
+ throw new Exception("Empty " + p_sAtt + " attribute");
+ }
+ return sRet;
+ } // __________________________________
+
+ public String getInsertStmt() {
+ String[] saCols = new String[m_oCols.size()];
+ m_oCols.keySet().toArray(saCols);
+
+ StringBuffer sbCol = new StringBuffer("insert into ").append(m_sTable).append(" ");
+ StringBuffer sbPrm = new StringBuffer(" values ");
+ for (int i1 = 0; i1 < saCols.length; i1++) {
+ String sIn = (i1 == 0) ? "(" : ",";
+ String sCurrCol = saCols[i1];
+ sbCol.append(sIn).append("\"").append(sCurrCol).append("\"");
+ sbPrm.append(sIn).append("'").append(m_oCols.getProperty(sCurrCol)).append("'");
+ // REVIEW: Does the value being inserted not need to be escaped e.g. what if it has a quote in its value??
+ }
+ return sbCol.append(")").append(sbPrm).append(")").toString();
+ } // __________________________________
+
+ public void sendNotification(java.io.Serializable p_o) {
+ m_oCols.setProperty(m_sDataCol, p_o.toString());
+ JdbcCleanConn oConn = null;
+ try {
+ oConn = new JdbcCleanConn(new SimpleDataSource(m_sDriver, m_sURL, m_sUser, m_sPwd));
+ PreparedStatement PS = oConn.prepareStatement(getInsertStmt());
+ oConn.execUpdWait(PS, 3);
+ oConn.commit();
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ } finally {
+ if (null != oConn) {
+ oConn.release();
+ }
+ }
+ } // __________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyTopics.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyTopics.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyTopics.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,78 @@
+/*
+ * 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.notification;
+
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+public class NotifyTopics extends NotifyJMS {
+
+ public static final String CONNECTION_FACTORY = "ConnectionFactory";
+ public static final String CHILD_TOPIC = "topic";
+
+ public NotifyTopics(ConfigTree p_oP) throws Exception {
+ super(p_oP);
+
+ setTopics(p_oP.getChildren(CHILD_TOPIC));
+ } // __________________________________
+
+ protected void setTopics(ConfigTree[] p_oaP) throws Exception {
+ // REVIEW: The connection factory name is hardcoded and is the same as that of the queue connection factory.
+ TopicConnectionFactory qcf = (TopicConnectionFactory) m_oCtx.lookup(CONNECTION_FACTORY);
+ TopicConnection oTconn = qcf.createTopicConnection();
+ TopicSession oTsess = oTconn.createTopicSession(false,
+ TopicSession.AUTO_ACKNOWLEDGE);
+
+ m_oaMssProd = new MessageProducer[p_oaP.length];
+ for (int i1 = 0; i1 < p_oaP.length; i1++) {
+ String sAtt = p_oaP[i1].getAttribute(ATT_DEST_NAME);
+ if (null == sAtt)
+ throw new Exception("Missing topic jndiName");
+ Topic oT = (Topic) m_oCtx.lookup(sAtt);
+ m_oaMssProd[i1] = oTsess.createPublisher(oT);
+ }
+
+ m_oConn = oTconn;
+ m_oSess = oTsess;
+ // m_oConn.start(); Only for incoming messages ???
+
+ } // __________________________________
+
+ protected void sendToAll(Message p_oMsg) {
+ for (int i1 = 0; i1 < m_oaMssProd.length; i1++) {
+ TopicPublisher oCurr = (TopicPublisher) m_oaMssProd[i1];
+ try {
+ oCurr.publish(p_oMsg);
+ } catch (Exception e) {
+ }
+ }
+ } // __________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyUtil.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyUtil.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/notification/NotifyUtil.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,87 @@
+/*
+ * 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.notification;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.Serializable;
+import java.util.Map;
+
+import org.jboss.internal.soa.esb.notification.MacroExpander;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.NotificationManager;
+
+public class NotifyUtil {
+
+ public static void notifyOK(NotificationManager p_oNH,
+ ConfigTree p_oParent, Serializable p_o, Map p_oCtx) {
+ try {
+ ConfigTree[] oaP = p_oParent.getChildren(NotificationList.ELEMENT);
+ for (int i1 = 0; i1 < oaP.length; i1++) {
+ NotificationList oCurr = new NotificationList(oaP[i1]);
+ if (!oCurr.isOK())
+ continue;
+ ConfigTree oCpy = oaP[i1].cloneObj();
+ MacroExpander.replaceMacros(oCpy, p_oCtx);
+ p_oNH.sendNotifications(oCpy, p_o);
+ }
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
+ } // __________________________________
+
+ public static void notifyError(NotificationManager p_oNH,
+ ConfigTree p_oParent, Object p_o, Map p_oCtx, Exception p_e) {
+ ByteArrayOutputStream oBO = new ByteArrayOutputStream();
+ PrintStream oPS = new PrintStream(oBO);
+ try {
+ oPS.println(p_o.toString());
+ if (null != p_e) {
+ p_e.printStackTrace(oPS);
+ }
+ oPS.close();
+
+ String sMsg = oBO.toString();
+ ConfigTree[] oaP = p_oParent.getChildren(NotificationList.ELEMENT);
+ // if (oaP.length<1) // Uncomment this line to send only to the list
+
+ // REVIEW: What's going on here? What's the difference between sending an
+ // error notification and sending a regular notification apart from there being an
+ // error message? What's the difference between how the InotificationHandler
+ // interface is used on the notifyOK and notifyError methods?
+
+ p_oNH.sendNotifications(sMsg);
+ for (int i1 = 0; i1 < oaP.length; i1++) {
+ NotificationList oCurr = new NotificationList(oaP[i1]);
+ if (!oCurr.isErr()) {
+ continue;
+ }
+ MacroExpander.replaceMacros(oaP[i1], p_oCtx);
+ p_oNH.sendNotifications(oaP[i1], sMsg);
+ }
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
+ } // __________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepository.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepository.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepository.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,71 @@
+/*
+ * 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.parameters;
+
+
+/**
+ * Parameter Repository Definition.
+ * <p/>
+ * A ParamRepository implementation allows persistence, retrieval and removal of
+ * parameter values.
+ * <p/>
+ * Note that it is assumed that implementations are Thread Safe.
+ *
+ * @author <a href="mailto:schifest at gmail.com">Esteban Shifman</a>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface ParamRepository {
+
+ // byte[] versions of the add and get methods might be needed on this.
+ // In fact, if this is done - rename the existing add and get methods
+ // to addString and getString and add the new byte[] methods as add/get.
+
+ /**
+ * Store a parameter value in the repository.
+ * @param name The parameter name. Must not be <code>null</code>.
+ * @param value The parameter value. Must not be <code>null</code>.
+ * @throws ParamRepositoryException Failed to store the specified parameter value.
+ */
+ public void add(String name, String value) throws ParamRepositoryException;
+
+ /**
+ * Get the value associated with the named parameter.
+ * @param name The parameter name. Must not be <code>null</code>.
+ * @return The parameter value, or null if the parameter is not available in
+ * the repository.
+ * @throws ParamRepositoryException The parameter exists, but an error has occured
+ * while readingit.
+ */
+ public String get(String name) throws ParamRepositoryException;
+
+ /**
+ * Remove a parameter, or a hierarchy of parameters.
+ * <p/>
+ * Because the repository is hierarchical in nature, parameters can be addressed
+ * explicitly or as a group using a hierarchical name.
+ * @param name The parameter name. Must not be <code>null</code>.
+ * @throws ParamRepositoryException Failed to remove the parameter, or hierarchy of parameters,
+ * from the repository..
+ */
+ public void remove(String name) throws ParamRepositoryException;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepositoryException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepositoryException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepositoryException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,29 @@
+package org.jboss.soa.esb.parameters;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * {@link org.jboss.soa.esb.parameters.ParamRepository} access Exception.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ParamRepositoryException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ */
+ public ParamRepositoryException(String message) {
+ super(message);
+ }
+
+ /**
+ * Public Constructor.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public ParamRepositoryException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepositoryFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepositoryFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/parameters/ParamRepositoryFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,119 @@
+/*
+ * 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.parameters;
+
+import org.jboss.internal.soa.esb.parameters.ParamFileRepository;
+import org.jboss.soa.esb.common.Configuration;
+
+/**
+ * Factory class for Singleton {@link ParamRepository} creation. <p/> Uses the
+ * "org.jboss.soa.esb.paramsRepository.class" system property to determine the
+ * {@link ParamRepository} implementation to be created. If not specified, the
+ * default implementation is the
+ * {@link org.jboss.internal.soa.esb.parameters.ParamFileRepository}.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class ParamRepositoryFactory
+{
+
+ /**
+ * Singleton instance of the repository.
+ */
+ private static ParamRepository instance;
+
+ /**
+ * Factory method for creating the Singleton {@link ParamRepository}
+ * instance for the system.
+ *
+ * @return The ParamRepository instance for the system.
+ */
+ public static ParamRepository getInstance()
+ {
+ if (instance == null)
+ {
+ // Hasn't been created yet - lets created it in a synchronized
+ // fashion...
+ instance = synchedGetInstance();
+ }
+
+ return instance;
+ }
+
+ /**
+ * Synchronizes creation of the Singleton instance.
+ *
+ * @return The Singleton ParamRepository instance.
+ */
+ private static ParamRepository synchedGetInstance()
+ {
+ synchronized (ParamRepositoryFactory.class)
+ {
+ // The following check ensures that multithreads won't create
+ // multiple instances of the singleton. Threads that are blocked
+ // waiting
+ // at the start of this synch block will simply fall through and
+ // return the
+ // instance created by the thread that got in ahead of them.
+ if (instance == null)
+ {
+ String runtimeClassName = Configuration
+ .getParamRepositoryImplClass();
+
+ if (runtimeClassName == null)
+ {
+ // If there's no repository name configured, return the
+ // default file-based repository...
+ instance = new ParamFileRepository();
+ } else
+ {
+ try
+ {
+ Class<?> runtimeClass = Class.forName(runtimeClassName);
+ instance = (ParamRepository) runtimeClass.newInstance();
+ } catch (Exception e)
+ {
+ new IllegalStateException(
+ "System Configuration Exception: Unable to create system "
+ + ParamRepository.class.getSimpleName()
+ + " instance from runtime class name ["
+ + runtimeClassName + "]", e);
+ }
+ }
+ }
+ }
+
+ return instance;
+ }
+
+ /**
+ * Resets the factory, allowing creation of a new Singleton instance. <p/>
+ * Should only need to be used for testing purposes.
+ */
+ protected static void reset()
+ {
+ synchronized (ParamRepositoryFactory.class)
+ {
+ instance = null;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/BatchManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/BatchManager.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/BatchManager.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,35 @@
+/*
+* 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.services;
+
+import org.jboss.soa.esb.common.bizclasses.BatchProcess;
+
+public interface BatchManager
+{
+ public long newBatch () throws Exception;
+ public int addToBatch (String p_s) throws Exception;
+ public void finish () throws Exception;
+ public void commitBatch(BatchProcess p_oBP) throws Exception;
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/DefaultEncryptionFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/DefaultEncryptionFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/DefaultEncryptionFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,63 @@
+/*
+ * 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.services;
+
+public class DefaultEncryptionFactory
+{
+ public static Encryption getEncrypter()
+ {
+ return new DummyEncrypter();
+
+ } //________________________________
+
+ public static Encryption getEncrypter(Object p_o)
+ {
+ return new DummyEncrypter();
+
+ } //________________________________
+
+ /**
+ * This is a dummy class to provide dummy
+ * encrypt/decrypt methods for a byte[]
+ *
+ */
+ private static class DummyEncrypter implements Encryption
+ {
+// private static Cipher s_oCC;
+// static
+// { try { s_oCC = Cipher.getInstance("DES"); }
+// catch (Exception e) { e.printStackTrace(); }
+// }
+ public byte [] encrypt (byte [] p_ba, Object p_oParms)
+ throws Exception
+ {
+ return p_ba;
+ } //__________________________________
+
+ public byte [] decrypt (byte [] p_ba, Object p_oParms)
+ throws Exception
+ {
+ return p_ba;
+ } //__________________________________
+ } //___________________________________________________
+
+} //____________________________________________________________________________
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/Encryption.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/Encryption.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/Encryption.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,28 @@
+/*
+* 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.services;
+
+public interface Encryption
+{
+ public byte [] encrypt (byte [] p_ba, Object p_oParms) throws Exception;
+ public byte [] decrypt (byte [] p_ba, Object p_oParms) throws Exception;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/NotificationManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/NotificationManager.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/NotificationManager.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,63 @@
+/*
+ * 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.services;
+
+import java.io.Serializable;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Use this interface to group all methods that can be useful to
+ * trigger events that can be caught by listeners, within or outside of
+ * the Rosetta framework
+ *
+ * @author Esteban
+ *
+ */
+public interface NotificationManager {
+
+ // REVIEW: Add some Javadoc for this interface!!!
+/**
+ * public void sendNotifications(ConfigTree p_oP, Serializable p_o)
+ *
+ * @param p_oP ConfigTree - A serialized NotificationList object (as a ConfigTree)
+ * @param p_o The Serializable object that will be sent to all the
+ * NotificationTarget objects contained in the NotificationList
+ *
+ * <p/>Implementations of this interface will be responsible of sending
+ * the Serializable (arg 1) to destinations determined by each
+ * NotificationTarget contained in the NotificationList represented by
+ * arg 0.
+ * <p/>Please see org.jboss.soa.esb.notification package for existing
+ * classes that extend NotificationTarget (Files, Queues, Topics, SqlTable...)
+ *
+ * <p/> Invoking processes are responsible to provide dynamic content
+ * of notification
+ * <p/> The NotificationTarget objects can define 'static' content for
+ * (suc as contents of certain columns in SQL, or message properties for
+ * JMS notification targets, etc.
+ */
+ public void sendNotifications(ConfigTree p_oP, Serializable p_o) throws Exception;
+
+ public void sendNotifications(Serializable p_o) throws Exception;
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/PersistManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/PersistManager.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/PersistManager.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+
+package org.jboss.soa.esb.services;
+
+import java.util.Properties;
+
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.ObjLocator;
+
+public interface PersistManager
+{
+ public long getUidChunk(int p_iHowMany) throws Exception;
+ public ObjLocator[] getLocatorList(Class p_oCls,Properties p_oProp) throws Exception;
+
+ public long addObject(BaseBusinessObject p_oQ) throws Exception;
+ public BaseBusinessObject getObject(Class p_oCls,long p_lUid) throws Exception;
+ public void rplObject(BaseBusinessObject p_o) throws Exception;
+ public void rmvObject(Class p_oCls,long p_lUid) throws Exception;
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStore.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStore.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStore.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,15 @@
+package org.jboss.soa.esb.services.persistence;
+
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Message;
+
+
+
+public interface MessageStore {
+
+ public URI addMessage(Message message);
+ public Message getMessage(URI uid) throws Exception;
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,59 @@
+package org.jboss.soa.esb.services.persistence;
+
+
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+
+
+
+ at SuppressWarnings("unchecked")
+public abstract class MessageStoreFactory {
+
+ private static MessageStoreFactory theFactory;
+
+ static
+ {
+
+ try {
+ Class cls = Class.forName("org.jboss.internal.soa.esb.persistence.format.MessageStoreFactoryImpl");
+ Constructor<MessageStoreFactory> c = cls.getConstructor(new Class[]{});
+ theFactory = c.newInstance(new Object[]{});
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+
+ /**
+ * @return a default implementation.
+ */
+
+ public abstract MessageStore getMessageStore ();
+
+ /**
+ * @param type the unique identifier representing the type of this MessageStore.
+ * @return the MessageStore, or <code>null</code> if no suitable store is available.
+ */
+
+ public abstract MessageStore getMessageStore (URI type);
+
+
+ public static MessageStoreFactory getInstance ()
+ {
+ return theFactory;
+ }
+
+ /**
+ * Reload the plugins.
+ */
+
+ public abstract void reset ();
+
+
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/TransformationException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/TransformationException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/TransformationException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,60 @@
+/*
+ * 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.services.transform;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * Transformation Service Exception.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class TransformationException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Public constructor.
+ * @param message Exception message.
+ */
+ public TransformationException(String message) {
+ super(message);
+ }
+
+ /**
+ * Public constructor.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public TransformationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Public constructor.
+ * @param cause Exception cause.
+ */
+ public TransformationException(Throwable cause) {
+ super(cause);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/TransformationService.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/TransformationService.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/services/transform/TransformationService.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.services.transform;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Transformation Service interface.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public interface TransformationService {
+
+ /**
+ * Transform the supplied message object and return the transformation result.
+ * @param message The message to be transformed.
+ * @return The transformed message.
+ * @throws TransformationException An Exception occured during the transformation process.
+ */
+ public Message transform(Message message) throws TransformationException;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/BaseBusinessObject.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/BaseBusinessObject.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/BaseBusinessObject.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,298 @@
+/*
+ * 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.util;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+
+public abstract class BaseBusinessObject {
+
+ public BobjStdDTO toDTO() throws Exception {
+ String sClass = getClass().getSimpleName();
+ BobjStdDTO oRet = new BobjStdDTO(sClass, getElemNm(), null);
+ if (hasUid())
+ try {
+ oRet.addAttr(HIDDEN.uid.toString(), Long.toString(m_lUid));
+ } catch (Exception e) {
+ }
+ putStdAtts(oRet);
+ return oRet;
+ }
+
+ public String toString() {
+ try {
+ return this.toDTO().toXml();
+ } catch (Exception e) {
+ return null;
+ }
+ } // __________________________________
+
+ public String[] locator() {
+ return new String[] {};
+ }
+
+ /**
+ * Get all locators for a given BaseBusinessObject
+ * <p />
+ * Override this method in your class if you have more than 1 locator array
+ *
+ * @return An array of String arrays containing all locators
+ */
+ public String[][] allLocators() {
+ return new String[][] { locator() };
+ }
+
+ private enum ATTRIB {
+ elem, rol
+ };
+
+ enum HIDDEN {
+ uid, stamp, type, snap, dtSnap, batch
+ };
+
+ private EnumMap<ATTRIB, String> m_oData;
+
+ private String setField(ATTRIB pKey, String pVal) {
+ if (null == pKey)
+ return null;
+ String sRet = (null == m_oData) ? null : m_oData.remove(pKey);
+ if (!Util.isNullString(pVal)) {
+ if (null == m_oData)
+ m_oData = new EnumMap<ATTRIB, String>(ATTRIB.class);
+ m_oData.put(pKey, pVal);
+ }
+ return sRet;
+ } // __________________________________
+
+ private String getField(ATTRIB pKey) {
+ if (null == pKey)
+ return null;
+ if (null == m_oData)
+ return null;
+ return m_oData.get(pKey);
+ } // __________________________________
+
+ private long m_lStamp = -1;
+
+ private long m_lUid = -1;
+
+ private long m_lLastSnap = 0;
+
+ private long m_lBatch = 0;
+
+ private String m_sDtSnap = null;
+
+ private String m_sPkg = null;
+
+ public boolean hasUid() {
+ return m_lUid > 0;
+ }
+
+ public void setElemNm(String p_s) {
+ setField(ATTRIB.elem, p_s);
+ }
+
+ public void setRole(String p_s) {
+ setField(ATTRIB.rol, p_s);
+ }
+
+ public void setStamp(long p_l) {
+ m_lStamp = p_l;
+ }
+
+ public void setUid(long p_l) {
+ m_lUid = p_l;
+ }
+
+ public void setSnap(long p_l) {
+ m_lLastSnap = p_l;
+ }
+
+ public void setBatchNum(long p_l) {
+ m_lBatch = p_l;
+ }
+
+ public void setSnapDate(String p_s) {
+ m_sDtSnap = p_s;
+ }
+
+ public void setPackage() {
+ m_sPkg = this.getClass().getPackage().getName();
+ }
+
+ public String getElemNm() {
+ return getField(ATTRIB.elem);
+ }
+
+ public String getRole() {
+ return getField(ATTRIB.rol);
+ }
+
+ public long getStamp() {
+ return m_lStamp;
+ }
+
+ public long getUid() {
+ return m_lUid;
+ }
+
+ public long getSnap() {
+ return m_lLastSnap;
+ }
+
+ public long getBatchNum() {
+ return m_lBatch;
+ }
+
+ public String getSnapDate() {
+ return m_sDtSnap;
+ }
+
+ public BaseBusinessObject() {
+ this((String) null);
+ }
+
+ protected BaseBusinessObject(String p_sElem) {
+ this(p_sElem, -1);
+ }
+
+ protected BaseBusinessObject(String p_sElem, long p_lUid) {
+ setField(ATTRIB.elem, p_sElem);
+ m_lUid = p_lUid;
+
+ if (null != getElemNm()) {
+ return;
+ }
+
+ String sClass = getClass().getSimpleName();
+
+ if (null == p_sElem) {
+ setField(ATTRIB.elem, sClass);
+ }
+ } // ________________________________
+
+ protected BaseBusinessObject(BobjStdDTO p_oDto) throws Exception {
+ this(p_oDto.elementNm());
+ if (p_oDto.isList())
+ return;
+ commonFieldsFromDTO(this, p_oDto);
+ } // ________________________________
+
+ private static final void commonFieldsFromDTO(BaseBusinessObject p_obj,
+ BobjStdDTO p_oDto) throws Exception {
+ for (ATTRIB oCurr : ATTRIB.values())
+ p_obj.setField(oCurr, p_oDto.getAttr(oCurr.toString()));
+
+ String sAux = p_oDto.getAttr(HIDDEN.uid.toString());
+ if (null != sAux)
+ p_obj.m_lUid = Long.parseLong(sAux);
+
+ sAux = p_oDto.getAttr(HIDDEN.stamp.toString());
+ if (null != sAux)
+ p_obj.m_lStamp = Long.parseLong(sAux);
+
+ sAux = p_oDto.getAttr(HIDDEN.snap.toString());
+ if (null != sAux)
+ p_obj.m_lLastSnap = Long.parseLong(sAux);
+
+ sAux = p_oDto.getAttr(HIDDEN.batch.toString());
+ p_obj.setBatchNum((null != sAux) ? Long.parseLong(sAux) : 0);
+
+ // Special treatment for package - only needed for root BaseBusinessObj
+ // this is so only to make XML more compact
+ p_obj.m_sPkg = p_oDto.getAttr(BobjStdDTO.BOBJ_PACKAGE);
+ } // ________________________________
+
+ public static final BaseBusinessObject getFromDTO(BobjStdDTO p_oDto)
+ throws Exception {
+ return BaseBusinessObject.fromDTO(p_oDto);
+ } // ________________________________
+
+ private static BaseBusinessObject fromDTO(BobjStdDTO p_oDto) throws Exception {
+ if (null == p_oDto)
+ return null;
+
+ Class oClass = Class.forName(p_oDto.fullClassName());
+ Constructor CC = oClass
+ .getConstructor(new Class[] { BobjStdDTO.class });
+ BaseBusinessObject oRet = (BaseBusinessObject) CC
+ .newInstance(new Object[] { p_oDto });
+
+ commonFieldsFromDTO(oRet, p_oDto);
+ return oRet;
+ } // ________________________________
+
+ private void putStdAtts(BobjStdDTO p_oRet) {
+ try {
+ p_oRet.addAttr(ATTRIB.rol.toString(), getRole());
+ // if (this instanceof XtfStorable)
+ // p_oRet.addAttr(HIDDEN.type.toString(),((XtfStorable)this).getSnapType());
+ if (m_lStamp > 0)
+ p_oRet
+ .addAttr(HIDDEN.stamp.toString(), Long
+ .toString(m_lStamp));
+ if (m_lLastSnap > 0)
+ p_oRet.addAttr(HIDDEN.snap.toString(), Long
+ .toString(m_lLastSnap));
+ if (!Util.isNullString(m_sDtSnap))
+ p_oRet.addAttr(HIDDEN.dtSnap.toString(), m_sDtSnap);
+ if (getBatchNum() > 0)
+ p_oRet.addAttr(HIDDEN.batch.toString(), Long
+ .toString(getBatchNum()));
+ if (!Util.isNullString(m_sPkg))
+ p_oRet.addAttr(BobjStdDTO.BOBJ_PACKAGE, m_sPkg);
+ } catch (Exception e1) {
+ }
+ } // ________________________________
+
+ public static final BobjStdDTO getDtoList(Class p_Class,
+ List<? extends BaseBusinessObject> p_oBobList) throws Exception {
+
+ if (null == p_oBobList || p_oBobList.isEmpty()) {
+ return null;
+ }
+
+ // Create a list of DTOs from the BaseBusinessObject list...
+ List<BobjStdDTO> dtoList = new ArrayList<BobjStdDTO>();
+ for (BaseBusinessObject oCurr : p_oBobList) {
+ dtoList.add(oCurr.toDTO());
+ }
+
+ // Package up the DTO list in a parent DTO and return ...
+ return new BobjStdDTO(p_Class.getSimpleName(), null, dtoList);
+ } // __________________________________
+
+ public static BaseBusinessObject getRoleFromList(String p_sRole,
+ List<? extends BaseBusinessObject> p_oL) {
+ if (null == p_sRole)
+ return null;
+ if (null == p_oL)
+ return null;
+ for (BaseBusinessObject oCurr : p_oL)
+ if (p_sRole.equals(oCurr.getRole()))
+ return oCurr;
+ return null;
+ } // __________________________________
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/BobjStdDTO.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/BobjStdDTO.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/BobjStdDTO.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,533 @@
+/*
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * {@link org.jboss.soa.esb.util.BaseBusinessObject} Data Transfer Object.
+ * <p/>
+ * {@link org.jboss.soa.esb.util.BaseBusinessObject} implementations use this
+ * class to create a serialized XML representation of their data. They do this
+ * in their {@link org.jboss.soa.esb.util.BaseBusinessObject#toDTO()} method
+ * implementation.
+ * <p/>
+ * This serialized XML form is used for object persistense. The DTO is also
+ * decorated with the following properties to aid lookup and processing
+ * of their persisted form:
+ * <ul>
+ * <li><b>{@link #getUid() UID}</b> //TODO: Define!!</li>
+ * <li><b>{@link #getStamp()() Stamp}</b> //TODO: Define!!</li>
+ * <li><b>{@link #getSnap()() Snap}</b> //TODO: Define!!</li>
+ * <li><b>{@link #getSnapType()()() SnapType}</b> //TODO: Define!!</li>
+ * <li><b>{@link #getSnapDate()()()() SnapDate}</b> //TODO: Define!!</li>
+ * <li><b>{@link #getBatch()()() Batch}</b> //TODO: Define!!</li>
+ * </ul>
+ *
+ * @see #getFromXml(String)
+ * @author <a href="mailto:schifest at gmail.com">Esteban Shifman</a>
+ */
+
+ at SuppressWarnings("serial")
+public class BobjStdDTO implements Serializable {
+ private static final transient String s_sCharset = "ISO-8859-1";
+
+ public static String getCharset() {
+ return s_sCharset;
+ }
+
+ private static final transient String s_sEncoding = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
+
+ // Some attribute names for the toXML() and fromXML()
+ public final static String BOBJ_PACKAGE = "__BobjPkg";
+
+ public final static String BOBJ_CLASS = "__Class";
+
+ protected String m_sClassNm;
+
+ protected String m_sElemNm;
+
+ protected Map<String, Object> m_oAtts;
+
+ protected List<BobjStdDTO> m_oChild;
+
+ protected String[][] m_saaLocators;
+
+ public void setLocators(String[][] p_saa) {
+ m_saaLocators = p_saa;
+ }
+
+ public String[][] getLocators() {
+ return m_saaLocators;
+ }
+
+ // Getters
+ public String classNm() {
+ return m_sClassNm;
+ }
+
+ public String elementNm() {
+ return m_sElemNm;
+ }
+
+ public boolean isList() {
+ return null != m_oChild;
+ }
+
+ public boolean isEmpty() {
+ return (isList()) ? (m_oChild).isEmpty() : m_oAtts.isEmpty();
+ }
+
+ protected BobjStdDTO(String p_sClassNm, String p_sElemNm,
+ List<BobjStdDTO> p_oList) {
+ initialize(p_sClassNm, p_sElemNm, p_oList);
+ }
+
+ private void initialize(String p_sClassNm, String p_sElemNm,
+ List<BobjStdDTO> p_oList) {
+ m_sClassNm = p_sClassNm;
+ m_sElemNm = (null != p_sElemNm) ? p_sElemNm : m_sClassNm
+ .substring(1 + m_sClassNm.lastIndexOf("."));
+ m_oChild = p_oList;
+ if (null == m_oChild)
+ m_oAtts = new HashMap<String, Object>();
+ } // __________________________________
+
+ private BobjStdDTO(Element p_n) throws Exception {
+ String sElem = p_n.getNodeName();
+
+ String sClass = null;
+ try {
+ sClass = p_n.getAttribute(BOBJ_CLASS);
+ } catch (Exception eC) {
+ }
+ sClass = (null == sClass) ? sElem : ("".equals(sClass)) ? sElem
+ : sClass;
+ p_n.removeAttribute(BOBJ_CLASS);
+
+ String sList = null;
+ try {
+ sList = p_n.getAttribute("List");
+ } catch (Exception eL) {
+ }
+ boolean m_bList = (null == sList) ? false : ("".equals(sList)) ? false
+ : true;
+ p_n.removeAttribute("List");
+
+ NodeList NL = p_n.getChildNodes();
+ int iQch = NL.getLength();
+ if (m_bList) {
+ List<BobjStdDTO> olCh = new ArrayList<BobjStdDTO>();
+ for (int i1 = 0; i1 < iQch; i1++) {
+ Node oCurr = NL.item(i1);
+ if (Node.ELEMENT_NODE != oCurr.getNodeType())
+ continue;
+ BobjStdDTO oThisCh = new BobjStdDTO((Element) NL.item(i1));
+ oThisCh.m_sElemNm = oThisCh.m_sClassNm = sClass;
+ olCh.add(oThisCh);
+ }
+ initialize(sClass, sElem, olCh);
+ return;
+ }
+
+ initialize(sClass, sElem, null);
+ this.addMap(mapFromAtts(p_n.getAttributes()));
+
+ for (int i1 = 0; i1 < iQch; i1++) {
+ Node oCurr = NL.item(i1);
+ if (Node.ELEMENT_NODE != oCurr.getNodeType())
+ continue;
+ this.addDto(((Element) oCurr).getNodeName(), new BobjStdDTO(
+ ((Element) oCurr)));
+ }
+ } // __________________________________
+
+ private void setLongAttr(String p_s, long pL) {
+ try {
+ addAttr(p_s, Long.toString(pL));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } // __________________________________
+
+ private void setStringAttr(String p_s, String pVal) {
+ try {
+ addAttr(p_s, pVal);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } // __________________________________
+
+ private long attrAsLong(String p_s) {
+ try {
+ String sVal = getAttr(p_s);
+ if (!Util.isNullString(sVal))
+ return Long.parseLong(sVal);
+ } catch (Exception e) {/* OK just fall through and return default */
+ }
+ return 0;
+ } // __________________________________
+
+ private String attrAsString(String p_s) {
+ try {
+ return getAttr(p_s);
+ } catch (Exception e) {/* OK just fall through and return default */
+ }
+ return null;
+ } // __________________________________
+
+ public long getStamp() {
+ return attrAsLong(BaseBusinessObject.HIDDEN.stamp.toString());
+ }
+
+ public long getUid() {
+ return attrAsLong(BaseBusinessObject.HIDDEN.uid.toString());
+ }
+
+ public long getSnap() {
+ return attrAsLong(BaseBusinessObject.HIDDEN.snap.toString());
+ }
+
+ public long getBatch() {
+ return attrAsLong(BaseBusinessObject.HIDDEN.batch.toString());
+ }
+
+ public String getSnapType() {
+ return attrAsString(BaseBusinessObject.HIDDEN.type.toString());
+ }
+
+ public String getSnapDate() {
+ return attrAsString(BaseBusinessObject.HIDDEN.dtSnap.toString());
+ }
+
+ public void setStamp(long pL) {
+ setLongAttr(BaseBusinessObject.HIDDEN.stamp.toString(), pL);
+ }
+
+ public void setUid(long pL) {
+ setLongAttr(BaseBusinessObject.HIDDEN.uid.toString(), pL);
+ }
+
+ public void setSnap(long pL) {
+ setLongAttr(BaseBusinessObject.HIDDEN.snap.toString(), pL);
+ }
+
+ public void setBatch(long pL) {
+ setLongAttr(BaseBusinessObject.HIDDEN.batch.toString(), pL);
+ }
+
+ public void setSnapType(String pS) {
+ setStringAttr(BaseBusinessObject.HIDDEN.type.toString(), pS);
+ }
+
+ public void setSnapDate(String pS) {
+ setStringAttr(BaseBusinessObject.HIDDEN.dtSnap.toString(), pS);
+ }
+
+ public String fullClassName() {
+ String sPkg = "";
+ try {
+ sPkg = getAttr(BobjStdDTO.BOBJ_PACKAGE);
+ } catch (Exception e) {/* just leave it empty */
+ }
+ String sConstrPkg = (sPkg.endsWith(".")) ? sPkg : sPkg + ".";
+ return sConstrPkg + classNm();
+ } // __________________________________
+
+ public List<? extends BaseBusinessObject> getChildObjList(String p_sElem,
+ Class pCls) throws Exception {
+ BobjStdDTO oChDto = this.getDTO(p_sElem);
+ if (null == oChDto)
+ return null;
+ if (!oChDto.isList())
+ throw new Exception("Child DTO is not List");
+ return oChDto.listDtoToList(pCls);
+ } // __________________________________
+
+ private List<BaseBusinessObject> listDtoToList(Class pCls) throws Exception {
+ if (!isList())
+ throw new Exception("BObjStdDTO is not a List");
+ Class[] oaCls = { BobjStdDTO.class };
+ Constructor CC = pCls.getConstructor(oaCls);
+ List<BaseBusinessObject> LL = new ArrayList<BaseBusinessObject>();
+ Object[] oaParms = new BobjStdDTO[1];
+ for (BobjStdDTO oCurr : m_oChild) {
+ oaParms[0] = oCurr;
+ LL.add((BaseBusinessObject) CC.newInstance(oaParms));
+ }
+ return (LL.size() > 0) ? LL : null;
+ } // __________________________________
+
+ public Map<String, Object> getAttrMap() throws Exception {
+ return m_oAtts;
+ } // __________________________________
+
+ public BobjStdDTO getDTO(String p_sKey) throws Exception {
+ if (isList())
+ throw new Exception("BObjStdDTO is a List");
+ Object oRet = m_oAtts.get(p_sKey);
+ if (null == oRet)
+ return null;
+ if (oRet instanceof BobjStdDTO)
+ return (BobjStdDTO) oRet;
+ throw new Exception("Value is not BObjStdDTO");
+ } // __________________________________
+
+ public String getAttr(String p_sAttrName) throws Exception {
+ if (isList()) {
+ throw new UnsupportedOperationException("BObjStdDTO is a List. Cannot call getAttr method. Use isList to check!");
+ }
+ Object oRet = m_oAtts.get(p_sAttrName);
+ if (null == oRet) {
+ return null;
+ }
+ if (oRet instanceof String) {
+ return (String) oRet;
+ }
+ throw new IllegalArgumentException("p_sAttrName is not an attribute");
+ } // __________________________________
+
+ @SuppressWarnings("unchecked")
+ public void addAttr(String p_sKey, String p_sAtt) throws Exception {
+ if (isList())
+ throw new Exception("BObjStdDTO is a List");
+ if (null == p_sKey)
+ return;
+ m_oAtts.remove(p_sKey);
+ if (null != p_sAtt)
+ if (p_sAtt.trim().length() > 0)
+ m_oAtts.put(p_sKey, p_sAtt.trim());
+ } // __________________________________
+
+ @SuppressWarnings("unchecked")
+ public void addDto(String p_sKey, BobjStdDTO p_oDto) throws Exception {
+ if (isList())
+ throw new Exception("BObjStdDTO is a List");
+ if (null == p_sKey)
+ return;
+ m_oAtts.remove(p_sKey);
+ if (null == p_oDto)
+ return;
+ if (p_oDto.isEmpty())
+ return;
+ p_oDto.m_sElemNm = p_sKey;
+ m_oAtts.put(p_sKey, p_oDto);
+ } // __________________________________
+
+ @SuppressWarnings("unchecked")
+ private void addMap(Map<String, Object> p_oM) throws Exception {
+ if (isList())
+ throw new Exception("BObjStdDTO is a List");
+ if (null == p_oM)
+ return;
+ for (Map.Entry<String, Object> oCurr : p_oM.entrySet())
+ m_oAtts.put(oCurr.getKey(), oCurr.getValue());
+ } // __________________________________
+
+ public String toXml() throws Exception {
+ return toXml(false);
+ }
+
+ public String toXml(boolean p_bDecl) throws Exception {
+ Document oDoc = toDoc();
+ oDoc.normalize();
+ DOMSource src = new DOMSource(oDoc);
+
+ OutputStream oStrm = new ByteArrayOutputStream(1000);
+ StreamResult res = new StreamResult(oStrm);
+
+ Transformer oTf = TransformerFactory.newInstance().newTransformer();
+ oTf.setOutputProperty(OutputKeys.INDENT, "no");
+ oTf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, (p_bDecl) ? "no"
+ : "yes");
+
+ oTf.setOutputProperty(OutputKeys.ENCODING, s_sCharset);
+ oTf.transform(src, res);
+ return oStrm.toString();
+ } // __________________________________
+
+ public Document toDoc() {
+ DocumentBuilder oDB = null;
+ try {
+ oDB = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ } catch (Exception e) {
+ }
+ Document oDoc = oDB.newDocument();
+ oDoc.appendChild(toElement(oDoc));
+ return oDoc;
+ } // __________________________________
+
+ public Node toElement(Document p_oDoc) {
+ return (isList()) ? listToElement(p_oDoc) : mapToElement(p_oDoc);
+ } // __________________________________
+
+ private Node mapToElement(Document p_oDoc) {
+ if (null == m_oAtts)
+ return null;
+ Element onRet = p_oDoc.createElement(m_sElemNm);
+ for (Map.Entry<String, Object> oCurr : m_oAtts.entrySet()) {
+ if (oCurr.getValue() instanceof BobjStdDTO) {
+ onRet.appendChild(((BobjStdDTO) oCurr.getValue())
+ .toElement(p_oDoc));
+ continue;
+ } else
+ // System.out.println("Elem<"+sKey+">
+ // Val<"+oVal.toString()+">");
+ onRet.setAttribute(oCurr.getKey(), oCurr.getValue().toString());
+ }
+
+ boolean bPutClass = (null != m_sClassNm)
+ && (!m_sElemNm.equals(m_sClassNm));
+ if (bPutClass)
+ onRet.setAttribute(BOBJ_CLASS, m_sClassNm);
+ else
+ onRet.removeAttribute(BOBJ_CLASS);
+
+ return onRet;
+ } // __________________________________
+
+ private Node listToElement(Document p_oDoc) {
+ if (null == m_oChild)
+ return null;
+ if (m_oChild.isEmpty())
+ return null;
+
+ Element onRet = p_oDoc.createElement(m_sElemNm);
+ onRet.setAttribute("List", "yes");
+ if (!m_sElemNm.equals(m_sClassNm))
+ onRet.setAttribute(BOBJ_CLASS, m_sClassNm);
+
+ for (BobjStdDTO oCurr : m_oChild) {
+ oCurr.m_sClassNm = null;
+ oCurr.m_sElemNm = "it";
+ onRet.appendChild(oCurr.toElement(p_oDoc));
+ }
+ return onRet;
+ } // __________________________________
+
+ public static synchronized BobjStdDTO getFromXml(String xmlBob)
+ throws Exception {
+
+ if(Util.isNullString(xmlBob)) {
+ throw new IllegalArgumentException("null or empty 'xmlBob' arg in call.");
+ }
+
+ StringBuffer sb = new StringBuffer(s_sEncoding).append("\n")
+ .append(xmlBob);
+ DocumentBuilder oDB = DocumentBuilderFactory.newInstance()
+ .newDocumentBuilder();
+ Document oDoc = oDB.parse(new ByteArrayInputStream(sb.toString()
+ .getBytes(s_sCharset)));
+ return new BobjStdDTO(oDoc.getDocumentElement());
+ } // __________________________________
+
+ private static synchronized Map<String, Object> mapFromAtts(
+ NamedNodeMap p_oNnm) {
+ if (null == p_oNnm)
+ return null;
+ int iQatt = p_oNnm.getLength();
+ if (iQatt < 1)
+ return null;
+ Map<String, Object> omAtts = new HashMap<String, Object>();
+ for (int i2 = 0; i2 < iQatt; i2++) {
+ Node nAtt = p_oNnm.item(i2);
+ omAtts.put(nAtt.getNodeName(), nAtt.getNodeValue());
+ }
+ return omAtts;
+ } // __________________________________
+
+ public void Dump(String p_sTitle) throws Exception {
+ System.out.println(p_sTitle);
+ Dump(0);
+ } // __________________________________
+
+ public void Dump(int p_iLev) throws Exception {
+ byte[] ba = new byte[3 * p_iLev];
+ Arrays.fill(ba, (byte) ' ');
+ String sTab = new String(ba);
+ System.out.print(sTab + "Elem " + m_sElemNm + " Class " + m_sClassNm);
+ if (isList()) {
+ System.out.println(" LIST");
+ for (BobjStdDTO oCurr : m_oChild)
+ oCurr.Dump(1 + p_iLev);
+ return;
+ }
+ System.out.print("\n" + sTab);
+
+ for (EnumMap.Entry<String, Object> oCurr : m_oAtts.entrySet()) {
+ if (oCurr.getValue() instanceof String)
+ System.out.print(" " + oCurr.getKey() + "<"
+ + oCurr.getValue() + ">");
+ }
+ System.out.println();
+ for (EnumMap.Entry<String, Object> oCurr : m_oAtts.entrySet()) {
+ if (oCurr.getValue() instanceof BobjStdDTO)
+ ((BobjStdDTO) oCurr.getValue()).Dump(1 + p_iLev);
+ }
+ } // __________________________________
+
+ public BaseBusinessObject getBobj(String p_sObj)
+ { if (null == p_sObj) return null;
+ try
+ { BobjStdDTO oDto = this.getDTO(p_sObj);
+ return BaseBusinessObject.getFromDTO(oDto);
+ }
+ catch (Exception e) {return null; }
+ } //__________________________________
+
+ @SuppressWarnings("unchecked")
+ public void addBobj(String p_sKey, BaseBusinessObject p_oBob) throws Exception
+ { if (isList()) throw new Exception("BObjStdDTO is a List");
+ if (null == p_sKey) return;
+ m_oAtts.remove(p_sKey);
+ if (null == p_oBob) return;
+ BobjStdDTO oDto = p_oBob.toDTO();
+ if (oDto.isEmpty()) return;
+ oDto.m_sElemNm=p_sKey;
+ m_oAtts.put(p_sKey,oDto);
+ } //__________________________________
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/FtpClientUtil.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,297 @@
+/*
+* 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.util;
+
+import java.io.File;
+import java.util.List;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+import com.enterprisedt.net.ftp.FTPClient;
+import com.enterprisedt.net.ftp.FTPConnectMode;
+import com.enterprisedt.net.ftp.FTPTransferType;
+
+/**
+ * Simplified FTP transfers
+ * <p>Description: Implements a simple set of FTP functionality
+ * Parameters to establish the FTP connection are provided at construction time
+ * and cannot change during the lifetime of the object
+ * <br/>Hides low level details. Current implementation is based on the
+ * "Entreprise Distributed Technology edtFTPj" library
+ * but this can be changed with no impact to existing code, just by changing
+ * this class without modifying the signature of it's public methods
+ * </p>
+ */
+
+public class FtpClientUtil
+{
+ public static final String PARMS_FTP_SERVER = "ftpServer";
+ public static final String PARMS_USER = "ftpUser";
+ public static final String PARMS_PASSWD = "ftpPassword";
+ public static final String PARMS_PORT = "ftpPort";
+ public static final String PARMS_REMOTE_DIR = "ftpRemoteDir";
+ public static final String PARMS_LOCAL_DIR = "ftpLocalDir";
+ public static final String PARMS_ASCII = "ftpAscii";
+ public static final String PARMS_PASSIVE = "ftpPassive";
+
+ private static final String TMP_SUFFIX = ".rosettaPart";
+
+ public enum XFER_TYPE
+ {ascii
+ ,binary
+ };
+
+ private ConfigTree m_oParms;
+ private String m_sFtpServer ,m_sUser ,m_sPasswd;
+ private String m_sRemoteDir ,m_sLocalDir;
+ private int m_iPort;
+ private boolean m_bPassive;
+ public String getRemoteDir() { return m_sRemoteDir; }
+
+ private FTPClient m_oConn = new FTPClient();
+ private FTPTransferType m_oXferType = FTPTransferType.BINARY;
+
+ /**
+ * Checks validity and completeness of parameters, and keeps the info internally
+ * for subsequent FTP requests
+ * @param p_oP ConfigTree
+ * @throws Exception : if parameters are invalid or incomplete
+ * <li>Parameters: (XML attributes at the root level) </li>
+ * <li> ftpServer = name or IP of FTP server </li>
+ * <li> ftpUser = login ID for server </li>
+ * <li> ftpPassword </li>
+ * <li> localDirURI = absolute path in the local filesystem </li>
+ * <li> remoteDirURI = remote path is relative to ftp user home in remote
+ * computer </li>
+ */
+
+ public FtpClientUtil (ConfigTree p_oP, boolean p_bConnect) throws Exception
+ { m_oParms = p_oP;
+ initialize(p_bConnect);
+ } //_________________________________
+
+ public FtpClientUtil (List<KeyValuePair> attribs, boolean connect) throws Exception
+ {
+ m_oParms = new ConfigTree("fromProps");
+ for (KeyValuePair oCurr : attribs)
+ m_oParms.setAttribute(oCurr.getKey(),oCurr.getValue());
+ initialize(connect);
+ } //__________________________________
+
+ private void initialize(boolean bConnect) throws Exception
+ {
+ checkParms();
+ if (bConnect)
+ {
+ m_oConn.setRemoteHost (m_sFtpServer);
+ m_oConn.setRemotePort(m_iPort);
+ m_oConn.connect();
+ for (int i1=0; i1<10 && ! m_oConn.connected(); i1++)
+ Thread.sleep(200);
+ if (! m_oConn.connected())
+ throw new Exception("Can't connect to FTP server");
+ m_oConn.user (m_sUser);
+ m_oConn.password (m_sPasswd);
+ m_oConn.setConnectMode ((m_bPassive) ? FTPConnectMode.PASV : FTPConnectMode.ACTIVE);
+ }
+ } //__________________________________
+ /**
+ * Terminates ftp session and frees resources
+ * <li>Well behaved programs should make sure to call this method </li>
+ */
+ public void quit ()
+ { if (null != m_oConn)
+ try { m_oConn.quit(); }
+ catch (Exception e) {}
+ } //_________________________________
+
+ /**
+ * Deletes specified file in remote directory
+ * @param p_sFile String : filename to delete. Method will attempt to delete
+ * file with rightmost node of argument within remote directory specified in 'remoteDirURI'
+ * @throws Exception : if ftp connection cannot be established, or file
+ * cannot be deleted in remote directory
+ */
+ public void deleteRemoteFile (String p_sFile) throws Exception
+ { m_oConn.delete(getRemoteDir()+"/"+new File(p_sFile).getName());
+ } //_________________________________
+
+ public void remoteDelete (File p_oFile) throws Exception
+ { m_oConn.delete(fileToFtpString(p_oFile));
+ } //_________________________________
+
+ /**
+ * Gets the list of files in the remote directory that end with arg0
+ * @param p_sSuffix String : retrieve only files that end with that suffix - all files if null
+ * @throws Exception : if ftp connection cannot be established, or problems encountered
+ */
+ public String[] getFileListFromRemoteDir (String p_sSuffix) throws Exception
+ {
+ String sSuffix = (null==p_sSuffix)?"*":"*"+p_sSuffix;
+ return m_oConn.dir(sSuffix);
+ } //_________________________________
+
+ /**
+ * Change remote directory
+ * @param p_sDir String : directory to set
+ * @throws Exception : if ftp connection cannot be established, or problems encountered
+ */
+ public void setRemoteDir (String p_sDir) throws Exception
+ {
+ m_oConn.chdir(p_sDir);
+ } //_________________________________
+
+ /**
+ * Renames specified file in remote directory to specified new name
+ * @param p_sFrom String : filename to rename
+ * @param p_sTo String : new filename
+ * @throws Exception : if ftp connection cannot be established, or file
+ * cannot be renamed to new name in remote directory
+ * <li>Method will attempt to rename file with rightmost node of argument
+ * within remote directory specified in 'remoteDirURI', to new name inside
+ * the SAME remote directory
+ */
+ public void renameInRemoteDir (String p_sFrom, String p_sTo) throws Exception
+ {
+ String sRmtFrom = new File(p_sFrom).getName();
+ String sRmtTo = new File(p_sTo).getName();
+
+ try { m_oConn.rename (getRemoteDir()+"/"+sRmtFrom,getRemoteDir()+"/"+sRmtTo); }
+ catch (Exception e)
+ { String sMess = this.getClass().getSimpleName()
+ +" can't rename in remote directory <"
+ +e.getMessage()+">"
+ ;
+ throw new Exception(sMess);
+ }
+ } //_________________________________
+
+ public void remoteRename(File p_oFrom, File p_oTo) throws Exception
+ {
+ try { m_oConn.rename (fileToFtpString(p_oFrom),fileToFtpString(p_oTo)); }
+ catch (Exception e)
+ { String sMess = this.getClass().getSimpleName()
+ +" can't rename in remote directory <"
+ +e.getMessage()+">"
+ ;
+ throw new Exception(sMess);
+ }
+ } //_________________________________
+
+ /**
+ * Uploads specified file from local directory (localDirURI) to remote
+ * directory (remoteDirURI)
+ * @param p_sFile String : filename to upload
+ * @throws Exception : if ftp connection cannot be established, or file
+ * cannot be uploaded
+ * <li> local file will be renamed during transfer ('.xferNotReady' appended
+ * to name)</li>
+ * <li> upon successful completion. the suffix '.xferDone' will be appended
+ * to the original filename </li>
+ */
+ public void uploadFile (File p_oFile, String p_sRemoteName) throws Exception
+ {
+ String sRemoteOK = getRemoteDir() + "/" + p_sRemoteName;
+ String sRemoteTmp = sRemoteOK+TMP_SUFFIX;
+ m_oConn.setType(m_oXferType);
+ m_oConn.put(fileToFtpString(p_oFile),sRemoteTmp);
+ m_oConn.rename(sRemoteTmp,sRemoteOK);
+ } //_________________________________
+
+ /**
+ * Downloads specified file from remote directory (remoteDirURI) to local
+ * directory (localDirURI)
+ * @param p_sFile String : filename to download
+ * @throws Exception : if ftp connection cannot be established, or file
+ * cannot be downloaded
+ * <li> local file is assigned a temporary name during transfer </li>
+ * <li> upon successful completion, local temporary file will be renamed to
+ * name specified in argument, and suffix '.xferDone' will be appended
+ * to the original filename in the remote directory </li>
+ */
+ public void downloadFile (String p_sFile, String p_sFinalName) throws Exception
+ {
+ File oLocalDir = new File(m_sLocalDir);
+ File oLclFile= File.createTempFile("Rosetta_",TMP_SUFFIX,oLocalDir);
+
+ try { oLclFile.delete(); }
+ catch (Exception e) {}
+ m_oConn.setType(m_oXferType);
+ m_oConn.get(fileToFtpString(oLclFile),p_sFile);
+
+ File oNew = new File(oLocalDir,p_sFinalName);
+ if (oNew.exists()) oNew.delete();
+ oLclFile.renameTo(oNew);
+ } //_________________________________
+
+ // Beware !!! The logic here seems wrong, but it works
+ // It appears that there's some kind of bug in the edtftpj.jar library
+ // The !XFER_TYPE.ascii.equals(p_oMode) should NOT be negated
+ // But it works when negated (newlines from Unix to DOS)
+ private void setXferType (XFER_TYPE p_oMode)
+ { m_oXferType = !XFER_TYPE.ascii.equals(p_oMode)
+ ? FTPTransferType.ASCII : FTPTransferType.BINARY;
+ } //_________________________________
+
+ private void checkParms() throws Exception
+ {
+ m_sFtpServer = m_oParms.getAttribute(PARMS_FTP_SERVER);
+ if (null==m_sFtpServer) throw new Exception ("No FTP server specified");
+
+ m_sUser = m_oParms.getAttribute(PARMS_USER);
+ if (null==m_sUser) throw new Exception ("No username specified for FTP");
+
+ m_sPasswd = m_oParms.getAttribute(PARMS_PASSWD);
+ if (null==m_sPasswd) throw new Exception ("No password specified for FTP");
+
+ m_sRemoteDir = m_oParms.getAttribute(PARMS_REMOTE_DIR);
+ if (null==m_sRemoteDir)
+ m_sRemoteDir = "";
+
+ m_sLocalDir = m_oParms.getAttribute(PARMS_LOCAL_DIR);
+ if (null==m_sLocalDir)
+ m_sLocalDir = ".";
+
+ String sAux = m_oParms.getAttribute(PARMS_PORT);
+ m_iPort = (null==sAux) ? 21 : Integer.parseInt(sAux);
+
+ boolean bAscii = false;
+ sAux = m_oParms.getAttribute(PARMS_ASCII);
+ if (null!=sAux)
+ bAscii = Boolean.parseBoolean(sAux);
+ setXferType((bAscii)?XFER_TYPE.ascii:XFER_TYPE.binary);
+
+ m_bPassive = false;
+ sAux = m_oParms.getAttribute(PARMS_PASSIVE);
+ m_bPassive = (null!=sAux) && Boolean.parseBoolean(sAux);
+
+ return;
+ } //__________________________________
+
+ public static String fileToFtpString(File p_oF)
+ {
+ return(null==p_oF) ? null
+ : p_oF.toString().replace("\\","/");
+ } //________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/NagiosStandaloneHeartbeat.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/NagiosStandaloneHeartbeat.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/NagiosStandaloneHeartbeat.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+
+
+package org.jboss.soa.esb.util;
+
+public class NagiosStandaloneHeartbeat
+{
+ public NagiosStandaloneHeartbeat
+ (String pNagiosServer
+ ,int pPort
+ ,String pService
+ ,String pDescription
+ )
+ {
+
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/ObjLocator.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/ObjLocator.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/ObjLocator.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,93 @@
+/*
+* 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.util;
+
+import java.io.Serializable;
+
+ at SuppressWarnings("serial")
+public class ObjLocator implements Serializable
+{
+ private long m_lUid;
+ private Object [] m_oaLocs;
+
+ public long getUid() { return m_lUid; }
+ public String [] getStrings() { return (String []) m_oaLocs; }
+ public int getColumnCount()
+ { return (null == m_oaLocs) ? 0 : m_oaLocs.length;
+ } //__________________________________
+
+ public ObjLocator(long p_lUid, Object [] p_sa)
+ { m_lUid = p_lUid;
+ m_oaLocs = (null == p_sa) ? new Object [0] : p_sa;
+ for (int i1=0; i1<m_oaLocs.length;i1++)
+ if (null == m_oaLocs[i1]) m_oaLocs[i1]="";
+ } //__________________________________
+
+ public Object get(int p_iCol)
+ { return (null == m_oaLocs) ? ""
+ :(p_iCol < 0 || p_iCol >= m_oaLocs.length) ? ""
+ : m_oaLocs[p_iCol];
+ } //__________________________________
+
+ public void set(int p_iCol, Object p_o)
+ { if (null == m_oaLocs) return;
+ if (p_iCol < 0 || p_iCol >= m_oaLocs.length) return;
+ m_oaLocs[p_iCol] = p_o;
+ } //__________________________________
+
+ public boolean equals(Object p_o)
+ { return (p_o instanceof ObjLocator)
+ ? m_lUid == ((ObjLocator)p_o).getUid()
+ : false;
+ } //__________________________________
+
+ public static ObjLocator find(long p_l, ObjLocator[] p_ola)
+ { ObjLocator oRet;
+ if (null != p_ola)
+ for (int i1=0; i1<p_ola.length;i1++)
+ if (p_l == (oRet = p_ola[i1]).getUid()) return oRet;
+ return null;
+ } //__________________________________
+
+ public String toString()
+ { StringBuffer sb = new StringBuffer(200);
+ sb.append("ObjLocator: ").append(m_lUid).append(" <");
+ for (int i1=0; i1<m_oaLocs.length;i1++)
+ { if (i1 > 0) sb.append(" ");
+ sb.append(m_oaLocs[i1].toString());
+ }
+ sb.append(">");
+ return sb.toString();
+ } //__________________________________
+
+ public static long [] getUids(ObjLocator[] p_ola)
+ { long [] laRet = new long [] {};
+ if (null == p_ola) return laRet;
+ if (p_ola.length<1) return laRet;
+ laRet = new long[p_ola.length];
+ for (int i1=0; i1<laRet.length; i1++)
+ laRet[i1] = p_ola[i1].getUid();
+
+ return laRet;
+ } //__________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/ObjLocatorSorter.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/ObjLocatorSorter.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/ObjLocatorSorter.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,87 @@
+/*
+* 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.util;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+public class ObjLocatorSorter
+{
+ private java.util.List<ObjLocator> m_olRows;
+ private int m_iQcols;
+ private char[] m_caSrt;
+
+ public ObjLocatorSorter(ObjLocator[] p_oa)
+ { m_iQcols = (null==p_oa) ? 0
+ : p_oa.length<1 ? 0
+ : p_oa[0].getColumnCount();
+ m_olRows = Arrays.asList(p_oa);
+ } //________________________________
+
+ public ObjLocator[] sort (int p_iCol)
+ { if (null == m_caSrt)
+ { m_caSrt = new char[m_iQcols];
+ for (int i1=0; i1<m_caSrt.length; i1++) m_caSrt[i1]='d';
+ }
+ ObjLocator [] oaLoc = new ObjLocator[m_olRows.size()];
+ m_olRows.toArray(oaLoc);
+ Arrays.sort(oaLoc,new RowCmp(p_iCol,ascOrDesc(oaLoc,p_iCol)));
+ m_olRows = Arrays.asList(oaLoc);
+ return oaLoc;
+ } //________________________________
+ private static char ascOrDesc(ObjLocator[] p_oa, int p_iCol)
+ {
+ String sMin = "";
+ for (int i1=0; i1<p_oa.length;i1++)
+ { Object oCurr = p_oa[i1].get(p_iCol);
+ if (! (oCurr instanceof String)) continue;
+ if (sMin.compareToIgnoreCase((String)oCurr) > 0)
+ return 'a';
+ sMin = (String) oCurr;
+ }
+ return 'd';
+ } //________________________________
+
+ // ---------------------------------------------------------
+ // Comparator for Table Columns
+ // ---------------------------------------------------------
+ private class RowCmp implements Comparator<ObjLocator>
+ {
+ int m_iCol;
+ boolean m_bAsc;
+
+ RowCmp(int p_i, char p_c)
+ {
+ m_iCol = p_i;
+ m_bAsc = 'a'==Character.toLowerCase(p_c);
+ } //______________________________
+
+ public int compare(ObjLocator o1, ObjLocator o2)
+ {
+ String s1 = (String) o1.get(m_iCol);
+ String s2 = (String) o2.get(m_iCol);
+ int iCmp = s1.compareToIgnoreCase(s2);
+ return (m_bAsc) ? iCmp : -iCmp;
+ } //______________________________
+ } //_______________________________________________
+} //______________________________________________________
+
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/src/org/jboss/soa/esb/util/Util.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,197 @@
+/*
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.Serializable;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.TTCCLayout;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+public class Util
+{
+ private Util()
+ {
+ }
+
+ public static void dumpSysProps(PrintStream p_OS)
+ {
+ String[] sa = new String[ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE)
+ .getProperties().size()];
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperties().keySet().toArray(sa);
+ Arrays.sort(sa);
+ for (String sCurr : sa)
+ p_OS.println(sCurr + "="
+ + ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(sCurr));
+ } // __________________________________
+
+ public static boolean isNullString(String p_s)
+ {
+ return (null == p_s) ? true : p_s.trim().length() < 1;
+ } // __________________________________
+
+ public static boolean isLong(String p_s)
+ {
+ if (isNullString(p_s))
+ return false;
+ try
+ {
+ Long.parseLong(p_s);
+ return true;
+ } catch (Exception e)
+ {
+ return false;
+ }
+ } // __________________________________
+
+ public static boolean isPositiveLong(String p_s)
+ {
+ if (isNullString(p_s))
+ return false;
+ try
+ {
+ long lBk = Long.parseLong(p_s);
+ return lBk > 0;
+ } catch (Exception e)
+ {
+ return false;
+ }
+ } // __________________________________
+
+ public static int parseInt(String s)
+ {
+ if (s == null)
+ return 0;
+ String sVal = s.trim();
+ if (sVal.length() < 1)
+ return 0;
+ else
+ try
+ {
+ return Integer.parseInt(s);
+ } catch (NumberFormatException ex)
+ {
+ return 0;
+ }
+ } // __________________________________
+
+ public static long parseLong(String s)
+ {
+ if (s == null)
+ return 0;
+ String sVal = s.trim();
+ if (sVal.length() < 1)
+ return 0;
+ else
+ try
+ {
+ return Long.parseLong(s);
+ } catch (NumberFormatException ex)
+ {
+ return 0;
+ }
+ } // __________________________________
+
+ public static Logger getDefaultLogger(Class p_oCls)
+ {
+ Logger oRet = Logger.getLogger(p_oCls.getName());
+ Appender oApp = new ConsoleAppender(new TTCCLayout("ISO8601"));
+ oRet.addAppender(oApp);
+ return oRet;
+ } // __________________________________
+
+ public static Serializable serialize(Message message)
+ throws ParserConfigurationException, IOException
+ {
+ if (message.getType().equals(org.jboss.soa.esb.message.format.MessageType.JAVA_SERIALIZED))
+ return (Serializable)message;
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ ((org.jboss.internal.soa.esb.message.format.xml.MessageImpl)message).toXML(doc);
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+ return sWriter.toString();
+ } //________________________________
+
+ public static Message deserialize(Serializable serial)
+ throws ParserConfigurationException,SAXException,IOException
+ {
+ if (serial instanceof MessageImpl) //MessageType.JAVA_SERIALIZED
+ return (Message)serial;
+
+ //MessageType.JBOSS_XML
+ InputStream inStream = new ByteArrayInputStream(((String)serial).getBytes());
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(inStream);
+
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl message =
+ new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+ message.fromXML(doc);
+ return message;
+ } //________________________________
+
+ public static List<KeyValuePair> propertiesFromSelector(String selector) throws Exception
+ {
+ // No problem if selector is null - everything in queue will be returned
+ List<KeyValuePair> oRet = new ArrayList<KeyValuePair>();
+ if (! Util.isNullString(selector))
+ for (String sCurr : selector.split(","))
+ {
+ String[] sa = sCurr.split("=");
+ if (sa.length!=2
+ || sa[1].charAt(0)!='\''
+ || sa[1].charAt(-1+sa[1].length())!='\'')
+ throw new Exception("Illegal message selector syntax <"+selector+">");
+ KeyValuePair oNew = new KeyValuePair
+ (sa[0],sa[1].substring(0,-1+sa[1].length()).substring(1));
+ oRet.add(oNew);
+ }
+ return oRet;
+ } //________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/build.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/build.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,128 @@
+<?xml version="1.0"?>
+<project name="build.rosetta.tests" default="org.jboss.esb.rosetta.tests.compile" basedir=".">
+
+ <property name="org.jboss.esb.internal.dest" value="${basedir}/../../../build"/>
+ <property name="org.jboss.esb.module.src.dir" value="../src"/>
+ <property name="org.jboss.esb.module.classes.dir" value="${org.jboss.esb.internal.dest}/classes/rosetta"/>
+ <property name="org.jboss.esb.module.tests.src.dir" value="${basedir}/src"/>
+ <property name="org.jboss.esb.tests.classes.dir" value="${org.jboss.esb.internal.dest}/tests"/>
+ <property name="org.jboss.esb.tests.report.dir" value="${org.jboss.esb.internal.dest}/tests/junit"/>
+ <property name="org.jboss.esb.root.dir" value="../.."/>
+ <property name="org.jboss.esb.module.tests.coverage.dir" value="${org.jboss.esb.internal.dest}/tests/coverage/rosetta"/>
+ <property name="org.jboss.esb.module.classes.instr.dir" value="${org.jboss.esb.module.tests.coverage.dir}/instr" />
+ <property environment="env"/>
+ <property name="org.jboss.esb.ejb3_embedded.lib.dir" value="${org.jboss.esb.root.dir}/../lib/ext/ejb3_embedded"/>
+ <property name="org.jboss.esb.ext.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext"/>
+ <!-- Set deployment properties filename -->
+ <property name="org.jboss.esb.deployment.properties" value="../../../install/deployment.properties"/>
+ <!-- Load deployment properties File -->
+ <property file="${org.jboss.esb.deployment.properties}"/>
+
+ <condition property="org.jboss.esb.ext.lib.dir" value="{org.jboss.esb.jboss.home}/client">
+ <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
+ </condition>
+
+ <path id="org.jboss.esb.tests.base.classpath">
+ <fileset dir="../${org.jboss.esb.ext.lib.dir}" includes="*.jar"/>
+ <pathelement location="${org.jboss.esb.root.dir}/rosetta/tests/resources/etc"/>
+ <pathelement location="${org.jboss.esb.module.classes.dir}"/>
+ <pathelement location="${org.jboss.esb.ejb3_conf.tests.src.dir}"/>
+ <fileset dir="${org.jboss.esb.ejb3_embedded.lib.dir}" includes="jboss-ejb3-all.jar hibernate-all.jar thirdparty-all.jar"/>
+ </path>
+
+ <target name="org.jboss.esb.tests.init">
+ <tstamp>
+ <format property="TODAY" pattern="dd-MM-yy"/>
+ </tstamp>
+
+ <mkdir dir="${org.jboss.esb.tests.classes.dir}"/>
+ <mkdir dir="${org.jboss.esb.tests.report.dir}"/>
+ </target>
+
+ <target name="clean"/>
+
+ <target name="purge" depends="clean">
+ <delete dir="${org.jboss.esb.tests.classes.dir}"/>
+ </target>
+
+ <target name="org.jboss.esb.rosetta.tests.compile" if="org.jboss.esb.buildtests" depends="org.jboss.esb.tests.init">
+
+ <javac
+ destdir="${org.jboss.esb.tests.classes.dir}"
+ classpathref="org.jboss.esb.tests.base.classpath"
+ debug="${org.jboss.esb.debug}"
+ optimize="${org.jboss.esb.optimize}"
+ >
+ <src path="${org.jboss.esb.module.tests.src.dir}"/>
+ </javac>
+
+ </target>
+
+ <!-- ====================================================================== -->
+ <!-- T E S T -->
+ <!-- ====================================================================== -->
+ <target name="org.jboss.esb.rosetta.internal.test">
+ <!-- Instrument the code for code coverage - using emma... -->
+ <delete dir="${org.jboss.esb.module.tests.coverage.dir}" />
+ <mkdir dir="${org.jboss.esb.module.classes.instr.dir}" />
+ <emma>
+ <instr instrpath="${org.jboss.esb.module.classes.dir}"
+ destdir="${org.jboss.esb.module.classes.instr.dir}"
+ metadatafile="${org.jboss.esb.module.tests.coverage.dir}/coverage.emma" />
+ </emma>
+
+ <!-- Run the tests -->
+ <antcall target="org.jboss.esb.services.internal.test.exec"/>
+
+ <!-- Generate the coverage report -->
+ <emma>
+ <report sourcepath="${org.jboss.esb.module.src.dir}" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">
+ <fileset dir="${org.jboss.esb.module.tests.coverage.dir}" >
+ <include name="*.emma" />
+ </fileset>
+ <html outfile="${org.jboss.esb.module.tests.coverage.dir}/index.html" depth="method" columns="name,line,class,method,block"/>
+ </report>
+ </emma>
+ </target>
+
+ <!-- ====================================================================== -->
+ <!-- U N I T A N D F U N C T I O N A L T E S T S -->
+ <!-- ====================================================================== -->
+ <target name="org.jboss.esb.services.internal.test.exec">
+ <echo message="Running tests for module"/>
+ <junit printsummary="yes" haltonerror="yes" haltonfailure="yes" showoutput="no" fork="true">
+ <formatter type="plain" usefile="false"/>
+ <formatter type="xml"/>
+ <batchtest todir="${org.jboss.esb.tests.report.dir}">
+ <fileset dir="${org.jboss.esb.module.tests.src.dir}">
+ <include name="**/**UnitTest.java"/>
+ <include name="**/**FuncTest.java"/>
+ </fileset>
+ </batchtest>
+ <classpath>
+ <!-- using instrumented code for code coverage -->
+ <pathelement location="${org.jboss.esb.module.classes.instr.dir}"/>
+ <pathelement location="${org.jboss.esb.tests.classes.dir}"/>
+ <!-- Need the tests src folder because there may be non-compiled test resources -->
+ <pathelement location="${org.jboss.esb.module.tests.src.dir}"/>
+ <path refid="org.jboss.esb.tests.base.classpath"/>
+ </classpath>
+ <!-- emma jvm args -->
+ <jvmarg value="-Demma.coverage.out.file=${org.jboss.esb.module.tests.coverage.dir}/coverage.emma" />
+ <jvmarg value="-Demma.coverage.out.merge=true" />
+
+ <sysproperty key="org.jboss.esb.test.db.driver" value="${org.jboss.esb.test.db.driver}"/>
+ <sysproperty key="org.jboss.esb.test.db.url" value="${org.jboss.esb.test.db.url}"/>
+ <sysproperty key="org.jboss.esb.test.db.user" value="${org.jboss.esb.test.db.user}"/>
+ <sysproperty key="org.jboss.esb.test.db.password" value="${org.jboss.esb.test.db.password}"/>
+ <sysproperty key="log4j.configuration" value="log4j.xml"/>
+ </junit>
+ <junitreport>
+ <fileset dir="${org.jboss.esb.tests.report.dir}">
+ <include name="*.xml"/>
+ </fileset>
+ <report format="frames" todir="${org.jboss.esb.tests.report.dir}"/>
+ <report format="noframes" todir="${org.jboss.esb.tests.report.dir}"/>
+ </junitreport>
+ </target>
+</project>
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/default.persistence.properties
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/default.persistence.properties 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/default.persistence.properties 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,17 @@
+hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
+#hibernate.connection.release_mode=after_statement
+#hibernate.transaction.flush_before_completion=false
+#hibernate.transaction.auto_close_session=false
+#hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
+#hibernate.hbm2ddl.auto=create-drop
+#hibernate.hbm2ddl.auto=create
+hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
+# Clustered cache with TreeCache
+#hibernate.cache.provider_class=org.jboss.ejb3.entity.TreeCacheProviderHook
+#hibernate.treecache.mbean.object_name=jboss.cache:service=EJB3EntityTreeCache
+#hibernate.dialect=org.hibernate.dialect.HSQLDialect
+hibernate.jndi.java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+hibernate.jndi.java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
+hibernate.bytecode.use_reflection_optimizer=false
+# I don't think this is honored, but EJB3Deployer uses it
+hibernate.bytecode.provider=javassist
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/ejb3-deployment.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/ejb3-deployment.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/ejb3-deployment.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
+ xmlns="urn:jboss:bean-deployer">
+
+ <bean name="EJBDeployment"
+ class="org.jboss.ejb3.embedded.EJB3StandaloneDeployer">
+ <property name="jndiProperties">
+ <inject bean="InitialContextProperties"/>
+ </property>
+ <property name="kernel">
+ <inject bean="jboss.kernel:service=Kernel"/>
+ </property>
+
+ </bean>
+
+</deployment>
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/ejb3-interceptors-aop.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/ejb3-interceptors-aop.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/ejb3-interceptors-aop.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,360 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE aop PUBLIC
+ "-//JBoss//DTD JBOSS AOP 1.0//EN"
+ "http://www.jboss.org/aop/dtd/jboss-aop_1_0.dtd">
+
+<aop>
+ <interceptor class="org.jboss.aspects.remoting.InvokeRemoteInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.aspects.security.SecurityClientInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.aspects.tx.ClientTxPropagationInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.ejb3.remoting.IsLocalInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.aspects.remoting.ClusterChooserInterceptor" scope="PER_VM"/>
+
+ <interceptor class="org.jboss.aspects.tx.TxPropagationInterceptor" scope="PER_VM"/>
+
+ <stack name="ServiceClientInterceptors">
+ <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+ </stack>
+
+ <stack name="AsynchronousStatelessSessionClientInterceptors">
+ <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+ </stack>
+
+ <stack name="AsynchronousStatefulSessionClientInterceptors">
+ <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+ </stack>
+
+ <stack name="StatelessSessionClientInterceptors">
+ <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+ </stack>
+
+ <stack name="StatefulSessionClientInterceptors">
+ <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+ </stack>
+
+ <stack name="ClusteredStatelessSessionClientInterceptors">
+ <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.ClusterChooserInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+ </stack>
+
+ <stack name="ClusteredStatefulSessionClientInterceptors">
+ <interceptor-ref name="org.jboss.ejb3.remoting.IsLocalInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.security.SecurityClientInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.ClientTxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.ClusterChooserInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.remoting.InvokeRemoteInterceptor"/>
+ </stack>
+
+ <interceptor class="org.jboss.ejb3.asynchronous.AsynchronousInterceptor" scope="PER_CLASS"/>
+ <interceptor class="org.jboss.ejb3.ENCPropagationInterceptor" scope="PER_VM"/>
+ <interceptor name="Basic Authorization" factory="org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorFactory" scope="PER_CLASS"/>
+ <interceptor name="JACC Authorization" factory="org.jboss.ejb3.security.JaccAuthorizationInterceptorFactory" scope="PER_CLASS"/>
+ <interceptor factory="org.jboss.ejb3.security.AuthenticationInterceptorFactory" scope="PER_CLASS"/>
+ <interceptor factory="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory" scope="PER_CLASS"/>
+ <interceptor class="org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.ejb3.stateless.StatelessInstanceInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.ejb3.stateful.StatefulInstanceInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.ejb3.service.ServiceSingletonInterceptor" scope="PER_VM"/>
+ <interceptor class="org.jboss.ejb3.cache.StatefulReplicationInterceptor" scope="PER_VM"/>
+ <interceptor factory="org.jboss.ejb3.stateful.StatefulRemoveFactory" scope="PER_CLASS_JOINPOINT"/>
+ <interceptor factory="org.jboss.ejb3.tx.TxInterceptorFactory" scope="PER_CLASS_JOINPOINT"/>
+ <interceptor factory="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory" scope="PER_CLASS_JOINPOINT"/>
+ <interceptor factory="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory" scope="PER_CLASS"/>
+ <interceptor class="org.jboss.ejb3.AllowedOperationsInterceptor" scope="PER_VM"/>
+ <interceptor factory="org.jboss.ejb3.mdb.CurrentMessageInjectorInterceptorFactory" scope="PER_CLASS"/>
+ <interceptor class="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor" scope="PER_VM"/>
+
+ <domain name="Stateless Bean">
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+ <interceptor-ref name="Basic Authorization"/>
+ </bind>
+ <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+ </bind>
+ <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+ @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+ </annotation>
+ </domain>
+
+ <domain name="JACC Stateless Bean">
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+ <interceptor-ref name="JACC Authorization"/>
+ </bind>
+ <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+ </bind>
+ <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+ @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+ </annotation>
+ </domain>
+
+ <domain name="Base Stateful Bean">
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+ <interceptor-ref name="Basic Authorization"/>
+ </bind>
+ <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->@javax.ejb.Remove(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateful.StatefulRemoveFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+ </bind>
+ <bind pointcut="execution(public * $instanceof{javax.ejb.SessionSynchronization}->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+ </bind>
+
+ <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..)) AND !execution(public * *->@javax.ejb.Remove(..))">
+ <interceptor-ref name="org.jboss.ejb3.cache.StatefulReplicationInterceptor"/>
+ </bind>
+ <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+ @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+ </annotation>
+ </domain>
+
+ <domain name="Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
+ <!-- NON Clustered cache configuration -->
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND !class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.simple.SimpleStatefulCache.class)
+ </annotation>
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.PersistenceManager) AND !class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.simple.PersistenceManager (org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.class)
+ </annotation>
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.CacheConfig) AND !class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300)
+ </annotation>
+
+ <!-- Clustered cache configuration -->
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
+ </annotation>
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.tree.CacheConfig) AND class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300)
+ </annotation>
+ </domain>
+
+ <domain name="JACC Stateful Bean">
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+ <interceptor-ref name="JACC Authorization"/>
+ </bind>
+ <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.remoting.ReplicantsManagerInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->@javax.ejb.Remove(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateful.StatefulRemoveFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateful.StatefulInstanceInterceptor"/>
+ <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+ </bind>
+ <bind pointcut="execution(public * $instanceof{javax.ejb.SessionSynchronization}->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateful.SessionSynchronizationInterceptor"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+ </bind>
+
+ <bind pointcut="execution(public * @org.jboss.annotation.ejb.Clustered->*(..)) AND !execution(public * *->@javax.ejb.Remove(..))">
+ <interceptor-ref name="org.jboss.ejb3.cache.StatefulReplicationInterceptor"/>
+ </bind>
+ <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+ @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.ThreadlocalPool.class, maxSize=30, timeout=10000)
+ </annotation>
+
+ <!-- NON Clustered cache configuration -->
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND !class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.simple.SimpleStatefulCache.class)
+ </annotation>
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.PersistenceManager) AND !class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.simple.PersistenceManager (org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.class)
+ </annotation>
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.simple.CacheConfig) AND !class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.simple.CacheConfig (maxSize=100000, idleTimeoutSeconds=300)
+ </annotation>
+
+ <!-- Clustered cache configuration -->
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache) AND class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
+ </annotation>
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.tree.CacheConfig) AND class(@org.jboss.annotation.ejb.Clustered)">
+ @org.jboss.annotation.ejb.cache.tree.CacheConfig (name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize=100000, idleTimeoutSeconds=300)
+ </annotation>
+ </domain>
+
+ <domain name="Embedded Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
+ <!-- NON Clustered cache configuration -->
+ <annotation expr="!class(@org.jboss.annotation.ejb.cache.Cache)">
+ @org.jboss.annotation.ejb.cache.Cache (org.jboss.ejb3.cache.NoPassivationCache.class)
+ </annotation>
+
+ </domain>
+
+ <domain name="Message Driven Bean">
+ <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+ </bind>
+ <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+ @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=30, timeout=10000)
+ </annotation>
+ </domain>
+
+ <domain name="Consumer Bean">
+ <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.stateless.StatelessInstanceInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..)) AND (has(* *->@org.jboss.annotation.ejb.CurrentMessage(..)) OR hasfield(* *->@org.jboss.annotation.ejb.CurrentMessage))">
+ <interceptor-ref name="org.jboss.ejb3.mdb.CurrentMessageInjectorInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+ </bind>
+ <annotation expr="!class(@org.jboss.annotation.ejb.PoolClass)">
+ @org.jboss.annotation.ejb.PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=30, timeout=10000)
+ </annotation>
+ </domain>
+
+ <domain name="Service Bean">
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+ </bind>
+ <bind pointcut="!execution(* *->create()) AND !execution(* *->start()) AND !execution(*->new(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+ <interceptor-ref name="Basic Authorization"/>
+ </bind>
+ <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..)) AND !execution(* *->create()) AND !execution(* *->start())">
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+ </bind>
+ </domain>
+
+ <domain name="JACC Service Bean">
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.ENCPropagationInterceptor"/>
+ </bind>
+ <bind pointcut="!execution(* *->create()) AND !execution(* *->start()) AND !execution(*->new(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.AuthenticationInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * @org.jboss.annotation.security.SecurityDomain->*(..))">
+ <interceptor-ref name="Basic Authorization"/>
+ </bind>
+ <bind pointcut="execution(public * @javax.annotation.security.RunAs->*(..))">
+ <interceptor-ref name="org.jboss.ejb3.security.RunAsSecurityInterceptorFactory"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..))">
+ <interceptor-ref name="org.jboss.aspects.tx.TxPropagationInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.tx.TxInterceptorFactory"/>
+ <interceptor-ref name="org.jboss.ejb3.AllowedOperationsInterceptor"/>
+ <interceptor-ref name="org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor"/>
+ </bind>
+ <bind pointcut="execution(public * *->*(..)) AND !execution(* *->create()) AND !execution(* *->start())">
+ <interceptor-ref name="org.jboss.ejb3.interceptor.EJB3InterceptorsFactory"/>
+ </bind>
+ </domain>
+
+
+</aop>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/embedded-jboss-beans.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/embedded-jboss-beans.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/embedded-jboss-beans.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
+ xmlns="urn:jboss:bean-deployer">
+ <bean name="Naming" class="org.jnp.server.SingletonNamingServer"/>
+
+ <bean name="InitialContextProperties" class="java.util.Hashtable">
+ <constructor>
+ <parameter class="java.util.Map">
+ <map keyClass="java.lang.String" valueClass="java.lang.String">
+ <entry>
+ <key>java.naming.factory.initial</key>
+ <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
+ </entry>
+ <entry>
+ <key>java.naming.factory.url.pkgs</key>
+ <value>org.jboss.naming:org.jnp.interfaces</value>
+ </entry>
+ </map>
+ </parameter>
+ </constructor>
+ </bean>
+
+ <bean name="java:comp/Initializer" class="org.jboss.ejb3.embedded.JavaCompInitializer">
+ <property name="jndiProperties"><inject bean="InitialContextProperties"/></property>
+ </bean>
+
+ <bean name="XidFactory" class="org.jboss.tm.XidFactoryImpl"/>
+
+ <bean name="XidFactoryMBean" class="org.jboss.ejb3.embedded.XidFactoryMBean">
+ <constructor>
+ <parameter class="org.jboss.tm.XidFactoryBase">
+ <inject bean="XidFactory"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+ <bean name="TransactionManagerInitializer" class="org.jboss.tm.TransactionManagerInitializer">
+ <property name="xidFactory"><inject bean="XidFactory"/></property>
+ <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
+ </bean>
+
+ <bean name="UserTransaction" class="org.jboss.ejb3.embedded.UserTransactionImpl">
+ <demand>TransactionManagerInitializer</demand>
+ </bean>
+
+ <bean name="UserTransactionBinding" class="org.jboss.ejb3.embedded.JndiBinder">
+ <property name="jndiProperties"><inject bean="InitialContextProperties"/></property>
+ <property name="target"><inject bean="UserTransaction"/></property>
+ <property name="bindTo">UserTransaction</property>
+ <property name="serializable">false</property>
+ </bean>
+
+
+ <bean name="TransactionManager" class="java.lang.Object">
+ <constructor factoryMethod="getTransactionManager">
+ <factory bean="TransactionManagerInitializer"/>
+ </constructor>
+ </bean>
+ <bean name="CachedConnectionManager" class="org.jboss.resource.connectionmanager.CachedConnectionManagerReference">
+ <property name="transactionManager"><inject bean="TransactionManager"/></property>
+ </bean>
+
+ <!--
+ <bean class="org.jboss.jdbc.HypersonicDatabase"
+ name="jboss:service=Hypersonic,database=localDB">
+ <property name="database">localDB</property>
+ <property name="inProcessMode">true</property>
+ <property name="dbDataDir">.</property>
+ </bean>
+ -->
+
+ <bean name="DefaultDSBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
+ <property name="driverClass">org.hsqldb.jdbcDriver</property>
+ <property name="connectionURL">jdbc:hsqldb:.</property>
+ <!-- <property name="connectionURL">jdbc:hsqldb:./hypersonic/localDB</property> -->
+ <property name="userName">sa</property>
+ <property name="jndiName">java:/DefaultDS</property>
+ <property name="minSize">0</property>
+ <property name="maxSize">10</property>
+ <property name="blockingTimeout">1000</property>
+ <property name="idleTimeout">100000</property>
+ <property name="transactionManager"><inject bean="TransactionManager"/></property>
+ <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
+ <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
+ </bean>
+
+ <bean name="DefaultDS" class="java.lang.Object">
+ <constructor factoryMethod="getDatasource">
+ <factory bean="DefaultDSBootstrap"/>
+ </constructor>
+ </bean>
+
+ <!--
+ <bean name="TimerServiceFactory" class="org.jboss.ejb3.timerservice.quartz.QuartzTimerServiceFactory">
+ <property name="properties">
+ org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreCMT
+ org.quartz.jobStore.nonManagedTXDataSource=myDS
+ org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
+ org.quartz.jobStore.tablePrefix=QRTZ_
+ org.quartz.jobStore.dataSource=myDS
+
+ # To get it to work with hypersonic
+ # FIXME: this doesn't lock the row
+ org.quartz.jobStore.selectWithLockSQL=SELECT * FROM qrtz_locks WHERE lock_name = ?
+
+ # from quartz.properties
+ org.quartz.scheduler.instanceName=JBossEJB3QuartzScheduler
+ org.quartz.scheduler.rmi.export=false
+ org.quartz.scheduler.rmi.proxy=false
+ org.quartz.scheduler.wrapJobExecutionInUserTransaction=false
+
+ org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
+ org.quartz.threadPool.threadCount=10
+ org.quartz.threadPool.threadPriority=5
+ org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
+
+ org.quartz.jobStore.misfireThreshold=60000
+ </property>
+ <property name="dataSource">java:/DefaultDS</property>
+ <property name="sqlProperties">
+ CREATE_DB_ON_STARTUP = TRUE
+
+ CREATE_TABLE_JOB_DETAILS = CREATE TABLE qrtz_job_details(JOB_NAME VARCHAR(80) NOT NULL, JOB_GROUP VARCHAR(80) NOT NULL, \
+ DESCRIPTION VARCHAR(120) NULL, JOB_CLASS_NAME VARCHAR(128) NOT NULL, IS_DURABLE VARCHAR(1) NOT NULL, \
+ IS_VOLATILE VARCHAR(1) NOT NULL, IS_STATEFUL VARCHAR(1) NOT NULL, REQUESTS_RECOVERY VARCHAR(1) NOT NULL, \
+ JOB_DATA BINARY NULL, PRIMARY KEY (JOB_NAME,JOB_GROUP))
+ CREATE_TABLE_JOB_LISTENERS = CREATE TABLE qrtz_job_listeners(JOB_NAME VARCHAR(80) NOT NULL, JOB_GROUP VARCHAR(80) NOT NULL, \
+ JOB_LISTENER VARCHAR(80) NOT NULL, PRIMARY KEY (JOB_NAME,JOB_GROUP,JOB_LISTENER), FOREIGN KEY (JOB_NAME,JOB_GROUP) \
+ REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP))
+ CREATE_TABLE_TRIGGERS = CREATE TABLE qrtz_triggers(TRIGGER_NAME VARCHAR(80) NOT NULL, TRIGGER_GROUP VARCHAR(80) NOT NULL, \
+ JOB_NAME VARCHAR(80) NOT NULL, JOB_GROUP VARCHAR(80) NOT NULL, IS_VOLATILE VARCHAR(1) NOT NULL, DESCRIPTION VARCHAR(120) NULL, \
+ NEXT_FIRE_TIME NUMERIC(13) NULL, PREV_FIRE_TIME NUMERIC(13) NULL, TRIGGER_STATE VARCHAR(16) NOT NULL, \
+ TRIGGER_TYPE VARCHAR(8) NOT NULL, START_TIME NUMERIC(13) NOT NULL, END_TIME NUMERIC(13) NULL, CALENDAR_NAME VARCHAR(80) NULL, \
+ MISFIRE_INSTR NUMERIC(2) NULL, JOB_DATA BINARY NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (JOB_NAME,JOB_GROUP) \
+ REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP))
+ CREATE_TABLE_SIMPLE_TRIGGERS = CREATE TABLE qrtz_simple_triggers(TRIGGER_NAME VARCHAR(80) NOT NULL, \
+ TRIGGER_GROUP VARCHAR(80) NOT NULL, REPEAT_COUNT NUMERIC(7) NOT NULL, REPEAT_INTERVAL NUMERIC(12) NOT NULL, \
+ TIMES_TRIGGERED NUMERIC(7) NOT NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) \
+ REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP))
+ CREATE_TABLE_CRON_TRIGGERS = CREATE TABLE qrtz_cron_triggers(TRIGGER_NAME VARCHAR(80) NOT NULL, \
+ TRIGGER_GROUP VARCHAR(80) NOT NULL, CRON_EXPRESSION VARCHAR(80) NOT NULL, TIME_ZONE_ID VARCHAR(80), \
+ PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) \
+ REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP))
+ CREATE_TABLE_BLOB_TRIGGERS = CREATE TABLE qrtz_blob_triggers(TRIGGER_NAME VARCHAR(80) NOT NULL, \
+ TRIGGER_GROUP VARCHAR(80) NOT NULL, BLOB_DATA BINARY NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), \
+ FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP))
+ CREATE_TABLE_TRIGGER_LISTENERS = CREATE TABLE qrtz_trigger_listeners(TRIGGER_NAME VARCHAR(80) NOT NULL, \
+ TRIGGER_GROUP VARCHAR(80) NOT NULL, TRIGGER_LISTENER VARCHAR(80) NOT NULL, \
+ PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_LISTENER), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) \
+ REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP))
+ CREATE_TABLE_CALENDARS = CREATE TABLE qrtz_calendars(CALENDAR_NAME VARCHAR(80) NOT NULL, CALENDAR BINARY NOT NULL, \
+ PRIMARY KEY (CALENDAR_NAME))
+ CREATE_TABLE_PAUSED_TRIGGER_GRPS = CREATE TABLE qrtz_paused_trigger_grps(TRIGGER_GROUP VARCHAR(80) NOT NULL, \
+ PRIMARY KEY (TRIGGER_GROUP))
+ CREATE_TABLE_FIRED_TRIGGERS = CREATE TABLE qrtz_fired_triggers(ENTRY_ID VARCHAR(95) NOT NULL, TRIGGER_NAME VARCHAR(80) NOT NULL, \
+ TRIGGER_GROUP VARCHAR(80) NOT NULL, IS_VOLATILE VARCHAR(1) NOT NULL, INSTANCE_NAME VARCHAR(80) NOT NULL, \
+ FIRED_TIME NUMERIC(13) NOT NULL, STATE VARCHAR(16) NOT NULL, JOB_NAME VARCHAR(80) NULL, JOB_GROUP VARCHAR(80) NULL, \
+ IS_STATEFUL VARCHAR(1) NULL, REQUESTS_RECOVERY VARCHAR(1) NULL, PRIMARY KEY (ENTRY_ID))
+ CREATE_TABLE_SCHEDULER_STATE = CREATE TABLE qrtz_scheduler_state(INSTANCE_NAME VARCHAR(80) NOT NULL, \
+ LAST_CHECKIN_TIME NUMERIC(13) NOT NULL, CHECKIN_INTERVAL NUMERIC(13) NOT NULL, RECOVERER VARCHAR(80) NULL, \
+ PRIMARY KEY (INSTANCE_NAME))
+ CREATE_TABLE_LOCKS = CREATE TABLE qrtz_locks(LOCK_NAME VARCHAR(40) NOT NULL, PRIMARY KEY (LOCK_NAME))
+ INSERT_TRIGGER_ACCESS = INSERT INTO qrtz_locks values('TRIGGER_ACCESS')
+ INSERT_JOB_ACCESS = INSERT INTO qrtz_locks values('JOB_ACCESS')
+ INSERT_CALENDAR_ACCESS = INSERT INTO qrtz_locks values('CALENDAR_ACCESS')
+ INSERT_STATE_ACCESS = INSERT INTO qrtz_locks values('STATE_ACCESS')
+ INSERT_MISFIRE_ACCESS = INSERT INTO qrtz_locks values('MISFIRE_ACCESS')
+ </property>
+ </bean>
+
+ -->
+
+</deployment>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/jboss-jms-beans.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/jboss-jms-beans.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/jboss-jms-beans.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,204 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
+ xmlns="urn:jboss:bean-deployer">
+ <bean name="jboss.mq:service=JMSProviderLoader,name=JMSProvider" class="org.jboss.jms.jndi.JNDIProviderAdapter">
+ <property name="factoryRef">java:/XAConnectionFactory</property>
+ <property name="queueFactoryRef">java:/XAConnectionFactory</property>
+ <property name="topicFactoryRef">java:/XAConnectionFactory</property>
+ <property name="properties" class="java.util.Properties">
+ <map keyClass="java.lang.String" valueClass="java.lang.String">
+ <entry>
+ <key>java.naming.factory.initial</key>
+ <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
+ </entry>
+ <entry>
+ <key>java.naming.factory.url.pkgs</key>
+ <value>org.jboss.naming:org.jnp.interfaces</value>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+ <bean name="b1" class="org.jboss.ejb3.embedded.JndiBinder">
+ <property name="jndiProperties"><inject bean="InitialContextProperties"/></property>
+ <property name="target"><inject bean="jboss.mq:service=JMSProviderLoader,name=JMSProvider"/></property>
+ <property name="bindTo">java:/DefaultJMSProvider</property>
+ <property name="serializable">true</property>
+ </bean>
+
+ <bean name="jboss.mq:service=ServerSessionPoolMBean,name=StdJMSPool" class="org.jboss.jms.asf.StdServerSessionPoolFactory">
+ <property name="name">StdJMSPool</property>
+ <property name="xidFactory"><inject bean="XidFactoryMBean"/></property>
+ <property name="transactionManager"><inject bean="TransactionManager"/></property>
+ </bean>
+
+ <bean name="b2" class="org.jboss.ejb3.embedded.JndiBinder">
+ <property name="jndiProperties"><inject bean="InitialContextProperties"/></property>
+ <property name="target"><inject bean="jboss.mq:service=ServerSessionPoolMBean,name=StdJMSPool"/></property>
+ <property name="bindTo">java:/StdJMSPool</property>
+ <property name="serializable">false</property>
+ </bean>
+
+
+ <bean name="jboss.mq:service=PersistenceManager" class="org.jboss.mq.kernel.JDBC2PersistenceManager">
+ <property name="transactionManager">
+ <inject bean="TransactionManager"/>
+ </property>
+ <property name="datasource">
+ <inject bean="DefaultDS"/>
+ </property>
+ <property name="sqlProperties">
+
+ BLOB_TYPE=OBJECT_BLOB
+ INSERT_TX = INSERT INTO JMS_TRANSACTIONS (TXID) values(?)
+ INSERT_MESSAGE = INSERT INTO JMS_MESSAGES (MESSAGEID, DESTINATION, MESSAGEBLOB, TXID, TXOP) VALUES(?,?,?,?,?)
+ SELECT_ALL_UNCOMMITED_TXS = SELECT TXID FROM JMS_TRANSACTIONS
+ SELECT_MAX_TX = SELECT MAX(TXID) FROM JMS_MESSAGES
+ SELECT_MESSAGES_IN_DEST = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE DESTINATION=?
+ SELECT_MESSAGE = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?
+ MARK_MESSAGE = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE MESSAGEID=? AND DESTINATION=?
+ UPDATE_MESSAGE = UPDATE JMS_MESSAGES SET MESSAGEBLOB=? WHERE MESSAGEID=? AND DESTINATION=?
+ UPDATE_MARKED_MESSAGES = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE TXOP=?
+ UPDATE_MARKED_MESSAGES_WITH_TX = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE TXOP=? AND TXID=?
+ DELETE_MARKED_MESSAGES_WITH_TX = DELETE FROM JMS_MESSAGES WHERE TXOP=? AND JMS_MESSAGES.TXID IN (SELECT TXID FROM JMS_TRANSACTIONS)
+ DELETE_TX = DELETE FROM JMS_TRANSACTIONS WHERE TXID = ?
+ DELETE_MARKED_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXID=? AND TXOP=?
+ DELETE_MESSAGE = DELETE FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?
+ CREATE_MESSAGE_TABLE = CREATE CACHED TABLE JMS_MESSAGES ( MESSAGEID INTEGER NOT NULL, \
+ DESTINATION VARCHAR(255) NOT NULL, TXID INTEGER, TXOP CHAR(1), \
+ MESSAGEBLOB OBJECT, PRIMARY KEY (MESSAGEID, DESTINATION) )
+ CREATE_IDX_MESSAGE_TXOP_TXID = CREATE INDEX JMS_MESSAGES_TXOP_TXID ON JMS_MESSAGES (TXOP, TXID)
+ CREATE_IDX_MESSAGE_DESTINATION = CREATE INDEX JMS_MESSAGES_DESTINATION ON JMS_MESSAGES (DESTINATION)
+ CREATE_TX_TABLE = CREATE CACHED TABLE JMS_TRANSACTIONS ( TXID INTEGER, PRIMARY KEY (TXID) )
+ CREATE_TABLES_ON_STARTUP = TRUE
+ DELETE_TEMPORARY_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXOP='T'
+
+ </property>
+ </bean>
+
+ <bean name="jboss.mq:service=MessageCache" class="org.jboss.mq.kernel.MessageCache">
+ <property name="persistenceManager"><inject bean="jboss.mq:service=PersistenceManager"/></property>
+ <property name="highMemoryMark">50</property>
+ <property name="maxMemoryMark">60</property>
+ </bean>
+
+ <bean name="jms-rar-WorkManager" class="org.jboss.ejb3.embedded.resource.JBossWorkManager">
+ </bean>
+
+ <bean name="jms-rar-DeploymentInfo" class="org.jboss.ejb3.embedded.resource.Ejb3DeploymentInfo">
+ <constructor>
+ <parameter class="java.lang.String">jms-ra.rar</parameter>
+ <parameter class="java.lang.String">javax.jms.MessageListener</parameter>
+ <parameter class="java.lang.String">org.jboss.resource.adapter.jms.inflow.JmsActivationSpec</parameter>
+ </constructor>
+ </bean>
+
+ <bean name="jboss.jca:name='jms-ra.rar',service=RARDeployment" class="org.jboss.ejb3.embedded.resource.RARDeployment">
+ <constructor>
+ <parameter class="org.jboss.deployment.DeploymentInfo">
+ <inject bean="jms-rar-DeploymentInfo"/>
+ </parameter>
+ </constructor>
+ <property name="workManager"><inject bean="jms-rar-WorkManager"/></property>
+ </bean>
+
+ <bean name="jboss.mq:service=StateManager" class="org.jboss.mq.kernel.JDBCStateManager">
+ <property name="transactionManager">
+ <inject bean="TransactionManager"/>
+ </property>
+ <property name="datasource">
+ <inject bean="DefaultDS"/>
+ </property>
+ <property name="sqlProperties">
+
+ CREATE_TABLES_ON_STARTUP = TRUE
+ CREATE_USER_TABLE = CREATE TABLE JMS_USERS (USERID VARCHAR(32) NOT NULL, PASSWD VARCHAR(32) NOT NULL, \
+ CLIENTID VARCHAR(128), PRIMARY KEY(USERID))
+ CREATE_ROLE_TABLE = CREATE TABLE JMS_ROLES (ROLEID VARCHAR(32) NOT NULL, USERID VARCHAR(32) NOT NULL, \
+ PRIMARY KEY(USERID, ROLEID))
+ CREATE_SUBSCRIPTION_TABLE = CREATE TABLE JMS_SUBSCRIPTIONS (CLIENTID VARCHAR(128) NOT NULL, \
+ SUBNAME VARCHAR(128) NOT NULL, TOPIC VARCHAR(255) NOT NULL, \
+ SELECTOR VARCHAR(255), PRIMARY KEY(CLIENTID, SUBNAME))
+ GET_SUBSCRIPTION = SELECT TOPIC, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND SUBNAME=?
+ LOCK_SUBSCRIPTION = SELECT TOPIC, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND SUBNAME=?
+ GET_SUBSCRIPTIONS_FOR_TOPIC = SELECT CLIENTID, SUBNAME, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE TOPIC=?
+ INSERT_SUBSCRIPTION = INSERT INTO JMS_SUBSCRIPTIONS (CLIENTID, SUBNAME, TOPIC, SELECTOR) VALUES(?,?,?,?)
+ UPDATE_SUBSCRIPTION = UPDATE JMS_SUBSCRIPTIONS SET TOPIC=?, SELECTOR=? WHERE CLIENTID=? AND SUBNAME=?
+ REMOVE_SUBSCRIPTION = DELETE FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND SUBNAME=?
+ GET_USER_BY_CLIENTID = SELECT USERID, PASSWD, CLIENTID FROM JMS_USERS WHERE CLIENTID=?
+ GET_USER = SELECT PASSWD, CLIENTID FROM JMS_USERS WHERE USERID=?
+ POPULATE.TABLES.01 = INSERT INTO JMS_USERS (USERID, PASSWD) VALUES ('guest', 'guest')
+ POPULATE.TABLES.02 = INSERT INTO JMS_USERS (USERID, PASSWD) VALUES ('j2ee', 'j2ee')
+ POPULATE.TABLES.03 = INSERT INTO JMS_USERS (USERID, PASSWD, CLIENTID) VALUES ('john', 'needle', 'DurableSubscriberExample')
+ POPULATE.TABLES.04 = INSERT INTO JMS_USERS (USERID, PASSWD) VALUES ('nobody', 'nobody')
+ POPULATE.TABLES.05 = INSERT INTO JMS_USERS (USERID, PASSWD) VALUES ('dynsub', 'dynsub')
+ POPULATE.TABLES.06 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('guest','guest')
+ POPULATE.TABLES.07 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('j2ee','guest')
+ POPULATE.TABLES.08 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('john','guest')
+ POPULATE.TABLES.09 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('subscriber','john')
+ POPULATE.TABLES.10 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('publisher','john')
+ POPULATE.TABLES.11 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('publisher','dynsub')
+ POPULATE.TABLES.12 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('durpublisher','john')
+ POPULATE.TABLES.13 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('durpublisher','dynsub')
+ POPULATE.TABLES.14 = INSERT INTO JMS_ROLES (ROLEID, USERID) VALUES ('noacc','nobody')
+
+ </property>
+ </bean>
+
+
+ <bean name="BasicQueueParameters" class="org.jboss.mq.server.BasicQueueParameters"/>
+
+ <bean name="jboss.mq:service=ThreadPool" class="org.jboss.util.threadpool.BasicThreadPool">
+ <property name="name">JMSThread</property>
+ <property name="threadGroupName">JBossMQ Server Threads</property>
+ <!-- The max number of threads in the pool -->
+ <property name="maximumPoolSize">10</property>
+ <!-- The max number of tasks before the queue is full -->
+ <property name="maximumQueueSize">1000</property>
+ <!-- The behavior of the pool when a task is added and the queue is full.
+ abort - a RuntimeException is thrown
+ run - the calling thread executes the task
+ wait - the calling thread blocks until the queue has room
+ discard - the task is silently discarded without being run
+ discardOldest - check to see if a task is about to complete and enque
+ the new task if possible, else run the task in the calling thread
+ -->
+ <property name="blockingModeString">run</property>
+ </bean>
+
+ <bean name="jboss.mq:service=DestinationManager" class="org.jboss.mq.server.JMSDestinationManager">
+ <constructor>
+ <parameter class="org.jboss.mq.server.BasicQueueParameters">
+ <inject bean="BasicQueueParameters"/>
+ </parameter>
+ </constructor>
+ <property name="persistenceManager"><inject bean="jboss.mq:service=PersistenceManager"/></property>
+ <property name="messageCache"><inject bean="jboss.mq:service=MessageCache"/></property>
+ <property name="stateManager"><inject bean="jboss.mq:service=StateManager"/></property>
+ <property name="threadPool"><inject bean="jboss.mq:service=ThreadPool"/></property>
+ <property name="threadGroup"><inject bean="jboss.mq:service=ThreadPool" property="threadGroup"/></property>
+ <start method="startServer"/>
+ <stop method="stopServer"/>
+ </bean>
+
+ <bean name="jboss.mq.destination:service=Queue,name=DLQ" class="org.jboss.mq.kernel.Queue">
+ <property name="destinationManagerPojo"><inject bean="jboss.mq:service=DestinationManager"/></property>
+ <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
+ <property name="destinationName">DLQ</property>
+ </bean>
+
+ <bean name="jboss.mq:service=Invoker" class="org.jboss.mq.server.JMSServerInvoker">
+ <property name="next"><inject bean="jboss.mq:service=DestinationManager"/></property>
+ </bean>
+
+ <bean name="jboss.mq:service=invocationlayer,type=JVM" class="org.jboss.mq.kernel.JVMIL">
+ <property name="jmsInvoker"><inject bean="jboss.mq:service=Invoker"/></property>
+ <property name="connectionFactoryJNDIRef">java:/ConnectionFactory</property>
+ <property name="XAConnectionFactoryJNDIRef">java:/XAConnectionFactory</property>
+ <property name="pingPeriod">0</property>
+ <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
+ </bean>
+
+</deployment>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/jndi.properties
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/jndi.properties 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/jndi.properties 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/log4j.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/log4j.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/log4j.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml 39945 2006-01-12 02:44:07Z bill $ -->
+
+<!--
+ | For more configuration infromation and examples see the Jakarta Log4j
+ | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
+ <param name="Target" value="System.out"/>
+ <param name="Threshold" value="WARN"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Messagen -->
+ <!--
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+ -->
+ <param name="ConversionPattern" value="%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L) -%m%n"/>
+ </layout>
+</appender>
+
+ <root>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/login-config.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/login-config.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/login-config.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,63 @@
+<?xml version='1.0'?>
+
+<!DOCTYPE policy PUBLIC
+ "-//JBoss//DTD JBOSS Security Config 3.0//EN"
+ "http://www.jboss.org/j2ee/dtd/security_config.dtd">
+
+<!-- The XML based JAAS login configuration read by the
+org.jboss.security.auth.login.XMLLoginConfig mbean. Add
+an application-policy element for each security domain.
+
+The outline of the application-policy is:
+<application-policy name="security-domain-name">
+ <authentication>
+ <login-module code="login.module1.class.name" flag="control_flag">
+ <module-option name = "option1-name">option1-value</module-option>
+ <module-option name = "option2-name">option2-value</module-option>
+ ...
+ </login-module>
+
+ <login-module code="login.module2.class.name" flag="control_flag">
+ ...
+ </login-module>
+ ...
+ </authentication>
+</application-policy>
+
+$Revision: 42748 $
+-->
+
+<policy>
+ <!-- Used by clients within the application server VM such as
+ mbeans and servlets that access EJBs.
+ -->
+ <application-policy name="client-login">
+ <authentication>
+ <login-module code="org.jboss.security.ClientLoginModule"
+ flag="required">
+ <!-- Any existing security context will be restored on logout -->
+ <module-option name="restore-login-identity">true</module-option>
+ </login-module>
+ </authentication>
+ </application-policy>
+
+ <application-policy name="other">
+ <!-- A simple server login module, which can be used when the number
+ of users is relatively small. It uses two properties files:
+ users.properties, which holds users (key) and their password (value).
+ roles.properties, which holds users (key) and a comma-separated list of
+ their roles (value).
+ The unauthenticatedIdentity property defines the name of the principal
+ that will be used when a null username and password are presented as is
+ the case for an unuathenticated web client or MDB. If you want to
+ allow such users to be authenticated add the property, e.g.,
+ unauthenticatedIdentity="nobody"
+ -->
+ <authentication>
+ <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
+ flag="required"/>
+ </authentication>
+ </application-policy>
+
+</policy>
+
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/security-beans.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/security-beans.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/conf/security-beans.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
+ xmlns="urn:jboss:bean-deployer">
+
+ <bean class="org.jboss.ejb3.embedded.JaasSecurityManagerService"
+ name="jboss.security:service=JaasSecurityManager">
+ <property name="initialContextProperties">
+ <inject bean="InitialContextProperties"/>
+ </property>
+ </bean>
+</deployment>
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/device-profile.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/device-profile.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/device-profile.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE device-profiles PUBLIC "-//MILYN//DTD TINAK 1.0//EN" "http://www.milyn.org/dtd/device-profile-1.0.dtd">
+
+<device-profiles>
+ <device-profile name="type:Acme-Order-XML" list="profile1,profile2"/>
+ <device-profile name="from:Acme" list="profile23,profile24"/>
+ <device-profile name="to:AcmePartner" list="profile55,profile56"/>
+
+ <device-profile name="profile1" list="A"/>
+ <device-profile name="profile2" list="B"/>
+ <device-profile name="profile23" list="C"/>
+ <device-profile name="profile24" list="D"/>
+ <device-profile name="profile55" list="E"/>
+ <device-profile name="profile56" list="E"/>
+</device-profiles>
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/etc/jbossesb-test-properties.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/etc/jbossesb-test-properties.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/resources/etc/jbossesb-test-properties.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ JBoss, Home of Professional Open Source
+ Copyright 2006, JBoss Inc., and others contributors as indicated
+ by the @authors tag. All rights reserved.
+ See the copyright.txt in the distribution for a
+ full listing of individual contributors.
+ This copyrighted material is made available to anyone wishing to use,
+ modify, copy, or redistribute it subject to the terms and conditions
+ of the GNU Lesser General Public License, v. 2.1.
+ This program is distributed in the hope that it will be useful, but WITHOUT A
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License,
+ v.2.1 along with this distribution; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA.
+
+ (C) 2005-2006,
+ @author JBoss Inc.
+-->
+<!-- $Id: default-jbossesb-properties.xml $ -->
+<!--
+ These options are described in the JBossESB manual.
+ Defaults are provided here for convenience only.
+
+ Please read through this file prior to using the system, and consider
+ updating the specified entries.
+-->
+<esb
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="jbossesb-1_0.xsd">
+ <properties name="core">
+ <property name="org.jboss.soa.esb.jndi.server.type" value="foobar"/>
+ <property name="org.jboss.soa.esb.objStore.configFile" value="file:config.xml"/>
+ </properties>
+ <properties name="transports" depends="core">
+ <property name="org.jboss.soa.esb.mail.smtp.host" value="thishost"/>
+ </properties>
+</esb>
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/StreamUtils.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/StreamUtils.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/StreamUtils.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -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;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Stream handling utilities for testing.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class StreamUtils {
+
+ /**
+ * Read the supplied InputStream and return as an array of bytes.
+ * @param stream The stream to read.
+ * @return The stream contents in an array of bytes.
+ */
+ public static byte[] readStream(InputStream stream) {
+ ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
+ byte[] buffer = new byte[256];
+ int readCount = 0;
+
+ try {
+ while((readCount = stream.read(buffer)) != -1) {
+ outBuffer.write(buffer, 0, readCount);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ TestCase.fail("Error reading input stream - See above stack trace.");
+ }
+
+ return outBuffer.toByteArray();
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/StringUtils.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/StringUtils.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/StringUtils.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,70 @@
+/*
+ * 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;
+
+/**
+ * Utility methods for string manipulation and testing.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class StringUtils {
+
+ /**
+ * Compare the supplied strings, ignoring line break characters.
+ * @param string1 The 1st string.
+ * @param string2 The 2nd string.
+ * @param ignorecase True if a case insensitive comparison is to
+ * be performed, otherwise false.
+ * @return True if the strings are equal, otherwise false.
+ */
+ public static boolean equalsIgnoreLinebreaks(String string1, String string2, boolean ignorecase) {
+ string1 = removeChar(string1, '\r');
+ string1 = removeChar(string1, '\n');
+ string2 = removeChar(string2, '\r');
+ string2 = removeChar(string2, '\n');
+
+ if(ignorecase) {
+ return string1.equalsIgnoreCase(string2);
+ } else {
+ return string1.equals(string2);
+ }
+ }
+
+ /**
+ * Delete all instances of the specified character from the supplied string.
+ * @param string The string to be opperated on.
+ * @param character The character to be removed.
+ */
+ public static String removeChar(String string, char character) {
+ StringBuffer stringBuf = new StringBuffer(string);
+ int index = 0;
+
+ while(index < stringBuf.length()) {
+ if(stringBuf.charAt(index) == character) {
+ stringBuf.deleteCharAt(index);
+ } else {
+ index++;
+ }
+ }
+
+ return stringBuf.toString();
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/W3CDomUtils.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/W3CDomUtils.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/W3CDomUtils.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,35 @@
+package org.jboss.soa.esb;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+
+public abstract class W3CDomUtils {
+
+ public static String serialize(Document document) {
+ DOMSource src = new DOMSource(document);
+
+ ByteArrayOutputStream byteBuf = new ByteArrayOutputStream(5000);
+ StreamResult res = new StreamResult(byteBuf);
+
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.transform(src, res);
+ } catch (Exception e) {
+ e.printStackTrace();
+ TestCase.fail("Failed to serialise doc. See above stack trace.");
+ }
+
+ return byteBuf.toString();
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/EmailUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,68 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.helpers.EmailEpr;
+
+/**
+ * Unit tests for the EPR class.
+ *
+ * @author Mark Little
+ */
+
+public class EmailUnitTest extends TestCase
+{
+
+ public void testConstructor ()
+ {
+ try
+ {
+ new EmailEpr(EmailEpr.SMTP_PROTOCOL, "myhost", "25", "foo", "bar");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGet ()
+ {
+ try
+ {
+ EmailEpr em = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "myhost", "25", "foo", "bar");
+
+ assertEquals(em.getHost(), "myhost");
+ assertEquals(em.getProtocol(), EmailEpr.SMTP_PROTOCOL);
+ assertEquals(em.getPort(), 25);
+ assertEquals(em.getUserName(), "foo");
+ assertEquals(em.getPassword(), "bar");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/FTPUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,72 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.helpers.FTPEpr;
+
+/**
+ * Unit tests for the EPR class.
+ *
+ * @author Mark Little
+ */
+
+public class FTPUnitTest extends TestCase
+{
+
+ public void testConstructor ()
+ {
+ try
+ {
+ new FTPEpr("ftp://foo.com");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGet ()
+ {
+ try
+ {
+ FTPEpr ftp = new FTPEpr("ftp://foo.com");
+
+ assertEquals(ftp.getURL().toString(), "ftp://foo.com");
+ assertEquals(ftp.getURL().getHost(), "foo.com");
+ assertEquals(ftp.getURL().getProtocol(), "ftp");
+
+ ftp.setPassword("foobar");
+ assertEquals(ftp.getPassword(), "foobar");
+
+ ftp.setUserName("barfoo");
+ assertEquals(ftp.getUserName(), "barfoo");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/HTTPUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.addressing.helpers.tests;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.helpers.HTTPEpr;
+
+/**
+ * Unit tests for the EPR class.
+ *
+ * @author Mark Little
+ */
+
+public class HTTPUnitTest extends TestCase
+{
+
+ public void testConstructor ()
+ {
+ try
+ {
+ String url1 = "http://www.local.bar:8080";
+ new HTTPEpr(url1);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGet ()
+ {
+ try
+ {
+ String url1 = "http://www.local.bar:8080";
+ HTTPEpr epr = new HTTPEpr(url1);
+
+ assertEquals(epr.getURL().toString(), url1);
+
+ String url2 = "http://foo.com";
+ epr.setURL(new URL(url2));
+
+ assertEquals(epr.getURL().toString(), url2);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JDBCUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,91 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.helpers.JDBCEpr;
+
+/**
+ * Unit tests for the EPR class.
+ *
+ * @author Mark Little
+ */
+
+public class JDBCUnitTest extends TestCase
+{
+
+ public void testConstructor ()
+ {
+ try
+ {
+ new JDBCEpr("jdbc:arjuna:oracle:thin", "CREATE TABLE foo");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGet ()
+ {
+ try
+ {
+ JDBCEpr em = new JDBCEpr("jdbc:arjuna:oracle:thin", "CREATE TABLE foo");
+
+ assertEquals(em.getURL(), "jdbc:arjuna:oracle:thin");
+ assertEquals(em.getSQL(), "CREATE TABLE foo");
+
+ em.setURL("jdbc:arjuna:oracle:thin");
+ assertEquals(em.getURL(), "jdbc:arjuna:oracle:thin");
+
+ em.setUserName("me");
+ assertEquals(em.getUserName(), "me");
+
+ em.setPassword("foobar");
+ assertEquals(em.getPassword(), "foobar");
+
+ try
+ {
+ em.setSQL("INVALID");
+
+ fail();
+ }
+ catch (IllegalStateException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ em.setDriver("cloudscape");
+ assertEquals(em.getDriver(), "cloudscape");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/helpers/tests/JMSUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,67 @@
+/*
+ * 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.addressing.helpers.tests;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.helpers.JMSEpr;
+
+/**
+ * Unit tests for the EPR class.
+ *
+ * @author Mark Little
+ */
+
+public class JMSUnitTest extends TestCase
+{
+
+ public void testConstructor ()
+ {
+ try
+ {
+ new JMSEpr(JMSEpr.ONE_ONE_PROTOCOL, JMSEpr.QUEUE_TYPE, "bar", "foobar",null,null,null);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGet ()
+ {
+ try
+ {
+ JMSEpr jms = new JMSEpr(JMSEpr.ONE_ONE_PROTOCOL, JMSEpr.QUEUE_TYPE, "bar", "foobar",null,null,null);
+
+ assertEquals(jms.getVersion(), JMSEpr.ONE_ONE_PROTOCOL);
+ assertEquals(jms.getConnectionFactory(), "foobar");
+ assertEquals(jms.getDestinationType(), JMSEpr.QUEUE_TYPE);
+ assertEquals(jms.getDestinationName(), "bar");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/CallUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/CallUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/CallUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,195 @@
+/*
+ * 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.addressing.tests;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class CallUnitTest extends TestCase
+{
+ public void testConstructor ()
+ {
+ Call call = new Call();
+
+ try
+ {
+ assertEquals((call.getTo() == null), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testEPRConstructor ()
+ {
+ try
+ {
+ EPR epr = new EPR(new URI("http://localhost"));
+ Call call = new Call(epr);
+
+ assertEquals(call.getTo().equals(epr), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGetTo ()
+ {
+ Call call = new Call();
+
+ try
+ {
+ EPR epr = new EPR(new URI("http://localhost"));
+
+ call.setTo(epr);
+
+ assertEquals(call.getTo().equals(epr), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGetFrom ()
+ {
+ Call call = new Call();
+
+ try
+ {
+ EPR epr = new EPR(new URI("http://localhost"));
+
+ call.setFrom(epr);
+
+ assertEquals(call.getFrom().equals(epr), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGetReplyTo ()
+ {
+ Call call = new Call();
+
+ try
+ {
+ EPR epr = new EPR(new URI("http://localhost"));
+
+ call.setReplyTo(epr);
+
+ assertEquals(call.getReplyTo().equals(epr), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGetFaultTo ()
+ {
+ Call call = new Call();
+
+ try
+ {
+ EPR epr = new EPR(new URI("http://localhost"));
+
+ call.setFaultTo(epr);
+
+ assertEquals(call.getFaultTo().equals(epr), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGetRelatesTo ()
+ {
+ Call call = new Call();
+
+ try
+ {
+ URI uri = new URI("urn:1234");
+
+ call.setRelatesTo(uri);
+
+ assertEquals(call.getRelatesTo().equals(uri), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGetAction ()
+ {
+ Call call = new Call();
+
+ try
+ {
+ URI uri = new URI("urn:1234");
+
+ call.setAction(uri);
+
+ assertEquals(call.getAction().equals(uri), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetGetMessageID ()
+ {
+ Call call = new Call();
+
+ try
+ {
+ URI uri = new URI("urn:1234");
+
+ call.setMessageID(uri);
+
+ assertEquals(call.getMessageID().equals(uri), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/EPRUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/EPRUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/EPRUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,115 @@
+/*
+ * 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.addressing.tests;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+
+/**
+ * Unit tests for the EPR class.
+ *
+ * @author Mark Little
+ */
+
+public class EPRUnitTest extends TestCase
+{
+
+ public void testConstructor ()
+ {
+ EPR epr = new EPR();
+
+ System.err.println("Default EPR: "+epr);
+ }
+
+ public void testPortReferenceConstructor ()
+ {
+ EPR epr = new EPR(new PortReference("http://localhost:8080"));
+
+ assertEquals(epr.toString(), "EPR: PortReference < http://localhost:8080 >");
+ }
+
+ public void testURIConstructor ()
+ {
+ try
+ {
+ EPR epr = new EPR(new URI("urn:foo:bar"));
+
+ assertEquals(epr.toString(), "EPR: PortReference < urn:foo:bar >");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testGetAddr ()
+ {
+ try
+ {
+ EPR epr = new EPR(new URI("urn:foo:bar"));
+
+ assertEquals(epr.getAddr().getAddress(), "urn:foo:bar");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSetAddr ()
+ {
+ EPR epr = new EPR();
+
+ epr.setAddr(new PortReference("http://localhost"));
+
+ try
+ {
+ assertEquals(epr.getAddr().getAddress(), "http://localhost");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testEquals ()
+ {
+ try
+ {
+ EPR epr1 = new EPR(new URI("http://localhost"));
+ EPR epr2 = new EPR(new URI("http://localhost"));
+ EPR epr3 = new EPR(new URI("http://localhost:8080"));
+
+ assertEquals(epr1.equals(epr2), true);
+ assertEquals(epr1.equals(epr3), false);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,77 @@
+/*
+ * 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.addressing.util.tests;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.helpers.EmailEpr;
+import org.jboss.soa.esb.addressing.util.EPRManager;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class EPRManagerUnitTest extends TestCase
+{
+
+ public void testCreate ()
+ {
+ EPRManager manager1 = EPRManager.getInstance(null);
+ EPRManager manager2 = EPRManager.getInstance("");
+ EPRManager manager3 = EPRManager.getInstance("/tmp");
+
+ assertEquals(manager1.equals(manager2), true);
+ assertEquals(manager1.equals(manager3), false);
+ }
+
+ public void testInputOutput ()
+ {
+ EmailEpr email = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "foobar", "25", "me", "letmein");
+
+ String tmpDir = "/tmp";
+ String os = System.getProperty("os.name").toLowerCase();
+ if (os.indexOf("windows")>=0) {
+ tmpDir="/Temp";
+ }
+ EPRManager manager = EPRManager.getInstance(tmpDir);
+
+ try
+ {
+ manager.saveEPR("MyEmail", email);
+
+ EmailEpr loaded = new EmailEpr(manager.loadEPR("MyEmail"));
+
+ assertEquals(loaded.getHost().equals("foobar"), true);
+ assertEquals(loaded.getPassword().equals("letmein"), true);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/command/InMemoryCommandQueueUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/command/InMemoryCommandQueueUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/command/InMemoryCommandQueueUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,124 @@
+package org.jboss.soa.esb.command;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.command.CommandQueue;
+import org.jboss.internal.soa.esb.command.CommandQueueException;
+import org.jboss.internal.soa.esb.command.InMemoryCommandQueue;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+public class InMemoryCommandQueueUnitTest extends TestCase {
+
+ public void test_args() throws CommandQueueException {
+ InMemoryCommandQueue commandQueue = new InMemoryCommandQueue();
+
+ try {
+ commandQueue.open(null);
+ fail("Expected IllegalArgumentException.");
+ } catch (IllegalArgumentException e) {
+ // OK
+ }
+
+ ConfigTree config = new ConfigTree("config");
+ try {
+ commandQueue.open(config);
+ fail("Expected CommandQueueException.");
+ } catch (CommandQueueException e) {
+ // OK
+ }
+ }
+
+ public void test_queue_open_close() throws CommandQueueException {
+ ConfigTree config = new ConfigTree("config");
+ InMemoryCommandQueue commandQueue = new InMemoryCommandQueue();
+
+ config.setAttribute(InMemoryCommandQueue.COMMAND_QUEUE_NAME, "test-queue");
+ assertEquals(null, InMemoryCommandQueue.getQueue("test-queue"));
+ commandQueue.open(config);
+ assertEquals(commandQueue, InMemoryCommandQueue.getQueue("test-queue"));
+ commandQueue.close();
+ assertEquals(null, InMemoryCommandQueue.getQueue("test-queue"));
+ }
+
+ public void test_queue_receive() throws CommandQueueException, InterruptedException {
+ ConfigTree config = new ConfigTree("config");
+ InMemoryCommandQueue commandQueue = new InMemoryCommandQueue();
+
+ // receive should fail if the queue hasn't been opened yet...
+ try {
+ commandQueue.receiveCommand(0);
+ fail("Expected CommandQueueException.");
+ } catch (CommandQueueException e) {
+ // OK
+ }
+
+ config.setAttribute(InMemoryCommandQueue.COMMAND_QUEUE_NAME, "test-queue");
+ commandQueue.open(config);
+
+ // Start the consumer thread - it will receive the commands from the queue.
+ CommandConsumerThread consumerThread = new CommandConsumerThread(commandQueue);
+ consumerThread.start();
+
+ // Make sure the thread is running.
+ assertTrue(consumerThread.isRunning);
+
+ commandQueue.addCommand("command1");
+ assertCommandReceived(consumerThread, "command1", 0);
+ commandQueue.addCommand("command2");
+ assertCommandReceived(consumerThread, "command2", 1);
+ commandQueue.addCommand("command3");
+ assertCommandReceived(consumerThread, "command3", 2);
+
+ // Stop the queue thread...
+ commandQueue.addCommand("stop");
+ Thread.sleep(50);
+ assertTrue(!consumerThread.isRunning); // this flag being reset proves the stop command was consumed and so the queue is really working
+ assertEquals(4, consumerThread.unblockCount); // Should have unblocked 4 times - once for each command.
+
+ // receive should fail if the queue has been closed...
+ commandQueue.close();
+ try {
+ commandQueue.receiveCommand(0);
+ fail("Expected CommandQueueException.");
+ } catch (CommandQueueException e) {
+ // OK
+ }
+ }
+
+ private void assertCommandReceived(CommandConsumerThread consumerThread, String expected, int index) throws InterruptedException {
+ Thread.sleep(50);
+ assertEquals("Received commands queue is not the expected length.", index + 1, consumerThread.commandsReceived.size());
+ assertEquals("Command not found as last added command.", expected, consumerThread.commandsReceived.get(index));
+ }
+
+ private class CommandConsumerThread extends Thread {
+
+ private List<String> commandsReceived = new ArrayList<String>();
+ private CommandQueue commandQueue;
+ private boolean isRunning = true;
+ private int unblockCount = 0;
+
+ private CommandConsumerThread(CommandQueue commandQueue) {
+ this.commandQueue = commandQueue;
+ }
+
+ @Override
+ public void run() {
+ String command = null;
+
+ while(!"stop".equals(command)) {
+ try {
+ command = commandQueue.receiveCommand(0);
+ commandsReceived.add(command);
+ } catch (CommandQueueException e) {
+ fail("CommandQueue Exception: " + e.getMessage());
+ }
+ unblockCount++;
+ }
+ isRunning = false;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/bizclasses/BatchProcessUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/bizclasses/BatchProcessUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/bizclasses/BatchProcessUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,35 @@
+/*
+ * 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.common.bizclasses;
+
+import junit.framework.TestCase;
+
+/**
+ * BatchProcess unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class BatchProcessUnitTest extends TestCase {
+
+ public void test_BatchProcess() {
+
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/BaseTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/BaseTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/BaseTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,187 @@
+/*
+ * 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.common.tests;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+
+/**
+ * Base test class for esb test classes, uses jboss logging.
+ *
+ * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
+ * @version <tt>$Revision:$</tt> $Id:$
+ */
+
+/*
+ * This should probably use its own property file.
+ */
+
+public class BaseTest extends TestCase
+{
+
+ /** The Database driver used for unit tests */
+ public static String DB_DRIVER = "org.jboss.esb.test.db.driver";
+
+ /** The Database connection url used for unit tests */
+ public static String DB_URL = "org.jboss.esb.test.db.url";
+
+ /** The Database user name used for unit tests */
+ public static String DB_USERNAME = "org.jboss.esb.test.db.user";
+
+ /** The Database password used for unit tests */
+ public static String DB_PASSWORD = "org.jboss.esb.test.db.password";
+
+ /** The Logger. */
+ protected Logger log = Logger.getLogger(getClass());
+
+ /** Contains user and or deployment specific paramater */
+ public static HashMap<String, String> SYSTEM_PARAMETERS;
+
+ /**
+ * Default class constructor.
+ */
+ public BaseTest()
+ {
+ SYSTEM_PARAMETERS = readSystemParameters();
+ }
+
+ /**
+ * Utility constructor.
+ *
+ * @param name
+ * The test name.
+ */
+ public BaseTest(String name)
+ {
+ super(name);
+ SYSTEM_PARAMETERS = readSystemParameters();
+ }
+
+ /**
+ * Reading system parameter that are set by the ant build when invoking the
+ * junit call. The parameter values should be set in the
+ * deployment.properties file. If the particular parameter is not found it
+ * will receive a default value.
+ */
+ private HashMap<String, String> readSystemParameters()
+ {
+ // Reading system parameter
+ String dbDriver = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(DB_DRIVER, "org.hsqldb.jdbcDriver");
+ String dbUrl = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(DB_URL, "jdbc:hsqldb:.");
+ String dbUsername = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(DB_USERNAME, "sa");
+ String dbPassword = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
+ .getProperty(DB_PASSWORD, "");
+
+ // Setting the paremeters in the HashMap
+ HashMap<String, String> systemParameters = new HashMap<String, String>();
+ systemParameters.put(DB_DRIVER, dbDriver);
+ systemParameters.put(DB_URL, dbUrl);
+ systemParameters.put(DB_USERNAME, dbUsername);
+ systemParameters.put(DB_PASSWORD, dbPassword);
+
+ log.log(Priority.INFO, "DB parameters:");
+ log.log(Priority.INFO, "Driver=" + dbDriver);
+ log.log(Priority.INFO, "url=" + dbUrl);
+ log.log(Priority.INFO, "username=" + dbUsername);
+ log.log(Priority.INFO, "password=" + dbPassword);
+
+ return systemParameters;
+ }
+
+ protected String getDbUrl()
+ {
+ return SYSTEM_PARAMETERS.get(DB_URL);
+ }
+
+ protected String getDbUser()
+ {
+ return SYSTEM_PARAMETERS.get(DB_USERNAME);
+ }
+
+ protected String getDbPassword()
+ {
+ return SYSTEM_PARAMETERS.get(DB_PASSWORD);
+ }
+
+ protected String getDbDriver()
+ {
+ return SYSTEM_PARAMETERS.get(DB_DRIVER);
+ }
+
+ public Connection getDbConnection() throws SQLException
+ {
+ registerJdbcDriver();
+ return DriverManager.getConnection(getDbUrl(), getDbUser(),
+ getDbPassword());
+ }
+
+ public Connection getDbConnection(String username, String password)
+ throws SQLException
+ {
+ registerJdbcDriver();
+ return DriverManager.getConnection(getDbUrl(), username, password);
+ }
+
+ /**
+ * Set the test ObjStoreConfigFile location in the classpath/filesystem.
+ *
+ * @param filePath
+ * Classpath/filesystem location.
+ */
+ public void setObjStoreConfigFile(String filePath)
+ {
+ if (filePath == null)
+ {
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperties()
+ .remove(Environment.OBJECT_STORE_CONFIG_FILE);
+ } else
+ {
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).setProperty(
+ Environment.OBJECT_STORE_CONFIG_FILE, filePath);
+ }
+ }
+
+ private void registerJdbcDriver()
+ {
+ try
+ {
+ Class.forName(getDbDriver()).newInstance();
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("JDBC Driver [" + getDbDriver()
+ + "] not available in classpath.");
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/EJBContainerSetup.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/EJBContainerSetup.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/EJBContainerSetup.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,156 @@
+/*
+* 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.common.tests;
+
+/**
+ * Special Setup class to invoke the JBoss microcontainer for testing ejb
+ * code. Based a class provided by John Gilbert.
+ *
+ * @author kstam
+ */
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
+import org.apache.log4j.Logger;
+import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+
+public class EJBContainerSetup extends TestSetup {
+
+ private static final Logger log = Logger.getLogger(EJBContainerSetup.class);
+
+ private static InitialContext initialContext;
+
+ private static boolean initialized = false;
+
+ public EJBContainerSetup(Test test) {
+ super(test);
+ }
+
+ protected void setUp() {
+ startupEmbeddedJboss();
+ }
+
+ protected void tearDown() {
+ // shutdownEmbeddedJboss();
+ }
+
+ public static void shutdownEmbeddedJboss() {
+ EJB3StandaloneBootstrap.shutdown();
+ }
+
+ public static void startupEmbeddedJboss() {
+ try {
+ if (initialized)
+ return;
+
+ // Boot the JBoss Microcontainer with EJB3 settings, loads
+ // ejb3-interceptors-aop.xml
+ EJB3StandaloneBootstrap.boot(null);
+
+ log.info("scanClasspath: "
+ + ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty("java.class.path"));
+ EJB3StandaloneBootstrap.scanClasspath();
+
+ // Create InitialContext from jndi.properties
+ System.setProperty("java.naming.factory.initial",
+ "org.jnp.interfaces.LocalOnlyContextFactory");
+ System.setProperty("java.naming.factory.url.pkgs",
+ "org.jboss.naming:org.jnp.interfaces");
+ initialContext = new InitialContext();
+
+ //printJndiTree();
+
+ initialized = true;
+
+ } catch (Exception ex) {
+ log.error("EJB3 Container Startup Error", ex);
+ throw new RuntimeException(ex);
+ }
+ }
+
+ @SuppressWarnings("unused")
+ static private void printJndiTree() throws Exception {
+
+ log.info("JNDI Tree");
+ NamingEnumeration e = initialContext.list("");
+ while (e.hasMore()) {
+ NameClassPair element = (NameClassPair) e.next();
+ print(element, "");
+ }
+ e = initialContext.list("java:");
+ while (e.hasMore()) {
+ NameClassPair element = (NameClassPair) e.next();
+ print(element, "");
+ }
+ }
+
+ static private void print(NameClassPair ctx, String tab) {
+ log.info(tab + ctx);
+ try {
+ NamingEnumeration e = initialContext.list(ctx.getName());
+ while (e.hasMore()) {
+ NameClassPair element = (NameClassPair) e.next();
+ print(element, tab + "--> ");
+ }
+ } catch (NamingException e1) {
+ }
+ }
+
+ public static Object lookup(String beanName) {
+ try {
+ return initialContext.lookup(beanName);
+ } catch (NamingException ex) {
+ throw new RuntimeException("Couldn't lookup: " + beanName, ex);
+ }
+ }
+
+ public static Object lookup(String beanName, String user, String password) {
+ InitialContext ctx = null;
+ try {
+ Properties env = new Properties();
+ env.setProperty(Context.SECURITY_PRINCIPAL, user);
+ env.setProperty(Context.SECURITY_CREDENTIALS, password);
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jboss.security.jndi.JndiLoginInitialContextFactory");
+ ctx = new InitialContext(env);
+
+ return ctx.lookup(beanName);
+ } catch (NamingException ex) {
+ throw new RuntimeException("Couldn't lookup: " + beanName, ex);
+ } finally {
+ try {
+ ctx.close();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/HsqldbUtil.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/HsqldbUtil.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/HsqldbUtil.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,64 @@
+package org.jboss.soa.esb.common.tests;
+
+import java.sql.DriverManager;
+import java.sql.Statement;
+
+import org.hsqldb.Server;
+/**
+ * Utility to start and stop a hsql Database.
+ *
+ * @author <a href="mailto:kurt.stam at jboss.com">Kurt Stam</a>
+ *
+ */
+public class HsqldbUtil
+{
+ final private static String THREAD_NAME = "hypersonic-unittest";
+ /**
+ * Starts the hsql database in it's own thread.
+ * Don't forget to shut it down when you're done.
+ *
+ * @param databaseFile - i.e. build/hsqltestdb
+ * @param databaseName - i.e. jbossesb
+ * @throws Exception
+ */
+ public static void startHsqldb(final String databaseFile,
+ final String databaseName) throws Exception
+ {
+ // Start DB in new thread, or else it will block us
+ Thread serverThread = new Thread(THREAD_NAME) {
+ public void run() {
+ try {
+ // Create startup arguments
+ String[] args = new String[4];
+ args[0] = "-database.0";
+ args[1] = databaseFile;
+ args[2] = "-dbname.0";
+ args[3] = databaseName;
+
+ // Start server
+ Server.main(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ //log.error("Failed to start database", e);
+ }
+ };
+ serverThread.run();
+ }
+ /**
+ *
+ * @param url
+ * @param username
+ * @param password
+ * @throws Exception
+ */
+ public static void stopHsqldb(String url, String username, String password) throws Exception {
+ java.sql.Connection connection = DriverManager.getConnection(
+ url, username, password);
+ Statement statement = connection.createStatement();
+ String shutdownCommand = "SHUTDOWN COMPACT";
+ statement.executeQuery(shutdownCommand);
+ }
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/MockDataSource.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/MockDataSource.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/MockDataSource.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,94 @@
+/*
+ * 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.common.tests;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+
+/**
+ * Mock {@link javax.sql.DataSource} implementation.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MockDataSource implements DataSource {
+
+ private BaseTest testClass;
+ private int loginTimeout;
+ private PrintWriter printWriter;
+
+ /**
+ * Construct from a BaseTest
+ */
+ public MockDataSource(BaseTest testClass) {
+ if(testClass == null) {
+ throw new IllegalArgumentException("null 'testClass' arg.");
+ }
+ this.testClass = testClass;
+ printWriter = new PrintWriter(System.out);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.sql.DataSource#getConnection()
+ */
+ public Connection getConnection() throws SQLException {
+ return testClass.getDbConnection();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
+ */
+ public Connection getConnection(String username, String password) throws SQLException {
+ return testClass.getDbConnection(username, password);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.sql.DataSource#getLogWriter()
+ */
+ public PrintWriter getLogWriter() throws SQLException {
+ return printWriter;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
+ */
+ public void setLogWriter(PrintWriter printWriter) throws SQLException {
+ this.printWriter = printWriter;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.sql.DataSource#getLoginTimeout()
+ */
+ public int getLoginTimeout() throws SQLException {
+ return loginTimeout;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.sql.DataSource#setLoginTimeout(int)
+ */
+ public void setLoginTimeout(int loginTimeout) throws SQLException {
+ this.loginTimeout = loginTimeout;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/TestUtil.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/TestUtil.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/TestUtil.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,36 @@
+package org.jboss.soa.esb.common.tests;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+
+public class TestUtil
+{
+ private static Logger log = Logger.getLogger(TestUtil.class);
+ private static String _prefix=null;
+ /**
+ * When performing file system interaction, the user.dir may differ (i.e. running the
+ * tests from within eclipse).
+ */
+ public static String getPrefix()
+ {
+ if (_prefix==null) {
+ _prefix="";
+ String baseDir = System.getProperty("user.dir");
+ log.log(Priority.INFO, baseDir);
+ if (!baseDir.endsWith("product")) {
+ _prefix = "product/";
+ }
+ }
+ return _prefix;
+ }
+ /**
+ * Sets the jbossesb-properties.xml to use for test
+ */
+ public static void setESBPropertiesFileToUse()
+ {
+ //Set the jbossesb properties file in System, so we can pick up the one for testing
+ String jbossesbPropertiesFile = getPrefix() + "etc/test/resources/jbossesb-unittest-properties.xml";
+ System.setProperty("org.jboss.soa.esb.propertyFile", jbossesbPropertiesFile);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/AddressUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/AddressUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/AddressUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,124 @@
+/*
+* 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.common.tests.bizclasses;
+
+import org.jboss.soa.esb.common.bizclasses.Address;
+import org.jboss.soa.esb.common.bizclasses.Telephone;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+
+/**
+ * Unit test for the address class.
+ *
+ * @author <a href="mailto:schifest at gmail.com">Esteban Shifman</a>
+ * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
+ * @version <tt>$Revision:$</tt>
+ * $Id:$
+ */
+public class AddressUnitTest extends BaseTest {
+
+
+ public void testAddress() throws Exception {
+ Address address = getAddress();
+ assertTrue("Expecting Address.strNum to be 50. Actual was " +
+ address.getField(Address.ATTRIB.strNum), address.getField(Address.ATTRIB.strNum).equals("50"));
+ assertTrue("Expecting Address.strLine1 to be Balcarce. Actual was " +
+ address.getField(Address.ATTRIB.strLine1), address.getField(Address.ATTRIB.strLine1).equals("Balcarce"));
+ assertTrue("Expecting Address.twnCty1 to be San Isidro. Actual was " +
+ address.getField(Address.ATTRIB.twnCty1), address.getField(Address.ATTRIB.twnCty1).equals("San Isidro"));
+ assertTrue("Expecting Address.postalZip to be 1642. Actual was " +
+ address.getField(Address.ATTRIB.postalZip), address.getField(Address.ATTRIB.postalZip).equals("1642"));
+ assertTrue("Expecting Address.provSt to be Buenos Aires. Actual was " +
+ address.getField(Address.ATTRIB.provSt), address.getField(Address.ATTRIB.provSt).equals("Buenos Aires"));
+ assertTrue("Expecting Address.cntry to be Argentina. Actual was " +
+ address.getField(Address.ATTRIB.cntry), address.getField(Address.ATTRIB.cntry).equals("Argentina"));
+
+ // Phone
+ assertTrue("Expecting Address.phone[0].role to be torIP. Actual was " +
+ address.getPhoneAt(0).getRole(), address.getPhoneAt(0).getRole().equals("torIP"));
+ assertTrue("Expecting Address.phone[0].country to be null. Actual was " +
+ address.getPhoneAt(0).getField(Telephone.ATTRIB.cntry), address.getPhoneAt(0).getField(Telephone.ATTRIB.cntry) == null);
+ assertTrue("Expecting Address.phone[0].city to be 416. Actual was " +
+ address.getPhoneAt(0).getField(Telephone.ATTRIB.city), address.getPhoneAt(0).getField(Telephone.ATTRIB.city).equals("416"));
+ assertTrue("Expecting Address.phone[0].num to be 555-1212. Actual was " +
+ address.getPhoneAt(0).getField(Telephone.ATTRIB.num), address.getPhoneAt(0).getField(Telephone.ATTRIB.num).equals("555-1212"));
+ assertTrue("Expecting Address.phone[0].ext to be null. Actual was " +
+ address.getPhoneAt(0).getField(Telephone.ATTRIB.ext), address.getPhoneAt(0).getField(Telephone.ATTRIB.ext) == null);
+
+ assertTrue("Expecting Address.phone[1].role to be home. Actual was " +
+ address.getPhoneAt(1).getRole(), address.getPhoneAt(1).getRole().equals("home"));
+ assertTrue("Expecting Address.phone[1].country to be 54. Actual was " +
+ address.getPhoneAt(1).getField(Telephone.ATTRIB.cntry), address.getPhoneAt(1).getField(Telephone.ATTRIB.cntry).equals("54"));
+ assertTrue("Expecting Address.phone[1].city to be 11. Actual was " +
+ address.getPhoneAt(1).getField(Telephone.ATTRIB.city), address.getPhoneAt(1).getField(Telephone.ATTRIB.city).equals("11"));
+ assertTrue("Expecting Address.phone[1].num to be 4555-1111. Actual was " +
+ address.getPhoneAt(1).getField(Telephone.ATTRIB.num), address.getPhoneAt(1).getField(Telephone.ATTRIB.num).equals("4555-1111"));
+ assertTrue("Expecting Address.phone[1].ext to be 7. Actual was " +
+ address.getPhoneAt(1).getField(Telephone.ATTRIB.ext), address.getPhoneAt(1).getField(Telephone.ATTRIB.ext).equals("7"));
+
+ }
+
+
+ public void testToDTO() throws Exception {
+ BaseBusinessObject addressA = getAddress();
+ addressA.setPackage();
+
+ BobjStdDTO oDto = addressA.toDTO();
+ System.out.println(oDto.toXml());
+
+ Address addressB = (Address) BaseBusinessObject.getFromDTO(oDto);
+ System.out.println(addressB.toDTO().toXml());
+
+ assertTrue("Expecting AddressA == AddressB", addressA.toDTO().toXml().equals(addressB.toDTO().toXml()));
+ }
+
+
+ static Address getAddress() throws Exception {
+ Address oP = new Address((String) null);
+ oP.setField(Address.ATTRIB.strNum, "50");
+ oP.setField(Address.ATTRIB.strLine1, "Balcarce");
+ oP.setField(Address.ATTRIB.twnCty1, "San Isidro");
+ oP.setField(Address.ATTRIB.postalZip, "1642");
+ oP.setField(Address.ATTRIB.provSt, "Buenos Aires");
+ oP.setField(Address.ATTRIB.cntry, "Argentina");
+
+ oP.addPhone(newPhone("torIP", null, "416", "555-1212", null));
+ oP.addPhone(newPhone("home", "54", "11", "4555-1111", "7"));
+
+ return oP;
+ }
+
+ public static Telephone newPhone(String p_sRole, String p_sCtry, String p_sCity,
+ String p_sNum, String p_sExt) {
+ Telephone oP = new Telephone((String) null);
+ oP.setRole(p_sRole);
+ oP.setField(Telephone.ATTRIB.cntry, p_sCtry);
+ oP.setField(Telephone.ATTRIB.city, p_sCity);
+ oP.setField(Telephone.ATTRIB.num, p_sNum);
+ oP.setField(Telephone.ATTRIB.ext, p_sExt);
+
+ return oP;
+ }
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/PersonUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/PersonUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/bizclasses/PersonUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,204 @@
+/*
+* 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.common.tests.bizclasses;
+
+import org.jboss.soa.esb.common.bizclasses.Address;
+import org.jboss.soa.esb.common.bizclasses.OneValue;
+import org.jboss.soa.esb.common.bizclasses.Person;
+import org.jboss.soa.esb.common.bizclasses.Telephone;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+
+/**
+ * Unit test for the person class.
+ *
+ * @author <a href="mailto:schifest at gmail.com">Esteban Shifman</a>
+ * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
+ * @version <tt>$Revision:$</tt>
+ * $Id:$
+ */
+public class PersonUnitTest extends BaseTest {
+
+
+ public void testPerson() throws Exception {
+
+ Person person = getPerson();
+
+ assertTrue("Expecting Person.pfx to be Mr. Actual was " +
+ person.getField(Person.ATTRIB.pfx), person.getField(Person.ATTRIB.pfx).equals("Mr."));
+ assertTrue("Expecting Person.fmlyN to be Brum. Actual was " +
+ person.getField(Person.ATTRIB.fmlyN), person.getField(Person.ATTRIB.fmlyN).equals("Brum"));
+ assertTrue("Expecting Person.givN to be Daniel. Actual was " +
+ person.getField(Person.ATTRIB.givN), person.getField(Person.ATTRIB.givN).equals("Daniel"));
+ assertTrue("Expecting Person.sfx to be the 1st.. Actual was " +
+ person.getField(Person.ATTRIB.sfx), person.getField(Person.ATTRIB.sfx).equals("the 1st."));
+
+ }
+
+ public void testPersonEmail() throws Exception {
+
+ Person person = getPerson();
+
+ String expectedEmail0 = "<OneValue rol=\"home\" v=\"myaddr at gmail.com\"/>";
+ assertTrue("Expecting Person.email[0] to be Actual was " +
+ person.getEmailAt(0).toString(), person.getEmailAt(0).toString().equals(expectedEmail0));
+
+ String expectedEmail1 = "<OneValue rol=\"work\" v=\"john.smith at jboss.com\"/>";
+ assertTrue("Expecting Person.email[0] to be Actual was " +
+ person.getEmailAt(1).toString(), person.getEmailAt(1).toString().equals(expectedEmail1));
+ }
+
+ public void testPersonTelephone() throws Exception {
+
+ Person person = getPerson();
+
+ assertTrue("Expecting Person.phone[0].role to be basement. Actual was " +
+ person.getPhoneAt(0).getRole(), person.getPhoneAt(0).getRole().equals("basement"));
+ assertTrue("Expecting Person.phone[0].country to be 1. Actual was " +
+ person.getPhoneAt(0).getField(Telephone.ATTRIB.cntry), person.getPhoneAt(0).getField(Telephone.ATTRIB.cntry).equals("1"));
+ assertTrue("Expecting Person.phone[0].city to be 416. Actual was " +
+ person.getPhoneAt(0).getField(Telephone.ATTRIB.city), person.getPhoneAt(0).getField(Telephone.ATTRIB.city).equals("416"));
+ assertTrue("Expecting Person.phone[0].num to be 555-1212. Actual was " +
+ person.getPhoneAt(0).getField(Telephone.ATTRIB.num), person.getPhoneAt(0).getField(Telephone.ATTRIB.num).equals("555-1212"));
+ assertTrue("Expecting Person.phone[0].ext to be null. Actual was " +
+ person.getPhoneAt(0).getField(Telephone.ATTRIB.ext), person.getPhoneAt(0).getField(Telephone.ATTRIB.ext) == null);
+
+ assertTrue("Expecting Person.phone[1].role to be basement. Actual was " +
+ person.getPhoneAt(1).getRole(), person.getPhoneAt(1).getRole().equals("cell"));
+ assertTrue("Expecting Person.phone[1].country to be null. Actual was " +
+ person.getPhoneAt(1).getField(Telephone.ATTRIB.cntry), person.getPhoneAt(1).getField(Telephone.ATTRIB.cntry) == null);
+ assertTrue("Expecting Person.phone[1].city to be 416. Actual was " +
+ person.getPhoneAt(1).getField(Telephone.ATTRIB.city), person.getPhoneAt(1).getField(Telephone.ATTRIB.city).equals("416"));
+ assertTrue("Expecting Person.phone[1].num to be 666-4444. Actual was " +
+ person.getPhoneAt(1).getField(Telephone.ATTRIB.num), person.getPhoneAt(1).getField(Telephone.ATTRIB.num).equals("666-4444"));
+ assertTrue("Expecting Person.phone[1].ext to be null. Actual was " +
+ person.getPhoneAt(1).getField(Telephone.ATTRIB.ext), person.getPhoneAt(1).getField(Telephone.ATTRIB.ext) == null);
+
+ }
+
+ public void testPersonAddress() throws Exception {
+
+ Address address = getPerson().getAddressAt(0);
+ assertTrue("Expecting Address.strNum to be 50. Actual was " +
+ address.getField(Address.ATTRIB.strNum), address.getField(Address.ATTRIB.strNum).equals("50"));
+ assertTrue("Expecting Address.strLine1 to be Balcarce. Actual was " +
+ address.getField(Address.ATTRIB.strLine1), address.getField(Address.ATTRIB.strLine1).equals("Balcarce"));
+ assertTrue("Expecting Address.twnCty1 to be San Isidro. Actual was " +
+ address.getField(Address.ATTRIB.twnCty1), address.getField(Address.ATTRIB.twnCty1).equals("San Isidro"));
+ assertTrue("Expecting Address.postalZip to be 1642. Actual was " +
+ address.getField(Address.ATTRIB.postalZip), address.getField(Address.ATTRIB.postalZip).equals("1642"));
+ assertTrue("Expecting Address.provSt to be Buenos Aires. Actual was " +
+ address.getField(Address.ATTRIB.provSt), address.getField(Address.ATTRIB.provSt).equals("Buenos Aires"));
+ assertTrue("Expecting Address.cntry to be Argentina. Actual was " +
+ address.getField(Address.ATTRIB.cntry), address.getField(Address.ATTRIB.cntry).equals("Argentina"));
+
+ // Phone
+ assertTrue("Expecting Address.phone[0].role to be torIP. Actual was " +
+ address.getPhoneAt(0).getRole(), address.getPhoneAt(0).getRole().equals("torIP"));
+ assertTrue("Expecting Address.phone[0].country to be null. Actual was " +
+ address.getPhoneAt(0).getField(Telephone.ATTRIB.cntry), address.getPhoneAt(0).getField(Telephone.ATTRIB.cntry) == null);
+ assertTrue("Expecting Address.phone[0].city to be 416. Actual was " +
+ address.getPhoneAt(0).getField(Telephone.ATTRIB.city), address.getPhoneAt(0).getField(Telephone.ATTRIB.city).equals("416"));
+ assertTrue("Expecting Address.phone[0].num to be 555-1212. Actual was " +
+ address.getPhoneAt(0).getField(Telephone.ATTRIB.num), address.getPhoneAt(0).getField(Telephone.ATTRIB.num).equals("555-1212"));
+ assertTrue("Expecting Address.phone[0].ext to be null. Actual was " +
+ address.getPhoneAt(0).getField(Telephone.ATTRIB.ext), address.getPhoneAt(0).getField(Telephone.ATTRIB.ext) == null);
+
+ assertTrue("Expecting Address.phone[1].role to be home. Actual was " +
+ address.getPhoneAt(1).getRole(), address.getPhoneAt(1).getRole().equals("home"));
+ assertTrue("Expecting Address.phone[1].country to be 54. Actual was " +
+ address.getPhoneAt(1).getField(Telephone.ATTRIB.cntry), address.getPhoneAt(1).getField(Telephone.ATTRIB.cntry).equals("54"));
+ assertTrue("Expecting Address.phone[1].city to be 11. Actual was " +
+ address.getPhoneAt(1).getField(Telephone.ATTRIB.city), address.getPhoneAt(1).getField(Telephone.ATTRIB.city).equals("11"));
+ assertTrue("Expecting Address.phone[1].num to be 4555-1111. Actual was " +
+ address.getPhoneAt(1).getField(Telephone.ATTRIB.num), address.getPhoneAt(1).getField(Telephone.ATTRIB.num).equals("4555-1111"));
+ assertTrue("Expecting Address.phone[1].ext to be 7. Actual was " +
+ address.getPhoneAt(1).getField(Telephone.ATTRIB.ext), address.getPhoneAt(1).getField(Telephone.ATTRIB.ext).equals("7"));
+
+
+ }
+
+
+
+
+
+ public void testToDTO() throws Exception {
+ BaseBusinessObject personA = getPerson();
+ personA.setPackage();
+
+ BobjStdDTO oDto = personA.toDTO();
+ System.out.println(oDto.toXml());
+
+ Person personB = (Person) BaseBusinessObject.getFromDTO(oDto);
+ System.out.println(personB.toDTO().toXml());
+
+ assertTrue("Expecting PersonA == PersonB", personA.toDTO().toXml().equals(personB.toDTO().toXml()));
+ }
+
+
+ public static Person getPerson() throws Exception {
+ Person oP = new Person((String) null);
+ oP.setField(Person.ATTRIB.pfx, "Mr.");
+ oP.setField(Person.ATTRIB.fmlyN, "Brum");
+ oP.setField(Person.ATTRIB.givN, "Daniel");
+ oP.setField(Person.ATTRIB.sfx, "the 1st.");
+
+ oP.addAddress(getAddress());
+
+ oP.addEmail(OneValue.getStringValue("myaddr at gmail.com", "home"));
+ oP.addEmail(OneValue.getStringValue("john.smith at jboss.com", "work"));
+
+ oP.addPhone(newPhone("basement", "1", "416", "555-1212", null));
+ oP.addPhone(newPhone("cell", null, "416", "666-4444", null));
+
+ return oP;
+ }
+
+ public static Address getAddress() throws Exception {
+ Address oP = new Address((String) null);
+ oP.setField(Address.ATTRIB.strNum, "50");
+ oP.setField(Address.ATTRIB.strLine1, "Balcarce");
+ oP.setField(Address.ATTRIB.twnCty1, "San Isidro");
+ oP.setField(Address.ATTRIB.postalZip, "1642");
+ oP.setField(Address.ATTRIB.provSt, "Buenos Aires");
+ oP.setField(Address.ATTRIB.cntry, "Argentina");
+
+ oP.addPhone(newPhone("torIP", null, "416", "555-1212", null));
+ oP.addPhone(newPhone("home", "54", "11", "4555-1111", "7"));
+
+ return oP;
+ }
+
+ public static Telephone newPhone(String p_sRole,
+ String p_sCtry, String p_sCity, String p_sNum, String p_sExt) {
+ Telephone oP = new Telephone((String) null);
+ oP.setRole(p_sRole);
+ oP.setField(Telephone.ATTRIB.cntry, p_sCtry);
+ oP.setField(Telephone.ATTRIB.city, p_sCity);
+ oP.setField(Telephone.ATTRIB.num, p_sNum);
+ oP.setField(Telephone.ATTRIB.ext, p_sExt);
+
+ return oP;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/propertymanager/PropertyManagerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/propertymanager/PropertyManagerUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/propertymanager/PropertyManagerUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,87 @@
+/*
+ * 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.common.tests.propertymanager;
+
+import junit.framework.ComparisonFailure;
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.common.Environment;
+
+import com.arjuna.common.internal.util.propertyservice.plugins.io.XMLFilePlugin;
+import com.arjuna.common.util.propertyservice.PropertyManager;
+import com.arjuna.common.util.propertyservice.PropertyManagerFactory;
+
+public class PropertyManagerUnitTest extends TestCase
+{
+
+ public void testPropertyManager ()
+ {
+ System.setProperty("com.arjuna.common.util.propertyservice.verbosePropertyManager", "ON");
+
+ PropertyManager corepm = PropertyManagerFactory.getPropertyManager("test.core", "core");
+
+ try
+ {
+ corepm.load(XMLFilePlugin.class.getName(), "jbossesb-test-properties.xml");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ fail(e.toString());
+ }
+
+ assertEquals(corepm.getProperty(Environment.JNDI_SERVER_TYPE), "foobar");
+ assertEquals(corepm.getProperty(Environment.OBJECT_STORE_CONFIG_FILE), "file:config.xml");
+
+ try
+ {
+ assertEquals(corepm.getProperty(Environment.SMTP_HOST), "thishost");
+
+ fail();
+ }
+ catch (ComparisonFailure ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ PropertyManager transportpm = PropertyManagerFactory.getPropertyManager("test.transports", "transports");
+
+ try
+ {
+ transportpm.load(XMLFilePlugin.class.getName(), "jbossesb-test-properties.xml");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ fail(e.toString());
+ }
+
+ assertEquals(transportpm.getProperty(Environment.JNDI_SERVER_TYPE), "foobar");
+ assertEquals(transportpm.getProperty(Environment.SMTP_HOST), "thishost");
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/utils/DrainQueuesAndTopics.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/utils/DrainQueuesAndTopics.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/utils/DrainQueuesAndTopics.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,124 @@
+/*
+ * 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.common.tests.utils;
+
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+import javax.naming.Context;
+
+import org.jboss.soa.esb.helpers.AppServerContext;
+
+public class DrainQueuesAndTopics
+{
+ private static final int MAX_TIMES_NOMSG = 10;
+ private static final String JNDI_URL = "localhost";
+ private static final String JNDI_TYPE
+ = AppServerContext.SERVER_TYPE.jboss.toString();
+
+ private Context m_oCtx;
+
+ public DrainQueuesAndTopics() throws Exception
+ {
+ purgeQueueTopic("queue/A");
+ purgeQueueTopic("queue/B");
+ purgeQueueTopic("topic/testTopic");
+ } //__________________________________
+
+ public int purgeQueueTopic(String p_sName) throws Exception
+ {
+ int iRet = 0;
+ m_oCtx = AppServerContext.getServerContext(JNDI_TYPE,JNDI_URL);
+
+ System.out.println(p_sName);
+ MessageConsumer oCns = null;
+ switch(p_sName.toLowerCase().charAt(0))
+ { case 't' : oCns = getTopic(p_sName); break;
+ case 'q' : oCns = getQueue(p_sName); break;
+ }
+ if (null==oCns)
+ return 0;
+
+ for (int iNoRcv=0; iNoRcv < MAX_TIMES_NOMSG; )
+ { Message oMsg = oCns.receive(200);
+ if (null==oMsg)
+ { iNoRcv++;
+ System.out.print(".");
+ continue;
+ }
+ iRet++;
+ dumpMessage(oMsg);
+ iNoRcv = 0;
+ }
+ System.out.println();
+ return iRet;
+ } //__________________________________
+
+ void dumpMessage(Message pM)
+ {
+ System.out.println(pM);
+ } //__________________________________
+
+ QueueReceiver getQueue(String p_sJndi) throws Exception
+ {
+ QueueConnection oQconn = null;
+ QueueSession oQsess = null;
+ QueueConnectionFactory qcf = (QueueConnectionFactory) m_oCtx
+ .lookup("ConnectionFactory");
+
+ oQconn = qcf.createQueueConnection();
+ oQsess = oQconn.createQueueSession(false
+ ,QueueSession.AUTO_ACKNOWLEDGE);
+ Queue oQueue
+ = (Queue) m_oCtx.lookup(p_sJndi);
+
+ QueueReceiver oRcv = oQsess.createReceiver(oQueue);
+ oQconn.start();
+ return oRcv;
+ } //__________________________________
+
+ TopicSubscriber getTopic(String p_sJndi) throws Exception
+ {
+ TopicConnection oTconn = null;
+ TopicSession oTsess = null;
+ TopicConnectionFactory qcf = (TopicConnectionFactory) m_oCtx
+ .lookup("ConnectionFactory");
+
+ oTconn = qcf.createTopicConnection();
+ oTsess = oTconn.createTopicSession(false
+ ,QueueSession.AUTO_ACKNOWLEDGE);
+ Topic oT = (Topic) m_oCtx.lookup(p_sJndi);
+
+ TopicSubscriber oRcv = oTsess.createSubscriber(oT);
+ oTconn.start();
+ return oRcv;
+ } //__________________________________
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/AbandonedConnectionFuncTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/AbandonedConnectionFuncTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/AbandonedConnectionFuncTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,72 @@
+/*
+* 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.connection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+
+/**
+ * This class tests for abandoned connections. Abandoned connections are connections which are requested from the pool, never used and
+ * never returned back to the pool by calling connection#close() method. This test gets a connection from pool and then sleeps for a elongated
+ * period of time and then fires methods on connection which is cleaned up the pool. This leads to SQLException.
+ * User: MohitK
+ * Date: Aug 3, 2006
+ */
+public class AbandonedConnectionFuncTest extends BaseTest {
+
+ Properties properties = new Properties();
+
+ protected void setUp() throws Exception {
+
+ properties.put(ConnectionProperties.DRIVER_CLASSNAME, SYSTEM_PARAMETERS.get(DB_DRIVER));
+ properties.put(ConnectionProperties.CONNECTION_URL, SYSTEM_PARAMETERS.get(DB_URL));
+ properties.put(ConnectionProperties.USERNAME, SYSTEM_PARAMETERS.get(DB_USERNAME));
+ properties.put(ConnectionProperties.PASSWORD, SYSTEM_PARAMETERS.get(DB_PASSWORD));
+ properties.put(ConnectionProperties.ABANDONED_CONNECTION_TIMEOUT, "2000");
+ properties.put(ConnectionProperties.ABANDONED_CONNECTION_CHECK_INTERVAL, "3000");
+ }
+
+
+ public void testAbandonedConnections() {
+ PoolDataSource ds = new PoolDataSource();
+ ds.setConnectionProperties(properties);
+ Connection con1 = null;
+ //Connection con2 = null;
+ //Connection con3 = null;
+ try {
+ con1 = ds.getConnection();
+ try {
+ Thread.sleep(4000);
+ } catch (InterruptedException e) {
+ //Do nothing
+ }
+ con1.createStatement();
+ } catch (SQLException e) {
+ //e.printStackTrace();
+ assertTrue(true);
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/ConnectionPoolFuncTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/ConnectionPoolFuncTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/ConnectionPoolFuncTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,84 @@
+/*
+* 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.connection;
+
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+
+/**
+ * TODO
+ * @author MohitK
+ * Date: Jul 22, 2006
+ */
+public class ConnectionPoolFuncTest extends BaseTest {
+
+ Properties properties = new Properties();
+
+ protected void setUp() throws Exception {
+ properties.put(ConnectionProperties.DRIVER_CLASSNAME, SYSTEM_PARAMETERS.get(DB_DRIVER));
+ properties.put(ConnectionProperties.CONNECTION_URL, SYSTEM_PARAMETERS.get(DB_URL));
+ properties.put(ConnectionProperties.USERNAME, SYSTEM_PARAMETERS.get(DB_USERNAME));
+ properties.put(ConnectionProperties.PASSWORD, SYSTEM_PARAMETERS.get(DB_PASSWORD));
+ }
+
+
+ public void testConnectionPool() {
+ PoolDataSource ds = new PoolDataSource();
+ ds.setConnectionProperties(properties);
+ Connection con = null;
+ Statement stat = null;
+ try {
+ con = ds.getConnection();
+ stat = con.createStatement();
+ stat.execute("CREATE TABLE uid_table (uid integer NOT NULL)");
+ ResultSet rs = stat.executeQuery("SELECT count(*) FROM uid_table");
+ while (rs.next()) {
+ int count = rs.getInt(1);
+ System.out.println("count = " + count);
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }finally{
+ try {
+ if (stat != null) {
+ stat.close();
+ }
+ if(con!=null){
+ con.close();
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/PasswordDecoderFuncTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/PasswordDecoderFuncTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/PasswordDecoderFuncTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,88 @@
+/*
+* 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.connection;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+
+/**
+ * TODO
+ *
+ * @author MohitK
+ * Date: Aug 1, 2006
+ */
+public class PasswordDecoderFuncTest extends BaseTest {
+
+ Properties properties = new Properties();
+
+ protected void setUp() throws Exception {
+ properties.put(ConnectionProperties.DRIVER_CLASSNAME, SYSTEM_PARAMETERS.get(DB_DRIVER));
+ properties.put(ConnectionProperties.CONNECTION_URL, SYSTEM_PARAMETERS.get(DB_URL));
+ properties.put(ConnectionProperties.USERNAME, SYSTEM_PARAMETERS.get(DB_USERNAME));
+ properties.setProperty(ConnectionProperties.PASSWORD_DECODER, PasswordDecoderTestImpl.class.getName());
+ }
+
+ public void testPasswordDecoder() {
+
+ PoolDataSource ds = new PoolDataSource();
+ ds.setConnectionProperties(properties);
+ Connection con1 = null;
+ Statement stat = null;
+ try {
+ con1 = ds.getConnection();
+ stat = con1.createStatement();
+ stat.execute("CREATE TABLE uid_table (uid integer NOT NULL)");
+ ResultSet rs = stat.executeQuery("SELECT count(*) FROM uid_table");
+ while (rs.next()) {
+ int count = rs.getInt(1);
+ System.out.println("count = " + count);
+ }
+
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ } finally {
+ if (stat != null) {
+ try {
+ stat.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+ if (con1 != null) {
+ try {
+ con1.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/PasswordDecoderTestImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/PasswordDecoderTestImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/connection/PasswordDecoderTestImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,35 @@
+/*
+* 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.connection;
+
+
+/**
+ * TODO
+ * @author MohitK
+ * Date: Aug 1, 2006
+ */
+public class PasswordDecoderTestImpl implements PasswordDecoder {
+
+ public String decode(String encodedPassword) {
+ return "";
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/AppServerContextUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/AppServerContextUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/AppServerContextUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,46 @@
+/*
+ * 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.helpers;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+/**
+ * AppServerContex unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class AppServerContextUnitTest extends TestCase {
+
+ public void test_AppServerContext() throws NamingException {
+ Context ctx = AppServerContext.getServerContext("jboss", "http://localhost:1234");
+
+ Hashtable props = ctx.getEnvironment();
+ System.out.println(props);
+ assertEquals("org.jnp.interfaces.NamingContextFactory", props.get(Context.INITIAL_CONTEXT_FACTORY));
+ assertEquals("http://localhost:1234", props.get(Context.PROVIDER_URL));
+ assertEquals("org.jboss.naming:org.jnp.interfaces", props.get("java.naming.factory.url.pkgs"));
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/ConfigTreeUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/ConfigTreeUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/ConfigTreeUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,260 @@
+/*
+ * 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.helpers;
+
+import java.io.*;
+import java.util.*;
+
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.StringUtils;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Unit tests for the ConfigTree class.
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ */
+public class ConfigTreeUnitTest extends BaseTest {
+
+ public void test_fromInputStream_args() throws SAXException, IOException {
+ try {
+ ConfigTree.fromInputStream(null);
+ fail("Expected IllegalArgumentException on null stream.");
+ } catch(IllegalArgumentException e) {
+ // Expected
+ }
+ }
+
+ private InputStream getStream(String sName)
+ {
+ InputStream oRet =getClass().getResourceAsStream(sName);
+ if (null==oRet)
+ try { oRet = new FileInputStream(sName); }
+ catch(IOException e) { /* OK Just fall through */}
+ return oRet;
+ }
+
+ public void test_fromInputStream_and_toXML() throws SAXException, IOException
+ {
+ ConfigTree confTree = ConfigTree.fromInputStream(getStream("testfile1.xml"));
+ byte[] expected = StreamUtils.readStream(getStream("expected_01.xml"));
+
+ // Create the ConfigTree from a Stream. Then...
+ // Dump the XML to a buffer and compare it with the expected - checking that the
+ // Created ConfigTree DOM is the same as what was supplied in the stream. Also
+ // tests the toXML method. If this fails, either fromInputStream is not working correctly
+ // or the toXML method is not serialising correctly.
+ String output = null;
+ try { output = confTree.toXml(); }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ assertTrue("ConfigTree creation from a stream failed, or, ConfigTree toXML failed - failed to produce the same XML.",
+ StringUtils.equalsIgnoreLinebreaks(new String(expected), output, false));
+ }
+
+ public void test_fromXML_args() throws SAXException, IOException
+ {
+ try {
+ ConfigTree.fromXml(null);
+ fail("Expected IllegalArgumentException on null String.");
+ } catch(IllegalArgumentException e) {
+ // Expected
+ }
+ try {
+ ConfigTree.fromXml(" ");
+ fail("Expected SAXParseException on null String.");
+ } catch(SAXParseException e) {
+ // Expected
+ }
+ }
+
+ public void test_fromXML_and_toXML() throws SAXException, IOException
+ {
+ byte[] source = StreamUtils.readStream(getStream("expected_01.xml"));
+ ConfigTree confTree = ConfigTree.fromXml(new String(source));
+ byte[] expected = source;
+
+ // Create the ConfigTree from a String. Then...
+ // Dump the XML to a buffer and compare it with the expected - checking that the
+ // Created ConfigTree DOM is the same as what was supplied in the stream. Also
+ // tests the toXML method. If this fails, either fromInputStream is not working correctly
+ // or the toXML method is not serialising correctly.
+ String output = confTree.toXml();
+ assertTrue("ConfigTree creation from a String failed, or, ConfigTree toXML failed - failed to produce the same XML.",
+ StringUtils.equalsIgnoreLinebreaks(new String(expected), output, false));
+ }
+
+ public void test_Constructor_Clone() throws SAXException, IOException {
+ ConfigTree conf1 = ConfigTree.fromInputStream(getStream("testfile1.xml"));
+// ByteArrayOutputStream output;
+ byte[] expected = StreamUtils.readStream(getStream("expected_01.xml"));
+ // Create a new ConfigTree from an existing one and compare it with the expected.
+ ConfigTree conf2 = conf1.cloneObj();
+ assertTrue("ConfigTree creation from a stream failed, or, cloneObj failed - failed to produce the same XML.",
+ StringUtils.equalsIgnoreLinebreaks(new String(expected), conf2.toXml(), false));
+ }
+
+ public void test_Constructor_String_withoutparent() throws SAXException, IOException {
+ // Create a new ConfigTree from without a parent ConfigTree.
+ ConfigTree confTree = new ConfigTree("newConfigTree",null);
+
+ assertEquals("New ConfigTree invalid.", "<newConfigTree/>" , confTree.toXml());
+ }
+
+ public void test_getName() {
+ ConfigTree confTree = new ConfigTree("newConfigTree",null);
+ assertEquals("getName returned invalid data.", "newConfigTree", confTree.getName());
+ }
+
+ public void test_getAttrKeys_hasnokeys() throws SAXException, IOException {
+ ConfigTree confTree = new ConfigTree("newConfigTree",null);
+ assertTrue("invalid attribute name list", confTree.attributeCount()== 0);
+ }
+
+ public void test_getAttrKeys_haskeys() throws SAXException, IOException {
+ ConfigTree confTree = ConfigTree.fromInputStream(getStream("testfile2.xml"));
+ String[] expected = new String[] {"attrib1", "attrib2", "attrib3"};
+ Arrays.sort(expected);
+ String[] actual = confTree.getAttributeNames().toArray(new String[confTree.attributeCount()]);
+ Arrays.sort(actual);
+
+ assertTrue("invalid attribute name list", Arrays.equals(expected, actual));
+ }
+
+ public void test_getAttr() throws SAXException, IOException {
+ ConfigTree confTree = ConfigTree.fromInputStream(getStream("testfile2.xml"));
+
+ assertEquals("invalid attribute value", "value2", confTree.getAttribute("attrib2"));
+ assertEquals("invalid attribute value", null, confTree.getAttribute("attribXX"));
+ }
+
+ public void test_getTextChildren() throws SAXException, IOException {
+ // This test also tests the static method getTextValue.
+ ConfigTree confTree = ConfigTree.fromInputStream(getStream("testfile3.xml"));
+
+ // REVIEW: These tests capture the current behavior of the getTextChildren method. I'm not convinced this behavior is correct!!
+ // I think perhaps this method should not be depending on getTextValue because getTextValue
+ // concatentates the child text nodes.
+ assertTrue("invalid Text Children list",
+ "Some root text... and some more root text...".equals(confTree.getWholeText()));
+ assertTrue("invalid Text Children list",
+ Arrays.equals(new String[] {"", "Some nested text..."}, confTree.getTextChildren("el")));
+ }
+
+ public void test_getElementChildren() throws SAXException, IOException {
+ ConfigTree confTree = ConfigTree.fromInputStream(getStream("testfile3.xml"));
+ ConfigTree[] confTrees;
+
+ String expected = new String(StreamUtils.readStream(getStream("expected_03.xml"))).trim();
+ assertEquals("Wrong ConfigTree ElementChild value.", expected, confTree.toString().trim());
+
+ // Test the nested <el> elements - of which there are 2...
+ confTrees = confTree.getChildren("el");
+ assertEquals("Wrong number of ConfigTree ElementChildren.", 2, confTrees.length);
+ assertEquals("Wrong ConfigTree ElementChild value.", "<el index=\"1\"/>", confTrees[0].toString().trim());
+ assertEquals("Wrong ConfigTree ElementChild value.", "<el index=\"2\">Some nested text...</el>", confTrees[1].toString().trim());
+
+ // Test for a non-existant element...
+ confTrees = confTree.getChildren("xxxx");
+ assertEquals("Wrong number of ConfigTree ElementChildren.", 0, confTrees.length);
+ }
+
+ public void test_getFirstElementChild() throws SAXException, IOException {
+ ConfigTree confTree = ConfigTree.fromInputStream(getStream("testfile3.xml"));
+
+ String expected = new String(StreamUtils.readStream(getStream("expected_03.xml"))).trim();
+ assertEquals("Wrong ConfigTree ElementChild value.", expected, confTree.toString().trim());
+
+ // Test the nested <el> elements - of which there are 2...
+ confTree = confTree.getFirstChild("el");
+ assertEquals("Wrong ConfigTree ElementChild value.", "<el index=\"1\"/>", confTree.toString().trim());
+
+ // Test for a non-existant element...
+ confTree = confTree.getFirstChild("xxxx");
+ assertEquals("Expected null ConfigTree ElementChildren for non-existant element.", null, confTree);
+ }
+
+ public void test_getAllElemChildren() throws SAXException, IOException {
+ ConfigTree confTree = ConfigTree.fromInputStream(getStream("testfile3.xml"));
+ ConfigTree[] confTrees;
+
+ confTrees = confTree.getAllChildren();
+ assertEquals("Wrong number of ConfigTree ElementChildren.", 2, confTrees.length);
+ assertEquals("Wrong ConfigTree ElementChild value.", "<el index=\"1\"/>", confTrees[0].toString().trim());
+ assertEquals("Wrong ConfigTree ElementChild value.", "<el index=\"2\">Some nested text...</el>", confTrees[1].toString().trim());
+
+ // REVIEW: Note, this method only returns ConfigTree instances for the child elements
+ // of the document root node. Comparing this to the behaviour of getFirstElementChild
+ // would seem to demonstrate an inconsitency??? To be consistent, I would expect this method
+ // to return a list of 3 ConfigTree instances - the <root> and 2 <el> elements.
+ }
+
+ public void test_setAttr() throws SAXException, IOException {
+ ConfigTree confTree = new ConfigTree("newConfigTree");
+
+ confTree.setAttribute("attrib1", "value1");
+ assertEquals("value1", confTree.getAttribute("attrib1"));
+
+ // A null value removes the attribute.
+ confTree.setAttribute("attrib1", null);
+ assertEquals(null, confTree.getAttribute("attrib1"));
+
+ try { confTree.setAttribute(null, null); }
+ catch (IllegalArgumentException e) {/* OK we expect this */}
+ catch (Exception e2) {fail(e2.getMessage());}
+ }
+
+ public void test_addElemChild() throws SAXException, IOException {
+ ConfigTree ConfigTree1 = new ConfigTree("newConfigTree");
+ ConfigTree ConfigTreeX = new ConfigTree("X",ConfigTree1);
+ new ConfigTree("Y1",ConfigTree1);
+ new ConfigTree("Y2",ConfigTreeX);
+
+ assertEquals("<newConfigTree><X><Y2/></X><Y1/></newConfigTree>", ConfigTree1.toString().trim());
+ }
+
+ public void test_rmvChildsByName() throws SAXException, IOException {
+ ConfigTree ConfigTree1 = new ConfigTree("newConfigTree");
+ ConfigTree ConfigTreeX = new ConfigTree("X",ConfigTree1);
+ new ConfigTree("Y1",ConfigTree1);
+ new ConfigTree("Y2",ConfigTreeX);
+
+ assertEquals("<newConfigTree><X><Y2/></X><Y1/></newConfigTree>", ConfigTree1.toString().trim());
+ ConfigTree1.removeChildrenByName("Y1");
+ assertEquals("<newConfigTree><X><Y2/></X></newConfigTree>", ConfigTree1.toString().trim());
+ }
+
+ public void test_cloneObj() throws SAXException, IOException {
+ ConfigTree ConfigTree1 = new ConfigTree("newConfigTree");
+ new ConfigTree("X",ConfigTree1);
+ new ConfigTree("Y",ConfigTree1);
+
+ ConfigTree clone = ConfigTree1.cloneObj();
+
+ assertTrue("Clone should produce a completely different object", (ConfigTree1 != clone));
+ assertEquals("Clone should produce the same XML", ConfigTree1.toString(), clone.toString());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/EmailUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/EmailUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/EmailUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,94 @@
+/*
+ * 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.helpers;
+
+import java.io.IOException;
+
+import javax.mail.Address;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the EsbEmail class.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class EmailUnitTest extends TestCase {
+
+ private ConfigTree mailParams;
+
+ @Override
+ protected void setUp() throws Exception {
+ mailParams = ConfigTree.fromInputStream(getClass().getResourceAsStream("testfile4.xml"));
+ }
+
+ public void test_Email() throws AddressException, MessagingException, IOException {
+ // Look at the source message in testfile4.xml before reading this test.
+
+ Email esbMail = new Email();
+ esbMail.setSendTo(mailParams.getAttribute(Email.SENDTO));
+ esbMail.setFrom(mailParams.getAttribute(Email.FROM));
+ esbMail.setCopyTo(mailParams.getAttribute(Email.COPYTO));
+ esbMail.setSubject(mailParams.getAttribute(Email.SUBJECT));
+
+ esbMail.setAttachments(mailParams.getTextChildren(Email.ATTACH));
+ esbMail.setMessage(mailParams.getAttribute(Email.MESSAGE));
+ MimeMessage message = esbMail.getMailMessage();
+ Address[] addresses;
+
+ // Check the "from" address details...
+ addresses = message.getFrom();
+ assertEquals(1, addresses.length);
+ assertEquals("x.x at x.com", addresses[0].toString());
+
+ // Check the "to" address details...
+ addresses = message.getRecipients(MimeMessage.RecipientType.TO);
+ assertEquals(2, addresses.length);
+ assertEquals("b.b at b.com", addresses[0].toString());
+ assertEquals("c.c at c.com", addresses[1].toString());
+
+ // Check the "cc" address details...
+ addresses = message.getRecipients(MimeMessage.RecipientType.CC);
+ assertEquals(2, addresses.length);
+ assertEquals("d.d at c.com", addresses[0].toString());
+ assertEquals("e.e at e.com", addresses[1].toString());
+
+ // Check the "subject"...
+ assertEquals("Unit Test - Subject", message.getSubject());
+
+ // Check the message body, including attachments...
+ MimeMultipart content = (MimeMultipart) message.getContent(); // expect a cast exception if it's not the expected type!
+ assertEquals(3, content.getCount()); // the message and the 2 attachments - see testfile4.xml
+ MimeBodyPart part = (MimeBodyPart) content.getBodyPart(0); // the message
+ assertEquals("Unit Test - Message", ((String)part.getContent()).trim());
+ part = (MimeBodyPart) content.getBodyPart(1); // attachement 1
+ assertEquals("attachment1.txt", ((String)part.getFileName()).trim());
+ part = (MimeBodyPart) content.getBodyPart(2); // attachement 2
+ assertEquals("attachment2.txt", ((String)part.getFileName()).trim());
+ }
+
+ // TODO: Add some negative tests!!!
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/KeyValuePairUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/KeyValuePairUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/KeyValuePairUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,84 @@
+/*
+ * 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.helpers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the KeyValuePair class.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class KeyValuePairUnitTest extends TestCase {
+
+ public void test_Constructor_args() {
+ try {
+ new KeyValuePair(null, "aaa");
+ fail("Expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+ try {
+ new KeyValuePair(" ", "aaa");
+ fail("Expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+ new KeyValuePair("a", "aaa");
+ new KeyValuePair("a", null);
+ new KeyValuePair("a", "");
+ }
+
+ public void test_methods() {
+ KeyValuePair kvp = new KeyValuePair("key", "value");
+
+ assertEquals("key", kvp.getKey());
+ assertEquals("value", kvp.getValue());
+ assertEquals("value", kvp.toString());
+ assertEquals("KVpair[key=value]", kvp.dump());
+ }
+
+ public void test_list() {
+ List<KeyValuePair> list = new ArrayList<KeyValuePair>();
+
+ list.add(new KeyValuePair("key1", "value1"));
+ list.add(new KeyValuePair("key2", "true"));
+ list.add(new KeyValuePair("key3", "false"));
+ list.add(new KeyValuePair("key4", "2"));
+ list.add(new KeyValuePair("key5", "10.8"));
+
+ assertEquals("value1", KeyValuePair.getValue("key1", list));
+ assertEquals("true", KeyValuePair.getValue("key2", list));
+ assertEquals("false", KeyValuePair.getValue("key3", list));
+ assertEquals("2", KeyValuePair.getValue("key4", list));
+
+ assertEquals(true, KeyValuePair.getBooleanValue("key2", list, false));
+ assertEquals(false, KeyValuePair.getBooleanValue("key3", list, true));
+ assertEquals(true, KeyValuePair.getBooleanValue("key1", list, true));
+
+ assertEquals(2.0, KeyValuePair.getDoubleValue("key4", list, 10.0));
+ assertEquals(10.8, KeyValuePair.getDoubleValue("key5", list, 2.0));
+ assertEquals(100.0, KeyValuePair.getDoubleValue("key1", list, 100.0));
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_01.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_01.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_01.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,7 @@
+<test>
+ <el index="1"/>
+ <el index="2">
+ <el index="2.1"/>
+ And some text...
+ </el>
+</test>
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_02.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_02.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_02.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1 @@
+<test> <el index="1"/> <el index="2"> <el index="2.1"/> And some text... </el> </test>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_03.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_03.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/expected_03.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1 @@
+<root><el index="1"/>Some root text...<el index="2">Some nested text...</el> and some more root text...</root>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile1.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile1.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile1.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,7 @@
+<test>
+ <el index="1"/>
+ <el index="2">
+ <el index="2.1"/>
+ And some text...
+ </el>
+</test>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile2.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile2.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile2.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1 @@
+<test attrib1="value1" attrib2="value2" attrib3="valu3" />
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile3.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile3.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile3.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1 @@
+<root><el index="1"/>Some root text...<el index="2">Some nested text...</el> and some more root text...</root>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile4.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile4.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/testfile4.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,9 @@
+<mailParams from="x.x at x.com"
+ sendTo="b.b at b.com,c.c at c.com"
+ ccTo="d.d at c.com,e.e at e.com"
+ subject="Unit Test - Subject" message="Unit Test - Message">
+
+ <attachment>attachment1.txt</attachment>
+ <attachment>attachment2.txt</attachment>
+
+</mailParams>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessageImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessageImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessageImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,117 @@
+package org.jboss.soa.esb.message.format.tests;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Attachment;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Context;
+import org.jboss.soa.esb.message.Fault;
+import org.jboss.soa.esb.message.Header;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new message formats dynamically. Each plugin is responsible for
+ * returning a message implementation that knows how to serialize its state in a
+ * specific manner, e.g., XML or ASN.1.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class ExampleMessageImpl implements Message
+{
+
+ /**
+ * @return get the header component of the message.
+ */
+
+ public Header getHeader ()
+ {
+ return null;
+ }
+
+ /**
+ * @return get the context component of the message.
+ */
+
+ public Context getContext ()
+ {
+ return null;
+ }
+
+ /**
+ * @return get the body component of the message.
+ */
+
+ public Body getBody ()
+ {
+ return null;
+ }
+
+ /**
+ * @return get any faults associated with the message. These should not
+ * be application level faults, but comms level.
+ */
+
+ public Fault getFault ()
+ {
+ return null;
+ }
+
+ /**
+ * @return get any message attachments.
+ */
+
+ public Attachment getAttachment ()
+ {
+ return null;
+ }
+ /**
+ * @return get any message properties
+ */
+ public Properties getProperties()
+ {
+ return null;
+ }
+
+ /**
+ * @return the type of this message.
+ */
+
+ public URI getType ()
+ {
+ try
+ {
+ return new URI(ExampleMessagePlugin.URN);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessagePlugin.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessagePlugin.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/ExampleMessagePlugin.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,69 @@
+package org.jboss.soa.esb.message.format.tests;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessagePlugin;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Used to plug in new message formats dynamically. Each plugin is responsible for
+ * returning a message implementation that knows how to serialize its state in a
+ * specific manner, e.g., XML or ASN.1.
+ *
+ * @author Mark Little
+ *
+ */
+
+public class ExampleMessagePlugin implements MessagePlugin
+{
+
+ public static final String URN = "foobar";
+
+ /**
+ * @return the message instance.
+ */
+
+ public Message getMessage ()
+ {
+ return new ExampleMessageImpl();
+ }
+
+ /**
+ * @return the unique identifier for this message plugin.
+ */
+
+ public URI getType ()
+ {
+ try
+ {
+ return new URI(URN);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/format/tests/MessageFactoryUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,131 @@
+/*
+ * 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.message.format.tests;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessagePlugin;
+import org.jboss.soa.esb.message.format.MessageType;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class MessageFactoryUnitTest extends TestCase
+{
+ public void testDefaultMessage ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+
+ assertEquals((msg != null), true);
+ }
+
+ public void testURIMessage ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(MessageType.DEFAULT_TYPE);
+ Message msg2 = MessageFactory.getInstance().getMessage();
+
+ assertEquals(msg1.getType().equals(msg2.getType()), true);
+
+ Message msg3 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ assertEquals(msg1.getType().equals(msg3.getType()), false);
+ }
+
+ public void testInvalidURIMessage ()
+ {
+ try
+ {
+ Message msg = MessageFactory.getInstance().getMessage(new URI("urn:foo"));
+
+ assertEquals((msg == null), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testNullURIMessage ()
+ {
+ try
+ {
+ @SuppressWarnings("unused")
+ Message msg = MessageFactory.getInstance().getMessage(null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ // success
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testNullURIConvertMessage ()
+ {
+ try
+ {
+ @SuppressWarnings("unused")
+ Message msg = MessageFactory.getInstance().getMessage(null, null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ // success
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testPlugin ()
+ {
+ System.setProperty(MessagePlugin.MESSAGE_PLUGIN+"1", ExampleMessagePlugin.class.getName());
+
+ MessageFactory.getInstance().reset();
+
+ try
+ {
+ URI uri = new URI(ExampleMessagePlugin.URN);
+ Message msg = MessageFactory.getInstance().getMessage(uri);
+
+ assertEquals(msg.getType().equals(uri), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/AttachmentUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,207 @@
+/*
+ * 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.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.jboss.soa.esb.message.Attachment;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.w3c.dom.Document;
+
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class AttachmentUnitTest extends TestCase
+{
+
+ public void testSerializeAttachment()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ Attachment at = msg.getAttachment();
+
+ assertEquals((msg != null), true);
+
+ at.addItem(new ExampleObject(0)); // un-named
+ at.addItemAt(0, new ExampleObject(0)); // un-named;
+
+ try
+ {
+ at.addItem(new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ assertEquals(at.getUnnamedCount(), 2);
+
+ assertEquals(at.get("foo"), null);
+
+ at.put("foobar", new ExampleObject(1));
+
+ assertEquals(at.getNamedCount(), 1);
+
+ at.addItem(new ExampleObject(1));
+ at.addItem(new ExampleObject(2));
+
+ assertEquals((at.getNames() != null), true);
+
+ assertEquals((at.removeItemAt(0) != null), true);
+
+ at.replaceItemAt(0, new ExampleObject(2));
+
+ int count = at.getUnnamedCount();
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ assertEquals(nImpl.getAttachment().getUnnamedCount(), count);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testXMLAttachment()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ Attachment at = msg.getAttachment();
+
+ assertEquals((msg != null), true);
+
+ at.addItem(new ExampleObject(0)); // un-named
+ at.addItemAt(0, new ExampleObject(0)); // un-named;
+
+ try
+ {
+ at.addItem(new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ assertEquals(at.getUnnamedCount(), 2);
+
+ assertEquals(at.get("foo"), null);
+
+ at.put("foobar", new ExampleObject(1));
+
+ assertEquals(at.getNamedCount(), 1);
+
+ at.addItem(new ExampleObject(1));
+ at.addItem(new ExampleObject(2));
+
+ assertEquals((at.getNames() != null), true);
+
+ assertEquals((at.removeItemAt(0) != null), true);
+
+ at.replaceItemAt(0, new ExampleObject(2));
+
+ int count = at.getUnnamedCount();
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl theImpl = (org.jboss.internal.soa.esb.message.format.xml.MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ System.err.println("Message looks like: " + documentAsString);
+
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl nImpl = new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+
+ nImpl.fromXML(doc);
+
+ assertEquals(nImpl.getAttachment().getUnnamedCount(), count);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/ExampleObject.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,49 @@
+/*
+ * 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.message.tests;
+
+import java.io.Serializable;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class ExampleObject implements Serializable
+{
+ private static final long serialVersionUID = 0x0;
+
+ public ExampleObject (long val)
+ {
+ value = val;
+ }
+
+ public long getValue ()
+ {
+ return value;
+ }
+
+ private long value;
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/FaultUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/FaultUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/FaultUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,143 @@
+/*
+ * 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.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.StringWriter;
+import java.net.URI;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.w3c.dom.Document;
+
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class FaultUnitTest extends TestCase
+{
+
+ public void testSerializeFault ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ URI code = new URI("urn:code");
+
+ msg.getFault().setCode(code);
+ msg.getFault().setReason("because");
+
+ assertEquals(msg.getFault().getCode(), code);
+ assertEquals(msg.getFault().getReason(), "because");
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ assertEquals(nImpl.getFault().getReason(), "because");
+
+ o.close();
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testXMLFault ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ URI code = new URI("urn:code");
+
+ msg.getFault().setCode(code);
+ msg.getFault().setReason("because");
+
+ assertEquals(msg.getFault().getCode(), code);
+ assertEquals(msg.getFault().getReason(), "because");
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl theImpl = (org.jboss.internal.soa.esb.message.format.xml.MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ System.err.println("Message looks like: " + documentAsString);
+
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl nImpl = new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+
+ nImpl.fromXML(doc);
+
+ assertEquals(nImpl.getFault().getReason(), "because");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,76 @@
+/*
+ * 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.message.tests;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class MessageUnitTest extends TestCase
+{
+
+ public void testDefaultMessageFields ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+
+ assertEquals((msg.getBody() != null), true);
+ assertEquals((msg.getHeader() != null), true);
+ assertEquals((msg.getContext() != null), true);
+ assertEquals((msg.getAttachment() != null), true);
+ assertEquals((msg.getFault() != null), true);
+ assertEquals((msg.getProperties() != null), true);
+ }
+
+ public void testXMLMessageFields ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+
+ assertEquals((msg.getBody() != null), true);
+ assertEquals((msg.getHeader() != null), true);
+ assertEquals((msg.getContext() != null), true);
+ assertEquals((msg.getAttachment() != null), true);
+ assertEquals((msg.getFault() != null), true);
+ assertEquals((msg.getProperties() != null), true);
+ }
+
+ public void testSerializedMessageFields ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg.getBody() != null), true);
+ assertEquals((msg.getHeader() != null), true);
+ assertEquals((msg.getContext() != null), true);
+ assertEquals((msg.getAttachment() != null), true);
+ assertEquals((msg.getFault() != null), true);
+ assertEquals((msg.getProperties() != null), true);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/PropertiesUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/PropertiesUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/PropertiesUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,161 @@
+/*
+ * 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.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.w3c.dom.Document;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class PropertiesUnitTest extends TestCase
+{
+
+ public void testSerializeProperties()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ msg.getProperties().setProperty("foo", "bar");
+
+ assertEquals(msg.getProperties().getProperty("foo"), "bar");
+ assertEquals((msg.getProperties().getProperty("foobar") == null), true);
+
+ assertEquals(msg.getProperties().getProperty("foobar", "barfoo"),
+ "barfoo");
+
+ try
+ {
+ msg.getProperties().setProperty("1234", new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ msg.getProperties().getNames();
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ assertEquals(nImpl.getProperties().getProperty("foo"), "bar");
+
+ o.close();
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ assertEquals(msg.getProperties().remove("foo"), "bar");
+ }
+
+ public void testXMLProperties()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ msg.getProperties().setProperty("foo", "bar");
+
+ assertEquals(msg.getProperties().getProperty("foo"), "bar");
+ assertEquals((msg.getProperties().getProperty("foobar") == null), true);
+
+ assertEquals(msg.getProperties().getProperty("foobar", "barfoo"),
+ "barfoo");
+
+ try
+ {
+ msg.getProperties().setProperty("1234", new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ msg.getProperties().getNames();
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl theImpl = (org.jboss.internal.soa.esb.message.format.xml.MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ org.jboss.internal.soa.esb.message.format.xml.MessageImpl nImpl = new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+
+ nImpl.fromXML(doc);
+
+ assertEquals(nImpl.getProperties().getProperty("foo"), "bar");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ assertEquals(msg.getProperties().remove("foo"), "bar");
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,336 @@
+/*
+ * 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.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class SerializedMessageUnitTest extends TestCase
+{
+
+ public void testSerialize()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+
+ }
+
+ public void testDeserialize()
+ {
+ // get XML message
+
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ @SuppressWarnings("unused")
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testHeader ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ Call call = new Call();
+
+ msg.getHeader().setCall(call);
+
+ call = msg.getHeader().getCall();
+
+ assertEquals((call != null), true);
+
+ try
+ {
+ msg.getHeader().setCall(null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testInvalidAdd ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ msg.getBody().add(null, null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testAddBytes ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ String testString = "test";
+
+ msg.getBody().setContents(testString.getBytes());
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ String val = new String(nImpl.getBody().getContents());
+
+ assertEquals(val, testString);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testReplace ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg1 != null), true);
+
+ String foo = "foo";
+
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg2 != null), true);
+
+ String bar = "bar";
+
+ msg1.getBody().setContents(foo.getBytes());
+ msg2.getBody().setContents(bar.getBytes());
+
+ msg1.getBody().replace(msg2.getBody());
+
+ String foobar = new String(msg1.getBody().getContents());
+
+ assertEquals(foobar.equals("bar"), true);
+ }
+
+ public void testMerge ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg1 != null), true);
+
+ String foo = "foo";
+
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg2 != null), true);
+
+ String bar = "bar";
+
+ msg1.getBody().setContents(foo.getBytes());
+ msg2.getBody().setContents(bar.getBytes());
+
+ msg1.getBody().merge(msg2.getBody());
+
+ String foobar = new String(msg1.getBody().getContents());
+
+ assertEquals(foobar, "foobar");
+ }
+
+ public void testAddObjects ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ ExampleObject value = new ExampleObject(1234);
+
+ msg.getBody().add("foo", value);
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ ExampleObject foo = (ExampleObject) nImpl.getBody().get("foo");
+
+ assertEquals((foo.getValue() == value.getValue()), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testAddInvalidObject ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ msg.getBody().add("foo", new Object());
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testRemoveObjects ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+
+ assertEquals((msg != null), true);
+
+ ExampleObject value = new ExampleObject(1234);
+
+ msg.getBody().add("bar", value);
+
+ msg.getBody().remove("bar");
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ ExampleObject foo = (ExampleObject) nImpl.getBody().get("bar");
+
+ assertEquals((foo == null), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,368 @@
+/*
+ * 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.message.tests;
+
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.message.format.xml.MessageImpl;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.w3c.dom.Document;
+
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+/**
+ * Unit tests for the Class class.
+ *
+ * @author Mark Little
+ */
+
+public class XMLMessageUnitTest extends TestCase
+{
+
+ public void testToXML()
+ {
+ // get XML message
+
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ System.err.println("Message looks like: " + documentAsString);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testFromXML()
+ {
+ // get XML message
+
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ MessageImpl nImpl = new MessageImpl();
+
+ nImpl.fromXML(doc);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testHeader ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ Call call = new Call();
+
+ msg.getHeader().setCall(call);
+
+ call = msg.getHeader().getCall();
+
+ assertEquals((call != null), true);
+
+ try
+ {
+ msg.getHeader().setCall(null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testInvalidAdd ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ try
+ {
+ msg.getBody().add(null, null);
+
+ fail();
+ }
+ catch (IllegalArgumentException ex)
+ {
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testAddBytes ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ String testString = "test";
+
+ msg.getBody().setContents(testString.getBytes());
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ MessageImpl nImpl = new MessageImpl();
+
+ System.err.println("Document is "+documentAsString);
+
+ nImpl.fromXML(doc);
+
+ String val = new String(nImpl.getBody().getContents());
+
+ assertEquals(val, testString);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testReplace ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg1 != null), true);
+
+ String foo = "foo";
+
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg2 != null), true);
+
+ String bar = "bar";
+
+ msg1.getBody().setContents(foo.getBytes());
+ msg2.getBody().setContents(bar.getBytes());
+
+ msg1.getBody().replace(msg2.getBody());
+
+ String foobar = new String(msg1.getBody().getContents());
+
+ assertEquals(foobar.equals("bar"), true);
+ }
+
+ public void testMerge ()
+ {
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg1 != null), true);
+
+ String foo = "foo";
+
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg2 != null), true);
+
+ String bar = "bar";
+
+ msg1.getBody().setContents(foo.getBytes());
+ msg2.getBody().setContents(bar.getBytes());
+
+ msg1.getBody().merge(msg2.getBody());
+
+ String foobar = new String(msg1.getBody().getContents());
+
+ assertEquals(foobar, "foobar");
+ }
+
+ public void testAddObjects ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ ExampleObject value = new ExampleObject(1234);
+
+ msg.getBody().add("foo", value);
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ MessageImpl nImpl = new MessageImpl();
+
+ System.err.println("Document is "+documentAsString);
+
+ nImpl.fromXML(doc);
+
+ ExampleObject foo = (ExampleObject) nImpl.getBody().get("foo");
+
+ assertEquals((foo.getValue() == value.getValue()), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testRemoveObjects ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+
+ assertEquals((msg != null), true);
+
+ ExampleObject value = new ExampleObject(1234);
+
+ msg.getBody().add("bar", value);
+
+ msg.getBody().remove("bar");
+
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ MessageImpl theImpl = (MessageImpl) msg;
+
+ doc = theImpl.toXML(doc);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
+
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
+
+ String documentAsString = sWriter.toString();
+
+ MessageImpl nImpl = new MessageImpl();
+
+ System.err.println("Document is "+documentAsString);
+
+ nImpl.fromXML(doc);
+
+ ExampleObject foo = (ExampleObject) nImpl.getBody().get("bar");
+
+ assertEquals((foo == null), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,53 @@
+/*
+ * 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.notification;
+
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.notification.MacroExpander;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * MacroExpander unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MacroExpanderUnitTest extends TestCase {
+
+ public void testReplaceMacros() {
+ ConfigTree rootDomEl = new ConfigTree("rootEl");
+ HashMap<String, String> map = new HashMap<String, String>();
+
+ ConfigTree childDomEl = new ConfigTree("childEl",rootDomEl);
+ rootDomEl.setAttribute("attrb1", "value1");
+ rootDomEl.setAttribute("attrb2", MacroExpander.CTX_BATCH_NUM + "BatchNumValue");
+ childDomEl.setAttribute("attrb1", MacroExpander.CTX_BATCH_UID + "UIDValue");
+ map.put(MacroExpander.CTX_BATCH_NUM, "ReplacementBNV!");
+ map.put(MacroExpander.CTX_BATCH_UID, "ReplacementUIDV!");
+
+ MacroExpander.replaceMacros(rootDomEl, map);
+ String expected = new String(StreamUtils.readStream(getClass().getResourceAsStream("MacroExpanderUnitTest_expected1.xml")));
+ assertEquals(expected.trim(), rootDomEl.toString().trim());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest_expected1.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest_expected1.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/MacroExpanderUnitTest_expected1.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1 @@
+<rootEl attrb1="value1" attrb2="ReplacementBNV!BatchNumValue"><childEl attrb1="ReplacementUIDV!UIDValue"/></rootEl>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotificationListUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotificationListUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotificationListUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,75 @@
+/*
+ * 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.notification;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * NotificationList unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotificationListUnitTest extends TestCase {
+
+ public void test_NotificationList() throws Exception {
+ ConfigTree domEl = ConfigTree.fromInputStream(getClass().getResourceAsStream("NotificationListUnitTest_testfile1.xml"));
+ NotificationList nList = new NotificationList(domEl);
+
+ List<String> messageList = new ArrayList<String>();
+ TestNotificationTarget1.messageList = messageList;
+ TestNotificationTarget2.messageList = messageList;
+
+ nList.sendNotification("tom");
+ assertEquals(4, messageList.size());
+ assertEquals("message 1-tom", messageList.get(0));
+ assertEquals("message 2-tom", messageList.get(1));
+ assertEquals("message 3-tom", messageList.get(2));
+ assertEquals("message 4-tom", messageList.get(3));
+ }
+
+ public void test_assertionMethods() throws Exception {
+ ConfigTree domEl;
+ NotificationList nList;
+
+ domEl = new ConfigTree("notif");
+ nList = new NotificationList(domEl);
+ assertTrue(nList.isOK());
+ assertTrue(nList.isErr());
+ // REVIEW: Is this behavior OK?? Can be OK and Err at the same time!!
+
+ domEl = new ConfigTree("notif");
+ domEl.setAttribute(NotificationList.TYPE, "ok");
+ nList = new NotificationList(domEl);
+ assertTrue(nList.isOK());
+ assertTrue(!nList.isErr());
+
+ domEl = new ConfigTree("notif");
+ domEl.setAttribute(NotificationList.TYPE, "err");
+ nList = new NotificationList(domEl);
+ assertTrue(!nList.isOK());
+ assertTrue(nList.isErr());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotificationListUnitTest_testfile1.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotificationListUnitTest_testfile1.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotificationListUnitTest_testfile1.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,6 @@
+<notif type="ok">
+ <target class="TestNotificationTarget1" message="message 1" />
+ <target class="TestNotificationTarget1" message="message 2" />
+ <target class="TestNotificationTarget2" message="message 3" />
+ <target class="TestNotificationTarget2" message="message 4" />
+</notif>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyEmailUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyEmailUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyEmailUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,58 @@
+/*
+ * 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.notification;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.Email;
+
+/**
+ * NotifyEmail unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifyEmailUnitTest extends TestCase {
+
+ public void test_NotifyEmail() throws Exception {
+ ConfigTree emailMessageEl = new ConfigTree("email");
+
+ emailMessageEl.setAttribute(Email.FROM, "a.b at c.com");
+ emailMessageEl.setAttribute(Email.SENDTO, "d.e at f.com");
+ emailMessageEl.setAttribute(Email.COPYTO, "g.h at i.com");
+ emailMessageEl.setAttribute(Email.MESSAGE, "Hi there!!!");
+
+ NotifyEmail ne = new TestNotifyEmail(emailMessageEl);
+ ne.sendNotification("Hello");
+ }
+
+ private class TestNotifyEmail extends NotifyEmail {
+ public TestNotifyEmail(ConfigTree p_oP) throws Exception {
+ super(p_oP);
+ }
+ protected void sendEmailNotification(ConfigTree messageParams) throws AddressException, MessagingException {
+ assertEquals("Hi there!!!\nHello", messageParams.getAttribute(Email.MESSAGE));
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyFilesUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyFilesUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyFilesUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,124 @@
+/*
+ * 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.notification;
+
+import java.io.File;
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * NotifyFiles unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifyFilesUnitTest extends TestCase {
+
+ public void test_BadFolderInfo() throws Exception {
+ ConfigTree rootEl = new ConfigTree("notif");
+ ConfigTree fileEl = new ConfigTree("file",rootEl);
+
+ // No file attribute defined on the ConfigTree
+ try {
+ new NotifyFiles(rootEl);
+ fail("Expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // Expected
+ }
+ // File attribute defined on the ConfigTree, but parent folder doesn't exist...
+ fileEl.setAttribute("URI", new File("./").toURI().toString() + "/xyzzyx/a.txt");
+ try {
+ new NotifyFiles(rootEl);
+ fail("Expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // Expected
+ }
+ }
+
+ public void test_StringObj() throws Exception {
+ sendNotification("Hello");
+ }
+
+ public void test_NonStringObj() throws Exception {
+ sendNotification(new Integer(1234));
+ }
+
+ public void sendNotification(Serializable obj) throws Exception {
+ ConfigTree rootEl = new ConfigTree("notif");
+ NotifyFiles notifyFiles;
+
+ // Add the file configs to the config DOM for 4 files...
+ addFileConfig(rootEl, "file1.notif", true);
+ addFileConfig(rootEl, "file2.notif", true);
+ addFileConfig(rootEl, "file3.notif", false);
+ addFileConfig(rootEl, "file4.notif", null);
+
+ // Create the class and call the sendNotification method twice...
+ notifyFiles = new NotifyFiles(rootEl);
+ notifyFiles.sendNotification(obj);
+ notifyFiles.sendNotification(obj);
+
+ // Test the files. Files 1 and 2 should be the same size. Files 3 and 4 should be the
+ // same size. Files 1 and 2 should be twice as big as files 3 and 4 because append was set
+ // "true" on 1 and 2 and sendNotification() was called twice...
+ File file1Obj = getFileObject("file1.notif");
+ File file2Obj = getFileObject("file2.notif");
+ File file3Obj = getFileObject("file3.notif");
+ File file4Obj = getFileObject("file4.notif");
+ assertEquals(file1Obj.length(), file2Obj.length());
+ assertEquals(file3Obj.length(), file4Obj.length());
+ assertEquals(file1Obj.length(), file3Obj.length() * 2);
+ }
+
+ private void addFileConfig(ConfigTree rootEl, String file, Boolean append) {
+ File fileObj = getFileObject(file);
+ ConfigTree fileEl = new ConfigTree("file",rootEl);
+
+ fileEl.setAttribute("URI", fileObj.toURI().toString());
+ fileEl.setAttribute("append", (append != null?append.toString():null));
+
+ // Also want to delete the file incase the tests are being rerun...
+ fileObj.delete();
+ }
+
+ private File getFileObject(String file) {
+ // TF: Excuse this hack!!! It's the safest way of calculating a
+ // relative URI within the test structure. It will prob cause
+ // Maven some issues i.e. getting it to work for both Ant and Maven :-(
+ // This code assumes that the working dir is the "product" folder.
+
+ File fileObj = new File("build/tests/" + getPKg() + "/" + file);
+ if(!fileObj.getParentFile().exists()) {
+ // The build folder may not exist e.g. if running this test from
+ // inside your IDE.
+ fileObj.getParentFile().mkdirs();
+ }
+
+ return fileObj;
+ }
+
+ private String getPKg() {
+ String javaPackage = NotifyFilesUnitTest.class.getPackage().getName();
+ return javaPackage.replace('.', '/');
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,138 @@
+/*
+ * 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.notification;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+/**
+ * NotifyQueues unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifyQueuesUnitTest extends TestCase {
+
+ private MockQueue mockQueue1;;
+ private MockQueue mockQueue2;
+ private NotifyQueues notifyQueues;
+
+ protected void setUp() throws Exception {
+ MockContextFactory.setAsInitial();
+ Context ctx = new InitialContext();
+ ctx.rebind(NotifyQueues.CONNECTION_FACTORY, new QueueConnectionFactoryImpl());
+
+ ConfigTree rootEl = new ConfigTree("rootEl");
+
+ addMessagePropertyConfigs(rootEl);
+ addQueueConfig(rootEl, "queue1");
+ addQueueConfig(rootEl, "queue2");
+ mockQueue1 = createAndBindQueue("queue1");
+ mockQueue2 = createAndBindQueue("queue2");
+
+ notifyQueues = new NotifyQueues(rootEl);
+ }
+
+ protected void tearDown() throws Exception {
+ notifyQueues.release();
+ MockContextFactory.revertSetAsInitial();
+ }
+
+ public void test_StringObj() throws Exception {
+ notifyQueues.sendNotification("Hello");
+
+ checkQueueTextMessage(mockQueue1, 0, "Hello");
+ checkQueueTextMessage(mockQueue2, 0, "Hello");
+ }
+
+ public void test_NonStringObj() throws Exception {
+ notifyQueues.sendNotification(new Integer(123));
+
+ checkQueueObjectMessage(mockQueue1, 0, new Integer(123));
+ checkQueueObjectMessage(mockQueue2, 0, new Integer(123));
+ }
+
+ private void checkQueueTextMessage(MockQueue mockQueue, int messageIdx, String expectedText) throws JMSException {
+ assertTrue(mockQueue.getMessages().size() > messageIdx);
+ Message message = mockQueue.getMessageAt(0);
+ assertTrue(message instanceof TextMessage);
+ assertEquals(expectedText, ((TextMessage)message).getText());
+ assertEquals("testpropvalue", message.getStringProperty("testpropname"));
+ }
+
+ private void checkQueueObjectMessage(MockQueue mockQueue, int messageIdx, Object expectedObj) throws JMSException {
+ assertTrue(mockQueue.getMessages().size() > messageIdx);
+ Message message = mockQueue.getMessageAt(0);
+ assertTrue(message instanceof ObjectMessage);
+ assertEquals(expectedObj, ((ObjectMessage)message).getObject());
+
+ // Note that the property bindings don't seem to work in this test i.e.
+ // it's returning null but should be returning the same as for a
+ // TextMessage (See above). This is most likely a mockejb lib issue
+ // and so we're ignoring it :-)
+ assertEquals(null, message.getStringProperty("testpropname"));
+ }
+
+ private void addMessagePropertyConfigs(ConfigTree rootEl) {
+
+ ConfigTree propEl = new ConfigTree(NotifyQueues.CHILD_MSG_PROP,rootEl);
+
+ propEl.setAttribute(NotifyJMS.ATT_PROP_NAME, "testpropname");
+ propEl.setAttribute(NotifyJMS.ATT_PROP_VALUE, "testpropvalue");
+ }
+
+ private void addQueueConfig(ConfigTree rootEl, String queueName) {
+ ConfigTree queueEl = new ConfigTree(NotifyQueues.CHILD_QUEUE,rootEl);
+
+ queueEl.setAttribute(NotifyJMS.ATT_DEST_NAME, queueName);
+ }
+
+ private MockQueue createAndBindQueue(String queueName) throws NamingException {
+ MockQueue mockQueue = new MockQueue(queueName);
+
+ Context ctx = new InitialContext();
+ ctx.rebind(queueName, mockQueue);
+
+ return mockQueue;
+ }
+
+ @SuppressWarnings("unused")
+ private MockTopic createAndBindTopic(String topicName) throws NamingException {
+ MockTopic mockTopic = new MockTopic(topicName);
+
+ Context ctx = new InitialContext();
+ ctx.rebind(topicName, mockTopic);
+
+ return mockTopic;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifySqlTableUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifySqlTableUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifySqlTableUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,52 @@
+/*
+ * 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.notification;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * NotifySqlTable unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifySqlTableUnitTest extends TestCase {
+
+ public void test_NotifySqlTable() throws Exception {
+ ConfigTree domEl = ConfigTree.fromInputStream(getClass().getResourceAsStream("NotifySqlTable_testfile1.xml"));
+ NotifySqlTable nst = new NotifySqlTable(domEl);
+
+ assertEquals("driver-class", nst.m_sDriver);
+ assertEquals("connection-url", nst.m_sURL);
+ assertEquals("user-name", nst.m_sUser);
+ assertEquals("password", nst.m_sPwd);
+ assertEquals("table", nst.m_sTable);
+ assertEquals("dataColumn", nst.m_sDataCol);
+
+ assertEquals(3, nst.m_oCols.size());
+ assertEquals("colvalue1", nst.m_oCols.getProperty("colname1"));
+ assertEquals("colvalue2", nst.m_oCols.getProperty("colname2"));
+ assertEquals("colvalue3", nst.m_oCols.getProperty("colname3"));
+
+ assertEquals("insert into table (\"colname3\",\"colname2\",\"colname1\") values ('colvalue3','colvalue2','colvalue1')", nst.getInsertStmt());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifySqlTable_testfile1.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifySqlTable_testfile1.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifySqlTable_testfile1.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,12 @@
+<notif driver-class="driver-class"
+ connection-url="connection-url"
+ user-name="user-name"
+ password="password"
+ table="table"
+ dataColumn="dataColumn">
+
+ <column name="colname1" value="colvalue1"/>
+ <column name="colname2" value="colvalue2"/>
+ <column name="colname3" value="colvalue3"/>
+
+</notif>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,126 @@
+/*
+ * 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.notification;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+/**
+ * NotifyTopics unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifyTopicsUnitTest extends TestCase {
+
+ private MockTopic mockTopic1;;
+ private MockTopic mockTopic2;
+ private NotifyTopics notifyTopics;
+
+ protected void setUp() throws Exception {
+ MockContextFactory.setAsInitial();
+ Context ctx = new InitialContext();
+ ctx.rebind(NotifyTopics.CONNECTION_FACTORY, new TopicConnectionFactoryImpl());
+
+ ConfigTree rootEl = new ConfigTree("rootEl");
+
+ addMessagePropertyConfigs(rootEl);
+ addTopicConfig(rootEl, "topic1");
+ addTopicConfig(rootEl, "topic2");
+ mockTopic1 = createAndBindTopic("topic1");
+ mockTopic2 = createAndBindTopic("topic2");
+
+ notifyTopics = new NotifyTopics(rootEl);
+ }
+
+ protected void tearDown() throws Exception {
+ notifyTopics.release();
+ MockContextFactory.revertSetAsInitial();
+ }
+
+ public void test_StringObj() throws Exception {
+ notifyTopics.sendNotification("Hello");
+
+ checkTopicTextMessage(mockTopic1, 0, "Hello");
+ checkTopicTextMessage(mockTopic2, 0, "Hello");
+ }
+
+ public void test_NonStringObj() throws Exception {
+ notifyTopics.sendNotification(new Integer(123));
+
+ checkTopicObjectMessage(mockTopic1, 0, new Integer(123));
+ checkTopicObjectMessage(mockTopic2, 0, new Integer(123));
+ }
+
+ private void checkTopicTextMessage(MockTopic mockTopic, int messageIdx, String expectedText) throws JMSException {
+ assertTrue(mockTopic.getMessages().size() > messageIdx);
+ Message message = mockTopic.getMessageAt(0);
+ assertTrue(message instanceof TextMessage);
+ assertEquals(expectedText, ((TextMessage)message).getText());
+ assertEquals("testpropvalue", message.getStringProperty("testpropname"));
+ }
+
+ private void checkTopicObjectMessage(MockTopic mockTopic, int messageIdx, Object expectedObj) throws JMSException {
+ assertTrue(mockTopic.getMessages().size() > messageIdx);
+ Message message = mockTopic.getMessageAt(0);
+ assertTrue(message instanceof ObjectMessage);
+ assertEquals(expectedObj, ((ObjectMessage)message).getObject());
+
+ // Note that the property bindings don't seem to work in this test i.e.
+ // it's returning null but should be returning the same as for a
+ // TextMessage (See above). This is most likely a mockejb lib issue
+ // and so we're ignoring it :-)
+ assertEquals(null, message.getStringProperty("testpropname"));
+ }
+
+ private void addMessagePropertyConfigs(ConfigTree rootEl) {
+ ConfigTree propEl = new ConfigTree(NotifyTopics.CHILD_MSG_PROP,rootEl);
+
+ propEl.setAttribute(NotifyJMS.ATT_PROP_NAME, "testpropname");
+ propEl.setAttribute(NotifyJMS.ATT_PROP_VALUE, "testpropvalue");
+ }
+
+ private void addTopicConfig(ConfigTree rootEl, String topicName) {
+ ConfigTree topicEl = new ConfigTree(NotifyTopics.CHILD_TOPIC,rootEl);
+
+ topicEl.setAttribute(NotifyJMS.ATT_DEST_NAME, topicName);
+ }
+
+ private MockTopic createAndBindTopic(String topicName) throws NamingException {
+ MockTopic mockTopic = new MockTopic(topicName);
+
+ Context ctx = new InitialContext();
+ ctx.rebind(topicName, mockTopic);
+
+ return mockTopic;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,78 @@
+/*
+ * 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.notification;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.NotificationManager;
+
+/**
+ * NotifyUtil unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifyUtilUnitTest extends TestCase {
+
+ public void test_NotifyUtil() {
+ ConfigTree rootEl = new ConfigTree("rootEl");
+
+ addNotificationConfig(rootEl, "message1", "ok");
+ addNotificationConfig(rootEl, "message2", "err");
+ addNotificationConfig(rootEl, "message3", "ok");
+ addNotificationConfig(rootEl, "message4", "err");
+
+ TestNotificationHandler handler = new TestNotificationHandler();
+ NotifyUtil.notifyOK(handler, rootEl, "somemessage", new HashMap());
+ assertEquals(2, handler.messages.size());
+ assertEquals("message1 - somemessage", handler.messages.get(0));
+ assertEquals("message3 - somemessage", handler.messages.get(1));
+
+ handler.messages.clear();
+ NotifyUtil.notifyError(handler, rootEl, "somemessage", new HashMap(), new Exception("test"));
+ assertEquals(3, handler.messages.size());
+ assertTrue(handler.messages.get(0).startsWith("somemessage"));
+ assertTrue(handler.messages.get(1).startsWith("message2 - somemessage"));
+ assertTrue(handler.messages.get(2).startsWith("message4 - somemessage"));
+ }
+
+ private void addNotificationConfig(ConfigTree rootEl, String message, String type) {
+ ConfigTree notifEl = new ConfigTree(NotificationList.ELEMENT,rootEl);
+ notifEl.setAttribute("message", message);
+ notifEl.setAttribute(NotificationList.TYPE, type);
+ }
+
+ private class TestNotificationHandler implements NotificationManager {
+ private List<String> messages = new ArrayList<String>();
+
+ public void sendNotifications(ConfigTree p_oP, Serializable p_o) throws Exception {
+ messages.add(p_oP.getAttribute("message") + " - " + p_o);
+ }
+ public void sendNotifications(Serializable p_o) throws Exception {
+ messages.add(p_o.toString());
+ }
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/TestNotificationTarget1.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/TestNotificationTarget1.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/TestNotificationTarget1.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,24 @@
+package org.jboss.soa.esb.notification;
+
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+public class TestNotificationTarget1 extends NotificationTarget {
+
+ private ConfigTree config;
+
+ public static List<String> messageList;
+
+ public TestNotificationTarget1(ConfigTree targetConf) {
+ super(targetConf);
+ config = targetConf;
+ }
+
+ @Override
+ public void sendNotification(Serializable obj) throws Exception {
+ messageList.add(config.getAttribute("message") + "-" + obj);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/TestNotificationTarget2.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/TestNotificationTarget2.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/TestNotificationTarget2.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,10 @@
+package org.jboss.soa.esb.notification;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+public class TestNotificationTarget2 extends TestNotificationTarget1 {
+
+ public TestNotificationTarget2(ConfigTree targetConf) {
+ super(targetConf);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/ParamRepositoryFactoryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/ParamRepositoryFactoryUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/ParamRepositoryFactoryUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,53 @@
+/*
+ * 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.parameters;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.parameters.ParamFileRepository;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+
+/**
+ * ParamRepositoryFactory unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ParamRepositoryFactoryUnitTest extends TestCase {
+
+ public void test_ParamRepositoryFactory() {
+ ParamRepository repo;
+
+ repo = ParamRepositoryFactory.getInstance();
+ assertTrue(repo instanceof ParamFileRepository);
+
+ ParamRepositoryFactory.reset();
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).setProperty(Environment.PARAMS_REPOS_IMPL_CLASS, TestParamRepo.class.getName());
+ repo = ParamRepositoryFactory.getInstance();
+ assertTrue(repo instanceof TestParamRepo);
+ }
+
+ public void test_ParamRepositoryException() {
+ // for the coverage results ;-)
+ new ParamRepositoryException("message");
+ new ParamRepositoryException("message", new Exception());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/ParamsFileRepositoryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/ParamsFileRepositoryUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/ParamsFileRepositoryUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,142 @@
+/*
+ * 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.parameters;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.parameters.ParamFileRepository;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+
+/**
+ * ParamFileRepository unit tests.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ParamsFileRepositoryUnitTest extends TestCase
+{
+
+ public void test_ParamsFileRepository() throws Exception
+ {
+ File root;
+ ParamFileRepository fileRepo;
+
+ // Check it defaults to the working dir...
+ root = new File("./");
+ fileRepo = new ParamFileRepository();
+ assertEquals(root, fileRepo.getRoot());
+
+ // Check it can pick up from the System prop...
+ root = new File("build/tests/");
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).setProperty(
+ ParamFileRepository.FILE_PARAMS_REPOS_ROOT, root.getPath());
+ fileRepo = new ParamFileRepository();
+ assertEquals(root, fileRepo.getRoot());
+
+ // Check for error on invalid System prop...
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).setProperty(
+ ParamFileRepository.FILE_PARAMS_REPOS_ROOT, "blah/blah");
+ try
+ {
+ new ParamFileRepository();
+ fail("expected IllegalStateException");
+ } catch (IllegalStateException e)
+ {
+ // expected
+ }
+ }
+
+ public void test_add_get_remove_badargs() throws Exception
+ {
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).setProperty(
+ ParamFileRepository.FILE_PARAMS_REPOS_ROOT, "build/tests/");
+ ParamFileRepository fileRepo = new ParamFileRepository();
+
+ test_add_badargs(fileRepo, null, "val");
+ test_add_badargs(fileRepo, "", "val");
+ test_add_badargs(fileRepo, "", "val");
+ test_add_badargs(fileRepo, "xxx/yyy", null);
+
+ test_get_badargs(fileRepo, null);
+ test_get_badargs(fileRepo, "");
+
+ test_remove_badargs(fileRepo, null);
+ test_remove_badargs(fileRepo, "");
+ }
+
+ private void test_add_badargs(ParamFileRepository fileRepo, String name,
+ String value) throws ParamRepositoryException
+ {
+ try
+ {
+ fileRepo.add(name, value);
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ private void test_get_badargs(ParamFileRepository fileRepo, String name)
+ throws ParamRepositoryException
+ {
+ try
+ {
+ fileRepo.get(name);
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ private void test_remove_badargs(ParamFileRepository fileRepo, String name)
+ {
+ try
+ {
+ fileRepo.remove(name);
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ public void test_add_get_remove() throws Exception
+ {
+ ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).setProperty(
+ ParamFileRepository.FILE_PARAMS_REPOS_ROOT, "build/tests/");
+ ParamFileRepository fileRepo = new ParamFileRepository();
+ String name = "repostests/jboss/testparam";
+
+ // Make sure the parameter doesn't already exist...
+ assertEquals(null, fileRepo.get(name));
+
+ // Now the tests...
+ assertEquals(null, fileRepo.get(name));
+ fileRepo.add(name, "tomtestvalue");
+ assertEquals("tomtestvalue", fileRepo.get(name));
+ fileRepo.remove(name);
+ assertEquals(null, fileRepo.get(name));
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/TestParamRepo.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/TestParamRepo.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/parameters/TestParamRepo.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,26 @@
+package org.jboss.soa.esb.parameters;
+
+public class TestParamRepo implements ParamRepository {
+
+ public TestParamRepo() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public void add(String name, String value)
+ throws ParamRepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String get(String name) throws ParamRepositoryException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void remove(String name) throws ParamRepositoryException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,113 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.util.StreamUtils;
+
+/**
+ * BaseBusinessObject unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class BaseBusinessObjectUnitTest extends TestCase {
+
+ private TestBob bob;
+
+ protected void setUp() throws Exception {
+ bob = new TestBob("blah", 1234L);
+ // Set the base properties...
+ bob.setBatchNum(1234);
+ bob.setElemNm("whoosh");
+ bob.setPackage();
+ bob.setRole("sweeper");
+ bob.setSnap(1234);
+ bob.setSnapDate("12/12/2000");
+ bob.setStamp(1234);
+ bob.setUid(1234);
+ }
+
+ public void test_BaseBusinessObject() throws Exception {
+
+ // ToDTO the bob and back again...
+ BobjStdDTO dtoBefore = bob.toDTO();
+ bob = (TestBob) BaseBusinessObject.getFromDTO(dtoBefore);
+
+ // Check the base properties...
+ assertEquals(1234, bob.getBatchNum());
+ assertEquals(null, bob.getElemNm()); // REVIEW: What happened to "whoosh"
+ assertEquals("sweeper", bob.getRole());
+ assertEquals(1234, bob.getSnap());
+ assertEquals(null, bob.getSnapDate()); // REVIEW: WHat happened to the snap date of "12/12/2000"
+ assertEquals(1234, bob.getStamp());
+ assertEquals(1234, bob.getUid());
+
+ BobjStdDTO dtoAfter = bob.toDTO();
+ assertEquals(TestBob.MY_BOB_PROP_VAL, dtoAfter.getAttr(TestBob.MY_BOB_PROP));
+ assertNotSame(dtoBefore.toXml(), dtoAfter.toXml()); // REVIEW: Would have expected these to be the same!!
+
+ // Construct using the default constructor...
+ bob = new TestBob();
+ assertEquals("TestBob", bob.getElemNm());
+ }
+
+ public void test_getDtoList() throws Exception {
+ List<BaseBusinessObject> bobList = new ArrayList<BaseBusinessObject>();
+
+ bobList.add(new TestBob());
+ bobList.add(new TestBob());
+ bobList.add(new TestBob());
+
+ BobjStdDTO dto = BaseBusinessObject.getDtoList(TestBob.class, bobList);
+ String expected = new String(StreamUtils.readStream(getClass().getResourceAsStream("BaseBusinessObjectUnitTest_testfile1.xml")));
+ assertEquals(expected, dto.toXml());
+ }
+
+ public void test_getRoleFromList() throws Exception {
+ List<BaseBusinessObject> bobList = new ArrayList<BaseBusinessObject>();
+
+ bobList.add(new TestBob());
+ bobList.add(new TestBob());
+ bobList.add(new TestBob());
+
+ bobList.get(0).setRole("role0");
+ bobList.get(1).setRole("role1");
+ bobList.get(2).setRole("role2");
+
+ assertEquals(bobList.get(0), BaseBusinessObject.getRoleFromList("role0", bobList));
+ assertEquals(bobList.get(1), BaseBusinessObject.getRoleFromList("role1", bobList));
+ assertEquals(bobList.get(2), BaseBusinessObject.getRoleFromList("role2", bobList));
+
+ assertEquals(null, BaseBusinessObject.getRoleFromList(null, bobList));
+ assertEquals(null, BaseBusinessObject.getRoleFromList("blah", null));
+ }
+
+ public void test_misc() {
+ // Noddy methods - just touching to improve the coverage figures :-)
+ bob.toString();
+ bob.locator();
+ bob.allLocators();
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest_testfile1.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest_testfile1.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BaseBusinessObjectUnitTest_testfile1.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1 @@
+<TestBob List="yes"><it myBobProp="myBobProp-hello"/><it myBobProp="myBobProp-hello"/><it myBobProp="myBobProp-hello"/></TestBob>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,152 @@
+/*
+ * 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.util;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.StringUtils;
+import org.jboss.soa.esb.W3CDomUtils;
+import org.jboss.soa.esb.common.bizclasses.Address;
+import org.w3c.dom.Document;
+
+/**
+ * BobjStdDTO unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class BobjStdDTOUnitTest extends TestCase {
+
+ public void test_getFromXml_String() throws Exception {
+ try {
+ BobjStdDTO.getFromXml(null);
+ fail("expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+ try {
+ BobjStdDTO.getFromXml(" ");
+ fail("expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+
+ String source = new String(StreamUtils.readStream(
+ getClass().getResourceAsStream("BobjStdDTOUnitTest_testfile1.xml")));
+ BobjStdDTO rootBob = BobjStdDTO.getFromXml(source);
+
+ // Check the attributes on the root element of the serialised object representation...
+ assertEquals("Brum", rootBob.getAttr("fmlyN"));
+ assertEquals("Daniel", rootBob.getAttr("givN"));
+ assertEquals("Mr.", rootBob.getAttr("pfx"));
+ assertEquals("the 1st.", rootBob.getAttr("sfx"));
+ assertTrue(!rootBob.isEmpty());
+ assertTrue(!rootBob.isList());
+
+ // Check the nested Address - this is a "List"....
+ BobjStdDTO childBob = rootBob.getDTO("Laddr");
+ assertNotNull(childBob);
+ assertTrue(!childBob.isEmpty());
+ assertTrue(childBob.isList());
+ // Address is a list type. Calling getAttr should result in an exception...
+ try {
+ childBob.getAttr("xx");
+ fail("expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals("Address", childBob.m_sClassNm);
+ assertEquals(null, childBob.m_oAtts);
+
+ // Run a few more checks...
+ childBob = rootBob.getDTO("Lpho");
+ assertNotNull(childBob);
+ childBob = rootBob.getDTO("Lemail");
+ assertNotNull(childBob);
+
+ // TODO: Add tests for the locator and batch "stuff"!
+ }
+
+ public void test_toDoc() throws Exception {
+ String source = new String(StreamUtils.readStream(
+ getClass().getResourceAsStream("BobjStdDTOUnitTest_testfile1.xml")));
+ BobjStdDTO bob = BobjStdDTO.getFromXml(source);
+
+ // Call toDoc on the Bob, serialise it and compare the serialised
+ // form to the original input. They should match...
+ Document doc = bob.toDoc();
+ String serialisedVer = W3CDomUtils.serialize(doc);
+ assertTrue(StringUtils.equalsIgnoreLinebreaks(source, serialisedVer, false));
+ }
+
+ public void test_getChildObjList() throws Exception {
+ String source = new String(StreamUtils.readStream(
+ getClass().getResourceAsStream("BobjStdDTOUnitTest_testfile1.xml")));
+ BobjStdDTO dto = BobjStdDTO.getFromXml(source);
+
+
+ List<? extends BaseBusinessObject> bobList = dto.getChildObjList("Laddr", Address.class);
+
+ assertEquals(1, bobList.size());
+ assertTrue(bobList.get(0) instanceof Address);
+ Address address = (Address) bobList.get(0);
+ assertEquals("Argentina", address.getField(Address.ATTRIB.cntry));
+ assertEquals("1642", address.getField(Address.ATTRIB.postalZip));
+ assertEquals("Buenos Aires", address.getField(Address.ATTRIB.provSt));
+ assertEquals("Balcarce", address.getField(Address.ATTRIB.strLine1));
+ assertEquals(null, address.getField(Address.ATTRIB.strLine2));
+ assertEquals("50", address.getField(Address.ATTRIB.strNum));
+ assertEquals(null, address.getField(Address.ATTRIB.suite));
+ assertEquals("San Isidro", address.getField(Address.ATTRIB.twnCty1));
+ assertEquals(null, address.getField(Address.ATTRIB.twnCty2));
+ assertEquals(2, address.getPhoneCount());
+ assertEquals("(416)555-1212", address.getPhoneAt(0).toString());
+ assertEquals("+54(11)4555-1111 Ext 7", address.getPhoneAt(1).toString());
+
+ }
+
+ public void test_MiscTests() throws Exception {
+ String source = new String(StreamUtils.readStream(
+ getClass().getResourceAsStream("BobjStdDTOUnitTest_testfile1.xml")));
+ BobjStdDTO bob = BobjStdDTO.getFromXml(source);
+
+ // Calling dump simply to improve the coverage figures - this is a dev utility method
+ // so testing this isn't so important...
+ bob.Dump(0);
+
+ // Check the setter and getter methods. This is a bit anal but makes a
+ // big diff on the coverage figures for this class...
+ bob.setUid(1234);
+ assertEquals(1234, bob.getUid());
+ bob.setBatch(1234);
+ assertEquals(1234, bob.getBatch());
+ bob.setSnap(1234);
+ assertEquals(1234, bob.getSnap());
+ bob.setStamp(1234);
+ assertEquals(1234, bob.getStamp());
+ bob.setSnapDate("30/12/1990");
+ assertEquals("30/12/1990", bob.getSnapDate());
+ bob.setSnapType("blah");
+ assertEquals("blah", bob.getSnapType());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest_testfile1.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest_testfile1.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/BobjStdDTOUnitTest_testfile1.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,18 @@
+<Person fmlyN="Brum" givN="Daniel" pfx="Mr." sfx="the 1st.">
+<Laddr List="yes" __Class="Address">
+<it cntry="Argentina" postalZip="1642" provSt="Buenos Aires" strLine1="Balcarce" strNum="50" twnCty1="San Isidro">
+<Lpho List="yes" __Class="Telephone">
+<it city="416" num="555-1212" rol="torIP"/>
+<it city="11" cntry="54" ext="7" num="4555-1111" rol="home"/>
+</Lpho>
+</it>
+</Laddr>
+<Lpho List="yes" __Class="Telephone">
+<it city="416" cntry="1" num="555-1212" rol="basement"/>
+<it city="416" num="666-4444" rol="cell"/>
+</Lpho>
+<Lemail List="yes" __Class="OneValue">
+<it rol="home" v="myaddr at gmail.com"/>
+<it rol="work" v="john.smith at jboss.com"/>
+</Lemail>
+</Person>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/StreamUtilsUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/StreamUtilsUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/StreamUtilsUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,59 @@
+/*
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.util.StreamUtils;
+
+/**
+ * StreamUtils unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class StreamUtilsUnitTest extends TestCase {
+
+ public void test_readStream_badargs() {
+ try {
+ StreamUtils.readStream(null);
+ fail("expected IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ public void test_readStream() {
+ StringBuffer testBuf = new StringBuffer(500);
+ @SuppressWarnings("unused")
+ byte[] resStream;
+
+ while(testBuf.length() < 500) {
+ testBuf.append("12121212121212121212121212121212121212121212121212");
+ }
+
+ String testString = testBuf.toString();
+ String resString = new String(StreamUtils.readStream(new ByteArrayInputStream(testString.getBytes())));
+
+ assertEquals(testString, resString);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/TestBob.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/TestBob.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/TestBob.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,51 @@
+/*
+ * 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.util;
+
+import junit.framework.TestCase;
+
+class TestBob extends BaseBusinessObject {
+
+ public static final String MY_BOB_PROP = "myBobProp";
+ public static final String MY_BOB_PROP_VAL = "myBobProp-hello";
+
+ public TestBob() {
+ super();
+ }
+
+ public TestBob(String elementName, long uid) {
+ super(elementName, uid);
+ }
+
+ public TestBob(BobjStdDTO dto) throws Exception {
+ super(dto);
+ TestCase.assertEquals(MY_BOB_PROP_VAL, dto.getAttr(MY_BOB_PROP));
+ }
+
+ public BobjStdDTO toDTO() throws Exception {
+ BobjStdDTO dto = super.toDTO();
+
+ dto.addAttr(MY_BOB_PROP, MY_BOB_PROP_VAL);
+
+ return dto;
+ }
+}
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/UtilUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/UtilUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/rosetta/tests/src/org/jboss/soa/esb/util/UtilUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,113 @@
+/*
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+/**
+ * Util unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class UtilUnitTest extends TestCase {
+
+ public void testDumpSysProps() throws IOException
+ {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+
+ Util.dumpSysProps(new PrintStream(buf));
+
+ Properties props = new Properties();
+ String env = buf.toString();
+ //escape backslashes to fix running under cygwin
+ env = env.replaceAll("\\\\", "\\\\\\\\");
+ props.load(new ByteArrayInputStream(env.getBytes()));
+
+ // Just make sure that something was dumped to the printstream
+ // by checking for a property we know will be in the System...
+ assertTrue(props.containsKey("file.separator"));
+ }
+
+ public void testIsNullString() {
+ assertTrue(Util.isNullString(null));
+ assertTrue(Util.isNullString(""));
+ assertTrue(Util.isNullString(" "));
+ assertTrue(!Util.isNullString("a"));
+ }
+
+ public void testIsLong() {
+ assertTrue(!Util.isLong(null));
+ assertTrue(!Util.isLong(""));
+ assertTrue(!Util.isLong(" "));
+ assertTrue(!Util.isLong("a"));
+ assertTrue(!Util.isLong(" 1"));
+ assertTrue(!Util.isLong("1 "));
+ assertTrue(!Util.isLong("1.1"));
+ assertTrue(Util.isLong("1"));
+ assertTrue(Util.isLong("-1"));
+ }
+
+ public void testIsPositiveLong() {
+ assertTrue(!Util.isPositiveLong(null));
+ assertTrue(!Util.isPositiveLong(""));
+ assertTrue(!Util.isPositiveLong(" "));
+ assertTrue(!Util.isPositiveLong("a"));
+ assertTrue(!Util.isPositiveLong(" 1"));
+ assertTrue(!Util.isPositiveLong("1 "));
+ assertTrue(!Util.isPositiveLong("1.1"));
+ assertTrue(Util.isPositiveLong("1"));
+ assertTrue(!Util.isPositiveLong("0"));
+ assertTrue(!Util.isPositiveLong("-1"));
+ }
+
+ public void testParseInt() {
+ assertEquals(0, Util.parseInt("a"));
+ assertEquals(0, Util.parseInt(""));
+ assertEquals(0, Util.parseInt(" "));
+ assertEquals(0, Util.parseInt(" 1"));
+ assertEquals(0, Util.parseInt("1 "));
+ assertEquals(0, Util.parseInt("0"));
+ assertEquals(1, Util.parseInt("1"));
+ assertEquals(-1, Util.parseInt("-1"));
+ }
+
+ public void testParseLong() {
+ assertEquals(0L, Util.parseLong("a"));
+ assertEquals(0L, Util.parseLong(""));
+ assertEquals(0L, Util.parseLong(" "));
+ assertEquals(0L, Util.parseLong(" 1"));
+ assertEquals(0L, Util.parseLong("1 "));
+ assertEquals(0L, Util.parseLong("0"));
+ assertEquals(1L, Util.parseLong("1"));
+ assertEquals(-1L, Util.parseLong("-1"));
+ }
+
+ public void testGetDefaultLogger() {
+ // Cheating here - just getting the coverage results up a little more :-)
+ Util.getDefaultLogger(Util.class);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/ant.bat
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/ant.bat 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/ant.bat 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,12 @@
+ at echo off
+set ANT_CMD_LINE_ARGS=%1
+if ""%1""=="""" goto doneStart
+shift
+:setupArgs
+if ""%1""=="""" goto doneStart
+set ANT_CMD_LINE_ARGS=%ANT_CMD_LINE_ARGS% %1
+shift
+goto setupArgs
+:doneStart
+%ANT_HOME%\bin\ant %ANT_CMD_LINE_ARGS%
+
Added: labs/jbossesb/workspace/b_georges/product/core/services/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/build.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/build.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<project name="JbossEsbServices" default="org.jboss.esb.services.compile" basedir=".">
+
+ <property name="org.jboss.esb.internal.dest" value="${basedir}/../../build"/>
+
+ <property name="org.jboss.esb.services.name.jar" value="${ant.project.name}.jar"/>
+ <property name="org.jboss.esb.services.dist.dir" value="${org.jboss.esb.internal.dest}/dist"/>
+ <property name="org.jboss.esb.services.appl.dir" value="../.."/>
+ <property name="org.jboss.esb.services.metainf.dir" value="src/META-INF"/>
+
+ <property name="org.jboss.esb.services.classes.dir" value="${org.jboss.esb.internal.dest}/classes/services"/>
+ <property name="org.jboss.esb.services.src.dir" value="${basedir}/src"/>
+ <property name="org.jboss.esb.root.dir" value="../.."/>
+ <property environment="env"/>
+
+ <property name="org.jboss.esb.ext.serverlib.dir" value="${org.jboss.esb.root.dir}/lib/ext"/>
+ <condition property="org.jboss.esb.ext.serverlib.dir" value="{org.jboss.esb.jboss.home}/server/all/lib">
+ <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
+ </condition>
+
+ <property name="org.jboss.esb.ext.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext"/>
+ <property name="org.jboss.esb.ejb3.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext/ejb3"/>
+ <condition property="org.jboss.esb.ext.lib.dir" value="${org.jboss.esb.jboss.home}/lib">
+ <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
+ </condition>
+
+ <!-- =================================================================== -->
+ <!-- Define the class path -->
+ <!-- =================================================================== -->
+ <path id="org.jboss.esb.services.base.classpath">
+ <fileset dir="${org.jboss.esb.ext.lib.dir}" includes="*.jar" excludes="jbossall-client.jar"/>
+ <fileset dir="${org.jboss.esb.ejb3.lib.dir}" includes="*.jar,*.zip"/>
+ </path>
+
+ <!-- =================================================================== -->
+ <!-- Initialize -->
+ <!-- =================================================================== -->
+ <target name="org.jboss.esb.services.init">
+ <tstamp>
+ <format property="TODAY" pattern="dd-MM-yy"/>
+ </tstamp>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Prepares the directory structure -->
+ <!-- =================================================================== -->
+ <target name="org.jboss.esb.services.prepare" depends="org.jboss.esb.services.init">
+ <mkdir dir="${org.jboss.esb.services.classes.dir}"/>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles all the classes -->
+ <!-- =================================================================== -->
+
+
+ <target name="org.jboss.esb.services.compile">
+ <!-- Compile services -->
+ <antcall target="org.jboss.esb.services.internal.compile"/>
+ <!-- Compile services tests -->
+ <ant inheritAll="true" dir="tests" target="org.jboss.esb.services.tests.compile"/>
+ </target>
+
+
+ <target name="org.jboss.esb.services.internal.compile" depends="org.jboss.esb.services.prepare"
+ description="Compile all classes">
+
+ <javac
+ destdir="${org.jboss.esb.services.classes.dir}"
+ classpathref="org.jboss.esb.services.default.classpath"
+ debug="${org.jboss.esb.debug}"
+ optimize="${org.jboss.esb.optimize}"
+ >
+ <src path="${org.jboss.esb.services.src.dir}"/>
+ </javac>
+
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Recompiles all the classes -->
+ <!-- =================================================================== -->
+
+ <target name="recompile" depends="clean,org.jboss.esb.services.compile"
+ description="Clean and compile"/>
+
+ <!-- =================================================================== -->
+ <!-- Clean -->
+ <!-- =================================================================== -->
+ <target name="clean" description="Remove classes directory">
+ <delete dir="${org.jboss.esb.services.classes.dir}"/>
+ </target>
+
+ <target name="purge" depends="clean">
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Rebuild everything from scratch -->
+ <!-- =================================================================== -->
+ <target name="all" depends="recompile,jar" />
+
+ <path id="org.jboss.esb.services.default.classpath">
+ <path refid="org.jboss.esb.services.base.classpath"/>
+ <pathelement location="${org.jboss.esb.internal.dest}/classes/rosetta"/>
+ <pathelement location="${org.jboss.esb.internal.dest}/classes/listeners"/>
+ </path>
+
+
+ <!-- =================================================================== -->
+ <!-- Jar -->
+ <!-- =================================================================== -->
+ <target name="jar" description="Assemble jar files"
+ depends="org.jboss.esb.services.compile"
+ >
+ <jar destfile="${org.jboss.esb.services.dist.dir}/lib/jbossesb-services.jar"
+ basedir="${org.jboss.esb.services.classes.dir}"
+ includes="**/*.class"
+ />
+
+ <antcall target="-ear"/>
+ </target>
+
+ <target name="-ear">
+ <ear destfile="${org.jboss.esb.services.dist.dir}/lib/jbossesb-appl.ear"
+ appxml="${org.jboss.esb.services.metainf.dir}/application.xml">
+ <fileset dir="${org.jboss.esb.services.dist.dir}"
+ includes="jbossesb-rosetta.jar
+ ,CQ3ServicesClient.jar
+ ,CQ3Services.jar
+ "/>
+ </ear>
+
+ </target>
+
+
+ <!-- =================================================================== -->
+ <!-- Test -->
+ <!-- =================================================================== -->
+ <target name="org.jboss.esb.services.test" description="Run tests for this module">
+ <!-- Compile tests -->
+ <ant dir="tests" target="org.jboss.esb.services.internal.test"/>
+ </target>
+
+</project>
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/application.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/application.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/application.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application version="1.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
+ <display-name>JbossEsb AppServer basic services</display-name>
+ <module>
+ <ejb>jbossesb-services.jar</ejb>
+ </module>
+ <module>
+ <java>jbossesb-listeners.jar</java>
+ </module>
+ <module>
+ <java>jbossesb-rosetta.jar</java>
+ </module>
+ <module>
+ <java>jbossts-common.jar</java>
+ </module>
+</application>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/manifest.server
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/manifest.server 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/META-INF/manifest.server 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: jbossesb-rosetta.jar jbossesb-services-client.jar
+
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/BobjStore.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/BobjStore.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/BobjStore.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,351 @@
+/*
+ * 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.internal.core.objectstore;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.beans.PersistHandler;
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+import org.xml.sax.SAXException;
+
+public class BobjStore {
+ protected static final String DATA_SOURCE_JNDI_NAME = "dataSourceJndiName";
+ protected static final String BATCH_TABLE = "batchTable";
+ protected static final String UID_TABLE = "uidTable";
+
+ protected static final String CLASS_TYPE_ATTR = "type";
+ protected static final String CLASS_TABLE_ATTR = "table";
+ protected static final String CLASS_ENCRYPT_ATTR = "encrypt";
+ protected static final String CLASS_NAME_ATTR = "name";
+ protected static final String CLASS_ELEMENT = "Class";
+
+ protected static final String INDEX_ELEMENT = "Index";
+ protected static final String INDEX_TABLE_ATTR = "table";
+
+ private static String DATASRC_JNDI_NAME;
+
+ public static void setDataSourceJndi(String p_s) {
+ DATASRC_JNDI_NAME = p_s;
+ }
+
+ public static String getDataSourceJndi() {
+ return DATASRC_JNDI_NAME;
+ }
+
+ private static String TBL_UIDS;
+
+ public static void setUidTableName(String p_s) {
+ TBL_UIDS = p_s;
+ }
+
+ public static String getUidTableName() {
+ return TBL_UIDS;
+ }
+
+ protected static void setStoreConfig(ConfigTree storeConfig) {
+ BobjStore.storeConfig = storeConfig;
+ }
+
+
+ private static String TBL_BATCHES;
+
+ private static ConfigTree storeConfig;
+
+ public static void setBatchTableName(String p_s) {
+ TBL_BATCHES = p_s;
+ }
+
+ public static String getBatchTableName() {
+ return TBL_BATCHES;
+ }
+
+ private static final Map<String, BobjStore> s_oStoreMap = new HashMap<String, BobjStore>();
+
+ static {
+ try {
+ configureStore();
+ } catch (Exception e) {
+ // REVIEW: Can we just carry on regardless here???
+ Util.getDefaultLogger(BobjStore.class).error(
+ "BobjStore configuration FAILED", e);
+ }
+ }
+
+ /**
+ * Configure/Reconfigure the BobjStore.
+ * <p/>
+ * The configuration is set either through a prior call to {@link #setStoreConfig(ConfigTree)}, or
+ * through a URI resource lookup configured by the "org.jboss.soa.esb.objStore.configfile" System property.
+ * @throws SAXException
+ * @throws IOException
+ * @throws MalformedURLException
+ */
+ protected static void configureStore() throws MalformedURLException, IOException, SAXException {
+ // storeConfig can be set for testing purposes - if already set, don't try reading from the configured URI.
+ if(storeConfig == null) {
+ storeConfig = readConfiguration();
+ }
+
+ if(storeConfig != null) {
+ setDataSourceJndi(storeConfig.getAttribute(DATA_SOURCE_JNDI_NAME));
+ setUidTableName(storeConfig.getAttribute(UID_TABLE));
+ setBatchTableName(storeConfig.getAttribute(BATCH_TABLE));
+
+ for (ConfigTree oCurr : storeConfig.getChildren(CLASS_ELEMENT)) {
+ String sClass = oCurr.getAttribute(CLASS_NAME_ATTR);
+ boolean bCrypt = "true".equalsIgnoreCase(oCurr
+ .getAttribute(CLASS_ENCRYPT_ATTR));
+
+ BobjStore oNew = new BobjStore(oCurr.getAttribute(CLASS_TYPE_ATTR),
+ oCurr.getAttribute(CLASS_TABLE_ATTR), null,
+ sClass.substring(1 + sClass.lastIndexOf(".")), bCrypt);
+
+ for (ConfigTree oIcurr : oCurr.getChildren(INDEX_ELEMENT)) {
+ oNew.addLocatorTable(oIcurr.getAttribute(INDEX_TABLE_ATTR));
+ }
+ s_oStoreMap.put(sClass, oNew);
+ }
+ }
+ }
+
+ /**
+ * Read the configuration.
+ * <p/>
+ * Tries reading it from the classpath. If that fails, tries reading it through a URI stream.
+ */
+ protected static ConfigTree readConfiguration() throws IOException, MalformedURLException, SAXException {
+ String configPath = Configuration.getObjStoreConfigFile();
+ URI configURI;
+ InputStream configStream = null;
+
+ if(configPath == null) {
+ throw new IllegalStateException("ObjStoreConfigFile location not configured (param name: " + Environment.OBJECT_STORE_CONFIG_FILE + ").");
+ }
+
+ configURI = URI.create(configPath);
+ if(!configURI.isAbsolute() || configURI.getPath() == null) {
+ throw new IllegalStateException("ObjStoreConfigFile location configuration error (" + Environment.OBJECT_STORE_CONFIG_FILE + "=" + configPath + "). Must be an absolute URI e.g. http://, file:/, classpath:/ etc.");
+ }
+
+ // Is it on the classpath...
+ if(configURI.getScheme().equals("classpath")) {
+ configStream = BobjStore.class.getResourceAsStream(configURI.getPath());
+ } else {
+ // OK, so can we load it through the URI stream...
+ try {
+ configStream = configURI.toURL().openStream();
+ } catch(IOException e) {
+ throw new IllegalStateException("Unable to locate and read ObjStoreConfigFile: " + configPath, e);
+ }
+ }
+
+ if(configStream == null) {
+ throw new IllegalStateException("Unable to locate and read ObjStoreConfigFile: " + configPath);
+ }
+
+ return ConfigTree.fromInputStream(configStream);
+ }
+
+ private String m_sSnapType, m_sSnapTbl, m_sClass;
+
+ private List<String> m_olLocators;
+
+ private boolean m_bEncrypt = false;
+
+ /**
+ * Snapshot type getter - The value assigned to this attribute will help if
+ * standard SQL queries are required to surf the Object Store's snapshot
+ * tables
+ *
+ * @return String - Value of snapshot type
+ * @see Istorable#getSnapType()
+ */
+ public String getSnapType() {
+ return m_sSnapType;
+ }
+
+ /**
+ * Snapshot tablename getter - The value assigned to this attribute is the
+ * name of the snapshot table for this object
+ *
+ * @return String - name of SQL table where snapshots of objects will be
+ * stored
+ * @see Istorable#getSnapTable()
+ */
+ public String getSnapTable() {
+ return m_sSnapTbl;
+ }
+
+ /**
+ * First locator tablename getter - Locator tables are also called index
+ * tables.
+ *
+ * @return String - name of SQL table where locators(0) will be stored
+ * @see Istorable#getLocatorTable()
+ * @see BusinessObject#getObjLocator()
+ */
+ public String getLocatorTable() {
+ return getLocatorTable(0);
+ }
+
+ /**
+ * Obtain Nth locator table
+ *
+ * @param p_n -
+ * Index for desired locator table
+ * @return String - name of Nth SQL table where for objects will be stored
+ * @see BaseBusinessObject#locator(p_i)
+ */
+ public String getLocatorTable(int p_n) {
+ return (null == m_olLocators) ? null
+ : (m_olLocators.size() <= p_n) ? null : m_olLocators.get(p_n);
+ }
+
+ /**
+ * Obtain all locator table names
+ *
+ * @return Names of all locator tables
+ */
+ public String[] allLocatorTables() {
+ return (null == m_olLocators) ? new String[] {} : m_olLocators
+ .toArray(new String[m_olLocators.size()]);
+ }
+
+ /**
+ * Class suffix getter - Deprecated - Left here for backwards compatibility
+ *
+ * @return String - Class suffix
+ * @see Istorable#getLocatorTable()
+ * @see BusinessObject#getObjLocator()
+ */
+ public String getClassSuffix() {
+ return m_sClass;
+ }
+
+ /**
+ * Encryption requirement getter
+ *
+ * @return boolean - true if Objects stored using this descriptor have to be
+ * encrypted - decrypted at storage/retrieval time
+ */
+ public boolean isEncrypted() {
+ return m_bEncrypt;
+ }
+
+ /**
+ * Constructor using all fields required by a BobjStore object
+ *
+ * @param p_sSnapType
+ * String - Snapshot type
+ * @param p_sSnapTbl
+ * String - Snapshot SQL tablename
+ * @param p_sLocTbl
+ * String - Locator SQL tablename (may be null - No locator
+ * table)
+ * @param p_sCls
+ * String - Class name excluding package prefix
+ * @param p_bCrypt
+ * boolean - Does data have to be encrypted in the snap table ?
+ * @see Istorable
+ * @see BusinessObject#classNm()
+ */
+ protected BobjStore(String p_sSnapType, String p_sSnapTbl,
+ String p_sLocTbl, String p_sCls, boolean p_bCrypt) {
+ m_sSnapType = p_sSnapType;
+ m_sSnapTbl = p_sSnapTbl;
+ addLocatorTable(p_sLocTbl);
+ m_sClass = p_sCls;
+ m_bEncrypt = p_bCrypt;
+ } // ________________________________
+
+ private void addLocatorTable(String p_s) {
+ if (Util.isNullString(p_s))
+ return;
+ if (null == m_olLocators)
+ m_olLocators = new ArrayList<String>();
+ m_olLocators.add(p_s);
+ } // ________________________________
+
+ /**
+ * Constructor for non encrypted BobjStore
+ *
+ * @param p_sSnapType
+ * String
+ * @param p_sSnapTbl
+ * String
+ * @param p_sLocTbl
+ * String
+ * @param p_sCls
+ * String
+ * @see BobjStore#BobjStore(String,String,String,String,boolean)
+ */
+ protected BobjStore(String p_sSnapType, String p_sSnapTbl,
+ String p_sLocTbl, String p_sCls) {
+ this(p_sSnapType, p_sSnapTbl, p_sLocTbl, p_sCls, false);
+ } // ________________________________
+
+ /**
+ * Get a BobjStore object that describes persistence details for objects of
+ * class <arg 1>
+ *
+ * @param p_sClassName
+ * Class to search for in descriptor table
+ * @return BobjStore - A descriptor that will provide persistence info
+ * @see PersistHandler
+ * @see BobjStore#getStore(BusinessObject)
+ */
+ public static BobjStore getStore(String p_sClassName) {
+ if (Util.isNullString(p_sClassName))
+ return null;
+ return s_oStoreMap.get(p_sClassName);
+ } // __________________________________
+
+ /**
+ * Get a BobjStore object that describes persistence details for BobjStdDTO
+ * <arg 1>
+ *
+ * @param p_sClassName
+ * BobjStdDTO for which we need an object store
+ * @return BobjStore - A descriptor that will provide persistence info
+ * @see PersistHandler
+ * @see BobjStore#getStore(String)
+ */
+ public static BobjStore getStore(BobjStdDTO p_oDto) {
+ if (null == p_oDto)
+ return null;
+ return getStore(p_oDto.fullClassName());
+ } // __________________________________
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoBatchTable.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoBatchTable.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoBatchTable.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,223 @@
+/*
+* 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.internal.core.objectstore;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.helpers.persist.SqlDbTable;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * Data access object for the SQL table where batches are temporarily stored
+ * until they are committed
+ *
+ */
+public class DaoBatchTable extends SqlDbTable
+{
+ private Logger m_oLog;
+ private JdbcCleanConn m_oConn;
+
+ private DaoBatchTable() throws Exception {this(null,null); }
+ /**
+ * Instantiate a DaoBatchTable object using the javax.sql.DataSource object
+ * within <arg 1>, with table name held in <arg 2>
+ * @param p_oConn JdbcCleanConn - Connection to use for preparing and executing
+ * all SQL statements in this DAO
+ * @param p_sTblName String - SQL table name to use in the context of this
+ * DaoBatchTable object
+ * @throws Exception - pass through from invoked methods - see Exception.getMessage()
+ * at runtime for details
+ * @see JdbcCleanConn
+ */
+ public DaoBatchTable(JdbcCleanConn p_oConn,String p_sTblName) throws Exception
+ { super(p_oConn,p_sTblName);
+ m_oLog = Util.getDefaultLogger(this.getClass());
+ m_oConn = p_oConn;
+ m_oaPS = new PreparedStatement[PS_MAX];
+ } //________________________________
+ /**
+ * List of fields for select statement - provided only to avoid time
+ * consuming 'select *' statements
+ * @return String - a Comma separated list of fields
+ */
+ protected String getSelectFields()
+ { return "batch_num,seq,data";
+ } //________________________________
+
+ // -------------------------------------------------------------
+ // Column constants
+ // -------------------------------------------------------------
+ private static int s_iFld = 0;
+ /**
+ * Column index for field representing batch number
+ */
+ public static final int BATCH_NUM = s_iFld++;
+ /**
+ * Column index for field representing sequence number within batch number
+ */
+ public static final int BATCH_SEQ = s_iFld++;
+ /**
+ * XML string that will be used to instantiate the BusinessObject
+ * @see BusinessObject#BusinessObject(BobjStdDTO)
+ * @see BobjStdDTO#getFromXml(String)
+ */
+ public static final int STR_DATA = s_iFld++;
+
+ private static final int QFIELDS = s_iFld;
+
+ /**
+ * Set values for insert statement
+ * @param p_PS PreparedStatement - The prepared SQL statement for insert in this
+ * table
+ * <p>Must be the result of a previous call to this.getPS(PS_INS_BATCHROW)</p>
+ * @param p_o Object - Object to get values from
+ * <p>arg 2 is Object to comply with SqlDbTable abstract method setInsValues()
+ * <li>For this particular class, arg 2 MUST be an instance of RowBatch</li>
+ * </p>
+ * @throws Exception
+ * @return int
+ * @see DaoBatchTable#getPS(int)
+ * @see RowBatch
+ */
+ public int setInsValues(PreparedStatement p_PS,Object p_o)
+ throws Exception
+ { try
+ { if (! (p_o instanceof RowBatch)) throw
+ new Exception ("Parameter must be RowBatch");
+
+ p_PS.clearParameters();
+ RowBatch oBR = (RowBatch)p_o;
+ setLong (p_PS, BATCH_NUM ,oBR.m_lBatch); // Batch Number
+ setInt (p_PS, BATCH_SEQ ,oBR.m_iSeq); // Batch Sequence
+ setObject (p_PS ,STR_DATA ,oBR.m_sData); // Batch Data
+
+ return QFIELDS;
+ }
+ catch (Exception e)
+ { m_oLog.error("setInsValues() Failed",e);
+ throw e;
+ }
+ } //________________________________
+ /**
+ * Returns a RowBatch object containing data from the row in the current
+ * cursor position of the ResultSet object <arg 1>
+ * @param p_oRS ResultSet - The current ResultSet
+ * <p>Must be the result of a previous execution of
+ * JdbcCleanConn.execQueryWait() method on a 'select' prepared statement for
+ * this object</p>
+ * @throws Exception
+ * @return Object - A RowBatch object
+ * @see JdbcCleanConn#execQueryWait(PreparedStatement, int)
+ * @see DaoBatchTable#getPS(int)
+ * @see DaoBatchTable#PS_GET_BATCH_ROWS
+ * @see RowBatch
+ */
+ public Object getFromRS (ResultSet p_oRS) throws Exception
+ { try
+ { RowBatch oRet = new RowBatch();
+ oRet.m_lBatch = p_oRS.getLong(1+BATCH_NUM);
+ oRet.m_iSeq = p_oRS.getInt (1+BATCH_SEQ);
+ oRet.m_sData = p_oRS.getString(1+STR_DATA);
+ return oRet;
+ }
+ catch (Exception e)
+ { m_oLog.error("getFromRS() Failed",e);
+ throw e;
+ }
+ } //________________________________
+ /**
+ * Index of the 'insert' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_INS_BATCHROW = 0;
+ /**
+ * Index of the 'delete' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_DELETE_BATCH = 1;
+ /**
+ * Index of the 'select' statement in the list of PreparedStatement objects
+ * for this DAO (it has a where batch_num = ?)
+ */
+ public static final int PS_GET_BATCH_ROWS = 2;
+
+ private static final int PS_MAX = 10;
+
+ /**
+ * Obtain a prepared statement for this DAO from the list of available PStmts
+ * <p>Uses lazy instantiation of requested objects</p>
+ * @param p_i int - Index of PreparedStatement object to obtain
+ * @throws Exception - If an invalid index is passed or there are problems
+ * during the prepareStatement() invocation
+ * @return PreparedStatement
+ */
+ public PreparedStatement getPS (int p_i) throws Exception
+ { try
+ { switch (p_i)
+ { case PS_INS_BATCHROW: return getInsBatchRow (p_i);
+ case PS_DELETE_BATCH: return deleteBatch (p_i);
+ case PS_GET_BATCH_ROWS: return getBatchRows (p_i);
+ }
+ ;
+ throw new Exception("Invalid Index "+p_i);
+ }
+ catch (Exception e)
+ { m_oLog.error("Request for Prepared Statement Failed",e);
+ throw e;
+ }
+ } //__________________________________
+
+ private PreparedStatement getInsBatchRow(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ m_oaPS[p_i] = m_oConn.prepareStatement(getInsertStatement());
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement deleteBatch(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ { StringBuffer sb = new StringBuffer("delete from ").append(m_sTableName)
+ .append(" where ")
+ .append(m_oaFields[BATCH_NUM].getFieldName()).append(" = ?")
+ ;
+ m_oaPS[p_i] = m_oConn.prepareStatement(sb.toString());
+ }
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement getBatchRows(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ { StringBuffer sb = new StringBuffer(getSelectStatement())
+ .append(" where ")
+ .append(m_oaFields[BATCH_NUM].getFieldName()).append(" = ?")
+ .append(" order by 1,2")
+ ;
+ m_oaPS[p_i] = m_oConn.prepareStatement(sb.toString());
+ }
+ return m_oaPS[p_i];
+ } //__________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoIndexTable.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoIndexTable.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoIndexTable.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,317 @@
+/*
+* 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.internal.core.objectstore;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.helpers.persist.SqlDbTable;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.ObjLocator;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * Data access object for all SQL tables that the ROS (Rosetta Object Store)
+ * uses as locator tables
+ * <p>Number of actual columns in all of these tables equals 4 + the
+ * length of the String[] returned by the BusinessObject locator() method</p>
+ * <p>It is responsibility of rosetta core developers to ensure
+ * synchronization between these two, as well as to add a corresponding
+ * entry in the BobjStore static descriptor table</p>
+ *
+ * @see BobjStore
+ * @see BusinessObject#locator()
+ */
+public class DaoIndexTable extends SqlDbTable
+{
+
+ public static final String LOCATOR_TABLE_INDEX = "__whichLocator";
+
+ private Logger m_oLog;
+ private JdbcCleanConn m_oConn;
+
+ private DaoIndexTable() throws Exception {this(null,null); }
+ /**
+ * Instantiate a DaoIndexTable object using the javax.sql.DataSource object
+ * within <arg 1>, with table name held in <arg 2>
+ * @param p_oConn JdbcCleanConn - Connection to use for preparing and executing
+ * all SQL statements in this DAO
+ * @param p_sTblName String - SQL table name to use in the context of this
+ * DaoIndexTable object
+ * @throws Exception - pass through from invoked methods - see Exception.getMessage()
+ * at runtime for details
+ * @see JdbcCleanConn
+ */
+ public DaoIndexTable(JdbcCleanConn p_oConn,String p_sTbl) throws Exception
+ { super(p_oConn,p_sTbl);
+ m_oLog = Util.getDefaultLogger(this.getClass());
+ m_oConn = p_oConn;
+ if (null != m_oaFields)
+ { m_oaFields[OBJECT_UID].setPrimaryKey(true);
+ m_sSelectSql = null;
+ }
+ m_oaPS = new PreparedStatement[PS_MAX];
+ } //________________________________
+
+ /**
+ * List of fields for select statement - provided only to avoid time
+ * consuming 'select *' statements
+ * @return String - a Comma separated list of fields
+ */
+ protected String getSelectFields()
+ { if (null==m_oaFields) return "*";
+ StringBuffer sb = new StringBuffer(256);
+ for (int i1=0; i1<m_oaFields.length;i1++)
+ ((i1 < 1)?sb:sb.append(","))
+ .append(m_oaFields[i1].getFieldName());
+ return sb.toString();
+ } //________________________________
+
+ // -------------------------------------------------------------
+ // Column constants
+ // -------------------------------------------------------------
+ private static int s_iFld = 0;
+ /**
+ * Column index for the BusinessObject UID represented in the corresponding
+ * SQL table row
+ */
+ public static final int OBJECT_UID = s_iFld++;
+ /**
+ * Column index for the latest Object snapshot taken for the BusinessObject
+ */
+ public static final int TIMESTAMP = s_iFld++;
+ /**
+ * Column index for the latest snapshot's UID for the BusinessObject the row
+ * represents
+ */
+ public static final int UID_SNAP = s_iFld++;
+ /**
+ * Column index for the latest Object snapshot's date (yyyymmdd)
+ */
+ public static final int SNAP_DATE = s_iFld++;
+ /**
+ * Column index for the first field in the String array returned by the
+ * BusinessObject's locator() method - Subsequent fields in the array will
+ * have consecutive sequential indices
+ * @see BusinessObject#locator()
+ */
+ public static final int FIRST_FIELD = s_iFld++;
+
+ public int setInsValues(PreparedStatement p_PS,Object p_o)
+ throws Exception
+ { return setInsValues (p_PS,p_o,0); }
+ /**
+ * Set values for insert statement
+ * @param p_PS PreparedStatement - The prepared SQL statement for insert in this
+ * table
+ * <p>Must be the result of a previous call to this.getPS(PS_INS_INDEX)</p>
+ * @param p_o Object - Object to get values from
+ * <p>arg 2 is Object to comply with SqlDbTable abstract method setInsValues()
+ * <li>For this particular class, arg 2 MUST be an instance of BobjStdDTO</li>
+ * </p>
+ * @param p_iNum int - Index of which locator String[] should be used
+ * @throws Exception
+ * @return int
+ * @see DaoIndexTable#getPS(int)
+ * @see DaoIndexTable#PS_INS_INDEX
+ */
+ public int setInsValues(PreparedStatement p_PS,Object p_o, int p_iNum)
+ throws Exception
+ { try
+ { if (! (p_o instanceof BobjStdDTO)) throw
+ new Exception ("Parameter must be BobjStdDTO");
+
+ BobjStdDTO oDto = (BobjStdDTO)p_o;
+
+ p_PS.clearParameters();
+ setLong (p_PS, OBJECT_UID ,oDto.getUid()); // Object's UID
+ long lStamp = oDto.getStamp();
+ setLong (p_PS, TIMESTAMP ,lStamp); // Timestamp
+ setLong (p_PS, UID_SNAP ,oDto.getSnap()); // Snap UID
+ setObject(p_PS, SNAP_DATE ,oDto.getSnapDate()); // Snap Date
+
+ int iFld = FIRST_FIELD;
+ String[] sa = oDto.getLocators()[p_iNum];
+ for (int i1=0; i1<sa.length;i1++)
+ if (iFld < m_oaFields.length) setObject(p_PS,iFld++,sa[i1]);
+
+ return iFld;
+ }
+ catch (Exception e)
+ { m_oLog.error("setInsValues() Failed",e);
+ throw e;
+ }
+ } //________________________________
+
+ public void setUpdValues(PreparedStatement p_PS,Object p_o)
+ throws Exception
+ { setUpdValues(p_PS,p_o,0); }
+
+ /**
+ * Set values for update statement
+ * @param p_PS PreparedStatement - The prepared SQL statement for update in this
+ * table
+ * <p>Must be the result of a previous call to this.getPS(PS_UPD_INDEX)</p>
+ * @param p_o Object - Object to get values from
+ * <li>For this particular class, arg 2 MUST be an instance of BaseBusinessObject</li>
+ * </p>
+ * @param p_iNum int - Index of which locator String[] should be used
+ * @throws Exception
+ * @see DaoIndexTable#getPS(int)
+ * @see DaoIndexTable#PS_UPD_INDEX
+ */
+ public void setUpdValues(PreparedStatement p_PS,Object p_o, int p_iNum)
+ throws Exception
+ { try
+ { if (! (p_o instanceof BobjStdDTO)) throw
+ new Exception ("Parameter must be BobjStdDTO");
+
+ BobjStdDTO oDto = (BobjStdDTO)p_o;
+
+ int iFld = 0;
+ p_PS.clearParameters();
+ setLong (p_PS, iFld++ ,oDto.getStamp()); // Timestamp
+ setLong (p_PS, iFld++ ,oDto.getSnap()); // Snap UID
+ setObject(p_PS, iFld++ ,oDto.getSnapDate());
+
+ String[] sa = oDto.getLocators()[p_iNum];
+ for (int i1=0; i1<sa.length;i1++)
+ if (iFld < m_oaFields.length) setObject(p_PS,iFld++,sa[i1]);
+
+ setLong(p_PS, iFld++, oDto.getUid());
+ }
+ catch (Exception e)
+ { m_oLog.error("setUpdValues() Failed",e);
+ throw e;
+ }
+ } //________________________________
+
+ /**
+ * Returns an ObjLocator object containing data from the row in the current
+ * cursor position of the ResultSet object <arg 1>
+ * @param p_oRS ResultSet - The current ResultSet
+ * <p>Must be the result of a previous execution of
+ * JdbcCleanConn.execQueryWait() method on a 'select' prepared statement for
+ * this object</p>
+ * @throws Exception
+ * @return Object - An ObjLocator object
+ * @see JdbcCleanConn#execQueryWait(PreparedStatement, int)
+ * @see DaoIndexTable#getPS(int)
+ * @see DaoIndexTable#PS_SEL_INDEX
+ * @see ObjLocator
+ */
+ public Object getFromRS (ResultSet p_oRS) throws Exception
+ { try
+ {
+ long lUid = p_oRS.getLong(1+OBJECT_UID);
+ String[] sa = new String[m_oaFields.length-FIRST_FIELD];
+ int iFld = FIRST_FIELD;
+ for (int i1=0; i1<sa.length;i1++) sa[i1] = p_oRS.getString(++iFld);
+
+ return new ObjLocator(lUid,sa);
+ }
+ catch (Exception e)
+ { m_oLog.error("getFromRS() Failed",e);
+ throw e;
+ }
+ } //________________________________
+
+
+ /**
+ * Index of the 'insert' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_INS_INDEX = 0;
+ /**
+ * Index of the 'select' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_SEL_INDEX = 1;
+ /**
+ * Index of the 'delete' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_RMV_INDEX = 2;
+ /**
+ * Index of the 'update' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_UPD_INDEX = 3;
+
+ private static final int PS_MAX = 10;
+
+ /**
+ * Obtain a prepared statement for this DAO from the list of available PStmts
+ * <p>Uses lazy instantiation of requested objects</p>
+ * @param p_i int - Index of PreparedStatement object to obtain
+ * @throws Exception - If an invalid index is passed or there are problems
+ * during the prepareStatement() invocation
+ * @return PreparedStatement
+ */
+ public PreparedStatement getPS (int p_i) throws Exception
+ { try
+ { switch (p_i)
+ { case PS_INS_INDEX: return getInsIndex(p_i);
+ case PS_SEL_INDEX: return getSelIndex(p_i);
+ case PS_RMV_INDEX: return getRmvIndex(p_i);
+ case PS_UPD_INDEX: return getUpdIndex(p_i);
+ }
+ ;
+ throw new Exception("Invalid Index "+p_i);
+ }
+ catch (Exception e)
+ { m_oLog.error("Request for Prepared Statement Failed",e);
+ throw e;
+ }
+ } //__________________________________
+
+ private PreparedStatement getInsIndex(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ m_oaPS[p_i] = m_oConn.prepareStatement(getInsertStatement());
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement getSelIndex(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ { StringBuffer sb = new StringBuffer(getSelectStatement())
+ .append(" where ").append(getFldName(OBJECT_UID)).append(" = ? ");
+ m_oaPS[p_i] = m_oConn.prepareStatement(sb.toString());
+ }
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement getRmvIndex(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ m_oaPS[p_i] = m_oConn.prepareStatement(getDeleteStatement());
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement getUpdIndex(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ m_oaPS[p_i] = m_oConn.prepareStatement(getUpdateStatement());
+ return m_oaPS[p_i];
+ } //__________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoSnapTable.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoSnapTable.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoSnapTable.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,401 @@
+/*
+* 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.internal.core.objectstore;
+
+import java.lang.reflect.Method;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.helpers.persist.SqlDbTable;
+import org.jboss.soa.esb.services.DefaultEncryptionFactory;
+import org.jboss.soa.esb.services.Encryption;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+
+
+/**
+ * Data access object for all SQL tables that the ROS (Rosetta Object Store)
+ * uses as snapshot tables
+ *
+ * @see BobjStore
+ */
+public class DaoSnapTable extends SqlDbTable
+{
+ private Logger m_oLogger;
+ private JdbcCleanConn m_oConn;
+ private BobjStore m_oST;
+
+ private DaoSnapTable() throws Exception {this(null,null); }
+ /**
+ * Instantiate a DaoSnapTable object using the javax.sql.DataSource object
+ * within <arg 1>, with table name held in <arg 2>
+ * @param p_oConn JdbcCleanConn - Connection to use for preparing and executing
+ * all SQL statements in this DAO
+ * @param p_oST BobjStore - Descriptor that holds information of what physical
+ * SQL tables to use both for the snapshot and the locator tables for
+ * BusinessObjects sent to this DAO
+ * @throws Exception - pass through from invoked methods - see Exception.getMessage()
+ * at runtime for details
+ * @see JdbcCleanConn
+ * @see BobjStore
+ * @see Istorable
+ */
+ public DaoSnapTable(JdbcCleanConn p_oConn,BobjStore p_oST) throws Exception
+ { super(p_oConn,p_oST.getSnapTable());
+ m_oLogger = Util.getDefaultLogger(this.getClass());
+ m_oConn = p_oConn;
+ m_oST = p_oST;
+ if (null != m_oaFields)m_oaFields[UID_SNAP].setPrimaryKey(true);
+ m_oaPS = new PreparedStatement[PS_MAX];
+ } //________________________________
+
+ /**
+ * List of fields for select statement - provided only to avoid time
+ * consuming 'select *' statements
+ * @return String - a Comma separated list of fields
+ */
+ protected String getSelectFields()
+ { return "uid,stamp,snap_type,object_uid,batch_num,xml_data";
+ } //________________________________
+
+ // -------------------------------------------------------------
+ // Column constants
+ // -------------------------------------------------------------
+ private static int s_iFld = 0;
+ /**
+ * Column index for the SQL table field representing snapshot's unique identifier
+ * <p>This would be the 'natural' primary key for all snapshot tables, and the
+ * number should only be assigned by the PersistHandler EJB at insert time</p>
+ * <p>There could potentially be several snapshots for the same
+ * BusinessObject - In that case, there would be several rows in the
+ * snapshot table with the same OBJECT_UID value and different UID_SNAP
+ * values
+ * </p>
+ * @see DaoSnapTable#OBJECT_UID
+ */
+ public static final int UID_SNAP = s_iFld++;
+ /**
+ * Column index for the SQL table field representing this snapshot's timestamp, expressed
+ * in milliseconds since the start of the 'epoch'
+ * @see java.util.Date
+ */
+ public static final int TIMESTAMP = s_iFld++;
+ /**
+ * Column index for the SQL table field representing this snapshot's
+ * underlying BusinessObject type - This is a Rosetta Core design level decision
+ * <p>Having this field as an SQL column will enable SQL 'visibility' and thus
+ * can be used in the 'where' clause of any SQL statement</p>
+ * <p>An example of when this field could potentially be used is if a
+ * decision is made by Rosetta Administrators to move all objects of a specific
+ * type to a different SQL snapshot table</p>
+ */
+ public static final int SNAP_TYPE = s_iFld++;
+ /**
+ * Column index for the SQL table field representing BusinessObject unique identifier
+ * <p>There could potentially be several snapshots for the same
+ * BusinessObject - In that case, there would be several rows in the
+ * snapshot table with the same OBJECT_UID value and different UID_SNAP
+ * values
+ * </p>
+ * @see DaoSnapTable#OBJECT_UID
+ */
+ public static final int OBJECT_UID = s_iFld++;
+ /**
+ * Column index for the SQL table field representing the batch number
+ * as a result of which this snapshot was added to the store
+ * <p>If this snapshot was not added as part of a batch process (meaning a
+ * group of BusinessObjects added using the BatchHandler EJB), then it
+ * will hold a null value</p>
+ */
+ public static final int BATCH_NUM = s_iFld++;
+ /**
+ * Column index for the SQL table field representing the XML representation
+ * of the BusinessObject stored in this SQL table
+ * <p>The contents of this field are going to be the result of invoking
+ * the BusinessObject.toDTO().toXml() method</p>
+ * @see BusinessObject#toDTO()
+ * @see BobjStdDTO#toXml()
+ * @see DaoSnapTable#setInsValues(PreparedStatement,Object)
+ */
+ public static final int XML_OBJECT = s_iFld++;
+
+ private static final int QFIELDS = s_iFld++;
+
+ /**
+ * Set values for insert statement
+ * @param p_PS PreparedStatement - The prepared SQL statement for insert in this
+ * table
+ * <p>Must be the result of a previous call to this.getPS(PS_INS_SNAP)</p>
+ * @param p_o Object - Object to get values from
+ * <p>arg 2 is Object to comply with SqlDbTable abstract method setInsValues()
+ * <li>For this particular class, arg 2 MUST be an instance of BusinessObject</li>
+ * </p>
+ * @throws Exception
+ * @return int
+ * @see DaoSnapTable#getPS(int)
+ * @see DaoSnapTable#PS_INS_SNAP
+ * @see BusinessObject
+ */
+ public int setInsValues(PreparedStatement p_PS,Object p_o)
+ throws Exception
+ { try
+ { if (! (p_o instanceof BobjStdDTO)) throw
+ new Exception ("Parameter must be BobjStdDTO");
+
+ BobjStdDTO oDto = (BobjStdDTO)p_o;
+ long lSnapUid = oDto.getSnap();
+
+ p_PS.clearParameters();
+ setLong (p_PS, UID_SNAP ,lSnapUid);
+ setLong (p_PS, TIMESTAMP ,oDto.getStamp()); // Timestamp
+ setObject(p_PS, SNAP_TYPE ,m_oST.getSnapType()); // Snap Type
+ setLong (p_PS, OBJECT_UID ,oDto.getUid()); // Object's UID
+ setLong (p_PS, BATCH_NUM ,oDto.getBatch()); // Batch Number
+ byte[] baXml = oDto.toXml().getBytes();
+ p_PS.setBytes(1+XML_OBJECT,seeCrypt(baXml,lSnapUid));
+
+ return QFIELDS;
+ }
+ catch (Exception e)
+ { m_oLogger.error("setInsValues() Failed",e);
+ throw e;
+ }
+ } //________________________________
+
+ /**
+ * Set values for update statement
+ * @param p_PS PreparedStatement - The prepared SQL statement for updates in this
+ * table
+ * <p>Must be the result of a previous call to this.getPS(PS_UPD_SNAP)</p>
+ * @param p_o Object - Object to get values from
+ * <li>For this particular class, arg 2 MUST be an instance of BobjStdDTO</li>
+ * </p>
+ * @throws Exception
+ * @see DaoSnapTable#getPS(int)
+ * @see DaoSnapTable#PS_UPD_SNAP
+ * @see BobjStdDTO
+ */
+ public void setUpdValues(PreparedStatement p_PS,Object p_o)
+ throws Exception
+ { try
+ { if (! (p_o instanceof BobjStdDTO)) throw
+ new Exception ("Parameter must be BobjStdDTO");
+
+ BobjStdDTO oDto = (BobjStdDTO)p_o;
+ long lSnapUid = oDto.getSnap();
+
+ p_PS.clearParameters();
+
+ int iFld = 0;
+ setLong (p_PS, iFld++ ,oDto.getStamp()); // Timestamp
+ setObject(p_PS, iFld++ ,m_oST.getSnapType()); // Snap Type
+ setLong (p_PS, iFld++ ,oDto.getUid()); // Object's UID
+ setLong (p_PS, iFld++ ,oDto.getBatch()); // Batch Number
+ byte[] baXml = oDto.toXml().getBytes();
+ p_PS.setBytes(1+iFld++ ,seeCrypt(baXml,lSnapUid));
+ setLong (p_PS, iFld++ ,lSnapUid);
+ }
+ catch (Exception e)
+ { m_oLogger.error("setInsValues() Failed",e);
+ throw e;
+ }
+ } //________________________________
+
+ private Encryption m_oMangler;
+ private static final Object s_oSync = new Integer(0);
+ private Encryption getMangler() throws Exception
+ { return getMangler(null); }
+ private Encryption getMangler(Object p_oFactParms) throws Exception
+ { if (null!=m_oMangler)
+ return m_oMangler;
+ synchronized(s_oSync)
+ { if (null!=m_oMangler)
+ return m_oMangler;
+
+ String sFactoryName = Configuration.getEncryptionFactoryClass();
+ Class oFactClass = DefaultEncryptionFactory.class;
+ if (null!=sFactoryName)
+ oFactClass = Class.forName(sFactoryName);
+ Method oMth = oFactClass.getMethod("getEncrypter"
+ ,new Class[] {Object.class});
+ m_oMangler = (Encryption) oMth.invoke(null,p_oFactParms);
+ }
+
+ return m_oMangler;
+ } //________________________________
+
+ /**
+ * Encrypt if you have to or just return your first argument
+ * <p />
+ * You'll probably override this method if you have your own Iencryption implementation
+ * @param p_ba the byte array to be encrypted (if the store so indicates)
+ * @param p_l an object for the encrypt method of the Iencryption object
+ * @return the value to be stored in the column
+ * @throws Exception
+ */
+
+ protected byte[] seeCrypt(byte[] p_ba,Object p_l) throws Exception
+ { if (! m_oST.isEncrypted()) return p_ba;
+ return getMangler().encrypt(p_ba,p_l);
+ } //________________________________
+
+ /**
+ * Decrypt if you have to or just return your first argument
+ * <p />
+ * You'll probably override this method if you have your own Iencryption implementation
+ * @param p_ba the byte array to be decrypted (if the store so indicates)
+ * @param p_l an object for the decrypt method of the Iencryption object
+ * @return the value to be used to construct the XML string
+ * @throws Exception
+ */
+ protected byte[] seeDecrypt(byte[] p_ba,Object p_l) throws Exception
+ { if (! m_oST.isEncrypted()) return p_ba;
+ return getMangler().decrypt(p_ba,p_l);
+ } //________________________________
+
+ /**
+ * Returns a BobjStdDTO containing data from the row in the current
+ * cursor position of the ResultSet object <arg 1>
+ * @param p_oRS ResultSet - The current ResultSet
+ * <p>Must be the result of a previous execution of
+ * JdbcCleanConn.execQueryWait() method on a 'select' prepared statement for
+ * this object</p>
+ * @throws Exception
+ * @return Object - A BobjStdDTO
+ * @see JdbcCleanConn#execQueryWait(PreparedStatement, int)
+ * @see DaoSnapTable#getPS(int)
+ * @see DaoSnapTable#PS_SEL_SNAP
+ * @see DaoSnapTable#PS_SEL_4UPD
+ * @see BobjStdDTO
+ */
+ public Object getFromRS (ResultSet p_oRS) throws Exception
+ { try
+ { long lUid = p_oRS.getLong(1+UID_SNAP);
+ String sXml = (m_oST.isEncrypted())
+ ? new String(seeDecrypt(p_oRS.getBytes(1+XML_OBJECT),lUid),"ISO-8859-1")
+ : p_oRS.getString(1+XML_OBJECT);
+ Object oRet = BobjStdDTO.getFromXml(sXml);
+ return oRet;
+ }
+ catch (Exception e)
+ { m_oLogger.error("getFromRS() Failed",e);
+ throw e;
+ }
+ } //________________________________
+
+
+ /**
+ * Index of the 'insert' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_INS_SNAP = 0;
+ /**
+ * Index of the 'select' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_SEL_SNAP = 1;
+ /**
+ * Index of the 'delete' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_RMV_SNAP = 2;
+ /**
+ * Index of the 'update' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_UPD_SNAP = 3;
+ /**
+ * Index of the 'select for update' statement in the list of PreparedStatement
+ * objects for this DAO
+ */
+ public static final int PS_SEL_4UPD = 4;
+
+ private static final int PS_MAX = 10;
+
+ /**
+ * Obtain a prepared statement for this DAO from the list of available PStmts
+ * <p>Uses lazy instantiation of requested objects</p>
+ * @param p_i int - Index of PreparedStatement object to obtain
+ * @throws Exception - If an invalid index is passed or there are problems
+ * during the prepareStatement() invocation
+ * @return PreparedStatement
+ */
+ public PreparedStatement getPS (int p_i) throws Exception
+ { try
+ { switch (p_i)
+ { case PS_INS_SNAP: return getInsSnap(p_i);
+ case PS_SEL_SNAP: return getSelSnap(p_i);
+ case PS_RMV_SNAP: return getRmvSnap(p_i);
+ case PS_UPD_SNAP: return getUpdSnap(p_i);
+ case PS_SEL_4UPD: return getSel4UpdSnap(p_i);
+ }
+ ;
+ throw new Exception("Invalid Index "+p_i);
+ }
+ catch (Exception e)
+ { m_oLogger.error("Request for Prepared Statement Failed",e);
+ throw e;
+ }
+ } //__________________________________
+
+ private PreparedStatement getInsSnap(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ m_oaPS[p_i] = m_oConn.prepareStatement(getInsertStatement());
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement getSelSnap(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ { StringBuffer sb = new StringBuffer(getSelectStatement())
+ .append(" where ").append(getFldName(UID_SNAP)).append(" = ? ");
+ m_oaPS[p_i] = m_oConn.prepareStatement(sb.toString());
+ }
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement getRmvSnap(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ m_oaPS[p_i] = m_oConn.prepareStatement(getDeleteStatement());
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement getUpdSnap(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ m_oaPS[p_i] = m_oConn.prepareStatement(getUpdateStatement());
+ return m_oaPS[p_i];
+ } //__________________________________
+
+ private PreparedStatement getSel4UpdSnap(int p_i) throws Exception
+ { if (null == m_oaPS[p_i])
+ { StringBuffer sb = new StringBuffer(getSelectStatement())
+ .append(" where ").append(getFldName(UID_SNAP)).append(" = ? ")
+ .append(" for update");
+ m_oaPS[p_i] = m_oConn.prepareStatement(sb.toString());
+ }
+ return m_oaPS[p_i];
+ } //__________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoUidTable.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoUidTable.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/DaoUidTable.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,275 @@
+/*
+ * 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.internal.core.objectstore;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.helpers.persist.SqlDbTable;
+import org.jboss.soa.esb.services.PersistManager;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * Data access object for the SQL table that the Object Store uses to assign
+ * Unique Identifiers (UID) to any object in the framework
+ *
+ * @see PersistManager#getUidChunk(int)
+ */
+public class DaoUidTable extends SqlDbTable {
+ /**
+ * Key value for the row in the UID table that holds UIDs for
+ * BusinessObjects "jbossEsb_objuid"
+ */
+ public static final String SEQUENCE_OBJ = "jbossEsb_objuid";
+
+ /**
+ * Key value for the row in the UID table that holds UIDs for BatchProcess
+ * "jbossEsb_batchuid"
+ */
+ public static final String SEQUENCE_BATCH = "jbossEsb_batchuid";
+
+ private Logger m_oLogger;
+
+ private DaoUidTable() throws Exception {
+ this(null, null);
+ }
+
+ /**
+ * Instantiate a DaoUidTable object using the javax.sql.DataSource object
+ * within <arg 1>, with table name held in <arg 2>
+ *
+ * @param p_oConn
+ * JdbcCleanConn - Connection to use for preparing and executing
+ * all SQL statements in this DAO
+ * @param p_sTblName
+ * String - SQL table name to use in the context of this
+ * DaoUidTable object
+ * @throws Exception -
+ * pass through from invoked methods - see
+ * Exception.getMessage() at runtime for details
+ * @see JdbcCleanConn
+ */
+ public DaoUidTable(JdbcCleanConn p_oConn, String p_sTblName)
+ throws Exception {
+ super(p_oConn, p_sTblName);
+ m_oLogger = Util.getDefaultLogger(this.getClass());
+ if (null != m_oaFields) {
+ m_oaFields[UID].setPrimaryKey(true);
+ }
+ m_oaPS = new PreparedStatement[PS_MAX];
+ } // ________________________________
+
+ /**
+ * List of fields for select statement - provided only to avoid time
+ * consuming 'select *' statements
+ *
+ * @return String - a Comma separated list of fields
+ */
+ protected String getSelectFields() {
+ return "uid,sequence_name,last_used_uid";
+ } // ________________________________
+
+ // -------------------------------------------------------------
+ // Column constants
+ // -------------------------------------------------------------
+ private static int s_iFld = 0;
+
+ /**
+ * Column index for field representing the UID of this table row
+ */
+ public static final int UID = s_iFld++;
+
+ /**
+ * Column index for field representing the sequence name of this row
+ *
+ * @see DoiUidTable#SEQUENCE_OBJ
+ * @see DoiUidTable#SEQUENCE_BATCH
+ */
+ public static final int SEQ_NAME = s_iFld++;
+
+ /**
+ * Column index for field representing the last used UID number for this
+ * particular sequence name
+ */
+ public static final int LAST_USED_UID = s_iFld++;
+
+ /**
+ * This method is supplied to comply with the parent class but it should
+ * NEVER be used
+ *
+ * @param p_PS
+ * PreparedStatement
+ * @param p_o
+ * Object
+ * @throws Exception -
+ * This will ALWAYS throw an Exception - Inserts to this table
+ * class should be handled ONLY by the Rosetta Administrator
+ * @return int - It will never return a value
+ */
+ public int setInsValues(PreparedStatement p_PS, Object p_o)
+ throws Exception {
+ String sErr = "No Inserts to UID table";
+ m_oLogger.error(sErr);
+ throw new Exception(sErr);
+ } // ________________________________
+
+ /**
+ * Provided for compatibility - Never used - Will always return null
+ *
+ * @param p_oRS
+ * ResultSet
+ * @throws Exception
+ * @return Object
+ */
+ public Object getFromRS(ResultSet p_oRS) throws Exception {
+ return null;
+ } // ________________________________
+
+ /**
+ * Index of the 'select for update' statement in the list of
+ * PreparedStatement objects for this DAO
+ */
+ public static final int PS_GET_SEQ_4_UPD = 0;
+
+ /**
+ * Index of the 'update' statement in the list of PreparedStatement objects
+ * for this DAO
+ */
+ public static final int PS_UPDATE_LAST_USED = 1;
+
+ private static final int PS_MAX = 10;
+
+ /**
+ * Obtain a prepared statement for this DAO from the list of available
+ * PStmts
+ * <p>
+ * Uses lazy instantiation of requested objects
+ * </p>
+ *
+ * @param p_i
+ * int - Index of PreparedStatement object to obtain
+ * @throws Exception -
+ * If an invalid index is passed or there are problems during
+ * the prepareStatement() invocation
+ * @return PreparedStatement
+ */
+ public PreparedStatement getPS(int p_i) throws Exception {
+ try {
+ switch (p_i) {
+ case PS_GET_SEQ_4_UPD:
+ return getSeq4Upd(p_i);
+ case PS_UPDATE_LAST_USED:
+ return updateLastUsed(p_i);
+ }
+ ;
+ throw new Exception("Invalid Index " + p_i);
+ } catch (Exception e) {
+ m_oLogger.error("Request for Prepared Statement Failed", e);
+ throw e;
+ }
+ } // __________________________________
+
+ private PreparedStatement getSeq4Upd(int p_i) throws Exception {
+ if (null == m_oaPS[p_i]) {
+ StringBuffer sb = new StringBuffer(getSelectStatement()).append(
+ " where ").append(getFldName(SEQ_NAME)).append(
+ " = ? for update");
+ m_oaPS[p_i] = getConn().prepareStatement(sb.toString());
+ }
+ return m_oaPS[p_i];
+ } // __________________________________
+
+ private PreparedStatement updateLastUsed(int p_i) throws Exception {
+ if (null == m_oaPS[p_i]) {
+ StringBuffer sb = new StringBuffer("update ").append(m_sTableName)
+ .append(" set ").append(getFldName(LAST_USED_UID)).append(
+ " = ?").append(" where ").append(
+ getFldName(SEQ_NAME)).append(" = ?");
+ m_oaPS[p_i] = getConn().prepareStatement(sb.toString());
+ }
+ return m_oaPS[p_i];
+ } // __________________________________
+
+ /**
+ * This is an exception to the standard behaviour of derived classes that
+ * extend the SqlDbTable abstract class
+ * <p>
+ * This method is called by the PersistHandler and BatchHandler EJBs and
+ * makes their life easier when they need to obtain UID chunks
+ * </p>
+ * <p>
+ * These EJBs rely on this table to ensure no duplicate UIDs across all of
+ * Rosetta
+ * </p>
+ * <p>
+ * It could also be invoked from a different context, provided that the
+ * Rosetta Administrators have added a row with a unique sequence name to
+ * the underlying SQL table that holds the last used UIDs for all numbering
+ * sequences
+ * </p>
+ *
+ * @param p_sSeqName
+ * String - Key to the sequence name to get the chunk from
+ * @param p_iQuids
+ * int - Number of UIDs to return
+ * @throws Exception
+ * @return long - First UID in the chunk assigned by this method
+ */
+ public long getUidChunk(String p_sSeqName, int p_iQuids) throws Exception {
+ try {
+ PreparedStatement PS = getPS(DaoUidTable.PS_GET_SEQ_4_UPD);
+ PS.setString(1, p_sSeqName);
+ ResultSet rs = getConn().execQueryWait(PS, 30);
+
+ boolean bOK = false;
+ try {
+ if (rs.next())
+ bOK = true;
+ } catch (Exception e1) {
+ getConn().rollback();
+ }
+ if (!bOK)
+ throw new Exception("Select FAILED jbossEsb.getChunk()");
+
+ int iSqlFld = 1 + DaoUidTable.LAST_USED_UID;
+ long lUid = rs.getLong(iSqlFld);
+ if (lUid < 1)
+ lUid = 1;
+ long lNewLast = lUid + p_iQuids;
+
+ PS = getPS(DaoUidTable.PS_UPDATE_LAST_USED);
+ PS.setLong(1, lNewLast);
+ PS.setString(2, p_sSeqName);
+ getConn().execUpdWait(PS, 10);
+
+ getConn().commit();
+
+ return lUid;
+ } catch (Exception e) {
+ m_oLogger.error(e.getMessage());
+ throw e;
+ }
+ } // __________________________________
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/RowBatch.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/RowBatch.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/RowBatch.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,42 @@
+/*
+* 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.internal.core.objectstore;
+
+public class RowBatch
+{
+ public long m_lBatch;
+ public int m_iSeq;
+ public long m_lCommitTS;
+ public String m_sData;
+
+ public RowBatch()
+ { this(0,0,0,null);
+ } //__________________________________
+
+ public RowBatch (long p_lBatch, int p_iSeq, long p_lTS, String p_sData)
+ { m_lBatch = p_lBatch;
+ m_iSeq = p_iSeq;
+ m_lCommitTS = p_lTS;
+ m_sData = p_sData;
+ } //__________________________________
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/Storable.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/Storable.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/internal/core/objectstore/Storable.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.soa.esb.internal.core.objectstore;
+
+/**
+ * Provides methods to learn about how and where a BusinessObject will be stored
+ * and retrieved from a BobjStore
+ * @see BobjStore
+ */
+
+public interface Storable
+{
+ public String getSnapType ();
+ public String getSnapTable ();
+ public String getLocatorTable ();
+ public String getLocatorTable (int p_i);
+ public boolean isEncrypted ();
+} // ___________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerBsDelegateLocal.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerBsDelegateLocal.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerBsDelegateLocal.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,58 @@
+/*
+* 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.services;
+
+import javax.naming.Context;
+
+import org.jboss.soa.esb.common.bizclasses.BatchProcess;
+import org.jboss.soa.esb.services.beans.BatchHandler;
+
+public class BatchHandlerBsDelegateLocal implements BatchManager
+{
+ private BatchHandler m_oBatchH;
+
+ public BatchHandlerBsDelegateLocal(Context p_ctx) throws Exception
+ {
+ m_oBatchH = (BatchHandler) p_ctx.lookup("jbossesb-appl/NotificationHandlerBean/local");
+ m_oBatchH.create();
+ }
+
+ public long newBatch() throws Exception
+ {
+ return m_oBatchH.newBatch();
+ }
+
+ public int addToBatch(String p_s) throws Exception
+ {
+ return m_oBatchH.addToBatch(p_s);
+ }
+
+ public void finish() throws Exception
+ {
+ m_oBatchH.finish();
+ }
+
+ public void commitBatch(BatchProcess p_oBP) throws Exception
+ {
+ m_oBatchH.commitBatch(p_oBP.toDTO());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerBsDelegateRemote.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerBsDelegateRemote.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerBsDelegateRemote.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,56 @@
+/*
+* 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.services;
+
+import javax.naming.Context;
+
+import org.jboss.soa.esb.common.bizclasses.BatchProcess;
+import org.jboss.soa.esb.services.beans.BatchHandler;
+
+public class BatchHandlerBsDelegateRemote implements BatchManager
+{
+ private BatchHandler m_oBatchH;
+
+ public BatchHandlerBsDelegateRemote(Context p_ctx) throws Exception {
+ m_oBatchH = (BatchHandler) p_ctx
+ .lookup("jbossesb-appl/NotificationHandlerBean/remote");
+ m_oBatchH.create();
+ }
+
+ public long newBatch() throws Exception {
+ return m_oBatchH.newBatch();
+ }
+
+ public int addToBatch(String p_s) throws Exception {
+ return m_oBatchH.addToBatch(p_s);
+ }
+
+ public void finish() throws Exception {
+ m_oBatchH.finish();
+ }
+
+ public void commitBatch(BatchProcess p_oBP) throws Exception {
+ m_oBatchH.commitBatch(p_oBP.toDTO());
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/BatchHandlerFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,61 @@
+/*
+* 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.services;
+
+import java.util.Arrays;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.soa.esb.helpers.AppServerContext;
+
+public class BatchHandlerFactory
+{
+ private static final String [] s_saTypes = {"local","remote","mock"};
+ private final static int LCL=0;
+ private final static int REM=1;
+ private final static int MOK=2;
+
+ public static BatchManager getBatchHandler(String p_sLocRem,
+ String p_sJndiType, String p_sJndiServer) throws Exception
+ {
+ int iIndex = Arrays.binarySearch(s_saTypes, p_sLocRem.toLowerCase());
+ if (iIndex < 0)
+ return null;
+ switch (iIndex) {
+ case LCL:
+ return new BatchHandlerBsDelegateLocal(new InitialContext());
+ case REM:
+ return getBatchHandler(AppServerContext.getServerContext(
+ p_sJndiType, p_sJndiServer));
+ case MOK:
+ return null; //return new MockBatchHandler()
+ }
+ throw new Exception("Invalid Batch Handler Delegate <" + p_sLocRem + ">");
+ }
+
+ public static BatchManager getBatchHandler(Context p_oCtx)
+ throws Exception
+ {
+ return new BatchHandlerBsDelegateRemote(p_oCtx);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotifHandlerBsDelegateLocal.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotifHandlerBsDelegateLocal.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotifHandlerBsDelegateLocal.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,52 @@
+/*
+* 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.services;
+
+import java.io.Serializable;
+
+import javax.naming.Context;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.beans.NotificationHandler;
+
+public class NotifHandlerBsDelegateLocal implements NotificationManager
+{
+ private NotificationHandler m_oNotifH;
+
+ public NotifHandlerBsDelegateLocal(Context p_ctx) throws Exception
+ {
+ m_oNotifH = (NotificationHandler) p_ctx.lookup("jbossesb-appl/NotificationHandlerBean/local");
+ m_oNotifH.create();
+ }
+
+ public void sendNotifications(ConfigTree p_oP, Serializable p_o)
+ throws Exception
+ {
+ m_oNotifH.sendNotifications(p_oP.toString(), p_o);
+ }
+
+ public void sendNotifications(Serializable p_o) throws Exception
+ {
+ m_oNotifH.sendNotifications(null, p_o);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotifHandlerBsDelegateRemote.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotifHandlerBsDelegateRemote.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotifHandlerBsDelegateRemote.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,53 @@
+/*
+* 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.services;
+
+import java.io.Serializable;
+
+import javax.naming.Context;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.services.beans.NotificationHandler;
+
+public class NotifHandlerBsDelegateRemote implements NotificationManager
+{
+ private NotificationHandler m_oNotifH;
+
+ public NotifHandlerBsDelegateRemote(Context p_ctx) throws Exception
+ {
+ m_oNotifH = (NotificationHandler) p_ctx.lookup("jbossesb-appl/NotificationHandlerBean/remote");
+ m_oNotifH.create();
+ }
+
+ public void sendNotifications(ConfigTree p_oP, Serializable p_o)
+ throws Exception
+ {
+ m_oNotifH.sendNotifications(p_oP.toString(), p_o);
+ }
+
+ public void sendNotifications(Serializable p_o) throws Exception
+ {
+ m_oNotifH.sendNotifications(null, p_o);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotificationHandlerFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotificationHandlerFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/NotificationHandlerFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,60 @@
+/*
+* 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.services;
+
+import java.util.Arrays;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.soa.esb.helpers.AppServerContext;
+
+
+public class NotificationHandlerFactory
+{
+ private static final String [] s_saTypes = {"local","remote","mock"};
+ private final static int LCL=0;
+ private final static int REM=1;
+ private final static int MOK=2;
+
+ public static NotificationManager getNotifHandler
+ (String p_sLocRem, String p_sJndiType, String p_sJndiServer) throws Exception
+ {
+ int iIndex = Arrays.binarySearch(s_saTypes,p_sLocRem.toLowerCase());
+ if (iIndex < 0) return null;
+ switch (iIndex)
+ {
+ case LCL: return new NotifHandlerBsDelegateLocal(new InitialContext());
+ case REM: return getNotifHandler
+ (AppServerContext.getServerContext(p_sJndiType,p_sJndiServer));
+ case MOK: return null; //return new MockNotificationHandler();
+ }
+ throw new Exception("Invalid Notification Handler Delegate <" + p_sLocRem + ">");
+ }
+
+ private static NotificationManager getNotifHandler(Context p_oCtx) throws Exception
+ {
+ return new NotifHandlerBsDelegateRemote(p_oCtx);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerBsDelegateLocal.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerBsDelegateLocal.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerBsDelegateLocal.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,80 @@
+/*
+* 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.services;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+
+import org.jboss.soa.esb.services.beans.PersistHandler;
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.ObjLocator;
+
+
+public class PersistHandlerBsDelegateLocal implements PersistManager
+{
+ private PersistHandler m_oSnapH;
+
+ public PersistHandlerBsDelegateLocal(Context p_ctx) throws Exception {
+ m_oSnapH = (PersistHandler) p_ctx.lookup("jbossesb-appl/PersistHandlerBean/local");
+ m_oSnapH.create();
+ }
+
+ public long getUidChunk(int p_iQ) throws Exception {
+ return m_oSnapH.getUidChunk(p_iQ);
+ }
+
+ public long addObject(BobjStdDTO p_oDto) throws Exception {
+ return m_oSnapH.addDTO(p_oDto);
+ }
+
+ public long addObject(BaseBusinessObject p_oBo) throws Exception {
+ p_oBo.setPackage();
+ return m_oSnapH.addDTO(p_oBo.toDTO());
+ }
+
+ public BaseBusinessObject getObject(Class p_oCls, long p_lUid)
+ throws Exception {
+ BobjStdDTO oDto = m_oSnapH.getDTO(p_oCls.getName(), p_lUid);
+ return (null == oDto) ? null : BaseBusinessObject.getFromDTO(oDto);
+ }
+
+ public void rmvObject(Class p_oCls, long p_lUid) throws Exception {
+ m_oSnapH.rmvObject(p_oCls.getName(), p_lUid);
+ }
+
+ public void rplObject(BaseBusinessObject p_o) throws Exception {
+ p_o.setPackage();
+ m_oSnapH.rplDTO(p_o.toDTO());
+ }
+
+ public ObjLocator[] getLocatorList(Class p_oCls, Properties p_oProp) {
+ return null;
+ } //__________________________________
+
+ public ObjLocator[] getLocatorList(Class p_oCls, long[] p_laUids) {
+ return null;
+ } //__________________________________
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerBsDelegateRemote.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerBsDelegateRemote.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerBsDelegateRemote.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,88 @@
+/*
+* 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.services;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+
+import org.jboss.soa.esb.services.beans.PersistHandler;
+import org.jboss.soa.esb.util.BaseBusinessObject;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.ObjLocator;
+
+
+public class PersistHandlerBsDelegateRemote implements PersistManager
+{
+ private PersistHandler m_oSnapH;
+
+ public PersistHandlerBsDelegateRemote(Context p_ctx) throws Exception
+ {
+ m_oSnapH = (PersistHandler) p_ctx.lookup("jbossesb-appl/PersistHandlerBean/remote");
+ m_oSnapH.create();
+ }
+
+ public long getUidChunk(int p_iQ) throws Exception
+ {
+ return m_oSnapH.getUidChunk(p_iQ);
+ }
+
+ public long addObject (BaseBusinessObject p_oBo) throws Exception
+ {
+ if (null==p_oBo) return -1;
+ p_oBo.setPackage();
+ BobjStdDTO oDto = p_oBo.toDTO();
+ oDto.setLocators(p_oBo.allLocators());
+ return m_oSnapH.addDTO(oDto);
+ }
+
+ public BaseBusinessObject getObject (Class p_oCls, long p_lUid) throws Exception
+ {
+ BobjStdDTO oDto = m_oSnapH.getDTO(p_oCls.getName(), p_lUid);
+ return (null==oDto)?null:BaseBusinessObject.getFromDTO(oDto);
+ }
+
+ public void rmvObject (Class p_oCls, long p_lUid) throws Exception
+ {
+ m_oSnapH.rmvObject(p_oCls.getName(), p_lUid);
+ }
+
+ public void rplObject (BaseBusinessObject p_oBo) throws Exception
+ { if (null==p_oBo) return;
+ p_oBo.setPackage();
+ BobjStdDTO oDto = p_oBo.toDTO();
+ oDto.setLocators(p_oBo.allLocators());
+ m_oSnapH.rplDTO(oDto);
+ }
+
+ public ObjLocator[] getLocatorList(Class p_oCls, Properties p_oProp)
+ {
+ return null;
+ } //__________________________________
+
+ public ObjLocator[] getLocatorList(Class p_oCls, long[] p_laUids)
+ {
+ return null;
+ } //__________________________________
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/PersistHandlerFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,59 @@
+/*
+* 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.services;
+
+import java.util.Arrays;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.soa.esb.helpers.AppServerContext;
+
+public class PersistHandlerFactory
+{
+ private static final String [] s_saTypes = {"local","remote","mock"};
+ private final static int LCL=0;
+ private final static int REM=1;
+ private final static int MOK=2;
+
+ public static PersistManager getPersistHandler
+ (String p_sLocRem, String p_sJndiType, String p_sJndiServer) throws Exception
+ {
+ int iIndex = Arrays.binarySearch(s_saTypes,p_sLocRem.toLowerCase());
+ if (iIndex < 0) return null;
+ switch (iIndex)
+ {
+ case LCL: return new PersistHandlerBsDelegateLocal(new InitialContext());
+ case REM: return getPersistHandler
+ (AppServerContext.getServerContext(p_sJndiType,p_sJndiServer));
+ case MOK: return null; //new MockPersistHandler();
+ }
+ throw new Exception("Invalid Persist Handler Delegate <" + p_sLocRem + ">");
+ }
+
+ public static PersistManager getPersistHandler(Context p_oCtx) throws Exception
+ {
+ return new PersistHandlerBsDelegateRemote(p_oCtx);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,39 @@
+/*
+* 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.services.beans;
+
+import javax.ejb.CreateException;
+
+import org.jboss.soa.esb.util.BobjStdDTO;
+
+/**
+ * @author kstam
+ */
+public interface BatchHandler
+{
+ public void create() throws CreateException;
+ public void finish() throws Exception;
+ public void commitBatch(BobjStdDTO p_oDto ) throws Exception;
+ public long newBatch() throws Exception;
+ public int addToBatch(String p_s) throws Exception;
+ public void remove();
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,327 @@
+/*
+* 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.services.beans;
+
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.text.SimpleDateFormat;
+
+import javax.ejb.CreateException;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.bizclasses.BatchProcess;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.internal.core.objectstore.BobjStore;
+import org.jboss.soa.esb.internal.core.objectstore.DaoBatchTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoIndexTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoSnapTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoUidTable;
+import org.jboss.soa.esb.internal.core.objectstore.RowBatch;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+/**
+ * @author Esteban
+ */
+ at Remote(BatchHandler.class)
+ at Local(BatchHandler.class)
+ at TransactionManagement(TransactionManagementType.BEAN)
+public @Stateful class BatchHandlerBean implements BatchHandler
+{
+ private static final long serialVersionUID = 1L;
+ SessionContext m_oSessCtx;
+
+ public void setSessionContext(SessionContext p_oSessCtx)
+ { this.m_oSessCtx = p_oSessCtx; }
+
+ private Logger m_oLogger;
+ private JdbcCleanConn m_oUidConn;
+ private JdbcCleanConn m_oDataConn;
+
+ private DaoUidTable m_oDaoUid;
+ private DaoBatchTable m_oDaoBatch;
+ private DaoIndexTable m_oDaoIndex;
+ private DaoSnapTable m_oDaoSnap;
+
+ private long m_lBatchNum = -1;
+ private int m_iSeq;
+
+/**
+ * @throws CreateException
+ */
+ @Init
+ public void create() throws CreateException
+ {
+ try
+ { getResources();
+ m_oLogger.info(this.toString()+" Created");
+ }
+ catch (Exception e)
+ { m_oLogger.error("Failed to Create : <"+e.getMessage()+">");
+ throw new CreateException(e.getMessage());
+ }
+ } //__________________________________
+
+ @PostActivate
+ public void ejbActivate()
+ { try
+ { getResources();
+ m_oLogger.info("EJB Activated");
+ }
+ catch (Exception e)
+ { m_oLogger.error("Failed to Activate : <"+e.getMessage()+">");
+ }
+ } //__________________________________
+
+ @PrePassivate
+ public void ejbPassivate()
+ { m_oLogger.info("EJB Passivated");
+ releaseResources();
+ m_oLogger = null;
+ m_oUidConn = null;
+ m_oDataConn = null;
+ } //__________________________________
+
+ @Remove
+ public void remove()
+ {
+ releaseResources();
+ m_oLogger.info("EJB Removed");
+ } //__________________________________
+
+ private void getResources() throws Exception
+ { Context oCtx = new InitialContext();
+ m_oLogger = Util.getDefaultLogger(this.getClass());
+ m_oUidConn = new JdbcCleanConn ((DataSource)oCtx.lookup("java:JbossEsbDS"));
+ m_oDataConn = new JdbcCleanConn ((DataSource)oCtx.lookup("java:JbossEsbDS"));
+ } //__________________________________
+
+ private void releaseResources()
+ { if (null != m_oDataConn) m_oDataConn.release();
+ if (null != m_oUidConn) m_oUidConn.release();
+ m_oDaoBatch = null;
+ m_oDaoUid = null;
+ m_oDaoIndex = null;
+ m_oDaoSnap = null;
+ } //__________________________________
+
+// Utility Methods
+
+ private DaoUidTable getDaoUid() throws Exception
+ { if (null==m_oDaoUid)
+ m_oDaoUid = new DaoUidTable(m_oUidConn, BobjStore.getUidTableName());
+ return m_oDaoUid;
+ } //__________________________________
+
+ private DaoBatchTable getDaoBatch(String p_sTbl) throws Exception
+ { if (null==m_oDaoBatch)
+ m_oDaoBatch = new DaoBatchTable(m_oDataConn,p_sTbl);
+ return m_oDaoBatch;
+ } //__________________________________
+
+ private DaoIndexTable getDaoIndex(String p_sTbl) throws Exception
+ { if (null==m_oDaoIndex)
+ m_oDaoIndex = new DaoIndexTable(m_oDataConn,p_sTbl);
+ return m_oDaoIndex;
+ } //__________________________________
+
+ private DaoSnapTable getDaoSnap(BobjStore p_o) throws Exception
+ { if (null==m_oDaoSnap)
+ m_oDaoSnap = new DaoSnapTable(m_oDataConn,p_o);
+ return m_oDaoSnap;
+ } //__________________________________
+
+ private void doCommitBatch(BatchProcess p_oBP) throws Exception
+ { String sPrevClass = null;
+ BobjStore oStore = null;
+
+ PreparedStatement PSbatch = getDaoBatch(BobjStore.getBatchTableName())
+ .getPS(DaoBatchTable.PS_GET_BATCH_ROWS);
+ PSbatch.setLong(1,p_oBP.getBatchNum());
+
+ long lNow = System.currentTimeMillis();
+ String sSnapDt = new SimpleDateFormat("yyyyMMdd").format(new Date(lNow));
+
+ // Get all Batch rows
+ ResultSet RS = m_oDataConn.execQueryWait(PSbatch,10);
+ while (RS.next())
+ { String sXml = RS.getString(1+DaoBatchTable.STR_DATA);
+ BobjStdDTO oDto = BobjStdDTO.getFromXml(sXml);
+ // Get proper Dao's for Index and Snap table
+ String sNewClass = oDto.fullClassName();
+ if (! sNewClass.equals(sPrevClass))
+ { oStore = BobjStore.getStore(sNewClass);
+ sPrevClass = sNewClass;
+ m_oDaoIndex = null;
+ m_oDaoSnap = null;
+ }
+ // Set batch number to current batch
+ oDto.setBatch (p_oBP.getBatchNum());
+ oDto.setStamp (lNow);
+ oDto.setSnapDate(sSnapDt);
+
+ // Insert Snap row
+ PreparedStatement PSins = getDaoSnap(oStore).getPS(DaoSnapTable.PS_INS_SNAP);
+ m_oDaoSnap.setInsValues(PSins,oDto);
+ try { m_oDataConn.execUpdWait(PSins,10); }
+ catch (Exception e) { m_oLogger.error(e.getMessage()); }
+
+ // Insert row in all index tables
+ String[][] saa = oDto.getLocators();
+ for (int i1=0; i1<saa.length; i1++)
+ { m_oDaoIndex = getDaoIndex(oStore.getLocatorTable(i1));
+ PSins = m_oDaoIndex.getPS(DaoIndexTable.PS_INS_INDEX);
+ m_oDaoIndex.setInsValues(PSins,oDto,i1);
+ try { m_oDataConn.execUpdWait(PSins,10); }
+ catch (Exception e) { m_oLogger.error(e.getMessage()); }
+ }
+ }
+ PSbatch.close();
+
+ // Delete batch rows we just used
+ PreparedStatement PSdel = getDaoBatch(BobjStore.getBatchTableName())
+ .getPS(DaoBatchTable.PS_DELETE_BATCH);
+ PSdel.setLong(1,p_oBP.getBatchNum());
+ m_oDataConn.execUpdWait(PSdel,10);
+
+ p_oBP.setField (BatchProcess.ATTRIB.commitStamp,Long.toString(lNow));
+ p_oBP.setStamp (lNow);
+ p_oBP.setSnapDate(sSnapDt);
+
+ oStore = BobjStore.getStore(BatchProcess.class.getName());
+
+ // Update snap table with proper timestamp
+ m_oDaoSnap = null;
+ PreparedStatement PSupd = getDaoSnap(oStore).getPS(DaoSnapTable.PS_UPD_SNAP);
+ getDaoSnap(oStore).setUpdValues(PSupd,p_oBP);
+ m_oDataConn.execUpdWait(PSupd,10);
+
+ // Update index table with proper timestamp
+ m_oDaoIndex = null;
+ PSupd = getDaoIndex(oStore.getLocatorTable()).getPS(DaoIndexTable.PS_UPD_INDEX);
+ getDaoIndex(oStore.getLocatorTable()).setUpdValues(PSupd,p_oBP);
+ m_oDataConn.execUpdWait(PSupd,10);
+
+ } //__________________________________
+
+//______________________________________________________________________________
+// Public local and remote interface methods
+/**
+ */
+ public long newBatch() throws Exception
+ { if (m_lBatchNum > 0) throw
+ new Exception ("Must finish with previous batch before opening new");
+ m_iSeq = 0;
+ try
+ { return m_lBatchNum = getDaoUid().getUidChunk(DaoUidTable.SEQUENCE_BATCH, 1);
+ }
+ catch (Exception e)
+ { m_oLogger.error("BatchHandlerBean.newBatch() FAILED "+ e.getMessage());
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+
+/**
+ * @return
+ */
+ public long getBatchNum()
+ { return m_lBatchNum;
+ } //__________________________________
+
+/**
+ * @param p_s
+ * @return
+ * @throws Exception
+ */
+ public int addToBatch(String p_s) throws Exception
+ { if (null==p_s) throw
+ new Exception ("Tryng to add a null String to a batch");
+ if (m_lBatchNum < 1) throw
+ new Exception ("Must request batch number before adding objects");
+ try
+ { RowBatch oRow = new RowBatch(m_lBatchNum,++m_iSeq,0,p_s);
+ getDaoBatch(BobjStore.getBatchTableName());
+ PreparedStatement PS = m_oDaoBatch.getPS(DaoBatchTable.PS_INS_BATCHROW);
+ m_oDaoBatch.setInsValues(PS,oRow);
+ m_oDataConn.execUpdWait(PS,1);
+ m_oDataConn.commit();
+ return m_iSeq;
+ }
+ catch (Exception e)
+ { if (null != m_oDataConn) m_oDataConn.rollback();
+ m_oLogger.error("addToBatch() failed",e);
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+/**
+ * @throws Exception
+ */
+ public void finish() throws Exception
+ { if (m_lBatchNum < 1) return;
+ m_lBatchNum = -1;
+ m_iSeq = 0;
+ } //__________________________________
+
+//______________________________________________________________________________
+// Public local interface methods
+///** KS: I'm commenting this out since we are now using the
+// same interface for local and remote calls. If all
+// works this code can be deleted.
+// */
+// public void commitBatch(BatchProcess p_oBO) throws Exception
+// { try { doCommitBatch(p_oBO); m_oDataConn.commit(); }
+// catch (Exception e)
+// { if (null != m_oDataConn) m_oDataConn.rollback();
+// m_oLogger.error("commitBatch(BatchProcess) FAILED ",e);
+// throw e;
+// }
+// finally { releaseResources(); }
+// } //__________________________________
+
+//______________________________________________________________________________
+// Public remote interface methods
+/**
+ */
+ public void commitBatch(BobjStdDTO p_oDto) throws Exception
+ {
+ doCommitBatch (new BatchProcess(p_oDto));
+ }
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,34 @@
+/*
+* 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.services.beans;
+
+import java.io.Serializable;
+
+/**
+ * Business interface for NotificationHandler.
+ * @author kstam
+ */
+public interface NotificationHandler
+{
+ public void create() throws Exception;
+ public void sendNotifications( String p_sParams, Serializable p_oMsg ) throws Exception;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,123 @@
+/*
+* 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.services.beans;
+
+import java.io.Serializable;
+
+import javax.ejb.CreateException;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.notification.NotificationList;
+import org.jboss.soa.esb.util.Util;
+/**
+ * @author Esteban
+ */
+ at Remote(NotificationHandler.class)
+ at Local(NotificationHandler.class)
+ at TransactionManagement(TransactionManagementType.CONTAINER)
+ at TransactionAttribute(TransactionAttributeType.REQUIRED)
+
+public @Stateless class NotificationHandlerBean implements NotificationHandler
+{
+ private static final long serialVersionUID = 1L;
+ private Logger m_oLogger;
+ SessionContext m_ctxSess;
+
+ public void setSessionContext(SessionContext sessionContext)
+ { m_ctxSess = sessionContext; }
+/**
+ * @throws CreateException
+ */
+ @Init
+ public void create() throws Exception
+ { try
+ { m_oLogger = Util.getDefaultLogger(this.getClass());
+ //Context oCtxInit =
+ // new InitialContext();
+
+ m_oLogger.info(this.toString()+" Created");
+ }
+ catch (Exception e)
+ { m_oLogger.error("EJB Create Failed <"+e.getMessage()+">");
+ throw new Exception(e.getMessage());
+ }
+ } //__________________________________
+
+ @Remove
+ public void ejbRemove()
+ { m_oLogger.info(this.toString()+" Removed");
+ } //__________________________________
+
+// Utility Methods
+
+ protected void releaseResources()
+ {
+ } //__________________________________
+
+//______________________________________________________________________________
+// Public local and remote interface methods
+
+ private static final String s_sDfltList =
+ "<NotificationList type=\"Error\" >"
+ +" <target"
+ +" class = \"NotifyEmail\""
+ +" from = \"JbossEsbDefault at myOrg.com\""
+ +" sendTo = \"\""
+ +" subject = \"Default JBoss ESB Notification\""
+ +" message = \" Message from JBoss ESB :\""
+ +" />"
+ +" </NotificationList>"
+ ;
+ private static NotificationList s_dfltList;
+ static
+ { try
+ { s_dfltList = new NotificationList(ConfigTree.fromXml(s_sDfltList)); }
+ catch (Exception e) { e.printStackTrace(System.out); }
+ }
+/**
+ * @param p_sParams
+ * @param p_sMsg
+ * @throws Exception
+ */
+ public void sendNotifications(String p_sParams, Serializable p_oMsg)
+ throws Exception
+ {
+ ConfigTree oP = (null==p_sParams)?null:ConfigTree.fromXml(p_sParams);
+ NotificationList m_oL = (null==oP) ? s_dfltList : new NotificationList(oP);
+ m_oL.sendNotification(p_oMsg);
+ } //__________________________________
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,43 @@
+/*
+* 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.services.beans;
+
+import org.jboss.soa.esb.util.BobjStdDTO;
+
+/**
+ * @author kstam
+ */
+public interface PersistHandler
+{
+ public void create() throws Exception;
+
+ public long getUidChunk( int p_iQ ) throws Exception;
+
+ public void rmvObject( String p_sClassName,long p_lUid ) throws Exception;
+
+ public long addDTO( BobjStdDTO p_oDto ) throws Exception;
+
+ public BobjStdDTO getDTO( String p_sClassName,long p_lUid ) throws Exception;
+
+ public void rplDTO( BobjStdDTO p_oDto ) throws Exception;
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,369 @@
+/*
+* 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.services.beans;
+
+import java.io.ObjectStreamClass;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.text.SimpleDateFormat;
+
+import javax.ejb.CreateException;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.internal.core.objectstore.BobjStore;
+import org.jboss.soa.esb.internal.core.objectstore.DaoIndexTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoSnapTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoUidTable;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.ObjLocator;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * @author Esteban
+ */
+ at Remote(PersistHandler.class)
+ at Local(PersistHandler.class)
+ at TransactionManagement(TransactionManagementType.BEAN)
+public @Stateless class PersistHandlerBean implements PersistHandler
+{
+ private static final long serialVersionUID = 1L;
+ private Logger m_oLogger;
+ SessionContext m_ctxSess;
+
+ private JdbcCleanConn m_oUidConn;
+ private JdbcCleanConn m_oDataConn;
+
+ private static final int s_iChunkSize=100;
+ private long m_lUid;
+ private int m_iChunkLeft=0;
+
+ private DaoUidTable m_oDaoUid;
+ private DaoSnapTable m_oDaoSnap;
+ private DaoIndexTable[] m_oaDaoIndex;
+
+ public void setSessionContext(SessionContext sessionContext)
+ { m_ctxSess = sessionContext; }
+/**
+ * Create method. Should get called to initialize this class.
+ * @throws CreateException
+ */
+ @Init
+ public void create() throws Exception
+ { try
+ { m_oLogger = Util.getDefaultLogger(this.getClass());
+ Context oCtxInit = new InitialContext();
+ String sDSjndiName = BobjStore.getDataSourceJndi();
+ DataSource oDS = (DataSource)oCtxInit.lookup(sDSjndiName);
+ m_oUidConn = new JdbcCleanConn(oDS);
+ m_oDataConn = new JdbcCleanConn(oDS);
+
+ Class oCls = BobjStdDTO.class;
+ ObjectStreamClass XX = ObjectStreamClass.lookup(oCls);
+ System.out.println(XX.getSerialVersionUID());
+ System.out.println(oCls.getProtectionDomain().getCodeSource().getLocation());
+
+ m_oLogger.info(this.toString()+" Created");
+ }
+ catch (Exception e)
+ { m_oLogger.error("EJB Create Failed <"+e.getMessage()+">");
+ throw e;
+ }
+ } //__________________________________
+
+ @Remove
+ public void remove()
+ { m_oLogger.info(this.toString()+" Removed");
+ } //__________________________________
+
+
+ /**
+ * @param p_sClassName - String Fully qualified name of class to be retrieved
+ * @param p_lUid
+ * @return
+ * @throws Exception
+ */
+ public BobjStdDTO getDTO (String p_sClassName, long p_lUid) throws Exception
+ { try { return doGetSnapshot(BobjStore.getStore(p_sClassName), p_lUid);}
+ catch (Exception e) { throw e; }
+ finally { releaseResources(); }
+ } //__________________________________
+ /**
+ *
+ * @param p_oDto BobjStdDTO - Serialized BaseBusinessObject that has to be replaced
+ * @throws Exception
+ */
+ public void rplDTO(BobjStdDTO p_oDto) throws Exception
+ { try
+ { doRplSnapshot(p_oDto);
+ m_oDataConn.commit();
+ }
+ catch (Exception e)
+ { try { if (null != m_oDataConn) m_oDataConn.rollback(); }
+ catch (Exception eRoll) {}
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+
+// ______________________________________________________________________________
+// Public local and remote interface methods
+ /**
+ */
+ public long getUidChunk (int p_iQ) throws Exception
+ { try { return getDaoUid().getUidChunk(DaoUidTable.SEQUENCE_OBJ,p_iQ); }
+ catch (Exception e) { throw e;}
+ finally { releaseResources(); }
+ } //__________________________________
+ /**
+ * @param p_sClassName
+ * @param p_lUid
+ * @throws Exception
+ */
+ public void rmvObject(String p_sClassName, long p_lUid) throws Exception
+ { try { doRmvSnapshot(BobjStore.getStore(p_sClassName), p_lUid); m_oDataConn.commit(); }
+ catch (Exception e)
+ { try { if (null != m_oDataConn) m_oDataConn.rollback(); }
+ catch (Exception eRoll) {}
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+
+ /**
+ */
+ public long addDTO(BobjStdDTO p_oDto) throws Exception
+ { try
+ { long lRet = doAddSnapshot(p_oDto);
+ m_oDataConn.commit();
+ return lRet;
+ }
+ catch (Exception e)
+ { try { if (null != m_oDataConn) m_oDataConn.rollback(); }
+ catch (Exception eRoll) {}
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+
+
+// Utility Methods
+
+ private DaoUidTable getDaoUid() throws Exception
+ { if (null==m_oDaoUid) m_oDaoUid
+ = new DaoUidTable(m_oUidConn,BobjStore.getUidTableName());
+ return m_oDaoUid;
+ } //__________________________________
+
+ private DaoSnapTable getDaoSnap(BobjStore p_oSt) throws Exception
+ { if (null==m_oDaoSnap)
+ m_oDaoSnap = new DaoSnapTable(m_oDataConn,p_oSt);
+ return m_oDaoSnap;
+ } //__________________________________
+
+ private DaoIndexTable getDaoIndex(BobjStore p_oSt,int p_i) throws Exception
+ { if (null==m_oaDaoIndex)
+ m_oaDaoIndex = new DaoIndexTable[p_oSt.allLocatorTables().length];
+ if (null==m_oaDaoIndex[p_i])
+ m_oaDaoIndex[p_i] = new DaoIndexTable(m_oDataConn,p_oSt.getLocatorTable(p_i));
+ return m_oaDaoIndex[p_i];
+ } //__________________________________
+
+ protected ObjLocator[] doAddLocators(BobjStore pStore,BobjStdDTO p_oDto) throws Exception
+ { long lUid = p_oDto.getUid();
+ if (lUid < 1)
+ { lUid = doAssignUid();
+ p_oDto.setUid(lUid);
+ p_oDto.setSnap(lUid);
+ }
+ long lStamp = p_oDto.getStamp();
+ if (lStamp < 1)
+ p_oDto.setStamp(lStamp = System.currentTimeMillis());
+
+ String[][] saa = p_oDto.getLocators();
+ ObjLocator[]oaRet = new ObjLocator[saa.length];
+ int iCurr = 0;
+ for (int i1=0; i1<saa.length; i1++)
+ { String[] saCurr = saa[i1];
+ ObjLocator oLoc = new ObjLocator(lUid,saCurr);
+ oaRet[iCurr] = oLoc;
+ String sTbl = pStore.getLocatorTable(iCurr++);
+ if (null == sTbl)
+ continue;
+
+ DaoIndexTable oDao = new DaoIndexTable(m_oDataConn,sTbl);
+ PreparedStatement PS = oDao.getPS(DaoIndexTable.PS_INS_INDEX);
+
+ PS.setLong (DaoIndexTable.OBJECT_UID,lUid);
+ PS.setLong (DaoIndexTable.TIMESTAMP,lStamp);
+ PS.setLong (DaoIndexTable.UID_SNAP,p_oDto.getSnap());
+ PS.setString (DaoIndexTable.SNAP_DATE,s_oY4md.format(new Date(lStamp)));
+
+ int iFld = DaoIndexTable.FIRST_FIELD;
+ for (int i2=0; i2<saCurr.length; i2++)
+ { String sFldVal = saCurr[i2];
+ PS.setString(iFld++,(null == sFldVal)?"":sFldVal);
+ }
+ m_oDataConn.execUpdWait(PS,1);
+ }
+
+ return oaRet;
+ } //__________________________________
+
+ private void doDelLocators (BobjStore p_oSt, long p_lUid)
+ { if (p_lUid < 1) return;
+ int iQlocs = p_oSt.allLocatorTables().length;
+ for (int i1=0; i1<iQlocs; i1++)
+ try
+ { PreparedStatement PS = getDaoIndex(p_oSt,i1).getPS(DaoIndexTable.PS_RMV_INDEX);
+ PS.setLong(1,p_lUid);
+ m_oDataConn.execUpdWait(PS,5);
+ }
+ catch (Exception e)
+ { m_oLogger.warn("doDelLocator() FAILED <"+e.getMessage()+">");
+ }
+ } //__________________________________
+
+ private void doDelOneSnap (BobjStore p_oSt,long p_lUid) throws Exception
+ { if (p_lUid < 1) return;
+ PreparedStatement PS = getDaoSnap(p_oSt).getPS(DaoSnapTable.PS_RMV_SNAP);
+ PS.setLong(1,p_lUid);
+ m_oDataConn.execUpdWait(PS,5);
+ } //__________________________________
+
+ private void doRmvSnapshot (BobjStore p_oSt,long p_lUid) throws Exception
+ {
+ PreparedStatement PS = getDaoSnap(p_oSt).getPS(DaoSnapTable.PS_SEL_4UPD);
+ PS.setLong(1,p_lUid);
+ ResultSet rs = m_oDataConn.execQueryWait(PS,30);
+ if (! rs.next()) throw new Exception("Non existing Snapshot");
+ long lObjUid = rs.getLong(DaoSnapTable.OBJECT_UID);
+
+ doDelOneSnap(p_oSt,p_lUid);
+ doDelLocators(p_oSt,lObjUid);
+
+ } //__________________________________
+
+ private void doRplSnapshot(BobjStdDTO p_oDto)
+ throws Exception
+ { long lSnapUid = p_oDto.getSnap();
+ BobjStore oSt = BobjStore.getStore(p_oDto);
+ doDelOneSnap(oSt,lSnapUid);
+ doDelLocators(oSt,p_oDto.getUid());
+ doAddSnapshot(p_oDto,false);
+ } //__________________________________
+
+ private long doAddSnapshot(BobjStdDTO p_oDto)
+ throws Exception
+ { return doAddSnapshot(p_oDto,true);
+ } //__________________________________
+
+ SimpleDateFormat s_oY4md = new SimpleDateFormat("yyyyMMdd");
+ private long doAddSnapshot(BobjStdDTO p_oDto, boolean p_bNewVrs)
+ throws Exception
+ { long lObjUid = p_oDto.getUid();
+ if (lObjUid < 1) p_oDto.setUid(lObjUid=doAssignUid());
+ p_oDto.setSnap(lObjUid);
+
+ // Set Timestamp
+ long lNow = System.currentTimeMillis();
+ p_oDto.setStamp(lNow);
+ p_oDto.setSnapDate(s_oY4md.format(new Date(lNow)));
+
+ BobjStore oSt = BobjStore.getStore(p_oDto);
+ PreparedStatement PS = getDaoSnap(oSt).getPS(DaoSnapTable.PS_INS_SNAP);
+ getDaoSnap(oSt).setInsValues(PS,p_oDto);
+
+ m_oDataConn.execUpdWait(PS,1);
+
+ int iQlocs = oSt.allLocatorTables().length;
+ for (int i1=0; i1<iQlocs; i1++)
+ { DaoIndexTable oDao = getDaoIndex(oSt,i1);
+ PS = oDao.getPS(DaoIndexTable.PS_INS_INDEX);
+ oDao.setInsValues(PS,p_oDto);
+ try { m_oDataConn.execUpdWait(PS,1); }
+ catch (Exception e)
+ { PS = oDao.getPS(DaoIndexTable.PS_UPD_INDEX);
+ oDao.setUpdValues(PS,p_oDto);
+ m_oDataConn.execUpdWait(PS,10);
+ }
+ }
+
+ return lObjUid;
+ } //__________________________________
+
+ protected void updateLocTbl(BobjStdDTO p_oDto, int p_iNum)
+ throws Exception
+ { BobjStore oSt = BobjStore.getStore(p_oDto);
+ String sTbl = oSt.getLocatorTable(p_iNum);
+ if (null==sTbl) return;
+ DaoIndexTable oDao = getDaoIndex(oSt,p_iNum);
+ PreparedStatement PSupd = oDao.getPS(DaoIndexTable.PS_UPD_INDEX);
+ oDao.setUpdValues(PSupd, p_oDto);
+
+ m_oDataConn.execUpdWait(PSupd,10);
+ } //__________________________________
+
+ private BobjStdDTO doGetSnapshot (BobjStore p_oSt,long p_lUid) throws Exception
+ { PreparedStatement PS = getDaoSnap(p_oSt).getPS(DaoSnapTable.PS_SEL_SNAP);
+ PS.setLong(1,p_lUid);
+ ResultSet rs = m_oDataConn.execQueryWait(PS,30);
+ if (! rs.next()) throw new Exception("Non existing Snapshot");
+ BobjStdDTO oRet = (BobjStdDTO)getDaoSnap(p_oSt).getFromRS(rs);
+ return oRet;
+ } //__________________________________
+
+ private void releaseResources()
+ { if (null!=m_oaDaoIndex)
+ for (int i1=0; i1<m_oaDaoIndex.length; i1++)
+ m_oaDaoIndex[i1] = null;
+ m_oaDaoIndex = null;
+ m_oDaoSnap = null;
+ m_oDaoUid = null;
+ if (null != m_oDataConn) m_oDataConn.release();
+ if (null != m_oUidConn) m_oUidConn.release();
+ } //__________________________________
+
+ private long doAssignUid() throws Exception
+ { if (m_iChunkLeft < 1)
+ { m_lUid = getDaoUid().getUidChunk(DaoUidTable.SEQUENCE_OBJ, s_iChunkSize);
+ m_iChunkLeft = s_iChunkSize;
+ }
+ m_iChunkLeft--;
+ return ++m_lUid;
+ } //__________________________________
+
+
+
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreFactoryImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreFactoryImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreFactoryImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+
+package org.jboss.internal.soa.esb.persistence.format;
+
+import java.net.URI;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
+
+
+import org.jboss.internal.soa.esb.persistence.format.db.DBMessageStorePlugin;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+import org.jboss.soa.esb.services.persistence.MessageStoreFactory;
+
+public class MessageStoreFactoryImpl extends MessageStoreFactory {
+
+ private final Hashtable<URI, MessageStorePlugin> messageStoreFormats = new Hashtable<URI, MessageStorePlugin>();
+
+
+ public MessageStoreFactoryImpl() {
+ reset();
+ }
+
+ public MessageStore getMessageStore() {
+ return ((MessageStorePlugin) messageStoreFormats.get(MessageStoreType.DEFAULT_TYPE)).getMessageStore();
+ }
+
+ public MessageStore getMessageStore(URI type) {
+ if (type == null)
+ throw new IllegalArgumentException();
+
+ MessageStorePlugin plugin = messageStoreFormats.get(type);
+
+ if (plugin != null)
+ return plugin.getMessageStore();
+ else
+ return null;
+ }
+
+ public void reset ()
+ {
+ messageStoreFormats.clear();
+ /*
+ * Go through the properties loaded from the property file. Anything
+ * starting with MessageStorePlugin.MESSAGE_STORE_PLUGIN is assumed to be a plugin
+ * that we load and add to the list.
+ */
+
+ Properties properties = System.getProperties();
+
+ if (properties != null)
+ {
+ Enumeration names = properties.propertyNames();
+
+ while (names.hasMoreElements())
+ {
+ String attrName = (String) names.nextElement();
+
+ if (attrName.startsWith(MessageStorePlugin. MESSAGE_STORE_PLUGIN))
+ {
+ try
+ {
+ String pluginName = properties.getProperty(attrName);
+ Class c = Class.forName(pluginName);
+ MessageStorePlugin thePlugin = (MessageStorePlugin) c.newInstance();
+
+ messageStoreFormats.put(thePlugin.getType(), thePlugin);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch (IllegalAccessException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch (InstantiationException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+
+ /*
+ * Now add the default(s).
+ */
+ messageStoreFormats.put(MessageStoreType.DATABASE, new DBMessageStorePlugin());
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStorePlugin.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStorePlugin.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStorePlugin.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.persistence.format;
+
+import java.net.URI;
+
+import org.jboss.soa.esb.services.persistence.MessageStore;
+
+
+/**
+* Used to plug in new message stores dynamically. Each plugin is responsible for
+* returning a message store implementation that knows how to handle its own persistence
+* mechanism, i.e: database, file, etc.
+*
+* @author Daniel Brum
+*
+*/
+
+public interface MessageStorePlugin {
+
+public static final String MESSAGE_STORE_PLUGIN = "org.jboss.soa.esb.persistence.base.plugin";
+
+ /**
+ * @return the message instance.
+ */
+
+ public MessageStore getMessageStore ();
+
+ /**
+ * @return the unique identifier for this message store plugin.
+ */
+
+ public URI getType ();
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreType.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreType.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/MessageStoreType.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+/**
+ * You get a message store of a specific type when you need it.
+ *
+ * @author Daniel Brum
+ *
+ */
+
+package org.jboss.internal.soa.esb.persistence.format;
+
+import java.net.URI;
+
+public abstract class MessageStoreType {
+ /*
+ * DO NOT reorder this list. New types may be added as required.
+ */
+
+ public static URI DATABASE = null;
+
+ public static URI DEFAULT_TYPE = null;
+
+ static
+ {
+ try
+ {
+ DATABASE = new URI("urn:jboss:esb:persistence:type:DATABASE");
+
+ DEFAULT_TYPE = DATABASE;
+ }
+ catch (Exception ex)
+ {
+ throw new ExceptionInInitializerError(ex.toString());
+ }
+
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBConnectionManager.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBConnectionManager.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBConnectionManager.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.persistence.format.db;
+
+import java.sql.Connection;
+
+import org.jboss.soa.esb.common.Configuration;
+
+import com.mchange.v2.c3p0.ComboPooledDataSource;
+
+
+public class DBConnectionManager {
+
+ private static DBConnectionManager instance =null;
+
+ protected ComboPooledDataSource pooledDS = null;
+
+ private static final Object foo = new Integer(0);
+
+
+ protected DBConnectionManager() {}
+
+ public static DBConnectionManager getInstance() {
+ if (null != instance) {
+ return instance;
+ } synchronized(foo) {
+ if (null != instance)
+ return instance;
+ try {
+ instance = new DBConnectionManager();
+ instance.init();
+ }catch(Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ return instance;
+ }
+
+ }
+
+ private void init() throws Exception{
+ System.out.println("Initializing DBConnectionManager2...");
+ pooledDS = new ComboPooledDataSource();
+
+ pooledDS.setDriverClass(Configuration.getStoreDriver());
+ pooledDS.setJdbcUrl(Configuration.getStoreUrl());
+ pooledDS.setUser(Configuration.getStoreUser());
+ pooledDS.setPassword(Configuration.getStorePwd());
+ pooledDS.setMinPoolSize(Integer.valueOf(Configuration.getStorePoolMinSize()));
+ pooledDS.setInitialPoolSize(Integer.valueOf(Configuration.getStorePoolInitialSize()));
+ pooledDS.setMaxPoolSize(Integer.valueOf(Configuration.getStorePoolMaxSize()));
+ pooledDS.setAutomaticTestTable(Configuration.getStorePoolTestTable());
+ pooledDS.setCheckoutTimeout(Integer.valueOf(Configuration.getStorePoolTimeoutMillis()));
+ }
+
+
+
+ public Connection getConnection() throws Exception{
+
+ Connection conn = null;
+
+ //TODO: figure out why this is neccessary - pool should never return null if DB is up and can connect
+ //testing showed null was being returned from pool in QA test MessageStoreTest
+ while (true)
+ {
+ if (null!=pooledDS)
+ if (null != (conn=pooledDS.getConnection()))
+ break;
+ else
+ System.out.println("Null pooledDS");
+ try { Thread.sleep(1000); }
+ catch(Exception e) {}
+ }
+
+ return conn;
+
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBConnectionManagerDBCP.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBConnectionManagerDBCP.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBConnectionManagerDBCP.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.persistence.format.db;
+
+
+import java.sql.Connection;
+
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.dbcp.ConnectionFactory;
+import org.apache.commons.dbcp.PoolingDataSource;
+import org.apache.commons.dbcp.PoolableConnectionFactory;
+import org.apache.commons.dbcp.DriverManagerConnectionFactory;
+import org.jboss.soa.esb.common.Configuration;
+
+/*
+ * the DBConnectionManager class (singleton) is used by classes implenting the MessageStore interface
+ * to obtain a connection to the persistence store database.
+ * This class uses the Apache Commons DB Connection Pooling to handle all aspects of managing the connections
+ * in a pool.
+ * $author Daniel Brum
+ */
+
+
+public class DBConnectionManagerDBCP {
+
+
+
+ private static DBConnectionManagerDBCP instance =null;
+ private PoolingDataSource dataSource = null;
+
+ protected DBConnectionManagerDBCP() {}
+
+ public static DBConnectionManagerDBCP getInstance() {
+ if (null == instance) {
+ try {
+ instance = new DBConnectionManagerDBCP();
+ instance.init();
+ }catch(Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ return instance;
+ }
+
+ private void init() throws Exception{
+
+ String connectURL = Configuration.getStoreUrl();
+ Class.forName(Configuration.getStoreDriver());
+
+ ObjectPool connectionPool = new GenericObjectPool(null);
+
+ ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURL,
+ Configuration.getStoreUser(), Configuration.getStorePwd());
+
+ @SuppressWarnings("unused")
+
+ PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
+ connectionPool,null,null,false,false);
+
+ int poolSize = Integer.valueOf(Configuration.getStorePoolInitialSize());
+
+ //add the max # of connections into the pool
+ for (int i=0 ; i<poolSize ; i++) {
+ try {
+ connectionPool.addObject();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ dataSource = new PoolingDataSource(connectionPool);
+ }
+
+ public Connection getConnection() throws Exception{
+ return dataSource.getConnection();
+ }
+
+
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBMessageStorePlugin.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBMessageStorePlugin.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/DBMessageStorePlugin.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.persistence.format.db;
+
+import java.net.URI;
+
+import org.jboss.internal.soa.esb.persistence.format.MessageStorePlugin;
+import org.jboss.internal.soa.esb.persistence.format.MessageStoreType;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+
+/**
+ * @author dbrum
+ *
+ */
+public class DBMessageStorePlugin implements MessageStorePlugin {
+
+
+ public MessageStore getMessageStore() {
+ return new MessageStoreImpl();
+ }
+
+
+ public URI getType() {
+ return MessageStoreType.DATABASE;
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/MessageStoreImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/MessageStoreImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/persistence/db/MessageStoreImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.persistence.format.db;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.UUID;
+
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+import org.jboss.soa.esb.util.Util;
+
+
+public class MessageStoreImpl implements MessageStore {
+
+
+ protected DBConnectionManager mgr = null;
+ protected Connection conn = null;
+ protected ResultSet rs = null;
+ protected PreparedStatement ps = null;
+
+ public MessageStoreImpl() {
+ mgr = DBConnectionManager.getInstance();
+ }
+
+ public synchronized URI addMessage(Message message){
+
+// String messageString = null;
+ URI uid = null;
+
+
+ try {
+ conn = mgr.getConnection();
+
+ uid = new URI("urn:jboss:esb:message:UID:" + UUID.randomUUID().toString());
+
+ String messageString = Base64.encodeObject(Util.serialize(message));
+
+// if (message.getType().equals(MessageType.JBOSS_XML) ) {
+// Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+// ((org.jboss.internal.soa.esb.message.format.xml.MessageImpl)message).toXML(doc);
+// StringWriter sWriter = new StringWriter();
+// OutputFormat format = new OutputFormat();
+// format.setIndenting(true);
+// XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+// xmlS.asDOMSerializer();
+// xmlS.serialize(doc);
+// messageString = sWriter.toString();
+// }
+//
+// if (message.getType().equals(MessageType.JAVA_SERIALIZED) ) {
+// messageString = Base64.encodeObject((Serializable)message);
+// }
+
+ //insert into the database
+ String sql = "insert into message(uid, type, message) values(?,?,?)";
+ ps = conn.prepareStatement(sql);
+ ps.setString(1, uid.toString());
+ ps.setString(2, message.getType().toString());
+ ps.setString(3, messageString);
+ ps.execute();
+
+ } catch (Exception e) { e.printStackTrace(); }
+ finally { release(); }
+
+ return uid;
+ }
+
+ public synchronized Message getMessage(URI uid) throws Exception{
+
+ String sql = "select uid,type,message from message where uid=?";
+ Message message = null;
+
+ try {
+ conn = mgr.getConnection();
+ ps = conn.prepareStatement(sql);
+ ps.setString(1, uid.toString());
+
+ rs = ps.executeQuery();
+ if (! rs.next()) throw new Exception("Non existing Message for UID: " + uid);
+// URI type= URI.create(rs.getString(2));
+ message = Util.deserialize((Serializable)Base64.decodeToObject(rs.getString(3)));
+
+
+// if (type.equals(MessageType.JBOSS_XML)) {
+//
+// InputStream inStream = new ByteArrayInputStream(msg.getBytes());
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+// DocumentBuilder builder = factory.newDocumentBuilder();
+// Document doc = builder.parse(inStream);
+//
+// org.jboss.internal.soa.esb.message.format.xml.MessageImpl xmlMessage =
+// new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
+// xmlMessage.fromXML(doc);
+// message=xmlMessage;
+//
+// }
+// if (type.equals(MessageType.JAVA_SERIALIZED)) {
+//
+// Object byteMessage = Base64.decodeToObject(msg);
+// message = (org.jboss.internal.soa.esb.message.format.serialized.MessageImpl)byteMessage;
+// }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return null;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }finally { release(); }
+
+ return message;
+
+ }
+
+ private void release() {
+
+ if (conn != null) {
+ if (rs != null) {
+ try{
+ rs.close();
+ }catch (Exception e) {}
+ }
+ try{
+ ps.close();
+ }catch (Exception e1){}
+ try{
+ conn.close();
+ }catch(Exception e2){}
+ }
+ }
+
+
+
+
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/JAXRRegistryImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/JAXRRegistryImpl.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/JAXRRegistryImpl.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,629 @@
+/*
+* 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.services.registry;
+
+import java.net.PasswordAuthentication;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.xml.registry.BulkResponse;
+import javax.xml.registry.BusinessLifeCycleManager;
+import javax.xml.registry.BusinessQueryManager;
+import javax.xml.registry.Connection;
+import javax.xml.registry.ConnectionFactory;
+import javax.xml.registry.FindQualifier;
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.JAXRResponse;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.EmailAddress;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.PersonName;
+import javax.xml.registry.infomodel.PostalAddress;
+import javax.xml.registry.infomodel.RegistryObject;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.TelephoneNumber;
+import javax.xml.registry.infomodel.User;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.internal.soa.esb.addressing.EPRHelper;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.Configuration;
+/**
+ * Utility class for the Registry.
+ * If need be we can extract the interface from here, add a factory and have JAXR as a plugin, allowing
+ * for other RegistryAPIs.
+ *
+ * @author Kurt Stam
+ */
+public class JAXRRegistryImpl implements Registry
+{
+ private static Logger logger = Logger.getLogger(JAXRRegistryImpl.class);
+ public static Set<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
+ private static Properties props = new Properties();
+ private static Organization jbossESBOrganization;
+
+ private static void init()
+ {
+ props = new Properties();
+ props.setProperty("javax.xml.registry.queryManagerURL", Configuration.getRegistryQueryManageURI());
+ props.setProperty("javax.xml.registry.lifeCycleManagerURL", Configuration.getRegistryLifecycleManagerURI());
+ props.setProperty("javax.xml.registry.factoryClass", Configuration.getRegistryFactoryClass());
+ props.setProperty("scout.proxy.transportClass", Configuration.getRegistryScoutTransportClass());
+ String user = Configuration.getRegistryUser();
+ String password = Configuration.getRegistryPassword();
+ PasswordAuthentication passwdAuth = new PasswordAuthentication(user, password.toCharArray());
+ creds.add(passwdAuth);
+ }
+
+ /**
+ * Creates a connecton to a JAXR capable registy.
+ *
+ * @return Connection to a Registry using JAXR.
+ */
+ protected static Connection getConnection()
+ {
+ Connection connection = null;
+ init();
+ try
+ { // Create the connection, passing it the configuration properties
+ ConnectionFactory factory = ConnectionFactory.newInstance();
+ factory.setProperties(props);
+ connection = factory.createConnection();
+ } catch (JAXRException e) {
+ logger.log(Priority.ERROR, "Could not set up a connection to the Registry. " + e.getMessage(), e);
+ }
+ return connection;
+ }
+ /**
+ * Closes the connection to the Registry
+ */
+ protected static void closeConnection(Connection connection)
+ {
+ try {
+ if (connection!=null && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (JAXRException je) {
+ logger.log(Priority.ERROR, je.getMessage(), je);
+ }
+ }
+ /**
+ * Publish an EPR to the Registry
+ */
+ protected Service registerService(String category, String serviceName, String serviceDescription) throws JAXRException
+ {
+ Service service =null;
+ Organization organization = getJBossESBOrganization();
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ connection.setCredentials(JAXRRegistryImpl.creds);
+ RegistryService rs = connection.getRegistryService();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ //Adding the category as prefix for the name
+ service = blm.createService(blm.createInternationalString(category + ":" + serviceName));
+ service.setDescription(blm.createInternationalString(serviceDescription));
+// ClassificationScheme cScheme = getClassificationScheme(blm, "uddi-org:general_keywords", "");
+// Classification classification = blm.createClassification(cScheme, "JBossESB" + category, category);
+// service.addClassification(classification);
+ organization.addService(service);
+ saveRegistryObject(service);
+ } finally {
+ closeConnection(connection);
+ }
+ return service;
+ }
+ /**
+ * Remove an EPR from the Registry
+ */
+ public void unRegisterService(String category, String serviceName) throws RegistryException{
+ try {
+ Organization organization = getJBossESBOrganization();
+ for (Iterator i=organization.getServices().iterator(); i.hasNext();) {
+ Service service = (Service) i.next();
+ if (service.getName().getValue().equals(category + ":" + serviceName)) {
+ organization.removeService(service);
+ saveRegistryObject(organization);
+ return;
+ }
+ }
+ } catch (JAXRException je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
+ }
+ /**
+ * Publish an EPR to the Registry
+ */
+ public void registerEPR(String category, String serviceName, String serviceDescription, EPR epr, String eprDescription)
+ throws RegistryException
+ {
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ //Find the service
+ Service service = findService(category,serviceName);
+ if (service==null) {
+ logger.log(Priority.INFO, "Service " + serviceName + " does not yet exist, creating now..");
+ service = registerService(category, serviceName, serviceDescription);
+ }
+ connection.setCredentials(JAXRRegistryImpl.creds);
+ RegistryService rs = connection.getRegistryService();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+// BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ ServiceBinding serviceBinding = blm.createServiceBinding();
+ serviceBinding.setDescription(blm.createInternationalString(eprDescription));
+ String xml = EPRHelper.toXMLString(epr);
+ serviceBinding.setAccessURI(URLEncoder.encode(xml,"UTF-8"));
+
+// The following code would store the EPR xml as an ExtrinsicObject, but scout does not
+// have an implementation for it.
+// DataHandler repositoryItem = new DataHandler(xml,"text/xml");
+// ExtrinsicObject eo = blm.createExtrinsicObject(repositoryItem);
+// eo.setName(blm.createInternationalString("EPR"));
+// eo.setMimeType("text/xml");
+// String conceptId = "urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject:ExtrinsicObject:XML";
+// Concept objectTypeConcept = (Concept) bqm.getRegistryObject(conceptId);
+// ((ExtrinsicObjectImpl)eo).setObjectType(objectTypeConcept);
+
+// Concept specConcept = blm.createConcept(null, "HelloConcept", "");
+// String schemeName = "uddi-org:types";
+// ClassificationScheme uddiOrgTypes =
+// bqm.findClassificationSchemeByName(null, schemeName);
+// Classification wsdlSpecClassification =
+// blm.createClassification(uddiOrgTypes,
+// "eprSpec", xml);
+// specConcept.addClassification(wsdlSpecClassification);
+// Collection<Concept> concepts = new ArrayList<Concept>();
+// concepts.add(specConcept);
+// BulkResponse br=blm.saveConcepts(concepts);
+// Key conceptKey = null;
+// if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
+// Collection keys = br.getCollection();
+// for (Iterator i=keys.iterator();i.hasNext();){
+// conceptKey = (Key) i.next();
+// break;
+// }
+// } else {
+// throw new RegistryException("Could not save the EPR as Concept");
+// }
+// //now adding this concept to the binding
+// Concept specificationConcept = (Concept) bqm.getRegistryObject(conceptKey.getId(), LifeCycleManager.CONCEPT);
+// SpecificationLink specificationLink = blm.createSpecificationLink();
+// specificationLink.setSpecificationObject(specificationConcept);
+// serviceBinding.addSpecificationLink(specificationLink);
+
+ ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
+ serviceBindings.add(serviceBinding);
+ service.addServiceBindings(serviceBindings);
+ saveRegistryObject(serviceBinding);
+ } catch (Exception je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ * Remove an EPR from the Registry
+ */
+ public void unRegisterEPR(String category, String serviceName, EPR toBeDeletedEPR) throws RegistryException{
+ //first find the ServiceBindings for this service
+ try {
+ Service service = findService(category, serviceName);
+ Collection<ServiceBinding> serviceBindings = findServiceBindings(service);
+ for (Iterator i=serviceBindings.iterator();i.hasNext();){
+ ServiceBinding serviceBinding = (ServiceBinding) i.next();
+ String xml = URLDecoder.decode(serviceBinding.getAccessURI(), "UTF-8");
+ if (xml.equals(EPRHelper.toXMLString(toBeDeletedEPR))) {
+ service.removeServiceBinding(serviceBinding);
+ service.setProvidingOrganization(getJBossESBOrganization());
+ saveRegistryObject(service);
+ return;
+ }
+ }
+ //We should not end up here or else we did not match any EPRs
+ throw new RegistryException("No such EPR found for service with name = "
+ + serviceName + " and EPR=" + toBeDeletedEPR);
+ } catch (Exception je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ * @return collection services
+ */
+ public Collection<String> findAllServices() throws RegistryException
+ {
+ Collection<String> serviceNames = new ArrayList<String>();
+ try {
+ Collection services = getJBossESBOrganization().getServices();
+ for (Iterator i=services.iterator();i.hasNext();) {
+ String serviceName = ((Service)i.next()).getName().getValue();
+ serviceNames.add(serviceName);
+ }
+ } catch (JAXRException je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
+ return serviceNames;
+ }
+ /**
+ * Find Services based on a category ("transformation").
+ *
+ * @param serviceType
+ * @return collection services
+ */
+ public Collection<String> findServices(String category) throws RegistryException
+ {
+ Collection<String>serviceNames = new ArrayList<String>();
+ try {
+ Collection<Service>services = findServicesForCategory(category);
+ for (Iterator<Service> i=services.iterator();i.hasNext();) {
+ String serviceName = i.next().getName().getValue();
+ serviceNames.add(serviceName);
+ }
+ } catch (JAXRException je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
+ return serviceNames;
+ }
+ /**
+ *
+ * @param service
+ * @return
+ */
+ public Collection<EPR> findEPRs(String category, String serviceName) throws RegistryException
+ {
+ Collection<EPR> eprs = new ArrayList<EPR>();
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ Service service = findService(category, serviceName);
+ // Get registry service and business query manager
+ Collection<ServiceBinding> serviceBindings = findServiceBindings(service);
+ //Converting them to EPRs
+ for (Iterator i=serviceBindings.iterator();i.hasNext();) {
+ ServiceBinding serviceBinding = (ServiceBinding) i.next();
+ @SuppressWarnings("unused")
+ String eprXML = URLDecoder.decode(serviceBinding.getAccessURI(),"UTF-8");
+ //TODO use the XML to generate the EPR
+ EPR epr = EPRHelper.fromXMLString(eprXML);
+ eprs.add(epr);
+ }
+ } catch (Exception je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ } finally {
+ closeConnection(connection);
+ }
+ return eprs;
+ }
+ /**
+ * Find all Organizations with a name mathing the queryString parameter.
+ *
+ * @param organizationName used to match with the name of the organization.
+ * @return the Organization.
+ */
+ protected static Organization findOrganization(String organizationName) throws JAXRException
+ {
+ if (organizationName==null) {
+ organizationName="";
+ }
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ // Define find qualifiers and name patterns
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
+ Collection<String> namePatterns = new ArrayList<String>();
+ namePatterns.add("%" + organizationName + "%");
+ //Find based upon qualifier type and values
+ System.out.println("Going to query the registry for name pattern " + namePatterns);
+ BulkResponse response = bqm.findOrganizations(findQualifiers,
+ namePatterns, null, null, null, null);
+ if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
+ for (Iterator orgIter = response.getCollection().iterator(); orgIter.hasNext();)
+ {
+ Organization org = (Organization) orgIter.next();
+ logger.log(Priority.INFO, "Organization name: " + org.getName().getValue());
+ logger.log(Priority.INFO, "Description: " + org.getDescription().getValue());
+ logger.log(Priority.INFO, "Key id: " + org.getKey().getId());
+ User primaryContact = org.getPrimaryContact();
+ logger.log(Priority.INFO, "Primary Contact: " + primaryContact.getPersonName().getFullName());
+ if (orgIter.hasNext()) {
+ logger.log(Priority.ERROR, "Found " + response.getCollection().size()
+ + " Organization, while expecting only one of name " + organizationName);
+ }
+ return org;
+ }
+ }
+ return null;
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ *
+ * @param category
+ * @param serviceName
+ * @return Service
+ */
+ protected static Service findService(String category, String serviceName) throws JAXRException
+ {
+ if (category==null) {
+ category="";
+ }
+ if (serviceName==null) {
+ serviceName="";
+ }
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ // Define find qualifiers and name patterns
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.AND_ALL_KEYS);
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
+ Collection<String> namePatterns = new ArrayList<String>();
+ namePatterns.add("%" + category + "%");
+ namePatterns.add("%" + serviceName + "%");
+ //Find based upon qualifier type and values
+ logger.log(Priority.DEBUG, "Going to query the registry for name pattern " + namePatterns);
+ BulkResponse response = bqm.findServices(null, findQualifiers,
+ namePatterns, null, null);
+ if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
+ for (Iterator servIter = response.getCollection().iterator(); servIter.hasNext();)
+ {
+ Service service = (Service) servIter.next();
+ logger.log(Priority.INFO, "Service name: " + service.getName().getValue());
+ if (service.getDescription()!=null) {
+ logger.log(Priority.INFO, "Description: " + service.getDescription().getValue());
+ }
+ logger.log(Priority.INFO, "Key id: " + service.getKey().getId());
+ if (servIter.hasNext()) {
+ logger.log(Priority.ERROR, "Found " + response.getCollection().size()
+ + " Services, while expecting only one by the name of "
+ + serviceName + " in category " + category);
+ }
+ return service;
+ }
+ }
+ return null;
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ * Finds all services for a given category.
+ * @param category
+ * @param serviceName
+ * @return Service
+ */
+ @SuppressWarnings("unchecked")
+ protected static Collection<Service> findServicesForCategory(String category) throws JAXRException
+ {
+ Collection<Service> services = new ArrayList<Service>();
+ if (category==null) {
+ category="";
+ }
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ // Define find qualifiers and name patterns
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.AND_ALL_KEYS);
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
+ Collection<String> namePatterns = new ArrayList<String>();
+ namePatterns.add("%" + category + "%");
+ //Find based upon qualifier type and values
+ logger.log(Priority.DEBUG, "Going to query the registry for name pattern " + namePatterns);
+ BulkResponse response = bqm.findServices(null, findQualifiers,
+ namePatterns, null, null);
+ if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
+ services = response.getCollection();
+ }
+ return services;
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ * Create a jbossesb organization under which we will register all our services.
+ *
+ * @param blm
+ * @return
+ * @throws JAXRException
+ */
+ protected static Organization createJBossESBOrganization()
+ throws JAXRException
+ {
+// Getting the connection to the Registry (reading config)
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ //Logging in
+ connection.setCredentials(JAXRRegistryImpl.creds);
+ RegistryService rs = connection.getRegistryService();
+ //Building organization
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ Organization organization = blm.createOrganization(blm.createInternationalString("Red Hat/JBossESB"));
+ organization.setDescription(blm.createInternationalString("Red Hat/JBoss Professional Open Source, Services for the JBossESB"));
+
+ User user = blm.createUser();
+ organization.setPrimaryContact(user);
+ PersonName personName = blm.createPersonName("JBossESB");
+ TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
+ telephoneNumber.setNumber("404 467-8555");
+ telephoneNumber.setType(null);
+ PostalAddress address = blm.createPostalAddress("3340",
+ "Peachtree Road, NE, Suite 1200", "Atlanta", "GA", "USA",
+ "30326", "");
+ Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
+ postalAddresses.add(address);
+ Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
+ EmailAddress emailAddress = blm
+ .createEmailAddress("jbossesb at jboss.com");
+ emailAddresses.add(emailAddress);
+
+ Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
+ numbers.add(telephoneNumber);
+ user.setPersonName(personName);
+ user.setPostalAddresses(postalAddresses);
+ user.setEmailAddresses(emailAddresses);
+ user.setTelephoneNumbers(numbers);
+
+ // Scout does not support this (yet), so leaving it out for now.
+ // ClassificationScheme cScheme = getClassificationScheme(blm,
+ // blm.createInternationalString("uddi-org:general_keywords"), blm.createInternationalString(""));
+ // Classification classification = blm.createClassification(cScheme,
+ // blm..createInternationalString("JBoss ESB"), blm..createInternationalString("JBESB"));
+ // org.addClassification(classification);
+
+ saveRegistryObject(organization);
+ return organization;
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ * Save Registry Object
+ */
+ protected static void saveRegistryObject(RegistryObject registryObject) throws JAXRException
+ {
+// Getting the connection to the Registry (reading config)
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ Collection<RegistryObject> registryObjects = new ArrayList<RegistryObject>();
+ BulkResponse br = null;
+ //Logging in
+ connection.setCredentials(JAXRRegistryImpl.creds);
+ RegistryService rs = connection.getRegistryService();
+ //Building organization
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ registryObjects.add(registryObject);
+ Class[] interfaces = registryObject.getClass().getInterfaces();
+ String interfaceName ="";
+ for (int i=0; i<interfaces.length; i++) {
+ interfaceName = interfaces[i].getName();
+ if (interfaceName.equals("javax.xml.registry.infomodel.Organization")) {
+ br = blm.saveOrganizations(registryObjects);
+ break;
+ } else if (interfaceName.equals("javax.xml.registry.infomodel.Service")) {
+ br = blm.saveServices(registryObjects);
+ break;
+ } else if (interfaceName.equals("javax.xml.registry.infomodel.ServiceBinding")) {
+ br = blm.saveServiceBindings(registryObjects);
+ break;
+ } else {
+ logger.log(Priority.ERROR, "Trying to save an unsupported RegistryObject");
+ throw new JAXRException("Trying to save an unsupported RegistryObject");
+ }
+ }
+ //Verify the return
+ if (br!=null && br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
+ logger.log(Priority.INFO, interfaceName + " successfully saved");
+ Collection coll = br.getCollection();
+ Iterator iter = coll.iterator();
+ while (iter.hasNext()) {
+ Key key = (Key) iter.next();
+ registryObject.setKey(key);
+ logger.log(Priority.INFO, "Saved Key=" + key.getId());
+ }
+ } else {
+ logger.log(Priority.ERROR, "Errors occurred during save.");
+ if (br!=null) {
+ Collection exceptions = br.getExceptions();
+ Iterator iter = exceptions.iterator();
+ String errors = "";
+ JAXRException je = new JAXRException("JAXRExceptions occurred during save");
+ while (iter.hasNext()) {
+ Exception e = (Exception) iter.next();
+ errors += e.getLocalizedMessage() + "\n";
+ je.setStackTrace(e.getStackTrace());
+ logger.log(Priority.ERROR, e.getLocalizedMessage(), e);
+ //if it's the last error, throw it now and set the current stacktrace
+ if (!iter.hasNext()) {
+ throw new JAXRException(errors, e);
+ }
+ }
+ throw new JAXRException("Errors occurred during save. Response status=" + br.getStatus());
+ }
+ throw new JAXRException("Errors occurred during save");
+ }
+ } finally {
+ JAXRRegistryImpl.closeConnection(connection);
+ }
+ }
+ /**
+ * finds the JBossESB Organizationa and creates one if it is not there.
+ * @return JBossESB Organization
+ * @throws JAXRException
+ */
+ private Organization getJBossESBOrganization() throws JAXRException
+ {
+ if (jbossESBOrganization==null) {
+ jbossESBOrganization = findOrganization("Red Hat/JBossESB");
+ if (jbossESBOrganization==null) {
+ jbossESBOrganization = createJBossESBOrganization();
+ }
+ }
+ return jbossESBOrganization;
+ }
+ /**
+ * Find the ServiceBindings for a given Service
+ * @param service
+ * @return
+ * @throws RegistryException
+ */
+ @SuppressWarnings("unchecked")
+ private Collection<ServiceBinding> findServiceBindings(Service service) throws RegistryException
+ {
+ Collection<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
+ BulkResponse bulkResponse = bqm.findServiceBindings(service.getKey(),findQualifiers,null,null);
+ if (bulkResponse.getStatus()==JAXRResponse.STATUS_SUCCESS){
+ serviceBindings = bulkResponse.getCollection();
+ }
+ return serviceBindings;
+ } catch (Exception je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ } finally {
+ closeConnection(connection);
+ }
+ }
+
+}
+
+
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,87 @@
+/*
+* 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.services.registry;
+
+import java.util.Collection;
+
+import org.jboss.soa.esb.addressing.EPR;
+/**
+ * Registry interface for the ESB.
+ *
+ * @author Kurt Stam
+ */
+interface Registry
+{
+ /**
+ * Removes a service from the Registry along with all the ServiceBindings underneath it.
+ *
+ * @param category - name of the service category, for example 'transformation'.
+ * @param serviceName - name of the service, for example 'smooks'.
+ * @throws RegistryException
+ */
+ public void unRegisterService(String category, String serviceName) throws RegistryException;
+ /**
+ * Registers an EPR under the specified category and service. If the specified service does
+ * not exist, it will be created at the same time.
+ *
+ * @param category - name of the category to which the service belongs.
+ * @param serviceName - name of the service to which the EPS belongs.
+ * @param serviceDescription - human readable description of the service,
+ * only used when it the service does not yet exist.
+ * @param epr - the EndPointReference (EPR) that needs to be registered.
+ * @param eprDescription - human readable description of the EPR
+ * @throws RegistryException
+ */
+ public void registerEPR(String category, String serviceName, String serviceDescription, EPR epr, String eprDescription)
+ throws RegistryException;
+ /**
+ * Removes an EPR from the Registry.
+ * @param category - name of the category to which the service belongs.
+ * @param serviceName - name of the service to which the EPS belongs.
+ * @param epr - the EndPointReference (EPR) that needs to be unregistered.
+ * @throws RegistryException
+ */
+ public void unRegisterEPR(String category, String serviceName, EPR epr) throws RegistryException;
+ /**
+ * Find all Services assigned to the Red Hat/JBossESB organization.
+ * @return Collection of Strings containing the service names.
+ * @throws RegistryException
+ */
+ public Collection<String> findAllServices() throws RegistryException;
+ /**
+ * Find all services that belong to the supplied category.
+ *
+ * @param category - name of the category to which the service belongs.
+ * @return Collection of Strings containing the service names
+ * @throws RegistryException
+ */
+ public Collection<String> findServices(String category) throws RegistryException;
+ /**
+ * Finds all the EPRs that belong to a specific category and service combination.
+ *
+ * @param category - name of the category to which the service belongs.
+ * @param serviceName - name of the service to which the EPS belongs.
+ * @return Collection of EPRs.
+ * @throws RegistryException
+ */
+ public Collection<EPR> findEPRs(String category, String serviceName) throws RegistryException;
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryException.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryException.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryException.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,29 @@
+/*
+ * Created on Jul 15, 2004
+ *
+ */
+package org.jboss.soa.esb.services.registry;
+
+/**
+ * @author gerry
+ *
+ * <p>Created: Jul 15, 2004</p>
+ */
+public class RegistryException extends Exception {
+ private static final long serialVersionUID = 1L;
+ public final static String STORE = "Failed to store. ";
+ public final static String DELETE = "Failed to delete. ";
+ public final static String FETCH = "Failed to fetch. ";
+
+ public RegistryException(){
+ super();
+ }
+
+ public RegistryException (String msg){
+ super(msg);
+ }
+
+ public RegistryException (String msg, Throwable cause){
+ super (msg, cause);
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryFactory.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryFactory.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/soa/esb/services/registry/RegistryFactory.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,75 @@
+/*
+* 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.services.registry;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.common.Configuration;
+/**
+ * Returns an Instance of the Registry.
+ * @author kstam
+ *
+ */
+public class RegistryFactory
+{
+ private static Logger logger = Logger.getLogger(RegistryFactory.class);
+
+ public static Registry getRegistry() {
+ Registry registry = null;
+ String className = Configuration.getRegistryImplementationClass();
+ try {
+ // instruct class loader to load the TransportFactory
+ Class registryClass = getClassForName(className);
+ // Try to instance the Registry
+ registry = (Registry) registryClass.newInstance();
+ } catch (ClassNotFoundException cnfex) {
+ cnfex.printStackTrace();
+ } catch (java.lang.Exception ex) {
+ ex.printStackTrace();
+ }
+ return registry;
+ }
+
+ /**
+ * Loads the class with the given name.
+ * @param className - the className to be found
+ * @return - the class
+ * @throws ClassNotFoundException
+ */
+ private static Class getClassForName(String className) throws ClassNotFoundException
+ {
+ Class clazz = null;
+ try {
+ logger.log(Priority.DEBUG, "Using the Context ClassLoader");
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ clazz = Class.forName(className, true, contextClassLoader);
+ } catch (ClassNotFoundException classNotFound) {
+ if (logger.isDebugEnabled()) {
+ logger.log(Priority.WARN, "The Contect ClassLoader could not find the class.");
+ logger.log(Priority.WARN, "Using the System ClassLoader");
+ }
+ ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+ clazz = Class.forName(className, true, systemClassLoader);
+ }
+ return clazz;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/application.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/application.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/application.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<application version="1.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
+ <display-name>JbossEsb AppServer basic services</display-name>
+ <module>
+ <ejb>jbossesb-instr-all.jar</ejb>
+ </module>
+ <module>
+ <java>jbossts-common.jar</java>
+ </module>
+</application>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/build.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/build.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/build.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,133 @@
+<?xml version="1.0"?>
+<project name="build.services.tests" default="org.jboss.esb.services.tests.compile" basedir=".">
+
+ <property file="../../../../install/deployment.properties"/>
+
+ <property name="org.jboss.esb.internal.dest" value="${basedir}/../../../build"/>
+
+ <property name="org.jboss.esb.module.src.dir" value="../src"/>
+ <property name="org.jboss.esb.module.classes.dir" value="${org.jboss.esb.internal.dest}/classes/services"/>
+ <property name="org.jboss.esb.module.tests.src.dir" value="${basedir}/src"/>
+ <property name="org.jboss.esb.tests.classes.dir" value="${org.jboss.esb.internal.dest}/tests"/>
+ <property name="org.jboss.esb.tests.report.dir" value="${org.jboss.esb.internal.dest}/tests/junit"/>
+ <property name="org.jboss.esb.root.dir" value="../.."/>
+
+ <property environment="env"/>
+
+ <property name="org.jboss.esb.ext.lib.dir" value="${org.jboss.esb.root.dir}/lib/ext"/>
+ <property name="org.jboss.esb.ejb3_embedded.lib.dir" value="${org.jboss.esb.root.dir}/../lib/ext/ejb3_embedded"/>
+ <property name="org.jboss.esb.ejb3_conf.tests.src.dir" value="${org.jboss.esb.root.dir}/rosetta/tests/resources/conf"/>
+ <condition property="org.jboss.esb.ext.lib.dir" value="{org.jboss.esb.jboss.home}/client">
+ <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
+ </condition>
+
+ <path id="org.jboss.esb.tests.base.classpath">
+ <fileset dir="../${org.jboss.esb.ext.lib.dir}"
+ includes="*.jar" excludes="jbossall-client.jar"/>
+ <pathelement location="${org.jboss.esb.module.classes.dir}"/>
+ <pathelement location="${org.jboss.esb.internal.dest}/classes/rosetta"/>
+ <pathelement location="${org.jboss.esb.ejb3_conf.tests.src.dir}"/>
+ <fileset dir="${org.jboss.esb.ejb3_embedded.lib.dir}" includes="*.jar"/>
+ </path>
+
+ <target name="org.jboss.esb.tests.init">
+ <tstamp>
+ <format property="TODAY" pattern="dd-MM-yy"/>
+ </tstamp>
+
+ <mkdir dir="${org.jboss.esb.tests.classes.dir}"/>
+ <mkdir dir="${org.jboss.esb.tests.report.dir}"/>
+ </target>
+
+ <target name="clean"/>
+
+ <target name="purge" depends="clean">
+ <delete dir="${org.jboss.esb.tests.classes.dir}"/>
+ </target>
+
+ <target name="org.jboss.esb.services.tests.compile" if="org.jboss.esb.buildtests" depends="org.jboss.esb.tests.init">
+
+ <javac
+ destdir="${org.jboss.esb.tests.classes.dir}"
+ classpathref="org.jboss.esb.tests.base.classpath"
+ debug="${org.jboss.esb.debug}"
+ optimize="${org.jboss.esb.optimize}"
+ >
+ <src path="${org.jboss.esb.module.tests.src.dir}"/>
+ </javac>
+
+ </target>
+
+ <!-- ====================================================================== -->
+ <!-- T E S T -->
+ <!-- ====================================================================== -->
+ <target name="org.jboss.esb.services.internal.test">
+ <property name="org.jboss.esb.module.tests.coverage.dir" value="${org.jboss.esb.internal.dest}/tests/coverage/services"/>
+ <property name="org.jboss.esb.module.classes.instr.dir" value="${org.jboss.esb.module.tests.coverage.dir}/instr" />
+
+ <delete dir="${org.jboss.esb.module.tests.coverage.dir}" />
+ <mkdir dir="${org.jboss.esb.module.tests.coverage.dir}" />
+ <emma>
+ <instr instrpath="${org.jboss.esb.module.classes.dir}"
+ destdir="${org.jboss.esb.module.classes.instr.dir}"
+ metadatafile="${org.jboss.esb.module.tests.coverage.dir}/coverage.emma" />
+ </emma>
+
+ <!-- Run the tests -->
+ <antcall target="org.jboss.esb.services.internal.test.exec"/>
+
+ <!-- Generate the coverage report -->
+ <emma>
+ <report sourcepath="${org.jboss.esb.module.src.dir}" sort="+block,+name,+method,+class" metrics="method:70,block:80,line:80,class:100">
+ <fileset dir="${org.jboss.esb.module.tests.coverage.dir}" >
+ <include name="*.emma" />
+ </fileset>
+ <html outfile="${org.jboss.esb.module.tests.coverage.dir}/index.html" depth="method" columns="name,line,class,method,block"/>
+ </report>
+ </emma>
+
+ </target>
+
+ <!-- ====================================================================== -->
+ <!-- U N I T A N D F U N C T I O N A L T E S T S -->
+ <!-- ====================================================================== -->
+ <target name="org.jboss.esb.services.internal.test.exec">
+ <echo message="Running tests for module"/>
+ <junit printsummary="yes" haltonerror="yes" haltonfailure="yes" showoutput="no" fork="true">
+ <formatter type="plain" usefile="false"/>
+ <formatter type="xml"/>
+ <batchtest todir="${org.jboss.esb.tests.report.dir}">
+ <fileset dir="${org.jboss.esb.module.tests.src.dir}">
+ <include name="**/**UnitTest.java"/>
+ <include name="**/**FuncTest.java"/>
+ </fileset>
+ </batchtest>
+ <classpath>
+ <!-- using instrumented code for code coverage -->
+ <pathelement location="${org.jboss.esb.module.classes.instr.dir}"/>
+ <pathelement location="${org.jboss.esb.tests.classes.dir}"/>
+ <!-- Need the tests src folder because there may be non-compiled test resources -->
+ <pathelement location="${org.jboss.esb.module.tests.src.dir}"/>
+ <path refid="org.jboss.esb.tests.base.classpath"/>
+
+ </classpath>
+ <!-- emma jvm args -->
+ <jvmarg value="-Demma.coverage.out.file=${org.jboss.esb.module.tests.coverage.dir}/coverage.emma" />
+ <jvmarg value="-Demma.coverage.out.merge=true" />
+ <!-- setting system properties -->
+ <sysproperty key="org.jboss.esb.db.driver" value="${org.jboss.esb.db.driver}"/>
+ <sysproperty key="org.jboss.esb.db.url" value="${org.jboss.esb.db.url}"/>
+ <sysproperty key="org.jboss.esb.db.user" value="${org.jboss.esb.db.user}"/>
+ <sysproperty key="org.jboss.esb.db.password" value="${org.jboss.esb.db.password}"/>
+ <sysproperty key="log4j.configuration" value="log4j.xml"/>
+
+ </junit>
+ <junitreport>
+ <fileset dir="${org.jboss.esb.tests.report.dir}">
+ <include name="*.xml"/>
+ </fileset>
+ <report format="frames" todir="${org.jboss.esb.tests.report.dir}"/>
+ <report format="noframes" todir="${org.jboss.esb.tests.report.dir}"/>
+ </junitreport>
+ </target>
+</project>
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,202 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.soa.esb.esb.persistence.tests;
+
+/**
+ * @author dbrum
+ *
+ *
+ */
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.Statement;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.persistence.format.MessageStoreType;
+import org.jboss.internal.soa.esb.persistence.format.db.DBConnectionManager;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.tests.HsqldbUtil;
+import org.jboss.soa.esb.common.tests.TestUtil;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+import org.jboss.soa.esb.services.persistence.MessageStoreFactory;
+import org.junit.Test;
+
+
+public class MessageStoreUnitTest extends TestCase{
+
+// private static Logger log = Logger.getLogger(MessageStoreUnitTest.class);
+
+ @Test
+ public void testDefaultMessageStore() {
+ TestUtil.setESBPropertiesFileToUse();
+ MessageStoreUnitTest.runBeforeAllTests();
+ MessageStore store = MessageStoreFactory.getInstance().getMessageStore();
+ assertEquals((store != null), true);
+ MessageStoreUnitTest.runAfterAllTests();
+ }
+
+ @Test
+ public void testURIMessageStore() {
+ TestUtil.setESBPropertiesFileToUse();
+
+ //only DB supported for now
+ MessageStoreUnitTest.runBeforeAllTests();
+ MessageStore store1 = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+ assertEquals((store1 != null), true);
+ MessageStoreUnitTest.runAfterAllTests();
+ }
+
+ @Test
+ public void testStoreAndRetrieve() {
+ TestUtil.setESBPropertiesFileToUse();
+ MessageStoreUnitTest.runBeforeAllTests();
+
+ //add new messages
+ Message msg1 = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+ Message msg2 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ assertEquals((msg1 != null), true);
+ assertEquals((msg2 != null), true);
+
+ MessageStore store = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+ assertEquals((store != null), true);
+
+ //set some properties inside the Message
+ msg1.getProperties().setProperty("prop1", "val1");
+ msg2.getProperties().setProperty("prop1", "val1");
+ msg1.getProperties().setProperty("prop2", "val2");
+ msg2.getProperties().setProperty("prop2", "val2");
+
+ //set the body inside the Message
+ msg1.getBody().setContents(("TEST BODY").getBytes());
+ msg2.getBody().setContents(("TEST BODY").getBytes());
+
+ //set some object attachments inside the Message
+ msg1.getAttachment().addItem(new String("TEST ATTACHMENT1"));
+ msg1.getAttachment().addItem(new String("TEST ATTACHMENT2"));
+ msg2.getAttachment().addItem(new String("TEST ATTACHMENT1"));
+ msg2.getAttachment().addItem(new String("TEST ATTACHMENT2"));
+
+ //keep track of the UID to use in retrieving the Message
+ URI uid1=null;
+ uid1 = store.addMessage(msg1);
+ System.out.println(uid1);
+ assertEquals((uid1 != null), true);
+
+ URI uid2 = null;
+ uid2 = store.addMessage(msg2);
+ System.out.println(uid2);
+ assertEquals((uid2 != null), true);
+
+ //now retrieve the messages
+ try {
+ Message msgIn1 = store.getMessage(uid1);
+ assertEquals((msgIn1 != null), true);
+
+ Message msgIn2 = store.getMessage(uid2);
+ assertEquals((msgIn2 != null), true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ MessageStoreUnitTest.runAfterAllTests();
+ }
+
+ @Test
+ public void testDBConnectionManager() {
+ TestUtil.setESBPropertiesFileToUse();
+ MessageStoreUnitTest.runBeforeAllTests();
+ MessageStore store = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+ assertEquals((store != null), true);
+ DBConnectionManager mgr = DBConnectionManager.getInstance();
+ assertEquals((mgr != null), true);
+ MessageStoreUnitTest.runAfterAllTests();
+ }
+
+
+ private static void runBeforeAllTests() {
+ TestUtil.setESBPropertiesFileToUse();
+ try {
+ if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
+ HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "jbossesb");
+ //Get the registry-schema create scripts
+ String database = "hsqldb";
+ String sqlDir = TestUtil.getPrefix() + "install/message-store/sql/" + database + "/";
+ //Drop what is there now, if exists. We want to start fresh.
+ String sqlCreateCmd = MessageStoreUnitTest.readTextFile(new File(sqlDir + "create_database.sql"));
+ String sqlDropCmd = MessageStoreUnitTest.readTextFile(new File(sqlDir + "drop_database.sql"));
+
+ DBConnectionManager mgr = DBConnectionManager.getInstance();
+ Connection con = mgr.getConnection();
+ Statement stmnt = con.createStatement();
+ System.out.println("Dropping the schema if exist");
+ stmnt.execute(sqlDropCmd);
+ System.out.println("Creating the message store schema");
+ stmnt.execute(sqlCreateCmd);
+ }
+ } catch (Exception e) { //
+ e.printStackTrace();
+ System.out.println("We should stop testing, since we don't have a db.");
+ assertTrue(false);
+ }
+ }
+
+ private static void runAfterAllTests() {
+ try {
+ if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver"))
+ HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
+ Configuration.getStoreUser(),Configuration.getStorePwd() );
+ } catch (Exception e) { //
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Read the file into a String.
+ * @param file - the file to be read
+ * @return String with the content of the file
+ * @throws IOException - when we can't read the file
+ */
+ public static String readTextFile(File file) throws IOException
+ {
+ StringBuffer sb = new StringBuffer(1024);
+ BufferedReader reader = new BufferedReader(new FileReader(file.getPath()));
+ char[] chars = new char[1];
+ while( (reader.read(chars)) > -1){
+ sb.append(String.valueOf(chars));
+ chars = new char[1];
+ }
+ reader.close();
+ return sb.toString();
+ }
+
+
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/BobjStoreUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/BobjStoreUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/BobjStoreUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,113 @@
+/*
+ * 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.internal.core.objectstore;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.xml.sax.SAXException;
+
+/**
+ * BobjStore unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class BobjStoreUnitTest extends BaseTest {
+
+ protected void tearDown() throws Exception {
+ setObjStoreConfigFile(null);
+ }
+
+ public void test_readConfiguration_invalidconfig() throws MalformedURLException, IOException, SAXException {
+ // Test URI not set
+ test_invalidURI(null);
+ // Test for no scheme in URI...
+ test_invalidURI("/nonexistent/classpath/location/config.xml");
+ // Test for no path in URI...
+ test_invalidURI("file:");
+ // Test non existent classpath URI path...
+ test_invalidURI("classpath:/nonexistent/classpath/location/config.xml");
+ // Test non existent http URI path...
+ test_invalidURI("http://nonexistent/classpath/location/config.xml");
+ // Test non existent file URI path...
+ test_invalidURI("file:/nonexistent/classpath/location/config.xml");
+ }
+
+ private void test_invalidURI(String uri) throws IOException, MalformedURLException, SAXException {
+ setObjStoreConfigFile("/nonexistent/classpath/location/config.xml");
+ try {
+ BobjStore.readConfiguration();
+ fail("expected IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ }
+
+ public void test_readConfiguration_validconfig() throws MalformedURLException, IOException, SAXException {
+ String resPath = getResourceClasspath("BobjStoreUnitTest_config1.xml");
+ ConfigTree config1, config2;
+
+ // Test a read from a valid classpath resource...
+ setObjStoreConfigFile("classpath:" + resPath);
+ config1 = BobjStore.readConfiguration();
+
+ // Test a read from a valid file resource...
+ String baseDir = System.getProperty("user.dir");
+ String fileStr = "core/services/tests/src" + resPath;
+ //Fix for running the tests in eclipse
+ if (!baseDir.endsWith("product")) {
+ fileStr = "product/" + fileStr;
+ }
+ File file = new File(fileStr);
+ setObjStoreConfigFile(file.toURI().toString());
+ config2 = BobjStore.readConfiguration();
+ assertEquals(config1.toString(), config2.toString());
+ }
+
+ public void test_BobjStore() throws MalformedURLException, IOException, SAXException {
+ setObjStoreConfigFile("classpath:" + getResourceClasspath("BobjStoreUnitTest_config1.xml"));
+ BobjStore.configureStore();
+
+ assertEquals("batchtable", BobjStore.getBatchTableName());
+ assertEquals("jndi-name", BobjStore.getDataSourceJndi());
+ assertEquals("uidtable", BobjStore.getUidTableName());
+
+ BobjStore bob = BobjStore.getStore("org.jboss.SomeClass1");
+ assertEquals("snaptable-1", bob.getSnapTable());
+ assertEquals("snaptype-1", bob.getSnapType());
+ assertTrue(bob.isEncrypted());
+ assertEquals("locator-table-1", bob.getLocatorTable(0));
+ assertEquals(null, bob.getLocatorTable(1));
+
+ bob = BobjStore.getStore("org.jboss.SomeClass2");
+ assertEquals("snaptable-2", bob.getSnapTable());
+ assertEquals("snaptype-2", bob.getSnapType());
+ assertTrue(!bob.isEncrypted());
+ assertEquals(null, bob.getLocatorTable(0));
+ }
+
+ private String getResourceClasspath(String resource) {
+ return "/" + BobjStoreUnitTest.class.getPackage().getName().replace('.', '/') + "/" + resource;
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/BobjStoreUnitTest_config1.xml
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/BobjStoreUnitTest_config1.xml 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/BobjStoreUnitTest_config1.xml 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,6 @@
+<config dataSourceJndiName="jndi-name" batchTable="batchtable" uidTable="uidtable">
+ <Class name="org.jboss.SomeClass1" type="snaptype-1" encrypt="true" table="snaptable-1">
+ <Index table="locator-table-1" />
+ </Class>
+ <Class name="org.jboss.SomeClass2" type="snaptype-2" encrypt="false" table="snaptable-2" />
+</config>
\ No newline at end of file
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/DaoUidTableUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/DaoUidTableUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/internal/core/objectstore/DaoUidTableUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,43 @@
+/*
+ * 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.internal.core.objectstore;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+
+/**
+ * DaoUidTable unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class DaoUidTableUnitTest extends BaseTest {
+
+ public void test_DaoUidTable() throws Exception {
+ //JdbcCleanConn conn = new JdbcCleanConn(new MockDataSource(this));
+
+ //conn.prepareStatement("select * from table1;");
+
+ // TODO: Figure out how to test these DAO classes. I suspect these classes
+ // will need a full JBossESB database (or a good part of) before we can do
+ // anything with them. Currently we use an in-memory HSQLDB which gets
+ // instanciated for each test. It we create and distroy a DB for each test
+ // we'll prob grind the tests to a hault. Need to try it I suppose!
+ }
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/DummyUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/DummyUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/DummyUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,45 @@
+/*
+* 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.services;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+
+/**
+ * Dummy test file.
+ *
+ * @author <a href="mailto:arvinder.singh at indigo-logic.com">Arvinder Singh</a>
+ * @version <tt>$Revision:$</tt>
+ * $Id:$
+ */
+public class DummyUnitTest extends BaseTest {
+
+ /**
+ * Remove me
+ * @throws Exception
+ */
+ public void testDummyCompileAndInvoke() throws Exception {
+ log.info("****************************************************************");
+ log.info(" Dummy unit test called. Replace this with module level tests");
+ log.info("****************************************************************");
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/NotificationUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/NotificationUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/NotificationUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,227 @@
+/*
+* 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.services.beans;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Hashtable;
+
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.common.tests.EJBContainerSetup;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.helpers.persist.SimpleDataSource;
+import org.jboss.soa.esb.notification.NotificationList;
+import org.jboss.soa.esb.notification.NotificationTarget;
+import org.jboss.soa.esb.notification.NotifySqlTable;
+
+
+public class NotificationUnitTest extends BaseTest
+{
+ private Logger logger = Logger.getLogger(NotificationUnitTest.class);
+
+ public void testNotification() {
+ try {
+ logger.log(Priority.INFO, "Notification Test");
+ InitialContext ctx = getInitialContext();
+ @SuppressWarnings("unused")
+ NotificationHandler local = (NotificationHandler ) ctx.lookup("NotificationHandlerBean/local");
+ ConfigTree oEl = new ConfigTree("MyFileList");
+ oEl.setAttribute(NotificationList.TYPE,"OK");
+
+ // oEl.addElemChild(fileListTarget());
+ // oEl.addElemChild(emailTarget());
+ // oEl.addElemChild(jmsQueueTarget());
+ // oEl.addElemChild(jmsTopicTarget());
+ sqlTableTarget(oEl);
+
+ NotificationList oNL = new NotificationList(oEl);
+
+ // to see how the XML looks like
+ // this is just a unit test class
+ // Typically the XML is used in a parameter object (ConfigTree.fromXml())
+ System.out.println(oNL.toString());
+
+ // a simple timestamped message
+ Date oNow = new Date(System.currentTimeMillis());
+ SimpleDateFormat oStamp = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss.SSS");
+ @SuppressWarnings("unused")
+ StringBuilder sb = new StringBuilder(oStamp.format(oNow))
+ .append(" This message from Notification test");
+
+ //KS local.sendNotifications(oNL.toString(),sb.toString());
+
+ } catch (Exception e) {
+ fail();
+ logger.log(Priority.ERROR, e.getMessage(), e);
+ }
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(NotificationUnitTest.class);
+ return new EJBContainerSetup(suite);
+ }
+
+ public static InitialContext getInitialContext() throws Exception
+ {
+ Hashtable props = getInitialContextProperties();
+ return new InitialContext(props);
+ }
+
+ private static Hashtable getInitialContextProperties()
+ {
+ Hashtable<String,String> props = new Hashtable<String,String>();
+ props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory");
+ props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+ return props;
+ }
+
+// static ConfigTree emailTarget() throws Exception
+// {
+// ConfigTree oTgt = new ConfigTree(NotificationList.CHILD_TGT);
+// oTgt.setAttribute(NotificationTarget.PRM_NOTIF_CLASS,"NotifyEmail");
+// oTgt.setAttribute(Email.FROM,"sender at jboss.com");
+// oTgt.setAttribute(Email.SENDTO,"receiver1 at hotmail.com,receiver2 at jboss.com");;
+// oTgt.setAttribute(Email.SUBJECT,"TEST from Rosetta");
+// oTgt.setAttribute(Email.MESSAGE,"This is the text of your message");
+//
+// // This class does NOT send the e-mails, the app server does
+// // consequently these paths would have to be accessible in the
+// // application server (filesystem / mounts)
+// String[] sa = {"/tmp/tomcat.sh","/tmp/program.js"};
+// for (String sCurr : sa)
+// oTgt.addTextChild(Email.ATTACH,sCurr);
+//
+// return oTgt;
+// } //________________________________
+//
+// static ConfigTree fileListTarget() throws Exception
+// {
+// ConfigTree oTgt = new ConfigTree(NotificationList.CHILD_TGT);
+// oTgt.setAttribute(NotificationTarget.PRM_NOTIF_CLASS,"NotifyFiles");
+//
+// // This class does NOT write the files, the app server does
+// // consequently these paths would have to be accessible in the
+// // application server (filesystem / mounts)
+// String[] sa = {"file:///tmp/file1.notif","file:///tmp/file2.notif"};
+// for (String sCurr : sa)
+// { ConfigTree oFile = new ConfigTree(NotifyFiles.CHILD_FILE);
+// oFile.setAttribute(NotifyFiles.ATT_URI,sCurr);
+// oFile.setAttribute(NotifyFiles.ATT_APPEND,Boolean.toString(true));
+// oTgt.addElemChild(oFile);
+// }
+// return oTgt;
+// } //________________________________
+//
+// static ConfigTree jmsQueueTarget() throws Exception
+// {
+// ConfigTree oTgt = new ConfigTree(NotificationList.CHILD_TGT);
+// oTgt.setAttribute(NotificationTarget.PRM_NOTIF_CLASS,"NotifyQueues");
+//
+// String[] sa = {"queue/A","queue/B"};
+// for (String sCurr : sa)
+// { ConfigTree oQ = new ConfigTree(NotifyQueues.CHILD_QUEUE);
+// oQ.setAttribute(NotifyJMS.ATT_DEST_NAME,sCurr);
+// for (ConfigTree oProp : getMessageProperties())
+// oQ.addElemChild(oProp);
+// oTgt.addElemChild(oQ);
+// }
+// return oTgt;
+// } //________________________________
+//
+// static ConfigTree jmsTopicTarget() throws Exception
+// {
+// ConfigTree oTgt = new ConfigTree(NotificationList.CHILD_TGT);
+// oTgt.setAttribute(NotificationTarget.PRM_NOTIF_CLASS,"NotifyTopics");
+//
+// String[] sa = {"topic/testTopic"};
+// for (String sCurr : sa)
+// { ConfigTree oQ = new ConfigTree(NotifyTopics.CHILD_TOPIC);
+// oQ.setAttribute(NotifyJMS.ATT_DEST_NAME,sCurr);
+// for (ConfigTree oProp : getMessageProperties())
+// oQ.addElemChild(oProp);
+// oTgt.addElemChild(oQ);
+// }
+// return oTgt;
+// } //________________________________
+//
+// static ConfigTree[] getMessageProperties() throws Exception
+// {
+// KeyValuePair[] oaProps = new KeyValuePair[]
+// {new KeyValuePair("prop1","111")
+// ,new KeyValuePair("prop2","bbb")
+// ,new KeyValuePair("prop3","abc123")
+// };
+// ConfigTree[] oaRet = new ConfigTree[oaProps.length];
+// int iCurr = 0;
+// for (KeyValuePair oCurr : oaProps)
+// { ConfigTree oElem = new ConfigTree(NotifyJMS.CHILD_MSG_PROP);
+// oElem.setAttribute(NotifyJMS.ATT_PROP_NAME,oCurr.getKey());
+// oElem.setAttribute(NotifyJMS.ATT_PROP_VALUE,oCurr.getValue());
+// oaRet[iCurr++] = oElem;
+// }
+// return oaRet;
+// } //________________________________
+
+ static ConfigTree sqlTableTarget(ConfigTree dad) throws Exception
+ {
+ ConfigTree oTgt = new ConfigTree(NotificationList.CHILD_TGT,dad);
+ oTgt.setAttribute(NotificationTarget.PRM_NOTIF_CLASS,"NotifySqlTable");
+
+ oTgt.setAttribute(SimpleDataSource.DRIVER,"org.postgresql.Driver");
+ oTgt.setAttribute(SimpleDataSource.URL,"jdbc:postgresql://localhost:5432/jbossesb");
+ oTgt.setAttribute(SimpleDataSource.USER,"postgres");
+ oTgt.setAttribute(SimpleDataSource.PASSWORD,"postgres");
+
+ // Table name for insert - must exist in database (URL)
+ oTgt.setAttribute(NotifySqlTable.ATT_TABLE,"test_notif_table");
+ // Column that will contain the dynamic data generated by the ActionClass
+ // must exist in table (ATT_TABLE above)
+ oTgt.setAttribute(NotifySqlTable.ATT_DATA,"msg");
+
+ // constant data that can be also added in the insert
+ // (perhaps needed for queries)
+ // Key = column name (it must exist in the table, same as ATT_DATA column)
+ KeyValuePair[] oaCols = new KeyValuePair[]
+ {new KeyValuePair("src","TestNotification")
+ ,new KeyValuePair("ref","any Ref")
+ ,new KeyValuePair("val1","VVVV 11111")
+ };
+ for (KeyValuePair oCurr : oaCols)
+ { ConfigTree oElem = new ConfigTree(NotifySqlTable.CHILD_COLUMN,oTgt);
+ oElem.setAttribute(NotifySqlTable.ATT_NAME,oCurr.getKey());
+ oElem.setAttribute(NotifySqlTable.ATT_VALUE,oCurr.getValue());
+ }
+
+ return oTgt;
+ }
+
+}
+
+
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/PersistHandlerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/PersistHandlerUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/beans/PersistHandlerUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,58 @@
+/*
+* 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.services.beans;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.common.tests.EJBContainerSetup;
+
+
+public class PersistHandlerUnitTest extends BaseTest
+{
+ private Logger logger = Logger.getLogger(PersistHandlerUnitTest.class);
+
+ public void testConnectivityToPersistHandler() {
+ try {
+ logger.log(Priority.INFO, "PersistHandler Test");
+ PersistHandler persistHandlerLocal = (PersistHandler ) EJBContainerSetup.lookup("PersistHandlerBean/remote");
+ logger.log(Priority.INFO, "persistHandlerLocal=" + persistHandlerLocal);
+ //Create is currently failing since the config file property is not set.
+ //persistHandlerLocal.create();
+ //persistHandlerLocal.addDTO(null);
+ } catch (Exception e) {
+ logger.log(Priority.ERROR, e.getMessage(), e);
+ }
+ }
+
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(PersistHandlerUnitTest.class);
+ return new EJBContainerSetup(suite);
+ }
+
+}
+
+
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/JAXRRegistryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/JAXRRegistryUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/JAXRRegistryUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,281 @@
+/*
+* 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.services.registry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URLDecoder;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.xml.registry.BulkResponse;
+import javax.xml.registry.BusinessLifeCycleManager;
+import javax.xml.registry.BusinessQueryManager;
+import javax.xml.registry.Connection;
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.Classification;
+import javax.xml.registry.infomodel.ClassificationScheme;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.User;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.internal.soa.esb.addressing.EPRHelper;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.tests.HsqldbUtil;
+import org.jboss.soa.esb.common.tests.TestUtil;
+import org.jboss.soa.esb.services.util.FileUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Testing the registry.
+ *
+ * @author kstam
+ *
+ */
+public class JAXRRegistryUnitTest
+{
+ private static Logger logger = Logger.getLogger(JAXRRegistryUnitTest.class);
+ private static String mDbDriver;
+ private static String mDbUrl;
+ private static String mDbUsername;
+ private static String mDbPassword;
+ /**
+ * Tests the successful creation of the RED HAT/JBossESB Organization.
+ */
+ @Test
+ public void publishOrganization()
+ {
+ try {
+ Organization org = JAXRRegistryImpl.createJBossESBOrganization();
+ logger.log(Priority.INFO, "Succesfully created organization: " + org.getName().getValue());
+ assertEquals("Red Hat/JBossESB", org.getName().getValue());
+ } catch (JAXRException je) {
+ logger.log(Priority.ERROR, je.getLocalizedMessage(), je);
+ assertTrue(false);
+ }
+ }
+ @Test
+ public void findOrganization()
+ {
+ try {
+ Organization org = JAXRRegistryImpl.findOrganization("Red Hat/JBossESB");
+ logger.log(Priority.INFO, "Succesfully created organization: " + org.getName().getValue());
+ assertEquals("Red Hat/JBossESB", org.getName().getValue());
+ } catch (JAXRException je) {
+ logger.log(Priority.ERROR, je.getLocalizedMessage(), je);
+ assertTrue(false);
+ }
+ try {
+ Organization org = JAXRRegistryImpl.findOrganization("Not Existing Org");
+ logger.log(Priority.INFO, "Could not find non-existing organization.");
+ assertEquals(null, org);
+ } catch (JAXRException je) {
+ logger.log(Priority.ERROR, je.getLocalizedMessage(), je);
+ assertTrue(false);
+ }
+ }
+ /**
+ * Tests the successful registration of a Service.
+ *
+ */
+ @Test
+ public void publishService()
+ {
+ try {
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ registry.registerService("registry", "Registry Test ServiceName", "Registry Test Service Description");
+ } catch (JAXRException je) {
+ logger.log(Priority.ERROR, je.getLocalizedMessage(), je);
+ assertTrue(false);
+ }
+ }
+ @Test
+ public void publishServiceBinding()
+ {
+ try {
+ EPR epr = new EPR();
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ registry.registerEPR("registry", "Registry Test ServiceName", "Registry Test Service Description",
+ epr, "EPR description");
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ }
+ /**
+ * Queries the newly added information
+ * @throws Exception
+ */
+ @Test
+ public void findServicesForAnOrganization()
+ {
+ try {
+ Organization org = JAXRRegistryImpl.findOrganization("Red Hat/JBossESB");
+ //Listing out the services and their Bindings
+ logger.log(Priority.INFO, "-------------------------------------------------");
+ logger.log(Priority.INFO, "Organization name: " + org.getName().getValue());
+ logger.log(Priority.INFO, "Description: " + org.getDescription().getValue());
+ logger.log(Priority.INFO, "Key id: " + org.getKey().getId());
+ User primaryContact = org.getPrimaryContact();
+ logger.log(Priority.INFO, "Primary Contact: " + primaryContact.getPersonName().getFullName());
+ Collection services = org.getServices();
+ for (Iterator serviceIter = services.iterator();serviceIter.hasNext();) {
+ Service service = (Service) serviceIter.next();
+ logger.log(Priority.INFO, "- Service Name: " + service.getName().getValue());
+ logger.log(Priority.INFO, " Service Key : " + service.getKey().getId());
+ Collection serviceBindings = service.getServiceBindings();
+ for (Iterator serviceBindingIter = serviceBindings.iterator();serviceBindingIter.hasNext();){
+ ServiceBinding serviceBinding = (ServiceBinding) serviceBindingIter.next();
+ logger.log(Priority.INFO, " ServiceBinding Description: " + serviceBinding.getDescription().getValue());
+ String xml = URLDecoder.decode(serviceBinding.getAccessURI(),"UTF-8");
+ logger.log(Priority.INFO, " ServiceBinding URI: " + xml);
+ assertEquals(EPRHelper.toXMLString(new EPR()),xml);
+ }
+ }
+ logger.log(Priority.INFO, "-------------------------------------------------");
+ } catch (Exception je) {
+ je.printStackTrace();
+ assertTrue(false);
+ }
+ }
+ /**
+ * This doesn't work because scout drops the classifications on the floor.
+ * We're ignoring this test until I come up with a patch.
+ *
+ */
+ public void findServicesByClassification()
+ {
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ ClassificationScheme classificationScheme = bqm.findClassificationSchemeByName(null, "uddi-org:general_keywords");
+ Classification classification = blm.createClassification(classificationScheme,
+ "Test transformation service", "transformation");
+ Collection<Classification> classifications = new ArrayList<Classification>();
+ classifications.add(classification);
+ //Here I'd like to test filtering by this classification, but scout ignored the classification
+ String name=classificationScheme.getName().getValue();
+ System.out.println("Name=" + name);
+ Collection<String> nameParams = new ArrayList<String>();
+ //The name of the service is wild
+ nameParams.add("%");
+ BulkResponse bs = bqm.findServices(null, null,nameParams,classifications, null);
+ int status = bs.getStatus();
+ System.out.println("status=" + status);
+ } catch (JAXRException je) {
+ je.printStackTrace();
+ }
+ finally{}
+ }
+ /**
+ * Setup the database.
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void runBeforeAllTests() throws Exception {
+ try {
+ DOMConfigurator.configure(TestUtil.getPrefix() + "/etc/test/resources/log4j.xml");
+ TestUtil.setESBPropertiesFileToUse();
+ //Set the juddi properties file in System so juddi will pick it up later and use the test values.
+ String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-unittest.properties";
+ System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
+ //Read this properties file to get the db connection string
+ Properties props = new Properties();
+ InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
+ props.load(inStream);
+ mDbDriver = props.getProperty("juddi.jdbcDriver");
+ mDbUrl = props.getProperty("juddi.jdbcUrl");
+ mDbUsername = props.getProperty("juddi.jdbcUsername");
+ mDbPassword = props.getProperty("juddi.jdbcPassword");
+
+ String database="not tested yet";
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+ database = "hsqldb";
+ //Bring up hsql on default port 9001
+ HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "juddi");
+ } else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
+ database = "mysql";
+ } //add and test your own database..
+
+ //Get the registry-schema create scripts
+ String sqlDir = TestUtil.getPrefix() + "install/jUDDI-registry/sql/" + database + "/";
+ //Drop what is there now, if exists. We want to start fresh.
+ String sqlDropCmd = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
+ String sqlCreateCmd = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
+ String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
+
+ try {
+ Class.forName(mDbDriver);
+ } catch (Exception e) {
+ System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+ e.printStackTrace();
+ return;
+ }
+ java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
+ Statement stmnt = con.createStatement();
+ System.out.println("Dropping the schema if exist");
+ stmnt.execute(sqlDropCmd);
+ System.out.println("Creating the juddi-schema");
+ stmnt.execute(sqlCreateCmd);
+ System.out.println("Adding the jbossesb publisher");
+ stmnt.execute(sqlInsertPubCmd);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("We should stop testing, since we don't have a db.");
+ assertTrue(false);
+ }
+ }
+ /**
+ * Shutdown the database
+ * @throws Exception
+ */
+ @AfterClass
+ public static void runAfterAllTests() throws Exception {
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+ HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+ }
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(JAXRRegistryUnitTest.class);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,219 @@
+/*
+* 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.services.registry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.tests.HsqldbUtil;
+import org.jboss.soa.esb.common.tests.TestUtil;
+import org.jboss.soa.esb.services.util.FileUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+/**
+ * Testing the registry.
+ *
+ * @author kstam
+ *
+ */
+public class RegistryUnitTest
+{
+ private static String mDbDriver;
+ private static String mDbUrl;
+ private static String mDbUsername;
+ private static String mDbPassword;
+ private static final String SERVICE_NAME = "Kurt's Travel Agency";
+ private static final String CATEGORY = "travel";
+
+ private Logger logger = Logger.getLogger(this.getClass());
+
+ /**
+ * Testing the registering of an EPR.
+ */
+ @Test
+ public void publishEPR()
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ EPR epr = new EPR();
+ try {
+ registry.registerEPR(CATEGORY, SERVICE_NAME, "Service for traveling",
+ epr, "Specific Service Binding for traveling");
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ }
+ /**
+ * This test will try to find all services in the "travel" category.
+ */
+ @Test
+ public void findService()
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ try {
+ Collection<String> services = registry.findServices(CATEGORY);
+ for (Iterator i=services.iterator();i.hasNext();) {
+ String serviceName = (String) i.next();
+ logger.log(Priority.INFO, "Found service: " + serviceName);
+ assertEquals(CATEGORY + ":" + SERVICE_NAME, serviceName);
+ }
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ }
+ /**
+ * Find the EPRs for this service.
+ */
+ @Test
+ public void findEPRs()
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ try {
+ Collection<EPR> eprs = registry.findEPRs(CATEGORY, SERVICE_NAME);
+ for (Iterator i=eprs.iterator();i.hasNext();) {
+ EPR epr = (EPR) i.next();
+ logger.log(Priority.INFO, "Found epr: " + epr);
+ }
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ }
+ @Test
+ public void unregisterEPR()
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ try {
+ EPR eprToBeRemoved = new EPR();
+ registry.unRegisterEPR(CATEGORY, SERVICE_NAME, eprToBeRemoved);
+// Now make sure this EPR is really gone
+ Collection<EPR> eprs = registry.findEPRs(CATEGORY, SERVICE_NAME);
+ logger.log(Priority.INFO, "Number of Bindings left should be 0, and is: " + eprs.size());
+ assertEquals(eprs.size(),0);
+ } catch (Exception re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ }
+ @Test
+ public void unregisterService()
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ try {
+ registry.unRegisterService(CATEGORY, SERVICE_NAME);
+ //Make sure it's really gone
+ Collection<String> services = registry.findAllServices();
+ logger.log(Priority.INFO, "Number of Services left should be 0, and is: " + services.size());
+ assertEquals(services.size(),0);
+ } catch (Exception re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ }
+ /**
+ * Setup the database.
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void runBeforeAllTests() throws Exception {
+ try {
+ TestUtil.setESBPropertiesFileToUse();
+ //Set the juddi properties file in System so juddi will pick it up later and use the test values.
+ String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-unittest.properties";
+ System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
+ //Read this properties file to get the db connection string
+ Properties props = new Properties();
+ InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
+ props.load(inStream);
+ mDbDriver = props.getProperty("juddi.jdbcDriver");
+ mDbUrl = props.getProperty("juddi.jdbcUrl");
+ mDbUsername = props.getProperty("juddi.jdbcUsername");
+ mDbPassword = props.getProperty("juddi.jdbcPassword");
+
+ String database="not tested yet";
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+ database = "hsqldb";
+ //Bring up hsql on default port 9001
+ HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "juddi");
+ } else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
+ database = "mysql";
+ } //add and test your own database..
+
+ //Get the registry-schema create scripts
+ String sqlDir = TestUtil.getPrefix() + "install/jUDDI-registry/sql/" + database + "/";
+ //Drop what is there now, if exists. We want to start fresh.
+ String sqlDropCmd = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
+ String sqlCreateCmd = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
+ String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
+
+ try {
+ Class.forName(mDbDriver);
+ } catch (Exception e) {
+ System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+ e.printStackTrace();
+ return;
+ }
+ java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
+ Statement stmnt = con.createStatement();
+ System.out.println("Dropping the schema if exist");
+ stmnt.execute(sqlDropCmd);
+ System.out.println("Creating the juddi-schema");
+ stmnt.execute(sqlCreateCmd);
+ System.out.println("Adding the jbossesb publisher");
+ stmnt.execute(sqlInsertPubCmd);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("We should stop testing, since we don't have a db.");
+ assertTrue(false);
+ }
+ }
+ /**
+ * Shutdown the database
+ * @throws Exception
+ */
+ @AfterClass
+ public static void runAfterAllTests() throws Exception {
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+ HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+ }
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(RegistryUnitTest.class);
+ }
+
+}
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/juddi-unittest.properties
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/juddi-unittest.properties 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/registry/juddi-unittest.properties 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,69 @@
+# jUDDI Registry Properties (used by RegistryServer)
+# see http://www.juddi.org for more information
+
+# The UDDI Operator Name
+juddi.operatorName = jUDDI.org
+
+# The i18n locale default codes
+juddi.i18n.languageCode = en
+juddi.i18n.countryCode = US
+
+# The UDDI DiscoveryURL Prefix
+juddi.discoveryURL = http://localhost:8080/juddi/uddiget.jsp?
+
+# The UDDI Operator Contact Email Address
+juddi.operatorEmailAddress = admin at juddi.org
+
+# The maximum name size and maximum number
+# of name elements allows in several of the
+# FindXxxx and SaveXxxx UDDI functions.
+juddi.maxNameLength=255
+juddi.maxNameElementsAllowed=5
+
+# The maximum number of UDDI artifacts allowed
+# per publisher. A value of '-1' indicates any
+# number of artifacts is valid (These values can be
+# overridden at the individual publisher level).
+juddi.maxBusinessesPerPublisher=25
+juddi.maxServicesPerBusiness=20
+juddi.maxBindingsPerService=10
+juddi.maxTModelsPerPublisher=100
+
+# jUDDI Authentication module to use
+juddi.auth = org.apache.juddi.auth.DefaultAuthenticator
+
+# jUDDI DataStore module currently to use
+juddi.dataStore = org.apache.juddi.datastore.jdbc.JDBCDataStore
+
+# use a dataSource (if set to false a direct
+# jdbc connection will be used.
+juddi.isUseDataSource=false
+juddi.jdbcDriver=org.hsqldb.jdbcDriver
+juddi.jdbcUrl=jdbc:hsqldb:hsql://localhost/juddi
+juddi.jdbcUsername=sa
+juddi.jdbcPassword=
+# jUDDI DataSource to use
+juddi.dataSource=java:comp/env/jdbc/juddiDB
+
+# jUDDI UUIDGen implementation to use
+juddi.uuidgen = org.apache.juddi.uuidgen.DefaultUUIDGen
+
+# jUDDI Cryptor implementation to use
+juddi.cryptor = org.apache.juddi.cryptor.DefaultCryptor
+
+# jUDDI Validator to use
+juddi.validator=org.apache.juddi.validator.DefaultValidator
+
+# jUDDI Proxy Properties (used by RegistryProxy)
+juddi.proxy.adminURL = http://localhost:8080/juddi/admin
+juddi.proxy.inquiryURL = http://localhost:8080/juddi/inquiry
+juddi.proxy.publishURL = http://localhost:8080/juddi/publish
+juddi.proxy.transportClass = org.apache.juddi.proxy.AxisTransport
+juddi.proxy.securityProvider = com.sun.net.ssl.internal.ssl.Provider
+juddi.proxy.protocolHandler = com.sun.net.ssl.internal.www.protocol
+
+# JNDI settings (used by RMITransport)
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming
+
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/tests/objectstore/ObjectStoreFuncTest.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/tests/objectstore/ObjectStoreFuncTest.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/tests/objectstore/ObjectStoreFuncTest.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,91 @@
+/*
+* 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.services.tests.objectstore;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+
+// DON'T FORGET !!
+// The Rosetta Application server has to be up and running
+// (set JNDI_SERVER appropriately)
+
+public class ObjectStoreFuncTest extends BaseTest
+{
+ public ObjectStoreFuncTest() {
+ }
+
+ public void testNotImplementedFuncTest() {
+ log.info("*******************************************");
+ log.info("Requires Implementation");
+ log.info("*******************************************");
+ }
+
+ /*
+ public ObjectStoreFuncTest () throws Exception
+ { performTest(); }
+
+ static void performTest() throws Exception
+ {
+ // get a handle to your business delegate
+ m_oH = PersistHandlerFactory.getPersistHandler
+ ("remote"
+ ,SystemProperties.getJndiServerType()
+ ,SystemProperties.getJndiServerURL()
+ );
+
+ // request UID chunks for your own use
+ // int[] ia = {10,20,30};
+ // for (int iCurr : ia)
+ // System.out.println
+ // ("Requesting "+iCurr+" uids "
+ // +" - First UID returned = " +m_oH.getUidChunk(iCurr)
+ // );
+
+ storeAndRetrievePerson();
+ } //________________________________
+
+ static void storeAndRetrievePerson() throws Exception
+ {
+ // set up a Person (see TestPersonAddrPhone.class)
+ Person oPrs = PersonUnitTest.getPerson();
+ // timestamp, uid and snap Uid are added just to make it easier
+ // to compare output text
+ oPrs.setStamp(System.currentTimeMillis());
+ long lUid = m_oH.addObject(oPrs);
+ oPrs.setUid(lUid);
+ oPrs.setSnap(lUid);
+
+ // retrieve it from the Object Store
+ Person oP2 = (Person)m_oH.getObject(Person.class,lUid);
+
+ // output in XML format both objects, and compare
+ // timestamps will differ slightly because first object
+ // has a dummy timestamp (just before "store" request)
+ System.out.println(oPrs.toDTO().toXml());
+ System.out.println(oP2.toDTO().toXml());
+
+ // if you used the "ObjStoreExample.xml" that comes with the
+ // standard example, you'll be able to see your objects
+ // in the "object_snap" and "people_index" tables
+
+ } //________________________________
+ */
+} //____________________________________________________________________________
Added: labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/util/FileUtil.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/util/FileUtil.java 2006-11-06 14:32:19 UTC (rev 7415)
+++ labs/jbossesb/workspace/b_georges/product/core/services/tests/src/org/jboss/soa/esb/services/util/FileUtil.java 2006-11-06 14:45:54 UTC (rev 7416)
@@ -0,0 +1,83 @@
+/*
+* 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.services.util;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+/**
+ * Utility class for reading a file into a String and back.
+ * @author kstam
+ */
+public class FileUtil {
+ /**
+ * Read the file into a String.
+ * @param file - the file to be read
+ * @return String with the content of the file
+ * @throws IOException - when we can't read the file
+ */
+ public static String readTextFile(File file) throws IOException
+ {
+ StringBuffer sb = new StringBuffer(1024);
+ BufferedReader reader = new BufferedReader(new FileReader(file.getPath()));
+ char[] chars = new char[1];
+ while( (reader.read(chars)) > -1){
+ sb.append(String.valueOf(chars));
+ chars = new char[1];
+ }
+ reader.close();
+ return sb.toString();
+ }
+ /**
+ *
+ */
+ public static String readStream(InputStream inputStream) throws IOException
+ {
+ StringBuffer sb = new StringBuffer(1024);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+ char[] chars = new char[1];
+ while( (reader.read(chars)) > -1){
+ sb.append(String.valueOf(chars));
+ chars = new char[1];
+ }
+ reader.close();
+ return sb.toString();
+ }
+ /**
+ * Write a String into a file.
+ * @param file - File to which we write the String
+ * @param str - string which will be written
+ * @throws IOException - when we can't write to the file
+ */
+ public static void writeTextFile(File file, String str) throws IOException
+ {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(file.getPath()));
+ writer.write(str);
+ writer.close();
+ }
+
+}
More information about the jboss-svn-commits
mailing list