Created
June 29, 2009 13:55
-
-
Save kitplummer/137619 to your computer and use it in GitHub Desktop.
This file contains 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, "xmppcollab@conference.latitude" ) | |
muc.join("test") | |
println "Connected to Jabber server: ${connection.isConnected()}" | |
// closure-based implementation of the Java Interface. | |
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') | |
} | |
} | |
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