Skip to content

Instantly share code, notes, and snippets.

@kitplummer
Created October 26, 2009 15:38
Show Gist options
  • Select an option

  • Save kitplummer/218743 to your computer and use it in GitHub Desktop.

Select an option

Save kitplummer/218743 to your computer and use it in GitHub Desktop.
Example showing Smack PacketExtension
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