@Override public NextAction handleWrite(FilterChainContext ctx) throws IOException { Connection<?> connection = ctx.getConnection(); GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler); try { handler.sent(channel, ctx.getMessage()); } catch (RemotingException e) { throw new IOException(StringUtils.toString(e)); } finally { GrizzlyChannel.removeChannelIfDisconnected(connection); } return ctx.getInvokeAction(); }
@Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { Connection<?> connection = ctx.getConnection(); GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler); try { handler.connected(channel); } catch (RemotingException e) { throw new IOException(StringUtils.toString(e)); } finally { GrizzlyChannel.removeChannelIfDisconnected(connection); } return ctx.getInvokeAction(); }
@Override public NextAction handleWrite(FilterChainContext context) throws IOException { Connection<?> connection = context.getConnection(); GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler); try { ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // Do not need to close Object msg = context.getMessage(); codec.encode(channel, channelBuffer, msg); GrizzlyChannel.removeChannelIfDisconnected(connection); Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes()); buffer.put(channelBuffer.toByteBuffer()); buffer.flip(); buffer.allowBufferDispose(true); context.setMessage(buffer); } finally { GrizzlyChannel.removeChannelIfDisconnected(connection); } return context.getInvokeAction(); }
@Override public NextAction handleClose(FilterChainContext ctx) throws IOException { logger.log(level, "LogFilter handleClose. Connection={0} message={1}", new Object[] {ctx.getConnection(), ctx.getMessage()}); return ctx.getInvokeAction(); }
@Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { final Object message = ctx.getMessage(); final Connection connection = ctx.getConnection(); final Object address = ctx.getAddress(); if (logger.isLoggable(Level.FINEST)) { logger.log(Level.FINEST, "EchoFilter. connection={0} dstAddress={1} message={2}", new Object[]{connection, address, message}); } if (message instanceof Buffer) { ((Buffer) message).allowBufferDispose(true); } ctx.write(address, message, null); return ctx.getStopAction(); } }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == SSLSwitchingEvent.class) { final SSLSwitchingEvent se = (SSLSwitchingEvent) event; final boolean isSecure = se.isSecure(); CONNECTION_IS_SECURE.set(se.getConnection(), isSecure); // if enabling security - create SSLEngine here, because default // Grizzly SSLFilter will use host/port info from the Connection, rather // than request URL. Specifically this doesn't work with CONNECT tunnels. if (isSecure && SSLUtils.getSSLEngine(ctx.getConnection()) == null) { // if SSLEngine is not yet set for the connection - initialize it final SSLEngine sslEngine = getClientSSLEngineConfigurator() .createSSLEngine(se.getHost(), se.getPort() == -1 ? 443 : se.getPort() ); sslEngine.beginHandshake(); SSLUtils.setSSLEngine(ctx.getConnection(), sslEngine); } return ctx.getStopAction(); } return ctx.getInvokeAction(); }
@Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { ctx.getConnection().close(); return ctx.getStopAction(); } }
/** * {@inheritDoc} */ @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { // a response is received - pass it to the callback final String responseMessage = ctx.getMessage(); callback.onResponseReceived(ctx.getConnection(), responseMessage); return ctx.getStopAction(); } }
@Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { final Connection connection = ctx.getConnection(); final SSLConnectionContext sslCtx = getSslConnectionContext(connection); if (sslCtx != null && sslCtx.getSslEngine() != null) { ctx.setMessage(allowDispose(allocateInputBuffer(sslCtx))); } return wrappedFilter.handleRead(ctx); } }
@Override public NextAction handleAccept(FilterChainContext ctx) throws IOException { logger.log(level, "LogFilter handleAccept. Connection={0} message={1}", new Object[] {ctx.getConnection(), ctx.getMessage()}); return ctx.getInvokeAction(); }
@Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { final Object message = ctx.getMessage(); final Connection connection = ctx.getConnection(); final Object address = ctx.getAddress(); if (logger.isLoggable(Level.FINEST)) { logger.log(Level.FINEST, "EchoFilter. connection={0} dstAddress={1} message={2}", new Object[]{connection, address, message}); } if (message instanceof Buffer) { ((Buffer) message).allowBufferDispose(true); } ctx.write(address, message, null); return ctx.getStopAction(); } }
@Override @SuppressWarnings("unchecked") public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (!Http2State.isHttp2(ctx.getConnection())) { return ctx.getInvokeAction(); } final Object type = event.type(); if (type == OutgoingHttpUpgradeEvent.TYPE) { assert event instanceof OutgoingHttpUpgradeEvent; final OutgoingHttpUpgradeEvent outUpgradeEvent = (OutgoingHttpUpgradeEvent) event; // If it's HTTP2 outgoing upgrade message - we have to re-enable content modifiers control outUpgradeEvent.getHttpHeader().setIgnoreContentModifiers(false); return ctx.getStopAction(); } return ctx.getInvokeAction(); }
@Override public NextAction handleWrite(FilterChainContext context) throws IOException { Connection<?> connection = context.getConnection(); GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler); try { ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // Do not need to close Object msg = context.getMessage(); codec.encode(channel, channelBuffer, msg); GrizzlyChannel.removeChannelIfDisconnected(connection); Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes()); buffer.put(channelBuffer.toByteBuffer()); buffer.flip(); buffer.allowBufferDispose(true); context.setMessage(buffer); } finally { GrizzlyChannel.removeChannelIfDisconnected(connection); } return context.getInvokeAction(); }
@Override public NextAction handleClose(final FilterChainContext ctx) throws IOException { final ClientContextImpl clientContext = LDAP_CONNECTION_ATTR.remove(ctx.getConnection()); if (clientContext != null) { clientContext.handleClose(-1, null); } return ctx.getStopAction(); }
@Override public NextAction handleWrite(FilterChainContext ctx) throws IOException { final Connection c = ctx.getConnection(); final Buffer msg = ctx.getMessage(); final CompositeBuffer buffer = bufferAttr.get(c); buffer.append(msg); return ctx.getStopAction(); }
@Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { final Connection connection = ctx.getConnection(); final SSLConnectionContext sslCtx = getSslConnectionContext(connection); if (sslCtx != null && sslCtx.getSslEngine() != null) { ctx.setMessage(allowDispose(allocateInputBuffer(sslCtx))); } return wrappedFilter.handleRead(ctx); } }
@Override public NextAction handleWrite(FilterChainContext ctx) throws IOException { Connection<?> connection = ctx.getConnection(); GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler); try { handler.sent(channel, ctx.getMessage()); } catch (RemotingException e) { throw new IOException(StringUtils.toString(e)); } finally { GrizzlyChannel.removeChannelIfDisconnected(connection); } return ctx.getInvokeAction(); }
@Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { Connection<?> connection = ctx.getConnection(); GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler); try { handler.connected(channel); } catch (RemotingException e) { throw new IOException(StringUtils.toString(e)); } finally { GrizzlyChannel.removeChannelIfDisconnected(connection); } return ctx.getInvokeAction(); }
@Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { logger.log(level, "LogFilter handleConnect. Connection={0} message={1}", new Object[] {ctx.getConnection(), ctx.getMessage()}); return ctx.getInvokeAction(); }
@Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { final Object message = ctx.getMessage(); final Connection connection = ctx.getConnection(); final Object address = ctx.getAddress(); if (logger.isLoggable(Level.FINEST)) { logger.log(Level.FINEST, "EchoFilter. connection={0} dstAddress={1} message={2}", new Object[]{connection, address, message}); } if (message instanceof Buffer) { ((Buffer) message).allowBufferDispose(true); } ctx.write(address, message, null); return ctx.getStopAction(); } }