@Override protected void doExceptionCaught(WsnSession session, Throwable cause) throws Exception { // trigger sessionClosed to update connection capabilities accordingly session.close(true); }
@Override @SuppressWarnings("unchecked") public void initializeSession(IoSession session, ConnectFuture future) { WsnSession wsnSession = (WsnSession) session; if (wsnSession.isBalanceSupported()) { IoSession parent = wsnSession.getParent(); List<String> selectedBalanceeURIs = (List<String>) parent.getAttribute(HttpAcceptor.BALANCEES_KEY); wsnSession.setBalanceeURIs(selectedBalanceeURIs); } }
@Override protected void doSessionClosed(IoSessionEx session) throws Exception { WsnSession wsnSession = SESSION_KEY.remove(session); if (wsnSession != null && !wsnSession.isClosing()) { wsnSession.reset(new IOException(LoggingUtils.EARLY_TERMINATION_OF_IOSESSION_MESSAGE, wsnSession.getCloseException()) .fillInStackTrace()); } }
if (wsnSession.isBalanceSupported()) { Collection<String> balanceeURIs = wsnSession.getBalanceeURIs(); String response = "" + '\uf0ff'; // Unique prefix to avoid collisions with responses from non Kaazing servers response += HttpUtils.mergeQueryParameters(wsnSession.getParentHttpRequestURI(), balanceeURIs.iterator().next()); } catch (URISyntaxException e) { logger.error( String.format("Failed to manufacture a balancee URI: The Http Request URI Query '%s' cannot merge with the configured balancee URI '%s'", wsnSession.getParentHttpRequestURI().getQuery(), balanceeURIs.iterator().next()), e); WebSocketWireProtocol wsVersion = wsnSession.getVersion(); Boolean codecRequired = wsnSession.getLocalAddress().getOption(CODEC_REQUIRED); final IoSessionEx parent = wsnSession.getParent(); if (WebSocketWireProtocol.HYBI_13.equals(wsVersion) || WebSocketWireProtocol.HYBI_8.equals(wsVersion)) { final IoBufferAllocatorEx<? extends WsBuffer> allocator = wsnSession.getBufferAllocator(); ByteBuffer messageNioBuf = allocator.allocate(response.getBytes().length + 4); IoBufferEx messageBuf = allocator.wrap(messageNioBuf).setAutoExpander(allocator);
@Override protected void doSessionClosed(IoSessionEx session) throws Exception { WsnSession wsnSession = SESSION_KEY.remove(session); if (wsnSession != null && !wsnSession.isClosing()) { boolean isWsx = !wsnSession.getLocalAddress().getOption(CODEC_REQUIRED); if (isWsx) { wsnSession.getProcessor().remove(wsnSession); } else { wsnSession.reset( new IOException(LoggingUtils.NETWORK_CONNECTIVITY_ERROR_MESSAGE, wsnSession.getCloseException()).fillInStackTrace()); } } IoFilterChain filterChain = session.getFilterChain(); removeBridgeFilters(filterChain); }
@Override protected void doFilterWrite(final NextFilter nextFilter, final WsnSession wsnSession, WriteRequest writeRequest) throws Exception { IoSession parent = wsnSession.getParent(); Encoding encoding = (Encoding) parent.getAttribute("encoding"); final WsMessage emptyWsMessage; final IoBufferAllocatorEx<?> allocator = wsnSession.getBufferAllocator(); switch(encoding) { case TEXT: emptyWsMessage = new WsTextMessage(allocator.wrap(allocator.allocate(0))); break; default: emptyWsMessage = new WsBinaryMessage(allocator.wrap(allocator.allocate(0))); } writeRequest.getFuture().addListener(new IoFutureListener<WriteFuture>() { @Override public void operationComplete(WriteFuture future) { if (logger.isDebugEnabled()) { logger.debug("HttpEmptyPacketWriterFilter writing empty packet."); } wsnSession.getParent().write(emptyWsMessage); } }); HttpResponseMessage message = (HttpResponseMessage) writeRequest.getMessage(); if ( message.getStatus() != HttpStatus.CLIENT_UNAUTHORIZED) { wsnSession.getFilterChain().remove(HttpEmptyPacketWriterFilter.this); } nextFilter.filterWrite(wsnSession, writeRequest); }
IoFilterChain filterChain = wsnSession.getFilterChain(); IoBufferAllocatorEx<? extends WsBuffer> allocator = wsnSession.getBufferAllocator(); final boolean hasPostUpgradeChildWsnSession = wsnSession.getHandler() == ioBridgeHandler; final ResourceAddress wsnSessionLocalAddress = wsnSession.getLocalAddress(); final boolean isLightweightWsnSession = wsnSessionLocalAddress.getOption(LIGHTWEIGHT); boolean sendMessagesDirect = isLightweightWsnSession
public boolean isBalanceSupported() { String query = httpRequestURI.getQuery(); return ((query != null) && query.contains(".kl=Y")) || this.getParent().getAttribute(HttpAcceptor.BALANCEES_KEY) != null; }
@Override public void operationComplete(WriteFuture future) { if (future.isWritten()) { // We both sent and received CLOSE frames: close // the session. if (logger != null && logger.isTraceEnabled()) { logger.trace("received and sent CLOSE frames, closing session"); } if (closeFuture != null && closeFuture.isDone() == false) { closeFuture.cancel(true); } WsnSession wsnSession = SESSION_KEY.get(session); wsnSession.getCloseFuture().setClosed(); wsnSession.getProcessor().remove(wsnSession); } } });
@Override protected Object getMessageFromWriteRequest(WsnSession session, WriteRequest request) { Object message = super.getMessageFromWriteRequest(session, request); boolean unwrapWsMessages = session.getLocalAddress().getOption(LIGHTWEIGHT); if (unwrapWsMessages && message instanceof WsMessage) { WsMessage wsMessage = (WsMessage)message; WsBuffer wsBuffer = (ioBufferEx instanceof WsBuffer) ? (WsBuffer) ioBufferEx : session.getBufferAllocator().wrap(ioBufferEx.buf()); switch (wsMessage.getKind()) { case BINARY:
CloseFuture closeFuture = wsnSession.getCloseFuture(); closeFuture.addListener(new IoFutureListener<CloseFuture>() { @Override wsnSession.startupScheduledCommands();
@Override protected void doSessionIdle(IoSessionEx session, IdleStatus status) throws Exception { WsnSession wsnSession = SESSION_KEY.get(session); if (wsnSession != null) { IoFilterChain filterChain = wsnSession.getFilterChain(); filterChain.fireSessionIdle(status); } }
@Override protected boolean shouldAccountForWrittenBytes(WsnSession session) { return !session.getLocalAddress().getOption(LIGHTWEIGHT); } }
Throwable cause = wsnSession == null ? null : wsnSession.getCloseException(); WsCloseMessage closeMessage; if (cause != null) {
@Override public void operationComplete(WriteFuture future) { if (logger.isDebugEnabled()) { logger.debug("HttpEmptyPacketWriterFilter writing empty packet."); } wsnSession.getParent().write(emptyWsMessage); } });
@Override protected void doSessionIdle(IoSessionEx session, IdleStatus status) throws Exception { WsnSession wsnSession = SESSION_KEY.get(session); IoFilterChain filterChain = wsnSession.getFilterChain(); filterChain.fireSessionIdle(status); }
@Override protected void doSessionOpened(WsnSession session) throws Exception { session.close(false); }
@Override protected void doMessageReceived(IoSessionEx session, Object message) throws Exception { WsnSession wsnSession = SESSION_KEY.get(session); IoFilterChain filterChain = wsnSession.getFilterChain();
@Override protected void doSessionCreated(WsnSession session) throws Exception { session.close(false); }
@Override public void closeWebSocketConnection(IoSession session) { WsnSession wsnSession = SESSION_KEY.get(session); assert wsnSession != null; wsnSession.close(false); }