powered by Jive Software

Custom IQ Extension from SessionListener

Hi,

I am trying to write a plugin that will send a custom IQ to a given user when a user session is started.

I have implemented a Plugin class that starts ok, and created a SessionEventListener that also receives sessionCreated(Session session)

events correctly.

My problem is when I am trying to route my custom IQ

I build my IQ like this :

public void sessionCreated(Session session) {

final SessionStateIQ sessionStateIQ = new SessionStateIQ(session.getAddress().toBareJID(), session.getStatus());

sessionStateIQ.setType(IQ.Type.set);

JID jid = new JID(getRecipientJID());

sessionStateIQ.setTo(jid);

sessionStateIQ.setFrom(getServerJID());

iqRouter.route(sessionStateIQ);

}

And the extension of IQ i am using is :

private class SessionStateIQ extends IQ{

    String sessionUserJID;
    int status;
   
    SessionStateIQ(String sessionUserJID , int status){
        super();
        this.sessionUserJID = sessionUserJID;
        this.status = status;
        Element child = buildChildElement();
        this.setChildElement(child);
    }
   

    private Element buildChildElement(){
        DocumentFactory docFactory = DocumentFactory.getInstance();
        Element child = docFactory.createElement("sess", "bar:sess");
        child.addAttribute("user", sessionUserJID);
        child.addAttribute("status", ""+status);
        return child;
    }
}

I have also created a PacketExtension class like this (probably that I don’t register it properly … ):

public class SessionStatePacketExtension extends PacketExtension{

public final static String ELEMENT_NAME="sess";
public final static String NAMESPACE= "bar:sess";

static{
    SessionStatePacketExtension.registeredExtensions.put(QName.get(ELEMENT_NAME, NAMESPACE), SessionStatePacketExtension.class);
}

public SessionStatePacketExtension(Element element) {
    super(element);
    // TODO Auto-generated constructor stub
}

}

The xml of my IQ before being routed is :

The error I get in the console is :

org.jivesoftware.openfire.PacketException: Cannot route packet of type IQ or Presence to bare JID:





On the smack side I also registered the corresponding IQProvier and IQ extension and I’m fairly at eease with that part. My real problem is on the Openfire plugin side as far as I can tell …

Can someone point me to what I am doig wrong ?I’m pretty sure it has to do with the packet extension not being registered properly but I can’t find the excact thing I’m doing wrong.

Many thanks for your help

Cherrs,

Alex