Refine search
@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 @SuppressWarnings("unchecked") public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == TransportFilter.FlushEvent.TYPE) { final Connection connection = ctx.getConnection(); final FilterChainContext.TransportContext transportContext = ctx.getTransportContext(); if (transportContext.getCompletionHandler() != null) { throw new IllegalStateException("TransportContext CompletionHandler must be null"); } final CompletionHandler completionHandler = ((TransportFilter.FlushEvent) event).getCompletionHandler(); transport.getWriter(transportContext.isBlocking()).write(connection, Buffers.EMPTY_BUFFER, completionHandler); } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == CertificateEvent.TYPE) { final CertificateEvent ce = (CertificateEvent) event; try { return ctx.getSuspendAction(); } finally { getPeerCertificateChain(obtainSslConnectionContext(ctx.getConnection()), ctx, ce.needClientAuth, ce.certsFuture); } } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == GracefulCloseEvent.class) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final GracefulCloseEvent closeEvent = (GracefulCloseEvent) event; final HttpResponsePacket response = closeEvent.getHttpTxContext().responsePacket; response.getProcessingState().getHttpContext().attach(ctx); onHttpPacketParsed(response, ctx); return ctx.getStopAction(); } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { final Object type = event.type(); if (type == ContinueEvent.class) { final ContinueEvent continueEvent = (ContinueEvent) event; continueEvent.getContext().payloadGenerator.continueConfirmed(ctx); } return ctx.getStopAction(); } // ----------------------------------------------------- Private Methods
@Override public NextAction handleEvent(FilterChainContext ctx, FilterChainEvent event) throws IOException { final Connection c = ctx.getConnection(); AtomicInteger ai = counterAttr.get(c); final int value = ai.get(); if (event.type() == DEC_EVENT.type()) { ai.decrementAndGet(); } else if (event.type() == INC_EVENT.type()) { ai.incrementAndGet(); } else { throw new UnsupportedOperationException("Unsupported event"); } if (value != checkValue) { throw new IllegalStateException("Unexpected value. Expected=" + checkValue + " got=" + value); } return ctx.getInvokeAction(); } }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == ShutdownEvent.TYPE) { if (shuttingDown.compareAndSet(false, true)) { final ShutdownEvent shutDownEvent = (ShutdownEvent) event; final FutureImpl<HttpServerFilter> future = Futures.createSafeFuture(); shutDownEvent.addShutdownTask(new Callable<Filter>() { @Override public Filter call() throws Exception { return future.get(); } }); shutdownCompletionFuture = new AtomicReference<>(future); if (activeRequestsCounter.get() == 0) { future.result(this); } } } return ctx.getInvokeAction(); }
@Override @SuppressWarnings("unchecked") public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == TransportFilter.FlushEvent.TYPE) { final Connection connection = ctx.getConnection(); final FilterChainContext.TransportContext transportContext = ctx.getTransportContext(); if (transportContext.getCompletionHandler() != null) { throw new IllegalStateException("TransportContext CompletionHandler must be null"); } final CompletionHandler completionHandler = ((TransportFilter.FlushEvent) event).getCompletionHandler(); transport.getWriter(transportContext.isBlocking()).write(connection, Buffers.EMPTY_BUFFER, completionHandler); } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == CertificateEvent.TYPE) { final CertificateEvent ce = (CertificateEvent) event; try { return ctx.getSuspendAction(); } finally { getPeerCertificateChain(obtainSslConnectionContext(ctx.getConnection()), ctx, ce.needClientAuth, ce.certsFuture); } } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(FilterChainContext ctx, FilterChainEvent event) throws IOException { if (event.type() == SSLSwitchingEvent.class) { final SSLSwitchingEvent se = (SSLSwitchingEvent) event; CONNECTION_IS_SECURE.set(se.connection, se.secure); return ctx.getStopAction(); } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { final Object type = event.type(); if (type == ContinueEvent.class) { final ContinueEvent continueEvent = (ContinueEvent) event; ((ExpectHandler) continueEvent.context.bodyHandler).finish(ctx); } return ctx.getStopAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == ShutdownEvent.TYPE) { if (shuttingDown.compareAndSet(false, true)) { final ShutdownEvent shutDownEvent = (ShutdownEvent) event; final FutureImpl<HttpServerFilter> future = Futures.createSafeFuture(); shutDownEvent.addShutdownTask(new Callable<Filter>() { @Override public Filter call() throws Exception { return future.get(); } }); shutdownCompletionFuture = new AtomicReference<>(future); if (activeRequestsCounter.get() == 0) { future.result(this); } } } return ctx.getInvokeAction(); }
@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 @SuppressWarnings("unchecked") public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == TransportFilter.FlushEvent.TYPE) { final Connection connection = ctx.getConnection(); final FilterChainContext.TransportContext transportContext = ctx.getTransportContext(); if (transportContext.getCompletionHandler() != null) { throw new IllegalStateException("TransportContext CompletionHandler must be null"); } final CompletionHandler completionHandler = ((TransportFilter.FlushEvent) event).getCompletionHandler(); transport.getWriter(transportContext.isBlocking()).write(connection, Buffers.EMPTY_BUFFER, completionHandler); } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == CertificateEvent.TYPE) { final CertificateEvent ce = (CertificateEvent) event; try { return ctx.getSuspendAction(); } finally { getPeerCertificateChain(obtainSslConnectionContext(ctx.getConnection()), ctx, ce.needClientAuth, ce.certsFuture); } } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == GracefulCloseEvent.class) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final GracefulCloseEvent closeEvent = (GracefulCloseEvent) event; final HttpResponsePacket response = closeEvent.getHttpTxContext().responsePacket; response.getProcessingState().getHttpContext().attach(ctx); onHttpPacketParsed(response, ctx); return ctx.getStopAction(); } return ctx.getInvokeAction(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { final Object type = event.type(); if (type == ContinueEvent.class) { final ContinueEvent continueEvent = (ContinueEvent) event; continueEvent.getContext().payloadGenerator.continueConfirmed(ctx); } return ctx.getStopAction(); } // ----------------------------------------------------- Private Methods
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == ShutdownEvent.TYPE) { if (shuttingDown.compareAndSet(false, true)) { final ShutdownEvent shutDownEvent = (ShutdownEvent) event; final FutureImpl<HttpServerFilter> future = Futures.createSafeFuture(); shutDownEvent.addShutdownTask(new Callable<Filter>() { @Override public Filter call() throws Exception { return future.get(); } }); shutdownCompletionFuture = new AtomicReference<>(future); if (activeRequestsCounter.get() == 0) { future.result(this); } } } return ctx.getInvokeAction(); }
@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 @SuppressWarnings("unchecked") public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == TransportFilter.FlushEvent.TYPE) { final Connection connection = ctx.getConnection(); final FilterChainContext.TransportContext transportContext = ctx.getTransportContext(); if (transportContext.getCompletionHandler() != null) { throw new IllegalStateException("TransportContext CompletionHandler must be null"); } final CompletionHandler completionHandler = ((TransportFilter.FlushEvent) event).getCompletionHandler(); transport.getWriter(transportContext.isBlocking()).write(connection, Buffers.EMPTY_BUFFER, completionHandler); } return ctx.getInvokeAction(); }