Enable {@link RequestContext} during operators.
176716
@SuppressWarnings({ "rawtypes", "unchecked" })
    public static synchronized void enable() {
        if (enabled) {
            return;
        }

        oldOnObservableAssembly = RxJavaPlugins.getOnObservableAssembly();
        RxJavaPlugins.setOnObservableAssembly(compose(
                oldOnObservableAssembly,
                new ConditionalOnCurrentRequestContextFunction<Observable>() {
                    @Override
                    Observable applyActual(Observable o, RequestContext ctx) {
                        if (!(o instanceof Callable)) {
                            return new RequestContextObservable(o, ctx);
                        }
                        if (o instanceof ScalarCallable) {
                            return new RequestContextScalarCallableObservable(o, ctx);
                        }
                        return new RequestContextCallableObservable(o, ctx);
                    }
                }));

        oldOnConnectableObservableAssembly = RxJavaPlugins.getOnConnectableObservableAssembly();
        RxJavaPlugins.setOnConnectableObservableAssembly(compose(
                oldOnConnectableObservableAssembly,
                new ConditionalOnCurrentRequestContextFunction<ConnectableObservable>() {
                    @Override
                    ConnectableObservable applyActual(ConnectableObservable co, RequestContext ctx) {
                        return new RequestContextConnectableObservable(co, ctx);
                    }
                }));

        oldOnCompletableAssembly = RxJavaPlugins.getOnCompletableAssembly();
        RxJavaPlugins.setOnCompletableAssembly(
                compose(oldOnCompletableAssembly,
                        new ConditionalOnCurrentRequestContextFunction<Completable>() {
                            @Override
                            Completable applyActual(Completable c,
                                                    RequestContext ctx) {
                                if (!(c instanceof Callable)) {
                                    return new RequestContextCompletable(c, ctx);
                                }
                                if (c instanceof ScalarCallable) {
                                    return new RequestContextScalarCallableCompletable(
                                            c, ctx);
                                }
                                return new RequestContextCallableCompletable(c, ctx);
                            }
                        }));

        oldOnSingleAssembly = RxJavaPlugins.getOnSingleAssembly();
        RxJavaPlugins.setOnSingleAssembly(
                compose(oldOnSingleAssembly, new ConditionalOnCurrentRequestContextFunction<Single>() {
                    @Override
                    Single applyActual(Single s, RequestContext ctx) {
                        if (!(s instanceof Callable)) {
                            return new RequestContextSingle(s, ctx);
                        }
                        if (s instanceof ScalarCallable) {
                            return new RequestContextScalarCallableSingle(s, ctx);
                        }
                        return new RequestContextCallableSingle(s, ctx);
                    }
                }));

        oldOnMaybeAssembly = RxJavaPlugins.getOnMaybeAssembly();
        RxJavaPlugins.setOnMaybeAssembly(
                compose(oldOnMaybeAssembly, new ConditionalOnCurrentRequestContextFunction<Maybe>() {
                    @Override
                    Maybe applyActual(Maybe m, RequestContext ctx) {
                        if (!(m instanceof Callable)) {
                            return new RequestContextMaybe(m, ctx);
                        }
                        if (m instanceof ScalarCallable) {
                            return new RequestContextScalarCallableMaybe(m, ctx);
                        }
                        return new RequestContextCallableMaybe(m, ctx);
                    }
                }));

        oldOnFlowableAssembly = RxJavaPlugins.getOnFlowableAssembly();
        RxJavaPlugins.setOnFlowableAssembly(
                compose(oldOnFlowableAssembly, new ConditionalOnCurrentRequestContextFunction<Flowable>() {
                    @Override
                    Flowable applyActual(Flowable f, RequestContext ctx) {
                        if (!(f instanceof Callable)) {
                            return new RequestContextFlowable(f, ctx);
                        }
                        if (f instanceof ScalarCallable) {
                            return new RequestContextScalarCallableFlowable(f, ctx);
                        }
                        return new RequestContextCallableFlowable(f, ctx);
                    }
                }));

        oldOnConnectableFlowableAssembly = RxJavaPlugins.getOnConnectableFlowableAssembly();
        RxJavaPlugins.setOnConnectableFlowableAssembly(
                compose(oldOnConnectableFlowableAssembly,
                        new ConditionalOnCurrentRequestContextFunction<ConnectableFlowable>() {
                            @Override
                            ConnectableFlowable applyActual(
                                    ConnectableFlowable cf,
                                    RequestContext ctx) {
                                return new RequestContextConnectableFlowable(
                                        cf, ctx);
                            }
                        }
                ));

        oldOnParallelAssembly = RxJavaPlugins.getOnParallelAssembly();
        RxJavaPlugins.setOnParallelAssembly(
                compose(oldOnParallelAssembly,
                        new ConditionalOnCurrentRequestContextFunction<ParallelFlowable>() {
                            @Override
                            ParallelFlowable applyActual(ParallelFlowable pf, RequestContext ctx) {
                                return new RequestContextParallelFlowable(pf, ctx);
                            }
                        }
                ));
        enabled = true;
    }
1152946
private RequestContext createRequestContext(final HttpServletRequest req) {
        return new RequestContext() {
            @Override
            public String getCharacterEncoding() {
                return req.getCharacterEncoding();
            }

            @Override
            public String getContentType() {
                return req.getContentType();
            }

            @Override
            @Deprecated
            public int getContentLength() {
                return req.getContentLength();
            }

            @Override
            public InputStream getInputStream() throws IOException {
                return req.getInputStream();
            }
        };
    }
1331029
public Binding<?> requestBinding(String key, Object requiredBy, ClassLoader classLoader) {
    return requestBinding(key, requiredBy, classLoader, true, true);
  }
800398
protected void activate(ComponentContext compcontext) {
        if (tc.isDebugEnabled()) {
            Tr.debug(tc, "Activating " + this.getClass().getName());
        }
        setInstance(this);
        this.beanValidation.activate(compcontext);
    }
295450
public boolean isCasAuthenticationOldForMaxAgeAuthorizationRequest(final WebContext context) {
        return isCasAuthenticationAvailable(context)
            .filter(a -> isCasAuthenticationOldForMaxAgeAuthorizationRequest(context, a))
            .isPresent();
    }
454854
protected Event grantServiceTicket(final RequestContext context) {
        val ticketGrantingTicketId = WebUtils.getTicketGrantingTicketId(context);
        val credential = getCredentialFromContext(context);

        try {
            val service = WebUtils.getService(context);
            val authn = getWebflowEventResolutionConfigurationContext().getTicketRegistrySupport().getAuthenticationFrom(ticketGrantingTicketId);
            val registeredService = getWebflowEventResolutionConfigurationContext().getServicesManager().findServiceBy(service);

            if (authn != null && registeredService != null) {
                LOGGER.debug("Enforcing access strategy policies for registered service [{}] and principal [{}]", registeredService, authn.getPrincipal());

                val audit = AuditableContext.builder().service(service)
                    .authentication(authn)
                    .registeredService(registeredService)
                    .retrievePrincipalAttributesFromReleasePolicy(Boolean.TRUE)
                    .build();
                val accessResult = getWebflowEventResolutionConfigurationContext().getRegisteredServiceAccessStrategyEnforcer().execute(audit);
                accessResult.throwExceptionIfNeeded();
            }

            val authenticationResult =
                getWebflowEventResolutionConfigurationContext().getAuthenticationSystemSupport()
                    .handleAndFinalizeSingleAuthenticationTransaction(service, credential);
            val serviceTicketId = getWebflowEventResolutionConfigurationContext().getCentralAuthenticationService()
                .grantServiceTicket(ticketGrantingTicketId, service, authenticationResult);
            WebUtils.putServiceTicketInRequestScope(context, serviceTicketId);
            WebUtils.putWarnCookieIfRequestParameterPresent(getWebflowEventResolutionConfigurationContext().getWarnCookieGenerator(), context);
            return newEvent(CasWebflowConstants.TRANSITION_ID_WARN);

        } catch (final AuthenticationException | AbstractTicketException e) {
            return newEvent(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, e);
        }
    }
108004
@Override
    public synchronized void start(final StartContext context) throws StartException {
        final ModelController modelController = modelControllerSupplier.get();
        final ControlledProcessStateService controlledProcessStateService = controlledProcessStateServiceSupplier.get();
        socketBindingManager = socketBindingManagerSupplier != null ? socketBindingManagerSupplier.get() : null;

        final SecurityRealm securityRealm = securityRealmSupplier != null ? securityRealmSupplier.get() : null;
        final HttpAuthenticationFactory httpAuthenticationFactory = httpAuthFactorySupplier != null ? httpAuthFactorySupplier.get() : null;
        SSLContext sslContext = sslContextSupplier != null ? sslContextSupplier.get() : null;
        final SslClientAuthMode sslClientAuthMode;
        if (sslContext == null && securityRealm != null) {
            sslContext = securityRealm.getSSLContext();
            sslClientAuthMode = getSslClientAuthMode(securityRealm);
        } else {
            sslClientAuthMode = null;
        }

        InetSocketAddress bindAddress = null;
        InetSocketAddress secureBindAddress = null;

        final SocketBinding basicBinding = socketBindingSupplier != null ? socketBindingSupplier.get() : null;
        final SocketBinding secureBinding = secureSocketBindingSupplier != null ? secureSocketBindingSupplier.get() : null;
        final NetworkInterfaceBinding interfaceBinding = interfaceBindingSupplier != null ? interfaceBindingSupplier.get() : null;
        final NetworkInterfaceBinding secureInterfaceBinding = secureInterfaceBindingSupplier != null ? secureInterfaceBindingSupplier.get() : null;
        if (interfaceBinding != null) {
            useUnmanagedBindings = true;
            assert this.port != null;
            final int port = this.port;
            if (port > 0) {
                bindAddress = new InetSocketAddress(interfaceBinding.getAddress(), port);
            }
            assert this.securePort != null;
            final int securePort = this.securePort;
            if (securePort > 0) {
                InetAddress secureAddress = secureInterfaceBinding == null ? interfaceBinding.getAddress() : secureInterfaceBinding.getAddress();
                secureBindAddress = new InetSocketAddress(secureAddress, securePort);
            }
        } else {
            if (basicBinding != null) {
                bindAddress = basicBinding.getSocketAddress();
            }
            if (secureBinding != null) {
                secureBindAddress = secureBinding.getSocketAddress();
            }
        }
        List<ListenerRegistry.Listener> listeners = new ArrayList<>();
        //TODO: rethink this whole ListenerRegistry business
        if(bindAddress != null) {
            ListenerRegistry.Listener http = new ListenerRegistry.Listener("http", HTTP_MANAGEMENT, SERVER_NAME, bindAddress);
            http.setContextInformation("socket-binding", basicBinding);
            listeners.add(http);
        }
        if(secureBindAddress != null) {
            ListenerRegistry.Listener https = new ListenerRegistry.Listener("https", HTTPS_MANAGEMENT, SERVER_NAME, bindAddress);
            https.setContextInformation("socket-binding", secureBinding);
            listeners.add(https);
        }

        final ChannelUpgradeHandler upgradeHandler = new ChannelUpgradeHandler();
        final ServiceBuilder<?> builder = context.getChildTarget().addService(HTTP_UPGRADE_SERVICE_NAME);
        final Consumer<Object> upgradeHandlerConsumer = builder.provides(HTTP_UPGRADE_SERVICE_NAME, HTTPS_UPGRADE_SERVICE_NAME);
        builder.setInstance(org.jboss.msc.Service.newInstance(upgradeHandlerConsumer, upgradeHandler));
        builder.install();
        for (ListenerRegistry.Listener listener : listeners) {
            listener.addHttpUpgradeMetadata(new ListenerRegistry.HttpUpgradeMetadata(JBOSS_REMOTING, MANAGEMENT_ENDPOINT));
        }

        if (listenerRegistrySupplier.get() != null) {
            for(ListenerRegistry.Listener listener : listeners) {
                listenerRegistrySupplier.get().addListener(listener);
            }
        }

        try {
            serverManagement = ManagementHttpServer.builder()
                    .setBindAddress(bindAddress)
                    .setSecureBindAddress(secureBindAddress)
                    .setModelController(modelController)
                    .setSecurityRealm(securityRealm)
                    .setSSLContext(sslContext)
                    .setSSLClientAuthMode(sslClientAuthMode)
                    .setHttpAuthenticationFactory(httpAuthenticationFactory)
                    .setControlledProcessStateService(controlledProcessStateService)
                    .setConsoleMode(consoleMode)
                    .setConsoleSlot(consoleSlot)
                    .setChannelUpgradeHandler(upgradeHandler)
                    .setManagementHttpRequestProcessor(requestProcessorSupplier.get())
                    .setAllowedOrigins(allowedOrigins)
                    .setWorker(workerSupplier.get())
                    .setExecutor(executorSupplier.get())
                    .build();

            serverManagement.start();

            // Register the now-created sockets with the SBM
            if (socketBindingManager != null) {
                if (useUnmanagedBindings) {
                    SocketBindingManager.UnnamedBindingRegistry registry = socketBindingManager.getUnnamedRegistry();
                    if (bindAddress != null) {
                        final InetSocketAddress boundAddress = serverManagement.getLocalAddress(InetSocketAddress.class);
                        basicManagedBinding = ManagedBinding.Factory.createSimpleManagedBinding("management-http", boundAddress, null);
                        registry.registerBinding(basicManagedBinding);
                    }
                    if (secureBindAddress != null) {
                        final InetSocketAddress boundAddress = serverManagement.getSecureLocalAddress(InetSocketAddress.class);
                        secureManagedBinding = ManagedBinding.Factory.createSimpleManagedBinding("management-https", boundAddress, null);
                        registry.registerBinding(secureManagedBinding);
                    }
                } else {
                    SocketBindingManager.NamedManagedBindingRegistry registry = socketBindingManager.getNamedRegistry();
                    if (basicBinding != null) {
                        final InetSocketAddress boundAddress = serverManagement.getLocalAddress(InetSocketAddress.class);
                        basicManagedBinding = ManagedBinding.Factory.createSimpleManagedBinding(basicBinding.getName(), boundAddress, null);
                        registry.registerBinding(basicManagedBinding);
                    }
                    if (secureBinding != null) {
                        final InetSocketAddress boundAddress = serverManagement.getSecureLocalAddress(InetSocketAddress.class);
                        secureManagedBinding = ManagedBinding.Factory.createSimpleManagedBinding(secureBinding.getName(), boundAddress, null);
                        registry.registerBinding(secureManagedBinding);
                    }
                }
            }
        } catch (Exception e) {
            Throwable cause = e.getCause();
            if (e instanceof BindException || cause instanceof BindException) {
                final StringBuilder sb = new StringBuilder().append(e.getLocalizedMessage());
                if (bindAddress != null)
                    sb.append(" ").append(bindAddress);
                if (secureBindAddress != null)
                    sb.append(" ").append(secureBindAddress);
                throw new StartException(sb.toString());
            } else {
                throw ServerLogger.ROOT_LOGGER.failedToStartHttpManagementService(e);
            }
        }
        httpManagementConsumer.accept(httpManagement);
    }
555625
public static ClientRequestContextBuilder of(RpcRequest request, String uri) {
        return of(request, URI.create(requireNonNull(uri, "uri")));
    }
1163806
public static void beforeRequest (@Nonnull final HttpUriRequest aRequest, @Nullable final HttpContext aHttpContext)
  {
    if (isEnabled ())
      if (LOGGER.isInfoEnabled ())
        LOGGER.info ("Before HTTP call: " +
                        aRequest.getMethod () +
                        " " +
                        aRequest.getURI () +
                        (aHttpContext != null ? " (with special HTTP context)" : ""));
  }
1250308
public <T> T executeInApplicationContext(Callable<T> callable) throws Exception {
        ApplicationContext context = (ApplicationContext) getScopedContext(ApplicationScoped.class);
        boolean activatedByUs = false;
        try {
            if (!context.isActive()) {
                context.activate();
                activatedByUs = true;
            }
            return callable.call();
        } finally {
            if (activatedByUs && context.isActive()) {
                context.deactivate();
            }
        }
    }
667035
public void beginContext(ServletContext context, ServletRequest req, ServletResponse resp)
    {
        pushRequestContext(context, req, resp);
        super.beginContext();
    }
1278543
public static RequestContextV1 get() {
        RequestContextV1 ret = CURRENT_CONTEXT.get();

        if (ret == null) {
            ret = new RequestContextV1();
            CURRENT_CONTEXT.set(ret);
        }

        return ret;
    }
1343968
private synchronized void pushRequestContext(ServletContext context,
                                                 ServletRequest req,
                                                 ServletResponse resp)
    {
        getRequestStack().push(new RequestContext(context, req, resp));
    }
847498
protected Service resolveServiceFromAuthenticationRequest(final RequestContext context) {
        val ctxService = WebUtils.getService(context);
        return resolveServiceFromAuthenticationRequest(ctxService);
    }
794362
protected void activate(final ComponentContext context)
			throws InvalidSyntaxException {
		log.info("activate");

		bundleContext = context.getBundleContext();

		sl = new ServiceListener() {
			public void serviceChanged(ServiceEvent event) {
				if (event.getType() == ServiceEvent.UNREGISTERING) {
					cache.unregisterComponentBindingsProvider(event
							.getServiceReference());
				} else if (event.getType() == ServiceEvent.REGISTERED) {
					cache.registerComponentBindingsProvider(event
							.getServiceReference());
				}
			}
		};
		bundleContext.addServiceListener(sl, "(" + Constants.OBJECTCLASS + "="
				+ ComponentBindingsProvider.class.getName() + ")");
		reloadCache();
		log.info("Activation successful");
	}
982791
public static void putServiceResponseIntoRequestScope(final RequestContext requestContext, final Response response) {
        requestContext.getRequestScope().put("parameters", response.getAttributes());
        putServiceRedirectUrl(requestContext, response.getUrl());
    }
1035250
public com.google.api.ads.adwords.axis.v201809.cm.RequestContextOperandContextType getContextType() {
        return contextType;
    }