protected StanzaHandler getStanzaHandler() { return (StanzaHandler)ioSession.getAttribute(ConnectionHandler.HANDLER); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public void operationComplete(CloseFuture future) { // now connection should be closed log.debug("Close operation completed {}: {}", sessionId, future.isClosed()); future.removeListener(this); for (Object key : session.getAttributeKeys()) { Object obj = session.getAttribute(key); log.debug("{}: {}", key, obj); if (obj != null) { if (log.isTraceEnabled()) { log.trace("Attribute: {}", obj.getClass().getName()); } if (obj instanceof IoProcessor) { log.debug("Flushing session in processor"); ((IoProcessor) obj).flush(session); log.debug("Removing session from processor"); ((IoProcessor) obj).remove(session); } else if (obj instanceof IoBuffer) { log.debug("Clearing session buffer"); ((IoBuffer) obj).clear(); ((IoBuffer) obj).free(); } } } } };
@Override public Certificate[] getPeerCertificates() { try { SSLSession sslSession = (SSLSession) ioSession.getAttribute(SslFilter.SSL_SESSION); if (sslSession != null) { return sslSession.getPeerCertificates(); } } catch (SSLPeerUnverifiedException e) { if (Log.isTraceEnabled()) { // This is perfectly acceptable when mutual authentication is not enforced by Openfire configuration. Log.trace( "Peer does not offer certificates in session: " + session, e); } } return new Certificate[0]; }
/** {@inheritDoc} */ @Override public void sessionClosed(IoSession session) throws Exception { String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); log.debug("Session closed: {} id: {}", session.getId(), sessionId); if (log.isTraceEnabled()) { log.trace("Session attributes: {}", session.getAttributeKeys()); } if (sessionId != null) { RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId); if (conn != null) { // fire-off closed event handler.connectionClosed(conn); // clear any session attributes we may have previously set // TODO: verify this cleanup code is necessary. The session is over and will be garbage collected surely? if (session.containsAttribute(RTMPConnection.RTMP_HANDSHAKE)) { session.removeAttribute(RTMPConnection.RTMP_HANDSHAKE); } if (session.containsAttribute(RTMPConnection.RTMPE_CIPHER_IN)) { session.removeAttribute(RTMPConnection.RTMPE_CIPHER_IN); session.removeAttribute(RTMPConnection.RTMPE_CIPHER_OUT); } } else { log.warn("Connection was not found for {}", sessionId); } cleanSession(session, false); } else { log.debug("Connections session id was null in session, may already be closed"); } }
@Override public Certificate[] getLocalCertificates() { SSLSession sslSession = (SSLSession) ioSession.getAttribute(SslFilter.SSL_SESSION); if (sslSession != null) { return sslSession.getLocalCertificates(); } return new Certificate[0]; }
@Override public void sessionClosed(IoSession session) throws Exception { final Connection connection = (Connection) session.getAttribute(CONNECTION); if ( connection != null ) { connection.close(); } }
@Override public void messageReceived(IoSession session, Object message) throws Exception { // Get the stanza handler for this session StanzaHandler handler = (StanzaHandler) session.getAttribute(HANDLER); // Get the parser to use to process stanza. For optimization there is going // to be a parser for each running thread. Each Filter will be executed // by the Executor placed as the first Filter. So we can have a parser associated // to each Thread final XMPPPacketReader parser = PARSER_CACHE.get(); // Update counter of read btyes updateReadBytesCounter(session); //System.out.println("RCVD: " + message); // Let the stanza handler process the received stanza try { handler.process((String) message, parser); } catch (Exception e) { Log.error("Closing connection due to error while processing message: " + message, e); final Connection connection = (Connection) session.getAttribute(CONNECTION); if ( connection != null ) { connection.close(); } } }
/** * Invoked when a MINA session has been idle for half of the allowed XMPP * session idle time as specified by {@link #getMaxIdleTime()}. This method * will be invoked each time that such a period passes (even if no IO has * occurred in between). * * Openfire will disconnect a session the second time this method is * invoked, if no IO has occurred between the first and second invocation. * This allows extensions of this class to use the first invocation to check * for livelyness of the MINA session (e.g by polling the remote entity, as * {@link ClientConnectionHandler} does). * * @see IoHandlerAdapter#sessionIdle(IoSession, IdleStatus) */ @Override public void sessionIdle(IoSession session, IdleStatus status) throws Exception { if (session.getIdleCount(status) > 1) { // Get the connection for this session final Connection connection = (Connection) session.getAttribute(CONNECTION); if (connection != null) { // Close idle connection if (Log.isDebugEnabled()) { Log.debug("ConnectionHandler: Closing connection that has been idle: " + connection); } connection.close(); } } }
/** {@inheritDoc} */ @SuppressWarnings("deprecation") @Override public void sessionClosed(NextFilter next, IoSession session) throws Exception { IoSession forward = (IoSession) session.getAttribute(FORWARD_KEY); if (forward != null && forward.isConnected() && !forward.isClosing()) { if (log.isDebugEnabled()) { log.debug("[{}] Closing: {}", name, forward); } forward.close(true); } next.sessionClosed(session); }
@Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { Log.warn("Closing connection due to exception in session: " + session, cause); try { // OF-524: Determine stream:error message. final StreamError error; if ( cause != null && (cause instanceof XMLNotWellFormedException || (cause.getCause() != null && cause.getCause() instanceof XMLNotWellFormedException) ) ) { error = new StreamError( StreamError.Condition.not_well_formed ); } else { error = new StreamError( StreamError.Condition.internal_server_error ); } final Connection connection = (Connection) session.getAttribute( CONNECTION ); connection.deliverRawText( error.toXML() ); } finally { final Connection connection = (Connection) session.getAttribute( CONNECTION ); if (connection != null) { connection.close(); } } }
/** {@inheritDoc} */ @Override public void sessionOpened(IoSession session) throws Exception { String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); log.debug("Session opened: {} id: {}", session.getId(), sessionId); RTMPConnManager connManager = (RTMPConnManager) RTMPConnManager.getInstance(); session.setAttribute(RTMPConnection.RTMP_CONN_MANAGER, new WeakReference<IConnectionManager<RTMPConnection>>(connManager)); RTMPMinaConnection conn = (RTMPMinaConnection) connManager.getConnectionBySessionId(sessionId); handler.connectionOpened(conn); }
public void messageSent(IoSession session, Object message) throws Exception { log.trace("messageSent session: {} message: {}", session, message); String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (log.isTraceEnabled()) { log.trace("Message sent on session: {} id: {}", session.getId(), sessionId);
/** {@inheritDoc} */ @Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { log.debug("Filter chain: {}", session.getFilterChain()); String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (log.isDebugEnabled()) { log.warn("Exception caught on session: {} id: {}", session.getId(), sessionId, cause); } if (cause instanceof IOException) { // Mina states that the connection will be automatically closed when an IOException is caught log.debug("IOException caught on {}", sessionId); } else { log.debug("Non-IOException caught on {}", sessionId); if (session.containsAttribute("FORCED_CLOSE")) { log.info("Close already forced on this session: {}", session.getId()); } else { // set flag session.setAttribute("FORCED_CLOSE", Boolean.TRUE); //session.suspendRead(); cleanSession(session, true); } } }
/** * Updates the system counter of read bytes. This information is used by the incoming * bytes statistic. * * @param session the session that read more bytes from the socket. */ private void updateReadBytesCounter(IoSession session) { long currentBytes = session.getReadBytes(); Long prevBytes = (Long) session.getAttribute("_read_bytes"); long delta; if (prevBytes == null) { delta = currentBytes; } else { delta = currentBytes - prevBytes; } session.setAttribute("_read_bytes", currentBytes); ServerTrafficCounter.incrementIncomingCounter(delta); }
log.trace("Filter chain: {}", session.getFilterChain()); String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (log.isTraceEnabled()) { log.trace("Message received on session: {} id: {}", session.getId(), sessionId);
/** * Updates the system counter of written bytes. This information is used by the outgoing * bytes statistic. * * @param session the session that wrote more bytes to the socket. */ private void updateWrittenBytesCounter(IoSession session) { long currentBytes = session.getWrittenBytes(); Long prevBytes = (Long) session.getAttribute("_written_bytes"); long delta; if (prevBytes == null) { delta = currentBytes; } else { delta = currentBytes - prevBytes; } session.setAttribute("_written_bytes", currentBytes); ServerTrafficCounter.incrementOutgoingCounter(delta); } }
@Override public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest request) throws Exception { log.trace("filterWrite nextFilter: {} session: {} request: {}", nextFilter, session, request); Cipher cipher = (Cipher) session.getAttribute(RTMPConnection.RTMPE_CIPHER_OUT); if (cipher == null) { if (log.isTraceEnabled()) {
/** {@inheritDoc} */ @Override public void sessionIdle(IoSession session, IdleStatus status) throws Exception { if (log.isTraceEnabled()) { log.trace("Idle (session: {}) local: {} remote: {}\nread: {} write: {}", session.getId(), session.getLocalAddress(), session.getRemoteAddress(), session.getReadBytes(), session.getWrittenBytes()); } String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID); if (sessionId != null) { RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId); if (conn != null) { // close the idle socket conn.onInactive(); } } }
@Override protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { // Get the XML light parser from the IoSession XMLLightweightParser parser = (XMLLightweightParser) session.getAttribute(ConnectionHandler.XML_PARSER); // Parse as many stanzas as possible from the received data parser.read(in); if (parser.areThereMsgs()) { for (String stanza : parser.getMsgs()) { out.write(stanza); } } return !in.hasRemaining(); } }
/** {@inheritDoc} */ @Override public void messageReceived(NextFilter next, IoSession session, Object message) throws Exception { // Create forwarding IO session IoSession forward = (IoSession) session.getAttribute(FORWARD_KEY); if (forward != null && forward.isConnected()) { if (message instanceof IoBuffer) { final IoBuffer buf = (IoBuffer) message; if (log.isDebugEnabled()) { log.debug("[{}] RAW >> {}", name, buf.getHexDump()); } IoBuffer copy = IoBuffer.allocate(buf.limit()); int limit = buf.limit(); copy.put(buf); copy.flip(); forward.write(copy); buf.flip(); buf.position(0); buf.limit(limit); } } next.messageReceived(session, message); }