1 11 12 package org.jivesoftware.messenger.transport; 13 14 import org.jivesoftware.messenger.container.BasicModule; 15 import org.jivesoftware.util.LocaleUtils; 16 import org.jivesoftware.util.Log; 17 import org.jivesoftware.messenger.*; 18 import org.jivesoftware.messenger.auth.UnauthorizedException; 19 import org.xmpp.packet.JID; 20 import org.xmpp.packet.Packet; 21 import org.xmpp.packet.PacketError; 22 23 import java.util.Map ; 24 import java.util.concurrent.ConcurrentHashMap ; 25 26 31 public class TransportHandler extends BasicModule implements ChannelHandler { 32 33 private Map <String , Channel> transports = new ConcurrentHashMap <String , Channel>(); 34 35 private PacketDeliverer deliverer; 36 37 public TransportHandler() { 38 super("Transport handler"); 39 } 40 41 public void addTransport(Channel transport) { 42 transports.put(transport.getName(), transport); 43 } 44 45 public void process(Packet packet) throws UnauthorizedException, PacketException { 46 boolean handled = false; 47 String host = packet.getTo().getDomain(); 48 for (Channel channel : transports.values()) { 49 if (channel.getName().equalsIgnoreCase(host)) { 50 channel.add(packet); 51 handled = true; 52 } 53 } 54 if (!handled) { 55 JID recipient = packet.getTo(); 56 JID sender = packet.getFrom(); 57 packet.setError(PacketError.Condition.remote_server_timeout); 58 packet.setFrom(recipient); 59 packet.setTo(sender); 60 try { 61 deliverer.deliver(packet); 62 } 63 catch (PacketException e) { 64 Log.error(LocaleUtils.getLocalizedString("admin.error"), e); 65 } 66 } 67 } 68 69 public void initialize(XMPPServer server) { 70 super.initialize(server); 71 deliverer = server.getPacketDeliverer(); 72 } 73 } | Popular Tags |