Search in sources :

Example 51 with Enumeration

use of java.util.Enumeration in project Openfire by igniterealtime.

the class JiveBeanInfo method getBeanDescriptor.

// BeanInfo Interface
@Override
public BeanDescriptor getBeanDescriptor() {
    BeanDescriptor descriptor = new BeanDescriptor(getBeanClass());
    try {
        // Attempt to load the displayName and shortDescription explicitly.
        String displayName = bundle.getString("displayName");
        if (displayName != null) {
            descriptor.setDisplayName(displayName);
        }
        String shortDescription = bundle.getString("shortDescription");
        if (shortDescription != null) {
            descriptor.setShortDescription(shortDescription);
        }
        // Add any other properties that are specified.
        Enumeration enumeration = bundle.getKeys();
        while (enumeration.hasMoreElements()) {
            String key = (String) enumeration.nextElement();
            String value = bundle.getString(key);
            if (value != null) {
                descriptor.setValue(key, value);
            }
        }
    } catch (Exception e) {
    // Ignore any exceptions. We may get some if we try to load a
    // a property that doesn't appear in the resource bundle.
    }
    return descriptor;
}
Also used : Enumeration(java.util.Enumeration) BeanDescriptor(java.beans.BeanDescriptor) IntrospectionException(java.beans.IntrospectionException)

Example 52 with Enumeration

use of java.util.Enumeration in project Openfire by igniterealtime.

the class ModuleLoader method loadNonBridgeModule.

private void loadNonBridgeModule(String dirEntry) throws IOException {
    JarFile jarFile = new JarFile(dirEntry);
    Enumeration entries = jarFile.entries();
    if (entries == null) {
        Logger.println("No entries in jarFile:  " + dirEntry);
        return;
    }
    while (entries.hasMoreElements()) {
        JarEntry jarEntry = (JarEntry) entries.nextElement();
        String className = jarEntry.getName();
        int ix;
        if ((ix = className.indexOf(".class")) < 0) {
            if (Logger.logLevel >= Logger.LOG_INFO) {
                Logger.println("Skipping non-class entry in jarFile:  " + className);
            }
            continue;
        }
        className = className.replaceAll(".class", "");
        className = className.replaceAll("/", ".");
        try {
            if (Logger.logLevel >= Logger.LOG_INFO) {
                Logger.println("Looking for class '" + className + "'");
            }
            // load the class
            loadClass(className);
        } catch (ClassNotFoundException e) {
            Logger.println("ClassNotFoundException:  '" + className + "'");
        }
    }
}
Also used : Enumeration(java.util.Enumeration) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry)

Example 53 with Enumeration

use of java.util.Enumeration in project Openfire by igniterealtime.

the class IRCListener method updateCommand.

@Override
@SuppressWarnings("unchecked")
protected void updateCommand(InCommand inCommand) {
    Log.debug("IRC: Received incoming command:" + inCommand);
    if (inCommand instanceof CtcpMessage) {
        CtcpMessage cm = (CtcpMessage) inCommand;
        if (cm.getAction().equals("VERSION")) {
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "VERSION", "IMGateway" + getSession().getTransport().getVersionString() + ":Java:-"));
        } else if (cm.getAction().equals("PING")) {
            String timestamp = cm.getMessage();
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "PING", timestamp));
        } else if (cm.getAction().equals("TIME")) {
            Date current = new Date();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZZ");
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "TIME", format.format(current)));
        } else if (cm.getAction().equals("ACTION")) {
            if (cm.isPrivateToUs(getSession().getConnection().getClientState())) {
                getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(cm.getSource().getNick()), "/me " + cm.getMessage());
            } else {
                getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(cm.getDest(), cm.getSource().getNick()), "/me " + cm.getMessage(), Message.Type.groupchat);
            }
        }
    } else if (inCommand instanceof MessageCommand) {
        MessageCommand mc = (MessageCommand) inCommand;
        if (mc.isPrivateToUs(getSession().getConnection().getClientState())) {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(mc.getSource().getNick()), IRCStringUtils.stripControlChars(mc.getMessage()));
        } else {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(mc.getDest(), mc.getSource().getNick()), IRCStringUtils.stripControlChars(mc.getMessage()), Message.Type.groupchat);
        }
    } else if (inCommand instanceof NoticeCommand) {
        NoticeCommand nc = (NoticeCommand) inCommand;
        if (nc.getFrom() != null) {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(nc.getFrom().getNick()), IRCStringUtils.stripControlChars(nc.getNotice()));
        }
    } else if (inCommand instanceof JoinCommand) {
        JoinCommand jc = (JoinCommand) inCommand;
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(jc.getChannel());
            mucSession.getContacts().add(jc.getUser().getNick());
            Presence p = new Presence();
            p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(jc.getChannel(), jc.getUser().getNick()));
            p.setTo(getSession().getJID());
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "member");
            item.addAttribute("role", "participant");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof PartCommand) {
        PartCommand pc = (PartCommand) inCommand;
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(pc.getChannel());
            mucSession.getContacts().remove(pc.getUser().getNick());
            Presence p = new Presence();
            p.setType(Presence.Type.unavailable);
            p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(pc.getChannel(), pc.getUser().getNick()));
            p.setTo(getSession().getJID());
            if (pc.getReason() != null && !pc.getReason().equals("")) {
                p.setStatus(pc.getReason());
            }
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof QuitCommand) {
        QuitCommand qc = (QuitCommand) inCommand;
        for (MUCTransportSession session : getSession().getMUCSessionManager().getSessions()) {
            if (((IRCMUCSession) session).getContacts().contains(qc.getUser().getNick())) {
                ((IRCMUCSession) session).getContacts().remove(qc.getUser().getNick());
                Presence p = new Presence();
                p.setType(Presence.Type.unavailable);
                p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(((IRCMUCSession) session).roomname, qc.getUser().getNick()));
                p.setTo(getSession().getJID());
                if (qc.getReason() != null && !qc.getReason().equals("")) {
                    p.setStatus(qc.getReason());
                }
                Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                Element item = elem.addElement("item");
                item.addAttribute("affiliation", "none");
                item.addAttribute("role", "none");
                getSession().getTransport().sendPacket(p);
            }
        }
    } else if (inCommand instanceof InviteCommand) {
        InviteCommand ic = (InviteCommand) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        Message m = new Message();
        m.setTo(getSession().getJID());
        m.setFrom(mucTransport.convertIDToJID(ic.getChannel(), null));
        Element x = m.addChildElement("x", "http://jabber.org/protocol/muc#user");
        Element invite = x.addElement("invite");
        invite.addAttribute("from", getSession().getTransport().convertIDToJID(ic.getSourceString()).toBareJID());
        getSession().getTransport().sendPacket(m);
    } else if (inCommand instanceof KickCommand) {
        KickCommand kc = (KickCommand) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(kc.getChannel());
            mucSession.getContacts().add(kc.getKicked().getNick());
            Presence p = new Presence();
            p.setType(Presence.Type.unavailable);
            p.setFrom(mucTransport.convertIDToJID(kc.getChannel(), kc.getKicked().getNick()));
            p.setTo(getSession().getJID());
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            Element actor = item.addElement("actor");
            actor.addAttribute("jid", getSession().getTransport().convertIDToJID(kc.getKicker().getNick()).toBareJID());
            Element reason = item.addElement("reason");
            reason.addText(kc.getComment());
            Element status = elem.addElement("status");
            status.addAttribute("code", "307");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
        if (kc.kickedUs(getSession().getConnection().getClientState())) {
            getSession().getMUCSessionManager().removeSession(kc.getChannel());
        }
    } else if (inCommand instanceof ChannelModeCommand) {
    //ChannelModeCommand cmc = (ChannelModeCommand)inCommand;
    // TODO: Fix up martyr to handle this then handle it here
    } else if (inCommand instanceof NickCommand) {
    //NickCommand nc = (NickCommand)inCommand;
    // TODO: Map to MUC event  (someone's nick just changed)
    } else if (inCommand instanceof ModeCommand) {
    //ModeCommand mc = (ModeCommand)inCommand;
    // TODO: Map to MUC event  (your mode just changed)
    } else if (inCommand instanceof TopicCommand) {
        TopicCommand tc = (TopicCommand) inCommand;
        Channel channel = getSession().getConnection().getClientState().getChannel(tc.getChannel());
        if (channel != null) {
            BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
            Message m = new Message();
            m.setType(Message.Type.groupchat);
            m.setTo(getSession().getJID());
            m.setFrom(mucTransport.convertIDToJID(channel.getName(), channel.getTopicAuthor()));
            m.setSubject(net.sf.kraken.util.StringUtils.removeInvalidXMLCharacters(channel.getTopic()));
            mucTransport.sendPacket(m);
        }
    } else if (inCommand instanceof TopicInfoReply) {
        TopicInfoReply tir = (TopicInfoReply) inCommand;
        Channel channel = getSession().getConnection().getClientState().getChannel(tir.getChannel());
        if (channel != null) {
            BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
            Message m = new Message();
            m.setType(Message.Type.groupchat);
            m.setTo(getSession().getJID());
            m.setFrom(mucTransport.convertIDToJID(channel.getName(), channel.getTopicAuthor()));
            m.setSubject(net.sf.kraken.util.StringUtils.removeInvalidXMLCharacters(channel.getTopic()));
            mucTransport.sendPacket(m);
        }
    } else if (inCommand instanceof NamesReply) {
        NamesReply nr = (NamesReply) inCommand;
        String channelName = nr.getChannel();
        List<MUCTransportRoomMember> members = new ArrayList<MUCTransportRoomMember>();
        for (String nick : nr.getNames()) {
            members.add(new MUCTransportRoomMember(getSession().getTransport().getMUCTransport().convertIDToJID(channelName, nick)));
        }
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRoomMembers(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(channelName, null), members);
    } else if (inCommand instanceof NamesEndReply) {
        NamesEndReply ner = (NamesEndReply) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(ner.getChannel());
            mucSession.getContacts().clear();
            Member myMember = null;
            Channel channel = getSession().getConnection().getClientState().getChannel(ner.getChannel());
            if (channel != null) {
                Enumeration members = channel.getMembers();
                while (members.hasMoreElements()) {
                    Member member = (Member) members.nextElement();
                    if (member.getNick().getNick().equals(mucSession.getNickname()) || member.getNick().getNick().equals(getSession().getRegistration().getNickname())) {
                        // Aha, this is us, save for the end.
                        myMember = member;
                        continue;
                    }
                    Presence p = new Presence();
                    p.setTo(getSession().getJID());
                    if (member.hasOps()) {
                        // Moderator.
                        mucSession.getContacts().add(member.getNick().getNick());
                        p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), member.getNick().getNick()));
                        Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                        Element item = elem.addElement("item");
                        item.addAttribute("affiliation", "admin");
                        item.addAttribute("role", "moderator");
                    } else {
                        // Regular participant.
                        mucSession.getContacts().add(member.getNick().getNick());
                        p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), member.getNick().getNick()));
                        Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                        Element item = elem.addElement("item");
                        item.addAttribute("affiliation", "member");
                        item.addAttribute("role", "participant");
                    }
                    mucTransport.sendPacket(p);
                }
            }
            if (myMember != null) {
                Presence p = new Presence();
                p.setTo(getSession().getJID());
                p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), mucSession.getNickname()));
                Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                Element item = elem.addElement("item");
                if (myMember.hasOps()) {
                    item.addAttribute("affiliation", "admin");
                    item.addAttribute("role", "moderator");
                } else {
                    item.addAttribute("affiliation", "member");
                    item.addAttribute("role", "participant");
                }
                Element status = elem.addElement("status");
                status.addAttribute("code", "110");
                mucTransport.sendPacket(p);
            }
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof ListStartReply) {
    // Do nothing.
    } else if (inCommand instanceof ListReply) {
        ListReply lr = (ListReply) inCommand;
        String channelName = lr.getChannel();
        MUCTransportRoom mucRoom = getSession().getTransport().getMUCTransport().getCachedRoom(channelName);
        if (mucRoom == null) {
            mucRoom = new MUCTransportRoom(getSession().getTransport().getMUCTransport().convertIDToJID(channelName, ""), channelName);
        }
        mucRoom.setTopic(lr.getTopic());
        mucRoom.setOccupant_count(lr.getMemberCount());
        getSession().getTransport().getMUCTransport().cacheRoom(mucRoom);
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRoomInfo(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(mucRoom.getName(), null), mucRoom);
    } else if (inCommand instanceof ListEndReply) {
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRooms(getSession().getJID(), getSession().getTransport().getMUCTransport().getCachedRooms());
    } else if (inCommand instanceof IsonCommand) {
        IsonCommand ic = (IsonCommand) inCommand;
        List<String> newNicks = new ArrayList<String>();
        for (String nick : ic.getNicks()) {
            newNicks.add(nick.toLowerCase());
        }
        Log.debug("IRC: Got ISON for " + ic.getDest() + " of: " + ic.getNicks());
        for (TransportBuddy buddy : getSession().getBuddyManager().getBuddies()) {
            if (!newNicks.contains(buddy.getName())) {
                // Previously online nick went offline
                buddy.setPresence(PresenceType.unavailable);
            } else {
                // Previously online nick is still online
                buddy.setPresence(PresenceType.available);
            }
        }
    } else if (inCommand instanceof UnAwayReply) {
        getSession().setPresence(PresenceType.available);
    } else if (inCommand instanceof NowAwayReply) {
        getSession().setPresence(PresenceType.away);
    } else if (inCommand instanceof AwayReply) {
        AwayReply ar = (AwayReply) inCommand;
        getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(ar.getNick()), LocaleUtils.getLocalizedString("gateway.irc.autoreply", "kraken") + " " + ar.getMessage());
    }
}
Also used : CtcpNotice(f00f.net.irc.martyr.commands.CtcpNotice) Message(org.xmpp.packet.Message) CtcpMessage(f00f.net.irc.martyr.commands.CtcpMessage) JoinCommand(f00f.net.irc.martyr.commands.JoinCommand) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException) NickCommand(f00f.net.irc.martyr.commands.NickCommand) UnAwayReply(f00f.net.irc.martyr.replies.UnAwayReply) AwayReply(f00f.net.irc.martyr.replies.AwayReply) NowAwayReply(f00f.net.irc.martyr.replies.NowAwayReply) UnAwayReply(f00f.net.irc.martyr.replies.UnAwayReply) InviteCommand(f00f.net.irc.martyr.commands.InviteCommand) TopicInfoReply(f00f.net.irc.martyr.replies.TopicInfoReply) PartCommand(f00f.net.irc.martyr.commands.PartCommand) ListStartReply(f00f.net.irc.martyr.replies.ListStartReply) NamesReply(f00f.net.irc.martyr.replies.NamesReply) KickCommand(f00f.net.irc.martyr.commands.KickCommand) Presence(org.xmpp.packet.Presence) ModeCommand(f00f.net.irc.martyr.commands.ModeCommand) ChannelModeCommand(f00f.net.irc.martyr.commands.ChannelModeCommand) ArrayList(java.util.ArrayList) List(java.util.List) MUCTransportRoomMember(net.sf.kraken.muc.MUCTransportRoomMember) Member(f00f.net.irc.martyr.clientstate.Member) NamesEndReply(f00f.net.irc.martyr.replies.NamesEndReply) BaseMUCTransport(net.sf.kraken.muc.BaseMUCTransport) IsonCommand(f00f.net.irc.martyr.commands.IsonCommand) MUCTransportSession(net.sf.kraken.muc.MUCTransportSession) Enumeration(java.util.Enumeration) TopicCommand(f00f.net.irc.martyr.commands.TopicCommand) NowAwayReply(f00f.net.irc.martyr.replies.NowAwayReply) MessageCommand(f00f.net.irc.martyr.commands.MessageCommand) Channel(f00f.net.irc.martyr.clientstate.Channel) TransportBuddy(net.sf.kraken.roster.TransportBuddy) CtcpMessage(f00f.net.irc.martyr.commands.CtcpMessage) NoticeCommand(f00f.net.irc.martyr.commands.NoticeCommand) MUCTransportRoomMember(net.sf.kraken.muc.MUCTransportRoomMember) ListEndReply(f00f.net.irc.martyr.replies.ListEndReply) Date(java.util.Date) ListReply(f00f.net.irc.martyr.replies.ListReply) MUCTransportRoom(net.sf.kraken.muc.MUCTransportRoom) QuitCommand(f00f.net.irc.martyr.commands.QuitCommand) ChannelModeCommand(f00f.net.irc.martyr.commands.ChannelModeCommand) SimpleDateFormat(java.text.SimpleDateFormat)

Example 54 with Enumeration

use of java.util.Enumeration in project Smack by igniterealtime.

the class ICEResolver method resolve.

/**
     * Resolve the IP and obtain a valid transport method.
     * @throws SmackException 
     * @throws InterruptedException 
     */
@Override
public synchronized void resolve(JingleSession session) throws XMPPException, SmackException, InterruptedException {
    this.setResolveInit();
    for (TransportCandidate candidate : this.getCandidatesList()) {
        if (candidate instanceof ICECandidate) {
            ICECandidate iceCandidate = (ICECandidate) candidate;
            iceCandidate.removeCandidateEcho();
        }
    }
    this.clear();
    // Create a transport candidate for each ICE negotiator candidate we have.
    ICENegociator iceNegociator = negociatorsMap.get(server);
    for (Candidate candidate : iceNegociator.getSortedCandidates()) try {
        Candidate.CandidateType type = candidate.getCandidateType();
        ICECandidate.Type iceType = ICECandidate.Type.local;
        if (type.equals(Candidate.CandidateType.ServerReflexive))
            iceType = ICECandidate.Type.srflx;
        else if (type.equals(Candidate.CandidateType.PeerReflexive))
            iceType = ICECandidate.Type.prflx;
        else if (type.equals(Candidate.CandidateType.Relayed))
            iceType = ICECandidate.Type.relay;
        else
            iceType = ICECandidate.Type.host;
        // JBW/GW - 17JUL08: Figure out the zero-based NIC number for this candidate.
        short nicNum = 0;
        try {
            Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
            short i = 0;
            NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
            while (nics.hasMoreElements()) {
                NetworkInterface checkNIC = nics.nextElement();
                if (checkNIC.equals(nic)) {
                    nicNum = i;
                    break;
                }
                i++;
            }
        } catch (SocketException e1) {
            LOGGER.log(Level.WARNING, "exeption", e1);
        }
        TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(Math.abs(random.nextLong())), candidate.getPort(), "1", candidate.getPriority(), iceType);
        transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
        transportCandidate.setPort(getFreePort());
        try {
            transportCandidate.addCandidateEcho(session);
        } catch (SocketException e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
        this.addCandidate(transportCandidate);
        LOGGER.fine("Candidate addr: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " Priority:" + candidate.getPriority());
    } catch (UtilityException e) {
        LOGGER.log(Level.WARNING, "exception", e);
    } catch (UnknownHostException e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
    if (RTPBridge.serviceAvailable(connection)) {
        //            try {
        String localIp;
        int network;
        // JBW/GW - 17JUL08: ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now the API doesn't exist in JSTUN 1.7.1
        //                if (iceNegociator.getPublicCandidate() != null) {
        //                    localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress();
        //                    network = iceNegociator.getPublicCandidate().getNetwork();
        //                }
        //                else {
        {
            localIp = BridgedResolver.getLocalHost();
            network = 0;
        }
        sid = Math.abs(random.nextLong());
        RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid));
        TransportCandidate localCandidate = new ICECandidate(rtpBridge.getIp(), 1, network, String.valueOf(Math.abs(random.nextLong())), rtpBridge.getPortA(), "1", 0, ICECandidate.Type.relay);
        localCandidate.setLocalIp(localIp);
        TransportCandidate remoteCandidate = new ICECandidate(rtpBridge.getIp(), 1, network, String.valueOf(Math.abs(random.nextLong())), rtpBridge.getPortB(), "1", 0, ICECandidate.Type.relay);
        remoteCandidate.setLocalIp(localIp);
        localCandidate.setSymmetric(remoteCandidate);
        remoteCandidate.setSymmetric(localCandidate);
        localCandidate.setPassword(rtpBridge.getPass());
        remoteCandidate.setPassword(rtpBridge.getPass());
        localCandidate.setSessionId(rtpBridge.getSid());
        remoteCandidate.setSessionId(rtpBridge.getSid());
        localCandidate.setConnection(this.connection);
        remoteCandidate.setConnection(this.connection);
        addCandidate(localCandidate);
        //          if (iceNegociator.getPublicCandidate() == null) {
        if (true) {
            String publicIp = RTPBridge.getPublicIP(connection);
            if (publicIp != null && !publicIp.equals("")) {
                Enumeration<NetworkInterface> ifaces = null;
                try {
                    ifaces = NetworkInterface.getNetworkInterfaces();
                } catch (SocketException e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
                // If detect this address in local machine, don't use it.
                boolean found = false;
                while (ifaces.hasMoreElements() && !false) {
                    NetworkInterface iface = ifaces.nextElement();
                    Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
                    while (iaddresses.hasMoreElements()) {
                        InetAddress iaddress = iaddresses.nextElement();
                        if (iaddress.getHostAddress().indexOf(publicIp) > -1) {
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    try {
                        TransportCandidate publicCandidate = new ICECandidate(publicIp, 1, 0, String.valueOf(Math.abs(random.nextLong())), getFreePort(), "1", 0, ICECandidate.Type.srflx);
                        publicCandidate.setLocalIp(InetAddress.getLocalHost().getHostAddress());
                        try {
                            publicCandidate.addCandidateEcho(session);
                        } catch (SocketException e) {
                            LOGGER.log(Level.WARNING, "exception", e);
                        }
                        addCandidate(publicCandidate);
                    } catch (UnknownHostException e) {
                        LOGGER.log(Level.WARNING, "exception", e);
                    }
                }
            }
        }
    }
    this.setResolveEnd();
}
Also used : Candidate(de.javawi.jstun.test.demo.ice.Candidate) SocketException(java.net.SocketException) Enumeration(java.util.Enumeration) UnknownHostException(java.net.UnknownHostException) NetworkInterface(java.net.NetworkInterface) UtilityException(de.javawi.jstun.util.UtilityException) ICENegociator(de.javawi.jstun.test.demo.ice.ICENegociator) InetAddress(java.net.InetAddress)

Example 55 with Enumeration

use of java.util.Enumeration in project Openfire by igniterealtime.

the class AdminConsole method load.

private static void load() {
    // Load the core model as the admin-sidebar.xml file from the classpath.
    InputStream in = ClassUtils.getResourceAsStream("/admin-sidebar.xml");
    if (in == null) {
        Log.error("Failed to load admin-sidebar.xml file from Openfire classes - admin " + "console will not work correctly.");
        return;
    }
    try {
        SAXReader saxReader = new SAXReader();
        Document doc = saxReader.read(in);
        coreModel = (Element) doc.selectSingleNode("/adminconsole");
    } catch (Exception e) {
        Log.error("Failure when parsing main admin-sidebar.xml file", e);
    }
    try {
        in.close();
    } catch (Exception ignored) {
    // Ignore.
    }
    // Load other admin-sidebar.xml files from the classpath
    ClassLoader[] classLoaders = getClassLoaders();
    for (ClassLoader classLoader : classLoaders) {
        URL url = null;
        try {
            if (classLoader != null) {
                Enumeration e = classLoader.getResources("/META-INF/admin-sidebar.xml");
                while (e.hasMoreElements()) {
                    url = (URL) e.nextElement();
                    try {
                        in = url.openStream();
                        addModel("admin", in);
                    } finally {
                        try {
                            if (in != null) {
                                in.close();
                            }
                        } catch (Exception ignored) {
                        // Ignore.
                        }
                    }
                }
            }
        } catch (Exception e) {
            String msg = "Failed to load admin-sidebar.xml";
            if (url != null) {
                msg += " from resource: " + url.toString();
            }
            Log.warn(msg, e);
        }
    }
    rebuildModel();
}
Also used : Enumeration(java.util.Enumeration) InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) Document(org.dom4j.Document) URL(java.net.URL)

Aggregations

Enumeration (java.util.Enumeration)1179 IOException (java.io.IOException)202 ArrayList (java.util.ArrayList)141 File (java.io.File)102 HashMap (java.util.HashMap)86 Properties (java.util.Properties)85 Vector (java.util.Vector)83 List (java.util.List)77 HashSet (java.util.HashSet)65 Hashtable (java.util.Hashtable)63 Map (java.util.Map)59 Set (java.util.Set)59 URL (java.net.URL)57 ZipEntry (java.util.zip.ZipEntry)55 ServletContext (javax.servlet.ServletContext)53 Iterator (java.util.Iterator)50 InputStream (java.io.InputStream)47 ZipFile (java.util.zip.ZipFile)46 FileInputStream (java.io.FileInputStream)40 X509Certificate (java.security.cert.X509Certificate)37