Setting the MQTT Queue URL to localhost by default

Shabirmean 9 years ago
parent 4717c578ea
commit b4bf46878d

@ -47,7 +47,6 @@ public class DigitalDisplayMqttCommunicationHandler extends MQTTTransportHandler
public void run() {
while (!isConnected()) {
try {
log.info("Trying to Connect..");
connectToQueue();
subscribeToQueue();

@ -28,6 +28,8 @@ public class MqttConfig {
private boolean isEnabled;
private static final String MQTT_QUEUE_CONFIG_NAME = "MQTT";
private static final String LOCALHOST = "localhost";
private static final String PORT_OFFSET_PROPERTY = "portOffset";
private ControlQueue mqttControlQueue;
@ -58,14 +60,29 @@ public class MqttConfig {
}
private MqttConfig() {
mqttControlQueue = DeviceManagementConfigurationManager.getInstance().getControlQueue(
MQTT_QUEUE_CONFIG_NAME);
mqttQueueEndpoint = mqttControlQueue.getServerURL() + ":" + mqttControlQueue.getPort();
mqttControlQueue = DeviceManagementConfigurationManager.getInstance().getControlQueue(MQTT_QUEUE_CONFIG_NAME);
int portOffset = Integer.parseInt(System.getProperty(PORT_OFFSET_PROPERTY));
String brokerURL = mqttControlQueue.getServerURL();
if (portOffset != 0 && brokerURL.contains(LOCALHOST)) {
// if using the internal MB (meaning URL is localhost and there is a portOffset)
// then increment port accordingly
int mqttPort = mqttControlQueue.getPort();
mqttPort = mqttPort + portOffset;
mqttQueueEndpoint = mqttControlQueue.getServerURL() + ":" + mqttPort;
} else {
mqttQueueEndpoint = mqttControlQueue.getServerURL() + ":" + mqttControlQueue.getPort();
}
mqttQueueUsername = mqttControlQueue.getUsername();
mqttQueuePassword = mqttControlQueue.getPassword();
isEnabled = mqttControlQueue.isEnabled();
}
public static MqttConfig getInstance() {
return mqttConfig;
}

@ -33,6 +33,14 @@ import java.util.Map;
public class ZipUtil {
private static final String LOCAL_BIND_ADDRESS_PROPERTY = "carbon.local.ip";
private static final String HTTPS_PORT_PROPERTY = "httpsPort";
private static final String HTTP_PORT_PROPERTY = "httpPort";
private static final String LOCALHOST = "localhost";
private static final String HTTPS_PROTOCOL_APPENDER = "https://";
private static final String HTTP_PROTOCOL_APPENDER = "http://";
public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType,
String deviceId, String deviceName, String token,
String refreshToken)
@ -48,12 +56,12 @@ public class ZipUtil {
String templateSketchPath = sketchFolder + sep + deviceType;
String serverName = DeviceManagementConfigurationManager.getInstance().getDeviceManagementServerInfo().getName();
String iotServerIP = System.getProperty("carbon.local.ip"); // bind.address
String httpsServerPort = System.getProperty("httpsPort");
String httpServerPort = System.getProperty("httpPort");
String iotServerIP = System.getProperty(LOCAL_BIND_ADDRESS_PROPERTY); // bind.address
String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY);
String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY);
String httpsServerEP = "https://" + iotServerIP + ":" + httpsServerPort;
String httpServerEP = "http://" + iotServerIP + ":" + httpServerPort;
String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort;
String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort;
String apimHost =
DeviceManagementConfigurationManager.getInstance().getDeviceCloudMgtConfig().getApiManager()
@ -65,6 +73,11 @@ public class ZipUtil {
String apimEndpoint = apimHost + ":" + apimGatewayPort;
String mqttEndpoint = MqttConfig.getInstance().getMqttQueueEndpoint();
if (mqttEndpoint.contains(LOCALHOST)) {
mqttEndpoint = mqttEndpoint.replace(LOCALHOST, iotServerIP);
}
String xmppEndpoint = XmppConfig.getInstance().getXmppEndpoint();
int indexOfChar = xmppEndpoint.lastIndexOf(":");

@ -32,7 +32,8 @@
<Enabled>true</Enabled>
<ControlClass>org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttControlPublisher</ControlClass>
<Protocol>MQTT</Protocol>
<ServerURL>tcp://204.232.188.214</ServerURL>
<!--<ServerURL>tcp://204.232.188.214</ServerURL>-->
<ServerURL>tcp://localhost</ServerURL>
<Port>1883</Port>
<Username>.</Username>
<Password>.</Password>
@ -58,9 +59,9 @@
<ApiManager>
<Enabled>true</Enabled>
<AccessTokenURL>https://localhost:9443/oauth2/token</AccessTokenURL>
<ServerURL>http://localhost</ServerURL>
<ServerPort>9763</ServerPort>
<GatewayPort>8280</GatewayPort>
<ServerURL>https://localhost</ServerURL>
<ServerPort>9443</ServerPort>
<GatewayPort>8243</GatewayPort>
<LoginURL>/api-store/site/blocks/user/login/ajax/login.jag</LoginURL>
<SubscriptionListURL>/api-store/site/blocks/subscription/subscription-list/ajax/subscription-list.jag</SubscriptionListURL>
<Username>admin</Username>

Loading…
Cancel
Save