@Override public void processPacket(final Packet packet) { if (log.isLoggable(Level.FINEST)) { log.log(Level.FINEST, "Processing packet: {0}", packet.toString()); } super.processPacket(packet); }
@Override public void getStatistics(StatisticsList list) { super.getStatistics(list); if (list.checkLevel(Level.FINEST)) { // Be careful here, the size() for this map is expensive to count list.add(getName(), "Bosh sessions", sessions.size(), Level.FINEST); } }
@Override public void setProperties(Map<String, Object> props) throws ConfigurationException { super.setProperties(props); if (props.get(MAX_WAIT_DEF_PROP_KEY) != null) { max_wait = (Long) props.get(MAX_WAIT_DEF_PROP_KEY); log.info("Setting max_wait to: " + max_wait); } if (props.get(MIN_POLLING_PROP_KEY) != null) { min_polling = (Long) props.get(MIN_POLLING_PROP_KEY); log.info("Setting min_polling to: " + min_polling); } if (props.get(MAX_INACTIVITY_PROP_KEY) != null) { max_inactivity = (Long) props.get(MAX_INACTIVITY_PROP_KEY); log.info("Setting max_inactivity to: " + max_inactivity); } if (props.get(CONCURRENT_REQUESTS_PROP_KEY) != null) { concurrent_requests = (Integer) props.get(CONCURRENT_REQUESTS_PROP_KEY); log.info("Setting concurrent_requests to: " + concurrent_requests); } if (props.get(HOLD_REQUESTS_PROP_KEY) != null) { hold_requests = (Integer) props.get(HOLD_REQUESTS_PROP_KEY); log.info("Setting hold_requests to: " + hold_requests); } if (props.get(MAX_PAUSE_PROP_KEY) != null) { max_pause = (Long) props.get(MAX_PAUSE_PROP_KEY); log.info("Setting max_pause to: " + max_pause); } if (props.get(MAX_BATCH_SIZE_KEY) != null) { max_batch_size = (Integer) props.get(MAX_BATCH_SIZE_KEY); log.info("Setting max_batch_size to: " + max_batch_size); } if (props.get(BATCH_QUEUE_TIMEOUT_KEY) != null) { batch_queue_timeout = (Long) props.get(BATCH_QUEUE_TIMEOUT_KEY); log.info("Setting batch_queue_timeout to: " + batch_queue_timeout); } if (props.get(MAX_SESSION_WAITING_PACKETS_KEY) != null) { maxSessionWaitingPackets = (Integer) props.get(MAX_SESSION_WAITING_PACKETS_KEY); log.info("Setting max session waiting packets to: " + maxSessionWaitingPackets); } if (props.get(SEND_NODE_HOSTNAME_KEY) != null) { sendNodeHostname = (Boolean) props.get(SEND_NODE_HOSTNAME_KEY); } if (props.size() == 1 && props.get(SID_LOGGER_KEY) != null) { Level lvl = Level.parse((String) props.get(SID_LOGGER_KEY)); setupSidlogger(lvl); log.info("Setting SID log level to: " + lvl); } }
@Override public void initBindings(Bindings binds) { super.initBindings(binds); binds.put("boshCM", this); }
@Override protected void processCommand(Packet packet) { BoshSession session = getBoshSession(packet.getTo()); switch (packet.getCommand()) { case USER_LOGIN: String jid = Command.getFieldValue(packet, "user-jid"); if (jid != null) { if (session != null) { try { BareJID fromJID = BareJID.bareJIDInstance(jid); BareJID hostJid = getSeeOtherHostForJID(fromJID, Phase.LOGIN); if (hostJid != null) { Element streamErrorElement = see_other_host_strategy.getStreamError( "urn:ietf:params:xml:ns:xmpp-streams", hostJid); Packet redirectPacket = Packet.packetInstance(streamErrorElement); redirectPacket.setPacketTo(packet.getTo()); writePacketToSocket(redirectPacket); session.sendWaitingPackets(); session.close(); if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "{0} : {1} ({2})", new Object[] { BOSH_OPERATION_TYPE.REMOVE, session.getSid(), "See other host" }); } sessions.remove(session.getSid()); } else { session.setUserJid(jid); } } catch (TigaseStringprepException ex) { log.log(Level.SEVERE, "user JID violates RFC6122 (XMPP:Address Format): ", ex); } } else { if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Missing XMPPIOService for USER_LOGIN command: {0}", packet); } } } else { log.log(Level.WARNING, "Missing user-jid for USER_LOGIN command: {0}", packet); } break; case CLOSE: if (session != null) { if (log.isLoggable(Level.FINER)) { log.log(Level.FINER, "Closing session for command CLOSE: {0}", session.getSid()); } try { List<Element> err_el = packet.getElement().getChildrenStaticStr(Iq.IQ_COMMAND_PATH); if ((err_el != null) && (err_el.size() > 0)) { Element error = new Element("stream:error"); error.addChild(err_el.get(0)); Packet condition = Packet.packetInstance(error); condition.setPacketTo(packet.getTo()); writePacketToSocket(condition); session.sendWaitingPackets(); bosh_session_close_delay = 100; } } catch (TigaseStringprepException ex) { Logger.getLogger(BoshConnectionManager.class.getName()).log(Level.SEVERE, null, ex); } if (bosh_session_close_delay > 0) { try { Thread.sleep(bosh_session_close_delay); } catch (InterruptedException ex) { // Intentionally left blank } } session.close(); if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "{0} : {1} ({2})", new Object[] { BOSH_OPERATION_TYPE.REMOVE, session.getSid(), "Closing session for command CLOSE" }); } sessions.remove(session.getSid()); } else { if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Session does not exist for packet: {0}", packet); } } break; case CHECK_USER_CONNECTION: if (session != null) { // It's ok, the session has been found, respond with OK. addOutPacket(packet.okResult((String) null, 0)); } else { // Session is no longer active, respond with an error. try { addOutPacket( Authorization.ITEM_NOT_FOUND.getResponseMessage(packet, "Connection gone.", false)); } catch (PacketErrorTypeException e) { // Hm, error already, ignoring... log.log(Level.INFO, "Error packet is not really expected here: {0}", packet); } } break; default: super.processCommand(packet); break; } // end of switch (pc.getCommand()) }
@Override public void writeRawData(BoshIOService ios, String data) { super.writeRawData(ios, data); }
@Override public void serviceStarted(XMPPIOService<Object> service) { super.serviceStarted(service); }