summaryrefslogtreecommitdiff
path: root/qpid
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2011-08-22 20:14:35 +0000
committerRobert Godfrey <rgodfrey@apache.org>2011-08-22 20:14:35 +0000
commit80f7040fb49757f80b9450bf497cbb1ff4f4f154 (patch)
treebf5c72e73579d6df3116ad13fa243730ed36a7fb /qpid
parent9d88761d6711f7f8722091fcb8849c0e89a8b8c9 (diff)
downloadqpid-python-80f7040fb49757f80b9450bf497cbb1ff4f4f154.tar.gz
NO-JIRA : Merge to 1-0 sandbox branch from current HEAD - r1160304
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/rg-amqp-1-0-sandbox@1160414 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid')
-rw-r--r--qpid/java/broker-plugins/extras/src/test/java/org/apache/qpid/server/plugins/ExtrasTest.java2
-rw-r--r--qpid/java/broker/etc/config.xml2
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java88
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java14
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java55
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java91
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties93
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java260
-rwxr-xr-xqpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java12
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java11
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java8
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java3
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java89
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java25
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java4
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/MockPluginManager.java56
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java93
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java2
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java118
-rw-r--r--qpid/java/build.xml2
-rw-r--r--qpid/java/client-plugins/.gitignore0
-rw-r--r--qpid/java/client-plugins/README.txt21
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java118
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java62
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java80
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java29
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java247
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/SSLConfiguration.java61
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/XAConnectionImpl.java4
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java3
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStream.java134
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java8
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverExchangeMethod.java1
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindConnectionFactory.java185
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindQueue.java213
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindTopic.java212
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/README.txt11
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/cluster/Client.java129
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java277
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/codec/Client.java133
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/codec/Server.java103
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/config/AbstractConfig.java69
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/config/ConnectionFactoryInitialiser.java29
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/config/Connector.java40
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/config/ConnectorConfig.java28
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java117
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/flow/ChannelFlowTest.java112
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/fragmentation/TestLargePublisher.java196
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/fragmentation/TestLargeSubscriber.java167
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/headers/Listener.java117
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/headers/MessageFactory.java175
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/headers/Publisher.java133
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Bind.java273
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Lookup.java196
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Unbind.java166
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/latency/LatencyTest.java153
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/mina/AcceptorTest.java102
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/mina/BlockingAcceptorTest.java93
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/mina/WriterTest.java271
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/multiconsumer/AMQTest.java269
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/pubsub1/TestPublisher.java176
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/pubsub1/TestSubscriber.java122
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/client/connection/TestManyConnections.java95
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java153
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/jndi/example.properties38
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/topic/Config.java243
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/topic/Listener.java141
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/topic/MessageFactory.java155
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/topic/Publisher.java175
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Config.java110
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Ping.java45
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Pong.java45
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Relay.java127
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Start.java44
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/weblogic/ServiceProvider.java151
-rw-r--r--qpid/java/client/src/old_test/java/org/apache/qpid/weblogic/ServiceRequestingClient.java185
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java31
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/client/message/TestMessageHelper.java5
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStreamTest.java87
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageUnitTest.java110
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java18
-rw-r--r--qpid/java/common.xml3
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/ssl/SSLContextFactory.java216
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java5
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java5
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java5
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkHandler.java26
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkTransport.java14
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/SSLStatus.java (renamed from qpid/java/client/src/old_test/java/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java)36
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/SecurityLayer.java31
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/QpidClientX509KeyManager.java4
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java54
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java43
-rw-r--r--qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java37
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/ssl/SSLContextFactoryTest.java84
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java90
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java7
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoAcceptor.java2
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoTransport.java65
-rw-r--r--qpid/java/perftests/src/main/java/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java14
-rw-r--r--qpid/java/systests/etc/config-systests-settings.xml11
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java159
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java6
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java219
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQSSLConnectionTest.java57
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/CloseAfterConnectionFailureTest.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java90
-rwxr-xr-xqpid/java/test-profiles/CPPExcludes3
-rw-r--r--qpid/java/test-profiles/JavaExcludes3
-rw-r--r--qpid/java/test-profiles/cpp.ssl.excludes7
-rw-r--r--qpid/java/test-profiles/cpp.ssl.testprofile4
-rw-r--r--qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile2
-rw-r--r--qpid/java/test-profiles/java-dby.0-9-1.testprofile2
-rw-r--r--qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile2
-rw-r--r--qpid/java/test-profiles/java-mms.0-9-1.testprofile2
-rw-r--r--qpid/java/test-profiles/log4j-test.xml4
-rw-r--r--qpid/java/test-profiles/test_resources/ssl/java_broker.crt15
-rw-r--r--qpid/java/test-profiles/test_resources/ssl/java_broker.req10
-rw-r--r--qpid/java/test-profiles/test_resources/ssl/java_broker_keystore.jksbin0 -> 2475 bytes
-rw-r--r--qpid/java/test-profiles/test_resources/ssl/java_client_keystore.jks (renamed from qpid/java/test-profiles/test_resources/ssl/keystore.jks)bin4296 -> 4296 bytes
-rw-r--r--qpid/java/test-profiles/test_resources/ssl/java_client_truststore.jks (renamed from qpid/java/test-profiles/test_resources/ssl/certstore.jks)bin591 -> 591 bytes
-rw-r--r--qpid/java/test-profiles/testprofile.defaults2
126 files changed, 1931 insertions, 7439 deletions
diff --git a/qpid/java/broker-plugins/extras/src/test/java/org/apache/qpid/server/plugins/ExtrasTest.java b/qpid/java/broker-plugins/extras/src/test/java/org/apache/qpid/server/plugins/ExtrasTest.java
index 57b6e19b5d..db3ebfd4e1 100644
--- a/qpid/java/broker-plugins/extras/src/test/java/org/apache/qpid/server/plugins/ExtrasTest.java
+++ b/qpid/java/broker-plugins/extras/src/test/java/org/apache/qpid/server/plugins/ExtrasTest.java
@@ -67,7 +67,7 @@ public class ExtrasTest extends TestCase
public void testNoExchanges() throws Exception
{
- PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp");
+ PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp", null);
Map<String, ExchangeType<?>> exchanges = manager.getExchanges();
assertTrue("Exchanges found", exchanges.isEmpty());
}
diff --git a/qpid/java/broker/etc/config.xml b/qpid/java/broker/etc/config.xml
index 61f1c832b1..59e5ed0f58 100644
--- a/qpid/java/broker/etc/config.xml
+++ b/qpid/java/broker/etc/config.xml
@@ -33,12 +33,12 @@
To disasble Non-SSL port set sslOnly to true -->
<ssl>
<enabled>false</enabled>
+ <port>5671</port>
<sslOnly>false</sslOnly>
<keystorePath>/path/to/keystore.ks</keystorePath>
<keystorePassword>keystorepass</keystorePassword>
</ssl>
<port>5672</port>
- <sslport>8672</sslport>
<socketReceiveBuffer>262144</socketReceiveBuffer>
<socketSendBuffer>262144</socketSendBuffer>
</connector>
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
index cdc022ddac..e29b07b3e7 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/Broker.java
@@ -34,6 +34,8 @@ import java.util.Properties;
import java.util.Set;
import java.util.logging.*;
+import javax.net.ssl.SSLContext;
+
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.QpidLog4JConfigurator;
import org.apache.qpid.server.configuration.ServerConfiguration;
@@ -46,8 +48,8 @@ import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.logging.actors.GenericActor;
import org.apache.qpid.server.logging.management.LoggingManagementMBean;
import org.apache.qpid.server.logging.messages.BrokerMessages;
-import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory;
import org.apache.qpid.server.protocol.AmqpProtocolVersion;
+import org.apache.qpid.server.protocol.MultiVersionProtocolEngineFactory;
import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry;
import org.apache.qpid.server.transport.QpidAcceptor;
@@ -115,7 +117,7 @@ public class Broker
configureLogging(logConfigFile, options.getLogWatchFrequency());
- ConfigurationFileApplicationRegistry config = new ConfigurationFileApplicationRegistry(configFile);
+ ConfigurationFileApplicationRegistry config = new ConfigurationFileApplicationRegistry(configFile, options.getBundleContext());
ServerConfiguration serverConfig = config.getConfiguration();
updateManagementPort(serverConfig, options.getJmxPort());
@@ -199,57 +201,41 @@ public class Broker
{
for(int port : ports)
{
- Set<AmqpProtocolVersion> supported = EnumSet.allOf(AmqpProtocolVersion.class);
-
- if(exclude_0_10.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_10);
- }
-
- if(exclude_0_9_1.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_9_1);
- }
- if(exclude_0_9.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_9);
- }
- if(exclude_0_8.contains(port))
- {
- supported.remove(AmqpProtocolVersion.v0_8);
- }
-
- NetworkTransportConfiguration settings =
- new ServerNetworkTransportConfiguration(serverConfig, port, bindAddress.getHostName(), Transport.TCP);
-
- IncomingNetworkTransport transport = Transport.getIncomingTransportInstance();
- MultiVersionProtocolEngineFactory protocolEngineFactory =
- new MultiVersionProtocolEngineFactory(hostName, supported);
+ final Set<AmqpProtocolVersion> supported =
+ getSupportedVersions(port, exclude_0_10, exclude_0_9_1, exclude_0_9, exclude_0_8);
+ final NetworkTransportConfiguration settings =
+ new ServerNetworkTransportConfiguration(serverConfig, port, bindAddress.getHostName(), Transport.TCP);
+
+ final IncomingNetworkTransport transport = Transport.getIncomingTransportInstance();
+ final MultiVersionProtocolEngineFactory protocolEngineFactory =
+ new MultiVersionProtocolEngineFactory(hostName, supported);
transport.accept(settings, protocolEngineFactory, null);
ApplicationRegistry.getInstance().addAcceptor(new InetSocketAddress(bindAddress, port),
- new QpidAcceptor(transport,"TCP"));
+ new QpidAcceptor(transport,"TCP"));
CurrentActor.get().message(BrokerMessages.LISTENING("TCP", port));
}
}
if (serverConfig.getEnableSSL())
{
- String keystorePath = serverConfig.getKeystorePath();
- String keystorePassword = serverConfig.getKeystorePassword();
- String certType = serverConfig.getCertType();
- SSLContextFactory sslFactory =
- new SSLContextFactory(keystorePath, keystorePassword, certType);
+ final String keystorePath = serverConfig.getKeystorePath();
+ final String keystorePassword = serverConfig.getKeystorePassword();
+ final String certType = serverConfig.getCertType();
+ final SSLContext sslContext = SSLContextFactory.buildServerContext(keystorePath, keystorePassword, certType);
for(int sslPort : sslPorts)
{
- NetworkTransportConfiguration settings =
+ final Set<AmqpProtocolVersion> supported =
+ getSupportedVersions(sslPort, exclude_0_10, exclude_0_9_1, exclude_0_9, exclude_0_8);
+ final NetworkTransportConfiguration settings =
new ServerNetworkTransportConfiguration(serverConfig, sslPort, bindAddress.getHostName(), Transport.TCP);
- IncomingNetworkTransport transport = new MinaNetworkTransport();
-
- transport.accept(settings, new MultiVersionProtocolEngineFactory(), sslFactory);
+ final IncomingNetworkTransport transport = new MinaNetworkTransport();
+ final MultiVersionProtocolEngineFactory protocolEngineFactory =
+ new MultiVersionProtocolEngineFactory(hostName, supported);
+ transport.accept(settings, protocolEngineFactory, sslContext);
ApplicationRegistry.getInstance().addAcceptor(new InetSocketAddress(bindAddress, sslPort),
new QpidAcceptor(transport,"TCP"));
CurrentActor.get().message(BrokerMessages.LISTENING("TCP/SSL", sslPort));
@@ -265,6 +251,32 @@ public class Broker
}
}
+ private static Set<AmqpProtocolVersion> getSupportedVersions(final int port, final Set<Integer> exclude_0_10,
+ final Set<Integer> exclude_0_9_1, final Set<Integer> exclude_0_9,
+ final Set<Integer> exclude_0_8)
+ {
+ final EnumSet<AmqpProtocolVersion> supported = EnumSet.allOf(AmqpProtocolVersion.class);
+
+ if(exclude_0_10.contains(port))
+ {
+ supported.remove(AmqpProtocolVersion.v0_10);
+ }
+ if(exclude_0_9_1.contains(port))
+ {
+ supported.remove(AmqpProtocolVersion.v0_9_1);
+ }
+ if(exclude_0_9.contains(port))
+ {
+ supported.remove(AmqpProtocolVersion.v0_9);
+ }
+ if(exclude_0_8.contains(port))
+ {
+ supported.remove(AmqpProtocolVersion.v0_8);
+ }
+
+ return supported;
+ }
+
private File getConfigFile(final String fileName,
final String defaultFileName,
final String qpidHome, boolean throwOnFileNotFound) throws InitException
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
index b83da92660..b2d029eb95 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
@@ -26,6 +26,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.osgi.framework.BundleContext;
+
public class BrokerOptions
{
/** serialVersionUID */
@@ -51,9 +53,11 @@ public class BrokerOptions
private String _logConfigFile;
private String _bind;
private Integer _jmxPort;
+ private BundleContext _bundleContext;
private Integer _logWatchFrequency = 0;
+
public void addPort(final int port)
{
_ports.add(port);
@@ -149,4 +153,14 @@ public class BrokerOptions
{
_logWatchFrequency = logWatchFrequency;
}
+
+ public BundleContext getBundleContext()
+ {
+ return _bundleContext ;
+ }
+
+ public void setBundleContext(final BundleContext bundleContext)
+ {
+ _bundleContext = bundleContext;
+ }
} \ No newline at end of file
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java
index 0621b87f0a..02f8a346cf 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ServerConfiguration.java
@@ -39,17 +39,13 @@ import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.SystemConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.log4j.Logger;
-import org.apache.qpid.server.configuration.management.ConfigurationManagementMBean;
import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.signal.SignalHandlerTask;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
-import org.apache.qpid.transport.NetworkTransportConfiguration;
-import sun.misc.Signal;
-import sun.misc.SignalHandler;
-
-public class ServerConfiguration extends ConfigurationPlugin implements SignalHandler
+public class ServerConfiguration extends ConfigurationPlugin
{
protected static final Logger _logger = Logger.getLogger(ServerConfiguration.class);
@@ -60,7 +56,7 @@ public class ServerConfiguration extends ConfigurationPlugin implements SignalHa
public static final int DEFAULT_FRAME_SIZE = 65536;
public static final int DEFAULT_PORT = 5672;
- public static final int DEFAULT_SSL_PORT = 8672;
+ public static final int DEFAULT_SSL_PORT = 5671;
public static final long DEFAULT_HOUSEKEEPING_PERIOD = 30000L;
public static final int DEFAULT_JMXPORT = 8999;
@@ -75,10 +71,6 @@ public class ServerConfiguration extends ConfigurationPlugin implements SignalHa
private File _configFile;
private File _vhostsFile;
- private Logger _log = Logger.getLogger(this.getClass());
-
- private ConfigurationManagementMBean _mbean;
-
// Map of environment variables to config items
private static final Map<String, String> envVarMap = new HashMap<String, String>();
@@ -137,15 +129,26 @@ public class ServerConfiguration extends ConfigurationPlugin implements SignalHa
{
this(parseConfig(configurationURL));
_configFile = configurationURL;
- try
+
+ SignalHandlerTask hupReparseTask = new SignalHandlerTask()
{
- Signal sig = new sun.misc.Signal("HUP");
- sun.misc.Signal.handle(sig, this);
- }
- catch (Exception e)
+ public void handle()
+ {
+ try
+ {
+ reparseConfigFileSecuritySections();
+ }
+ catch (ConfigurationException e)
+ {
+ _logger.error("Could not reload configuration file security sections", e);
+ }
+ }
+ };
+
+ if(!hupReparseTask.register("HUP"))
{
- _logger.info("Signal HUP not supported for OS: " + System.getProperty("os.name"));
- // We're on something that doesn't handle SIGHUP, how sad, Windows.
+ _logger.info("Unable to register Signal HUP handler to reload security configuration.");
+ _logger.info("Signal HUP not supported for this OS / JVM combination - " + SignalHandlerTask.getPlatformDescription());
}
}
@@ -416,18 +419,6 @@ public class ServerConfiguration extends ConfigurationPlugin implements SignalHa
return _configFile == null ? "" : _configFile.getAbsolutePath();
}
- public void handle(Signal arg0)
- {
- try
- {
- reparseConfigFileSecuritySections();
- }
- catch (ConfigurationException e)
- {
- _logger.error("Could not reload configuration file security sections", e);
- }
- }
-
public void reparseConfigFileSecuritySections() throws ConfigurationException
{
if (_configFile != null)
@@ -688,12 +679,12 @@ public class ServerConfiguration extends ConfigurationPlugin implements SignalHa
public String getKeystorePath()
{
- return getStringValue("connector.ssl.keystorePath", "none");
+ return getStringValue("connector.ssl.keystorePath");
}
public String getKeystorePassword()
{
- return getStringValue("connector.ssl.keystorePassword", "none");
+ return getStringValue("connector.ssl.keystorePassword");
}
public String getCertType()
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java
new file mode 100644
index 0000000000..644f714c8c
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtil.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.server.plugins;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.osgi.framework.Version;
+
+/**
+ * Utility class to convert a map of package name to version numbers into the string
+ * with the format expected of a OSGi system package declaration:
+ *
+ * <code>
+ * org.xyz; version=1.0.0, org.xyz.xyz; version=1.0.0,...
+ * </code>
+ *
+ * Additionally, if the caller has provided a qpidPackageReleaseNumber and the package
+ * begins org.apache.qpid, this release number will be used, in preference to the one
+ * found in the Map.
+ *
+ * @see org.osgi.framework.Constants#FRAMEWORK_SYSTEMPACKAGES
+ *
+ */
+public class OsgiSystemPackageUtil
+{
+ private static final String APACHE_QPID_PKG_PREFIX = "org.apache.qpid";
+
+ private final Map<String, String> _packageNameVersionMap;
+ private final Version _qpidPackageReleaseNumber;
+
+ public OsgiSystemPackageUtil(final Version qpidPackageReleaseNumber, final Map<String, String> packageNameVersionMap)
+ {
+ _qpidPackageReleaseNumber = qpidPackageReleaseNumber;
+ _packageNameVersionMap = packageNameVersionMap;
+ }
+
+ public String getFormattedSystemPackageString()
+ {
+ if (_packageNameVersionMap == null || _packageNameVersionMap.size() == 0)
+ {
+ return null;
+ }
+
+ final StringBuilder packages = new StringBuilder();
+
+ for(Iterator<String> itr = _packageNameVersionMap.keySet().iterator(); itr.hasNext();)
+ {
+ final String packageName = itr.next();
+ final String packageVersion;
+
+ if (_qpidPackageReleaseNumber != null && packageName.startsWith(APACHE_QPID_PKG_PREFIX))
+ {
+ packageVersion = _qpidPackageReleaseNumber.toString();
+ }
+ else
+ {
+ packageVersion = _packageNameVersionMap.get(packageName);
+ }
+
+ packages.append(packageName);
+ packages.append("; ");
+ packages.append("version=");
+ packages.append(packageVersion);
+
+ if (itr.hasNext())
+ {
+ packages.append(", ");
+ }
+ }
+
+ return packages.toString();
+ }
+
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties
new file mode 100644
index 0000000000..aaab4f76cc
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/OsgiSystemPackages.properties
@@ -0,0 +1,93 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one#
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+#
+# OSGi framework system package list
+#
+# PluginManager uses these properties to construct the FRAMEWORK_SYSTEMPACKAGES list
+#
+
+# Format is:
+# <package>=<version>
+# and PluginManager will convert this into:
+# <package>; version=<version>
+# e.g. org.osgi.framework; version=1.3.0
+
+javax.management.openmbean=1.0.0
+javax.management=1.0.0
+
+javax.security.auth=1.0.0
+javax.security.auth.callback=1.0.0
+javax.security.sasl=1.0.0
+javax.security=1.0.0
+
+org.xml.sax=1.0.0
+org.xml.sax.helpers=1.0.0
+
+org.osgi.framework=1.3.0
+org.osgi.service.packageadmin=1.2.0
+org.osgi.service.startlevel=1.0.0
+org.osgi.service.url=1.0.0
+org.osgi.util.tracker=1.0.0
+
+org.apache.commons.configuration=1.0.0
+
+org.apache.commons.lang=1.0.0
+org.apache.commons.lang.builder=1.0.0
+org.apache.commons.logging=1.0.0
+
+org.apache.log4j=1.2.12
+
+org.slf4j=1.6.1
+
+# For Qpid packages (org.apache.qpid), the version number is automatically overridden by QpidPropertis#getReleaseVersion()
+
+org.apache.qpid.junit.extensions.util=0.0.0
+org.apache.qpid=0.0.0
+org.apache.qpid.common=0.0.0
+org.apache.qpid.exchange=0.0.0
+org.apache.qpid.framing=0.0.0
+org.apache.qpid.management.common.mbeans.annotations=0.0.0
+org.apache.qpid.protocol=0.0.0
+org.apache.qpid.transport=0.0.0
+org.apache.qpid.transport.codec=0.0.0
+org.apache.qpid.server.binding=0.0.0
+org.apache.qpid.server.configuration=0.0.0
+org.apache.qpid.server.configuration.plugins=0.0.0
+org.apache.qpid.server.configuration.management=0.0.0
+org.apache.qpid.server.exchange=0.0.0
+org.apache.qpid.server.logging=0.0.0
+org.apache.qpid.server.logging.actors=0.0.0
+org.apache.qpid.server.logging.subjects=0.0.0
+org.apache.qpid.server.management=0.0.0
+org.apache.qpid.server.persistent=0.0.0
+org.apache.qpid.server.plugins=0.0.0
+org.apache.qpid.server.protocol=0.0.0
+org.apache.qpid.server.queue=0.0.0
+org.apache.qpid.server.registry=0.0.0
+org.apache.qpid.server.security=0.0.0
+org.apache.qpid.server.security.access=0.0.0
+org.apache.qpid.server.security.access.plugins=0.0.0
+org.apache.qpid.server.security.auth=0.0.0
+org.apache.qpid.server.security.auth.sasl=0.0.0
+org.apache.qpid.server.security.auth.manager=0.0.0
+org.apache.qpid.server.virtualhost=0.0.0
+org.apache.qpid.server.virtualhost.plugins=0.0.0
+org.apache.qpid.util=0.0.0
+
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java
index c8a7b56ccb..43c4fa26b7 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java
@@ -30,18 +30,22 @@ import static org.osgi.framework.Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT;
import static org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.util.StringMap;
import org.apache.log4j.Logger;
import org.apache.qpid.common.Closeable;
+import org.apache.qpid.common.QpidProperties;
import org.apache.qpid.server.configuration.TopicConfiguration;
import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
import org.apache.qpid.server.configuration.plugins.SlowConsumerDetectionConfiguration.SlowConsumerDetectionConfigurationFactory;
@@ -59,8 +63,11 @@ import org.apache.qpid.server.virtualhost.plugins.SlowConsumerDetection;
import org.apache.qpid.server.virtualhost.plugins.VirtualHostPluginFactory;
import org.apache.qpid.server.virtualhost.plugins.policies.TopicDeletePolicy;
import org.apache.qpid.slowconsumerdetection.policies.SlowConsumerPolicyPluginFactory;
+import org.apache.qpid.util.FileUtils;
import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Version;
import org.osgi.framework.launch.Framework;
import org.osgi.util.tracker.ServiceTracker;
@@ -73,7 +80,6 @@ public class PluginManager implements Closeable
private static final Logger _logger = Logger.getLogger(PluginManager.class);
private static final int FELIX_STOP_TIMEOUT = 30000;
- private static final String QPID_VER_SUFFIX = "version=0.13,";
private Framework _felix;
@@ -92,7 +98,50 @@ public class PluginManager implements Closeable
private Map<String, SlowConsumerPolicyPluginFactory> _policyPlugins = new HashMap<String, SlowConsumerPolicyPluginFactory>();
private Map<String, AuthenticationManagerPluginFactory<? extends Plugin>> _authenticationManagerPlugins = new HashMap<String, AuthenticationManagerPluginFactory<? extends Plugin>>();
- public PluginManager(String pluginPath, String cachePath) throws Exception
+ /** The default name of the OSGI system package list. */
+ private static final String DEFAULT_RESOURCE_NAME = "org/apache/qpid/server/plugins/OsgiSystemPackages.properties";
+
+ /** The name of the override system property that holds the name of the OSGI system package list. */
+ private static final String FILE_PROPERTY = "qpid.osgisystempackages.properties";
+
+ private static final String OSGI_SYSTEM_PACKAGES;
+
+ static
+ {
+ final String filename = System.getProperty(FILE_PROPERTY);
+ final InputStream is = FileUtils.openFileOrDefaultResource(filename, DEFAULT_RESOURCE_NAME,
+ PluginManager.class.getClassLoader());
+
+ try
+ {
+ Version qpidReleaseVersion;
+ try
+ {
+ qpidReleaseVersion = Version.parseVersion(QpidProperties.getReleaseVersion());
+ }
+ catch (IllegalArgumentException iae)
+ {
+ qpidReleaseVersion = null;
+ }
+
+ final Properties p = new Properties();
+ p.load(is);
+
+ final OsgiSystemPackageUtil osgiSystemPackageUtil = new OsgiSystemPackageUtil(qpidReleaseVersion, (Map)p);
+
+ OSGI_SYSTEM_PACKAGES = osgiSystemPackageUtil.getFormattedSystemPackageString();
+
+ _logger.debug("List of OSGi system packages to be added: " + OSGI_SYSTEM_PACKAGES);
+ }
+ catch (IOException e)
+ {
+ _logger.error("Error reading OSGI system package list", e);
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+
+ public PluginManager(String pluginPath, String cachePath, BundleContext bundleContext) throws Exception
{
// Store all non-OSGi plugins
// A little gross that we have to add them here, but not all the plugins are OSGIfied
@@ -131,127 +180,97 @@ public class PluginManager implements Closeable
_authenticationManagerPlugins.put(pluginFactory.getPluginName(), pluginFactory);
}
- // Check the plugin directory path is set and exist
- if (pluginPath == null)
- {
- return;
- }
- File pluginDir = new File(pluginPath);
- if (!pluginDir.exists())
+ if(bundleContext == null)
{
- return;
- }
-
- // Setup OSGi configuration propery map
- StringMap configMap = new StringMap(false);
-
- // Add the bundle provided service interface package and the core OSGi
- // packages to be exported from the class path via the system bundle.
- configMap.put(FRAMEWORK_SYSTEMPACKAGES,
- "org.osgi.framework; version=1.3.0," +
- "org.osgi.service.packageadmin; version=1.2.0," +
- "org.osgi.service.startlevel; version=1.0.0," +
- "org.osgi.service.url; version=1.0.0," +
- "org.osgi.util.tracker; version=1.0.0," +
- "org.apache.qpid.junit.extensions.util; " + QPID_VER_SUFFIX +
- "org.apache.qpid; " + QPID_VER_SUFFIX +
- "org.apache.qpid.common; " + QPID_VER_SUFFIX +
- "org.apache.qpid.exchange; " + QPID_VER_SUFFIX +
- "org.apache.qpid.framing; " + QPID_VER_SUFFIX +
- "org.apache.qpid.management.common.mbeans.annotations; " + QPID_VER_SUFFIX +
- "org.apache.qpid.protocol; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.binding; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.configuration; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.configuration.plugins; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.configuration.management; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.exchange; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.logging; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.logging.actors; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.logging.subjects; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.management; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.persistent; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.plugins; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.protocol; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.queue; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.registry; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.security; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.security.access; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.security.access.plugins; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.virtualhost; " + QPID_VER_SUFFIX +
- "org.apache.qpid.server.virtualhost.plugins; " + QPID_VER_SUFFIX +
- "org.apache.qpid.util; " + QPID_VER_SUFFIX +
- "org.apache.commons.configuration; version=1.0.0," +
- "org.apache.commons.lang; version=1.0.0," +
- "org.apache.commons.lang.builder; version=1.0.0," +
- "org.apache.commons.logging; version=1.0.0," +
- "org.apache.log4j; version=1.2.12," +
- "javax.management.openmbean; version=1.0.0," +
- "javax.management; version=1.0.0," +
- "javax.security.auth; version=1.0.0"
- );
-
- // No automatic shutdown hook
- configMap.put("felix.shutdown.hook", "false");
-
- // Add system activator
- List<BundleActivator> activators = new ArrayList<BundleActivator>();
- _activator = new Activator();
- activators.add(_activator);
- configMap.put(SYSTEMBUNDLE_ACTIVATORS_PROP, activators);
+ // Check the plugin directory path is set and exist
+ if (pluginPath == null)
+ {
+ _logger.info("No plugin path specified, no plugins will be loaded.");
+ return;
+ }
+ File pluginDir = new File(pluginPath);
+ if (!pluginDir.exists())
+ {
+ _logger.warn("Plugin dir : " + pluginDir + " does not exist.");
+ return;
+ }
- if (cachePath != null)
- {
- File cacheDir = new File(cachePath);
- if (!cacheDir.exists() && cacheDir.canWrite())
+ // Add the bundle provided service interface package and the core OSGi
+ // packages to be exported from the class path via the system bundle.
+
+ // Setup OSGi configuration property map
+ final StringMap configMap = new StringMap(false);
+ configMap.put(FRAMEWORK_SYSTEMPACKAGES, OSGI_SYSTEM_PACKAGES);
+
+ // No automatic shutdown hook
+ configMap.put("felix.shutdown.hook", "false");
+
+ // Add system activator
+ List<BundleActivator> activators = new ArrayList<BundleActivator>();
+ _activator = new Activator();
+ activators.add(_activator);
+ configMap.put(SYSTEMBUNDLE_ACTIVATORS_PROP, activators);
+
+ if (cachePath != null)
{
- _logger.info("Creating plugin cache directory: " + cachePath);
- cacheDir.mkdir();
+ File cacheDir = new File(cachePath);
+ if (!cacheDir.exists() && cacheDir.canWrite())
+ {
+ _logger.info("Creating plugin cache directory: " + cachePath);
+ cacheDir.mkdir();
+ }
+
+ // Set plugin cache directory and empty it
+ _logger.info("Cache bundles in directory " + cachePath);
+ configMap.put(FRAMEWORK_STORAGE, cachePath);
}
-
- // Set plugin cache directory and empty it
- _logger.info("Cache bundles in directory " + cachePath);
- configMap.put(FRAMEWORK_STORAGE, cachePath);
- }
- configMap.put(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
-
- // Set directory with plugins to auto-deploy
- _logger.info("Auto deploying bundles from directory " + pluginPath);
- configMap.put(AUTO_DEPLOY_DIR_PROPERY, pluginPath);
- configMap.put(AUTO_DEPLOY_ACTION_PROPERY, AUTO_DEPLOY_INSTALL_VALUE + "," + AUTO_DEPLOY_START_VALUE);
-
- // Start plugin manager and trackers
- _felix = new Felix(configMap);
- try
- {
- _logger.info("Starting plugin manager...");
- _felix.init();
- process(configMap, _felix.getBundleContext());
- _felix.start();
- _logger.info("Started plugin manager");
+ configMap.put(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
+
+ // Set directory with plugins to auto-deploy
+ _logger.info("Auto deploying bundles from directory " + pluginPath);
+ configMap.put(AUTO_DEPLOY_DIR_PROPERY, pluginPath);
+ configMap.put(AUTO_DEPLOY_ACTION_PROPERY, AUTO_DEPLOY_INSTALL_VALUE + "," + AUTO_DEPLOY_START_VALUE);
+
+ // Start plugin manager
+ _felix = new Felix(configMap);
+ try
+ {
+ _logger.info("Starting plugin manager framework");
+ _felix.init();
+ process(configMap, _felix.getBundleContext());
+ _felix.start();
+ _logger.info("Started plugin manager framework");
+ }
+ catch (BundleException e)
+ {
+ throw new ConfigurationException("Could not start plugin manager: " + e.getMessage(), e);
+ }
+
+ bundleContext = _activator.getContext();
}
- catch (BundleException e)
+ else
{
- throw new ConfigurationException("Could not start plugin manager: " + e.getMessage(), e);
+ _logger.info("Using the specified external BundleContext");
}
-
+
// TODO save trackers in a map, keyed by class name
- _exchangeTracker = new ServiceTracker(_activator.getContext(), ExchangeType.class.getName(), null);
+ _exchangeTracker = new ServiceTracker(bundleContext, ExchangeType.class.getName(), null);
_exchangeTracker.open();
- _securityTracker = new ServiceTracker(_activator.getContext(), SecurityPluginFactory.class.getName(), null);
+ _securityTracker = new ServiceTracker(bundleContext, SecurityPluginFactory.class.getName(), null);
_securityTracker.open();
- _configTracker = new ServiceTracker(_activator.getContext(), ConfigurationPluginFactory.class.getName(), null);
+ _configTracker = new ServiceTracker(bundleContext, ConfigurationPluginFactory.class.getName(), null);
_configTracker.open();
- _virtualHostTracker = new ServiceTracker(_activator.getContext(), VirtualHostPluginFactory.class.getName(), null);
+ _virtualHostTracker = new ServiceTracker(bundleContext, VirtualHostPluginFactory.class.getName(), null);
_virtualHostTracker.open();
- _policyTracker = new ServiceTracker(_activator.getContext(), SlowConsumerPolicyPluginFactory.class.getName(), null);
+ _policyTracker = new ServiceTracker(bundleContext, SlowConsumerPolicyPluginFactory.class.getName(), null);
_policyTracker.open();
- _authenticationManagerTracker = new ServiceTracker(_activator.getContext(), AuthenticationManagerPluginFactory.class.getName(), null);
+ _authenticationManagerTracker = new ServiceTracker(bundleContext, AuthenticationManagerPluginFactory.class.getName(), null);
_authenticationManagerTracker.open();
_logger.info("Opened service trackers");
@@ -331,21 +350,21 @@ public class PluginManager implements Closeable
public void close()
{
- if (_felix != null)
+ try
{
- try
- {
- // Close all bundle trackers
- _exchangeTracker.close();
- _securityTracker.close();
- _configTracker.close();
- _virtualHostTracker.close();
- _policyTracker.close();
- _authenticationManagerTracker.close();
- }
- finally
+ // Close all bundle trackers
+ _exchangeTracker.close();
+ _securityTracker.close();
+ _configTracker.close();
+ _virtualHostTracker.close();
+ _policyTracker.close();
+ _authenticationManagerTracker.close();
+ }
+ finally
+ {
+ if (_felix != null)
{
- _logger.info("Stopping plugin manager");
+ _logger.info("Stopping plugin manager framework");
try
{
// FIXME should be stopAndWait() but hangs VM, need upgrade in felix
@@ -364,7 +383,12 @@ public class PluginManager implements Closeable
{
// Ignore
}
- _logger.info("Stopped plugin manager");
+ _logger.info("Stopped plugin manager framework");
+ }
+ else
+ {
+ _logger.info("Plugin manager was started with an external BundleContext, " +
+ "skipping remaining shutdown tasks");
}
}
}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
index 460ea93509..8a7159bdc2 100755
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactory.java
@@ -20,7 +20,6 @@
*/
package org.apache.qpid.server.protocol;
-import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
@@ -32,23 +31,12 @@ import org.apache.qpid.transport.network.NetworkConnection;
public class MultiVersionProtocolEngineFactory implements ProtocolEngineFactory
{
- private static final Set<AmqpProtocolVersion> ALL_VERSIONS = EnumSet.allOf(AmqpProtocolVersion.class);
private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
private final IApplicationRegistry _appRegistry;
private final String _fqdn;
private final Set<AmqpProtocolVersion> _supported;
- public MultiVersionProtocolEngineFactory()
- {
- this("localhost", ALL_VERSIONS);
- }
-
- public MultiVersionProtocolEngineFactory(String fqdn)
- {
- this(fqdn, ALL_VERSIONS);
- }
-
public MultiVersionProtocolEngineFactory(String fqdn, Set<AmqpProtocolVersion> supportedVersions)
{
_appRegistry = ApplicationRegistry.getInstance();
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
index bfdb30764a..c07074f69c 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
@@ -65,6 +65,7 @@ import org.apache.qpid.server.transport.QpidAcceptor;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.server.virtualhost.VirtualHostImpl;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.osgi.framework.BundleContext;
/**
@@ -111,6 +112,8 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
private boolean _statisticsEnabled = false;
private StatisticsCounter _messagesDelivered, _dataDelivered, _messagesReceived, _dataReceived;
+ private BundleContext _bundleContext;
+
static
{
Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownService()));
@@ -209,7 +212,13 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
protected ApplicationRegistry(ServerConfiguration configuration)
{
+ this(configuration, null);
+ }
+
+ protected ApplicationRegistry(ServerConfiguration configuration, BundleContext bundleContext)
+ {
_configuration = configuration;
+ _bundleContext = bundleContext;
}
public void configure() throws ConfigurationException
@@ -218,7 +227,7 @@ public abstract class ApplicationRegistry implements IApplicationRegistry
try
{
- _pluginManager = new PluginManager(_configuration.getPluginDirectory(), _configuration.getCacheDirectory());
+ _pluginManager = new PluginManager(_configuration.getPluginDirectory(), _configuration.getCacheDirectory(), _bundleContext);
}
catch (Exception e)
{
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java
index ff2a8c959b..9121f8f927 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ConfigurationFileApplicationRegistry.java
@@ -29,12 +29,18 @@ import org.apache.qpid.server.logging.actors.BrokerActor;
import org.apache.qpid.server.logging.actors.CurrentActor;
import org.apache.qpid.server.management.JMXManagedObjectRegistry;
import org.apache.qpid.server.management.NoopManagedObjectRegistry;
+import org.osgi.framework.BundleContext;
public class ConfigurationFileApplicationRegistry extends ApplicationRegistry
{
public ConfigurationFileApplicationRegistry(File configurationURL) throws ConfigurationException
{
- super(new ServerConfiguration(configurationURL));
+ this(configurationURL, null);
+ }
+
+ public ConfigurationFileApplicationRegistry(File configurationURL, BundleContext bundleContext) throws ConfigurationException
+ {
+ super(new ServerConfiguration(configurationURL), bundleContext);
}
@Override
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java
index d6a09d8217..d6f6c714e2 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/security/auth/sasl/JCAProvider.java
@@ -21,12 +21,11 @@
package org.apache.qpid.server.security.auth.sasl;
import java.security.Provider;
-import java.security.Security;
import java.util.Map;
import javax.security.sasl.SaslServerFactory;
-public final class JCAProvider extends Provider
+public class JCAProvider extends Provider
{
public JCAProvider(String name, Map<String, Class<? extends SaslServerFactory>> providerMap)
{
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java
new file mode 100644
index 0000000000..4e3fae1dbd
--- /dev/null
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/signal/SignalHandlerTask.java
@@ -0,0 +1,89 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.signal;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.apache.log4j.Logger;
+
+public abstract class SignalHandlerTask
+{
+ private static final Logger LOGGER = Logger.getLogger(SignalHandlerTask.class);
+
+ private static final String HANDLE_METHOD = "handle";
+ private static final String SUN_MISC_SIGNAL_CLASS = "sun.misc.Signal";
+ private static final String SUN_MISC_SIGNAL_HANDLER_CLASS = "sun.misc.SignalHandler";
+
+ public boolean register(final String signalName)
+ {
+ try
+ {
+ //try to load the signal handling classes
+ Class<?> signalClazz = Class.forName(SUN_MISC_SIGNAL_CLASS);
+ Class<?> handlerClazz = Class.forName(SUN_MISC_SIGNAL_HANDLER_CLASS);
+
+ //create an InvocationHandler that just executes the SignalHandlerTask
+ InvocationHandler invoker = new InvocationHandler()
+ {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ handle();
+
+ return null;
+ }
+ };
+
+ //create a dynamic proxy implementing SignalHandler
+ Object handler = Proxy.newProxyInstance(handlerClazz.getClassLoader(), new Class[]{handlerClazz}, invoker);
+
+ //create the Signal to handle
+ Constructor<?> signalConstructor = signalClazz.getConstructor(String.class);
+ Object signal = signalConstructor.newInstance(signalName);
+
+ //invoke the Signal.handle(signal, handler) method
+ Method handleMethod = signalClazz.getMethod(HANDLE_METHOD, signalClazz, handlerClazz);
+ handleMethod.invoke(null, signal, handler);
+ }
+ catch (Exception e)
+ {
+ LOGGER.debug("Unable to register handler for Signal " + signalName + " due to exception: " + e, e);
+ return false;
+ }
+
+ return true;
+ }
+
+ public abstract void handle();
+
+ public static String getPlatformDescription()
+ {
+ String name = System.getProperty("os.name");
+ String osVer = System.getProperty("os.version");
+ String jvmVendor = System.getProperty("java.vm.vendor");
+ String jvmName = System.getProperty("java.vm.name");
+ String javaRuntimeVer = System.getProperty("java.runtime.version");
+
+ return "OS: " + name + " " + osVer + ", JVM:" + jvmVendor + " " + jvmName + " " + javaRuntimeVer;
+ }
+}
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java
index 0f6480253c..0921decda4 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/subscription/Subscription_0_10.java
@@ -109,15 +109,15 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
private final MessageAcquireMode _acquireMode;
private MessageFlowMode _flowMode;
private final ServerSession _session;
- private AtomicBoolean _stopped = new AtomicBoolean(true);
+ private final AtomicBoolean _stopped = new AtomicBoolean(true);
private static final Struct[] EMPTY_STRUCT_ARRAY = new Struct[0];
private LogActor _logActor;
- private Map<String, Object> _properties = new ConcurrentHashMap<String, Object>();
+ private final Map<String, Object> _properties = new ConcurrentHashMap<String, Object>();
private UUID _id;
private String _traceExclude;
private String _trace;
- private long _createTime = System.currentTimeMillis();
+ private final long _createTime = System.currentTimeMillis();
private final AtomicLong _deliveredCount = new AtomicLong(0);
private final Map<String, Object> _arguments;
@@ -711,13 +711,22 @@ public class Subscription_0_10 implements Subscription, FlowCreditManager.FlowCr
public void stop()
{
- if(_state.compareAndSet(State.ACTIVE, State.SUSPENDED))
+ try
{
- _stateListener.stateChange(this, State.ACTIVE, State.SUSPENDED);
+ getSendLock();
+
+ if(_state.compareAndSet(State.ACTIVE, State.SUSPENDED))
+ {
+ _stateListener.stateChange(this, State.ACTIVE, State.SUSPENDED);
+ }
+ _stopped.set(true);
+ FlowCreditManager_0_10 creditManager = getCreditManager();
+ creditManager.clearCredit();
+ }
+ finally
+ {
+ releaseSendLock();
}
- _stopped.set(true);
- FlowCreditManager_0_10 creditManager = getCreditManager();
- creditManager.clearCredit();
}
public void addCredit(MessageCreditUnit unit, long value)
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
index b0893eb53f..37375c2b7b 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/ServerConfigurationTest.java
@@ -511,7 +511,7 @@ public class ServerConfigurationTest extends QpidTestCase
{
// Check default
_serverConfig.initialise();
- assertEquals("none", _serverConfig.getKeystorePath());
+ assertNull(_serverConfig.getKeystorePath());
// Check value we set
_config.setProperty("connector.ssl.keystorePath", "a");
@@ -524,7 +524,7 @@ public class ServerConfigurationTest extends QpidTestCase
{
// Check default
_serverConfig.initialise();
- assertEquals("none", _serverConfig.getKeystorePassword());
+ assertNull(_serverConfig.getKeystorePassword());
// Check value we set
_config.setProperty("connector.ssl.keystorePassword", "a");
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/MockPluginManager.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/MockPluginManager.java
deleted file mode 100644
index a64ec5d3b1..0000000000
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/MockPluginManager.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.qpid.server.plugins;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.qpid.server.configuration.plugins.ConfigurationPluginFactory;
-import org.apache.qpid.server.exchange.ExchangeType;
-import org.apache.qpid.server.security.SecurityPluginFactory;
-
-public class MockPluginManager extends PluginManager
-{
- private Map<String, SecurityPluginFactory> _securityPlugins = new HashMap<String, SecurityPluginFactory>();
- private Map<List<String>, ConfigurationPluginFactory> _configPlugins = new HashMap<List<String>, ConfigurationPluginFactory>();
-
- public MockPluginManager(String pluginPath, String cachePath) throws Exception
- {
- super(pluginPath, cachePath);
- }
-
- @Override
- public Map<String, ExchangeType<?>> getExchanges()
- {
- return null;
- }
-
- @Override
- public Map<String, SecurityPluginFactory> getSecurityPlugins()
- {
- return _securityPlugins;
- }
-
- @Override
- public Map<List<String>, ConfigurationPluginFactory> getConfigurationPlugins()
- {
- return _configPlugins;
- }
-}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java
new file mode 100644
index 0000000000..4a03445357
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/OsgiSystemPackageUtilTest.java
@@ -0,0 +1,93 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.plugins;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.osgi.framework.Version;
+
+/**
+ *
+ */
+public class OsgiSystemPackageUtilTest extends QpidTestCase
+{
+ private OsgiSystemPackageUtil _util = null; // Object under test
+
+ private Map<String, String> _map = new TreeMap<String, String>(); // Use a TreeMap for unit test in order for determinstic results.
+
+ public void testWithOnePackage() throws Exception
+ {
+ _map.put("org.xyz", "1.0.0");
+
+ _util = new OsgiSystemPackageUtil(null, _map);
+
+ final String systemPackageString = _util.getFormattedSystemPackageString();
+
+ assertEquals("org.xyz; version=1.0.0", systemPackageString);
+ }
+
+ public void testWithTwoPackages() throws Exception
+ {
+ _map.put("org.xyz", "1.0.0");
+ _map.put("org.abc", "1.2.3");
+
+ _util = new OsgiSystemPackageUtil(null, _map);
+
+ final String systemPackageString = _util.getFormattedSystemPackageString();
+
+ assertEquals("org.abc; version=1.2.3, org.xyz; version=1.0.0", systemPackageString);
+ }
+
+ public void testWithNoPackages() throws Exception
+ {
+ _util = new OsgiSystemPackageUtil(null, _map);
+
+ final String systemPackageString = _util.getFormattedSystemPackageString();
+
+ assertNull(systemPackageString);
+ }
+
+ public void testWithQpidPackageWithQpidReleaseNumberSet() throws Exception
+ {
+ _map.put("org.apache.qpid.xyz", "1.0.0");
+ _map.put("org.abc", "1.2.3");
+
+ _util = new OsgiSystemPackageUtil(new Version("0.13"), _map);
+
+ final String systemPackageString = _util.getFormattedSystemPackageString();
+
+ assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=0.13.0", systemPackageString);
+ }
+
+ public void testWithQpidPackageWithoutQpidReleaseNumberSet() throws Exception
+ {
+ _map.put("org.apache.qpid.xyz", "1.0.0");
+ _map.put("org.abc", "1.2.3");
+
+ _util = new OsgiSystemPackageUtil(null, _map);
+
+ final String systemPackageString = _util.getFormattedSystemPackageString();
+
+ assertEquals("org.abc; version=1.2.3, org.apache.qpid.xyz; version=1.0.0", systemPackageString);
+ }
+}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java
index 8c18ab85b0..8c945aabfb 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/plugins/PluginTest.java
@@ -49,7 +49,7 @@ public class PluginTest extends InternalBrokerBaseCase
public void testNoExchanges() throws Exception
{
- PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp");
+ PluginManager manager = new PluginManager("/path/to/nowhere", "/tmp", null);
Map<String, ExchangeType<?>> exchanges = manager.getExchanges();
assertTrue("Exchanges found", exchanges.isEmpty());
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java
new file mode 100644
index 0000000000..886cb080aa
--- /dev/null
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/signal/SignalHandlerTaskTest.java
@@ -0,0 +1,118 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.signal;
+
+import java.lang.management.ManagementFactory;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class SignalHandlerTaskTest extends QpidTestCase
+{
+ private static final Logger LOGGER = Logger.getLogger(SignalHandlerTaskTest.class);
+ private static final String SUN_MISC_SIGNAL_CLASS = "sun.misc.Signal";
+ private static final String SUN_MISC_SIGNAL_HANDLER_CLASS = "sun.misc.SignalHandler";
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ public void testSignalHandlerTask() throws Exception
+ {
+ final boolean expectedResult = classifyExpectedRegistrationResult();
+ final int pid = getPID();
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ SignalHandlerTask hupReparseTask = new SignalHandlerTask()
+ {
+ public void handle()
+ {
+ latch.countDown();
+ LOGGER.info("Signal handled, latch decremented");
+ }
+ };
+
+ assertEquals("Unexpected result trying to register Signal handler",
+ expectedResult, hupReparseTask.register("HUP"));
+ LOGGER.info("Signal handler was registered");
+
+ assertEquals("unexpected count for the latch", 1, latch.getCount());
+
+ if(expectedResult)
+ {
+ //registration succeeded as expected, so now
+ //send SIGHUP and verify the handler was run
+ String cmd = "/bin/kill -SIGHUP " + pid;
+
+ LOGGER.info("Sending SIGHUP");
+ Runtime.getRuntime().exec(cmd);
+
+ assertTrue("HUP Signal was not handled in the allowed timeframe",
+ latch.await(5, TimeUnit.SECONDS));
+ }
+ }
+
+ public void testGetPlatformDescription() throws Exception
+ {
+ assertNotNull(SignalHandlerTask.getPlatformDescription());
+ }
+
+ private boolean classifyExpectedRegistrationResult()
+ {
+ String os = System.getProperty("os.name");
+ if(String.valueOf(os).toLowerCase().contains("windows"))
+ {
+ //Windows does not support SIGHUP so registration will fail
+ LOGGER.info("Running on windows, so we expect SIGHUP handler registration to fail");
+ return false;
+ }
+
+ //otherwise, if the signal handler classes are present we would expect
+ //registration to succeed
+ boolean classesPresent = true;
+ try
+ {
+ Class.forName(SUN_MISC_SIGNAL_CLASS);
+ Class.forName(SUN_MISC_SIGNAL_HANDLER_CLASS);
+ LOGGER.info("Signal handling classes were present so we expect SIGHUP handler registration to succeed");
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ classesPresent = false;
+ }
+
+ return classesPresent;
+ }
+
+ private int getPID()
+ {
+ String processName = ManagementFactory.getRuntimeMXBean().getName();
+
+ int pid = Integer.parseInt(processName.substring(0,processName.indexOf('@')));
+ LOGGER.info("PID was determined to be " + pid);
+
+ return pid;
+ }
+
+}
diff --git a/qpid/java/build.xml b/qpid/java/build.xml
index 1fb52c5c2a..4761bad877 100644
--- a/qpid/java/build.xml
+++ b/qpid/java/build.xml
@@ -23,7 +23,7 @@
<import file="common.xml"/>
<findSubProjects name="broker-plugins" dir="broker-plugins"/>
- <findSubProjects name="client-plugins" dir="client-plugins" erroronmissingdir="false"/>
+ <findSubProjects name="client-plugins" dir="client-plugins"/>
<findSubProjects name="management" dir="management" excludes="common,example"/>
<property name="modules.core" value="junit-toolkit common management/common amqp-1-0-common broker client amqp-1-0-client amqp-1-0-client-jms tools"/>
diff --git a/qpid/java/client-plugins/.gitignore b/qpid/java/client-plugins/.gitignore
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/qpid/java/client-plugins/.gitignore
diff --git a/qpid/java/client-plugins/README.txt b/qpid/java/client-plugins/README.txt
new file mode 100644
index 0000000000..64884f27a2
--- /dev/null
+++ b/qpid/java/client-plugins/README.txt
@@ -0,0 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+Placeholder directory to allow for the building of client side optional modules such as transports or custom SASL modules etc. Analogous to
+broker-plugins.
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
index c8576bf00d..c0d4d8a893 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQBrokerDetails.java
@@ -26,7 +26,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.qpid.jms.BrokerDetails;
-import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.url.URLHelper;
import org.apache.qpid.url.URLSyntaxException;
@@ -38,8 +38,6 @@ public class AMQBrokerDetails implements BrokerDetails
private Map<String, String> _options = new HashMap<String, String>();
- private SSLConfiguration _sslConfiguration;
-
public AMQBrokerDetails(){}
public AMQBrokerDetails(String url) throws URLSyntaxException
@@ -200,11 +198,10 @@ public class AMQBrokerDetails implements BrokerDetails
}
}
- public AMQBrokerDetails(String host, int port, SSLConfiguration sslConfiguration)
+ public AMQBrokerDetails(String host, int port)
{
_host = host;
_port = port;
- _sslConfiguration = sslConfiguration;
}
public String getHost()
@@ -280,16 +277,6 @@ public class AMQBrokerDetails implements BrokerDetails
setProperty(OPTIONS_CONNECT_TIMEOUT, Long.toString(timeout));
}
- public SSLConfiguration getSSLConfiguration()
- {
- return _sslConfiguration;
- }
-
- public void setSSLConfiguration(SSLConfiguration sslConfig)
- {
- _sslConfiguration = sslConfig;
- }
-
public String toString()
{
StringBuffer sb = new StringBuffer();
@@ -316,9 +303,8 @@ public class AMQBrokerDetails implements BrokerDetails
return _host.equalsIgnoreCase(bd.getHost()) &&
(_port == bd.getPort()) &&
- _transport.equalsIgnoreCase(bd.getTransport()) &&
- compareSSLConfigurations(bd.getSSLConfiguration());
- //todo do we need to compare all the options as well?
+ _transport.equalsIgnoreCase(bd.getTransport());
+ //TODO do we need to compare all the options as well?
}
@Override
@@ -359,24 +345,6 @@ public class AMQBrokerDetails implements BrokerDetails
return optionsURL.toString();
}
- // Do we need to do a more in-depth comparison?
- private boolean compareSSLConfigurations(SSLConfiguration other)
- {
- boolean retval = false;
- if (_sslConfiguration == null &&
- other == null)
- {
- retval = true;
- }
- else if (_sslConfiguration != null &&
- other != null)
- {
- retval = true;
- }
-
- return retval;
- }
-
public static String checkTransport(String broker)
{
if ((!broker.contains("://")))
@@ -398,4 +366,82 @@ public class AMQBrokerDetails implements BrokerDetails
{
_options = props;
}
+
+ public ConnectionSettings buildConnectionSettings()
+ {
+ ConnectionSettings conSettings = new ConnectionSettings();
+
+ conSettings.setHost(getHost());
+ conSettings.setPort(getPort());
+
+ // ------------ sasl options ---------------
+ if (getProperty(BrokerDetails.OPTIONS_SASL_MECHS) != null)
+ {
+ conSettings.setSaslMechs(
+ getProperty(BrokerDetails.OPTIONS_SASL_MECHS));
+ }
+
+ // Sun SASL Kerberos client uses the
+ // protocol + servername as the service key.
+
+ if (getProperty(BrokerDetails.OPTIONS_SASL_PROTOCOL_NAME) != null)
+ {
+ conSettings.setSaslProtocol(
+ getProperty(BrokerDetails.OPTIONS_SASL_PROTOCOL_NAME));
+ }
+
+
+ if (getProperty(BrokerDetails.OPTIONS_SASL_SERVER_NAME) != null)
+ {
+ conSettings.setSaslServerName(
+ getProperty(BrokerDetails.OPTIONS_SASL_SERVER_NAME));
+ }
+
+ conSettings.setUseSASLEncryption(
+ getBooleanProperty(BrokerDetails.OPTIONS_SASL_ENCRYPTION));
+
+ // ------------- ssl options ---------------------
+ conSettings.setUseSSL(getBooleanProperty(BrokerDetails.OPTIONS_SSL));
+
+ if (getProperty(BrokerDetails.OPTIONS_TRUST_STORE) != null)
+ {
+ conSettings.setTrustStorePath(
+ getProperty(BrokerDetails.OPTIONS_TRUST_STORE));
+ }
+
+ if (getProperty(BrokerDetails.OPTIONS_TRUST_STORE_PASSWORD) != null)
+ {
+ conSettings.setTrustStorePassword(
+ getProperty(BrokerDetails.OPTIONS_TRUST_STORE_PASSWORD));
+ }
+
+ if (getProperty(BrokerDetails.OPTIONS_KEY_STORE) != null)
+ {
+ conSettings.setKeyStorePath(
+ getProperty(BrokerDetails.OPTIONS_KEY_STORE));
+ }
+
+ if (getProperty(BrokerDetails.OPTIONS_KEY_STORE_PASSWORD) != null)
+ {
+ conSettings.setKeyStorePassword(
+ getProperty(BrokerDetails.OPTIONS_KEY_STORE_PASSWORD));
+ }
+
+ if (getProperty(BrokerDetails.OPTIONS_SSL_CERT_ALIAS) != null)
+ {
+ conSettings.setCertAlias(
+ getProperty(BrokerDetails.OPTIONS_SSL_CERT_ALIAS));
+ }
+ // ----------------------------
+
+ conSettings.setVerifyHostname(getBooleanProperty(BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME));
+
+ if (getProperty(BrokerDetails.OPTIONS_TCP_NO_DELAY) != null)
+ {
+ conSettings.setTcpNodelay(
+ getBooleanProperty(BrokerDetails.OPTIONS_TCP_NO_DELAY));
+ }
+
+ return conSettings;
+ }
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
index 4a62f443f1..c38188cdc3 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnection.java
@@ -147,9 +147,6 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
*/
private QpidConnectionMetaData _connectionMetaData;
- /** Configuration info for SSL */
- private SSLConfiguration _sslConfiguration;
-
private AMQShortString _defaultTopicExchangeName = ExchangeDefaults.TOPIC_EXCHANGE_NAME;
private AMQShortString _defaultQueueExchangeName = ExchangeDefaults.DIRECT_EXCHANGE_NAME;
private AMQShortString _temporaryTopicExchangeName = ExchangeDefaults.TOPIC_EXCHANGE_NAME;
@@ -194,68 +191,27 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
this(new AMQConnectionURL(
ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
+ ((clientName == null) ? "" : clientName) + "/" + virtualHost + "?brokerlist='"
- + AMQBrokerDetails.checkTransport(broker) + "'"), null);
- }
-
- /**
- * @param broker brokerdetails
- * @param username username
- * @param password password
- * @param clientName clientid
- * @param virtualHost virtualhost
- *
- * @throws AMQException
- * @throws URLSyntaxException
- */
- public AMQConnection(String broker, String username, String password, String clientName, String virtualHost,
- SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
- {
- this(new AMQConnectionURL(
- ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
- + ((clientName == null) ? "" : clientName) + "/" + virtualHost + "?brokerlist='"
- + AMQBrokerDetails.checkTransport(broker) + "'"), sslConfig);
+ + AMQBrokerDetails.checkTransport(broker) + "'"));
}
public AMQConnection(String host, int port, String username, String password, String clientName, String virtualHost)
throws AMQException, URLSyntaxException
{
- this(host, port, false, username, password, clientName, virtualHost, null);
- }
-
- public AMQConnection(String host, int port, String username, String password, String clientName, String virtualHost,
- SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
- {
- this(host, port, false, username, password, clientName, virtualHost, sslConfig);
- }
-
- public AMQConnection(String host, int port, boolean useSSL, String username, String password, String clientName,
- String virtualHost, SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
- {
this(new AMQConnectionURL(
- useSSL
- ? (ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
- + ((clientName == null) ? "" : clientName) + virtualHost + "?brokerlist='tcp://" + host + ":" + port
- + "'" + "," + BrokerDetails.OPTIONS_SSL + "='true'")
- : (ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
- + ((clientName == null) ? "" : clientName) + virtualHost + "?brokerlist='tcp://" + host + ":" + port
- + "'" + "," + BrokerDetails.OPTIONS_SSL + "='false'")), sslConfig);
+ ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@"
+ + ((clientName == null) ? "" : clientName) + virtualHost + "?brokerlist='tcp://" + host + ":" + port + "'"));
}
public AMQConnection(String connection) throws AMQException, URLSyntaxException
{
- this(new AMQConnectionURL(connection), null);
- }
-
- public AMQConnection(String connection, SSLConfiguration sslConfig) throws AMQException, URLSyntaxException
- {
- this(new AMQConnectionURL(connection), sslConfig);
+ this(new AMQConnectionURL(connection));
}
/**
* @todo Some horrible stuff going on here with setting exceptions to be non-null to detect if an exception
* was thrown during the connection! Intention not clear. Use a flag anyway, not exceptions... Will fix soon.
*/
- public AMQConnection(ConnectionURL connectionURL, SSLConfiguration sslConfig) throws AMQException
+ public AMQConnection(ConnectionURL connectionURL) throws AMQException
{
if (connectionURL == null)
{
@@ -350,7 +306,6 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
_logger.info("Connection:" + connectionURL);
}
- _sslConfiguration = sslConfig;
_connectionURL = connectionURL;
_clientName = connectionURL.getClientName();
@@ -548,7 +503,7 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
public boolean attemptReconnection(String host, int port)
{
- BrokerDetails bd = new AMQBrokerDetails(host, port, _sslConfiguration);
+ BrokerDetails bd = new AMQBrokerDetails(host, port);
_failoverPolicy.setBroker(bd);
@@ -1376,11 +1331,6 @@ public class AMQConnection extends Closeable implements Connection, QueueConnect
AMQConnectionFactory.class.getName(), null); // factory location
}
- public SSLConfiguration getSSLConfiguration()
- {
- return _sslConfiguration;
- }
-
public AMQShortString getDefaultTopicExchangeName()
{
return _defaultTopicExchangeName;
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
index cb531d4fca..6b9cf909a8 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
@@ -191,8 +191,7 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec
+ _conn.getPassword());
}
- ConnectionSettings conSettings = new ConnectionSettings();
- retriveConnectionSettings(conSettings,brokerDetail);
+ ConnectionSettings conSettings = retriveConnectionSettings(brokerDetail);
_qpidConnection.connect(conSettings);
_conn._connected = true;
@@ -352,77 +351,14 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec
return (String)_qpidConnection.getServerProperties().get(UUID_NAME);
}
- private void retriveConnectionSettings(ConnectionSettings conSettings, BrokerDetails brokerDetail)
+ private ConnectionSettings retriveConnectionSettings(BrokerDetails brokerDetail)
{
+ ConnectionSettings conSettings = brokerDetail.buildConnectionSettings();
- conSettings.setHost(brokerDetail.getHost());
- conSettings.setPort(brokerDetail.getPort());
conSettings.setVhost(_conn.getVirtualHost());
conSettings.setUsername(_conn.getUsername());
conSettings.setPassword(_conn.getPassword());
- // ------------ sasl options ---------------
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_SASL_MECHS) != null)
- {
- conSettings.setSaslMechs(
- brokerDetail.getProperty(BrokerDetails.OPTIONS_SASL_MECHS));
- }
-
- // Sun SASL Kerberos client uses the
- // protocol + servername as the service key.
-
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_SASL_PROTOCOL_NAME) != null)
- {
- conSettings.setSaslProtocol(
- brokerDetail.getProperty(BrokerDetails.OPTIONS_SASL_PROTOCOL_NAME));
- }
-
-
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_SASL_SERVER_NAME) != null)
- {
- conSettings.setSaslServerName(
- brokerDetail.getProperty(BrokerDetails.OPTIONS_SASL_SERVER_NAME));
- }
-
- conSettings.setUseSASLEncryption(
- brokerDetail.getBooleanProperty(BrokerDetails.OPTIONS_SASL_ENCRYPTION));
-
- // ------------- ssl options ---------------------
- conSettings.setUseSSL(brokerDetail.getBooleanProperty(BrokerDetails.OPTIONS_SSL));
-
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_TRUST_STORE) != null)
- {
- conSettings.setTrustStorePath(
- brokerDetail.getProperty(BrokerDetails.OPTIONS_TRUST_STORE));
- }
-
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_TRUST_STORE_PASSWORD) != null)
- {
- conSettings.setTrustStorePassword(
- brokerDetail.getProperty(BrokerDetails.OPTIONS_TRUST_STORE_PASSWORD));
- }
-
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_KEY_STORE) != null)
- {
- conSettings.setKeyStorePath(
- brokerDetail.getProperty(BrokerDetails.OPTIONS_KEY_STORE));
- }
-
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_KEY_STORE_PASSWORD) != null)
- {
- conSettings.setKeyStorePassword(
- brokerDetail.getProperty(BrokerDetails.OPTIONS_KEY_STORE_PASSWORD));
- }
-
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_SSL_CERT_ALIAS) != null)
- {
- conSettings.setCertAlias(
- brokerDetail.getProperty(BrokerDetails.OPTIONS_SSL_CERT_ALIAS));
- }
- // ----------------------------
-
- conSettings.setVerifyHostname(brokerDetail.getBooleanProperty(BrokerDetails.OPTIONS_SSL_VERIFY_HOSTNAME));
-
// Pass client name from connection URL
Map<String, Object> clientProps = new HashMap<String, Object>();
try
@@ -434,14 +370,10 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, Connec
{
// Ignore
}
-
- if (brokerDetail.getProperty(BrokerDetails.OPTIONS_TCP_NO_DELAY) != null)
- {
- conSettings.setTcpNodelay(
- brokerDetail.getBooleanProperty(BrokerDetails.OPTIONS_TCP_NO_DELAY));
- }
-
+
conSettings.setHeartbeatInterval(getHeartbeatInterval(brokerDetail));
+
+ return conSettings;
}
// The idle_timeout prop is in milisecs while
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
index 0cd1d49224..8bc9889050 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_8_0.java
@@ -23,6 +23,7 @@ package org.apache.qpid.client;
import java.io.IOException;
import java.net.ConnectException;
import java.nio.channels.UnresolvedAddressException;
+import java.security.GeneralSecurityException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.EnumSet;
@@ -31,6 +32,7 @@ import java.util.Set;
import javax.jms.JMSException;
import javax.jms.XASession;
+import javax.net.ssl.SSLContext;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.failover.FailoverException;
@@ -93,20 +95,31 @@ public class AMQConnectionDelegate_8_0 implements AMQConnectionDelegate
StateWaiter waiter = _conn._protocolHandler.createWaiter(openOrClosedStates);
- ConnectionSettings settings = new ConnectionSettings();
- settings.setHost(brokerDetail.getHost());
- settings.setPort(brokerDetail.getPort());
+ ConnectionSettings settings = brokerDetail.buildConnectionSettings();
settings.setProtocol(brokerDetail.getTransport());
- SSLConfiguration sslConfig = _conn.getSSLConfiguration();
- SSLContextFactory sslFactory = null;
- if (sslConfig != null)
+ SSLContext sslContext = null;
+ if (settings.isUseSSL())
{
- sslFactory = new SSLContextFactory(sslConfig.getKeystorePath(), sslConfig.getKeystorePassword(), sslConfig.getCertType());
+ try
+ {
+ sslContext = SSLContextFactory.buildClientContext(
+ settings.getTrustStorePath(),
+ settings.getTrustStorePassword(),
+ settings.getTrustStoreCertType(),
+ settings.getKeyStorePath(),
+ settings.getKeyStorePassword(),
+ settings.getKeyStoreCertType(),
+ settings.getCertAlias());
+ }
+ catch (GeneralSecurityException e)
+ {
+ throw new AMQException("Unable to create SSLContext: " + e.getMessage(), e);
+ }
}
OutgoingNetworkTransport transport = Transport.getOutgoingTransportInstance(getProtocolVersion());
- NetworkConnection network = transport.connect(settings, _conn._protocolHandler, sslFactory);
+ NetworkConnection network = transport.connect(settings, _conn._protocolHandler, sslContext);
_conn._protocolHandler.setNetworkConnection(network);
_conn._protocolHandler.getProtocolSession().init();
// this blocks until the connection has been set up or when an error
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
index ec4c668d7e..fc2d6c94eb 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java
@@ -44,210 +44,34 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
ObjectFactory, Referenceable, XATopicConnectionFactory,
XAQueueConnectionFactory, XAConnectionFactory
{
- private String _host;
- private int _port;
- private String _defaultUsername;
- private String _defaultPassword;
- private String _virtualPath;
+ private final ConnectionURL _connectionDetails;
- private ConnectionURL _connectionDetails;
- private SSLConfiguration _sslConfig;
-
- public AMQConnectionFactory()
+ public AMQConnectionFactory(final String url) throws URLSyntaxException
{
- }
-
- /**
- * This is the Only constructor used!
- * It is used form the context and from the JNDI objects.
- */
- public AMQConnectionFactory(String url) throws URLSyntaxException
- {
- _connectionDetails = new AMQConnectionURL(url);
- }
-
- /**
- * This constructor is never used!
- */
- public AMQConnectionFactory(ConnectionURL url)
- {
- _connectionDetails = url;
- }
-
- /**
- * This constructor is never used!
- */
- public AMQConnectionFactory(String broker, String username, String password, String clientName, String virtualHost)
- throws URLSyntaxException
- {
- this(new AMQConnectionURL(
- ConnectionURL.AMQ_PROTOCOL + "://" + username + ":" + password + "@" + clientName + "/" + virtualHost + "?brokerlist='" + broker + "'"));
- }
-
- /**
- * This constructor is never used!
- */
- public AMQConnectionFactory(String host, int port, String virtualPath)
- {
- this(host, port, "guest", "guest", virtualPath);
- }
-
- /**
- * This constructor is never used!
- */
- public AMQConnectionFactory(String host, int port, String defaultUsername, String defaultPassword,
- String virtualPath)
- {
- _host = host;
- _port = port;
- _defaultUsername = defaultUsername;
- _defaultPassword = defaultPassword;
- _virtualPath = virtualPath;
-
-//todo when setting Host/Port has been resolved then we can use this otherwise those methods won't work with the following line.
-// _connectionDetails = new AMQConnectionURL(
-// ConnectionURL.AMQ_PROTOCOL + "://" +
-// _defaultUsername + ":" + _defaultPassword + "@" +
-// virtualPath + "?brokerlist='tcp://" + host + ":" + port + "'");
- }
-
- /**
- * @return The _defaultPassword.
- */
- public final String getDefaultPassword(String password)
- {
- if (_connectionDetails != null)
- {
- return _connectionDetails.getPassword();
- }
- else
- {
- return _defaultPassword;
- }
- }
-
- /**
- * @param password The _defaultPassword to set.
- */
- public final void setDefaultPassword(String password)
- {
- if (_connectionDetails != null)
+ if (url == null)
{
- _connectionDetails.setPassword(password);
+ throw new IllegalArgumentException("url cannot be null");
}
- _defaultPassword = password;
- }
-
- /**
- * Getter for SSLConfiguration
- *
- * @return SSLConfiguration if set, otherwise null
- */
- public final SSLConfiguration getSSLConfiguration()
- {
- return _sslConfig;
- }
-
- /**
- * Setter for SSLConfiguration
- *
- * @param sslConfig config to store
- */
- public final void setSSLConfiguration(SSLConfiguration sslConfig)
- {
- _sslConfig = sslConfig;
- }
- /**
- * @return The _defaultPassword.
- */
- public final String getDefaultUsername(String password)
- {
- if (_connectionDetails != null)
- {
- return _connectionDetails.getUsername();
- }
- else
- {
- return _defaultUsername;
- }
+ _connectionDetails = new AMQConnectionURL(url);
}
- /**
- * @param username The _defaultUsername to set.
- */
- public final void setDefaultUsername(String username)
+ public AMQConnectionFactory(ConnectionURL url)
{
- if (_connectionDetails != null)
+ if (url == null)
{
- _connectionDetails.setUsername(username);
+ throw new IllegalArgumentException("url cannot be null");
}
- _defaultUsername = username;
- }
-
- /**
- * @return The _host .
- */
- public final String getHost()
- {
- //todo this doesn't make sense in a multi broker URL as we have no current as that is done by AMQConnection
- return _host;
- }
- /**
- * @param host The _host to set.
- */
- public final void setHost(String host)
- {
- //todo if _connectionDetails is set then run _connectionDetails.addBrokerDetails()
- // Should perhaps have this method changed to setBroker(host,port)
- _host = host;
- }
-
- /**
- * @return _port The _port to set.
- */
- public final int getPort()
- {
- //todo see getHost
- return _port;
- }
-
- /**
- * @param port The port to set.
- */
- public final void setPort(int port)
- {
- //todo see setHost
- _port = port;
+ _connectionDetails = url;
}
/**
- * @return he _virtualPath.
+ * @return the virtualPath of the connection details.
*/
public final String getVirtualPath()
{
- if (_connectionDetails != null)
- {
- return _connectionDetails.getVirtualHost();
- }
- else
- {
- return _virtualPath;
- }
- }
-
- /**
- * @param path The _virtualPath to set.
- */
- public final void setVirtualPath(String path)
- {
- if (_connectionDetails != null)
- {
- _connectionDetails.setVirtualHost(path);
- }
-
- _virtualPath = path;
+ return _connectionDetails.getVirtualHost();
}
public static String getUniqueClientID()
@@ -267,19 +91,11 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
{
try
{
- if (_connectionDetails != null)
- {
- if (_connectionDetails.getClientName() == null || _connectionDetails.getClientName().equals(""))
- {
- _connectionDetails.setClientName(getUniqueClientID());
- }
- return new AMQConnection(_connectionDetails, _sslConfig);
- }
- else
+ if (_connectionDetails.getClientName() == null || _connectionDetails.getClientName().equals(""))
{
- return new AMQConnection(_host, _port, _defaultUsername, _defaultPassword, getUniqueClientID(),
- _virtualPath);
+ _connectionDetails.setClientName(getUniqueClientID());
}
+ return new AMQConnection(_connectionDetails);
}
catch (Exception e)
{
@@ -288,8 +104,6 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
jmse.initCause(e);
throw jmse;
}
-
-
}
public Connection createConnection(String userName, String password) throws JMSException
@@ -301,25 +115,18 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
{
try
{
- if (_connectionDetails != null)
+ _connectionDetails.setUsername(userName);
+ _connectionDetails.setPassword(password);
+
+ if (id != null && !id.equals(""))
{
- _connectionDetails.setUsername(userName);
- _connectionDetails.setPassword(password);
-
- if (id != null && !id.equals(""))
- {
- _connectionDetails.setClientName(id);
- }
- else if (_connectionDetails.getClientName() == null || _connectionDetails.getClientName().equals(""))
- {
- _connectionDetails.setClientName(getUniqueClientID());
- }
- return new AMQConnection(_connectionDetails, _sslConfig);
- }
- else
+ _connectionDetails.setClientName(id);
+ }
+ else if (_connectionDetails.getClientName() == null || _connectionDetails.getClientName().equals(""))
{
- return new AMQConnection(_host, _port, userName, password, (id != null ? id : getUniqueClientID()), _virtualPath);
+ _connectionDetails.setClientName(getUniqueClientID());
}
+ return new AMQConnection(_connectionDetails);
}
catch (Exception e)
{
@@ -361,12 +168,6 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
return _connectionDetails.toString();
}
-
- public final void setConnectionURLString(String url) throws URLSyntaxException
- {
- _connectionDetails = new AMQConnectionURL(url);
- }
-
/**
* JNDI interface to create objects from References.
*
@@ -457,7 +258,7 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF
{
try
{
- return new XAConnectionImpl(_connectionDetails, _sslConfig);
+ return new XAConnectionImpl(_connectionDetails);
}
catch (Exception e)
{
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/SSLConfiguration.java b/qpid/java/client/src/main/java/org/apache/qpid/client/SSLConfiguration.java
deleted file mode 100644
index 2280cc9870..0000000000
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/SSLConfiguration.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.qpid.client;
-
-public class SSLConfiguration {
-
- private String _keystorePath;
-
- private String _keystorePassword;
-
- private String _certType = "SunX509";
-
- public void setKeystorePath(String path)
- {
- _keystorePath = path;
- }
-
- public String getKeystorePath()
- {
- return _keystorePath;
- }
-
- public void setKeystorePassword(String password)
- {
- _keystorePassword = password;
- }
-
- public String getKeystorePassword()
- {
- return _keystorePassword;
- }
-
- public void setCertType(String type)
- {
- _certType = type;
- }
-
- public String getCertType()
- {
- return _certType;
- }
-}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/XAConnectionImpl.java b/qpid/java/client/src/main/java/org/apache/qpid/client/XAConnectionImpl.java
index 43025bd724..97048f39f4 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/XAConnectionImpl.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/XAConnectionImpl.java
@@ -31,9 +31,9 @@ public class XAConnectionImpl extends AMQConnection implements XAConnection, XAQ
/**
* Create a XAConnection from a connectionURL
*/
- public XAConnectionImpl(ConnectionURL connectionURL, SSLConfiguration sslConfig) throws AMQException
+ public XAConnectionImpl(ConnectionURL connectionURL) throws AMQException
{
- super(connectionURL, sslConfig);
+ super(connectionURL);
}
//-- interface XAConnection
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java b/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java
index 637d9dd692..370e2d6c55 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSObjectMessage.java
@@ -33,6 +33,7 @@ import javax.jms.ObjectMessage;
import org.apache.mina.common.ByteBuffer;
import org.apache.qpid.AMQException;
+import org.apache.qpid.client.util.ClassLoadingAwareObjectInputStream;
public class JMSObjectMessage extends AbstractJMSMessage implements ObjectMessage
{
@@ -136,7 +137,7 @@ public class JMSObjectMessage extends AbstractJMSMessage implements ObjectMessag
try
{
_data.rewind();
- in = new ObjectInputStream(_data.asInputStream());
+ in = new ClassLoadingAwareObjectInputStream(_data.asInputStream());
return (Serializable) in.readObject();
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStream.java b/qpid/java/client/src/main/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStream.java
new file mode 100644
index 0000000000..669a0f1abf
--- /dev/null
+++ b/qpid/java/client/src/main/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStream.java
@@ -0,0 +1,134 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.client.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+
+
+/**
+ * <code>ClassLoadingAwareObjectInputStream</code> is an Extention of Object input stream to be used
+ * to de-serialize JMS Object Messages.
+ *
+ * <p>This was introduced to resolve the class loading issues which can happen when we use the client
+ * libraries in a complex class loading Environment.</p>
+ */
+public class ClassLoadingAwareObjectInputStream extends ObjectInputStream
+{
+ /** <p>Class loader instance which loaded this class.
+ * It will be used to load classes when we failed to load classes from dynamic class loading</p> */
+ private static final ClassLoader _ON_FAULT_CLASS_LOADER =
+ ClassLoadingAwareObjectInputStream.class.getClassLoader();
+
+ /** <p>Maps primitive type names to corresponding class objects.</p> */
+ private static final HashMap<String, Class> _primitives = new HashMap<String, Class>(8, 1.0F);
+
+
+ public ClassLoadingAwareObjectInputStream(InputStream in) throws IOException
+ {
+ super(in);
+ }
+
+ @Override
+ protected Class resolveClass(ObjectStreamClass classDesc)
+ throws IOException, ClassNotFoundException
+ {
+
+ // Here we use TTCL as our primary class loader to load the classes
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+ return load(classDesc.getName(), cl);
+ }
+
+ @Override
+ protected Class resolveProxyClass(String[] interfaces)
+ throws IOException, ClassNotFoundException
+ {
+ // Here we use TTCL as our primary class loader to load the classes
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+ Class[] cinterfaces = new Class[interfaces.length];
+ for (int i = 0; i < interfaces.length; i++)
+ {
+ cinterfaces[i] = load(interfaces[i], cl);
+ }
+
+ try
+ {
+ return Proxy.getProxyClass(cinterfaces[0].getClassLoader(), cinterfaces);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ClassNotFoundException(null, e);
+ }
+ }
+
+ /**
+ * <p>
+ * Method we used to load class that are needed to de-serialize the objects. </p>
+ * <p>
+ * Here we first look up for the objects from the given class loader and if its not there
+ * we will be using the class loader of this class.
+ * </p>
+ * @param className Class name to lookup
+ * @param cl primary class loader which we 1st use to lookup
+ * @return Class instance we are looking for
+ * @throws ClassNotFoundException if both primary and secondary lockup's failed.
+ */
+ private Class load(String className, ClassLoader cl)
+ throws ClassNotFoundException
+ {
+ try
+ {
+ return Class.forName(className, false, cl);
+ }
+ catch (ClassNotFoundException e)
+ {
+ final Class clazz = _primitives.get(className);
+
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ else
+ {
+ return Class.forName(className, false, _ON_FAULT_CLASS_LOADER);
+ }
+ }
+ }
+
+ static
+ {
+ _primitives.put("boolean", boolean.class);
+ _primitives.put("byte", byte.class);
+ _primitives.put("char", char.class);
+ _primitives.put("short", short.class);
+ _primitives.put("int", int.class);
+ _primitives.put("long", long.class);
+ _primitives.put("float", float.class);
+ _primitives.put("double", double.class);
+ _primitives.put("void", void.class);
+ }
+}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java
index 4db6a11e4d..0c2f4ce57d 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/BrokerDetails.java
@@ -22,7 +22,7 @@ package org.apache.qpid.jms;
import java.util.Map;
-import org.apache.qpid.client.SSLConfiguration;
+import org.apache.qpid.transport.ConnectionSettings;
public interface BrokerDetails
{
@@ -104,14 +104,12 @@ public interface BrokerDetails
long getTimeout();
void setTimeout(long timeout);
-
- SSLConfiguration getSSLConfiguration();
-
- void setSSLConfiguration(SSLConfiguration sslConfiguration);
boolean getBooleanProperty(String propName);
String toString();
boolean equals(Object o);
+
+ ConnectionSettings buildConnectionSettings();
}
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverExchangeMethod.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverExchangeMethod.java
index ef30f2adbc..cb3ab718e9 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverExchangeMethod.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverExchangeMethod.java
@@ -140,7 +140,6 @@ public class FailoverExchangeMethod implements FailoverMethod, MessageListener
broker.setHost(tokens[1]);
broker.setPort(Integer.parseInt(tokens[2]));
broker.setProperties(_originalBrokerDetail.getProperties());
- broker.setSSLConfiguration(_originalBrokerDetail.getSSLConfiguration());
brokerList.add(broker);
if (currentBrokerIP.equals(broker.getHost()) &&
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindConnectionFactory.java b/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindConnectionFactory.java
deleted file mode 100644
index 2c08f1e34a..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindConnectionFactory.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.IBMPerfTest;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.url.URLSyntaxException;
-
-import javax.jms.ConnectionFactory;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.File;
-import java.util.Hashtable;
-
-public class JNDIBindConnectionFactory
-{
-
- public static final String CONNECTION_FACTORY_BINDING = "amq.ConnectionFactory";
- public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + File.separator + "IBMPerfTestsJNDI";
- public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH;
- public static final String FSCONTEXT_FACTORY = "com.sun.jndi.fscontext.RefFSContextFactory";
- public static final String DEFAULT_CONNECTION_URL = "amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5672'";
-
- private static void printUsage()
- {
- System.out.println("Using default values: Usage:java JNDIBindConnectionFactory <connection url> [<Connection Factory Binding>] [<Provider URL>] [<JNDI Context Factory>]");
-
- }
-
- public static void main(String[] args)
- {
- Logger.getRootLogger().setLevel(Level.OFF);
-
- String connectionFactoryBinding = CONNECTION_FACTORY_BINDING;
- String provider = PROVIDER_URL;
- String contextFactory = FSCONTEXT_FACTORY;
- if (args.length == 0)
- {
- printUsage();
- System.exit(1);
- }
-
- String connectionURL = args[0];
-
- System.out.println("Using Connection:" + connectionURL + "\n");
-
-
- if (args.length > 1)
- {
- connectionFactoryBinding = args[1];
-
- if (args.length > 2)
- {
- provider = args[2];
-
- if (args.length > 3)
- {
- contextFactory = args[3];
- }
- }
- else
- {
- System.out.println("Using default File System Context Factory");
- System.out.println("Using default Connection Factory Binding:" + connectionFactoryBinding);
- }
- }
- else
- {
- printUsage();
- }
-
-
- System.out.println("File System Context Factory\n" +
- "Connection:" + connectionURL + "\n" +
- "Connection Factory Binding:" + connectionFactoryBinding + "\n" +
- "JNDI Provider URL:" + provider);
-
- if (provider.startsWith("file"))
- {
- File file = new File(provider.substring(provider.indexOf("://") + 3));
-
- if (file.exists() && !file.isDirectory())
- {
- System.out.println("Couldn't make directory file already exists");
- System.exit(1);
- }
- else
- {
- if (!file.exists())
- {
- if (!file.mkdirs())
- {
- System.out.println("Couldn't make directory");
- System.exit(1);
- }
- }
- }
- }
-
- new JNDIBindConnectionFactory(provider, connectionFactoryBinding, contextFactory, connectionURL);
-
- }
-
- public JNDIBindConnectionFactory(String provider, String binding, String contextFactory, String CONNECTION_URL)
- {
- // Set up the environment for creating the initial context
- Hashtable env = new Hashtable(11);
- env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
-
- env.put(Context.PROVIDER_URL, provider);
-
- try
- {
- // Create the initial context
- Context ctx = new InitialContext(env);
-
- // Create the object to be bound
- ConnectionFactory factory = null;
-
- try
- {
- factory = new AMQConnectionFactory(CONNECTION_URL);
-
-
- try
- {
- Object obj = ctx.lookup(binding);
-
- if (obj != null)
- {
- System.out.println("Un-binding previous Connection Factory");
- ctx.unbind(binding);
- }
- }
- catch (NamingException e)
- {
- System.out.println("Operation failed: " + e);
- }
-
- // Perform the bind
- ctx.bind(binding, factory);
- System.out.println("Bound Connection Factory:" + binding);
-
- // Check that it is bound
- Object obj = ctx.lookup(binding);
- System.out.println("Connection URL:" + ((AMQConnectionFactory) obj).getConnectionURL());
-
- System.out.println("JNDI FS Context:" + provider);
- }
- catch (NamingException amqe)
- {
- System.out.println("Operation failed: " + amqe);
- }
- catch (URLSyntaxException e)
- {
- System.out.println("Operation failed: " + e);
- }
-
- }
- catch (NamingException e)
- {
- System.out.println("Operation failed: " + e);
- }
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindQueue.java b/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindQueue.java
deleted file mode 100644
index 10e8b94311..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindQueue.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.IBMPerfTest;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQSession;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.File;
-import java.util.Hashtable;
-
-public class JNDIBindQueue
-{
- public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + File.separator + "IBMPerfTestsJNDI";
- public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH;
- public static final String FSCONTEXT_FACTORY = "com.sun.jndi.fscontext.RefFSContextFactory";
-
- Connection _connection = null;
- Context _ctx = null;
-
-
- public JNDIBindQueue(String queueBinding, String queueName, String provider, String contextFactory)
- {
- // Set up the environment for creating the initial context
- Hashtable env = new Hashtable(11);
- env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
-
- env.put(Context.PROVIDER_URL, provider);
-
- try
- {
- // Create the initial context
- _ctx = new InitialContext(env);
-
- // Create the object to be bound
-
- try
- {
- _connection = new AMQConnection("amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'");
- System.out.println("Connected");
- }
- catch (Exception amqe)
- {
- System.out.println("Unable to create AMQConnectionFactory:" + amqe);
- }
-
- if (_connection != null)
- {
- bindQueue(queueName, queueBinding);
- }
-
- // Check that it is bound
- Object obj = _ctx.lookup(queueBinding);
-
- System.out.println("Bound Queue:" + ((AMQQueue) obj).toURL());
-
- System.out.println("JNDI FS Context:" + provider);
-
- }
- catch (NamingException e)
- {
- System.out.println("Operation failed: " + e);
- }
- finally
- {
- try
- {
- if (_connection != null)
- {
- _connection.close();
- }
- }
- catch (JMSException closeE)
- {
- System.out.println("Connection closing failed: " + closeE);
- }
- }
-
-
- }
-
-
- private void bindQueue(String queueName, String queueBinding) throws NamingException
- {
-
- try
- {
- Object obj = _ctx.lookup(queueBinding);
-
- if (obj != null)
- {
- System.out.println("Un-binding exisiting object");
- _ctx.unbind(queueBinding);
- }
- }
- catch (NamingException e)
- {
-
- }
-
- Queue queue = null;
- try
- {
-
- Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- if (session != null)
- {
- queue = ((AMQSession) session).createQueue(queueName);
- }
- }
- catch (JMSException jmse)
- {
- System.out.println("Unable to create Queue:" + jmse);
- }
-
- // Perform the bind
- _ctx.bind(queueBinding, queue);
- }
-
-
- public static void main(String[] args)
- {
- Logger.getRootLogger().setLevel(Level.OFF);
-
- String provider = JNDIBindQueue.PROVIDER_URL;
- String contextFactory = JNDIBindQueue.FSCONTEXT_FACTORY;
-
- if (args.length > 1)
- {
- String binding = args[0];
- String queueName = args[1];
-
- if (args.length > 2)
- {
- provider = args[2];
-
- if (args.length > 3)
- {
- contextFactory = args[3];
- }
- }
- else
- {
- System.out.println("Using default File System Context Factory");
- }
-
- System.out.println("File System Context Factory\n" +
- "Binding Queue:'" + queueName + "' to '" + binding + "'\n" +
- "JNDI Provider URL:" + provider);
-
- if (provider.startsWith("file"))
- {
- File file = new File(provider.substring(provider.indexOf("://") + 3));
-
- if (file.exists() && !file.isDirectory())
- {
- System.out.println("Couldn't make directory file already exists");
- System.exit(1);
- }
- else
- {
- if (!file.exists())
- {
- if (!file.mkdirs())
- {
- System.out.println("Couldn't make directory");
- System.exit(1);
- }
- }
- }
- }
-
-
- new JNDIBindQueue(binding, queueName, provider, contextFactory);
-
- }
- else
- {
- System.out.println("Using Defaults: Usage:java JNDIBindQueue <Binding> <queue name> [<Provider URL> [<JNDI Context Factory>]]");
- }
-
- }
-
-
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindTopic.java b/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindTopic.java
deleted file mode 100644
index ca071c1187..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/JNDIBindTopic.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.IBMPerfTest;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.AMQTopic;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.File;
-import java.util.Hashtable;
-
-public class JNDIBindTopic
-{
- public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + File.separator + "IBMPerfTestsJNDI";
- public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH;
-
- public static final String FSCONTEXT_FACTORY = "com.sun.jndi.fscontext.RefFSContextFactory";
-
- Connection _connection = null;
- Context _ctx = null;
-
-
- public JNDIBindTopic(String topicBinding, String topicName, String provider, String contextFactory)
- {
- // Set up the environment for creating the initial context
- Hashtable env = new Hashtable(11);
- env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
-
- env.put(Context.PROVIDER_URL, provider);
-
- try
- {
- // Create the initial context
- _ctx = new InitialContext(env);
-
- // Create the object to be bound
-
- try
- {
- _connection = new AMQConnection("amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:5672'");
- System.out.println("Connected");
- }
- catch (Exception amqe)
- {
- System.out.println("Unable to create AMQConnectionFactory:" + amqe);
- }
-
- if (_connection != null)
- {
- bindTopic(topicName, topicBinding);
- }
-
- // Check that it is bound
- Object obj = _ctx.lookup(topicBinding);
-
- System.out.println("Bound Queue:" + ((AMQTopic) obj).toURL());
-
- System.out.println("JNDI FS Context:" + provider);
-
- }
- catch (NamingException e)
- {
- System.out.println("Operation failed: " + e);
- }
- finally
- {
- try
- {
- if (_connection != null)
- {
- _connection.close();
- }
- }
- catch (JMSException closeE)
- {
- System.out.println("Operation failed: " + closeE);
- }
- }
- }
-
-
- private void bindTopic(String topicName, String topicBinding) throws NamingException
- {
-
- try
- {
- Object obj = _ctx.lookup(topicBinding);
-
- if (obj != null)
- {
- System.out.println("Un-binding exisiting object");
- _ctx.unbind(topicBinding);
- }
- }
- catch (NamingException e)
- {
-
- }
-
- Topic topic = null;
- try
- {
-
- Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- if (session != null)
- {
- topic = ((AMQSession) session).createTopic(topicName);
- }
- }
- catch (JMSException jmse)
- {
- System.out.println("Unable to create Topic:" + jmse);
- }
-
- // Perform the bind
- _ctx.bind(topicBinding, topic);
- }
-
-
- public static void main(String[] args)
- {
- Logger.getRootLogger().setLevel(Level.OFF);
-
- String provider = JNDIBindTopic.PROVIDER_URL;
- String contextFactory = JNDIBindTopic.FSCONTEXT_FACTORY;
-
- if (args.length > 1)
- {
- String binding = args[0];
- String queueName = args[1];
-
- if (args.length > 2)
- {
- provider = args[2];
-
- if (args.length > 3)
- {
- contextFactory = args[3];
- }
- }
- else
- {
- System.out.println("Using default File System Context Factory");
- }
-
- System.out.println("File System Context Factory\n" +
- "Binding Topic:'" + queueName + "' to '" + binding + "'\n" +
- "JNDI Provider URL:" + provider);
-
-
- if (provider.startsWith("file"))
- {
- File file = new File(provider.substring(provider.indexOf("://") + 3));
-
- if (file.exists() && !file.isDirectory())
- {
- System.out.println("Couldn't make directory file already exists");
- System.exit(1);
- }
- else
- {
- if (!file.exists())
- {
- if (!file.mkdirs())
- {
- System.out.println("Couldn't make directory");
- System.exit(1);
- }
- }
- }
- }
-
- new JNDIBindTopic(binding, queueName, provider, contextFactory);
-
- }
- else
- {
- System.out.println("Usage:java JNDIBindTopic <Binding> <topic name> [<Provider URL> [<JNDI Context Factory>]]");
- }
-
- }
-
-
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/README.txt b/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/README.txt
deleted file mode 100644
index 95ee9f9c77..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/IBMPerfTest/README.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-These JNDI setup tools are mainly for use in conjunction with the IBM JMS Performance Harness available here:
-The jar should be placed in the client/test/lib/ directory.
-
-http://www.alphaworks.ibm.com/tech/perfharness
-
-
-These JNDI classes use the the SUN FileSystem context.
-There are two jar files that should be placed in your client/test/lib directory.
-
-http://javashoplm.sun.com/ECom/docs/Welcome.jsp?StoreId=22&PartDetailId=7110-jndi-1.2.1-oth-JPR&SiteId=JSC&TransactionId=noreg
-
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/cluster/Client.java b/qpid/java/client/src/old_test/java/org/apache/qpid/cluster/Client.java
deleted file mode 100644
index cf8059a143..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/cluster/Client.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.cluster;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.AMQTopic;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.url.URLSyntaxException;
-
-import javax.jms.MessageListener;
-import javax.jms.Message;
-import javax.jms.Session;
-import javax.jms.JMSException;
-import javax.jms.MessageProducer;
-import javax.jms.TextMessage;
-import java.util.Random;
-
-public class Client
-{
- private final Random random = new Random();
- private final String name;
- private final Session session;
- private final MessageProducer topicProducer;
- private final MessageProducer queueProducer;
-
- Client(AMQConnection connection, String name) throws JMSException, InterruptedException
- {
- this.name = name;
- session = connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
-
- AMQTopic topic = new AMQTopic(((AMQSession)session).getDefaultTopicExchangeName(), new AMQShortString("cluster_test_topic"));
- AMQQueue queue = new AMQQueue(((AMQSession)session).getDefaultQueueExchangeName(), new AMQShortString("cluster_test_queue"));
-
- topicProducer = session.createProducer(topic);
- queueProducer = session.createProducer(queue);
-
- //subscribe to a known topic
- session.createConsumer(topic).setMessageListener(new TopicHandler());
- //subscribe to a known queue
- session.createConsumer(queue).setMessageListener(new QueueHandler());
-
- connection.start();
-
- while(true)
- {
- Thread.sleep(random.nextInt(60000));
- sendToQueue(name + ":" + randomString(5));
- }
- }
-
- private synchronized void sendToTopic(String message) throws JMSException
- {
- topicProducer.send(session.createTextMessage(message));
- }
-
- private synchronized void sendToQueue(String message) throws JMSException
- {
- queueProducer.send(session.createTextMessage(message));
- }
-
- private String randomString(int length){
- char[] c = new char[length];
- for(int i = 0; i < length; i++)
- {
- c[i] = (char) ('A' + random.nextInt(26));
- }
- return new String(c);
- }
-
- private class QueueHandler implements MessageListener
- {
- public void onMessage(Message message)
- {
- try
- {
- sendToTopic(((TextMessage) message).getText());
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- }
- }
- }
-
- private class TopicHandler implements MessageListener
- {
- public void onMessage(Message message)
- {
- try
- {
- System.out.println(((TextMessage) message).getText());
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- }
- }
- }
-
- public static void main(String[] argv) throws AMQException, JMSException, InterruptedException, URLSyntaxException
- {
- //assume args describe the set of brokers to try
-
- String clientName = argv.length > 1 ? argv[1] : "testClient";
- new Client(new AMQConnection(argv.length > 0 ? argv[0] : "vm://:1", "guest", "guest", clientName, "/test"), clientName);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java b/qpid/java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java
deleted file mode 100644
index 1db7e200bd..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/codec/BasicDeliverTest.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.codec;
-
-import org.apache.qpid.framing.*;
-import org.apache.mina.common.*;
-import org.apache.mina.common.support.BaseIoSession;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
-import org.apache.mina.filter.codec.ProtocolEncoderOutput;
-
-import java.net.SocketAddress;
-
-/**
- */
-public class BasicDeliverTest
-{
- public static void main(String[] argv) throws Exception
- {
- BasicDeliverTest test = new BasicDeliverTest();
-
- //warm up:
- test.encode(512, 100000);
-
- //real tests:
- test.encode(16, 10000, 15);
- test.encode(32, 10000, 15);
- test.encode(64, 10000, 15);
- test.encode(128, 10000, 15);
- test.encode(256, 10000, 15);
- test.encode(512, 10000, 15);
- test.encode(1024, 10000, 15);
- test.encode(2048, 10000, 15);
-
- test.decode(16, 10000, 15);
- test.decode(32, 10000, 15);
- test.decode(64, 10000, 15);
- test.decode(128, 10000, 15);
- test.decode(256, 10000, 15);
- test.decode(512, 10000, 15);
- test.decode(1024, 10000, 15);
- test.decode(2048, 10000, 15);
- }
-
- void decode(int size, int count, int iterations) throws Exception
- {
- long min = Long.MAX_VALUE;
- long max = 0;
- long total = 0;
- for (int i = 0; i < iterations; i++)
- {
- long time = decode(size, count);
- total += time;
- if (time < min)
- {
- min = time;
- }
- if (time > max)
- {
- max = time;
- }
- }
- System.out.println("Decoded " + count + " messages of " + size +
- " bytes: avg=" + (total / iterations) + ", min=" + min + ", max=" + max);
- }
-
-
- long decode(int size, int count) throws Exception
- {
- AMQDataBlock block = getDataBlock(size);
- ByteBuffer data = ByteBuffer.allocate((int) block.getSize()); // XXX: Is cast a problem?
- block.writePayload(data);
- data.flip();
- AMQDecoder decoder = new AMQDecoder(false);
- long start = System.currentTimeMillis();
- for (int i = 0; i < count; i++)
- {
- decoder.decode(session, data, decoderOutput);
- data.rewind();
- }
- return System.currentTimeMillis() - start;
- }
-
- void encode(int size, int count, int iterations) throws Exception
- {
- long min = Long.MAX_VALUE;
- long max = 0;
- long total = 0;
- for (int i = 0; i < iterations; i++)
- {
- long time = encode(size, count);
- total += time;
- if (time < min)
- {
- min = time;
- }
- if (time > max)
- {
- max = time;
- }
- }
- System.out.println("Encoded " + count + " messages of " + size +
- " bytes: avg=" + (total / iterations) + ", min=" + min + ", max=" + max);
- }
-
- long encode(int size, int count) throws Exception
- {
- IoSession session = null;
- AMQDataBlock block = getDataBlock(size);
- AMQEncoder encoder = new AMQEncoder();
- long start = System.currentTimeMillis();
- for (int i = 0; i < count; i++)
- {
- encoder.encode(session, block, encoderOutput);
- }
- return System.currentTimeMillis() - start;
- }
-
- private final ProtocolEncoderOutput encoderOutput = new ProtocolEncoderOutput()
- {
-
- public void write(ByteBuffer byteBuffer)
- {
- }
-
- public void mergeAll()
- {
- }
-
- public WriteFuture flush()
- {
- return null;
- }
- };
-
- private final ProtocolDecoderOutput decoderOutput = new ProtocolDecoderOutput()
- {
- public void write(Object object)
- {
- }
-
- public void flush()
- {
- }
- };
-
- private final IoSession session = new BaseIoSession()
- {
-
- protected void updateTrafficMask()
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public IoService getService()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public IoServiceConfig getServiceConfig()
- {
- return null;
- }
-
- public IoHandler getHandler()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public IoSessionConfig getConfig()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public IoFilterChain getFilterChain()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public TransportType getTransportType()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public SocketAddress getRemoteAddress()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public SocketAddress getLocalAddress()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public SocketAddress getServiceAddress()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public int getScheduledWriteRequests()
- {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public int getScheduledWriteBytes()
- {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
- }
- };
-
- private static final char[] DATA = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
-
- static CompositeAMQDataBlock getDataBlock(int size)
- {
- //create a frame representing message delivery
- AMQFrame[] frames = new AMQFrame[3];
- frames[0] = wrapBody(createBasicDeliverBody());
- frames[1] = wrapBody(createContentHeaderBody());
- frames[2] = wrapBody(createContentBody(size));
-
- return new CompositeAMQDataBlock(frames);
- }
-
- static AMQFrame wrapBody(AMQBody body)
- {
- AMQFrame frame = new AMQFrame(1, body);
- return frame;
- }
-
- static ContentBody createContentBody(int size)
- {
- ContentBody body = new ContentBody();
- body.payload = ByteBuffer.allocate(size);
- for (int i = 0; i < size; i++)
- {
- body.payload.put((byte) DATA[i % DATA.length]);
- }
- return body;
- }
-
- static ContentHeaderBody createContentHeaderBody()
- {
- ContentHeaderBody body = new ContentHeaderBody();
- body.properties = new BasicContentHeaderProperties();
- body.weight = 1;
- body.classId = 6;
- return body;
- }
-
- static BasicDeliverBody createBasicDeliverBody()
- {
- BasicDeliverBody body = new BasicDeliverBody((byte) 8, (byte) 0,
- BasicDeliverBody.getClazz((byte) 8, (byte) 0),
- BasicDeliverBody.getMethod((byte) 8, (byte) 0),
- new AMQShortString("myConsumerTag"), 1,
- new AMQShortString("myExchange"), false,
- new AMQShortString("myRoutingKey"));
- return body;
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/codec/Client.java b/qpid/java/client/src/old_test/java/org/apache/qpid/codec/Client.java
deleted file mode 100644
index 3886021277..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/codec/Client.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.codec;
-
-import org.apache.mina.transport.socket.nio.SocketConnector;
-import org.apache.mina.common.ConnectFuture;
-import org.apache.mina.common.IoHandlerAdapter;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
-import org.apache.qpid.framing.AMQDataBlock;
-import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.BasicDeliverBody;
-import org.apache.qpid.framing.ContentBody;
-
-import java.net.InetSocketAddress;
-
-public class Client extends IoHandlerAdapter
-{
- //private static final int[] DEFAULT_SIZES = new int[]{1024, 512, 256, 128, 56};
- //private static final int[] DEFAULT_SIZES = new int[]{256, 256, 256, 256, 256, 512, 512, 512, 512, 512};
- private static final int[] DEFAULT_SIZES = new int[]{256, 512, 256, 512, 256, 512, 256, 512, 256, 512};
- //private static final int[] DEFAULT_SIZES = new int[]{1024, 1024, 1024, 1024, 1024};
-
- private final IoSession _session;
- private final long _start;
- private final int _size;
- private final int _count;
- private int _received;
- private boolean _closed;
-
- Client(String host, int port, int size, int count) throws Exception
- {
- _count = count;
- _size = size;
- AMQDataBlock block = BasicDeliverTest.getDataBlock(size);
-
- InetSocketAddress address = new InetSocketAddress(host, port);
- ConnectFuture future = new SocketConnector().connect(address, this);
- future.join();
- _session = future.getSession();
-
- _start = System.currentTimeMillis();
- for(int i = 0; i < count; i++)
- {
- _session.write(block);
- }
- }
-
- void close()
- {
- long time = System.currentTimeMillis() - _start;
- System.out.println("Received " + _received + " messages of " + _size
- + " bytes in " + time + "ms.");
- _session.close();
- synchronized(this)
- {
- _closed = true;
- notify();
- }
- }
-
- void waitForClose() throws InterruptedException
- {
- synchronized(this)
- {
- while(!_closed)
- {
- wait();
- }
- }
- }
-
- public void sessionCreated(IoSession session) throws Exception
- {
- session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new AMQCodecFactory(false)));
- }
-
- public void messageReceived(IoSession session, Object object) throws Exception
- {
- if(isContent(object) && ++_received == _count) close();
- }
-
- public void exceptionCaught(IoSession session, Throwable throwable) throws Exception
- {
- throwable.printStackTrace();
- close();
- }
-
- private static boolean isDeliver(Object o)
- {
- return o instanceof AMQFrame && ((AMQFrame) o).getBodyFrame() instanceof BasicDeliverBody;
- }
-
- private static boolean isContent(Object o)
- {
- return o instanceof AMQFrame && ((AMQFrame) o).getBodyFrame() instanceof ContentBody;
- }
-
- public static void main(String[] argv) throws Exception
- {
- String host = argv.length > 0 ? argv[0] : "localhost";
- int port = argv.length > 1 ? Integer.parseInt(argv[1]) : 8888;
- int count = argv.length > 2 ? Integer.parseInt(argv[2]) : 10000;
- int[] sizes = argv.length > 3 ? new int[]{Integer.parseInt(argv[3])} : DEFAULT_SIZES;
-
- System.out.println("Connecting to " + host + ":" + port);
-
- for(int i = 0; i < sizes.length; i++)
- {
- new Client(host, port, sizes[i], count).waitForClose();
- Thread.sleep(1000);
- }
- }
-
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/codec/Server.java b/qpid/java/client/src/old_test/java/org/apache/qpid/codec/Server.java
deleted file mode 100644
index fa4295e0b2..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/codec/Server.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.codec;
-
-import org.apache.mina.common.IoHandlerAdapter;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.transport.socket.nio.SocketAcceptor;
-import org.apache.mina.util.SessionUtil;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
-import org.apache.qpid.framing.AMQFrame;
-import org.apache.qpid.framing.CompositeAMQDataBlock;
-
-import java.net.InetSocketAddress;
-
-public class Server extends IoHandlerAdapter
-{
- Server(int port) throws Exception
- {
- new SocketAcceptor().bind(new InetSocketAddress(port), this);
- System.out.println("Listening on " + port);
- }
-
- public void sessionCreated(IoSession session) throws Exception
- {
- SessionUtil.initialize(session);
- session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new AMQCodecFactory(false)));
- }
-
- public void messageReceived(IoSession session, Object object) throws Exception
- {
- getAccumulator(session).received(session, (AMQFrame) object);
- }
-
- public void sessionOpened(IoSession session) throws Exception
- {
- System.out.println("sessionOpened()");
- }
-
- public void sessionClosed(IoSession session) throws Exception
- {
- System.out.println("sessionClosed()");
- }
-
- public void exceptionCaught(IoSession session, Throwable t) throws Exception
- {
- System.out.println("exceptionCaught()");
- t.printStackTrace();
- session.close();
- }
-
- private Accumulator getAccumulator(IoSession session)
- {
- Accumulator a = (Accumulator) session.getAttribute(ACCUMULATOR);
- if(a == null)
- {
- a = new Accumulator();
- session.setAttribute(ACCUMULATOR, a);
- }
- return a;
- }
-
- private static final String ACCUMULATOR = Accumulator.class.getName();
-
- private static class Accumulator
- {
- private final AMQFrame[] frames = new AMQFrame[3];
- private int i;
-
- void received(IoSession session, AMQFrame frame)
- {
- frames[i++] = frame;
- if(i >= frames.length)
- {
- i = 0;
- session.write(new CompositeAMQDataBlock(frames));
- }
- }
- }
-
- public static void main(String[] argv) throws Exception
- {
- int port = argv.length > 0 ? Integer.parseInt(argv[0]) : 8888;
- new Server(port);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/config/AbstractConfig.java b/qpid/java/client/src/old_test/java/org/apache/qpid/config/AbstractConfig.java
deleted file mode 100644
index 04381d66a0..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/config/AbstractConfig.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.config;
-
-public abstract class AbstractConfig
-{
- public boolean setOptions(String[] argv)
- {
- try
- {
- for(int i = 0; i < argv.length - 1; i += 2)
- {
- String key = argv[i];
- String value = argv[i+1];
- setOption(key, value);
- }
- return true;
- }
- catch(Exception e)
- {
- System.out.println(e.getMessage());
- }
- return false;
- }
-
- protected int parseInt(String msg, String i)
- {
- try
- {
- return Integer.parseInt(i);
- }
- catch(NumberFormatException e)
- {
- throw new RuntimeException(msg + ": " + i);
- }
- }
-
- protected long parseLong(String msg, String i)
- {
- try
- {
- return Long.parseLong(i);
- }
- catch(NumberFormatException e)
- {
- throw new RuntimeException(msg + ": " + i);
- }
- }
-
- public abstract void setOption(String key, String value);
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/config/ConnectionFactoryInitialiser.java b/qpid/java/client/src/old_test/java/org/apache/qpid/config/ConnectionFactoryInitialiser.java
deleted file mode 100644
index a9984eb09a..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/config/ConnectionFactoryInitialiser.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.config;
-
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-
-public interface ConnectionFactoryInitialiser
-{
- public ConnectionFactory getFactory(ConnectorConfig config) throws JMSException;
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/config/Connector.java b/qpid/java/client/src/old_test/java/org/apache/qpid/config/Connector.java
deleted file mode 100644
index ff2377f087..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/config/Connector.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.config;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-
-public class Connector
-{
- public Connection createConnection(ConnectorConfig config) throws Exception
- {
- return getConnectionFactory(config).createConnection();
- }
-
- ConnectionFactory getConnectionFactory(ConnectorConfig config) throws Exception
- {
- String factory = config.getFactory();
- if(factory == null) factory = AMQConnectionFactoryInitialiser.class.getName();
- System.out.println("Using " + factory);
- return ((ConnectionFactoryInitialiser) Class.forName(factory).newInstance()).getFactory(config);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/config/ConnectorConfig.java b/qpid/java/client/src/old_test/java/org/apache/qpid/config/ConnectorConfig.java
deleted file mode 100644
index b120ed3f12..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/config/ConnectorConfig.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.config;
-
-public interface ConnectorConfig
-{
- public String getHost();
- public int getPort();
- public String getFactory();
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java b/qpid/java/client/src/old_test/java/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java
deleted file mode 100644
index 1c86aea56c..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.config;
-
-import org.apache.qpid.config.ConnectionFactoryInitialiser;
-import org.apache.qpid.config.ConnectorConfig;
-
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.MBeanException;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.naming.NameNotFoundException;
-import java.util.Hashtable;
-
-public class JBossConnectionFactoryInitialiser implements ConnectionFactoryInitialiser
-{
- public ConnectionFactory getFactory(ConnectorConfig config) throws JMSException
- {
- ConnectionFactory cf = null;
- InitialContext ic = null;
- Hashtable ht = new Hashtable();
- ht.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
- String jbossHost = System.getProperty("jboss.host", "eqd-lxamq01");
- String jbossPort = System.getProperty("jboss.port", "1099");
- ht.put(InitialContext.PROVIDER_URL, "jnp://" + jbossHost + ":" + jbossPort);
- ht.put(InitialContext.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
-
- try
- {
- ic = new InitialContext(ht);
- if (!doesDestinationExist("topictest.messages", ic))
- {
- deployTopic("topictest.messages", ic);
- }
- if (!doesDestinationExist("topictest.control", ic))
- {
- deployTopic("topictest.control", ic);
- }
-
- cf = (ConnectionFactory) ic.lookup("/ConnectionFactory");
- return cf;
- }
- catch (NamingException e)
- {
- JMSException jmse = new JMSException("Unable to lookup object: " + e);
- jmse.setLinkedException(e);
- jmse.initCause(e);
- throw jmse;
- }
- catch (Exception e)
- {
- JMSException jmse = new JMSException("Error creating topic: " + e);
- jmse.setLinkedException(e);
- jmse.initCause(e);
- throw jmse;
- }
- }
-
- private boolean doesDestinationExist(String name, InitialContext ic) throws Exception
- {
- try
- {
- ic.lookup("/" + name);
- }
- catch (NameNotFoundException e)
- {
- return false;
- }
- return true;
- }
-
- private void deployTopic(String name, InitialContext ic) throws Exception
- {
- MBeanServerConnection mBeanServer = lookupMBeanServerProxy(ic);
-
- ObjectName serverObjectName = new ObjectName("jboss.messaging:service=ServerPeer");
-
- String jndiName = "/" + name;
- try
- {
- mBeanServer.invoke(serverObjectName, "createTopic",
- new Object[]{name, jndiName},
- new String[]{"java.lang.String", "java.lang.String"});
- }
- catch (MBeanException e)
- {
- System.err.println("Error: " + e);
- System.err.println("Cause: " + e.getCause());
- }
- }
-
- private MBeanServerConnection lookupMBeanServerProxy(InitialContext ic) throws NamingException
- {
- return (MBeanServerConnection) ic.lookup("jmx/invoker/RMIAdaptor");
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/flow/ChannelFlowTest.java b/qpid/java/client/src/old_test/java/org/apache/qpid/flow/ChannelFlowTest.java
deleted file mode 100644
index cb8adae18c..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/flow/ChannelFlowTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.flow;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQDestination;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-
-public class ChannelFlowTest implements MessageListener
-{
- private int sent;
- private int received;
-
- ChannelFlowTest(String broker) throws Exception
- {
- this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test"));
- }
-
- ChannelFlowTest(AMQConnection connection) throws Exception
- {
- this(connection, new AMQQueue(connection.getDefaultQueueExchangeName(), new AMQShortString(randomize("ChannelFlowTest")), true));
- }
-
- ChannelFlowTest(AMQConnection connection, AMQDestination destination) throws Exception
- {
- AMQSession session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE, 50,25);
-
- //set up a slow consumer
- session.createConsumer(destination).setMessageListener(this);
- connection.start();
-
- //create a publisher
- MessageProducer producer = session.createProducer(destination);
- Message msg = session.createTextMessage("Message");
-
- //publish in bursts that are fast enough to cause channel flow control
- for(int i = 0; i < 10; i++)
- {
- for(int j = 0; j < 100; j++)
- {
- producer.send(msg);
- sent++;
- }
- waitUntilReceived(sent - 40);
- }
-
- waitUntilReceived(sent);
-
- session.close();
- connection.close();
- }
-
-
- private synchronized void waitUntilReceived(int count) throws InterruptedException
- {
- while(received <count)
- {
- wait();
- }
- }
-
- public synchronized void onMessage(Message message)
- {
- try
- {
- Thread.sleep(50);
-
- received++;
- notify();
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
-
- private static String randomize(String in)
- {
- return in + System.currentTimeMillis();
- }
-
- public static void main(String[] argv) throws Exception
- {
- new ChannelFlowTest(argv.length == 0 ? "localhost:5672" : argv[0]);
- }
-
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/fragmentation/TestLargePublisher.java b/qpid/java/client/src/old_test/java/org/apache/qpid/fragmentation/TestLargePublisher.java
deleted file mode 100644
index 2fe01fc126..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/fragmentation/TestLargePublisher.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.fragmentation;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQTopic;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.jms.MessageProducer;
-import org.apache.qpid.jms.Session;
-import org.apache.log4j.Logger;
-
-import javax.jms.BytesMessage;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-/**
- * A client that behaves as follows:
- * <ul><li>Connects to a queue, whose name is specified as a cmd-line argument</li>
- * <li>Creates a temporary queue</li>
- * <li>Creates messages containing a property that is the name of the temporary queue</li>
- * <li>Fires off a message on the original queue and waits for a response on the temporary queue</li>
- * </ul>
- */
-public class TestLargePublisher
-{
- private static final Logger _log = Logger.getLogger(TestLargePublisher.class);
-
- private AMQConnection _connection;
-
- private AMQSession _session;
-
- private class CallbackHandler implements MessageListener
- {
- private int _expectedMessageCount;
-
- private int _actualMessageCount;
-
- private long _startTime;
-
- public CallbackHandler(int expectedMessageCount, long startTime)
- {
- _expectedMessageCount = expectedMessageCount;
- _startTime = startTime;
- }
-
- public void onMessage(Message m)
- {
- if (_log.isDebugEnabled())
- {
- _log.debug("Message received: " + m);
- }
- _actualMessageCount++;
- if (_actualMessageCount%1000 == 0)
- {
- _log.info("Received message count: " + _actualMessageCount);
- }
- /*if (!"henson".equals(m.toString()))
- {
- _log.error("AbstractJMSMessage response not correct: expected 'henson' but got " + m.toString());
- }
- else
- {
- if (_log.isDebugEnabled())
- {
- _log.debug("AbstractJMSMessage " + m + " received");
- }
- else
- {
- _log.info("AbstractJMSMessage received");
- }
- } */
-
- if (_actualMessageCount == _expectedMessageCount)
- {
- long timeTaken = System.currentTimeMillis() - _startTime;
- System.out.println("Total time taken to receive " + _expectedMessageCount+ " messages was " +
- timeTaken + "ms, equivalent to " +
- (_expectedMessageCount/(timeTaken/1000.0)) + " messages per second");
- }
- }
- }
-
- public TestLargePublisher(String host, int port, String clientID,
- final int messageCount) throws AMQException,URLSyntaxException
- {
- try
- {
- createConnection(host, port, clientID);
-
- _session = (AMQSession) _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- AMQTopic destination = new AMQTopic(_session.getDefaultTopicExchangeName(), new AMQShortString("large"));
- MessageProducer producer = (MessageProducer) _session.createProducer(destination);
-
- _connection.start();
- //TextMessage msg = _session.createTextMessage(tempDestination.getQueueName() + "/Presented to in conjunction with Mahnah Mahnah and the Snowths");
- final long startTime = System.currentTimeMillis();
-
- for (int i = 0; i < messageCount; i++)
- {
- BytesMessage msg = _session.createBytesMessage();
- populateMessage(msg);
- producer.send(msg);
- }
- _log.info("Finished sending " + messageCount + " messages");
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- }
- }
-
- private void createConnection(String host, int port, String clientID) throws AMQException , URLSyntaxException
- {
- _connection = new AMQConnection(host, port, "guest", "guest",
- clientID, "/test");
- }
-
- private void populateMessage(BytesMessage msg) throws JMSException
- {
- int size = 1024 * 187; // 187k
- byte[] data = new byte[size];
- for (int i = 0; i < data.length; i++)
- {
- data[i] = (byte)(i%25);
- }
- msg.writeBytes(data);
- }
-
- /**
- *
- * @param args argument 1 if present specifies the name of the temporary queue to create. Leaving it blank
- * means the server will allocate a name.
- */
- public static void main(String[] args) throws URLSyntaxException
- {
- final String host;
- final int port;
- final int numMessages;
- if (args.length == 0)
- {
- host = "localhost";
- port = 5672;
- numMessages = 100;
-// System.err.println("Usage: TestLargePublisher <host> <port> <number of messages>");
- }
- else
- {
- host = args[0];
- port = Integer.parseInt(args[1]);
- numMessages = Integer.parseInt(args[2]);
- }
-
- try
- {
- InetAddress address = InetAddress.getLocalHost();
- String clientID = address.getHostName() + System.currentTimeMillis();
- TestLargePublisher client = new TestLargePublisher(host, port, clientID, numMessages);
- }
- catch (UnknownHostException e)
- {
- e.printStackTrace();
- }
- catch (AMQException e)
- {
- System.err.println("Error in client: " + e);
- e.printStackTrace();
- }
-
- //System.exit(0);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/fragmentation/TestLargeSubscriber.java b/qpid/java/client/src/old_test/java/org/apache/qpid/fragmentation/TestLargeSubscriber.java
deleted file mode 100644
index b0cde22349..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/fragmentation/TestLargeSubscriber.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.fragmentation;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQTopic;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.jms.Session;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.log4j.Logger;
-
-import javax.jms.*;
-import java.net.InetAddress;
-
-public class TestLargeSubscriber
-{
- private static final Logger _logger = Logger.getLogger(TestLargeSubscriber.class);
-
- private static MessageProducer _destinationProducer;
-
- private static String _destinationName;
-
- public static void main(String[] args)
- {
- _logger.info("Starting...");
-
- final String host;
- final int port;
- final String username;
- final String password;
- final String virtualPath;
- final int numExpectedMessages;
- if (args.length == 0)
- {
- host = "localhost";
- port = 5672;
- username = "guest";
- password = "guest";
- virtualPath = "/test";
- numExpectedMessages = 100;
- }
- else if (args.length == 6)
- {
- host = args[0];
- port = Integer.parseInt(args[1]);
- username = args[2];
- password = args[3];
- virtualPath = args[4];
- numExpectedMessages = Integer.parseInt(args[5]);
- }
- else
- {
- System.out.println("Usage: host port username password virtual-path expectedMessageCount");
- System.exit(1);
- throw new RuntimeException("cannot be reached");
- }
-
- try
- {
- InetAddress address = InetAddress.getLocalHost();
- AMQConnection con = new AMQConnection(host, port, username, password,
- address.getHostName(), virtualPath);
- final AMQSession session = (AMQSession) con.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- final int expectedMessageCount = numExpectedMessages;
-
- MessageConsumer consumer = session.createConsumer(new AMQTopic(session.getDefaultTopicExchangeName(),
- new AMQShortString("large")),
- 100, true, false, null);
-
- consumer.setMessageListener(new MessageListener()
- {
- private int _messageCount;
-
- private long _startTime = 0;
-
- public void onMessage(Message message)
- {
- validateMessage(message);
- if (_messageCount++ == 0)
- {
- _startTime = System.currentTimeMillis();
- }
- if (_logger.isInfoEnabled())
- {
- _logger.info("Got message '" + message + "'");
- }
- if (_messageCount == expectedMessageCount)
- {
- long totalTime = System.currentTimeMillis() - _startTime;
- _logger.error("Total time to receive " + _messageCount + " messages was " +
- totalTime + "ms. Rate is " + (_messageCount/(totalTime/1000.0)));
- }
- }
-
- private void validateMessage(Message message)
- {
- if (!(message instanceof BytesMessage))
- {
- _logger.error("Message is not of correct type - should be BytesMessage and is " +
- message.getClass());
- }
- BytesMessage bm = (BytesMessage) message;
- final int expectedSize = 1024 * 187; // 187k
- try
- {
- if (bm.getBodyLength() != expectedSize)
- {
- _logger.error("Message is not correct length - should be " + expectedSize + " and is " +
- bm.getBodyLength());
- }
- }
- catch (JMSException e)
- {
- _logger.error("Failed to validate message: " + e, e);
- }
- try
- {
- byte[] data = new byte[(int)bm.getBodyLength()];
- bm.readBytes(data);
- for (int i = 0; i < data.length; i++)
- {
- if (data[i] != (byte)(i%25))
- {
- _logger.error("byte " + i + " of message is wrong - should be " + i%25 + " but is " +
- data[i]);
- }
- }
- _logger.info("***** Validated message successfully");
- }
- catch (JMSException e)
- {
- _logger.error("Failed to validate message: " + e, e);
- }
- }
- });
- con.start();
- }
- catch (Throwable t)
- {
- System.err.println("Fatal error: " + t);
- t.printStackTrace();
- }
-
- System.out.println("Waiting...");
- }
-}
-
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/headers/Listener.java b/qpid/java/client/src/old_test/java/org/apache/qpid/headers/Listener.java
deleted file mode 100644
index cb5caefc1e..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/headers/Listener.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.headers;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.jms.Session;
-//import org.apache.qpid.testutil.Config;
-
-import javax.jms.MessageListener;
-import javax.jms.Message;
-import javax.jms.Destination;
-import javax.jms.MessageProducer;
-import javax.jms.JMSException;
-
-public class Listener //implements MessageListener
-{
-/* private final AMQConnection _connection;
- private final MessageProducer _controller;
- private final AMQSession _session;
- private final MessageFactory _factory;
- private int count;
- private long start;
-
- Listener(AMQConnection connection, Destination exchange) throws Exception
- {
- _connection = connection;
- _session = (AMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- _factory = new MessageFactory(_session, 0, 19);
-
- //register for events
- _factory.createConsumer(exchange).setMessageListener(this);
- _connection.start();
-
- _controller = _session.createProducer(exchange);
- }
-
- private void shutdown()
- {
- try
- {
- _session.close();
- _connection.stop();
- _connection.close();
- }
- catch(Exception e)
- {
- e.printStackTrace(System.out);
- }
- }
-
- private void report()
- {
- try
- {
- String msg = getReport();
- _controller.send(_factory.createReportResponseMessage(msg));
- System.out.println("Sent report: " + msg);
- }
- catch(Exception e)
- {
- e.printStackTrace(System.out);
- }
- }
-
- private String getReport() throws JMSException
- {
- long time = (System.currentTimeMillis() - start);
- return "Received " + count + " in " + time + "ms";
- }
-
- public void onMessage(Message message)
- {
- if(count == 0) start = System.currentTimeMillis();
-
- if(_factory.isShutdown(message))
- {
- shutdown();
- }
- else if(_factory.isReport(message))
- {
- //send a report:
- report();
- }
- else if (++count % 100 == 0)
- {
- System.out.println("Received " + count + " messages.");
- }
- }
-
- public static void main(String[] argv) throws Exception
- {
- Config config = new Config();
- config.setType(Config.HEADERS);
- config.setName("test_headers_exchange");
- config.setOptions(argv);
- new Listener((AMQConnection) config.getConnection(), config.getDestination());
- }*/
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/headers/MessageFactory.java b/qpid/java/client/src/old_test/java/org/apache/qpid/headers/MessageFactory.java
deleted file mode 100644
index a2d575fdd4..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/headers/MessageFactory.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.headers;
-
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.framing.FieldTableFactory;
-
-import javax.jms.BytesMessage;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.TextMessage;
-
-/**
- */
-class MessageFactory
-{
- private static final char[] DATA = "abcdefghijklmnopqrstuvwxyz".toCharArray();
-
- private final AMQSession _session;
- private final byte[] _payload;
-
- private String[] _headerNames;
-
- MessageFactory(AMQSession session)
- {
- this(session, Integer.getInteger("amqj.test.message_size", 256).intValue(), 5);
- }
-
- MessageFactory(AMQSession session, int payloadSize, int headerCount)
- {
- if (headerCount < 1)
- {
- throw new IllegalArgumentException("Header count must be positive");
- }
- _session = session;
- _payload = new byte[payloadSize];
- for (int i = 0; i < _payload.length; i++)
- {
- _payload[i] = (byte) DATA[i % DATA.length];
- }
- _headerNames = new String[headerCount];
- // note that with the standard encoding the headers get prefixed with an S to indicate their type
- for (int i = 0; i < _headerNames.length; i++)
- {
- if (i < 10)
- {
- _headerNames[i] = "F000" + i;
- }
- else if (i >= 10 && i < 100)
- {
- _headerNames[i] = "F00" + i;
- }
- else
- {
- _headerNames[i] = "F0" + i;
- }
- }
- }
-
- Message createEventMessage() throws JMSException
- {
- BytesMessage msg = _session.createBytesMessage();
- if (_payload.length != 0)
- {
- msg.writeBytes(_payload);
- }
- return setHeaders(msg, _headerNames);
- }
-
- Message createShutdownMessage() throws JMSException
- {
- return setHeaders(_session.createMessage(), new String[]{"F0000", "SHUTDOWN"});
- }
-
- Message createReportRequestMessage() throws JMSException
- {
- return setHeaders(_session.createMessage(), new String[]{"F0000", "REPORT"});
- }
-
- Message createReportResponseMessage(String msg) throws JMSException
- {
- return setHeaders(_session.createTextMessage(msg), new String[]{"CONTROL", "REPORT"});
- }
-
- boolean isShutdown(Message m)
- {
- return checkPresent(m, "SHUTDOWN");
- }
-
- boolean isReport(Message m)
- {
- return checkPresent(m, "REPORT");
- }
-
- Object getReport(Message m)
- {
- try
- {
- return ((TextMessage) m).getText();
- }
- catch (JMSException e)
- {
- e.printStackTrace(System.out);
- return e.toString();
- }
- }
-
- FieldTable getConsumerBinding()
- {
- FieldTable binding = FieldTableFactory.newFieldTable();
- binding.setString("SF0000", "value");
- return binding;
- }
-
- FieldTable getControllerBinding()
- {
- FieldTable binding = FieldTableFactory.newFieldTable();
- binding.setString("SCONTROL", "value");
- return binding;
- }
-
- MessageConsumer createConsumer(Destination source) throws Exception
- {
- return _session.createConsumer(source, 0, false, true, null, getConsumerBinding());
- }
-
- MessageConsumer createController(Destination source) throws Exception
- {
- return _session.createConsumer(source, 0, false, true, null, getControllerBinding());
- }
-
- private static boolean checkPresent(Message m, String s)
- {
- try
- {
- return m.getStringProperty(s) != null;
- }
- catch (JMSException e)
- {
- e.printStackTrace(System.out);
- return false;
- }
- }
-
- private static Message setHeaders(Message m, String[] headers) throws JMSException
- {
- for (int i = 0; i < headers.length; i++)
- {
- // the value in GRM is 5 bytes
- m.setStringProperty(headers[i], "value");
- }
- return m;
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/headers/Publisher.java b/qpid/java/client/src/old_test/java/org/apache/qpid/headers/Publisher.java
deleted file mode 100644
index d9ef702c48..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/headers/Publisher.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.headers;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQSession;
-//import org.apache.qpid.testutil.Config;
-
-import javax.jms.*;
-
-public class Publisher // implements MessageListener
-{
-/* private final Object _lock = new Object();
- private final AMQConnection _connection;
- private final AMQSession _session;
- private final Destination _exchange;
- private final MessageFactory _factory;
- private final MessageProducer _publisher;
- private int _count;
-
- Publisher(AMQConnection connection, Destination exchange) throws Exception
- {
- _connection = connection;
- _exchange = exchange;
- _session = (AMQSession) _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- _factory = new MessageFactory(_session, 0, 19);
- _publisher = _session.createProducer(_exchange);
- }
-
- Publisher(Config config) throws Exception
- {
- this((AMQConnection) config.getConnection(), config.getDestination());
- }
-
- private void test(int msgCount, int consumerCount) throws Exception
- {
- _count = consumerCount;
- _factory.createController(_exchange).setMessageListener(this);
- _connection.start();
- long start = System.currentTimeMillis();
- publish(msgCount);
- waitForCompletion(consumerCount);
- long end = System.currentTimeMillis();
-
- System.out.println("Completed in " + (end - start) + " ms.");
-
- //request shutdown
- _publisher.send(_factory.createShutdownMessage());
-
- _connection.stop();
- _connection.close();
- }
-
- private void publish(int count) throws Exception
- {
-
- //send events
- for (int i = 0; i < count; i++)
- {
- _publisher.send(_factory.createEventMessage());
- if ((i + 1) % 100 == 0)
- {
- System.out.println("Sent " + (i + 1) + " messages");
- }
- }
-
- //request report
- _publisher.send(_factory.createReportRequestMessage());
- }
-
- private void waitForCompletion(int consumers) throws Exception
- {
- System.out.println("Waiting for completion...");
- synchronized (_lock)
- {
- while (_count > 0)
- {
- _lock.wait();
- }
- }
- }
-
-
- public void onMessage(Message message)
- {
- System.out.println("Received report " + _factory.getReport(message) + " " + --_count + " remaining");
- if (_count == 0)
- {
- synchronized (_lock)
- {
- _lock.notify();
- }
- }
- }
-
-
- public static void main(String[] argv) throws Exception
- {
- if (argv.length >= 2)
- {
- int msgCount = Integer.parseInt(argv[argv.length - 2]);
- int consumerCount = Integer.parseInt(argv[argv.length - 1]);
-
- Config config = new Config();
- config.setType(Config.HEADERS);
- config.setName("test_headers_exchange");
- String[] options = new String[argv.length - 2];
- System.arraycopy(argv, 0, options, 0, options.length);
- config.setOptions(options);
-
- new Publisher(config).test(msgCount, consumerCount);
- }
-
- }*/
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Bind.java b/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Bind.java
deleted file mode 100644
index ee6a12c233..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Bind.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jndi.referenceable;
-
-import org.apache.qpid.client.*;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.url.URLSyntaxException;
-
-import javax.jms.*;
-import javax.naming.*;
-
-import java.util.Properties;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-/**
- * Binds a reference from a JNDI source.
- * Given a properties file with the JNDI information and a binding string.
- */
-public class Bind
-{
- private static final String USAGE="USAGE: java bind <JNDI Properties file> -cf <url> <binding> | -c <url> <binding> [-t <topic Name> <binding>] [-q <queue Name> <binding>]";
- public Bind(String propertiesFile, String bindingURL, Referenceable reference) throws NameAlreadyBoundException, NoInitialContextException
- {
- // Set up the environment for creating the initial context
- String qpid_home = System.getProperty("QPID_HOME");
-
- if (qpid_home == null || qpid_home.equals(""))
- {
- System.out.println("QPID_HOME is not set");
- System.exit(1);
- }
-
- if (qpid_home.charAt(qpid_home.length() - 1) != '/')
- {
- qpid_home += "/";
- }
-
- try
- {
- InputStream inputStream = new FileInputStream(qpid_home + propertiesFile);
- Properties properties = new Properties();
- properties.load(inputStream);
-
- // Create the initial context
- Context ctx = new InitialContext(properties);
-
- // Perform the binds
- ctx.bind(bindingURL, reference);
-
- // Close the context when we're done
- ctx.close();
- }
- catch (IOException ioe)
- {
- System.out.println("Unable to access properties file:" + propertiesFile + " Due to:" + ioe);
- }
- catch (NamingException e)
- {
- System.out.println("Operation failed: " + e);
- if (e instanceof NameAlreadyBoundException)
- {
- throw (NameAlreadyBoundException) e;
- }
-
- if (e instanceof NoInitialContextException)
- {
- throw (NoInitialContextException) e;
- }
- }
-
- }
-
- private static String parse(String[] args, int index, String what, String type)
- {
- try
- {
- return args[index];
- }
- catch (IndexOutOfBoundsException ioobe)
- {
- System.out.println("ERROR: No " + what + " specified for " + type + ".");
- System.out.println(USAGE);
- System.exit(1);
- }
-
- // The path is either return normally or exception.. which calls system exit so keep the compiler happy
- return "Never going to happen";
- }
-
-
- public static void main(String[] args) throws NameAlreadyBoundException, NoInitialContextException, URLSyntaxException, AMQException, JMSException
- {
-
-
- org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
-
-// org.apache.log4j.Logger _logger = org.apache.log4j.Logger.getLogger(AMQConnection.class);
-// _logger.setLevel(org.apache.log4j.Level.OFF);
-
- boolean exit = false;
-
- String qpid_home = System.getProperty("QPID_HOME");
-
- if (qpid_home == null || qpid_home.equals(""))
- {
- System.out.println("QPID_HOME is not set");
- exit = true;
- }
-
- if (args.length <= 2)
- {
- System.out.println("At least a connection or connection factory must be requested to be bound.");
- exit = true;
- }
- else
- {
- if ((args.length - 1) % 3 != 0)
- {
- System.out.println("Not all values have full details");
- exit = true;
- }
- }
- if (exit)
- {
- System.out.println(USAGE);
- System.exit(1);
- }
-
- if (qpid_home.charAt(qpid_home.length() - 1) != '/')
-
- {
- qpid_home += "/";
- }
-
- AMQConnectionFactory cf = null;
- AMQConnection c = null;
- AMQSession session = null;
- Referenceable reference = null;
-
- for (int index = 1; index < args.length; index ++)
- {
- String obj = args[index];
-
- String what = "Invalid";
- String binding;
-
- if (obj.startsWith("-c"))
- {
- boolean isFactory = obj.contains("f");
-
-
- if (isFactory)
- {
- what = "ConnectionFactory";
- }
- else
- {
- what = "Factory";
- }
-
- String url = parse(args, ++index, "url", what);
-
- if (isFactory)
- {
-
- cf = new AMQConnectionFactory(url);
- reference = cf;
- }
- else
- {
- c = new AMQConnection(url);
- reference = c;
- }
-
- }
-
- if (obj.equals("-t") || obj.equals("-q"))
- {
- if (c == null)
- {
- c = (AMQConnection) cf.createConnection();
- }
-
- if (session == null)
- {
- session = (AMQSession) c.createSession(false, Session.AUTO_ACKNOWLEDGE);
- }
-
- }
-
- if (obj.equals("-t"))
- {
-
- String topicName = parse(args, ++index, "Topic Name", "Topic");
- reference = (AMQTopic) session.createTopic(topicName);
- what = "Topic";
- }
- else
- {
- if (obj.equals("-q"))
- {
- String topicName = parse(args, ++index, "Queue Name", "Queue");
- reference = (AMQQueue) session.createQueue(topicName);
- what = "Queue";
- }
- }
-
- binding = parse(args, ++index, "binding", what);
- if (binding == null)
- {
- System.out.println(obj + " is not a known Object to bind.");
- System.exit(1);
- }
- else
- {
- System.out.print("Binding:" + reference + " to " + binding);
- try
- {
- new Bind(args[0], binding, reference);
- System.out.println(" ..Successful");
-
- }
- catch (NameAlreadyBoundException nabe)
- {
- System.out.println("");
- if (!obj.startsWith("-c") || index == args.length - 1)
- {
- throw nabe;
- }
- else
- {
- System.out.println("Continuing with other bindings using the same connection details");
- }
- }
- finally
- {
- if (!obj.startsWith("-c") || index == args.length - 1)
- {
- if (c != null)
- {
- c.close();
- }
- }
- }
- }
- }
-
- if (c != null)
- {
- c.close();
- }
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Lookup.java b/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Lookup.java
deleted file mode 100644
index 1c9d8b0fd5..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Lookup.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jndi.referenceable;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-/**
- * Looksup a reference from a JNDI source.
- * Given a properties file with the JNDI information and a binding string.
- */
-public class Lookup
-{
- private static final String USAGE = "USAGE: java lookup <JNDI Properties file> -b <binding>";
- private Properties _properties;
- private Object _object;
-
- public Lookup(String propertiesFile, String bindingValue) throws NamingException
- {
- // Set up the environment for creating the initial context
- String qpid_home = System.getProperty("QPID_HOME");
-
- if (qpid_home == null || qpid_home.equals(""))
- {
- System.out.println("QPID_HOME is not set");
- System.exit(1);
- }
-
- if (qpid_home.charAt(qpid_home.length() - 1) != '/')
- {
- qpid_home += "/";
- }
-
- try
- {
- InputStream inputStream = new FileInputStream(qpid_home + propertiesFile);
- Properties properties = new Properties();
- properties.load(inputStream);
-
- _properties = properties;
- lookup(bindingValue);
- }
- catch (IOException ioe)
- {
- System.out.println("Unable to access properties file:" + propertiesFile + " Due to:" + ioe);
- }
- }
-
- public Object lookup(String bindingValue) throws NamingException
- {
-
- // Create the initial context
- Context ctx = new InitialContext(_properties);
-
- // Perform the binds
- _object = ctx.lookup(bindingValue);
-
- // Close the context when we're done
- ctx.close();
-
- return getObject();
- }
-
- public Object getObject()
- {
- return _object;
- }
-
- private static String parse(String[] args, int index, String what)
- {
- try
- {
- return args[index];
- }
- catch (IndexOutOfBoundsException ioobe)
- {
- System.out.println("ERROR: No " + what + " specified.");
- System.out.println(USAGE);
- System.exit(1);
- }
-
- // The path is either return normally or exception.. which calls system exit so keep the compiler happy
- return "Never going to happen";
- }
-
-
- public static void main(String[] args) throws NamingException
- {
- boolean exit = false;
-
- String qpid_home = System.getProperty("QPID_HOME");
-
- if (qpid_home == null || qpid_home.equals(""))
- {
- System.out.println("QPID_HOME is not set");
- exit = true;
- }
-
- if (args.length <= 2)
- {
- System.out.println("At least a connection or connection factory must be requested to be bound.");
- exit = true;
- }
- else
- {
- if ((args.length - 1) % 2 != 0)
- {
- System.out.println("Not all values have full details");
- exit = true;
- }
- }
- if (exit)
- {
- System.out.println(USAGE);
- System.exit(1);
- }
-
- if (qpid_home.charAt(qpid_home.length() - 1) != '/')
-
- {
- qpid_home += "/";
- }
-
- for (int index = 1; index < args.length; index ++)
- {
- String obj = args[index];
-
-
- if (obj.equals("-b"))
- {
- String binding = parse(args, ++index, "binding");
-
- if (binding == null)
- {
- System.out.println("Binding not specified.");
- System.exit(1);
- }
- else
- {
- System.out.print("Looking up:" + binding);
- try
- {
- Lookup l = new Lookup(args[0], binding);
-
- Object object = l.getObject();
-
- if (object instanceof Connection)
- {
- try
- {
- ((Connection) object).close();
- }
- catch (JMSException jmse)
- {
- ;
- }
- }
- }
- catch (NamingException nabe)
- {
- System.out.println("Problem unbinding " + binding + " continuing with other values.");
- }
- }
- }// if -b
- else
- {
- System.out.println("Continuing with other bindings option not known:" + obj);
- }
- }//for
- }//main
-}//class
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Unbind.java b/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Unbind.java
deleted file mode 100644
index 1acead674c..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/jndi/referenceable/Unbind.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jndi.referenceable;
-
-import javax.naming.*;
-
-import java.util.Properties;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-/**
- * Unbinds a reference from a JNDI source.
- * Given a properties file with the JNDI information and a binding string.
- */
-public class Unbind
-{
- private static final String USAGE = "USAGE: java unbind <JNDI Properties file> -b <binding>";
-
- public Unbind(String propertiesFile, String bindingValue) throws NamingException
- {
- // Set up the environment for creating the initial context
- String qpid_home = System.getProperty("QPID_HOME");
-
- if (qpid_home == null || qpid_home.equals(""))
- {
- System.out.println("QPID_HOME is not set");
- System.exit(1);
- }
-
- if (qpid_home.charAt(qpid_home.length() - 1) != '/')
- {
- qpid_home += "/";
- }
-
- try
- {
- InputStream inputStream = new FileInputStream(qpid_home + propertiesFile);
- Properties properties = new Properties();
- properties.load(inputStream);
-
- // Create the initial context
- Context ctx = new InitialContext(properties);
-
- // Perform the binds
- ctx.unbind(bindingValue);
-
- // Close the context when we're done
- ctx.close();
- }
- catch (IOException ioe)
- {
- System.out.println("Unable to access properties file:" + propertiesFile + " Due to:" + ioe);
- }
- }
-
- private static String parse(String[] args, int index, String what)
- {
- try
- {
- return args[index];
- }
- catch (IndexOutOfBoundsException ioobe)
- {
- System.out.println("ERROR: No " + what + " specified.");
- System.out.println(USAGE);
- System.exit(1);
- }
-
- // The path is either return normally or exception.. which calls system exit so keep the compiler happy
- return "Never going to happen";
- }
-
-
- public static void main(String[] args) throws NamingException
- {
- boolean exit = false;
-
- String qpid_home = System.getProperty("QPID_HOME");
-
- if (qpid_home == null || qpid_home.equals(""))
- {
- System.out.println("QPID_HOME is not set");
- exit = true;
- }
-
- if (args.length <= 2)
- {
- System.out.println("At least a connection or connection factory must be requested to be bound.");
- exit = true;
- }
- else
- {
- if ((args.length - 1) % 2 != 0)
- {
- System.out.println("Not all values have full details");
- exit = true;
- }
- }
- if (exit)
- {
- System.out.println(USAGE);
- System.exit(1);
- }
-
- if (qpid_home.charAt(qpid_home.length() - 1) != '/')
-
- {
- qpid_home += "/";
- }
-
- for (int index = 1; index < args.length; index ++)
- {
- String obj = args[index];
-
-
- if (obj.equals("-b"))
- {
- String binding = parse(args, ++index, "binding");
-
- if (binding == null)
- {
- System.out.println("Binding not specified.");
- System.exit(1);
- }
- else
- {
- System.out.print("UnBinding:" + binding);
- try
- {
- new Unbind(args[0], binding);
- System.out.println(" ..Successful");
- }
- catch (NamingException nabe)
- {
- System.out.println("");
-
- System.out.println("Problem unbinding " + binding + " continuing with other values.");
- }
- }
- }// if -b
- else
- {
- System.out.println("Continuing with other bindings option not known:" + obj);
- }
- }//for
- }//main
-}//class
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/latency/LatencyTest.java b/qpid/java/client/src/old_test/java/org/apache/qpid/latency/LatencyTest.java
deleted file mode 100644
index 4865a68dc4..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/latency/LatencyTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.latency;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQDestination;
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-
-import javax.jms.MessageProducer;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.JMSException;
-import javax.jms.TextMessage;
-import javax.jms.BytesMessage;
-
-public class LatencyTest implements MessageListener
-{
- private volatile boolean waiting;
- private int sent;
- private int received;
-
- private final byte[] data;
-
- private long min = Long.MAX_VALUE;
- private long max = 0;
- private long total = 0;
-
- LatencyTest(String broker, int count, int delay, int length) throws Exception
- {
- this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test"), count, delay, length);
- }
-
- LatencyTest(AMQConnection connection, int count, int delay, int length) throws Exception
- {
- this(connection, new AMQQueue(connection.getDefaultQueueExchangeName(), new AMQShortString(randomize("LatencyTest")), true), count, delay, length);
- }
-
- LatencyTest(AMQConnection connection, AMQDestination destination, int count, int delay, int length) throws Exception
- {
- AMQSession session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
-
- data = new byte[length];
- for(int i = 0; i < data.length; i++)
- {
- data[i] = (byte) (i % 100);
- }
-
- //set up a consumer
- session.createConsumer(destination).setMessageListener(this);
- connection.start();
-
- //create a publisher
- MessageProducer producer = session.createProducer(destination, false, false, true);
-
- //publish at a low volume
- for(int i = 0; i < count; i++)
- {
- BytesMessage msg = session.createBytesMessage();
- msg.writeBytes(data);
- msg.setStringProperty("sent-at", Long.toString(System.nanoTime()));
- producer.send(msg);
- Thread.sleep(delay);
- if(++sent % 100 == 0)
- {
- System.out.println("Sent " + sent + " of " + count);
- }
- }
-
- waitUntilReceived(sent);
-
- session.close();
- connection.close();
-
- System.out.println("Latency (in nanoseconds): avg=" + (total/sent) + ", min=" + min + ", max=" + max
- + ", avg(discarding min and max)=" + ((total - min - max) / (sent - 2)));
- }
-
-
- private synchronized void waitUntilReceived(int count) throws InterruptedException
- {
- waiting = true;
- while(received < count)
- {
- wait();
- }
- waiting = false;
- }
-
- public void onMessage(Message message)
- {
- received++;
- try
- {
- long sent = Long.parseLong(message.getStringProperty("sent-at"));
- long time = System.nanoTime() - sent;
- total += time;
- min = Math.min(min, time);
- max = Math.max(max, time);
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- }
-
- if(waiting){
- synchronized(this)
- {
- notify();
- }
- }
- }
-
- private static String randomize(String in)
- {
- return in + System.currentTimeMillis();
- }
-
- public static void main(String[] argv) throws Exception
- {
- String host = argv.length > 0 ? argv[0] : "localhost:5672";
- if("-help".equals(host))
- {
- System.out.println("Usage: <broker> <message count> <delay between messages> <message size>");
- }
- int count = argv.length > 1 ? Integer.parseInt(argv[1]) : 1000;
- int delay = argv.length > 2 ? Integer.parseInt(argv[2]) : 1000;
- int size = argv.length > 3 ? Integer.parseInt(argv[3]) : 512;
- new LatencyTest(host, count, delay, size);
- }
-
-
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/mina/AcceptorTest.java b/qpid/java/client/src/old_test/java/org/apache/qpid/mina/AcceptorTest.java
deleted file mode 100644
index f0ac0e6902..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/mina/AcceptorTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.mina;
-
-import org.apache.log4j.Logger;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoHandlerAdapter;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.transport.socket.nio.SocketAcceptor;
-import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
-import org.apache.mina.transport.socket.nio.SocketSessionConfig;
-import org.apache.qpid.pool.ReadWriteThreadModel;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
-import junit.framework.TestCase;
-
-/**
- * Tests MINA socket performance. This acceptor simply reads data from the network and writes it back again.
- *
- */
-public class AcceptorTest extends TestCase
-{
- private static final Logger _logger = Logger.getLogger(AcceptorTest.class);
-
- public static int PORT = 9999;
-
- private static class TestHandler extends IoHandlerAdapter
- {
- private int _sentCount;
-
- private int _bytesSent;
-
- public void messageReceived(IoSession session, Object message) throws Exception
- {
- ((ByteBuffer) message).acquire();
- session.write(message);
- _logger.debug("Sent response " + ++_sentCount);
- _bytesSent += ((ByteBuffer)message).remaining();
- _logger.debug("Bytes sent: " + _bytesSent);
- }
-
- public void messageSent(IoSession session, Object message) throws Exception
- {
- //((ByteBuffer) message).release();
- }
-
- public void exceptionCaught(IoSession session, Throwable cause) throws Exception
- {
- _logger.error("Error: " + cause, cause);
- }
- }
-
- public void testStartAcceptor() throws IOException
- {
- IoAcceptor acceptor = null;
- acceptor = new SocketAcceptor();
-
- SocketAcceptorConfig config = (SocketAcceptorConfig) acceptor.getDefaultConfig();
- SocketSessionConfig sc = (SocketSessionConfig) config.getSessionConfig();
- sc.setTcpNoDelay(true);
- sc.setSendBufferSize(32768);
- sc.setReceiveBufferSize(32768);
-
- config.setThreadModel(ReadWriteThreadModel.getInstance());
-
- acceptor.bind(new InetSocketAddress(PORT),
- new TestHandler());
- _logger.info("Bound on port " + PORT);
- }
-
- public static void main(String[] args) throws IOException
- {
- AcceptorTest a = new AcceptorTest();
- a.testStartAcceptor();
- }
-
- public static junit.framework.Test suite()
- {
- return new junit.framework.TestSuite(AcceptorTest.class);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/mina/BlockingAcceptorTest.java b/qpid/java/client/src/old_test/java/org/apache/qpid/mina/BlockingAcceptorTest.java
deleted file mode 100644
index bfe29c47e6..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/mina/BlockingAcceptorTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.mina;
-
-import org.apache.log4j.Logger;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-import junit.framework.TestCase;
-
-public class BlockingAcceptorTest extends TestCase
-{
- private static final Logger _logger = Logger.getLogger(BlockingAcceptorTest.class);
-
- public static int PORT = 9999;
-
- public void testStartAcceptor() throws IOException
- {
-
- ServerSocket sock = new ServerSocket(PORT);
-
- sock.setReuseAddress(true);
- sock.setReceiveBufferSize(32768);
- _logger.info("Bound on port " + PORT);
-
- while (true)
- {
- final Socket s = sock.accept();
- _logger.info("Received connection from " + s.getRemoteSocketAddress());
- s.setReceiveBufferSize(32768);
- s.setSendBufferSize(32768);
- s.setTcpNoDelay(true);
- new Thread(new Runnable()
- {
- public void run()
- {
- byte[] chunk = new byte[32768];
- try
- {
- InputStream is = s.getInputStream();
- OutputStream os = s.getOutputStream();
-
- while (true)
- {
- int count = is.read(chunk, 0, chunk.length);
- if (count > 0)
- {
- os.write(chunk, 0, count);
- }
- }
- }
- catch (IOException e)
- {
- _logger.error("Error - closing connection: " + e, e);
- }
- }
- }, "SocketReaderWriter").start();
- }
- }
-
- public static void main(String[] args) throws IOException
- {
- BlockingAcceptorTest a = new BlockingAcceptorTest();
- a.testStartAcceptor();
- }
-
- public static junit.framework.Test suite()
- {
- return new junit.framework.TestSuite(AcceptorTest.class);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/mina/WriterTest.java b/qpid/java/client/src/old_test/java/org/apache/qpid/mina/WriterTest.java
deleted file mode 100644
index 910345624f..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/mina/WriterTest.java
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.mina;
-
-import org.apache.log4j.Logger;
-import org.apache.mina.common.*;
-import org.apache.mina.transport.socket.nio.SocketConnector;
-import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
-import org.apache.mina.transport.socket.nio.SocketSessionConfig;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.concurrent.CountDownLatch;
-
-import junit.framework.TestCase;
-
-public class WriterTest extends TestCase
-{
- private static final Logger _logger = Logger.getLogger(WriterTest.class);
-
- private static class RunnableWriterTest implements Runnable
- {
- private Logger _logger;
-
- private IoSession _session;
-
- private long _startTime;
-
- private long[] _chunkTimes;
-
- private int _chunkCount = 500000;
-
- private int _chunkSize = 1024;
-
- private CountDownLatch _notifier;
-
- public RunnableWriterTest(Logger logger)
- {
- _logger = logger;
- }
-
- public void run()
- {
- _startTime = System.currentTimeMillis();
- _notifier = new CountDownLatch(1);
- for (int i = 0; i < _chunkCount; i++)
- {
- ByteBuffer buf = ByteBuffer.allocate(_chunkSize, false);
- byte check = (byte) (i % 128);
- buf.put(check);
- buf.fill((byte)88, buf.remaining());
- buf.flip();
- _session.write(buf);
- }
-
- try
- {
- _logger.info("All buffers sent; waiting for receipt from server");
- _notifier.await();
- }
- catch (InterruptedException e)
- {
- }
- _logger.info("Completed");
- long totalTime = System.currentTimeMillis() - _startTime;
- _logger.info("Total time: " + totalTime);
- _logger.info("MB per second: " + (_chunkSize * _chunkCount)/totalTime);
- long lastChunkTime = _startTime;
- double average = 0;
- for (int i = 0; i < _chunkTimes.length; i++)
- {
- if (i == 0)
- {
- average = _chunkTimes[i] - _startTime;
- }
- else
- {
- long delta = _chunkTimes[i] - lastChunkTime;
- if (delta != 0)
- {
- average = (average + delta)/2;
- }
- }
- lastChunkTime = _chunkTimes[i];
- }
- _logger.info("Average chunk time: " + average + "ms");
- CloseFuture cf = _session.close();
- cf.join();
- }
-
- private class WriterHandler extends IoHandlerAdapter
- {
- private int _chunksReceived = 0;
-
- private int _partialBytesRead = 0;
-
- private byte _partialCheckNumber;
-
- private int _totalBytesReceived = 0;
-
- public void messageReceived(IoSession session, Object message) throws Exception
- {
- ByteBuffer result = (ByteBuffer) message;
- _totalBytesReceived += result.remaining();
- int size = result.remaining();
- long now = System.currentTimeMillis();
- if (_partialBytesRead > 0)
- {
- int offset = _chunkSize - _partialBytesRead;
- if (size >= offset)
- {
- _chunkTimes[_chunksReceived++] = now;
- result.position(offset);
- }
- else
- {
- // have not read even one chunk, including the previous partial bytes
- _partialBytesRead += size;
- return;
- }
- }
-
- int chunkCount = result.remaining()/_chunkSize;
-
- for (int i = 0; i < chunkCount; i++)
- {
- _chunkTimes[_chunksReceived++] = now;
- byte check = result.get();
- _logger.debug("Check number " + check + " read");
- if (check != (byte)((_chunksReceived - 1)%128))
- {
- _logger.error("Check number " + check + " read when expected " + (_chunksReceived%128));
- }
- _logger.debug("Chunk times recorded");
-
- try
- {
- result.skip(_chunkSize - 1);
- }
- catch (IllegalArgumentException e)
- {
- _logger.error("Position was: " + result.position());
- _logger.error("Tried to skip to: " + (_chunkSize * i));
- _logger.error("limit was; " + result.limit());
- }
- }
- _logger.debug("Chunks received now " + _chunksReceived);
- _logger.debug("Bytes received: " + _totalBytesReceived);
- _partialBytesRead = result.remaining();
-
- if (_partialBytesRead > 0)
- {
- _partialCheckNumber = result.get();
- }
-
- if (_chunksReceived >= _chunkCount)
- {
- _notifier.countDown();
- }
-
- }
-
- public void exceptionCaught(IoSession session, Throwable cause) throws Exception
- {
- _logger.error("Error: " + cause, cause);
- }
- }
-
- public void startWriter(int chunkSize) throws IOException, InterruptedException
- {
- _chunkSize = chunkSize;
-
- IoConnector ioConnector = null;
-
- ioConnector = new SocketConnector();
-
- SocketConnectorConfig cfg = (SocketConnectorConfig) ioConnector.getDefaultConfig();
- cfg.setThreadModel(ThreadModel.MANUAL);
- SocketSessionConfig scfg = (SocketSessionConfig) cfg.getSessionConfig();
- scfg.setTcpNoDelay(true);
- scfg.setSendBufferSize(32768);
- scfg.setReceiveBufferSize(32768);
-
- final InetSocketAddress address = new InetSocketAddress("localhost", AcceptorTest.PORT);
- _logger.info("Attempting connection to " + address);
- ConnectFuture future = ioConnector.connect(address, new WriterHandler());
- // wait for connection to complete
- future.join();
- _logger.info("Connection completed");
- // we call getSession which throws an IOException if there has been an error connecting
- _session = future.getSession();
- _chunkTimes = new long[_chunkCount];
- Thread t = new Thread(this);
- t.start();
- t.join();
- _logger.info("Test completed");
- }
- }
-
- private RunnableWriterTest _runnableWriterTest = new RunnableWriterTest(_logger);
-
- public void test1k() throws IOException, InterruptedException
- {
- _logger.info("Starting 1k test");
- _runnableWriterTest.startWriter(1024);
- }
-
- public void test2k() throws IOException, InterruptedException
- {
- _logger.info("Starting 2k test");
- _runnableWriterTest.startWriter(2048);
- }
-
- public void test4k() throws IOException, InterruptedException
- {
- _logger.info("Starting 4k test");
- _runnableWriterTest.startWriter(4096);
- }
-
- public void test8k() throws IOException, InterruptedException
- {
- _logger.info("Starting 8k test");
- _runnableWriterTest.startWriter(8192);
- }
-
- public void test16k() throws IOException, InterruptedException
- {
- _logger.info("Starting 16k test");
- _runnableWriterTest.startWriter(16384);
- }
-
- public void test32k() throws IOException, InterruptedException
- {
- _logger.info("Starting 32k test");
- _runnableWriterTest.startWriter(32768);
- }
-
- public static void main(String[] args) throws IOException, InterruptedException
- {
- WriterTest w = new WriterTest();
- //w.test1k();
- //w.test2k();
- //w.test4k();
- w.test8k();
- //w.test16k();
- //w.test32k();
- }
-
- public static junit.framework.Test suite()
- {
- return new junit.framework.TestSuite(WriterTest.class);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/multiconsumer/AMQTest.java b/qpid/java/client/src/old_test/java/org/apache/qpid/multiconsumer/AMQTest.java
deleted file mode 100644
index db02b9954a..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/multiconsumer/AMQTest.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.multiconsumer;
-
-import java.io.ByteArrayOutputStream;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-
-import javax.jms.Connection;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQTopic;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.jms.Session;
-
-/**
- * Test AMQ.
- */
-public class AMQTest extends TestCase implements ExceptionListener
-{
-
- private final static String COMPRESSION_PROPNAME = "_MSGAPI_COMP";
- private final static String UTF8 = "UTF-8";
- private static final String SUBJECT = "test.amq";
- private static final String DUMMYCONTENT = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- private static final String HUGECONTENT;
-
- private AMQConnection connect = null;
- private Session pubSession = null;
- private Session subSession = null;
- private Topic topic = null;
-
- static
- {
- StringBuilder sb = new StringBuilder(DUMMYCONTENT.length() * 115);
- for (int i = 0; i < 100; i++)
- {
- sb.append(DUMMYCONTENT);
- }
- HUGECONTENT = sb.toString();
- }
-
- private void setup() throws Exception
- {
- connect = new AMQConnection("localhost", 5672, "guest", "guest", "client1", "/");
- connect.setExceptionListener(this);
- pubSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
- subSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
- topic = new AMQTopic(pubSession.getDefaultTopicExchangeName(), new AMQShortString(SUBJECT));
-
- connect.start();
- }
-
- public void testMultipleListeners() throws Exception
- {
- setup();
- try
- {
- // Create 5 listeners
- MsgHandler[] listeners = new MsgHandler[5];
- for (int i = 0; i < listeners.length; i++)
- {
- listeners[i] = new MsgHandler();
- MessageConsumer subscriber = subSession.createConsumer(topic);
- subscriber.setMessageListener(listeners[i]);
- }
- MessageProducer publisher = pubSession.createProducer(topic);
- // Send a single message
- TextMessage msg = pubSession.createTextMessage();
- msg.setText(DUMMYCONTENT);
- publisher.send(msg);
- Thread.sleep(5000);
- // Check listeners to ensure they all got it
- for (int i = 0; i < listeners.length; i++)
- {
- if (listeners[i].isGotIt())
- {
- System.out.println("Got callback for listener " + i);
- }
- else
- {
- TestCase.fail("Listener " + i + " did not get callback");
- }
- }
- }
- catch (Throwable e)
- {
- System.err.println("Error: " + e);
- e.printStackTrace(System.err);
- }
- finally
- {
- close();
- }
- }
-
- public void testCompression() throws Exception
- {
- setup();
- String comp = this.compressString(HUGECONTENT);
- try
- {
- MsgHandler listener = new MsgHandler();
- MessageConsumer subscriber = subSession.createConsumer(topic);
- subscriber.setMessageListener(listener);
- MessageProducer publisher = pubSession.createProducer(topic);
-
- // Send a single message
- TextMessage msg = pubSession.createTextMessage();
- // Set the compressed text
- msg.setText(comp);
- msg.setBooleanProperty(COMPRESSION_PROPNAME, true);
- publisher.send(msg);
- Thread.sleep(1000);
- // Check listeners to ensure we got it
- if (listener.isGotIt())
- {
- System.out.println("Got callback for listener");
- }
- else
- {
- TestCase.fail("Listener did not get callback");
- }
- }
- finally
- {
- close();
- }
- }
-
- private void close() throws Exception
- {
- if (connect != null)
- {
- connect.close();
- }
- }
-
- private class MsgHandler implements MessageListener
- {
- private boolean gotIt = false;
-
- public void onMessage(Message msg)
- {
- try
- {
- TextMessage textMessage = (TextMessage) msg;
- String string = textMessage.getText();
- if (string != null && string.length() > 0)
- {
- gotIt = true;
- }
- if (textMessage.getBooleanProperty(COMPRESSION_PROPNAME))
- {
- string = inflateString(string);
- }
- System.out.println("Got callback of size " + (string==null?0:string.length()));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- public boolean isGotIt()
- {
- return this.gotIt;
- }
- }
-
- private String compressString(String string) throws Exception
- {
- long start = System.currentTimeMillis();
- byte[] input = string.getBytes();
- Deflater compressor = new Deflater(Deflater.BEST_COMPRESSION);
- compressor.setInput(input);
- compressor.finish();
-
- // Get byte array from output of compressor
- ByteArrayOutputStream baos = new ByteArrayOutputStream(input.length);
- byte[] buf = new byte[1024];
- while (!compressor.finished())
- {
- int cnt = compressor.deflate(buf);
- baos.write(buf, 0, cnt);
- }
- baos.close();
- byte[] output = baos.toByteArray();
-
- // Convert byte array into String
- byte[] base64 = Base64.encodeBase64(output);
- String sComp = new String(base64, UTF8);
-
- long diff = System.currentTimeMillis() - start;
- System.out.println("Compressed text from " + input.length + " to "
- + sComp.getBytes().length + " in " + diff + " ms");
- System.out.println("Compressed text = '" + sComp + "'");
-
- return sComp;
- }
-
- private String inflateString(String string) throws Exception
- {
- byte[] input = string.getBytes();
-
- // First convert Base64 string back to binary array
- byte[] bytes = Base64.decodeBase64(input);
-
- // Set string as input data for decompressor
- Inflater decompressor = new Inflater();
- decompressor.setInput(bytes);
-
- // Decompress the data
- ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
- byte[] buf = new byte[1024];
- while (!decompressor.finished())
- {
- int count = decompressor.inflate(buf);
- bos.write(buf, 0, count);
- }
- bos.close();
- byte[] output = bos.toByteArray();
-
- // Get the decompressed data
- return new String(output, UTF8);
- }
-
- /**
- * @see javax.jms.ExceptionListener#onException(javax.jms.JMSException)
- */
- public void onException(JMSException e)
- {
- System.err.println(e.getMessage());
- e.printStackTrace(System.err);
- }
-
-
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/pubsub1/TestPublisher.java b/qpid/java/client/src/old_test/java/org/apache/qpid/pubsub1/TestPublisher.java
deleted file mode 100644
index 37b4ff1498..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/pubsub1/TestPublisher.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.pubsub1;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.client.AMQTopic;
-import org.apache.qpid.jms.MessageProducer;
-import org.apache.qpid.jms.Session;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.TextMessage;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-/**
- * A client that behaves as follows:
- * <ul><li>Connects to a queue, whose name is specified as a cmd-line argument</li>
- * <li>Creates a temporary queue</li>
- * <li>Creates messages containing a property that is the name of the temporary queue</li>
- * <li>Fires off a message on the original queue and waits for a response on the temporary queue</li>
- * </ul>
- *
- */
-public class TestPublisher
-{
- private static final Logger _log = Logger.getLogger(TestPublisher.class);
-
- private AMQConnection _connection;
-
- private Session _session;
-
- private class CallbackHandler implements MessageListener
- {
- private int _expectedMessageCount;
-
- private int _actualMessageCount;
-
- private long _startTime;
-
- public CallbackHandler(int expectedMessageCount, long startTime)
- {
- _expectedMessageCount = expectedMessageCount;
- _startTime = startTime;
- }
-
- public void onMessage(Message m)
- {
- if (_log.isDebugEnabled())
- {
- _log.debug("Message received: " + m);
- }
- _actualMessageCount++;
- if (_actualMessageCount%1000 == 0)
- {
- _log.info("Received message count: " + _actualMessageCount);
- }
- /*if (!"henson".equals(m.toString()))
- {
- _log.error("AbstractJMSMessage response not correct: expected 'henson' but got " + m.toString());
- }
- else
- {
- if (_log.isDebugEnabled())
- {
- _log.debug("AbstractJMSMessage " + m + " received");
- }
- else
- {
- _log.info("AbstractJMSMessage received");
- }
- } */
-
- if (_actualMessageCount == _expectedMessageCount)
- {
- long timeTaken = System.currentTimeMillis() - _startTime;
- System.out.println("Total time taken to receive " + _expectedMessageCount+ " messages was " +
- timeTaken + "ms, equivalent to " +
- (_expectedMessageCount/(timeTaken/1000.0)) + " messages per second");
- }
- }
- }
-
- public TestPublisher(String host, int port, String clientID, String commandQueueName,
- final int messageCount) throws AMQException, URLSyntaxException
- {
- try
- {
- createConnection(host, port, clientID);
-
- _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- AMQTopic destination = new AMQTopic(_session.getDefaultTopicExchangeName(), new AMQShortString(commandQueueName));
- MessageProducer producer = (MessageProducer) _session.createProducer(destination);
-
- _connection.start();
- //TextMessage msg = _session.createTextMessage(tempDestination.getQueueName() + "/Presented to in conjunction with Mahnah Mahnah and the Snowths");
- final long startTime = System.currentTimeMillis();
-
- for (int i = 0; i < messageCount; i++)
- {
- TextMessage msg = _session.createTextMessage(destination.getTopicName() + "/Presented to in conjunction with Mahnah Mahnah and the Snowths: " + i);
-
- //msg.setIntProperty("a",i % 2);
- //msg.setIntProperty("b",i % 4);
-
- producer.send(msg);
- }
- _log.info("Finished sending " + messageCount + " messages");
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- }
- }
-
- private void createConnection(String host, int port, String clientID) throws AMQException, URLSyntaxException
- {
- _connection = new AMQConnection(host, port, "guest", "guest",
- clientID, "/test");
- }
-
- /**
- *
- * @param args argument 1 if present specifies the name of the temporary queue to create. Leaving it blank
- * means the server will allocate a name.
- */
- public static void main(String[] args) throws URLSyntaxException
- {
- if (args.length == 0)
- {
- System.err.println("Usage: TestPublisher <host> <port> <command queue name> <number of messages>");
- }
- try
- {
- int port = Integer.parseInt(args[1]);
- InetAddress address = InetAddress.getLocalHost();
- String clientID = address.getHostName() + System.currentTimeMillis();
- TestPublisher client = new TestPublisher(args[0], port, clientID, args[2], Integer.parseInt(args[3]));
- }
- catch (UnknownHostException e)
- {
- e.printStackTrace();
- }
- catch (AMQException e)
- {
- System.err.println("Error in client: " + e);
- e.printStackTrace();
- }
-
- //System.exit(0);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/pubsub1/TestSubscriber.java b/qpid/java/client/src/old_test/java/org/apache/qpid/pubsub1/TestSubscriber.java
deleted file mode 100644
index 450d9b3914..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/pubsub1/TestSubscriber.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.pubsub1;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQTopic;
-import org.apache.qpid.jms.Session;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.Topic;
-import java.net.InetAddress;
-
-public class TestSubscriber
-{
- private static final Logger _logger = Logger.getLogger(TestSubscriber.class);
-
- private static class TestMessageListener implements MessageListener
- {
- private String _name;
-
- private int _expectedMessageCount;
-
- private int _messageCount;
-
- private long _startTime = 0;
-
- public TestMessageListener(String name, int expectedMessageCount)
- {
- _name = name;
- _expectedMessageCount = expectedMessageCount;
- }
-
- public void onMessage(javax.jms.Message message)
- {
- if (_messageCount++ == 0)
- {
- _startTime = System.currentTimeMillis();
- }
- if (_logger.isInfoEnabled())
- {
- _logger.info(_name + " got message '" + message + "'");
- }
- if (_messageCount == _expectedMessageCount)
- {
- long totalTime = System.currentTimeMillis() - _startTime;
- _logger.error(_name + ": Total time to receive " + _messageCount + " messages was " +
- totalTime + "ms. Rate is " + (_messageCount/(totalTime/1000.0)));
- }
- if (_messageCount > _expectedMessageCount)
- {
- _logger.error("Oops! More messages received than expected (" + _messageCount + ")");
- }
- }
- }
-
- public static void main(String[] args)
- {
- _logger.info("Starting...");
-
- if (args.length != 7)
- {
- System.out.println("Usage: host port username password virtual-path expectedMessageCount selector");
- System.exit(1);
- }
- try
- {
- InetAddress address = InetAddress.getLocalHost();
- AMQConnection con1 = new AMQConnection(args[0], Integer.parseInt(args[1]), args[2], args[3],
- address.getHostName(), args[4]);
- final Session session1 = con1.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- AMQConnection con2 = new AMQConnection(args[0], Integer.parseInt(args[1]), args[2], args[3],
- address.getHostName(), args[4]);
- final Session session2 = con2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- String selector = args[6];
-
- final int expectedMessageCount = Integer.parseInt(args[5]);
- _logger.info("Message selector is <" + selector + ">...");
-
- Topic t = new AMQTopic(session1.getDefaultTopicExchangeName(), new AMQShortString("cbr"));
- MessageConsumer consumer1 = session1.createConsumer(t,
- 100, false, false, selector);
- MessageConsumer consumer2 = session2.createConsumer(t,
- 100, false, false, selector);
-
- consumer1.setMessageListener(new TestMessageListener("ML 1", expectedMessageCount));
- consumer2.setMessageListener(new TestMessageListener("ML 2", expectedMessageCount));
- con1.start();
- con2.start();
- }
- catch (Throwable t)
- {
- System.err.println("Fatal error: " + t);
- t.printStackTrace();
- }
-
- System.out.println("Waiting...");
- }
-}
-
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/client/connection/TestManyConnections.java b/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/client/connection/TestManyConnections.java
deleted file mode 100644
index f59b36166a..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/client/connection/TestManyConnections.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.unit.client.connection;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.log4j.Logger;
-
-import junit.framework.TestCase;
-
-public class TestManyConnections extends TestCase
-{
- private static final Logger _log = Logger.getLogger(TestManyConnections.class);
-
- private AMQConnection[] _connections;
-
- private void createConnection(int index, String brokerHosts, String clientID, String username, String password,
- String vpath) throws AMQException, URLSyntaxException
- {
- _connections[index] = new AMQConnection(brokerHosts, username, password,
- clientID, vpath);
- }
-
- private void createConnections(int count) throws AMQException, URLSyntaxException
- {
- _connections = new AMQConnection[count];
- long startTime = System.currentTimeMillis();
- for (int i = 0; i < count; i++)
- {
- createConnection(i, "vm://:1", "myClient" + i, "guest", "guest", "test");
- }
- long endTime = System.currentTimeMillis();
- _log.info("Time to create " + count + " connections: " + (endTime - startTime) +
- "ms");
- }
-
- public void testCreate10Connections() throws AMQException, URLSyntaxException
- {
- createConnections(10);
- }
-
- public void testCreate50Connections() throws AMQException, URLSyntaxException
- {
- createConnections(50);
- }
-
- public void testCreate100Connections() throws AMQException, URLSyntaxException
- {
- createConnections(100);
- }
-
- public void testCreate250Connections() throws AMQException, URLSyntaxException
- {
- createConnections(250);
- }
-
- public void testCreate500Connections() throws AMQException, URLSyntaxException
- {
- createConnections(500);
- }
-
- public void testCreate1000Connections() throws AMQException, URLSyntaxException
- {
- createConnections(1000);
- }
-
- public void testCreate5000Connections() throws AMQException, URLSyntaxException
- {
- createConnections(5000);
- }
-
- public static junit.framework.Test suite()
- {
- return new junit.framework.TestSuite(TestManyConnections.class);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java b/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java
deleted file mode 100644
index 5ab5722146..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.unit.jndi;
-
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.client.AMQQueue;
-import org.apache.qpid.client.AMQTopic;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-import java.util.Properties;
-import java.io.InputStream;
-
-
-import junit.framework.TestCase;
-
-public class PropertiesFileInitialContextFactoryTest extends TestCase
-{
- InitialContextFactory contextFactory;
- Properties _properties;
- Properties _fileProperties;
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- //create simple set of hardcoded props
- _properties = new Properties();
- _properties.put("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory");
- _properties.put("connectionfactory.local", "amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'");
- _properties.put("queue.MyQueue", "example.MyQueue");
- _properties.put("topic.ibmStocks", "stocks.nyse.ibm");
- _properties.put("destination.direct", "direct://amq.direct//directQueue");
-
- //create properties from file as a more realistic test
- _fileProperties = new Properties();
- ClassLoader cl = this.getClass().getClassLoader();
- InputStream is = cl.getResourceAsStream("org/apache/qpid/test/unit/jndi/example.properties");
- _fileProperties.load(is);
- }
-
- /**
- * Test using hardcoded properties
- */
- public void testWithoutFile()
- {
- Context ctx = null;
-
- try
- {
- ctx = new InitialContext(_properties);
- }
- catch (NamingException ne)
- {
- fail("Error loading context:" + ne);
- }
-
- checkPropertiesMatch(ctx, "Using hardcoded properties: ");
- }
-
- /**
- * Test using properties from example file
- */
- public void testWithFile()
- {
- Context ctx = null;
-
- try
- {
- ctx = new InitialContext(_fileProperties);
- }
- catch (Exception e)
- {
- fail("Error loading context:" + e);
- }
-
- checkPropertiesMatch(ctx, "Using properties from file: ");
- }
-
- public void tearDown()
- {
- _properties = null;
- _fileProperties = null;
- }
-
- public static junit.framework.Test suite()
- {
- return new junit.framework.TestSuite(PropertiesFileInitialContextFactoryTest.class);
- }
-
- private void checkPropertiesMatch(Context ctx, String errorInfo)
- {
- try
- {
- AMQConnectionFactory cf = (AMQConnectionFactory) ctx.lookup("local");
- assertEquals("amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'", cf.getConnectionURL().toString());
- }
- catch (NamingException ne)
- {
- fail(errorInfo + "Unable to create Connection Factory:" + ne);
- }
-
- try
- {
- AMQQueue queue = (AMQQueue) ctx.lookup("MyQueue");
- assertEquals("example.MyQueue", queue.getRoutingKey().toString());
- }
- catch (NamingException ne)
- {
- fail(errorInfo + "Unable to create queue:" + ne);
- }
-
- try
- {
- AMQTopic topic = (AMQTopic) ctx.lookup("ibmStocks");
- assertEquals("stocks.nyse.ibm", topic.getTopicName().toString());
- }
- catch (Exception ne)
- {
- fail(errorInfo + "Unable to create topic:" + ne);
- }
-
- try
- {
- AMQQueue direct = (AMQQueue) ctx.lookup("direct");
- assertEquals("directQueue", direct.getRoutingKey().toString());
- }
- catch (NamingException ne)
- {
- fail(errorInfo + "Unable to create direct destination:" + ne);
- }
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/jndi/example.properties b/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/jndi/example.properties
deleted file mode 100644
index ea9dc5ae0e..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/test/unit/jndi/example.properties
+++ /dev/null
@@ -1,38 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
-
-# use the following property to configure the default connector
-#java.naming.provider.url - ignored.
-
-# register some connection factories
-# connectionfactory.[jndiname] = [ConnectionURL]
-connectionfactory.local = amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'
-
-# register some queues in JNDI using the form
-# queue.[jndiName] = [physicalName]
-queue.MyQueue = example.MyQueue
-
-# register some topics in JNDI using the form
-# topic.[jndiName] = [physicalName]
-topic.ibmStocks = stocks.nyse.ibm
-
-# Register an AMQP destination in JNDI
-# NOTE: Qpid currently only supports direct,topics and headers
-# destination.[jniName] = [BindingURL]
-destination.direct = direct://amq.direct//directQueue
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Config.java b/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Config.java
deleted file mode 100644
index bb740f9094..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Config.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.topic;
-
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.config.ConnectorConfig;
-import org.apache.qpid.config.ConnectionFactoryInitialiser;
-import org.apache.qpid.config.Connector;
-import org.apache.qpid.config.AbstractConfig;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-
-class Config extends AbstractConfig implements ConnectorConfig
-{
-
- private String host = "localhost";
- private int port = 5672;
- private String factory = null;
-
- private int payload = 256;
- private int messages = 1000;
- private int clients = 1;
- private int batch = 1;
- private long delay = 1;
- private int warmup;
- private int ackMode= AMQSession.NO_ACKNOWLEDGE;
- private String clientId;
- private String subscriptionId;
- private boolean persistent;
-
- public Config()
- {
- }
-
- int getAckMode()
- {
- return ackMode;
- }
-
- void setPayload(int payload)
- {
- this.payload = payload;
- }
-
- int getPayload()
- {
- return payload;
- }
-
- void setClients(int clients)
- {
- this.clients = clients;
- }
-
- int getClients()
- {
- return clients;
- }
-
- void setMessages(int messages)
- {
- this.messages = messages;
- }
-
- int getMessages()
- {
- return messages;
- }
-
- public String getHost()
- {
- return host;
- }
-
- public void setHost(String host)
- {
- this.host = host;
- }
-
- public int getPort()
- {
- return port;
- }
-
- public String getFactory()
- {
- return factory;
- }
-
- public void setPort(int port)
- {
- this.port = port;
- }
-
- int getBatch()
- {
- return batch;
- }
-
- void setBatch(int batch)
- {
- this.batch = batch;
- }
-
- int getWarmup()
- {
- return warmup;
- }
-
- void setWarmup(int warmup)
- {
- this.warmup = warmup;
- }
-
- public long getDelay()
- {
- return delay;
- }
-
- public void setDelay(long delay)
- {
- this.delay = delay;
- }
-
- String getClientId()
- {
- return clientId;
- }
-
- String getSubscriptionId()
- {
- return subscriptionId;
- }
-
- boolean usePersistentMessages()
- {
- return persistent;
- }
-
- public void setOption(String key, String value)
- {
- if("-host".equalsIgnoreCase(key))
- {
- setHost(value);
- }
- else if("-port".equalsIgnoreCase(key))
- {
- try
- {
- setPort(Integer.parseInt(value));
- }
- catch(NumberFormatException e)
- {
- throw new RuntimeException("Bad port number: " + value);
- }
- }
- else if("-payload".equalsIgnoreCase(key))
- {
- setPayload(parseInt("Bad payload size", value));
- }
- else if("-messages".equalsIgnoreCase(key))
- {
- setMessages(parseInt("Bad message count", value));
- }
- else if("-clients".equalsIgnoreCase(key))
- {
- setClients(parseInt("Bad client count", value));
- }
- else if("-batch".equalsIgnoreCase(key))
- {
- setBatch(parseInt("Bad batch count", value));
- }
- else if("-delay".equalsIgnoreCase(key))
- {
- setDelay(parseLong("Bad batch delay", value));
- }
- else if("-warmup".equalsIgnoreCase(key))
- {
- setWarmup(parseInt("Bad warmup count", value));
- }
- else if("-ack".equalsIgnoreCase(key))
- {
- ackMode = parseInt("Bad ack mode", value);
- }
- else if("-factory".equalsIgnoreCase(key))
- {
- factory = value;
- }
- else if("-clientId".equalsIgnoreCase(key))
- {
- clientId = value;
- }
- else if("-subscriptionId".equalsIgnoreCase(key))
- {
- subscriptionId = value;
- }
- else if("-persistent".equalsIgnoreCase(key))
- {
- persistent = "true".equalsIgnoreCase(value);
- }
- else
- {
- System.out.println("Ignoring unrecognised option: " + key);
- }
- }
-
- static String getAckModeDescription(int ackMode)
- {
- switch(ackMode)
- {
- case AMQSession.NO_ACKNOWLEDGE: return "NO_ACKNOWLEDGE";
- case AMQSession.AUTO_ACKNOWLEDGE: return "AUTO_ACKNOWLEDGE";
- case AMQSession.CLIENT_ACKNOWLEDGE: return "CLIENT_ACKNOWLEDGE";
- case AMQSession.DUPS_OK_ACKNOWLEDGE: return "DUPS_OK_ACKNOWELDGE";
- case AMQSession.PRE_ACKNOWLEDGE: return "PRE_ACKNOWLEDGE";
- }
- return "AckMode=" + ackMode;
- }
-
- public Connection createConnection() throws Exception
- {
- return new Connector().createConnection(this);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Listener.java b/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Listener.java
deleted file mode 100644
index 47c608cfe4..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Listener.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.topic;
-
-import javax.jms.Connection;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-
-public class Listener implements MessageListener
-{
- private final Connection _connection;
- private final MessageProducer _controller;
- private final javax.jms.Session _session;
- private final MessageFactory _factory;
- private boolean init;
- private int count;
- private long start;
-
- Listener(Connection connection, int ackMode) throws Exception
- {
- this(connection, ackMode, null);
- }
-
- Listener(Connection connection, int ackMode, String name) throws Exception
- {
- _connection = connection;
- _session = connection.createSession(false, ackMode);
- _factory = new MessageFactory(_session);
-
- //register for events
- if(name == null)
- {
- _factory.createTopicConsumer().setMessageListener(this);
- }
- else
- {
- _factory.createDurableTopicConsumer(name).setMessageListener(this);
- }
-
- _connection.start();
-
- _controller = _factory.createControlPublisher();
- System.out.println("Waiting for messages " +
- Config.getAckModeDescription(ackMode)
- + (name == null ? "" : " (subscribed with name " + name + " and client id " + connection.getClientID() + ")")
- + "...");
-
- }
-
- private void shutdown()
- {
- try
- {
- _session.close();
- _connection.stop();
- _connection.close();
- }
- catch(Exception e)
- {
- e.printStackTrace(System.out);
- }
- }
-
- private void report()
- {
- try
- {
- String msg = getReport();
- _controller.send(_factory.createReportResponseMessage(msg));
- System.out.println("Sent report: " + msg);
- }
- catch(Exception e)
- {
- e.printStackTrace(System.out);
- }
- }
-
- private String getReport()
- {
- long time = (System.currentTimeMillis() - start);
- return "Received " + count + " in " + time + "ms";
- }
-
- public void onMessage(Message message)
- {
- if(!init)
- {
- start = System.currentTimeMillis();
- count = 0;
- init = true;
- }
-
- if(_factory.isShutdown(message))
- {
- shutdown();
- }
- else if(_factory.isReport(message))
- {
- //send a report:
- report();
- init = false;
- }
- else if (++count % 100 == 0)
- {
- System.out.println("Received " + count + " messages.");
- }
- }
-
- public static void main(String[] argv) throws Exception
- {
- Config config = new Config();
- config.setOptions(argv);
-
- Connection con = config.createConnection();
- if(config.getClientId() != null)
- {
- con.setClientID(config.getClientId());
- }
- new Listener(con, config.getAckMode(), config.getSubscriptionId());
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/topic/MessageFactory.java b/qpid/java/client/src/old_test/java/org/apache/qpid/topic/MessageFactory.java
deleted file mode 100644
index 39d64069d1..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/topic/MessageFactory.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.topic;
-
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.client.AMQTopic;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.framing.AMQShortString;
-
-import javax.jms.*;
-
-/**
- */
-class MessageFactory
-{
- private static final char[] DATA = "abcdefghijklmnopqrstuvwxyz".toCharArray();
-
- private final Session _session;
- private final Topic _topic;
- private final Topic _control;
- private final byte[] _payload;
-
-
- MessageFactory(Session session) throws JMSException
- {
- this(session, 256);
- }
-
- MessageFactory(Session session, int size) throws JMSException
- {
- _session = session;
- if(session instanceof AMQSession)
- {
- _topic = new AMQTopic(((AMQSession)session).getDefaultTopicExchangeName(),new AMQShortString("topictest.messages"));
- _control = new AMQTopic(((AMQSession)session).getDefaultTopicExchangeName(),new AMQShortString("topictest.control"));
- }
- else
- {
- _topic = session.createTopic("topictest.messages");
- _control = session.createTopic("topictest.control");
- }
- _payload = new byte[size];
-
- for(int i = 0; i < size; i++)
- {
- _payload[i] = (byte) DATA[i % DATA.length];
- }
- }
-
- Topic getTopic()
- {
- return _topic;
- }
-
- Message createEventMessage() throws JMSException
- {
- BytesMessage msg = _session.createBytesMessage();
- msg.writeBytes(_payload);
- return msg;
- }
-
- Message createShutdownMessage() throws JMSException
- {
- return _session.createTextMessage("SHUTDOWN");
- }
-
- Message createReportRequestMessage() throws JMSException
- {
- return _session.createTextMessage("REPORT");
- }
-
- Message createReportResponseMessage(String msg) throws JMSException
- {
- return _session.createTextMessage(msg);
- }
-
- boolean isShutdown(Message m)
- {
- return checkText(m, "SHUTDOWN");
- }
-
- boolean isReport(Message m)
- {
- return checkText(m, "REPORT");
- }
-
- Object getReport(Message m)
- {
- try
- {
- return ((TextMessage) m).getText();
- }
- catch (JMSException e)
- {
- e.printStackTrace(System.out);
- return e.toString();
- }
- }
-
- MessageConsumer createTopicConsumer() throws Exception
- {
- return _session.createConsumer(_topic);
- }
-
- MessageConsumer createDurableTopicConsumer(String name) throws Exception
- {
- return _session.createDurableSubscriber(_topic, name);
- }
-
- MessageConsumer createControlConsumer() throws Exception
- {
- return _session.createConsumer(_control);
- }
-
- MessageProducer createTopicPublisher() throws Exception
- {
- return _session.createProducer(_topic);
- }
-
- MessageProducer createControlPublisher() throws Exception
- {
- return _session.createProducer(_control);
- }
-
- private static boolean checkText(Message m, String s)
- {
- try
- {
- return m instanceof TextMessage && ((TextMessage) m).getText().equals(s);
- }
- catch (JMSException e)
- {
- e.printStackTrace(System.out);
- return false;
- }
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Publisher.java b/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Publisher.java
deleted file mode 100644
index d788029ee9..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/topic/Publisher.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.topic;
-
-import javax.jms.*;
-
-public class Publisher implements MessageListener
-{
- private final Object _lock = new Object();
- private final Connection _connection;
- private final Session _session;
- private final MessageFactory _factory;
- private final MessageProducer _publisher;
- private int _count;
-
- Publisher(Connection connection, int size, int ackMode, boolean persistent) throws Exception
- {
- _connection = connection;
- _session = _connection.createSession(false, ackMode);
- _factory = new MessageFactory(_session, size);
- _publisher = _factory.createTopicPublisher();
- _publisher.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
- System.out.println("Publishing " + (persistent ? "persistent" : "non-persistent") + " messages of " + size + " bytes, " + Config.getAckModeDescription(ackMode) + ".");
- }
-
- private void test(Config config) throws Exception
- {
- test(config.getBatch(), config.getDelay(), config.getMessages(), config.getClients(), config.getWarmup());
- }
-
- private void test(int batches, long delay, int msgCount, int consumerCount, int warmup) throws Exception
- {
- _factory.createControlConsumer().setMessageListener(this);
- _connection.start();
-
- if(warmup > 0)
- {
- System.out.println("Runing warmup (" + warmup + " msgs)");
- long time = batch(warmup, consumerCount);
- System.out.println("Warmup completed in " + time + "ms");
- }
-
- long[] times = new long[batches];
- for(int i = 0; i < batches; i++)
- {
- if(i > 0) Thread.sleep(delay*1000);
- times[i] = batch(msgCount, consumerCount);
- System.out.println("Batch " + (i+1) + " of " + batches + " completed in " + times[i] + " ms.");
- }
-
- long min = min(times);
- long max = max(times);
- System.out.println("min: " + min + ", max: " + max + " avg: " + avg(times, min, max));
-
- //request shutdown
- _publisher.send(_factory.createShutdownMessage());
-
- _connection.stop();
- _connection.close();
- }
-
- private long batch(int msgCount, int consumerCount) throws Exception
- {
- _count = consumerCount;
- long start = System.currentTimeMillis();
- publish(msgCount);
- waitForCompletion(consumerCount);
- return System.currentTimeMillis() - start;
- }
-
- private void publish(int count) throws Exception
- {
-
- //send events
- for (int i = 0; i < count; i++)
- {
- _publisher.send(_factory.createEventMessage());
- if ((i + 1) % 100 == 0)
- {
- System.out.println("Sent " + (i + 1) + " messages");
- }
- }
-
- //request report
- _publisher.send(_factory.createReportRequestMessage());
- }
-
- private void waitForCompletion(int consumers) throws Exception
- {
- System.out.println("Waiting for completion...");
- synchronized (_lock)
- {
- while (_count > 0)
- {
- _lock.wait();
- }
- }
- }
-
-
- public void onMessage(Message message)
- {
- System.out.println("Received report " + _factory.getReport(message) + " " + --_count + " remaining");
- if (_count == 0)
- {
- synchronized (_lock)
- {
- _lock.notify();
- }
- }
- }
-
- static long min(long[] times)
- {
- long min = times.length > 0 ? times[0] : 0;
- for(int i = 0; i < times.length; i++)
- {
- min = Math.min(min, times[i]);
- }
- return min;
- }
-
- static long max(long[] times)
- {
- long max = times.length > 0 ? times[0] : 0;
- for(int i = 0; i < times.length; i++)
- {
- max = Math.max(max, times[i]);
- }
- return max;
- }
-
- static long avg(long[] times, long min, long max)
- {
- long sum = 0;
- for(int i = 0; i < times.length; i++)
- {
- sum += times[i];
- }
- sum -= min;
- sum -= max;
-
- return (sum / (times.length - 2));
- }
-
- public static void main(String[] argv) throws Exception
- {
- Config config = new Config();
- config.setOptions(argv);
-
- Connection con = config.createConnection();
- int size = config.getPayload();
- int ackMode = config.getAckMode();
- boolean persistent = config.usePersistentMessages();
- new Publisher(con, size, ackMode, persistent).test(config);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Config.java b/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Config.java
deleted file mode 100644
index bd104e5407..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Config.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.transacted;
-
-import org.apache.qpid.config.ConnectorConfig;
-import org.apache.qpid.config.AbstractConfig;
-import org.apache.qpid.config.Connector;
-
-import javax.jms.Connection;
-
-class Config extends AbstractConfig implements ConnectorConfig
-{
- private String host = "localhost";
- private int port = 5672;
- private String factory;
- private boolean echo;
- private int batch = 100;
- private boolean persistent = true;
-
- Config(String[] argv)
- {
- setOptions(argv);
- }
-
- Connection createConnection() throws Exception
- {
- return new Connector().createConnection(this);
- }
-
- public boolean isEchoOn()
- {
- return echo;
- }
-
- public boolean usePersistentMessages()
- {
- return persistent;
- }
-
- public int getBatchSize()
- {
- return batch;
- }
-
- public String getHost()
- {
- return host;
- }
-
- public int getPort()
- {
- return port;
- }
-
- public String getFactory()
- {
- return factory;
- }
-
- public void setOption(String key, String value)
- {
- if("-host".equalsIgnoreCase(key))
- {
- host = value;
- }
- else if("-port".equalsIgnoreCase(key))
- {
- port = parseInt("Bad port number", value);
- }
- else if("-factory".equalsIgnoreCase(key))
- {
- factory = value;
- }
- else if("-echo".equalsIgnoreCase(key))
- {
- echo = "true".equalsIgnoreCase(value);
- }
- else if("-persistent".equalsIgnoreCase(key))
- {
- persistent = "true".equalsIgnoreCase(value);
- }
- else if("-batch".equalsIgnoreCase(key))
- {
- batch = parseInt("Bad batch size", value);
- }
- else
- {
- System.out.println("Ignoring nrecognised option " + key);
- }
- }
-
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Ping.java b/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Ping.java
deleted file mode 100644
index 8f15bf089e..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Ping.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.transacted;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.client.AMQQueue;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import java.util.Arrays;
-
-public class Ping
-{
- public static void main(String[] argv) throws Exception
- {
- Config config = new Config(argv);
- Connection con = config.createConnection();
- con.setClientID("ping");
- new Relay(new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, new AMQShortString("ping")), new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, new AMQShortString("pong")), con,
- config.isEchoOn(),
- config.getBatchSize(),
- config.usePersistentMessages()).start();
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Pong.java b/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Pong.java
deleted file mode 100644
index f4f4b20d7c..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Pong.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.transacted;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.client.AMQQueue;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-
-public class Pong
-{
- public static void main(String[] argv) throws Exception
- {
- Config config = new Config(argv);
- Connection con = config.createConnection();
- con.setClientID("pong");
- new Relay(new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, new AMQShortString("pong")), new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, new AMQShortString("ping")), con,
- config.isEchoOn(),
- config.getBatchSize(),
- config.usePersistentMessages()).start();
-
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Relay.java b/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Relay.java
deleted file mode 100644
index cede95e5f0..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Relay.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.transacted;
-
-import org.apache.qpid.client.AMQSession;
-
-import javax.jms.MessageProducer;
-import javax.jms.MessageConsumer;
-import javax.jms.Session;
-import javax.jms.Destination;
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.TextMessage;
-import javax.jms.DeliveryMode;
-
-class Relay implements Runnable
-{
- private final Connection _con;
- private final Session _session;
- private final MessageConsumer _src;
- private final MessageProducer _dest;
- private final int _batch;
- private final boolean _echo;
- private int _counter;
- private long start;
- private boolean _running;
-
- Relay(Destination src, Destination dest, Connection con) throws JMSException
- {
- this(src, dest, con, false, 100, true);
- }
-
- Relay(Destination src, Destination dest, Connection con, boolean echo, int batch, boolean persistent) throws JMSException
- {
- _echo = echo;
- _batch = batch;
- _con = con;
- _session = con.createSession(true, AMQSession.NO_ACKNOWLEDGE);
- _src = _session.createConsumer(src);
- _dest = _session.createProducer(dest);
- _dest.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
-
- }
-
- public void run()
- {
- start = System.currentTimeMillis();
- try{
- while(true) relay();
- }
- catch(JMSException e)
- {
- e.printStackTrace();
- }
- try
- {
- _session.close();
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- }
- }
-
- void relay() throws JMSException
- {
- _dest.send(relay(_src.receive()));
- _session.commit();
- }
-
- Message relay(Message in) throws JMSException
- {
- if(!_running)
- {
- System.out.println(_con.getClientID() + " started.");
- _running = true;
- }
- if(++_counter % _batch == 0)
- {
- long time = System.currentTimeMillis() - start;
- System.out.println(_batch + " iterations performed in " + time + " ms");
- try
- {
- Thread.sleep(100);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- start = System.currentTimeMillis();
- }
- if(_echo)
- {
- System.out.println("Received: " + ((TextMessage) in).getText());
- }
- return _session.createTextMessage(_con.getClientID() + _counter);
- }
-
- void start() throws InterruptedException, JMSException
- {
- Thread runner = new Thread(this);
- runner.start();
- _con.start();
- System.out.println(_con.getClientID() + " waiting...");
- runner.join();
- _con.close();
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Start.java b/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Start.java
deleted file mode 100644
index de718d828a..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/transacted/Start.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.transacted;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.framing.AMQShortString;
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.client.AMQQueue;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Session;
-
-public class Start
-{
- public static void main(String[] argv) throws Exception
- {
- Connection con = new Config(argv).createConnection();
- AMQQueue ping = new AMQQueue(ExchangeDefaults.DIRECT_EXCHANGE_NAME, new AMQShortString("ping"));
- Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
- session.createProducer(ping).send(session.createTextMessage("start"));
- session.close();
- con.close();
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/weblogic/ServiceProvider.java b/qpid/java/client/src/old_test/java/org/apache/qpid/weblogic/ServiceProvider.java
deleted file mode 100644
index 71d806b338..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/weblogic/ServiceProvider.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.weblogic;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQDestination;
-
-import javax.jms.*;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.naming.Context;
-import java.net.InetAddress;
-import java.util.Hashtable;
-
-public class ServiceProvider
-{
- private static final String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
- private static final String JMS_FACTORY = "transientJMSConnectionFactory";
-
- private static final Logger _logger = Logger.getLogger(ServiceProvider.class);
-
- private static MessageProducer _destinationProducer;
-
- private static Queue _destinationQ;
-
- public static void main(String[] args)
- {
- _logger.info("Starting...");
-
- if (args.length != 2)
- {
- System.out.println("Usage: <WLS URI> <service queue>");
- System.exit(1);
- }
- try
- {
- String url = args[0];
- String receiveQueue = args[1];
-
- final InitialContext ctx = getInitialContext(url);
-
- QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
- QueueConnection qcon = qconFactory.createQueueConnection();
- final QueueSession qsession = qcon.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
- Queue receiveQ = (Queue) ctx.lookup(receiveQueue);
-
- _logger.info("Service (queue) name is '" + receiveQ + "'...");
-
- String selector = (args.length > 2 && args[2] != null && args[2].length() > 1) ? args[2] : null;
-
- _logger.info("Message selector is <" + selector + ">...");
-
- MessageConsumer consumer = qsession.createConsumer(receiveQ, selector);
-
- consumer.setMessageListener(new MessageListener()
- {
- private int _messageCount;
-
- public void onMessage(javax.jms.Message message)
- {
- //_logger.info("Got message '" + message + "'");
-
- TextMessage tm = (TextMessage) message;
-
- try
- {
- Queue responseQueue = (Queue)tm.getJMSReplyTo();
- if (!responseQueue.equals(_destinationQ))
- {
- _destinationQ = responseQueue;
- _logger.info("Creating destination for " + responseQueue);
-
- try
- {
- _destinationProducer = qsession.createProducer(_destinationQ);
- _destinationProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- }
- catch (JMSException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- _messageCount++;
- if (_messageCount % 1000 == 0)
- {
- _logger.info("Received message total: " + _messageCount);
- _logger.info("Sending response to '" + responseQueue + "'");
- }
-
- String payload = "This is a response: sing together: 'Mahnah mahnah...'" + tm.getText();
- TextMessage msg = qsession.createTextMessage(payload);
- if (tm.propertyExists("timeSent"))
- {
- _logger.info("timeSent property set on message");
- final long timeSent = tm.getLongProperty("timeSent");
- msg.setLongProperty("timeSent", timeSent);
- _logger.info("time taken to go from service request to provider is: " + (System.currentTimeMillis() - timeSent));
- }
- _destinationProducer.send(msg);
- if (_messageCount % 1000 == 0)
- {
- tm.acknowledge();
- _logger.info("Sent response to '" + responseQueue + "'");
- }
- }
- catch (JMSException e)
- {
- _logger.error("Error sending message: " + e, e);
- }
- }
- });
- qcon.start();
- }
- catch (Throwable t)
- {
- System.err.println("Fatal error: " + t);
- t.printStackTrace();
- }
-
-
- System.out.println("Waiting...");
- }
-
- private static InitialContext getInitialContext(String url) throws NamingException
- {
- Hashtable env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
- env.put(Context.PROVIDER_URL, url);
- return new InitialContext(env);
- }
-}
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/weblogic/ServiceRequestingClient.java b/qpid/java/client/src/old_test/java/org/apache/qpid/weblogic/ServiceRequestingClient.java
deleted file mode 100644
index 2f64a1dde5..0000000000
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/weblogic/ServiceRequestingClient.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.weblogic;
-
-import org.apache.log4j.Logger;
-
-import javax.jms.*;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.util.Hashtable;
-
-/**
- * Created by IntelliJ IDEA.
- * User: U806869
- * Date: 28-May-2005
- * Time: 21:54:51
- * To change this template use File | Settings | File Templates.
- */
-public class ServiceRequestingClient
-{
- private static final Logger _log = Logger.getLogger(ServiceRequestingClient.class);
- private static final String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
- private static final String JMS_FACTORY = "transientJMSConnectionFactory";
-
- private static class CallbackHandler implements MessageListener
- {
- private int _expectedMessageCount;
-
- private int _actualMessageCount;
-
- private long _startTime;
-
- private long _averageLatency;
-
- public CallbackHandler(int expectedMessageCount, long startTime)
- {
- _expectedMessageCount = expectedMessageCount;
- _startTime = startTime;
- }
-
- public void onMessage(Message m)
- {
- if (_log.isDebugEnabled())
- {
- _log.debug("Message received: " + m);
- }
- try
- {
- if (m.propertyExists("timeSent"))
- {
- long timeSent = m.getLongProperty("timeSent");
- long now = System.currentTimeMillis();
- if (_averageLatency == 0)
- {
- _averageLatency = now - timeSent;
- _log.info("Latency " + _averageLatency);
- }
- else
- {
- _log.info("Individual latency: " + (now-timeSent));
- _averageLatency = (_averageLatency + (now - timeSent))/2;
- _log.info("Average latency now: " + _averageLatency);
- }
- }
- }
- catch (JMSException e)
- {
- _log.error("Could not calculate latency");
- }
-
- _actualMessageCount++;
- if (_actualMessageCount%1000 == 0)
- {
- try
- {
- m.acknowledge();
- }
- catch (JMSException e)
- {
- _log.error("Error acknowledging message");
- }
- _log.info("Received message count: " + _actualMessageCount);
- }
- /*if (!"henson".equals(m.toString()))
- {
- _log.error("Message response not correct: expected 'henson' but got " + m.toString());
- }
- else
- {
- if (_log.isDebugEnabled())
- {
- _log.debug("Message " + m + " received");
- }
- else
- {
- _log.info("Message received");
- }
- } */
-
- if (_actualMessageCount == _expectedMessageCount)
- {
- long timeTaken = System.currentTimeMillis() - _startTime;
- System.out.println("Total time taken to receive " + _expectedMessageCount+ " messages was " +
- timeTaken + "ms, equivalent to " +
- (_expectedMessageCount/(timeTaken/1000.0)) + " messages per second");
- System.out.println("Average latency is: " + _averageLatency);
- }
- }
- }
-
- public static void main(String[] args) throws Exception
- {
- if (args.length != 3)
- {
- System.out.println("Usage: IXPublisher <WLS URL> <sendQueue> <count> will publish count messages to ");
- System.out.println("queue sendQueue and waits for a response on a temp queue");
- System.exit(1);
- }
-
- String url = args[0];
- String sendQueue = args[1];
- int messageCount = Integer.parseInt(args[2]);
-
- InitialContext ctx = getInitialContext(url);
-
- QueueConnectionFactory qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
- QueueConnection qcon = qconFactory.createQueueConnection();
- QueueSession qsession = qcon.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
- Queue sendQ = (Queue) ctx.lookup(sendQueue);
- Queue receiveQ = qsession.createTemporaryQueue();
- QueueSender qsender = qsession.createSender(sendQ);
- qsender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- _log.debug("Queue sender created for service queue " + sendQ);
-
- javax.jms.MessageConsumer messageConsumer = (javax.jms.MessageConsumer) qsession.createConsumer(receiveQ);
-
- //TextMessage msg = _session.createTextMessage(tempDestination.getQueueName() + "/Presented to in conjunction with Mahnah Mahnah and the Snowths");
- final long startTime = System.currentTimeMillis();
-
- messageConsumer.setMessageListener(new CallbackHandler(messageCount, startTime));
- qcon.start();
- for (int i = 0; i < messageCount; i++)
- {
- TextMessage msg = qsession.createTextMessage("/Presented to in conjunction with Mahnah Mahnah and the Snowths:" + i);
- msg.setJMSReplyTo(receiveQ);
- if (i%1000 == 0)
- {
- long timeNow = System.currentTimeMillis();
- msg.setLongProperty("timeSent", timeNow);
- }
- qsender.send(msg);
- }
-
- new Thread("foo").start();
- //qsession.close();
- //qcon.close();
- }
-
- private static InitialContext getInitialContext(String url) throws NamingException
- {
- Hashtable env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
- env.put(Context.PROVIDER_URL, url);
- return new InitialContext(env);
- }
-}
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java b/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java
index 5972bf3fae..73e67469ae 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java
@@ -23,7 +23,6 @@ package org.apache.qpid.client;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.state.AMQState;
import org.apache.qpid.framing.ProtocolVersion;
-import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.url.URLSyntaxException;
@@ -37,48 +36,18 @@ public class MockAMQConnection extends AMQConnection
super(broker, username, password, clientName, virtualHost);
}
- public MockAMQConnection(String broker, String username, String password, String clientName, String virtualHost, SSLConfiguration sslConfig)
- throws AMQException, URLSyntaxException
- {
- super(broker, username, password, clientName, virtualHost, sslConfig);
- }
-
public MockAMQConnection(String host, int port, String username, String password, String clientName, String virtualHost)
throws AMQException, URLSyntaxException
{
super(host, port, username, password, clientName, virtualHost);
}
- public MockAMQConnection(String host, int port, String username, String password, String clientName, String virtualHost, SSLConfiguration sslConfig)
- throws AMQException, URLSyntaxException
- {
- super(host, port, username, password, clientName, virtualHost, sslConfig);
- }
-
- public MockAMQConnection(String host, int port, boolean useSSL, String username, String password, String clientName, String virtualHost, SSLConfiguration sslConfig)
- throws AMQException, URLSyntaxException
- {
- super(host, port, useSSL, username, password, clientName, virtualHost, sslConfig);
- }
-
public MockAMQConnection(String connection)
throws AMQException, URLSyntaxException
{
super(connection);
}
- public MockAMQConnection(String connection, SSLConfiguration sslConfig)
- throws AMQException, URLSyntaxException
- {
- super(connection, sslConfig);
- }
-
- public MockAMQConnection(ConnectionURL connectionURL, SSLConfiguration sslConfig)
- throws AMQException
- {
- super(connectionURL, sslConfig);
- }
-
@Override
public ProtocolVersion makeBrokerConnection(BrokerDetails brokerDetail) throws IOException
{
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/message/TestMessageHelper.java b/qpid/java/client/src/test/java/org/apache/qpid/client/message/TestMessageHelper.java
index 7ee991b63c..b5c31e7c5e 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/client/message/TestMessageHelper.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/client/message/TestMessageHelper.java
@@ -43,4 +43,9 @@ public class TestMessageHelper
{
return new JMSStreamMessage(AMQMessageDelegateFactory.FACTORY_0_8);
}
+
+ public static JMSObjectMessage newJMSObjectMessage()
+ {
+ return new JMSObjectMessage(AMQMessageDelegateFactory.FACTORY_0_8);
+ }
}
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStreamTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStreamTest.java
new file mode 100644
index 0000000000..93a4fb39f5
--- /dev/null
+++ b/qpid/java/client/src/test/java/org/apache/qpid/client/util/ClassLoadingAwareObjectInputStreamTest.java
@@ -0,0 +1,87 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.client.util;
+
+import java.io.InputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class ClassLoadingAwareObjectInputStreamTest extends QpidTestCase
+{
+ InputStream _in;
+ ClassLoadingAwareObjectInputStream _claOIS;
+
+ protected void setUp() throws Exception
+ {
+ //Create a viable input stream for instantiating the CLA OIS
+ ByteBuffer buf = ByteBuffer.allocate(10);
+ buf.setAutoExpand(true);
+
+ ObjectOutputStream out = new ObjectOutputStream(buf.asOutputStream());
+ out.writeObject("testString");
+ out.flush();
+ out.close();
+
+ buf.rewind();
+ _in = buf.asInputStream();
+
+ _claOIS = new ClassLoadingAwareObjectInputStream(_in);
+ }
+
+ /**
+ * Test that the resolveProxyClass method returns a proxy class implementing the desired interface
+ */
+ public void testResolveProxyClass() throws Exception
+ {
+ //try to proxy an interface
+ Class<?> clazz = _claOIS.resolveProxyClass(new String[]{"java.lang.CharSequence"});
+
+ //verify the proxy supports the expected interface (only)
+ List<Class<?>> interfaces = Arrays.asList(clazz.getInterfaces());
+ assertTrue("Unexpected interfaces supported by proxy", interfaces.contains(CharSequence.class));
+ assertEquals("Unexpected interfaces supported by proxy", 1, interfaces.size());
+ }
+
+ /**
+ * Test that the resolveProxyClass method throws a ClassNotFoundException wrapping an
+ * IllegalArgumentException if it is provided arguments which violate the restrictions allowed
+ * by Proxy.getProxyClass (as required by the ObjectInputStream.resolveProxyClass javadoc).
+ */
+ public void testResolveProxyClassThrowsCNFEWrappingIAE() throws Exception
+ {
+ try
+ {
+ //try to proxy a *class* rather than an interface, which is illegal
+ _claOIS.resolveProxyClass(new String[]{"java.lang.String"});
+ fail("should have thrown an exception");
+ }
+ catch(ClassNotFoundException cnfe)
+ {
+ //expected, but must verify it is wrapping an IllegalArgumentException
+ assertTrue(cnfe.getCause() instanceof IllegalArgumentException);
+ }
+ }
+}
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageUnitTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageUnitTest.java
new file mode 100644
index 0000000000..177dccea7e
--- /dev/null
+++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/message/ObjectMessageUnitTest.java
@@ -0,0 +1,110 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.test.unit.client.message;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.apache.qpid.client.message.JMSObjectMessage;
+import org.apache.qpid.client.message.TestMessageHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class ObjectMessageUnitTest extends QpidTestCase
+{
+ private JMSObjectMessage _om;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _om = TestMessageHelper.newJMSObjectMessage();
+ }
+
+ /**
+ * Test that setObject with a primitive works
+ */
+ public void testSetObjectWithBooleanPrimitive() throws Exception
+ {
+ _om.setObject(true);
+
+ //make the message readable
+ _om.reset();
+
+ Object object = _om.getObject();
+
+ assertTrue("Unexpected type returned", object instanceof Boolean);
+ assertEquals("Unexpected value returned", true, object);
+ }
+
+ /**
+ * Test that setObject with a serializable Object works
+ */
+ public void testSetObjectWithString() throws Exception
+ {
+ _om.setObject("test string");
+
+ //make the message readable
+ _om.reset();
+
+ Object object = _om.getObject();
+
+ assertTrue("Unexpected type returned", object instanceof String);
+ assertEquals("Unexpected value returned", "test string", object);
+ }
+
+ /**
+ * Test that setObject with a Collection of serializable's works, returning
+ * the items in the list when deserialized and ignoring any values
+ * added to the collection after setObject() is called on the message.
+ */
+ public void testSetObjectWithArrayListOfInteger() throws Exception
+ {
+ ArrayList<Integer> list = new ArrayList<Integer>();
+ list.add(1234);
+ list.add(Integer.MIN_VALUE);
+ list.add(Integer.MAX_VALUE);
+
+ _om.setObject(list);
+
+ //add something extra to the list now, and check it isn't in the value read back
+ list.add(0);
+
+ //make the message readable
+ _om.reset();
+
+ //retrieve the Object
+ Object object = _om.getObject();
+
+ ArrayList<?> returnedList = null;
+ if(object instanceof ArrayList<?>)
+ {
+ returnedList = (ArrayList<?>) object;
+ }
+ else
+ {
+ fail("returned object was not an ArrayList");
+ }
+
+ //verify the extra added Integer was not present, then remove it from original list again and compare contents with the returned list
+ assertFalse("returned list should not have had the value added after setObject() was used", returnedList.contains(0));
+ list.remove(Integer.valueOf(0));
+ assertTrue("list contents were not equal", Arrays.equals(list.toArray(), returnedList.toArray()));
+ }
+}
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java
index 9e76b0d468..20496026ce 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java
@@ -21,10 +21,10 @@
package org.apache.qpid.test.unit.jndi;
import junit.framework.TestCase;
+
import org.apache.qpid.client.AMQConnectionFactory;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ConnectionURL;
-import org.apache.qpid.url.URLSyntaxException;
public class ConnectionFactoryTest extends TestCase
{
@@ -34,21 +34,9 @@ public class ConnectionFactoryTest extends TestCase
public static final String URL = "amqp://guest:guest@clientID/test?brokerlist='tcp://localhost:5672'";
public static final String URL_STAR_PWD = "amqp://guest:********@clientID/test?brokerlist='tcp://localhost:5672'";
- public void testConnectionURLString()
+ public void testConnectionURLStringMasksPassword() throws Exception
{
- AMQConnectionFactory factory = new AMQConnectionFactory();
-
- assertNull("ConnectionURL should have no value at start",
- factory.getConnectionURL());
-
- try
- {
- factory.setConnectionURLString(URL);
- }
- catch (URLSyntaxException e)
- {
- fail(e.getMessage());
- }
+ AMQConnectionFactory factory = new AMQConnectionFactory(URL);
//URL will be returned with the password field swapped for '********'
assertEquals("Connection URL not correctly set", URL_STAR_PWD, factory.getConnectionURLString());
diff --git a/qpid/java/common.xml b/qpid/java/common.xml
index f503a5c7da..6bb71ef24e 100644
--- a/qpid/java/common.xml
+++ b/qpid/java/common.xml
@@ -116,10 +116,9 @@
<attribute name="dir"/>
<attribute name="name"/>
<attribute name="excludes" default=""/>
- <attribute name="erroronmissingdir" default="true"/>
<sequential>
- <dirset id="@{dir}.refid" dir="@{dir}" excludes="@{excludes}" erroronmissingdir="@{erroronmissingdir}">
+ <dirset id="@{dir}.refid" dir="@{dir}" excludes="@{excludes}">
<present targetdir="@{dir}">
<mapper type="glob" from="*" to="*/build.xml" />
</present>
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/ssl/SSLContextFactory.java b/qpid/java/common/src/main/java/org/apache/qpid/ssl/SSLContextFactory.java
index 702746b3da..01f13408b0 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/ssl/SSLContextFactory.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/ssl/SSLContextFactory.java
@@ -20,18 +20,17 @@
*/
package org.apache.qpid.ssl;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
+import org.apache.qpid.transport.network.security.ssl.QpidClientX509KeyManager;
import org.apache.qpid.transport.network.security.ssl.SSLUtil;
/**
@@ -39,157 +38,92 @@ import org.apache.qpid.transport.network.security.ssl.SSLUtil;
* before this will work.
*
*/
-public class SSLContextFactory {
-
- /**
- * Path to the Java keystore file
- */
- private String _keyStorePath;
-
- /**
- * Password for the keystore
- */
- private String _keyStorePassword;
-
- /**
- * Cert type to use in keystore
- */
- private String _keyStoreCertType;
-
- /**
- * Path to the Java truststore file
- */
- private String _trustStorePath;
-
- /**
- * Password for the truststore
- */
- private String _trustStorePassword;
-
- /**
- * Cert type to use in truststore
- */
- private String _trustStoreCertType;
-
- private KeyManager customKeyManager;
-
- public SSLContextFactory(String trustStorePath, String trustStorePassword,
- String trustStoreCertType)
+public class SSLContextFactory
+{
+ public static final String JAVA_KEY_STORE_CODE = "JKS";
+ public static final String TRANSPORT_LAYER_SECURITY_CODE = "TLS";
+ public static final String KEY_STORE_CERTIFICATE_TYPE = "SunX509";
+
+ private SSLContextFactory()
{
- this(trustStorePath,trustStorePassword,trustStoreCertType,
- trustStorePath,trustStorePassword,trustStoreCertType);
+ //no instances
}
- /**
- * Create a factory instance
- * @param keystorePath path to the Java keystore file
- * @param keystorePassword password for the Java keystore
- * @param certType certificate type
- */
- public SSLContextFactory(String trustStorePath, String trustStorePassword, String trustStoreCertType,
- String keyStorePath, String keyStorePassword, String keyStoreCertType)
- {
+ public static SSLContext buildServerContext(final String keyStorePath,
+ final String keyStorePassword, final String keyStoreCertType)
+ throws GeneralSecurityException, IOException
+ {
+ return buildContext(null, null, null, keyStorePath, keyStorePassword,
+ keyStoreCertType, null);
+ }
- _trustStorePath = trustStorePath;
- _trustStorePassword = trustStorePassword;
-
- if (_trustStorePassword != null && _trustStorePassword.equals("none"))
- {
- _trustStorePassword = null;
- }
- _trustStoreCertType = trustStoreCertType;
-
- _keyStorePath = keyStorePath;
- _keyStorePassword = keyStorePassword;
-
- if (_keyStorePassword != null && _keyStorePassword.equals("none"))
- {
- _keyStorePassword = null;
- }
- _keyStoreCertType = keyStoreCertType;
-
- if (_trustStorePath == null) {
- throw new IllegalArgumentException("A TrustStore path or KeyStore path must be specified");
- }
- if (_trustStoreCertType == null) {
- throw new IllegalArgumentException("Cert type must be specified");
- }
- }
-
- public SSLContextFactory(String trustStorePath, String trustStorePassword, String trustStoreCertType,
- KeyManager customKeyManager)
+ public static SSLContext buildClientContext(final String trustStorePath,
+ final String trustStorePassword, final String trustStoreCertType,
+ final String keyStorePath, final String keyStorePassword,
+ final String keyStoreCertType, final String certAlias)
+ throws GeneralSecurityException, IOException
+ {
+ return buildContext(trustStorePath, trustStorePassword,
+ trustStoreCertType, keyStorePath, keyStorePassword,
+ keyStoreCertType, certAlias);
+ }
+
+ private static SSLContext buildContext(final String trustStorePath,
+ final String trustStorePassword, final String trustStoreCertType,
+ final String keyStorePath, final String keyStorePassword,
+ final String keyStoreCertType, final String certAlias)
+ throws GeneralSecurityException, IOException
{
+ // Initialize the SSLContext to work with our key managers.
+ final SSLContext sslContext = SSLContext
+ .getInstance(TRANSPORT_LAYER_SECURITY_CODE);
- _trustStorePath = trustStorePath;
- _trustStorePassword = trustStorePassword;
-
- if (_trustStorePassword != null && _trustStorePassword.equals("none"))
+ final TrustManager[] trustManagers;
+ final KeyManager[] keyManagers;
+
+ if (trustStorePath != null)
{
- _trustStorePassword = null;
- }
- _trustStoreCertType = trustStoreCertType;
-
- if (_trustStorePath == null) {
- throw new IllegalArgumentException("A TrustStore path or KeyStore path must be specified");
+ final KeyStore ts = SSLUtil.getInitializedKeyStore(trustStorePath,
+ trustStorePassword);
+ final TrustManagerFactory tmf = TrustManagerFactory
+ .getInstance(trustStoreCertType);
+ tmf.init(ts);
+
+ trustManagers = tmf.getTrustManagers();
}
- if (_trustStoreCertType == null) {
- throw new IllegalArgumentException("Cert type must be specified");
+ else
+ {
+ trustManagers = null;
}
-
- this.customKeyManager = customKeyManager;
- }
-
-
- /**
- * Builds a SSLContext appropriate for use with a server
- * @return SSLContext
- * @throws GeneralSecurityException
- * @throws IOException
- */
- public SSLContext buildServerContext() throws GeneralSecurityException, IOException
- {
- KeyStore ts = SSLUtil.getInitializedKeyStore(_trustStorePath,_trustStorePassword);
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(_trustStoreCertType);
- tmf.init(ts);
-
- // Initialize the SSLContext to work with our key managers.
- SSLContext sslContext = SSLContext.getInstance("TLS");
-
- if (customKeyManager != null)
+ if (keyStorePath != null)
{
- sslContext.init(new KeyManager[]{customKeyManager},
- tmf.getTrustManagers(), null);
-
+ if (certAlias != null)
+ {
+ keyManagers = new KeyManager[] { new QpidClientX509KeyManager(
+ certAlias, keyStorePath, keyStorePassword,
+ keyStoreCertType) };
+ }
+ else
+ {
+ final KeyStore ks = SSLUtil.getInitializedKeyStore(
+ keyStorePath, keyStorePassword);
+
+ char[] keyStoreCharPassword = keyStorePassword == null ? null : keyStorePassword.toCharArray();
+ // Set up key manager factory to use our key store
+ final KeyManagerFactory kmf = KeyManagerFactory
+ .getInstance(keyStoreCertType);
+ kmf.init(ks, keyStoreCharPassword);
+ keyManagers = kmf.getKeyManagers();
+ }
}
else
{
- // Create keystore
- KeyStore ks = SSLUtil.getInitializedKeyStore(_keyStorePath,_keyStorePassword);
- // Set up key manager factory to use our key store
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(_keyStoreCertType);
- kmf.init(ks, _keyStorePassword.toCharArray());
-
- sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
+ keyManagers = null;
}
-
- return sslContext;
- }
-
- /**
- * Creates a SSLContext factory appropriate for use with a client
- * @return SSLContext
- * @throws GeneralSecurityException
- * @throws IOException
- */
- public SSLContext buildClientContext() throws GeneralSecurityException, IOException
- {
- KeyStore ks = SSLUtil.getInitializedKeyStore(_trustStorePath,_trustStorePassword);
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(_trustStoreCertType);
- tmf.init(ks);
- SSLContext context = SSLContext.getInstance("TLS");
- context.init(null, tmf.getTrustManagers(), null);
- return context;
- }
-
+
+ sslContext.init(keyManagers, trustManagers, null);
+
+ return sslContext;
+ }
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java
index 7099916c33..b371df639e 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/IncomingNetworkTransport.java
@@ -20,11 +20,12 @@
*/
package org.apache.qpid.transport.network;
+import javax.net.ssl.SSLContext;
+
import org.apache.qpid.protocol.ProtocolEngineFactory;
-import org.apache.qpid.ssl.SSLContextFactory;
import org.apache.qpid.transport.NetworkTransportConfiguration;
public interface IncomingNetworkTransport extends NetworkTransport
{
- public void accept(NetworkTransportConfiguration config, ProtocolEngineFactory factory, SSLContextFactory sslFactory);
+ public void accept(NetworkTransportConfiguration config, ProtocolEngineFactory factory, SSLContext sslContext);
} \ No newline at end of file
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java
index ff86ba481f..0bae46e8eb 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/OutgoingNetworkTransport.java
@@ -22,11 +22,12 @@ package org.apache.qpid.transport.network;
import java.nio.ByteBuffer;
-import org.apache.qpid.ssl.SSLContextFactory;
+import javax.net.ssl.SSLContext;
+
import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.transport.Receiver;
public interface OutgoingNetworkTransport extends NetworkTransport
{
- public NetworkConnection connect(ConnectionSettings settings, Receiver<ByteBuffer> delegate, SSLContextFactory sslFactory);
+ public NetworkConnection connect(ConnectionSettings settings, Receiver<ByteBuffer> delegate, SSLContext sslContext);
} \ No newline at end of file
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
index d611ab1cf3..30e2856c59 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/io/IoNetworkTransport.java
@@ -27,7 +27,8 @@ import java.net.Socket;
import java.net.SocketException;
import java.nio.ByteBuffer;
-import org.apache.qpid.ssl.SSLContextFactory;
+import javax.net.ssl.SSLContext;
+
import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.transport.Receiver;
import org.apache.qpid.transport.TransportException;
@@ -51,7 +52,7 @@ public class IoNetworkTransport implements OutgoingNetworkTransport
private IoNetworkConnection _connection;
private long _timeout = 60000;
- public NetworkConnection connect(ConnectionSettings settings, Receiver<ByteBuffer> delegate, SSLContextFactory sslFactory)
+ public NetworkConnection connect(ConnectionSettings settings, Receiver<ByteBuffer> delegate, SSLContext sslContext)
{
int sendBufferSize = settings.getWriteBufferSize();
int receiveBufferSize = settings.getReadBufferSize();
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkHandler.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkHandler.java
index c00187480c..0e4492e31b 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkHandler.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkHandler.java
@@ -21,6 +21,8 @@
package org.apache.qpid.transport.network.mina;
+import javax.net.ssl.SSLContext;
+
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoHandlerAdapter;
@@ -30,7 +32,6 @@ import org.apache.mina.filter.SSLFilter;
import org.apache.mina.util.SessionUtil;
import org.apache.qpid.protocol.ProtocolEngine;
import org.apache.qpid.protocol.ProtocolEngineFactory;
-import org.apache.qpid.ssl.SSLContextFactory;
import org.apache.qpid.transport.network.NetworkConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +41,8 @@ public class MinaNetworkHandler extends IoHandlerAdapter
private static final Logger LOGGER = LoggerFactory.getLogger(MinaNetworkHandler.class);
private ProtocolEngineFactory _factory;
- private SSLContextFactory _sslFactory = null;
+ private SSLContext _sslContext = null;
+ private boolean _useClientMode;
static
{
@@ -52,15 +54,19 @@ public class MinaNetworkHandler extends IoHandlerAdapter
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
}
- public MinaNetworkHandler(SSLContextFactory sslFactory, ProtocolEngineFactory factory)
+ public MinaNetworkHandler(SSLContext sslContext, ProtocolEngineFactory factory)
{
- _sslFactory = sslFactory;
+ _sslContext = sslContext;
_factory = factory;
+ if(_factory == null)
+ {
+ _useClientMode = true;
+ }
}
- public MinaNetworkHandler(SSLContextFactory sslFactory)
+ public MinaNetworkHandler(SSLContext sslContext)
{
- this(sslFactory, null);
+ this(sslContext, null);
}
public void messageReceived(IoSession session, Object message)
@@ -100,10 +106,12 @@ public class MinaNetworkHandler extends IoHandlerAdapter
SessionUtil.initialize(ioSession);
- if (_sslFactory != null)
+ if (_sslContext != null)
{
- ioSession.getFilterChain().addBefore("protocolFilter", "sslFilter",
- new SSLFilter(_sslFactory.buildServerContext()));
+ SSLFilter sslFilter = new SSLFilter(_sslContext);
+ sslFilter.setUseClientMode(_useClientMode);
+
+ ioSession.getFilterChain().addFirst("sslFilter",sslFilter);
}
if (_factory != null)
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkTransport.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkTransport.java
index d0367b82f4..85b42da2b2 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkTransport.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/mina/MinaNetworkTransport.java
@@ -26,6 +26,8 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+import javax.net.ssl.SSLContext;
+
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.ExecutorThreadModel;
import org.apache.mina.common.IoConnector;
@@ -62,7 +64,7 @@ public class MinaNetworkTransport implements OutgoingNetworkTransport, IncomingN
private InetSocketAddress _address;
public NetworkConnection connect(ConnectionSettings settings,
- Receiver<java.nio.ByteBuffer> delegate, SSLContextFactory sslFactory)
+ Receiver<java.nio.ByteBuffer> delegate, SSLContext sslContext)
{
int transport = getTransport(settings.getProtocol());
@@ -77,7 +79,7 @@ public class MinaNetworkTransport implements OutgoingNetworkTransport, IncomingN
return new SocketConnector(1, new QpidThreadExecutor()); // non-blocking connector
}
});
- _connection = stc.connect(delegate, settings, sslFactory);
+ _connection = stc.connect(delegate, settings, sslContext);
break;
case UNKNOWN:
default:
@@ -115,7 +117,7 @@ public class MinaNetworkTransport implements OutgoingNetworkTransport, IncomingN
}
public void accept(final NetworkTransportConfiguration config, final ProtocolEngineFactory factory,
- final SSLContextFactory sslFactory)
+ final SSLContext sslContext)
{
int processors = config.getConnectorProcessors();
@@ -146,7 +148,7 @@ public class MinaNetworkTransport implements OutgoingNetworkTransport, IncomingN
try
{
- _acceptor.bind(_address, new MinaNetworkHandler(sslFactory, factory));
+ _acceptor.bind(_address, new MinaNetworkHandler(sslContext, factory));
}
catch (IOException e)
{
@@ -168,7 +170,7 @@ public class MinaNetworkTransport implements OutgoingNetworkTransport, IncomingN
_ioConnectorFactory = socketConnectorFactory;
}
- public NetworkConnection connect(Receiver<java.nio.ByteBuffer> receiver, ConnectionSettings settings, SSLContextFactory sslFactory)
+ public NetworkConnection connect(Receiver<java.nio.ByteBuffer> receiver, ConnectionSettings settings, SSLContext sslContext)
{
final IoConnector ioConnector = _ioConnectorFactory.newConnector();
final SocketAddress address;
@@ -203,7 +205,7 @@ public class MinaNetworkTransport implements OutgoingNetworkTransport, IncomingN
((SocketConnector) ioConnector).setWorkerTimeout(0);
}
- ConnectFuture future = ioConnector.connect(address, new MinaNetworkHandler(sslFactory), ioConnector.getDefaultConfig());
+ ConnectFuture future = ioConnector.connect(address, new MinaNetworkHandler(sslContext), ioConnector.getDefaultConfig());
future.join();
if (!future.isConnected())
{
diff --git a/qpid/java/client/src/old_test/java/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/SSLStatus.java
index cac0064785..9db7dd557a 100644
--- a/qpid/java/client/src/old_test/java/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/SSLStatus.java
@@ -1,5 +1,4 @@
/*
- *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -7,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,18 +17,33 @@
* under the License.
*
*/
-package org.apache.qpid.config;
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.config.ConnectionFactoryInitialiser;
-import org.apache.qpid.config.ConnectorConfig;
+package org.apache.qpid.transport.network.security;
-import javax.jms.ConnectionFactory;
+import java.util.concurrent.atomic.AtomicBoolean;
-class AMQConnectionFactoryInitialiser implements ConnectionFactoryInitialiser
+public class SSLStatus
{
- public ConnectionFactory getFactory(ConnectorConfig config)
+ private final Object _sslLock = new Object();
+ private final AtomicBoolean _sslErrorFlag = new AtomicBoolean(false);
+
+ /**
+ * Lock used to coordinate the SSL sender with the SSL receiver.
+ *
+ * @return lock
+ */
+ public Object getSslLock()
+ {
+ return _sslLock;
+ }
+
+ public boolean getSslErrorFlag()
+ {
+ return _sslErrorFlag.get();
+ }
+
+ public void setSslErrorFlag()
{
- return new AMQConnectionFactory(config.getHost(), config.getPort(), "/test_path");
+ _sslErrorFlag.set(true);
}
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/SecurityLayer.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/SecurityLayer.java
index 69e4b52edb..e80f8904a3 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/SecurityLayer.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/SecurityLayer.java
@@ -25,6 +25,7 @@ import java.nio.ByteBuffer;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
+import org.apache.qpid.ssl.SSLContextFactory;
import org.apache.qpid.transport.Connection;
import org.apache.qpid.transport.ConnectionListener;
import org.apache.qpid.transport.ConnectionSettings;
@@ -106,15 +107,22 @@ public class SecurityLayer
class SSLSecurityLayer
{
- SSLEngine engine;
- SSLSender sender;
+ final SSLEngine _engine;
+ final SSLStatus _sslStatus = new SSLStatus();
public SSLSecurityLayer()
{
SSLContext sslCtx;
try
{
- sslCtx = SSLUtil.createSSLContext(settings);
+ sslCtx = SSLContextFactory
+ .buildClientContext(settings.getTrustStorePath(),
+ settings.getTrustStorePassword(),
+ settings.getTrustStoreCertType(),
+ settings.getKeyStorePath(),
+ settings.getKeyStorePassword(),
+ settings.getKeyStoreCertType(),
+ settings.getCertAlias());
}
catch (Exception e)
{
@@ -123,8 +131,8 @@ public class SecurityLayer
try
{
- engine = sslCtx.createSSLEngine();
- engine.setUseClientMode(true);
+ _engine = sslCtx.createSSLEngine();
+ _engine.setUseClientMode(true);
}
catch(Exception e)
{
@@ -134,28 +142,21 @@ public class SecurityLayer
public SSLSender sender(Sender<ByteBuffer> delegate)
{
- sender = new SSLSender(engine,delegate);
+ SSLSender sender = new SSLSender(_engine, delegate, _sslStatus);
sender.setConnectionSettings(settings);
return sender;
}
public SSLReceiver receiver(Receiver<ByteBuffer> delegate)
{
- if (sender == null)
- {
- throw new
- IllegalStateException("SecurityLayer.sender method should be " +
- "invoked before SecurityLayer.receiver");
- }
-
- SSLReceiver receiver = new SSLReceiver(engine,delegate,sender);
+ SSLReceiver receiver = new SSLReceiver(_engine, delegate, _sslStatus);
receiver.setConnectionSettings(settings);
return receiver;
}
public String getUserID()
{
- return SSLUtil.retriveIdentity(engine);
+ return SSLUtil.retriveIdentity(_engine);
}
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/QpidClientX509KeyManager.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/QpidClientX509KeyManager.java
index 0dd86d4560..4391e8adfc 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/QpidClientX509KeyManager.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/QpidClientX509KeyManager.java
@@ -20,7 +20,9 @@
*/
package org.apache.qpid.transport.network.security.ssl;
+import java.io.IOException;
import java.net.Socket;
+import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.Principal;
import java.security.PrivateKey;
@@ -40,7 +42,7 @@ public class QpidClientX509KeyManager extends X509ExtendedKeyManager
String alias;
public QpidClientX509KeyManager(String alias, String keyStorePath,
- String keyStorePassword,String keyStoreCertType) throws Exception
+ String keyStorePassword,String keyStoreCertType) throws GeneralSecurityException, IOException
{
this.alias = alias;
KeyStore ks = SSLUtil.getInitializedKeyStore(keyStorePath,keyStorePassword);
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java
index e227a51729..878f0b2352 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLReceiver.java
@@ -24,38 +24,37 @@ import java.nio.ByteBuffer;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
-import javax.net.ssl.SSLException;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import javax.net.ssl.SSLEngineResult.Status;
+import javax.net.ssl.SSLException;
import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.transport.Receiver;
import org.apache.qpid.transport.TransportException;
+import org.apache.qpid.transport.network.security.SSLStatus;
import org.apache.qpid.transport.util.Logger;
public class SSLReceiver implements Receiver<ByteBuffer>
{
- private Receiver<ByteBuffer> delegate;
- private SSLEngine engine;
- private SSLSender sender;
- private int sslBufSize;
+ private static final Logger log = Logger.get(SSLReceiver.class);
+
+ private final Receiver<ByteBuffer> delegate;
+ private final SSLEngine engine;
+ private final int sslBufSize;
+ private final ByteBuffer localBuffer;
+ private final SSLStatus _sslStatus;
+ private ConnectionSettings settings;
private ByteBuffer appData;
- private ByteBuffer localBuffer;
private boolean dataCached = false;
- private final Object notificationToken;
- private ConnectionSettings settings;
-
- private static final Logger log = Logger.get(SSLReceiver.class);
- public SSLReceiver(SSLEngine engine, Receiver<ByteBuffer> delegate,SSLSender sender)
+ public SSLReceiver(final SSLEngine engine, final Receiver<ByteBuffer> delegate, final SSLStatus sslStatus)
{
this.engine = engine;
this.delegate = delegate;
- this.sender = sender;
this.sslBufSize = engine.getSession().getApplicationBufferSize();
appData = ByteBuffer.allocate(sslBufSize);
localBuffer = ByteBuffer.allocate(sslBufSize);
- notificationToken = sender.getNotificationToken();
+ _sslStatus = sslStatus;
}
public void setConnectionSettings(ConnectionSettings settings)
@@ -102,9 +101,9 @@ public class SSLReceiver implements Receiver<ByteBuffer>
try
{
SSLEngineResult result = engine.unwrap(netData, appData);
- synchronized (notificationToken)
+ synchronized (_sslStatus.getSslLock())
{
- notificationToken.notifyAll();
+ _sslStatus.getSslLock().notifyAll();
}
int read = result.bytesProduced();
@@ -129,9 +128,9 @@ public class SSLReceiver implements Receiver<ByteBuffer>
switch(status)
{
case CLOSED:
- synchronized(notificationToken)
+ synchronized(_sslStatus.getSslLock())
{
- notificationToken.notifyAll();
+ _sslStatus.getSslLock().notifyAll();
}
return;
@@ -163,7 +162,7 @@ public class SSLReceiver implements Receiver<ByteBuffer>
break;
case NEED_TASK:
- sender.doTasks();
+ doTasks();
handshakeStatus = engine.getHandshakeStatus();
case FINISHED:
@@ -174,9 +173,9 @@ public class SSLReceiver implements Receiver<ByteBuffer>
case NEED_WRAP:
case NOT_HANDSHAKING:
- synchronized(notificationToken)
+ synchronized(_sslStatus.getSslLock())
{
- notificationToken.notifyAll();
+ _sslStatus.getSslLock().notifyAll();
}
break;
@@ -189,14 +188,23 @@ public class SSLReceiver implements Receiver<ByteBuffer>
catch(SSLException e)
{
log.error(e, "Error caught in SSLReceiver");
- sender.setErrorFlag();
- synchronized(notificationToken)
+ _sslStatus.setSslErrorFlag();
+ synchronized(_sslStatus.getSslLock())
{
- notificationToken.notifyAll();
+ _sslStatus.getSslLock().notifyAll();
}
exception(new TransportException("Error in SSLReceiver",e));
}
}
}
+
+ private void doTasks()
+ {
+ Runnable runnable;
+ while ((runnable = engine.getDelegatedTask()) != null) {
+ runnable.run();
+ }
+ }
+
}
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java
index cd47a11825..5e0ee93cb8 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLSender.java
@@ -31,30 +31,32 @@ import javax.net.ssl.SSLEngineResult.Status;
import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.SenderException;
+import org.apache.qpid.transport.network.security.SSLStatus;
import org.apache.qpid.transport.util.Logger;
public class SSLSender implements Sender<ByteBuffer>
{
- private Sender<ByteBuffer> delegate;
- private SSLEngine engine;
- private int sslBufSize;
- private ByteBuffer netData;
- private long timeout = 30000;
+ private static final Logger log = Logger.get(SSLSender.class);
+
+ private final Sender<ByteBuffer> delegate;
+ private final SSLEngine engine;
+ private final int sslBufSize;
+ private final ByteBuffer netData;
+ private final long timeout;
+ private final SSLStatus _sslStatus;
private ConnectionSettings settings;
- private final Object engineState = new Object();
private final AtomicBoolean closed = new AtomicBoolean(false);
- private final AtomicBoolean error = new AtomicBoolean(false);
- private static final Logger log = Logger.get(SSLSender.class);
- public SSLSender(SSLEngine engine, Sender<ByteBuffer> delegate)
+ public SSLSender(SSLEngine engine, Sender<ByteBuffer> delegate, SSLStatus sslStatus)
{
this.engine = engine;
this.delegate = delegate;
sslBufSize = engine.getSession().getPacketBufferSize();
netData = ByteBuffer.allocate(sslBufSize);
timeout = Long.getLong("qpid.ssl_timeout", 60000);
+ _sslStatus = sslStatus;
}
public void setConnectionSettings(ConnectionSettings settings)
@@ -83,13 +85,13 @@ public class SSLSender implements Sender<ByteBuffer>
}
- synchronized(engineState)
+ synchronized(_sslStatus.getSslLock())
{
while (!engine.isOutboundDone())
{
try
{
- engineState.wait();
+ _sslStatus.getSslLock().wait();
}
catch(InterruptedException e)
{
@@ -148,7 +150,7 @@ public class SSLSender implements Sender<ByteBuffer>
HandshakeStatus handshakeStatus;
Status status;
- while(appData.hasRemaining() && !error.get())
+ while(appData.hasRemaining() && !_sslStatus.getSslErrorFlag())
{
int read = 0;
try
@@ -160,6 +162,7 @@ public class SSLSender implements Sender<ByteBuffer>
}
catch(SSLException e)
{
+ // Should this set _sslError??
throw new SenderException("SSL, Error occurred while encrypting data",e);
}
@@ -207,7 +210,7 @@ public class SSLSender implements Sender<ByteBuffer>
case NEED_UNWRAP:
flush();
- synchronized(engineState)
+ synchronized(_sslStatus.getSslLock())
{
switch (engine.getHandshakeStatus())
{
@@ -215,7 +218,7 @@ public class SSLSender implements Sender<ByteBuffer>
long start = System.currentTimeMillis();
try
{
- engineState.wait(timeout);
+ _sslStatus.getSslLock().wait(timeout);
}
catch(InterruptedException e)
{
@@ -249,7 +252,7 @@ public class SSLSender implements Sender<ByteBuffer>
}
}
- public void doTasks()
+ private void doTasks()
{
Runnable runnable;
while ((runnable = engine.getDelegatedTask()) != null) {
@@ -257,16 +260,6 @@ public class SSLSender implements Sender<ByteBuffer>
}
}
- public Object getNotificationToken()
- {
- return engineState;
- }
-
- public void setErrorFlag()
- {
- error.set(true);
- }
-
public void setIdleTimeout(int i)
{
delegate.setIdleTimeout(i);
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java
index fd73915b65..6bb038a581 100644
--- a/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java
+++ b/qpid/java/common/src/main/java/org/apache/qpid/transport/network/security/ssl/SSLUtil.java
@@ -125,38 +125,6 @@ public class SSLUtil
return id.toString();
}
- public static SSLContext createSSLContext(ConnectionSettings settings) throws Exception
- {
- SSLContextFactory sslContextFactory;
-
- if (settings.getCertAlias() == null)
- {
- sslContextFactory =
- new SSLContextFactory(settings.getTrustStorePath(),
- settings.getTrustStorePassword(),
- settings.getTrustStoreCertType(),
- settings.getKeyStorePath(),
- settings.getKeyStorePassword(),
- settings.getKeyStoreCertType());
-
- } else
- {
- sslContextFactory =
- new SSLContextFactory(settings.getTrustStorePath(),
- settings.getTrustStorePassword(),
- settings.getTrustStoreCertType(),
- new QpidClientX509KeyManager(settings.getCertAlias(),
- settings.getKeyStorePath(),
- settings.getKeyStorePassword(),
- settings.getKeyStoreCertType()));
-
- log.debug("Using custom key manager");
- }
-
- return sslContextFactory.buildServerContext();
-
- }
-
public static KeyStore getInitializedKeyStore(String storePath, String storePassword) throws GeneralSecurityException, IOException
{
KeyStore ks = KeyStore.getInstance("JKS");
@@ -176,7 +144,10 @@ public class SSLUtil
{
throw new IOException("Unable to load keystore resource: " + storePath);
}
- ks.load(in, storePassword.toCharArray());
+
+ char[] storeCharPassword = storePassword == null ? null : storePassword.toCharArray();
+
+ ks.load(in, storeCharPassword);
}
finally
{
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/ssl/SSLContextFactoryTest.java b/qpid/java/common/src/test/java/org/apache/qpid/ssl/SSLContextFactoryTest.java
new file mode 100644
index 0000000000..288946e064
--- /dev/null
+++ b/qpid/java/common/src/test/java/org/apache/qpid/ssl/SSLContextFactoryTest.java
@@ -0,0 +1,84 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.qpid.ssl;
+
+import java.io.IOException;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class SSLContextFactoryTest extends QpidTestCase
+{
+ private static final String BROKER_KEYSTORE_PATH = TEST_RESOURCES_DIR + "/ssl/java_broker_keystore.jks";
+ private static final String CLIENT_KEYSTORE_PATH = TEST_RESOURCES_DIR + "/ssl/java_client_keystore.jks";
+ private static final String CLIENT_TRUSTSTORE_PATH = TEST_RESOURCES_DIR + "/ssl/java_client_truststore.jks";
+ private static final String STORE_PASSWORD = "password";
+ private static final String CERT_TYPE = "SunX509";
+ private static final String CERT_ALIAS_APP1 = "app1";
+
+ public void testBuildServerContext() throws Exception
+ {
+ SSLContext context = SSLContextFactory.buildServerContext(BROKER_KEYSTORE_PATH, STORE_PASSWORD, CERT_TYPE);
+ assertNotNull("SSLContext should not be null", context);
+ }
+
+ public void testBuildServerContextWithIncorrectPassword() throws Exception
+ {
+ try
+ {
+ SSLContextFactory.buildServerContext(BROKER_KEYSTORE_PATH, "sajdklsad", CERT_TYPE);
+ fail("Exception was not thrown due to incorrect password");
+ }
+ catch (IOException e)
+ {
+ //expected
+ }
+ }
+
+ public void testTrustStoreDoesNotExist() throws Exception
+ {
+ try
+ {
+ SSLContextFactory.buildClientContext("/path/to/nothing", STORE_PASSWORD, CERT_TYPE, CLIENT_KEYSTORE_PATH, STORE_PASSWORD, CERT_TYPE, null);
+ fail("Exception was not thrown due to incorrect path");
+ }
+ catch (IOException e)
+ {
+ //expected
+ }
+ }
+
+ public void testBuildClientContextForSSLEncryptionOnly() throws Exception
+ {
+ SSLContext context = SSLContextFactory.buildClientContext(CLIENT_TRUSTSTORE_PATH, STORE_PASSWORD, CERT_TYPE, null, null, null, null);
+ assertNotNull("SSLContext should not be null", context);
+ }
+
+ public void testBuildClientContextWithForClientAuth() throws Exception
+ {
+ SSLContext context = SSLContextFactory.buildClientContext(CLIENT_TRUSTSTORE_PATH, STORE_PASSWORD, CERT_TYPE, CLIENT_KEYSTORE_PATH, STORE_PASSWORD, CERT_TYPE, null);
+ assertNotNull("SSLContext should not be null", context);
+ }
+
+ public void testBuildClientContextWithForClientAuthWithCertAlias() throws Exception
+ {
+ SSLContext context = SSLContextFactory.buildClientContext(CLIENT_TRUSTSTORE_PATH, STORE_PASSWORD, CERT_TYPE, CLIENT_KEYSTORE_PATH, STORE_PASSWORD, CERT_TYPE, CERT_ALIAS_APP1);
+ assertNotNull("SSLContext should not be null", context);
+ }
+}
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
index 89542e8125..ac3380e0c0 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java
@@ -32,15 +32,22 @@ import java.util.Map;
import junit.framework.TestCase;
import junit.framework.TestResult;
+import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.mina.util.AvailablePortFinder;
public class QpidTestCase extends TestCase
{
- protected static final Logger _logger = Logger.getLogger(QpidTestCase.class);
+ public static final String QPID_HOME = System.getProperty("QPID_HOME");
+ public static final String TEST_RESOURCES_DIR = QPID_HOME + "/../test-profiles/test_resources/";
+ private static final Logger _logger = Logger.getLogger(QpidTestCase.class);
+
+ private final Map<Logger, Level> _loggerLevelSetForTest = new HashMap<Logger, Level>();
private final Map<String, String> _propertiesSetForTest = new HashMap<String, String>();
+ private String _testName;
+
/**
* Some tests are excluded when the property test.excludes is set to true.
* An exclusion list is either a file (prop test.excludesfile) which contains one test name
@@ -144,9 +151,9 @@ public class QpidTestCase extends TestCase
* completes.
*
* @param property The property to set
- * @param value the value to set it to.
+ * @param value the value to set it to, if null, the property will be cleared
*/
- protected void setTestSystemProperty(String property, String value)
+ protected void setTestSystemProperty(final String property, final String value)
{
if (!_propertiesSetForTest.containsKey(property))
{
@@ -154,7 +161,14 @@ public class QpidTestCase extends TestCase
_propertiesSetForTest.put(property, System.getProperty(property));
}
- System.setProperty(property, value);
+ if (value == null)
+ {
+ System.clearProperty(property);
+ }
+ else
+ {
+ System.setProperty(property, value);
+ }
}
/**
@@ -162,24 +176,74 @@ public class QpidTestCase extends TestCase
*/
protected void revertTestSystemProperties()
{
- for (String key : _propertiesSetForTest.keySet())
+ if(!_propertiesSetForTest.isEmpty())
{
- String value = _propertiesSetForTest.get(key);
- if (value != null)
+ _logger.debug("reverting " + _propertiesSetForTest.size() + " test properties");
+ for (String key : _propertiesSetForTest.keySet())
{
- System.setProperty(key, value);
- }
- else
- {
- System.clearProperty(key);
+ String value = _propertiesSetForTest.get(key);
+ if (value != null)
+ {
+ System.setProperty(key, value);
+ }
+ else
+ {
+ System.clearProperty(key);
+ }
}
+
+ _propertiesSetForTest.clear();
+ }
+ }
+
+ /**
+ * Adjust the VMs Log4j Settings just for this test run
+ *
+ * @param logger the logger to change
+ * @param level the level to set
+ */
+ protected void setLoggerLevel(Logger logger, Level level)
+ {
+ assertNotNull("Cannot set level of null logger", logger);
+ assertNotNull("Cannot set Logger("+logger.getName()+") to null level.",level);
+
+ if (!_loggerLevelSetForTest.containsKey(logger))
+ {
+ // Record the current value so we can revert it later.
+ _loggerLevelSetForTest.put(logger, logger.getLevel());
}
- _propertiesSetForTest.clear();
+ logger.setLevel(level);
+ }
+
+ /**
+ * Restore the logging levels defined by this test.
+ */
+ protected void revertLoggingLevels()
+ {
+ for (Logger logger : _loggerLevelSetForTest.keySet())
+ {
+ logger.setLevel(_loggerLevelSetForTest.get(logger));
+ }
+
+ _loggerLevelSetForTest.clear();
}
protected void tearDown() throws java.lang.Exception
{
+ _logger.info("========== tearDown " + _testName + " ==========");
revertTestSystemProperties();
+ revertLoggingLevels();
+ }
+
+ protected void setUp() throws Exception
+ {
+ _testName = getClass().getSimpleName() + "." + getName();
+ _logger.info("========== start " + _testName + " ==========");
+ }
+
+ protected String getTestName()
+ {
+ return _testName;
}
}
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java b/qpid/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java
index 4e504c69eb..d2fab7d163 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/transport/network/TransportTest.java
@@ -23,9 +23,10 @@ package org.apache.qpid.transport.network;
import java.nio.ByteBuffer;
+import javax.net.ssl.SSLContext;
+
import org.apache.qpid.framing.ProtocolVersion;
import org.apache.qpid.protocol.ProtocolEngineFactory;
-import org.apache.qpid.ssl.SSLContextFactory;
import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.transport.ConnectionSettings;
import org.apache.qpid.transport.NetworkTransportConfiguration;
@@ -129,7 +130,7 @@ public class TransportTest extends QpidTestCase
}
public NetworkConnection connect(ConnectionSettings settings,
- Receiver<ByteBuffer> delegate, SSLContextFactory sslFactory)
+ Receiver<ByteBuffer> delegate, SSLContext sslContext)
{
throw new UnsupportedOperationException();
}
@@ -149,7 +150,7 @@ public class TransportTest extends QpidTestCase
}
public void accept(NetworkTransportConfiguration config,
- ProtocolEngineFactory factory, SSLContextFactory sslFactory)
+ ProtocolEngineFactory factory, SSLContext sslContext)
{
throw new UnsupportedOperationException();
}
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoAcceptor.java b/qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoAcceptor.java
index 8530240dcc..e075681acb 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoAcceptor.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoAcceptor.java
@@ -80,7 +80,7 @@ public class IoAcceptor<E> extends Thread
try
{
Socket sock = socket.accept();
- IoTransport<E> transport = new IoTransport<E>(sock, binding,false);
+ IoTransport<E> transport = new IoTransport<E>(sock, binding);
}
catch (IOException e)
{
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoTransport.java b/qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoTransport.java
index 796a845593..0de1308281 100644
--- a/qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoTransport.java
+++ b/qpid/java/common/src/test/java/org/apache/qpid/transport/network/io/IoTransport.java
@@ -29,6 +29,7 @@ import org.apache.qpid.ssl.SSLContextFactory;
import org.apache.qpid.transport.Binding;
import org.apache.qpid.transport.Sender;
import org.apache.qpid.transport.TransportException;
+import org.apache.qpid.transport.network.security.SSLStatus;
import org.apache.qpid.transport.network.security.ssl.SSLReceiver;
import org.apache.qpid.transport.network.security.ssl.SSLSender;
import org.apache.qpid.transport.util.Logger;
@@ -67,18 +68,10 @@ public final class IoTransport<E>
private IoReceiver receiver;
private long timeout = 60000;
- IoTransport(Socket socket, Binding<E,ByteBuffer> binding, boolean ssl)
+ IoTransport(Socket socket, Binding<E,ByteBuffer> binding)
{
this.socket = socket;
-
- if (ssl)
- {
- setupSSLTransport(socket, binding);
- }
- else
- {
- setupTransport(socket, binding);
- }
+ setupTransport(socket, binding);
}
private void setupTransport(Socket socket, Binding<E, ByteBuffer> binding)
@@ -95,40 +88,6 @@ public final class IoTransport<E>
ios.registerCloseListener(this.receiver);
}
- private void setupSSLTransport(Socket socket, Binding<E, ByteBuffer> binding)
- {
- SSLEngine engine = null;
- SSLContext sslCtx;
- try
- {
- sslCtx = createSSLContext();
- }
- catch (Exception e)
- {
- throw new TransportException("Error creating SSL Context", e);
- }
-
- try
- {
- engine = sslCtx.createSSLEngine();
- engine.setUseClientMode(true);
- }
- catch(Exception e)
- {
- throw new TransportException("Error creating SSL Engine", e);
- }
- IoSender ios = new IoSender(socket, 2*writeBufferSize, timeout);
- ios.initiate();
- this.sender = new SSLSender(engine,ios);
- this.endpoint = binding.endpoint(sender);
- this.receiver = new IoReceiver(socket, new SSLReceiver(engine,binding.receiver(endpoint),(SSLSender)sender),
- 2*readBufferSize, timeout);
- this.receiver.initiate();
- ios.registerCloseListener(this.receiver);
-
- log.info("SSL Sender and Receiver initiated");
- }
-
public Sender<ByteBuffer> getSender()
{
return sender;
@@ -144,22 +103,4 @@ public final class IoTransport<E>
return socket;
}
- private SSLContext createSSLContext() throws Exception
- {
- String trustStorePath = System.getProperty("javax.net.ssl.trustStore");
- String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
- String trustStoreCertType = System.getProperty("qpid.ssl.trustStoreCertType","SunX509");
-
- String keyStorePath = System.getProperty("javax.net.ssl.keyStore",trustStorePath);
- String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword",trustStorePassword);
- String keyStoreCertType = System.getProperty("qpid.ssl.keyStoreCertType","SunX509");
-
- SSLContextFactory sslContextFactory = new SSLContextFactory(trustStorePath,trustStorePassword,
- trustStoreCertType,keyStorePath,
- keyStorePassword,keyStoreCertType);
-
- return sslContextFactory.buildServerContext();
-
- }
-
}
diff --git a/qpid/java/perftests/src/main/java/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java b/qpid/java/perftests/src/main/java/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java
index cac0064785..76fd318625 100644
--- a/qpid/java/perftests/src/main/java/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java
+++ b/qpid/java/perftests/src/main/java/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java
@@ -21,8 +21,11 @@
package org.apache.qpid.config;
import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.config.ConnectionFactoryInitialiser;
import org.apache.qpid.config.ConnectorConfig;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.url.URLSyntaxException;
import javax.jms.ConnectionFactory;
@@ -30,6 +33,15 @@ class AMQConnectionFactoryInitialiser implements ConnectionFactoryInitialiser
{
public ConnectionFactory getFactory(ConnectorConfig config)
{
- return new AMQConnectionFactory(config.getHost(), config.getPort(), "/test_path");
+ try
+ {
+ final ConnectionURL connectionUrl = new AMQConnectionURL(ConnectionURL.AMQ_PROTOCOL +
+ "://guest:guest@/test_path?brokerlist='tcp://" + config.getHost() + ":" + config.getPort() + "'");
+ return new AMQConnectionFactory(connectionUrl);
+ }
+ catch (URLSyntaxException e)
+ {
+ throw new RuntimeException("Problem building URL", e);
+ }
}
}
diff --git a/qpid/java/systests/etc/config-systests-settings.xml b/qpid/java/systests/etc/config-systests-settings.xml
index 751ff133cb..5ed208bfe7 100644
--- a/qpid/java/systests/etc/config-systests-settings.xml
+++ b/qpid/java/systests/etc/config-systests-settings.xml
@@ -20,11 +20,20 @@
-
-->
<broker>
+ <connector>
+ <ssl>
+ <port>15671</port>
+ <enabled>false</enabled>
+ <sslOnly>false</sslOnly>
+ <keystorePath>${QPID_HOME}/../test-profiles/test_resources/ssl/java_broker_keystore.jks</keystorePath>
+ <keystorePassword>password</keystorePassword>
+ </ssl>
+ </connector>
<management>
<enabled>false</enabled>
<ssl>
<enabled>false</enabled>
- <keyStorePath>${QPID_HOME}/../test-profiles/test_resources/ssl/keystore.jks</keyStorePath>
+ <keyStorePath>${QPID_HOME}/../test-profiles/test_resources/ssl/java_broker_keystore.jks</keyStorePath>
<keyStorePassword>password</keyStorePassword>
</ssl>
</management>
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
index 8cdf12eaa4..471ebb16fc 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java
@@ -31,62 +31,72 @@ import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.transport.Connection;
public class SSLTest extends QpidBrokerTestCase
-{
-
+{
+ private static final String KEYSTORE = TEST_RESOURCES_DIR + "/ssl/java_client_keystore.jks";
+ private static final String KEYSTORE_PASSWORD = "password";
+ private static final String TRUSTSTORE = TEST_RESOURCES_DIR + "/ssl/java_client_truststore.jks";
+ private static final String TRUSTSTORE_PASSWORD = "password";
+ private static final String CERT_ALIAS_APP1 = "app1";
+ private static final String CERT_ALIAS_APP2 = "app2";
+
@Override
protected void setUp() throws Exception
{
- System.setProperty("javax.net.debug", "ssl");
+ if(isJavaBroker())
+ {
+ setTestClientSystemProperty("profile.use_ssl", "true");
+ setConfigurationProperty("connector.ssl.enabled", "true");
+ setConfigurationProperty("connector.ssl.sslOnly", "true");
+ }
+
+ // set the ssl system properties
+ setSystemProperty("javax.net.ssl.keyStore", KEYSTORE);
+ setSystemProperty("javax.net.ssl.keyStorePassword", KEYSTORE_PASSWORD);
+ setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE);
+ setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD);
+ setSystemProperty("javax.net.debug", "ssl");
super.setUp();
}
- @Override
- protected void tearDown() throws Exception
- {
- System.setProperty("javax.net.debug", "");
- super.tearDown();
- }
-
- public void testCreateSSLContextFromConnectionURLParams()
+ public void testCreateSSLConnectionUsingConnectionURLParams() throws Exception
{
if (Boolean.getBoolean("profile.use_ssl"))
- {
+ {
+ // Clear the ssl system properties
+ setSystemProperty("javax.net.ssl.keyStore", null);
+ setSystemProperty("javax.net.ssl.keyStorePassword", null);
+ setSystemProperty("javax.net.ssl.trustStore", null);
+ setSystemProperty("javax.net.ssl.trustStorePassword", null);
+
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" +
"?ssl='true'&ssl_verify_hostname='true'" +
"&key_store='%s'&key_store_password='%s'" +
"&trust_store='%s'&trust_store_password='%s'" +
"'";
- String keyStore = System.getProperty("javax.net.ssl.keyStore");
- String keyStorePass = System.getProperty("javax.net.ssl.keyStorePassword");
- String trustStore = System.getProperty("javax.net.ssl.trustStore");
- String trustStorePass = System.getProperty("javax.net.ssl.trustStorePassword");
+ url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT,
+ KEYSTORE,KEYSTORE_PASSWORD,TRUSTSTORE,TRUSTSTORE_PASSWORD);
- url = String.format(url,System.getProperty("test.port.ssl"),
- keyStore,keyStorePass,trustStore,trustStorePass);
+ AMQConnection con = new AMQConnection(url);
+ assertNotNull("connection should be successful", con);
+ Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
+ assertNotNull("create session should be successful", ssn);
+ }
+ }
+
+ public void testCreateSSLConnectionUsingSystemProperties() throws Exception
+ {
+ if (Boolean.getBoolean("profile.use_ssl"))
+ {
+
+ String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s?ssl='true''";
+
+ url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT);
- // temporarily set the trust/key store jvm args to something else
- // to ensure we only read from the connection URL param.
- System.setProperty("javax.net.ssl.trustStore","fessgsdgd");
- System.setProperty("javax.net.ssl.trustStorePassword","fessgsdgd");
- System.setProperty("javax.net.ssl.keyStore","fessgsdgd");
- System.setProperty("javax.net.ssl.keyStorePassword","fessgsdgd");
- try
- {
- AMQConnection con = new AMQConnection(url);
- Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
- }
- catch (Exception e)
- {
- fail("SSL Connection should be successful");
- }
- finally
- {
- System.setProperty("javax.net.ssl.trustStore",trustStore);
- System.setProperty("javax.net.ssl.trustStorePassword",trustStorePass);
- System.setProperty("javax.net.ssl.keyStore",keyStore);
- System.setProperty("javax.net.ssl.keyStorePassword",keyStorePass);
- }
+ AMQConnection con = new AMQConnection(url);
+ assertNotNull("connection should be successful", con);
+ Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
+ assertNotNull("create session should be successful", ssn);
}
}
@@ -95,8 +105,8 @@ public class SSLTest extends QpidBrokerTestCase
if (Boolean.getBoolean("profile.use_ssl"))
{
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:" +
- System.getProperty("test.port.ssl") +
- "?ssl='true'&ssl_cert_alias='app1''";
+ QpidBrokerTestCase.DEFAULT_SSL_PORT +
+ "?ssl='true'&ssl_cert_alias='" + CERT_ALIAS_APP1 + "''";
AMQTestConnection_0_10 con = new AMQTestConnection_0_10(url);
Connection transportCon = con.getConnection();
@@ -105,8 +115,8 @@ public class SSLTest extends QpidBrokerTestCase
con.close();
url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:" +
- System.getProperty("test.port.ssl") +
- "?ssl='true'&ssl_cert_alias='app2''";
+ QpidBrokerTestCase.DEFAULT_SSL_PORT +
+ "?ssl='true'&ssl_cert_alias='" + CERT_ALIAS_APP2 + "''";
con = new AMQTestConnection_0_10(url);
transportCon = con.getConnection();
@@ -116,12 +126,12 @@ public class SSLTest extends QpidBrokerTestCase
}
}
- public void testVerifyHostName()
+ public void testVerifyHostNameWithIncorrectHostname()
{
if (Boolean.getBoolean("profile.use_ssl"))
{
String url = "amqp://guest:guest@test/?brokerlist='tcp://127.0.0.1:" +
- System.getProperty("test.port.ssl") +
+ QpidBrokerTestCase.DEFAULT_SSL_PORT +
"?ssl='true'&ssl_verify_hostname='true''";
try
@@ -140,42 +150,53 @@ public class SSLTest extends QpidBrokerTestCase
}
}
- public void testVerifyLocalHost()
+ public void testVerifyLocalHost() throws Exception
{
if (Boolean.getBoolean("profile.use_ssl"))
{
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:" +
- System.getProperty("test.port.ssl") +
+ QpidBrokerTestCase.DEFAULT_SSL_PORT +
"?ssl='true'&ssl_verify_hostname='true''";
-
- try
- {
- AMQConnection con = new AMQConnection(url);
- }
- catch (Exception e)
- {
- fail("Hostname verification should succeed");
- }
- }
+
+ AMQConnection con = new AMQConnection(url);
+ assertNotNull("connection should have been created", con);
+ }
}
- public void testVerifyLocalHostLocalDomain()
+ public void testVerifyLocalHostLocalDomain() throws Exception
{
if (Boolean.getBoolean("profile.use_ssl"))
{
String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost.localdomain:" +
- System.getProperty("test.port.ssl") +
+ QpidBrokerTestCase.DEFAULT_SSL_PORT +
"?ssl='true'&ssl_verify_hostname='true''";
+
+ AMQConnection con = new AMQConnection(url);
+ assertNotNull("connection should have been created", con);
+ }
+ }
+
+ public void testCreateSSLConnectionUsingConnectionURLParamsTrustStoreOnly() throws Exception
+ {
+ if (Boolean.getBoolean("profile.use_ssl"))
+ {
+ // Clear the ssl system properties
+ setSystemProperty("javax.net.ssl.keyStore", null);
+ setSystemProperty("javax.net.ssl.keyStorePassword", null);
+ setSystemProperty("javax.net.ssl.trustStore", null);
+ setSystemProperty("javax.net.ssl.trustStorePassword", null);
- try
- {
- AMQConnection con = new AMQConnection(url);
- }
- catch (Exception e)
- {
- fail("Hostname verification should succeed");
- }
-
+ String url = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" +
+ "?ssl='true'&ssl_verify_hostname='true'" +
+ "&trust_store='%s'&trust_store_password='%s'" +
+ "'";
+
+ url = String.format(url,QpidBrokerTestCase.DEFAULT_SSL_PORT, TRUSTSTORE,TRUSTSTORE_PASSWORD);
+
+ AMQConnection con = new AMQConnection(url);
+ assertNotNull("connection should be successful", con);
+ Session ssn = con.createSession(false,Session.AUTO_ACKNOWLEDGE);
+ assertNotNull("create session should be successful", ssn);
}
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java
index 11db513e00..30d2d851a0 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java
@@ -60,7 +60,7 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL
try
{
long start = System.currentTimeMillis();
- AMQConnection connection = new AMQConnection(url, null);
+ AMQConnection connection = new AMQConnection(url);
connection.setExceptionListener(this);
@@ -104,7 +104,7 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL
try
{
long start = System.currentTimeMillis();
- AMQConnection connection = new AMQConnection(url, null);
+ AMQConnection connection = new AMQConnection(url);
connection.setExceptionListener(this);
@@ -210,7 +210,7 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL
long start = System.currentTimeMillis();
//Start the connection so it will use the retries
- AMQConnection connection = new AMQConnection(url, null);
+ AMQConnection connection = new AMQConnection(url);
long end = System.currentTimeMillis();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
index 9155b84365..e901903eb4 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
@@ -519,7 +519,7 @@ public class BrokerLoggingTest extends AbstractTestLogging
setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath"));
setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword"));
- Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.sslport"));
+ Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.ssl.port"));
startBroker();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
index 7f8f71d965..8aa5b6d9de 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
@@ -196,7 +196,7 @@ public abstract class AbstractACLTestCase extends QpidBrokerTestCase implements
}
PrintWriter out = new PrintWriter(new FileWriter(aclFile));
- out.println(String.format("# %s", _testName));
+ out.println(String.format("# %s", getTestName()));
for (String line : rules)
{
out.println(line);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
index fcbab273e5..3068deecf8 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
@@ -299,7 +299,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
details.setProperty(BrokerDetails.OPTIONS_RETRY, String.valueOf(RETRIES));
details.setProperty(BrokerDetails.OPTIONS_CONNECT_DELAY, String.valueOf(DELAY));
- connection = new AMQConnection(connectionURL, null);
+ connection = new AMQConnection(connectionURL);
((AMQConnection) connection).setConnectionListener(this);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java
index 481b144caf..e79fe69199 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQConnectionTest.java
@@ -50,9 +50,9 @@ import org.slf4j.LoggerFactory;
public class AMQConnectionTest extends QpidBrokerTestCase
{
- private static AMQConnection _connection;
- private static AMQTopic _topic;
- private static AMQQueue _queue;
+ protected static AMQConnection _connection;
+ protected static AMQTopic _topic;
+ protected static AMQQueue _queue;
private static QueueSession _queueSession;
private static TopicSession _topicSession;
protected static final Logger _logger = LoggerFactory.getLogger(AMQConnectionTest.class);
@@ -60,15 +60,14 @@ public class AMQConnectionTest extends QpidBrokerTestCase
protected void setUp() throws Exception
{
super.setUp();
- _connection = (AMQConnection) getConnection("guest", "guest");
+ createConnection();
_topic = new AMQTopic(_connection.getDefaultTopicExchangeName(), new AMQShortString("mytopic"));
_queue = new AMQQueue(_connection.getDefaultQueueExchangeName(), new AMQShortString("myqueue"));
}
-
- protected void tearDown() throws Exception
+
+ protected void createConnection() throws Exception
{
- _connection.close();
- super.tearDown();
+ _connection = (AMQConnection) getConnection("guest", "guest");
}
/**
@@ -207,61 +206,50 @@ public class AMQConnectionTest extends QpidBrokerTestCase
public void testPrefetchSystemProperty() throws Exception
{
- String oldPrefetch = System.getProperty(ClientProperties.MAX_PREFETCH_PROP_NAME);
- try
- {
- _connection.close();
- System.setProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, new Integer(2).toString());
- _connection = (AMQConnection) getConnection();
- _connection.start();
- // Create two consumers on different sessions
- Session consSessA = _connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer consumerA = consSessA.createConsumer(_queue);
-
- Session producerSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = producerSession.createProducer(_queue);
+ _connection.close();
+ setTestClientSystemProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, new Integer(2).toString());
+
+ createConnection();
+ _connection.start();
+ // Create two consumers on different sessions
+ Session consSessA = _connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumerA = consSessA.createConsumer(_queue);
- // Send 3 messages
- for (int i = 0; i < 3; i++)
- {
- producer.send(producerSession.createTextMessage("test"));
- }
-
- MessageConsumer consumerB = null;
- // 0-8, 0-9, 0-9-1 prefetch is per session, not consumer.
- if (!isBroker010())
- {
- Session consSessB = _connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- consumerB = consSessB.createConsumer(_queue);
- }
- else
- {
- consumerB = consSessA.createConsumer(_queue);
- }
+ Session producerSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = producerSession.createProducer(_queue);
- Message msg;
- // Check that consumer A has 2 messages
- for (int i = 0; i < 2; i++)
- {
- msg = consumerA.receive(1500);
- assertNotNull("Consumer A should receive 2 messages",msg);
- }
-
- msg = consumerA.receive(1500);
- assertNull("Consumer A should not have received a 3rd message",msg);
-
- // Check that consumer B has the last message
- msg = consumerB.receive(1500);
- assertNotNull("Consumer B should have received the message",msg);
+ // Send 3 messages
+ for (int i = 0; i < 3; i++)
+ {
+ producer.send(producerSession.createTextMessage("test"));
}
- finally
+
+ MessageConsumer consumerB = null;
+ // 0-8, 0-9, 0-9-1 prefetch is per session, not consumer.
+ if (!isBroker010())
{
- if (oldPrefetch == null)
- {
- oldPrefetch = ClientProperties.MAX_PREFETCH_DEFAULT;
- }
- System.setProperty(ClientProperties.MAX_PREFETCH_PROP_NAME, oldPrefetch);
+ Session consSessB = _connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ consumerB = consSessB.createConsumer(_queue);
+ }
+ else
+ {
+ consumerB = consSessA.createConsumer(_queue);
+ }
+
+ Message msg;
+ // Check that consumer A has 2 messages
+ for (int i = 0; i < 2; i++)
+ {
+ msg = consumerA.receive(1500);
+ assertNotNull("Consumer A should receive 2 messages",msg);
}
+
+ msg = consumerA.receive(1500);
+ assertNull("Consumer A should not have received a 3rd message",msg);
+
+ // Check that consumer B has the last message
+ msg = consumerB.receive(1500);
+ assertNotNull("Consumer B should have received the message",msg);
}
public void testGetChannelID() throws Exception
@@ -284,120 +272,5 @@ public class AMQConnectionTest extends QpidBrokerTestCase
}
}
}
-
- /**
- * Test Strategy : Kill -STOP the broker and see
- * if the client terminates the connection with a
- * read timeout.
- * The broker process is cleaned up in the test itself
- * and avoids using process.waitFor() as it hangs.
- */
- public void testHeartBeat() throws Exception
- {
- boolean windows =
- ((String) System.getProperties().get("os.name")).matches("(?i).*windows.*");
-
- if (!isCppBroker() || windows)
- {
- return;
- }
-
- Process process = null;
- int port = getPort(0);
- String pid = null;
- try
- {
- // close the connection and shutdown the broker started by QpidTest
- _connection.close();
- stopBroker(port);
-
- System.setProperty("qpid.heartbeat", "1");
-
- // in case this broker gets stuck, atleast the rest of the tests will not fail.
- port = port + 200;
- String startCmd = getBrokerCommand(port);
-
- // start a broker using a script
- ProcessBuilder pb = new ProcessBuilder(System.getProperty("broker.start"));
- pb.redirectErrorStream(true);
-
- Map<String, String> env = pb.environment();
- env.put("BROKER_CMD",startCmd);
- env.put("BROKER_READY",System.getProperty(BROKER_READY));
-
- Process startScript = pb.start();
- startScript.waitFor();
- startScript.destroy();
-
- Connection con =
- new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:" + port + "'");
- final AtomicBoolean lock = new AtomicBoolean(false);
-
- String cmd = "/usr/bin/pgrep -f " + port;
- process = Runtime.getRuntime().exec("/bin/bash");
- LineNumberReader reader = new LineNumberReader(new InputStreamReader(process.getInputStream()));
- PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(process.getOutputStream())), true);
- out.println(cmd);
- pid = reader.readLine();
- try
- {
- Integer.parseInt(pid);
- }
- catch (NumberFormatException e)
- {
- // Error! try to read further to gather the error msg.
- String line;
- _logger.debug(pid);
- while ((line = reader.readLine()) != null )
- {
- _logger.debug(line);
- }
- throw new Exception( "Unable to get the brokers pid " + pid);
- }
- _logger.debug("pid : " + pid);
-
- con.setExceptionListener(new ExceptionListener(){
-
- public void onException(JMSException e)
- {
- synchronized(lock) {
- lock.set(true);
- lock.notifyAll();
- }
- }
- });
- out.println("kill -STOP " + pid);
-
- synchronized(lock){
- lock.wait(2500);
- }
- out.close();
- reader.close();
- assertTrue("Client did not terminate the connection, check log for details",lock.get());
- }
- catch(Exception e)
- {
- throw e;
- }
- finally
- {
- System.setProperty("qpid.heartbeat", "");
-
- if (process != null)
- {
- process.destroy();
- }
-
- Process killScript = Runtime.getRuntime().exec(System.getProperty("broker.kill") + " " + pid);
- killScript.waitFor();
- killScript.destroy();
- cleanBroker();
- }
- }
-
- public static junit.framework.Test suite()
- {
- return new junit.framework.TestSuite(AMQConnectionTest.class);
- }
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQSSLConnectionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQSSLConnectionTest.java
new file mode 100644
index 0000000000..53a433c543
--- /dev/null
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/AMQSSLConnectionTest.java
@@ -0,0 +1,57 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.test.unit.client;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionURL;
+
+public class AMQSSLConnectionTest extends AMQConnectionTest
+{
+ private static final String KEYSTORE = TEST_RESOURCES_DIR + "/ssl/java_client_keystore.jks";
+ private static final String KEYSTORE_PASSWORD = "password";
+ private static final String TRUSTSTORE = TEST_RESOURCES_DIR + "/ssl/java_client_truststore.jks";
+ private static final String TRUSTSTORE_PASSWORD = "password";
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ setTestClientSystemProperty("profile.use_ssl", "true");
+ setConfigurationProperty("connector.ssl.enabled", "true");
+ setConfigurationProperty("connector.ssl.sslOnly", "true");
+ super.setUp();
+ }
+
+ protected void createConnection() throws Exception
+ {
+
+ final String sslPrototypeUrl = "amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" +
+ "?ssl='true'&ssl_verify_hostname='false'" +
+ "&key_store='%s'&key_store_password='%s'" +
+ "&trust_store='%s'&trust_store_password='%s'" +
+ "'";
+
+ final String url = String.format(sslPrototypeUrl,System.getProperty("test.port.ssl"),
+ KEYSTORE,KEYSTORE_PASSWORD,TRUSTSTORE,TRUSTSTORE_PASSWORD);
+
+ _connection = (AMQConnection) getConnection(new AMQConnectionURL(url));
+ }
+}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/CloseAfterConnectionFailureTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/CloseAfterConnectionFailureTest.java
index dc2f59c384..91e681131f 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/CloseAfterConnectionFailureTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/CloseAfterConnectionFailureTest.java
@@ -55,7 +55,7 @@ public class CloseAfterConnectionFailureTest extends QpidBrokerTestCase implemen
try
{
//Start the connection so it will use the retries
- connection = new AMQConnection(url, null);
+ connection = new AMQConnection(url);
connection.setExceptionListener(this);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
index 124e756fad..fe2ea6ef10 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
@@ -81,7 +81,7 @@ public class ConnectionTest extends QpidBrokerTestCase
+ "&temporaryTopicExchange='tmp.topic'");
System.err.println(url.toString());
- conn = new AMQConnection(url, null);
+ conn = new AMQConnection(url);
AMQSession sess = (AMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
index c8ccdf91bb..0a98fc3382 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
@@ -83,7 +83,7 @@ public class QpidBrokerTestCase extends QpidTestCase
INTERNAL /** Test case starts an embedded broker within this JVM */,
SPAWNED /** Test case spawns a new broker as a separate process */
}
- protected final String QpidHome = System.getProperty("QPID_HOME");
+ protected final static String QpidHome = System.getProperty("QPID_HOME");
protected File _configFile = new File(System.getProperty("broker.config"));
protected static final Logger _logger = Logger.getLogger(QpidBrokerTestCase.class);
@@ -92,7 +92,6 @@ public class QpidBrokerTestCase extends QpidTestCase
protected long RECEIVE_TIMEOUT = 1000l;
private Map<String, String> _propertiesSetForBroker = new HashMap<String, String>();
- private Map<Logger, Level> _loggerLevelSetForTest = new HashMap<Logger, Level>();
private XMLConfiguration _testConfiguration = new XMLConfiguration();
private XMLConfiguration _testVirtualhosts = new XMLConfiguration();
@@ -139,7 +138,7 @@ public class QpidBrokerTestCase extends QpidTestCase
public static final int DEFAULT_PORT = Integer.getInteger("test.port", ServerConfiguration.DEFAULT_PORT);
public static final int FAILING_PORT = Integer.parseInt(System.getProperty("test.port.alt"));
public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", ServerConfiguration.DEFAULT_JMXPORT);
- public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.sslport", ServerConfiguration.DEFAULT_SSL_PORT);
+ public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", ServerConfiguration.DEFAULT_SSL_PORT);
protected String _brokerLanguage = System.getProperty(BROKER_LANGUAGE, JAVA);
protected BrokerType _brokerType = BrokerType.valueOf(System.getProperty(BROKER_TYPE, "").toUpperCase());
@@ -163,8 +162,6 @@ public class QpidBrokerTestCase extends QpidTestCase
protected InitialContext _initialContext;
protected AMQConnectionFactory _connectionFactory;
- protected String _testName;
-
// the connections created for a given test
protected List<Connection> _connections = new ArrayList<Connection>();
public static final String QUEUE = "queue";
@@ -206,7 +203,6 @@ public class QpidBrokerTestCase extends QpidTestCase
public void runBare() throws Throwable
{
- _testName = getClass().getSimpleName() + "." + getName();
String qname = getClass().getName() + "." + getName();
// Initialize this for each test run
@@ -237,7 +233,6 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
- _logger.info("========== start " + _testName + " ==========");
try
{
super.runBare();
@@ -258,6 +253,10 @@ public class QpidBrokerTestCase extends QpidTestCase
_logger.error("exception stopping broker", e);
}
+ // reset properties used in the test
+ revertSystemProperties();
+ revertLoggingLevels();
+
if(_brokerCleanBetweenTests)
{
try
@@ -270,7 +269,7 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
- _logger.info("========== stop " + _testName + " ==========");
+ _logger.info("========== stop " + getTestName() + " ==========");
if (redirected)
{
@@ -289,6 +288,8 @@ public class QpidBrokerTestCase extends QpidTestCase
@Override
protected void setUp() throws Exception
{
+ super.setUp();
+
if (!_configFile.exists())
{
fail("Unable to test without config file:" + _configFile);
@@ -440,10 +441,11 @@ public class QpidBrokerTestCase extends QpidTestCase
protected String getBrokerCommand(int port) throws MalformedURLException
{
- final String protocolExcludesList = _brokerProtocolExcludes.replace("@PORT", "" + port);
+ final int sslPort = port-1;
+ final String protocolExcludesList = getProtocolExcludesList(port, sslPort);
return _brokerCommand
.replace("@PORT", "" + port)
- .replace("@SSL_PORT", "" + (port - 1))
+ .replace("@SSL_PORT", "" + sslPort)
.replace("@MPORT", "" + getManagementPort(port))
.replace("@CONFIG_FILE", _configFile.toString())
.replace("@EXCLUDES", protocolExcludesList);
@@ -476,7 +478,7 @@ public class QpidBrokerTestCase extends QpidTestCase
options.setConfigFile(_configFile.getAbsolutePath());
options.addPort(port);
- addExcludedPorts(port, options);
+ addExcludedPorts(port, DEFAULT_SSL_PORT, options);
options.setJmxPort(getManagementPort(port));
@@ -507,7 +509,7 @@ public class QpidBrokerTestCase extends QpidTestCase
//Add the test name to the broker run.
// DON'T change PNAME, qpid.stop needs this value.
- env.put("QPID_PNAME", "-DPNAME=QPBRKR -DTNAME=\"" + _testName + "\"");
+ env.put("QPID_PNAME", "-DPNAME=QPBRKR -DTNAME=\"" + getTestName() + "\"");
// Add the port to QPID_WORK to ensure unique working dirs for multi broker tests
env.put("QPID_WORK", getQpidWork(_brokerType, port));
@@ -597,9 +599,9 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
- private void addExcludedPorts(int port, BrokerOptions options)
+ private void addExcludedPorts(int port, int sslPort, BrokerOptions options)
{
- final String protocolExcludesList = _brokerProtocolExcludes.replace("@PORT", "" + port);
+ final String protocolExcludesList = getProtocolExcludesList(port, sslPort);
if (protocolExcludesList.equals(""))
{
@@ -621,6 +623,13 @@ public class QpidBrokerTestCase extends QpidTestCase
}
}
+ protected String getProtocolExcludesList(int port, int sslPort)
+ {
+ final String protocolExcludesList =
+ _brokerProtocolExcludes.replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort);
+ return protocolExcludesList;
+ }
+
private boolean existingInternalBroker()
{
for(BrokerHolder holder : _brokers.values())
@@ -908,40 +917,6 @@ public class QpidBrokerTestCase extends QpidTestCase
}
/**
- * Adjust the VMs Log4j Settings just for this test run
- *
- * @param logger the logger to change
- * @param level the level to set
- */
- protected void setLoggerLevel(Logger logger, Level level)
- {
- assertNotNull("Cannot set level of null logger", logger);
- assertNotNull("Cannot set Logger("+logger.getName()+") to null level.",level);
-
- if (!_loggerLevelSetForTest.containsKey(logger))
- {
- // Record the current value so we can revert it later.
- _loggerLevelSetForTest.put(logger, logger.getLevel());
- }
-
- logger.setLevel(level);
- }
-
- /**
- * Restore the logging levels defined by this test.
- */
- protected void revertLoggingLevels()
- {
- for (Logger logger : _loggerLevelSetForTest.keySet())
- {
- logger.setLevel(_loggerLevelSetForTest.get(logger));
- }
-
- _loggerLevelSetForTest.clear();
-
- }
-
- /**
* Check whether the broker is an 0.8
*
* @return true if the broker is an 0_8 version, false otherwise.
@@ -1049,7 +1024,7 @@ public class QpidBrokerTestCase extends QpidTestCase
{
return (AMQConnectionFactory) getInitialContext().lookup(factoryName);
}
-
+
public Connection getConnection() throws JMSException, NamingException
{
return getConnection("guest", "guest");
@@ -1117,19 +1092,12 @@ public class QpidBrokerTestCase extends QpidTestCase
protected void tearDown() throws java.lang.Exception
{
- try
- {
- // close all the connections used by this test.
- for (Connection c : _connections)
- {
- c.close();
- }
- }
- finally
+ super.tearDown();
+
+ // close all the connections used by this test.
+ for (Connection c : _connections)
{
- // Ensure any problems with close does not interfer with property resets
- revertSystemProperties();
- revertLoggingLevels();
+ c.close();
}
}
diff --git a/qpid/java/test-profiles/CPPExcludes b/qpid/java/test-profiles/CPPExcludes
index 89cdd792de..8c05b28161 100755
--- a/qpid/java/test-profiles/CPPExcludes
+++ b/qpid/java/test-profiles/CPPExcludes
@@ -144,9 +144,6 @@ org.apache.qpid.test.unit.ack.FailoverBeforeConsumingRecoverTest#*
org.apache.qpid.test.client.RollbackOrderTest#testOrderingAfterRollbackOnMessage#*
-// Temporarily adding the following until the issues are sorted out.
-org.apache.qpid.test.unit.client.AMQConnectionTest#testHeartBeat
-
//Excluded due to QPID-1447 : CPP broker does not have SlowConsumer Disconnection
org.apache.qpid.systest.GlobalQueuesTest#*
org.apache.qpid.systest.GlobalTopicsTest#*
diff --git a/qpid/java/test-profiles/JavaExcludes b/qpid/java/test-profiles/JavaExcludes
index 4be228c7da..2fc70e6e70 100644
--- a/qpid/java/test-profiles/JavaExcludes
+++ b/qpid/java/test-profiles/JavaExcludes
@@ -88,3 +88,6 @@ org.apache.qpid.server.configuration.ServerConfigurationFileTest#*
org.apache.qpid.test.unit.client.connection.ConnectionTest#testClientIDVerification
org.apache.qpid.jms.xa.XAResourceTest#*
+
+//The Java broker doesnt support client auth
+org.apache.qpid.client.ssl.SSLTest#testMultipleCertsInSingleStore
diff --git a/qpid/java/test-profiles/cpp.ssl.excludes b/qpid/java/test-profiles/cpp.ssl.excludes
index 4d499c57b9..14c8ac2fe3 100644
--- a/qpid/java/test-profiles/cpp.ssl.excludes
+++ b/qpid/java/test-profiles/cpp.ssl.excludes
@@ -18,3 +18,10 @@
//
#org.apache.qpid.test.client.failover.FailoverTest#*
+
+//This test does not supply a client keystore, therefore it cant login to the C++ broker
+//in this test profile as it demands client certificate authentication
+org.apache.qpid.client.ssl.SSLTest#testCreateSSLConnectionUsingConnectionURLParamsTrustStoreOnly
+
+//QPID-3431: excluding because this takes 30+ mins to run on the C++ SSL profile for some reason
+org.apache.qpid.client.SessionCreateTest#testSessionCreationLimit
diff --git a/qpid/java/test-profiles/cpp.ssl.testprofile b/qpid/java/test-profiles/cpp.ssl.testprofile
index bf71384835..b3bb5e22f7 100644
--- a/qpid/java/test-profiles/cpp.ssl.testprofile
+++ b/qpid/java/test-profiles/cpp.ssl.testprofile
@@ -23,7 +23,7 @@ broker.modules=--load-module ${broker.module.ssl} --ssl-cert-name localhost.loca
profile.use_ssl=true
broker.ready= Listening for SSL connections
-javax.net.ssl.keyStore=${test.profiles}/test_resources/ssl/keystore.jks
+javax.net.ssl.keyStore=${test.profiles}/test_resources/ssl/java_client_keystore.jks
javax.net.ssl.keyStorePassword=password
-javax.net.ssl.trustStore=${test.profiles}/test_resources/ssl/certstore.jks
+javax.net.ssl.trustStore=${test.profiles}/test_resources/ssl/java_client_truststore.jks
javax.net.ssl.trustStorePassword=password
diff --git a/qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile b/qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile
index f79e1f3aad..1580cec1c5 100644
--- a/qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-dby-spawn.0-9-1.testprofile
@@ -24,7 +24,7 @@ broker.clean=${test.profiles}/clean-dir ${build.data} ${project.root}/build/work
broker.ready=BRK-1004
broker.stopped=Exception
broker.config=${project.root}/build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT
+broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT
messagestore.class.name=org.apache.qpid.server.store.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-dby.0-9-1.testprofile b/qpid/java/test-profiles/java-dby.0-9-1.testprofile
index f9700da82d..b4d506df05 100644
--- a/qpid/java/test-profiles/java-dby.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-dby.0-9-1.testprofile
@@ -24,7 +24,7 @@ broker.clean=${test.profiles}/clean-dir ${build.data} ${project.root}/build/work
broker.ready=BRK-1004
broker.stopped=Exception
broker.config=${project.root}/build/etc/config-systests-derby.xml
-broker.protocol.excludes=--exclude-0-10 @PORT
+broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT
messagestore.class.name=org.apache.qpid.server.store.DerbyMessageStore
profile.excludes=JavaPersistentExcludes JavaPre010Excludes
broker.clean.between.tests=true
diff --git a/qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile b/qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile
index f94b93c793..4563600ba1 100644
--- a/qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-mms-spawn.0-9-1.testprofile
@@ -23,7 +23,7 @@ broker.command=${project.root}/build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDE
broker.clean=${test.profiles}/clean-dir ${build.data} ${project.root}/build/work
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT
+broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/java-mms.0-9-1.testprofile b/qpid/java/test-profiles/java-mms.0-9-1.testprofile
index 45e2fc7162..cec02f3aa6 100644
--- a/qpid/java/test-profiles/java-mms.0-9-1.testprofile
+++ b/qpid/java/test-profiles/java-mms.0-9-1.testprofile
@@ -24,7 +24,7 @@ broker.command=${project.root}/build/bin/qpid-server -p @PORT -m @MPORT @EXCLUDE
broker.clean=${test.profiles}/clean-dir ${build.data} ${project.root}/build/work
broker.ready=BRK-1004
broker.stopped=Exception
-broker.protocol.excludes=--exclude-0-10 @PORT
+broker.protocol.excludes=--exclude-0-10 @PORT --exclude-0-10 @SSL_PORT
#
# Do not enable. Allow client to attempt 0-10 and negotiate downwards
#
diff --git a/qpid/java/test-profiles/log4j-test.xml b/qpid/java/test-profiles/log4j-test.xml
index 9adfd68202..062acaaac9 100644
--- a/qpid/java/test-profiles/log4j-test.xml
+++ b/qpid/java/test-profiles/log4j-test.xml
@@ -59,10 +59,6 @@
<level value="ERROR"/>
</logger>
- <logger name="org.apache.qpid.server.virtualhost.VirtualHostImpl$1HouseKeepingTask">
- <level value="WARN"/>
- </logger>
-
<root>
<level value="${root.logging.level}"/>
<appender-ref ref="console" />
diff --git a/qpid/java/test-profiles/test_resources/ssl/java_broker.crt b/qpid/java/test-profiles/test_resources/ssl/java_broker.crt
new file mode 100644
index 0000000000..7543ee8a7d
--- /dev/null
+++ b/qpid/java/test-profiles/test_resources/ssl/java_broker.crt
@@ -0,0 +1,15 @@
+-----BEGIN CERTIFICATE-----
+MIICVzCCAcCgAwIBAgIFAJVWeugwDQYJKoZIhvcNAQEFBQAwQTELMAkGA1UEBhMC
+Q0ExEDAOBgNVBAgTB09udGFyaW8xDTALBgNVBAoTBEFDTUUxETAPBgNVBAMTCE15
+Um9vdENBMB4XDTExMDgxNzEzNTQ1NFoXDTExMTExNzEzNTQ1NFowejEQMA4GA1UE
+BhMHVW5rbm93bjEQMA4GA1UECBMHVW5rbm93bjEQMA4GA1UEBxMHVW5rbm93bjEQ
+MA4GA1UEChMHVW5rbm93bjEQMA4GA1UECxMHVW5rbm93bjEeMBwGA1UEAxMVbG9j
+YWxob3N0LmxvY2FsZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCj
+VSo/qOCDsPXQ2HKn2M4ey1FzK6NORkWYefFu5fDFJUKKPXXA8Ey9rPDv+XGGIQKI
+6JlmD2nnjp8Em7+/xa6u4XbFqLR8ycmgldGB7r8RbH3B7KYY3s4AxL9A3/TzHza4
+FJAk2X4LTVWHuX8tB/JyLS6695NSLoI5xKW4maARxwIDAQABoyIwIDAJBgNVHRME
+AjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMA0GCSqGSIb3DQEBBQUAA4GBAFsexncH
+xxTjk9YMoPpjjU0t/UgzjBLEruIIQQ/EtcZIOEqNCDwpzfgY/x7GVCy8VjLISgzK
+xJsNv75F/vP8a4eaeTRJmrvVcWUZJu6r/A8WNwJVYUvXhy2+jbfdp/UMlRg+ODw7
+GMU9ILQW4LGJnTtJKrlVrcQqzw6IZRduEE65
+-----END CERTIFICATE-----
diff --git a/qpid/java/test-profiles/test_resources/ssl/java_broker.req b/qpid/java/test-profiles/test_resources/ssl/java_broker.req
new file mode 100644
index 0000000000..05fc8b0eda
--- /dev/null
+++ b/qpid/java/test-profiles/test_resources/ssl/java_broker.req
@@ -0,0 +1,10 @@
+-----BEGIN NEW CERTIFICATE REQUEST-----
+MIIBujCCASMCAQAwejEQMA4GA1UEBhMHVW5rbm93bjEQMA4GA1UECBMHVW5rbm93bjEQMA4GA1UE
+BxMHVW5rbm93bjEQMA4GA1UEChMHVW5rbm93bjEQMA4GA1UECxMHVW5rbm93bjEeMBwGA1UEAxMV
+bG9jYWxob3N0LmxvY2FsZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjVSo/qOCD
+sPXQ2HKn2M4ey1FzK6NORkWYefFu5fDFJUKKPXXA8Ey9rPDv+XGGIQKI6JlmD2nnjp8Em7+/xa6u
+4XbFqLR8ycmgldGB7r8RbH3B7KYY3s4AxL9A3/TzHza4FJAk2X4LTVWHuX8tB/JyLS6695NSLoI5
+xKW4maARxwIDAQABoAAwDQYJKoZIhvcNAQEFBQADgYEAjXXfPRv7xQYY3R8lZ78/0gbXZ35Lq/1h
+6sxShXfqXxFXE8oP4uGLTlsnSvfsHQL60ihKP3V+nv/zIxNudAsrM57x70owUWyp/bm0XXD89X0T
+zEBP9OQexDTwC2r/8gvYMi++022LMTluEPw29bCsp6usuKh61eLmekprpNlhs5M=
+-----END NEW CERTIFICATE REQUEST-----
diff --git a/qpid/java/test-profiles/test_resources/ssl/java_broker_keystore.jks b/qpid/java/test-profiles/test_resources/ssl/java_broker_keystore.jks
new file mode 100644
index 0000000000..4c4449e20d
--- /dev/null
+++ b/qpid/java/test-profiles/test_resources/ssl/java_broker_keystore.jks
Binary files differ
diff --git a/qpid/java/test-profiles/test_resources/ssl/keystore.jks b/qpid/java/test-profiles/test_resources/ssl/java_client_keystore.jks
index e3a850a248..e3a850a248 100644
--- a/qpid/java/test-profiles/test_resources/ssl/keystore.jks
+++ b/qpid/java/test-profiles/test_resources/ssl/java_client_keystore.jks
Binary files differ
diff --git a/qpid/java/test-profiles/test_resources/ssl/certstore.jks b/qpid/java/test-profiles/test_resources/ssl/java_client_truststore.jks
index 2af95f21f8..2af95f21f8 100644
--- a/qpid/java/test-profiles/test_resources/ssl/certstore.jks
+++ b/qpid/java/test-profiles/test_resources/ssl/java_client_truststore.jks
Binary files differ
diff --git a/qpid/java/test-profiles/testprofile.defaults b/qpid/java/test-profiles/testprofile.defaults
index 35429d3fed..151e904930 100644
--- a/qpid/java/test-profiles/testprofile.defaults
+++ b/qpid/java/test-profiles/testprofile.defaults
@@ -20,7 +20,7 @@ java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFac
java.naming.provider.url=${test.profiles}/test-provider.properties
broker.clean=${test.profiles}/clean-dir ${build.data} ${project.root}/build/work
-broker.ready=Listening on TCP port
+broker.ready=Listening on TCP
broker.config=${project.root}/build/etc/config-systests.xml
messagestore.class.name=org.apache.qpid.server.store.MemoryMessageStore
broker.protocol.excludes=