|
|
|
@ -69,7 +69,6 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
|
|
|
|
|
|
|
|
|
|
private InputEventAdapterListener eventAdapterListener = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MQTTAdapterListener(MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration,
|
|
|
|
|
String topic, String mqttClientId,
|
|
|
|
|
InputEventAdapterListener inputEventAdapterListener, int tenantId) {
|
|
|
|
@ -173,8 +172,10 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
|
|
|
|
|
StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
|
|
|
|
|
postMethod.setEntity(requestEntity);
|
|
|
|
|
HttpResponse httpResponse = httpClient.execute(postMethod);
|
|
|
|
|
if (httpResponse != null) {
|
|
|
|
|
String response = MQTTUtil.getResponseString(httpResponse);
|
|
|
|
|
try {
|
|
|
|
|
if (response != null) {
|
|
|
|
|
JSONParser jsonParser = new JSONParser();
|
|
|
|
|
JSONObject jsonPayload = (JSONObject) jsonParser.parse(response);
|
|
|
|
|
String clientId = (String) jsonPayload.get(MQTTEventAdapterConstants.CLIENT_ID);
|
|
|
|
@ -183,6 +184,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
|
|
|
|
|
AccessTokenInfo accessTokenInfo = jwtClientManagerService.getJWTClient().getAccessToken(
|
|
|
|
|
clientId, clientSecret, username, scopes);
|
|
|
|
|
connectionOptions.setUserName(accessTokenInfo.getAccessToken());
|
|
|
|
|
}
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
String msg = "error occurred while parsing client credential payload";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
@ -190,6 +192,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
|
|
|
|
|
String msg = "error occurred while parsing the response from JWT Client";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
|
log.error("Invalid dcrUrl : " + dcrUrlString);
|
|
|
|
|
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | IOException e) {
|
|
|
|
@ -263,10 +266,10 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
int connectionDuration = MQTTEventAdapterConstants.initialReconnectDuration;
|
|
|
|
|
int connectionDuration = MQTTEventAdapterConstants.INITIAL_RECONNECTION_DURATION;
|
|
|
|
|
while (!connectionSucceeded) {
|
|
|
|
|
try {
|
|
|
|
|
connectionDuration = connectionDuration * MQTTEventAdapterConstants.reconnectionProgressionFactor;
|
|
|
|
|
connectionDuration = connectionDuration * MQTTEventAdapterConstants.RECONNECTION_PROGRESS_FACTOR;
|
|
|
|
|
Thread.sleep(connectionDuration);
|
|
|
|
|
startListener();
|
|
|
|
|
connectionSucceeded = true;
|
|
|
|
|