Sample packet extension code

Hi All,

Can someone please point me to sample packetextension code? I am working on a simple extension where I can send a URL as value in extension. I am able to send and recieve simple chat messages fine, but when I try to add a packet extension which contains a URL, user gets logged out of Jive server.

Any pointers will be a help.

Code snippet of how I send the message which results in log off

try

{

Chat chat = SOWClient.xmpCon.createChat(this.teamMember.getUser());

Message qceMessage = chat.createMessage();

QuickConfExtension qcePacket = new QuickConfExtension();

qcePacket.SetURL(“http:
www.xyz.com”);

qceMessage.addExtension(qcePacket);

qceMessage.setBody("");

qceMessage.setType(Message.Type.NORMAL);

 qceMessage.setFrom("test@xyz.com");

chat.sendMessage(qceMessage);

}

catch (XMPPException xmpE)

{

}

/code

Code Snippet of my packet extension class

public class QuickConfExtension implements PacketExtension

{

private String url;

public QuickConfExtension()

{

}

public void SetURL(String newVal)

{

url=newVal;

}

public String getNamespace()

{

return “http:
www.xyz.com”;

}

public String getElementName()

{

return “QuickConfExtension”;

}

public String toXML()

{

String tmpXML;

tmpXML="<“getElementName()” xmlns="“getNamespace()”>";

tmpXML*=""*url+"";

return tmpXML;

}

}

/code

Finally I figured it out. I had to download and use tcpTrace to ensure that XML formed was correct. So I did a port trace on server and xml for message I was sending was not well formed. I had to fix “toXML” of my packet extension class

public String toXML()

{

String tmpXML;

tmpXML="<“getElementName()” xmlns="“getNamespace()”"" +">";

tmpXML*=""*url+"";

tmpXML*="</"*getElementName()+">";

return tmpXML;

}

/code

Sort of as a side note if you want these packets to pop up in the debugger correctly and for that matter be recieved correctly you will need to write a PacketExtensionProvider that will take the xml and turn it into the corresponding java object. Didn’'t know if youy had done that already but I figured I would save you some trouble if I could.

Alex

One nifty technique for packet extensions is to write an XML schema for them and use a binding package such as JAXB or XMLBeans to create your classes. There’'s much less to worry about in the toXML() method that way.