|
15 | 15 |
|
16 | 16 | package com.rabbitmq.perf; |
17 | 17 |
|
| 18 | +import java.security.NoSuchAlgorithmException; |
18 | 19 | import java.text.SimpleDateFormat; |
19 | | -import java.util.Arrays; |
20 | 20 | import java.util.Calendar; |
21 | 21 | import java.util.Collections; |
22 | 22 | import java.util.List; |
| 23 | +import java.util.Properties; |
23 | 24 |
|
24 | 25 | import org.apache.commons.cli.CommandLine; |
25 | 26 | import org.apache.commons.cli.CommandLineParser; |
|
30 | 31 | import org.apache.commons.cli.ParseException; |
31 | 32 |
|
32 | 33 | import com.rabbitmq.client.ConnectionFactory; |
| 34 | +import org.slf4j.Logger; |
| 35 | +import org.slf4j.LoggerFactory; |
| 36 | + |
| 37 | +import javax.net.ssl.SSLContext; |
33 | 38 |
|
34 | 39 | import static java.util.Arrays.asList; |
35 | 40 |
|
36 | 41 | public class PerfTest { |
37 | 42 |
|
| 43 | + private static final Logger LOGGER = LoggerFactory.getLogger(PerfTest.class); |
| 44 | + |
38 | 45 | public static void main(String[] args) { |
39 | 46 | Options options = getOptions(); |
40 | 47 | CommandLineParser parser = new GnuParser(); |
@@ -100,7 +107,12 @@ public static void main(String[] args) { |
100 | 107 | flags.contains("immediate")), |
101 | 108 | confirm != -1); |
102 | 109 |
|
| 110 | + SSLContext sslContext = getSslContextIfNecessary(cmd, System.getProperties()); |
| 111 | + |
103 | 112 | ConnectionFactory factory = new ConnectionFactory(); |
| 113 | + if (sslContext != null) { |
| 114 | + factory.useSslProtocol(sslContext); |
| 115 | + } |
104 | 116 | factory.setShutdownTimeout(0); // So we still shut down even with slow consumers |
105 | 117 | factory.setUri(uris.get(0)); |
106 | 118 | factory.setRequestedFrameMax(frameMax); |
@@ -150,6 +162,26 @@ public static void main(String[] args) { |
150 | 162 | } |
151 | 163 | } |
152 | 164 |
|
| 165 | + private static SSLContext getSslContextIfNecessary(CommandLine cmd, Properties systemProperties) throws NoSuchAlgorithmException { |
| 166 | + SSLContext sslContext = null; |
| 167 | + if (cmd.hasOption("useDefaultSslContext")) { |
| 168 | + LOGGER.info("Using default SSL context as per command line option"); |
| 169 | + sslContext = SSLContext.getDefault(); |
| 170 | + } |
| 171 | + for (String propertyName : systemProperties.stringPropertyNames()) { |
| 172 | + if (propertyName != null && isPropertyTlsRelated(propertyName)) { |
| 173 | + LOGGER.info("TLS related system properties detected, using default SSL context"); |
| 174 | + sslContext = SSLContext.getDefault(); |
| 175 | + break; |
| 176 | + } |
| 177 | + } |
| 178 | + return sslContext; |
| 179 | + } |
| 180 | + |
| 181 | + private static boolean isPropertyTlsRelated(String propertyName) { |
| 182 | + return propertyName.startsWith("javax.net.ssl") || propertyName.startsWith("jdk.tls"); |
| 183 | + } |
| 184 | + |
153 | 185 | private static void usage(Options options) { |
154 | 186 | HelpFormatter formatter = new HelpFormatter(); |
155 | 187 | formatter.printHelp("<program>", options); |
@@ -192,7 +224,7 @@ private static Options getOptions() { |
192 | 224 | options.addOption(new Option("p", "predeclared", false,"allow use of predeclared objects")); |
193 | 225 | options.addOption(new Option("B", "body", true, "comma-separated list of files to use in message bodies")); |
194 | 226 | options.addOption(new Option("T", "bodyContenType", true, "body content-type")); |
195 | | - |
| 227 | + options.addOption(new Option("useDefaultSslContext", "useDefaultSslContext", false,"use JVM default SSL context")); |
196 | 228 | return options; |
197 | 229 | } |
198 | 230 |
|
|
0 commit comments