fixing the issues when reading the mqtt receiver configurations.

revert-dabc3590
sinthuja 8 years ago
parent 6bb0387dac
commit 0ef0d871fb

@ -20,6 +20,6 @@
<eventPublisher name="android_sense_publisher" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher"> <eventPublisher name="android_sense_publisher" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
<from streamName="org.wso2.iot.android.sense" version="1.0.0"/> <from streamName="org.wso2.iot.android.sense" version="1.0.0"/>
<mapping customMapping="disable" type="wso2event"/> <mapping customMapping="disable" type="wso2event"/>
<to eventAdapterType="secured-ui"/> <to eventAdapterType="secured-websocket"/>
</eventPublisher> </eventPublisher>

@ -23,7 +23,7 @@
<property name="username">admin</property> <property name="username">admin</property>
<property name="contentValidator">org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator</property> <property name="contentValidator">org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator</property>
<property name="contentTransformer">default</property> <property name="contentTransformer">default</property>
<property name="dcrUrl">https://localhost:${carbon.https.port}/dynamic-client-web/register</property> <property name="dcrUrl">https://${iot.core.host}:${iot.core.https.port}/dynamic-client-web/register</property>
<property name="url">tcp://${mqtt.broker.host}:${mqtt.broker.port}</property> <property name="url">tcp://${mqtt.broker.host}:${mqtt.broker.port}</property>
<property name="cleanSession">true</property> <property name="cleanSession">true</property>
</from> </from>

@ -24,7 +24,7 @@
<property name="contentTransformer">default</property> <property name="contentTransformer">default</property>
<property name="transports">all</property> <property name="transports">all</property>
<property name="maximumTotalHttpConnection">100</property> <property name="maximumTotalHttpConnection">100</property>
<property name="tokenValidationEndpointUrl">https://localhost:${carbon.https.port}/services/OAuth2TokenValidationService</property> <property name="tokenValidationEndpointUrl">https://localhost:${dcr.endpoint.port}/services/OAuth2TokenValidationService</property>
<property name="password">admin</property> <property name="password">admin</property>
</from> </from>
<mapping customMapping="disable" type="json"/> <mapping customMapping="disable" type="json"/>

@ -22,7 +22,7 @@
<property name="username">admin</property> <property name="username">admin</property>
<property name="contentValidator">org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator</property> <property name="contentValidator">org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator</property>
<property name="contentTransformer">default</property> <property name="contentTransformer">default</property>
<property name="dcrUrl">https://localhost:${carbon.https.port}/dynamic-client-web/register</property> <property name="dcrUrl">https://${iot.core.host}:${iot.core.https.port}/dynamic-client-web/register</property>
<property name="url">tcp://${mqtt.broker.host}:${mqtt.broker.port}</property> <property name="url">tcp://${mqtt.broker.host}:${mqtt.broker.port}</property>
<property name="cleanSession">true</property> <property name="cleanSession">true</property>
</from> </from>

@ -17,6 +17,8 @@
*/ */
package org.wso2.carbon.device.mgt.input.adapter.mqtt.util; package org.wso2.carbon.device.mgt.input.adapter.mqtt.util;
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException;
/** /**
* This holds the configurations related to MQTT Broker. * This holds the configurations related to MQTT Broker.
*/ */
@ -65,7 +67,7 @@ public class MQTTBrokerConnectionConfiguration {
public MQTTBrokerConnectionConfiguration(String brokerUrl, String brokerUsername, String brokerScopes, public MQTTBrokerConnectionConfiguration(String brokerUrl, String brokerUsername, String brokerScopes,
String dcrUrl, String cleanSession, int keepAlive, String dcrUrl, String cleanSession, int keepAlive,
String contentValidatorClassName, String contentTransformerClassName) { String contentValidatorClassName, String contentTransformerClassName) throws InputEventAdapterException {
this.brokerUsername = brokerUsername; this.brokerUsername = brokerUsername;
this.brokerScopes = brokerScopes; this.brokerScopes = brokerScopes;
if (brokerScopes == null) { if (brokerScopes == null) {

@ -18,37 +18,28 @@
package org.wso2.carbon.device.mgt.input.adapter.mqtt.util; package org.wso2.carbon.device.mgt.input.adapter.mqtt.util;
import org.wso2.carbon.base.ServerConfiguration; import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException;
import org.wso2.carbon.core.util.Utils;
public class PropertyUtils { import java.util.regex.Matcher;
private static final String MQTT_PORT = "\\$\\{mqtt.broker.port\\}"; import java.util.regex.Pattern;
private static final String MQTT_BROKER_HOST = "\\$\\{mqtt.broker.host\\}";
private static final String CARBON_CONFIG_PORT_OFFSET = "Ports.Offset";
private static final String DEFAULT_CARBON_LOCAL_IP_PROPERTY = "carbon.local.ip";
private static final int CARBON_DEFAULT_PORT_OFFSET = 0;
private static final int DEFAULT_MQTT_PORT = 1886;
//This method is only used if the mb features are within DAS. class PropertyUtils {
public static String replaceMqttProperty (String urlWithPlaceholders) {
urlWithPlaceholders = Utils.replaceSystemProperty(urlWithPlaceholders);
urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_PORT, "" + (DEFAULT_MQTT_PORT + getPortOffset()));
urlWithPlaceholders = urlWithPlaceholders.replaceAll(MQTT_BROKER_HOST, System.getProperty(
DEFAULT_CARBON_LOCAL_IP_PROPERTY, "localhost"));
return urlWithPlaceholders;
}
private static int getPortOffset() { //This method is only used if the mb features are within DAS.
ServerConfiguration carbonConfig = ServerConfiguration.getInstance(); static String replaceMqttProperty(String urlWithPlaceholders) throws InputEventAdapterException {
String portOffset = System.getProperty("portOffset", carbonConfig.getFirstProperty(CARBON_CONFIG_PORT_OFFSET)); String regex = "\\$\\{(.*?)\\}";
try { Pattern pattern = Pattern.compile(regex);
if (portOffset != null) { Matcher matchPattern = pattern.matcher(urlWithPlaceholders);
return Integer.parseInt(portOffset.trim()); while (matchPattern.find()) {
String sysPropertyName = matchPattern.group(1);
String sysPropertyValue = System.getProperty(sysPropertyName);
if (sysPropertyValue != null && !sysPropertyName.isEmpty()) {
urlWithPlaceholders = urlWithPlaceholders.replaceAll("\\$\\{(" + sysPropertyName + ")\\}", sysPropertyValue);
} else { } else {
return CARBON_DEFAULT_PORT_OFFSET; throw new InputEventAdapterException("System property - " + sysPropertyName
+ " is not defined, hence cannot resolve : " + urlWithPlaceholders);
} }
} catch (NumberFormatException e) {
return CARBON_DEFAULT_PORT_OFFSET;
} }
return urlWithPlaceholders;
} }
} }

Loading…
Cancel
Save