mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
fixing the issues when reading the mqtt receiver configurations.
This commit is contained in:
parent
6bb0387dac
commit
0ef0d871fb
@ -20,6 +20,6 @@
|
||||
<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"/>
|
||||
<mapping customMapping="disable" type="wso2event"/>
|
||||
<to eventAdapterType="secured-ui"/>
|
||||
<to eventAdapterType="secured-websocket"/>
|
||||
</eventPublisher>
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
<property name="username">admin</property>
|
||||
<property name="contentValidator">org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator</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="cleanSession">true</property>
|
||||
</from>
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
<property name="contentTransformer">default</property>
|
||||
<property name="transports">all</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>
|
||||
</from>
|
||||
<mapping customMapping="disable" type="json"/>
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
<property name="username">admin</property>
|
||||
<property name="contentValidator">org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator</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="cleanSession">true</property>
|
||||
</from>
|
||||
|
||||
@ -17,6 +17,8 @@
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -65,7 +67,7 @@ public class MQTTBrokerConnectionConfiguration {
|
||||
|
||||
public MQTTBrokerConnectionConfiguration(String brokerUrl, String brokerUsername, String brokerScopes,
|
||||
String dcrUrl, String cleanSession, int keepAlive,
|
||||
String contentValidatorClassName, String contentTransformerClassName) {
|
||||
String contentValidatorClassName, String contentTransformerClassName) throws InputEventAdapterException {
|
||||
this.brokerUsername = brokerUsername;
|
||||
this.brokerScopes = brokerScopes;
|
||||
if (brokerScopes == null) {
|
||||
|
||||
@ -18,37 +18,28 @@
|
||||
|
||||
package org.wso2.carbon.device.mgt.input.adapter.mqtt.util;
|
||||
|
||||
import org.wso2.carbon.base.ServerConfiguration;
|
||||
import org.wso2.carbon.core.util.Utils;
|
||||
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException;
|
||||
|
||||
public class PropertyUtils {
|
||||
private static final String MQTT_PORT = "\\$\\{mqtt.broker.port\\}";
|
||||
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;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class PropertyUtils {
|
||||
|
||||
//This method is only used if the mb features are within DAS.
|
||||
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"));
|
||||
static String replaceMqttProperty(String urlWithPlaceholders) throws InputEventAdapterException {
|
||||
String regex = "\\$\\{(.*?)\\}";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matchPattern = pattern.matcher(urlWithPlaceholders);
|
||||
while (matchPattern.find()) {
|
||||
String sysPropertyName = matchPattern.group(1);
|
||||
String sysPropertyValue = System.getProperty(sysPropertyName);
|
||||
if (sysPropertyValue != null && !sysPropertyName.isEmpty()) {
|
||||
urlWithPlaceholders = urlWithPlaceholders.replaceAll("\\$\\{(" + sysPropertyName + ")\\}", sysPropertyValue);
|
||||
} else {
|
||||
throw new InputEventAdapterException("System property - " + sysPropertyName
|
||||
+ " is not defined, hence cannot resolve : " + urlWithPlaceholders);
|
||||
}
|
||||
}
|
||||
return urlWithPlaceholders;
|
||||
}
|
||||
|
||||
private static int getPortOffset() {
|
||||
ServerConfiguration carbonConfig = ServerConfiguration.getInstance();
|
||||
String portOffset = System.getProperty("portOffset", carbonConfig.getFirstProperty(CARBON_CONFIG_PORT_OFFSET));
|
||||
try {
|
||||
if (portOffset != null) {
|
||||
return Integer.parseInt(portOffset.trim());
|
||||
} else {
|
||||
return CARBON_DEFAULT_PORT_OFFSET;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return CARBON_DEFAULT_PORT_OFFSET;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user