@Override public boolean serviceStopped(XMPPIOService<Object> xmppService) { BoshIOService service = (BoshIOService) xmppService; boolean result = super.serviceStopped(service); UUID sid = service.getSid(); if (sid != null) { BoshSession bs = sessions.get(sid); if (bs != null) { if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "{0} : {1} ({2})", new Object[] {BOSH_OPERATION_TYPE.REMOVE, bs.getSid(), "Closing bosh session"}); } bs.disconnected(service); } } return result; }
@Override public Queue<Packet> processSocketData(XMPPIOService<Object> srv) { BoshIOService serv = (BoshIOService) srv; Packet p = null; while ((p = serv.getReceivedPackets().poll()) != null) { Queue<Packet> out_results = new ArrayDeque<Packet>(2); BoshSession bs = null; String sid_str = null; synchronized (sessions) { if (log.isLoggable(Level.FINER)) { log.log( Level.FINER, "Processing packet: {0}, type: {1}", new Object[] {p.getElemName(), p.getType()}); } if (log.isLoggable(Level.FINEST)) { log.log(Level.FINEST, "Processing socket data: {0}", p); } sid_str = p.getAttributeStaticStr(SID_ATTR); UUID sid = null; if (sid_str == null) { String hostname = p.getAttributeStaticStr(Packet.TO_ATT); if ((hostname != null) && isLocalDomain(hostname)) { if (!isAllowed(srv, hostname)) { if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, "Policy violation. Closing connection: {0}", p); } try { serv.sendErrorAndStop(Authorization.NOT_ALLOWED, p, "Policy violation."); } catch (IOException e) { log.log( Level.WARNING, "Problem sending invalid hostname error for sid = " + sid, e); } } else { bs = new BoshSession( getDefVHostItem().getDomain(), JID.jidInstanceNS(routings.computeRouting(hostname)), this, sendNodeHostname ? getDefHostName().getDomain() : null, maxSessionWaitingPackets); sid = bs.getSid(); sessions.put(sid, bs); if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "{0} : {1} ({2})", new Object[] {BOSH_OPERATION_TYPE.CREATE, sid, "Socket bosh session"}); } } } else { try { serv.sendErrorAndStop(Authorization.NOT_ALLOWED, p, "Invalid hostname."); } catch (IOException e) { log.log(Level.WARNING, "Problem sending invalid hostname error for sid = " + sid, e); } } } else { try { sid = UUID.fromString(sid_str); bs = sessions.get(sid); } catch (IllegalArgumentException e) { log.log( Level.WARNING, "Problem processing socket data, sid = " + sid_str + " does not conform to the UUID string representation.", e); } } } try { if (bs != null) { synchronized (bs) { if (sid_str == null) { bs.init( p, serv, max_wait, min_polling, max_inactivity, concurrent_requests, hold_requests, max_pause, max_batch_size, batch_queue_timeout, out_results); } else { bs.processSocketPacket(p, serv, out_results); } } } else { if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "{0} : {1} ({2})", new Object[] {BOSH_OPERATION_TYPE.INVALID_SID, sid_str, "Invalid SID"}); } serv.sendErrorAndStop(Authorization.ITEM_NOT_FOUND, p, "Invalid SID"); } addOutPackets(out_results, bs); } catch (IOException e) { log.log(Level.WARNING, "Problem processing socket data for sid = " + sid_str, e); } // addOutPackets(out_results); } // end of while () return null; }