Created
October 26, 2009 15:38
-
-
Save kitplummer/218743 to your computer and use it in GitHub Desktop.
Example showing Smack PacketExtension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import groovy.xml.MarkupBuilder | |
| import org.jivesoftware.smack.packet.PacketExtension | |
| import org.jivesoftware.smack.Chat | |
| import org.jivesoftware.smack.ConnectionConfiguration | |
| import org.jivesoftware.smack.PacketListener | |
| import org.jivesoftware.smack.XMPPConnection | |
| import org.jivesoftware.smack.XMPPException | |
| import org.jivesoftware.smack.filter.PacketFilter | |
| import org.jivesoftware.smack.filter.PacketTypeFilter | |
| import org.jivesoftware.smack.packet.Message | |
| import org.jivesoftware.smackx.muc.MultiUserChat | |
| println "PacketExtension Example Test in Groovy!" | |
| ConnectionConfiguration cc = new ConnectionConfiguration("latitude", | |
| 5222, "latitude") | |
| connection = new XMPPConnection(cc) | |
| println "Connecting to Jabber server and room" | |
| connection.connect() | |
| connection.login("test", "test", "test" + | |
| Long.toHexString(System.currentTimeMillis())) | |
| MultiUserChat muc = new MultiUserChat(connection, "[email protected]" ) | |
| muc.join("test") | |
| println "Connected to Jabber server: ${connection.isConnected()}" | |
| def pe = [ getElementName:{return "CollaborationWrapper"}, | |
| getNamespace:{return "http://generated.data.collaboration.xmpp.absd"}, | |
| toXML:{ | |
| def writer = new StringWriter() | |
| def xml = new MarkupBuilder(writer) | |
| xml.CollaborationWrapper() { | |
| MapGraphic { | |
| Identifier('ID_09c3d0c0-331b-4c73-ac2b-fb097d652f29') | |
| MessageTimestamp('2009-05-11T10:11:38.937-04:00') | |
| Originator('XMPPClient') | |
| Action('ADD') | |
| SymbolCode('SFGPUCV--------') | |
| Geometry { | |
| Point{ | |
| XY('-0.9940357852882704 31.809145129224653') | |
| } | |
| } | |
| UniqueDesignation('Unit') | |
| DTG1('2009-05-11T10:11:38.937-04:00') | |
| } | |
| } | |
| return writer.toString() | |
| } | |
| ] as PacketExtension | |
| println "Element Name: " + pe.getElementName() | |
| println "Namespace: " + pe.getNamespace() | |
| println "XML: " + pe.toXML() | |
| def msgObj = muc.createMessage() | |
| msgObj.setBody("testing 1,2,3") | |
| msgObj.addExtension(pe) | |
| muc.sendMessage(msgObj) | |
| println "Sending message: " + msgObj.toXML() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment