Skip to content

Commit

Permalink
Merge pull request #13 from Esri/10.6.0_bug_ei1
Browse files Browse the repository at this point in the history
Fixed Connection Parameter Bug
  • Loading branch information
eironside authored Mar 12, 2020
2 parents bf0b984 + 470095a commit 80c8fd2
Show file tree
Hide file tree
Showing 12 changed files with 772 additions and 785 deletions.
83 changes: 40 additions & 43 deletions mqtt-transport/pom.xml
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.esri.geoevent.parent</groupId>
<artifactId>mqtt</artifactId>
<version>10.4.0</version>
</parent>

<groupId>com.esri.geoevent.transport</groupId>
<artifactId>mqtt-transport</artifactId>
<name>Esri :: GeoEvent :: Transport :: MQTT Transport</name>
<packaging>bundle</packaging>

<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-ContactAddress>${contact.address}</Bundle-ContactAddress>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package/>
<Import-Package>!com.ibm.mqttdirect.modules.local.bindings;*</Import-Package>
<Embed-Dependency>
*;scope=compile|runtime;inline=true
</Embed-Dependency>
<Private-Package>com.esri.geoevent.transport.mqtt</Private-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.esri.geoevent.parent</groupId>
<artifactId>mqtt</artifactId>
<version>10.4.0</version>
</parent>
<groupId>com.esri.geoevent.transport</groupId>
<artifactId>mqtt-transport</artifactId>
<name>Esri :: GeoEvent :: Transport :: MQTT Transport</name>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-ContactAddress>${contact.address}</Bundle-ContactAddress>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package />
<Import-Package>!com.ibm.mqttdirect.modules.local.bindings;*</Import-Package>
<Embed-Dependency> *;scope=compile|runtime;inline=true
</Embed-Dependency>
<Private-Package>com.esri.geoevent.transport.mqtt</Private-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class MqttClientManager
private String topic;
private int qos;
private String username;
private char[] password;
private String password;
private boolean retain;

public MqttClientManager(BundleLogger logger)
Expand Down Expand Up @@ -97,7 +97,8 @@ public void applyProperties(TransportBase transport) throws Exception
String value = (String) transport.getProperty("password").getDecryptedValue();
if (value != null)
{
password = value.toCharArray();
// password = value.toCharArray();
password = value;
}
}

Expand All @@ -114,7 +115,7 @@ public void applyProperties(TransportBase transport) throws Exception
}
else
{
log.warn("Property value for QOS is not valid ({0}). Using default of 0 instead.", value);
log.debug("Property value for QOS is not valid ({0}). Using default of 0 instead.", value);
}
}
catch (NumberFormatException e)
Expand All @@ -137,6 +138,9 @@ public void applyProperties(TransportBase transport) throws Exception
}
}
}

if (log.isTraceEnabled())
log.trace(this.toString());
}

/**
Expand Down Expand Up @@ -167,14 +171,22 @@ public MqttClient createMqttClient(MqttCallback callback) throws MqttException
mqttClient.setCallback(callback);
}

getMqttClientOptions();

// Let the caller connect so they can handle connection failures and reconnects.
return mqttClient;
}

public MqttConnectOptions getMqttClientOptions()
{
MqttConnectOptions options = new MqttConnectOptions();

// Connect with username and password if both are available.
if (username != null && password != null && !username.isEmpty() && password.length > 0)
if (username != null && password != null && !username.isEmpty() && !password.isEmpty())
{
log.trace("Connecting to MQTT Broker using credentials. Username={0}", username);
options.setUserName(username);
options.setPassword(password);
options.setPassword(password.toCharArray());
}

if (ssl)
Expand All @@ -187,9 +199,7 @@ public MqttClient createMqttClient(MqttCallback callback) throws MqttException
}

options.setCleanSession(true);

// Let the caller connect so they can handle connection failures and reconnects.
return mqttClient;
return options;
}

/**
Expand All @@ -215,7 +225,7 @@ public void disconnectMqtt(MqttClient mqttClient)
}
catch (MqttException e)
{
log.error("UNABLE_TO_CLOSE", e);
log.debug("UNABLE_TO_CLOSE", e);
}
finally
{
Expand Down Expand Up @@ -250,22 +260,22 @@ public boolean isTopicValid(String topic)
}
else
{
log.error("GeoEvent TOPIC = {0}. ERROR, the topic must be more than one character long or equal to '/'.", topic);
log.debug("GeoEvent TOPIC = {0}. ERROR, the topic must be more than one character long or equal to '/'.", topic);
}
}
else
{
log.error("GeoEvent TOPIC = {0}. ERROR, cannot contain the '$' symbol.", topic);
log.debug("GeoEvent TOPIC = {0}. ERROR, cannot contain the '$' symbol.", topic);
}
}
else
{
log.error("GeoEvent TOPIC cannot be EMPTY.");
log.debug("GeoEvent TOPIC cannot be EMPTY.");
}
}
else
{
log.error("GeoEvent TOPIC cannot be NULL.");
log.debug("GeoEvent TOPIC cannot be NULL.");
}
return result;
}
Expand Down Expand Up @@ -332,4 +342,10 @@ public boolean isRetain()
{
return retain;
}

@Override
public String toString()
{
return "MqttClientManager [log=" + log + ", port=" + port + ", host=" + host + ", ssl=" + ssl + ", topic=" + topic + ", qos=" + qos + ", username=" + username + ", password=" + password + ", retain=" + retain + "]";
}
}
Loading

0 comments on commit 80c8fd2

Please sign in to comment.