public void addBridgeFilters(IoFilterChain bridgeFilterChain, WsebSession wsebSession) { bridgeFilterChain.addLast(CODEC_FILTER, codec); if (encoding != null) { bridgeFilterChain.addBefore(CODEC_FILTER, ENCODING_FILTER, encoding); } }
@Override protected void doSessionOpened(final HttpAcceptSession session) throws Exception { WsebSession wsebSession = getSession(session); if (wsebSession == null || wsebSession.isClosing()) { session.close(false); return; } IoFilterChain filterChain = session.getFilterChain(); filterChain.addLast(CODEC_FILTER, codec); // only supported for non-binary upstream if (utf8 != null) { // Note: encoding filter needs to be closer to the network than the codec filter String contentType = session.getReadHeader(HEADER_CONTENT_TYPE); if (CONTENT_TYPE_TEXT_PLAIN_CHARSET_UTF_8.equalsIgnoreCase(contentType)) { filterChain.addBefore(CODEC_FILTER, UTF8_FILTER, utf8); } } final CloseFuture wsebCloseFuture = wsebSession.getCloseFuture(); final IoFutureListener<CloseFuture> listener = new IoFutureListener<CloseFuture>() { @Override public void operationComplete(CloseFuture future) { // Note: this reference to HTTP session is pinned by listener // and must be removed to avoid a memory leak (see below) session.close(false); } }; // detect when emulated session is closed to force upstream to close wsebCloseFuture.addListener(listener); // detect when upstream is closed to remove upstream reference from emulated session session .getCloseFuture() .addListener( new IoFutureListener<CloseFuture>() { @Override public void operationComplete(CloseFuture future) { // Note: a reference to the HTTP upstream session is pinned by listener // and must be removed to avoid a memory leak (see above) wsebCloseFuture.removeListener(listener); } }); wsebSession.attachReader(session); }