use of org.apache.catalina.Valve in project tomcat by apache.
the class StandardEngineSF method storeChildren.
/**
* Store the specified Engine properties.
*
* @param aWriter
* PrintWriter to which we are storing
* @param indent
* Number of spaces to indent this element
* @param aEngine
* Object whose properties are being stored
*
* @exception Exception
* if an exception occurs while storing
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aEngine, StoreDescription parentDesc) throws Exception {
if (aEngine instanceof StandardEngine) {
StandardEngine engine = (StandardEngine) aEngine;
// Store nested <Listener> elements
LifecycleListener[] listeners = engine.findLifecycleListeners();
storeElementArray(aWriter, indent, listeners);
// Store nested <Realm> element
Realm realm = engine.getRealm();
Realm parentRealm = null;
// TODO is this case possible? (see it a old Server 5.0 impl)
if (engine.getParent() != null) {
parentRealm = engine.getParent().getRealm();
}
if (realm != parentRealm) {
storeElement(aWriter, indent, realm);
}
// Store nested <Valve> elements
Valve[] valves = engine.getPipeline().getValves();
if (valves != null && valves.length > 0) {
List<Valve> engineValves = new ArrayList<>();
for (Valve valve : valves) {
if (!(valve instanceof ClusterValve)) {
engineValves.add(valve);
}
}
storeElementArray(aWriter, indent, engineValves.toArray());
}
// store all <Cluster> elements
Cluster cluster = engine.getCluster();
if (cluster != null) {
storeElement(aWriter, indent, cluster);
}
// store all <Host> elements
Container[] children = engine.findChildren();
storeElementArray(aWriter, indent, children);
}
}
use of org.apache.catalina.Valve in project tomcat by apache.
the class AsyncContextImpl method setErrorState.
public void setErrorState(Throwable t, boolean fireOnError) {
if (t != null) {
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
}
request.getCoyoteRequest().action(ActionCode.ASYNC_ERROR, null);
if (fireOnError) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("asyncContextImpl.fireOnError"));
}
AsyncEvent errorEvent = new AsyncEvent(event.getAsyncContext(), event.getSuppliedRequest(), event.getSuppliedResponse(), t);
List<AsyncListenerWrapper> listenersCopy = new ArrayList<>(listeners);
for (AsyncListenerWrapper listener : listenersCopy) {
try {
listener.fireOnError(errorEvent);
} catch (Throwable t2) {
ExceptionUtils.handleThrowable(t2);
log.warn(sm.getString("asyncContextImpl.onErrorError", listener.getClass().getName()), t2);
}
}
}
AtomicBoolean result = new AtomicBoolean();
request.getCoyoteRequest().action(ActionCode.ASYNC_IS_ERROR, result);
if (result.get()) {
// No listener called dispatch() or complete(). This is an error.
// SRV.2.3.3.3 (search for "error dispatch")
// Take a local copy to avoid threading issues if another thread
// clears this (can happen during error handling with non-container
// threads)
ServletResponse servletResponse = this.servletResponse;
if (servletResponse instanceof HttpServletResponse) {
((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
Host host = (Host) context.getParent();
Valve stdHostValve = host.getPipeline().getBasic();
if (stdHostValve instanceof StandardHostValve) {
((StandardHostValve) stdHostValve).throwable(request, request.getResponse(), t);
}
request.getCoyoteRequest().action(ActionCode.ASYNC_IS_ERROR, result);
if (result.get()) {
// Still in the error state. The error page did not call
// complete() or dispatch(). Complete the async processing.
complete();
}
}
}
use of org.apache.catalina.Valve in project tomcat by apache.
the class ContainerMBean method removeValve.
/**
* Remove an existing Valve.
*
* @param valveName MBean Name of the Valve to remove
*
* @exception MBeanException if a component cannot be removed
*/
public void removeValve(String valveName) throws MBeanException {
Container container = doGetManagedResource();
ObjectName oname;
try {
oname = new ObjectName(valveName);
} catch (MalformedObjectNameException | NullPointerException e) {
throw new MBeanException(e);
}
if (container != null) {
Valve[] valves = container.getPipeline().getValves();
for (Valve valve : valves) {
if (valve instanceof JmxEnabled) {
ObjectName voname = ((JmxEnabled) valve).getObjectName();
if (voname.equals(oname)) {
container.getPipeline().removeValve(valve);
}
}
}
}
}
use of org.apache.catalina.Valve in project tomcat by apache.
the class OpenWebBeansContextLifecycleListener method lifecycleEvent.
@Override
public void lifecycleEvent(LifecycleEvent event) {
if (event.getSource() instanceof Context) {
Context context = (Context) event.getSource();
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
if (getStartWithoutBeansXml() || context.getResources().getResource("/WEB-INF/beans.xml").exists() || context.getResources().getResource("/WEB-INF/classes/META-INF/beans.xml").exists()) {
// Registering ELResolver with JSP container
System.setProperty("org.apache.webbeans.application.jsp", "true");
// Add Listeners
String[] oldListeners = context.findApplicationListeners();
LinkedList<String> listeners = new LinkedList<>();
listeners.addFirst(WebBeansConfigurationListener.class.getName());
for (String listener : oldListeners) {
listeners.add(listener);
context.removeApplicationListener(listener);
}
for (String listener : listeners) {
context.addApplicationListener(listener);
}
Pipeline pipeline = context.getPipeline();
// Add to the corresponding pipeline to get a notification once configure is done
if (pipeline instanceof Lifecycle) {
boolean contextLifecycleListenerFound = false;
for (LifecycleListener listener : ((Lifecycle) pipeline).findLifecycleListeners()) {
if (listener instanceof OpenWebBeansContextLifecycleListener) {
contextLifecycleListenerFound = true;
}
}
if (!contextLifecycleListenerFound) {
((Lifecycle) pipeline).addLifecycleListener(this);
}
}
if (getAddSecurityValve()) {
// Add security valve
boolean securityValveFound = false;
for (Valve valve : pipeline.getValves()) {
if (valve instanceof OpenWebBeansSecurityValve) {
securityValveFound = true;
}
}
if (!securityValveFound) {
pipeline.addValve(new OpenWebBeansSecurityValve());
}
}
}
}
} else if (event.getSource() instanceof Pipeline && event.getType().equals(Lifecycle.START_EVENT)) {
// This notification occurs once the configuration is fully done, including naming resources setup
// Otherwise, the instance manager is not ready for creation
Pipeline pipeline = (Pipeline) event.getSource();
if (pipeline.getContainer() instanceof Context) {
Context context = (Context) pipeline.getContainer();
if (!(context.getInstanceManager() instanceof OpenWebBeansInstanceManager)) {
InstanceManager processor = context.getInstanceManager();
if (processor == null) {
processor = context.createInstanceManager();
}
InstanceManager custom = new OpenWebBeansInstanceManager(context.getLoader().getClassLoader(), processor);
context.setInstanceManager(custom);
}
}
}
}
use of org.apache.catalina.Valve in project tomcat by apache.
the class TestCrawlerSessionManagerValve method testCrawlerIpsNegative.
@Test
public void testCrawlerIpsNegative() throws Exception {
CrawlerSessionManagerValve valve = new CrawlerSessionManagerValve();
valve.setCrawlerIps("216\\.58\\.206\\.174");
valve.setCrawlerUserAgents(valve.getCrawlerUserAgents());
valve.setNext(EasyMock.createMock(Valve.class));
HttpSession session = createSessionExpectations(valve, false);
Request request = createRequestExpectations("127.0.0.1", session, false);
EasyMock.replay(request, session);
valve.invoke(request, EasyMock.createMock(Response.class));
EasyMock.verify(request, session);
}
Aggregations