Search in sources :

Example 36 with Valve

use of org.apache.catalina.Valve in project tomcat by apache.

the class SimpleTcpCluster method unregisterClusterValve.

/**
 * unregister all cluster valve to host or engine
 */
protected void unregisterClusterValve() {
    for (Valve v : valves) {
        ClusterValve valve = (ClusterValve) v;
        if (log.isDebugEnabled()) {
            log.debug("Invoking removeValve on " + getContainer() + " with class=" + valve.getClass().getName());
        }
        if (valve != null) {
            container.getPipeline().removeValve(valve);
            valve.setCluster(null);
        }
    }
}
Also used : Valve(org.apache.catalina.Valve) JvmRouteBinderValve(org.apache.catalina.ha.session.JvmRouteBinderValve) ClusterValve(org.apache.catalina.ha.ClusterValve) ClusterValve(org.apache.catalina.ha.ClusterValve)

Example 37 with Valve

use of org.apache.catalina.Valve in project meecrowave by apache.

the class Meecrowave method buildValves.

/**
 * Syntax uses:
 * <code>
 * valves.myValve1._className = org.apache.meecrowave.tomcat.LoggingAccessLogPattern
 * valves.myValve1._order = 0
 * <p>
 * valves.myValve1._className = SSOVa
 * valves.myValve1._order = 1
 * valves.myValve1.showReportInfo = false
 * </code>
 *
 * @return the list of valve from the properties.
 */
private List<Valve> buildValves() {
    final List<Valve> valves = new ArrayList<>();
    configuration.getProperties().stringPropertyNames().stream().filter(key -> key.startsWith("valves.") && key.endsWith("._className")).sorted(comparing(key -> Integer.parseInt(configuration.getProperties().getProperty(key.replaceFirst("\\._className$", "._order"), "0")))).map(key -> key.split("\\.")).filter(parts -> parts.length == 3).forEach(key -> {
        final String prefix = key[0] + '.' + key[1] + '.';
        final ObjectRecipe recipe = newRecipe(configuration.getProperties().getProperty(prefix + key[2]));
        configuration.getProperties().stringPropertyNames().stream().filter(it -> it.startsWith(prefix) && !it.endsWith("._order") && !it.endsWith("._className")).forEach(propKey -> {
            final String value = configuration.getProperties().getProperty(propKey);
            recipe.setProperty(propKey.substring(prefix.length()), value);
        });
        valves.add(Valve.class.cast(recipe.create(Thread.currentThread().getContextClassLoader())));
    });
    return valves;
}
Also used : MeecrowaveContextConfig(org.apache.meecrowave.tomcat.MeecrowaveContextConfig) ProvidedLoader(org.apache.meecrowave.tomcat.ProvidedLoader) SessionCookieConfig(javax.servlet.SessionCookieConfig) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection) SecretKeySpec(javax.crypto.spec.SecretKeySpec) ServerSocket(java.net.ServerSocket) URLClassLoader(java.net.URLClassLoader) Host(org.apache.catalina.Host) StopListening(org.apache.meecrowave.api.StopListening) Map(java.util.Map) SAXParser(javax.xml.parsers.SAXParser) Path(java.nio.file.Path) Log4j2Log(org.apache.meecrowave.logging.tomcat.Log4j2Log) LifecycleException(org.apache.catalina.LifecycleException) Set(java.util.Set) CDI(javax.enterprise.inject.spi.CDI) CDIInstanceManager(org.apache.meecrowave.tomcat.CDIInstanceManager) StandardCharsets(java.nio.charset.StandardCharsets) WebBeansContext(org.apache.webbeans.config.WebBeansContext) ResourceFinder(org.apache.xbean.finder.ResourceFinder) Stream(java.util.stream.Stream) ConfigurableBus(org.apache.meecrowave.cxf.ConfigurableBus) JarScanFilter(org.apache.tomcat.JarScanFilter) Log4j2s(org.apache.meecrowave.logging.log4j2.Log4j2s) TomcatAutoInitializer(org.apache.meecrowave.tomcat.TomcatAutoInitializer) Log4j2Logger(org.apache.meecrowave.logging.jul.Log4j2Logger) Connector(org.apache.catalina.connector.Connector) StandardHost(org.apache.catalina.core.StandardHost) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) CreationalContext(javax.enterprise.context.spi.CreationalContext) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) StreamSupport(java.util.stream.StreamSupport) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) ManagementFactory(java.lang.management.ManagementFactory) Properties(java.util.Properties) LogFacade(org.apache.meecrowave.logging.tomcat.LogFacade) Files(java.nio.file.Files) Cxfs(org.apache.meecrowave.cxf.Cxfs) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ValueTransformer(org.apache.meecrowave.service.ValueTransformer) Field(java.lang.reflect.Field) File(java.io.File) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) DefaultHandler(org.xml.sax.helpers.DefaultHandler) StringReader(java.io.StringReader) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) Pipeline(org.apache.catalina.Pipeline) BeanManager(javax.enterprise.inject.spi.BeanManager) URL(java.net.URL) Lifecycle(org.apache.catalina.Lifecycle) Priotities(org.apache.meecrowave.service.Priotities) Catalina(org.apache.catalina.startup.Catalina) OWBJarScanner(org.apache.meecrowave.tomcat.OWBJarScanner) Http2Protocol(org.apache.coyote.http2.Http2Protocol) IO(org.apache.meecrowave.io.IO) LifecycleState(org.apache.catalina.LifecycleState) Collectors.toSet(java.util.stream.Collectors.toSet) Server(org.apache.catalina.Server) StartListening(org.apache.meecrowave.api.StartListening) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) StandardSessionIdGenerator(org.apache.catalina.util.StandardSessionIdGenerator) ServiceLoader(java.util.ServiceLoader) Substitutor(org.apache.meecrowave.lang.Substitutor) Objects(java.util.Objects) Base64(java.util.Base64) List(java.util.List) Realm(org.apache.catalina.Realm) SAXException(org.xml.sax.SAXException) Writer(java.io.Writer) StandardContext(org.apache.catalina.core.StandardContext) OWBAutoSetup(org.apache.meecrowave.openwebbeans.OWBAutoSetup) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Valve(org.apache.catalina.Valve) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Cipher(javax.crypto.Cipher) Option(org.apache.xbean.recipe.Option) BiPredicate(java.util.function.BiPredicate) ServletContainerInitializer(javax.servlet.ServletContainerInitializer) Log4j2Shutdown(org.apache.meecrowave.logging.log4j2.Log4j2Shutdown) Attributes(org.xml.sax.Attributes) Comparator.comparing(java.util.Comparator.comparing) ROOT(java.util.Locale.ROOT) InjectionTarget(javax.enterprise.inject.spi.InjectionTarget) CxfCdiAutoSetup(org.apache.meecrowave.cxf.CxfCdiAutoSetup) OutputStream(java.io.OutputStream) Collections.emptySet(java.util.Collections.emptySet) MalformedURLException(java.net.MalformedURLException) Log4j2LoggerFactory(org.apache.meecrowave.logging.openwebbeans.Log4j2LoggerFactory) Optional.ofNullable(java.util.Optional.ofNullable) LoggingAccessLogPattern(org.apache.meecrowave.tomcat.LoggingAccessLogPattern) FileWriter(java.io.FileWriter) Globals(org.apache.catalina.Globals) Configuration(org.apache.meecrowave.configuration.Configuration) StandardManager(org.apache.catalina.session.StandardManager) FileInputStream(java.io.FileInputStream) Context(org.apache.catalina.Context) Registry(org.apache.tomcat.util.modeler.Registry) Consumer(java.util.function.Consumer) Tomcat(org.apache.catalina.startup.Tomcat) Collectors.toList(java.util.stream.Collectors.toList) InputStream(java.io.InputStream) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) ArrayList(java.util.ArrayList) Valve(org.apache.catalina.Valve)

Example 38 with Valve

use of org.apache.catalina.Valve in project spring-boot by spring-projects.

the class DefaultServletWebServerFactoryCustomizerTests method customTomcatRemoteIpValve.

@Test
public void customTomcatRemoteIpValve() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.remote_ip_header", "x-my-remote-ip-header");
    map.put("server.tomcat.protocol_header", "x-my-protocol-header");
    map.put("server.tomcat.internal_proxies", "192.168.0.1");
    map.put("server.tomcat.port-header", "x-my-forward-port");
    map.put("server.tomcat.protocol-header-https-value", "On");
    bindProperties(map);
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    this.customizer.customize(factory);
    assertThat(factory.getEngineValves()).hasSize(1);
    Valve valve = factory.getEngineValves().iterator().next();
    assertThat(valve).isInstanceOf(RemoteIpValve.class);
    RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
    assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("x-my-protocol-header");
    assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("On");
    assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("x-my-remote-ip-header");
    assertThat(remoteIpValve.getPortHeader()).isEqualTo("x-my-forward-port");
    assertThat(remoteIpValve.getInternalProxies()).isEqualTo("192.168.0.1");
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) HashMap(java.util.HashMap) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) Test(org.junit.Test)

Example 39 with Valve

use of org.apache.catalina.Valve in project tomcat70 by apache.

the class StandardPipeline method getValves.

/**
 * Return the set of Valves in the pipeline associated with this
 * Container, including the basic Valve (if any).  If there are no
 * such Valves, a zero-length array is returned.
 */
@Override
public Valve[] getValves() {
    ArrayList<Valve> valveList = new ArrayList<Valve>();
    Valve current = first;
    if (current == null) {
        current = basic;
    }
    while (current != null) {
        valveList.add(current);
        current = current.getNext();
    }
    return valveList.toArray(new Valve[0]);
}
Also used : ArrayList(java.util.ArrayList) Valve(org.apache.catalina.Valve)

Example 40 with Valve

use of org.apache.catalina.Valve in project tomcat70 by apache.

the class StandardPipeline method removeValve.

/**
 * Remove the specified Valve from the pipeline associated with this
 * Container, if it is found; otherwise, do nothing.  If the Valve is
 * found and removed, the Valve's <code>setContainer(null)</code> method
 * will be called if it implements <code>Contained</code>.
 *
 * @param valve Valve to be removed
 */
@Override
public void removeValve(Valve valve) {
    Valve current;
    if (first == valve) {
        first = first.getNext();
        current = null;
    } else {
        current = first;
    }
    while (current != null) {
        if (current.getNext() == valve) {
            current.setNext(valve.getNext());
            break;
        }
        current = current.getNext();
    }
    if (first == basic)
        first = null;
    if (valve instanceof Contained)
        ((Contained) valve).setContainer(null);
    if (valve instanceof Lifecycle) {
        // Stop this valve if necessary
        if (getState().isAvailable()) {
            try {
                ((Lifecycle) valve).stop();
            } catch (LifecycleException e) {
                log.error("StandardPipeline.removeValve: stop: ", e);
            }
        }
        try {
            ((Lifecycle) valve).destroy();
        } catch (LifecycleException e) {
            log.error("StandardPipeline.removeValve: destroy: ", e);
        }
    }
    container.fireContainerEvent(Container.REMOVE_VALVE_EVENT, valve);
}
Also used : Contained(org.apache.catalina.Contained) LifecycleException(org.apache.catalina.LifecycleException) Lifecycle(org.apache.catalina.Lifecycle) Valve(org.apache.catalina.Valve)

Aggregations

Valve (org.apache.catalina.Valve)72 ArrayList (java.util.ArrayList)15 Lifecycle (org.apache.catalina.Lifecycle)14 Container (org.apache.catalina.Container)13 LifecycleException (org.apache.catalina.LifecycleException)13 Pipeline (org.apache.catalina.Pipeline)11 ObjectName (javax.management.ObjectName)9 Realm (org.apache.catalina.Realm)8 AccessLogValve (org.apache.catalina.valves.AccessLogValve)8 Contained (org.apache.catalina.Contained)7 LifecycleListener (org.apache.catalina.LifecycleListener)7 Request (org.apache.catalina.connector.Request)7 ClusterValve (org.apache.catalina.ha.ClusterValve)7 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)7 Test (org.junit.Test)7 Context (org.apache.catalina.Context)6 JmxEnabled (org.apache.catalina.JmxEnabled)6 Response (org.apache.catalina.connector.Response)6 IOException (java.io.IOException)5 ContainerBase (org.apache.catalina.core.ContainerBase)5