powered by Jive Software

Dev: added roster items not being cached

Ok, so i have the plugin working so that i can add roster items to users’’ rosters through an unattended http call to the admin port, and it’'s using the rosterprovider methods (as opposed to SQL calls) to do it. All hunky-dory, right? not so much.

now, from the RosterItemProvider.createItem comments we read, “The roster item returned from the method will be cached by Messenger”.

Perhaps this doesn’‘t mean what i think it does, because when i call createItem the roster item get added to the backend storage but any users who are currently logged on don’'t see the changes, even they log off and on, until a server restart (or, presumably, after the caches expire).

Any advice from those who know the jive internals a little (read: infinitely) better than I?

I’‘ll post my code if you like but, it’‘s a fairly unglamorous call too createItem after some pre-existing user checking. Considering i have to do that, i’‘m wondering if i’'m not making too low-level of a call for what i want, but who knows?

Thanks a ton.

jerm

add roster items , you must be send a message to server .

I am write source code of add roster items plugin.

package org.jivesoftware.messenger.plugin.click2show;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.Iterator;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.dom4j.Element;

import org.dom4j.Namespace;

import org.dom4j.QName;

import org.jivesoftware.admin.AuthCheckFilter;

import org.jivesoftware.messenger.XMPPServer;

import org.jivesoftware.messenger.plugin.Click2ShowPlugin;

import org.jivesoftware.util.Log;

import org.jivesoftware.util.ParamUtils;

import org.xmpp.packet.JID;

import org.xmpp.packet.Presence;

import org.xmpp.packet.Roster;

import org.xmpp.packet.IQ;

import org.xmpp.packet.Roster.Subscription;

/**

*/

public class RosterManagerServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

private Click2ShowPlugin plugin;

public void init(ServletConfig servletConfig) throws ServletException {

super.init(servletConfig);

plugin = (Click2ShowPlugin) XMPPServer.getInstance().getPluginManager()

.getPlugin(“click2show”);

// Exclude this servlet from requering the user to login

AuthCheckFilter.addExclude(“click2show/rostermanager”);

}

protected void doGet(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

String type = ParamUtils.getParameter(request,“type”);

String fromjid = ParamUtils.getParameter(request,“fromjid”);

String tojid = ParamUtils.getParameter(request,“tojid”);

response.setContentType(“text/xml”);

PrintWriter out = response.getWriter();

try{

if (“add”.equals(type)) {

// IQRosterHandler.manageRoster java.lang.NullPointerException

// Because of current user is not login to jabber server,

// sessionManager.getSession() is null.

//

// createAddRosterPacket(fromjid, tojid)

// createRemoveRosterPacket(fromjid, tojid)

Roster packet = createAddRosterPacket(fromjid, tojid);

if (plugin.isSession(packet)) {

plugin.PacketRoute(packet);

}

plugin.PacketRoute(createSubscribePresence(fromjid, tojid));

out.write(“1”);

} else if (“delete”.equals(type)) {

Roster packet = createRemoveRosterPacket(fromjid, tojid);

if (plugin.isSession(packet)) {

plugin.PacketRoute(packet);

}

plugin.PacketRoute(createUnsubscribePresence(fromjid, tojid));

out.write(“1”);

} else {

Log.warn("The RosterManager servlet received an invalid request of type: " + type);

out.write("-1");

}

}catch(Exception e){

out.write("-1");

}finally{

out.flush();

}

}

protected void doPost(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

doGet(request, response);

}

public void destroy() {

super.destroy();

// Release the excluded URL

AuthCheckFilter.removeExclude(“click2show/rostermanager”);

}

/**

  • Adding a Roster Item

  • <iq from=’‘juliet@example.com/balcony’’ type=’‘set’’ id=’‘roster_2’’>

*/

private Roster createAddRosterPacket(String fromJid, String toJid) {

RosterExt roster = new RosterExt();

roster.setFrom(fromJid);

roster.setType(IQ.Type.set);

roster.addItem(new JID(toJid), “”);

return roster;

}

/**

  • Deleting a Roster Item

*/

private Roster createRemoveRosterPacket(String fromJid, String toJid) {

RosterExt roster = new RosterExt();

roster.setFrom(fromJid);

roster.setType(IQ.Type.set);

roster.addItem(toJid,Subscription.remove);

return roster;

}

/**

  • 0

*/

private Presence createSubscribePresence(String fromJid, String toJid){

Presence presence = new Presence();

presence.setFrom(fromJid);

presence.setTo(toJid);

presence.setType(Presence.Type.subscribe);

return presence;

}

/**

  • 0

*/

private Presence createUnsubscribePresence(String fromJid, String toJid){

Presence presence = new Presence();

presence.setFrom(fromJid);

presence.setTo(toJid);

presence.setType(Presence.Type.unsubscribe);

return presence;

}

private class RosterExt extends Roster {

public void addItem(JID jid, String group) {

if (jid == null) {

throw new NullPointerException(“JID cannot be null”);

}

Element query = element.element(new QName(“query”, Namespace

.get(“jabber:iq:roster”)));

if (query == null) {

query = element.addElement(“query”, “jabber:iq:roster”);

}

Element item = null;

for (Iterator i = query.elementIterator(“item”); i.hasNext():wink: {

Element el = (Element) i.next();

if (el.attributeValue(“jid”).equals(jid.toString())) {

item = el;

}

}

if (item == null) {

item = query.addElement(“item”);

}

item.addAttribute(“jid”, jid.toBareJID());

item.addAttribute(“name”, jid.getNode());

// Add in groups.

item.addElement(“group”).setText(“not group”);

}

}

}[/code]

Message was edited by:

zhuam

zhuam

zhuam, add and then putting some code examples here without spaces inside the brackets. Will look nicer

wow, nice… certainly more comprehensive than mine, just have to add the ability to plugin the groupname on the url

do you have the rest of the plugin packaging available by any chance?

thanks

jerm

zhuam, add and then putting some

code examples here without spaces inside the

brackets. Will look nicer

Ok, thanks !

hay jerm !

I am already write a roster management plugin of Jive messenger.

I think free the plugin ,

cool, thanks… where can i get it from?