Merge pull request #664 from rasika/master

Fixing java.lang.IllegalStateException: Tenant ID cannot be -1 issue
merge-requests/1/head
Ayyoob Hamza 8 years ago committed by GitHub
commit b71699dd13

@ -18,10 +18,9 @@
package org.wso2.carbon.device.mgt.input.adapter.mqtt; package org.wso2.carbon.device.mgt.input.adapter.mqtt;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.internal.InputAdapterServiceDataHolder;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTAdapterListener; import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTAdapterListener;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTEventAdapterConstants;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTBrokerConnectionConfiguration; import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTBrokerConnectionConfiguration;
import org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTEventAdapterConstants;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapter; import org.wso2.carbon.event.input.adapter.core.InputEventAdapter;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration; import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration;
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterListener; import org.wso2.carbon.event.input.adapter.core.InputEventAdapterListener;
@ -57,11 +56,10 @@ public class MQTTEventAdapter implements InputEventAdapter {
mqttBrokerConnectionConfiguration = new MQTTBrokerConnectionConfiguration(eventAdapterConfiguration mqttBrokerConnectionConfiguration = new MQTTBrokerConnectionConfiguration(eventAdapterConfiguration
,globalProperties); ,globalProperties);
String topic = eventAdapterConfiguration.getProperties().get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_TOPIC); String topic = eventAdapterConfiguration.getProperties().get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_TOPIC);
String tenantDomain = topic.split("/")[0];
mqttAdapterListener = new MQTTAdapterListener(mqttBrokerConnectionConfiguration mqttAdapterListener = new MQTTAdapterListener(mqttBrokerConnectionConfiguration
,topic ,topic
,eventAdapterConfiguration ,eventAdapterConfiguration
,eventAdapterListener, tenantDomain); ,eventAdapterListener);
} catch (Throwable t) { } catch (Throwable t) {
throw new InputEventAdapterException(t.getMessage(), t); throw new InputEventAdapterException(t.getMessage(), t);
} }

@ -76,7 +76,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
public MQTTAdapterListener(MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration, public MQTTAdapterListener(MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration,
String topic, InputEventAdapterConfiguration inputEventAdapterConfiguration, String topic, InputEventAdapterConfiguration inputEventAdapterConfiguration,
InputEventAdapterListener inputEventAdapterListener, String tenantDomain) { InputEventAdapterListener inputEventAdapterListener) {
String mqttClientId = inputEventAdapterConfiguration.getProperties() String mqttClientId = inputEventAdapterConfiguration.getProperties()
.get(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID); .get(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID);
if(mqttClientId == null || mqttClientId.trim().isEmpty()){ if(mqttClientId == null || mqttClientId.trim().isEmpty()){
@ -88,7 +88,7 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
int keepAlive = mqttBrokerConnectionConfiguration.getKeepAlive(); int keepAlive = mqttBrokerConnectionConfiguration.getKeepAlive();
this.topic = PropertyUtils.replaceTenantDomainProperty(topic); this.topic = PropertyUtils.replaceTenantDomainProperty(topic);
this.eventAdapterListener = inputEventAdapterListener; this.eventAdapterListener = inputEventAdapterListener;
this.tenantDomain = tenantDomain; this.tenantDomain = this.topic.split("/")[0];
//SORTING messages until the server fetches them //SORTING messages until the server fetches them
String temp_directory = System.getProperty("java.io.tmpdir"); String temp_directory = System.getProperty("java.io.tmpdir");

Loading…
Cancel
Save