@@ -15,15 +15,39 @@ public class RoundTripTest {
1515 public static String getEnv (String property , String defaultValue ) {
1616 return System .getenv (property ) == null ? defaultValue : System .getenv (property );
1717 }
18+ public static String getEnv (String property ) {
19+ String value = System .getenv (property );
20+ if (value == null ) {
21+ throw new IllegalArgumentException ("Missing env variable " + property );
22+ }
23+ return value ;
24+ }
1825 public static void main (String args []) throws Exception {
1926 String hostname = getEnv ("RABBITMQ_HOSTNAME" , "localhost" );
2027 String port = getEnv ("RABBITMQ_AMQP_PORT" , "5672" );
2128 String scheme = getEnv ("RABBITMQ_AMQP_SCHEME" , "amqp" );
2229 String username = args .length > 0 ? args [0 ] : getEnv ("RABBITMQ_AMQP_USERNAME" , "guest" );
2330 String password = args .length > 1 ? args [1 ] : getEnv ("RABBITMQ_AMQP_PASSWORD" , "guest" );
2431 String uri = scheme + "://" + hostname + ":" + port ;
32+ boolean usemtls = Boolean .parseBoolean (getEnv ("AMQP_USE_MTLS" , "false" ));
33+ String certsLocation = getEnv ("RABBITMQ_CERTS" );
34+
35+ if ("amqps" .equals (scheme )) {
36+ List <String > connectionParams = new ArrayList <String >();
2537
26- System .out .println ("AMQPS Roundrip using uri " + uri );
38+ connectionParams .add ("transport.trustStoreLocation=" + certsLocation + "/truststore.jks" );
39+ connectionParams .add ("transport.trustStorePassword=foobar" );
40+ connectionParams .add ("transport.verifyHost=true" );
41+
42+ if (usemtls ) {
43+ connectionParams .add ("transport.keyStoreLocation=" + certsLocation + "/rabbitmq.jks" );
44+ connectionParams .add ("transport.keyStorePassword=foobar" );
45+ connectionParams .add ("transport.keyAlias=rabbitmq-tls" );
46+ }
47+ if (!connectionParams .isEmpty ()) {
48+ uri += "?" + java .net .URLEncoder .encode (String .join ("&" , connectionParams ));
49+ }
50+ }
2751
2852 Hashtable <Object , Object > env = new Hashtable <>();
2953 env .put (Context .INITIAL_CONTEXT_FACTORY , "org.apache.qpid.jms.jndi.JmsInitialContextFactory" );
0 commit comments