11/*******************************************************************************
2- * Copyright (c) 2009, 2016 IBM Corp.
2+ * Copyright (c) 2009, 2018 IBM Corp.
33 *
44 * All rights reserved. This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License v1.0
1111 * http://www.eclipse.org/org/documents/edl-v10.php.
1212 *
1313 * Contributors:
14- * Dave Locke - initial API and implementation and/or initial documentation
15- * Ian Craggs - MQTT 3.1.1 support
16- * Ian Craggs - per subscription message handlers (bug 466579)
17- * Ian Craggs - ack control (bug 472172)
18- * James Sutton - Bug 459142 - WebSocket support for the Java client.
19- * James Sutton - Automatic Reconnect & Offline Buffering.
14+ * James Sutton - initial API and implementation and/or initial documentation
2015 */
2116
2217package org .eclipse .paho .mqttv5 .client ;
@@ -1107,7 +1102,6 @@ public IMqttToken subscribe(MqttSubscription[] subscriptions) throws MqttExcepti
11071102 @ Override
11081103 public IMqttToken subscribe (MqttSubscription [] subscriptions , Object userContext , MqttActionListener callback ,
11091104 MqttProperties subscriptionProperties ) throws MqttException {
1110- final String methodName = "subscribe" ;
11111105
11121106 // remove any message handlers for individual topics and validate Topics
11131107 for (int i = 0 ; i < subscriptions .length ; ++i ) {
@@ -1117,7 +1111,14 @@ public IMqttToken subscribe(MqttSubscription[] subscriptions, Object userContext
11171111 this .mqttConnection .isWildcardSubscriptionsAvailable (),
11181112 this .mqttConnection .isSharedSubscriptionsAvailable ());
11191113 }
1114+
1115+ return this .subscribeBase (subscriptions , userContext , callback , subscriptionProperties );
1116+ }
11201117
1118+ private IMqttToken subscribeBase (MqttSubscription [] subscriptions , Object userContext , MqttActionListener callback ,
1119+ MqttProperties subscriptionProperties ) throws MqttException {
1120+ final String methodName = "subscribe" ;
1121+
11211122 // Only Generate Log string if we are logging at FINE level
11221123 if (log .isLoggable (Logger .FINE )) {
11231124 StringBuffer subs = new StringBuffer ();
@@ -1208,14 +1209,15 @@ public IMqttToken subscribe(MqttSubscription[] subscriptions, IMqttMessageListen
12081209 public IMqttToken subscribe (MqttSubscription [] subscriptions , Object userContext , MqttActionListener callback ,
12091210 IMqttMessageListener [] messageListeners , MqttProperties subscriptionProperties ) throws MqttException {
12101211
1211- IMqttToken token = this .subscribe (subscriptions , userContext , callback , subscriptionProperties );
1212-
12131212 // add message handlers to the list for this client
12141213 for (int i = 0 ; i < subscriptions .length ; ++i ) {
1214+ MqttTopicValidator .validate (subscriptions [i ].getTopic (),
1215+ this .mqttConnection .isWildcardSubscriptionsAvailable (),
1216+ this .mqttConnection .isSharedSubscriptionsAvailable ());
12151217 this .comms .setMessageListener (null , subscriptions [i ].getTopic (), messageListeners [i ]);
12161218 }
1217-
1218- return token ;
1219+
1220+ return this . subscribeBase ( subscriptions , userContext , callback , subscriptionProperties ) ;
12191221 }
12201222
12211223 /*
@@ -1251,15 +1253,16 @@ public IMqttToken subscribe(MqttSubscription[] subscriptions, Object userContext
12511253 subId = this .mqttSession .getNextSubscriptionIdentifier ();
12521254 }
12531255 }
1254-
1255- IMqttToken token = this .subscribe (subscriptions , userContext , callback , subscriptionProperties );
1256-
1256+
12571257 // add message handlers to the list for this client
12581258 for (int i = 0 ; i < subscriptions .length ; ++i ) {
1259+ MqttTopicValidator .validate (subscriptions [i ].getTopic (),
1260+ this .mqttConnection .isWildcardSubscriptionsAvailable (),
1261+ this .mqttConnection .isSharedSubscriptionsAvailable ());
12591262 this .comms .setMessageListener (subId , subscriptions [i ].getTopic (), messageListener );
12601263 }
12611264
1262- return token ;
1265+ return this . subscribeBase ( subscriptions , userContext , callback , subscriptionProperties ) ;
12631266 }
12641267
12651268 /*
0 commit comments