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