Search in sources :

Example 1 with ServletRequestAttributeEvent

use of jakarta.servlet.ServletRequestAttributeEvent in project tomcat by apache.

the class Request method notifyAttributeRemoved.

/**
 * Notify interested listeners that attribute has been removed.
 *
 * @param name Attribute name
 * @param value Attribute value
 */
private void notifyAttributeRemoved(String name, Object value) {
    Context context = getContext();
    Object[] listeners = context.getApplicationEventListeners();
    if ((listeners == null) || (listeners.length == 0)) {
        return;
    }
    ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value);
    for (Object o : listeners) {
        if (!(o instanceof ServletRequestAttributeListener)) {
            continue;
        }
        ServletRequestAttributeListener listener = (ServletRequestAttributeListener) o;
        try {
            listener.attributeRemoved(event);
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            // Error valve will pick this exception up and display it to user
            attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
            context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
        }
    }
}
Also used : ServletRequestContext(org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext) ServletContext(jakarta.servlet.ServletContext) AsyncContext(jakarta.servlet.AsyncContext) Context(org.apache.catalina.Context) ServletRequestAttributeListener(jakarta.servlet.ServletRequestAttributeListener) ServletRequestAttributeEvent(jakarta.servlet.ServletRequestAttributeEvent)

Example 2 with ServletRequestAttributeEvent

use of jakarta.servlet.ServletRequestAttributeEvent in project tomcat by apache.

the class Request method notifyAttributeAssigned.

/**
 * Notify interested listeners that attribute has been assigned a value.
 *
 * @param name Attribute name
 * @param value New attribute value
 * @param oldValue Old attribute value
 */
private void notifyAttributeAssigned(String name, Object value, Object oldValue) {
    Context context = getContext();
    if (context == null) {
        return;
    }
    Object[] listeners = context.getApplicationEventListeners();
    if ((listeners == null) || (listeners.length == 0)) {
        return;
    }
    boolean replaced = (oldValue != null);
    ServletRequestAttributeEvent event = null;
    if (replaced) {
        event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, oldValue);
    } else {
        event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value);
    }
    for (Object o : listeners) {
        if (!(o instanceof ServletRequestAttributeListener)) {
            continue;
        }
        ServletRequestAttributeListener listener = (ServletRequestAttributeListener) o;
        try {
            if (replaced) {
                listener.attributeReplaced(event);
            } else {
                listener.attributeAdded(event);
            }
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            // Error valve will pick this exception up and display it to user
            attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
            context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
        }
    }
}
Also used : ServletRequestContext(org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext) ServletContext(jakarta.servlet.ServletContext) AsyncContext(jakarta.servlet.AsyncContext) Context(org.apache.catalina.Context) ServletRequestAttributeListener(jakarta.servlet.ServletRequestAttributeListener) ServletRequestAttributeEvent(jakarta.servlet.ServletRequestAttributeEvent)

Aggregations

AsyncContext (jakarta.servlet.AsyncContext)2 ServletContext (jakarta.servlet.ServletContext)2 ServletRequestAttributeEvent (jakarta.servlet.ServletRequestAttributeEvent)2 ServletRequestAttributeListener (jakarta.servlet.ServletRequestAttributeListener)2 Context (org.apache.catalina.Context)2 ServletRequestContext (org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext)2