I am new to XMPP and pubsub. I am trying to setup a simple example to familiarize myself with how things work. I was successful in first creating a topic/node called Location and was able to publish. However, I am not able to use the PubSubManager.getNode(“Location”) on additional runs without deleting and recreating Location. Below is code that I have been trying to get working. What am I missing? I am using smack 4.1.4. Thanks in advance for the help.
String host = “192.168.133.187”;
String service = “server.domain.internal”;
int port = 5222;
String username = “user”;
String password = “password”;
AbstractXMPPConnection connection;
Message message = new Message();
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(username, password)
.setServiceName(service)
.setHost(host)
.setPort(port)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.build();
connection = new XMPPTCPConnection(config);
try {
connection.connect();
connection.login(username, password);
} catch (XMPPException e) {
e.printStackTrace();
}
GeolocationElementExtension glee = new GeolocationElementExtension(“geoloc”, “geolocElement”);
String latitude = “35.576375”;
String longitude = “-47.436990”;
glee.setValue(“accuracy”, “0”);
glee.setValue(“alt”, “0”);
glee.setValue(“bearing”,“0”);
glee.setValue(“datum”, “0”);
glee.setValue(“lat”, “” + latitude);
glee.setValue(“lon”, “” + longitude);
glee.setValue(“speed”, “0”);
glee.setValue(“timestamp”, “” + System.currentTimeMillis());
message.addExtension(glee);
message.setTo(service);
message.setFrom("");
//Create the topic
ConfigureForm f = new ConfigureForm(Type.submit);
//Set some params for the topic – according to your requirement
f.setPersistentItems(true);
f.setDeliverPayloads(true);
f.setAccessModel(AccessModel.open);
f.setPublishModel(PublishModel.open);
f.setSubscribe(true);
//Note that you need to set the second parameter for openfire. This is the
//same as the pubsub service name
PubSubManager mgr = new PubSubManager(connection, service);
Node n = mgr.getNode(“Location”); //fail
//mgr.deleteNode(TOPIC);
// Node n = mgr.createNode(TOPIC, f);
SimplePayload payload = new SimplePayload(“location”,“pubsub:test:location”, glee.toXML());
PayloadItem payloadItem = new PayloadItem(null, payload);
((LeafNode) n).publish(payloadItem);
connection.disconnect();
System.out.println(“Disconnected”);