You will need a \WEB-INF subdirectory off the directory you are running your client and/or smack api code. (Package names removed for this example)
Create a file call smack.providers with the following xml text:
<?xml version="1.0"?>
query
jabber:iq:time
Time <!Add your package name to the Time class if needed>
Add a Time class:
import org.jivesoftware.smack.packet.*;
/**
*/
public class Time extends IQ {
private String utc = null;
private String display = null;
private String tz = null;
public Time() {
setType(IQ.Type.GET);
}
public String getUtc() {
return utc;
}
public void setUtc(String utc) {
this.utc = utc;
}
public String getTz() {
return tz;
}
public void setTz(String tz) {
this.tz = tz;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public String getQueryXML() {
StringBuffer buf = new StringBuffer();
buf.append("<query xmlns=“jabber:iq:time”>");
if (utc != null) {
if (utc.equals("")) {
buf.append("");
}
else {
buf.append("").append(utc).append("");
}
}
if (tz != null) {
if (tz.equals("")) {
buf.append("");
}
else {
buf.append("").append(tz).append("");
}
}
if (display != null) {
if (display.equals("")) {
buf.append("");
}
else {
buf.append("").append(display).append("") ;
}
}
buf.append("");
return buf.toString();
}
}
Client code to login:
//Create a connection to the XMPP server.
XMPPConnection.DEBUG_ENABLED = true;
XMPPConnection con = new XMPPConnection(“jabber.org”);
con.login(“xxxxx”, “xxxxx”, “xxxxx”);
//Add filter to see everything basically
OrFilter or1 = new OrFilter(new PacketTypeFilter(IQ.class),
new PacketTypeFilter(Message.class));
OrFilter or2 = new OrFilter(new PacketTypeFilter(Presence.class), or1);
con.addPacketListener(this, or2);
Packet pck = new Packet() {
public String toXML() {
return “<iq id=“id1_001” to=“jabber.org” type=“get”><query xmlns=“jabber:iq:time”/>”;
}
};
con.sendPacket(pck);
Listener code to verify Time class is working:
public void processPacket(Packet packet) {
if (packet instanceof Message) {
Message message = (Message) packet;
System.out.println(“Message XML:” + message.toXML());
}
else if (packet instanceof IQ) {
IQ message = (IQ) packet;
System.out.println(“IQ XML:” + message.toXML());
if (message instanceof Time) {
System.out.println(“IQ XML from Time Class:” + message.toXML());
}
}
else if (packet instanceof Presence) {
Presence message = (Presence) packet;
System.out.println(“Presence XML:” + message.toXML());
}
}
Message was edited by: glickster