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);
}
}
}
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;
}
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");
}
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]);
}
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);
}
Aggregations