Handling xmpp recipients with invalid JIDs

Shabirmean 9 years ago
parent 25f14be3fb
commit ece41c90c5

@ -70,41 +70,46 @@ public class VirtualFireAlarmXMPPConnector extends XmppConnector {
int indexOfAt = from.indexOf("@"); int indexOfAt = from.indexOf("@");
int indexOfSlash = from.indexOf("/"); int indexOfSlash = from.indexOf("/");
String deviceId = from.substring(0, indexOfAt); if (indexOfAt != -1 && indexOfSlash != -1) {
String owner = from.substring(indexOfSlash + 1, from.length()); String deviceId = from.substring(0, indexOfAt);
String owner = from.substring(indexOfSlash + 1, from.length());
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Received XMPP message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}"); log.debug("Received XMPP message for: {OWNER-" + owner + "} & {DEVICE.ID-" + deviceId + "}");
} }
if (subject != null) { if (subject != null) {
switch (subject) { switch (subject) {
case "PUBLISHER": case "PUBLISHER":
float temperature = Float.parseFloat(message.split(":")[1]); float temperature = Float.parseFloat(message.split(":")[1]);
if (!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) { if (!VirtualFireAlarmServiceUtils.publishToDAS(owner, deviceId, temperature)) {
log.error("XMPP Connector: Publishing data to DAS failed."); log.error("XMPP Connector: Publishing data to DAS failed.");
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("XMPP: Publisher Message [" + message + "] from [" + from + "]"); log.debug("XMPP: Publisher Message [" + message + "] from [" + from + "]");
log.debug("XMPP Connector: Published data to DAS successfully."); log.debug("XMPP Connector: Published data to DAS successfully.");
} }
break; break;
case "CONTROL-REPLY": case "CONTROL-REPLY":
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("XMPP: Reply Message [" + message + "] from [" + from + "]"); log.debug("XMPP: Reply Message [" + message + "] from [" + from + "]");
} }
String tempVal = message.split(":")[1]; String tempVal = message.split(":")[1];
SensorDataManager.getInstance().setSensorRecord(deviceId, SensorDataManager.getInstance().setSensorRecord(deviceId,
VirtualFireAlarmConstants.SENSOR_TEMPERATURE, VirtualFireAlarmConstants.SENSOR_TEMPERATURE,
tempVal, Calendar.getInstance().getTimeInMillis()); tempVal,
break; Calendar.getInstance().getTimeInMillis());
default: break;
if (log.isDebugEnabled()) { default:
log.warn("Unknown XMPP Message [" + message + "] from [" + from + "] received"); if (log.isDebugEnabled()) {
} log.warn("Unknown XMPP Message [" + message + "] from [" + from + "] received");
break; }
break;
}
} }
} else {
log.warn("Received XMPP message from client with unexpected JID [" + from + "].");
} }
} }

Loading…
Cancel
Save