1 11 12 package org.jivesoftware.messenger.handler; 13 14 import org.jivesoftware.messenger.*; 15 import org.jivesoftware.messenger.auth.UnauthorizedException; 16 import org.jivesoftware.messenger.container.BasicModule; 17 import org.jivesoftware.util.LocaleUtils; 18 import org.jivesoftware.util.Log; 19 import org.xmpp.packet.IQ; 20 import org.xmpp.packet.Packet; 21 import org.xmpp.packet.PacketError; 22 23 31 public abstract class IQHandler extends BasicModule implements ChannelHandler { 32 33 protected PacketDeliverer deliverer; 34 protected SessionManager sessionManager; 35 36 41 public IQHandler(String moduleName) { 42 super(moduleName); 43 } 44 45 public void process(Packet packet) throws PacketException { 46 IQ iq = (IQ) packet; 47 try { 48 iq = handleIQ(iq); 49 if (iq != null) { 50 deliverer.deliver(iq); 51 } 52 } 53 catch (org.jivesoftware.messenger.auth.UnauthorizedException e) { 54 if (iq != null) { 55 try { 56 IQ response = IQ.createResultIQ(iq); 57 response.setChildElement(iq.getChildElement().createCopy()); 58 response.setError(PacketError.Condition.not_authorized); 59 Session session = sessionManager.getSession(iq.getFrom()); 60 if (!session.getConnection().isClosed()) { 61 session.process(response); 62 } 63 } 64 catch (Exception de) { 65 Log.error(LocaleUtils.getLocalizedString("admin.error"), de); 66 sessionManager.getSession(iq.getFrom()).getConnection().close(); 67 } 68 } 69 } 70 catch (Exception e) { 71 Log.error(LocaleUtils.getLocalizedString("admin.error"), e); 72 } 73 } 74 75 83 public abstract IQ handleIQ(IQ packet) throws UnauthorizedException; 84 85 92 public abstract IQHandlerInfo getInfo(); 93 94 public void initialize(XMPPServer server) { 95 super.initialize(server); 96 deliverer = server.getPacketDeliverer(); 97 sessionManager = server.getSessionManager(); 98 } 99 } | Popular Tags |