javax.servlet.ServletRequestAttributeListener Java Examples
The following examples show how to use
javax.servlet.ServletRequestAttributeListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Request.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * 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 (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletRequestAttributeListener)) { continue; } ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i]; 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); } } }
Example #2
Source File: DefaultWebApplication.java From piranha with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Add the listener. * * @param <T> the type. * @param listener the listener */ @Override public <T extends EventListener> void addListener(T listener) { if (listener instanceof ServletContextListener) { contextListeners.add((ServletContextListener) listener); } if (listener instanceof ServletContextAttributeListener) { contextAttributeListeners.add((ServletContextAttributeListener) listener); } if (listener instanceof ServletRequestListener) { requestListeners.add((ServletRequestListener) listener); } if (listener instanceof ServletRequestAttributeListener) { httpRequestManager.addListener((ServletRequestAttributeListener) listener); } if (listener instanceof HttpSessionAttributeListener) { httpSessionManager.addListener(listener); } if (listener instanceof HttpSessionIdListener) { httpSessionManager.addListener(listener); } if (listener instanceof HttpSessionListener) { httpSessionManager.addListener(listener); } }
Example #3
Source File: DefaultWebApplication.java From piranha with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create the listener. * * @param <T> the type. * @param clazz the class of the listener to create. * @return the listener. * @throws ServletException when it fails to create the listener. */ @Override public <T extends EventListener> T createListener(Class<T> clazz) throws ServletException { T result = objectInstanceManager.createListener(clazz); boolean ok = false; if (result instanceof ServletContextListener || result instanceof ServletContextAttributeListener || result instanceof ServletRequestListener || result instanceof ServletRequestAttributeListener || result instanceof HttpSessionAttributeListener || result instanceof HttpSessionIdListener || result instanceof HttpSessionListener) { ok = true; } if (!ok) { LOGGER.log(WARNING, "Unable to create listener: {0}", clazz); throw new IllegalArgumentException("Invalid type"); } return result; }
Example #4
Source File: Request.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Notify interested listeners that attribute has been removed. */ private void notifyAttributeRemoved(String name, Object value) { Object listeners[] = context.getApplicationEventListeners(); if ((listeners == null) || (listeners.length == 0)) { return; } ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletRequestAttributeListener)) { continue; } ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i]; try { listener.attributeRemoved(event); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t); // Error valve will pick this exception up and display it to user attributes.put(RequestDispatcher.ERROR_EXCEPTION, t); } } }
Example #5
Source File: Request.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Notify interested listeners that attribute has been removed. */ private void notifyAttributeRemoved(String name, Object value) { Object listeners[] = context.getApplicationEventListeners(); if ((listeners == null) || (listeners.length == 0)) { return; } ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(), name, value); for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof ServletRequestAttributeListener)) { continue; } ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i]; try { listener.attributeRemoved(event); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t); // Error valve will pick this exception up and display it to user attributes.put(RequestDispatcher.ERROR_EXCEPTION, t); } } }
Example #6
Source File: WebContext.java From tomee with Apache License 2.0 | 6 votes |
private static boolean isWeb(final Class<?> beanClass) { if (Servlet.class.isAssignableFrom(beanClass) || Filter.class.isAssignableFrom(beanClass)) { return true; } if (EventListener.class.isAssignableFrom(beanClass)) { return HttpSessionAttributeListener.class.isAssignableFrom(beanClass) || ServletContextListener.class.isAssignableFrom(beanClass) || ServletRequestListener.class.isAssignableFrom(beanClass) || ServletContextAttributeListener.class.isAssignableFrom(beanClass) || HttpSessionListener.class.isAssignableFrom(beanClass) || HttpSessionBindingListener.class.isAssignableFrom(beanClass) || HttpSessionActivationListener.class.isAssignableFrom(beanClass) || HttpSessionIdListener.class.isAssignableFrom(beanClass) || ServletRequestAttributeListener.class.isAssignableFrom(beanClass); } return false; }
Example #7
Source File: ApplicationContext.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public <T extends EventListener> void addListener(T t) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException( sm.getString("applicationContext.addListener.ise", getContextPath())); } boolean match = false; if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestListener || t instanceof ServletRequestAttributeListener || t instanceof HttpSessionIdListener || t instanceof HttpSessionAttributeListener) { context.addApplicationEventListener(t); match = true; } if (t instanceof HttpSessionListener || (t instanceof ServletContextListener && newServletContextListenerAllowed)) { // Add listener directly to the list of instances rather than to // the list of class names. context.addApplicationLifecycleListener(t); match = true; } if (match) return; if (t instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.sclNotAllowed", t.getClass().getName())); } else { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.wrongType", t.getClass().getName())); } }
Example #8
Source File: ApplicationListeners.java From quarkus-http with Apache License 2.0 | 5 votes |
public void servletRequestAttributeAdded(final HttpServletRequest request, final String name, final Object value) { if(!started || servletContextAttributeListeners.length == 0) { return; } final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value); for (int i = 0; i < servletRequestAttributeListeners.length; ++i) { this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeAdded(sre); } }
Example #9
Source File: ApplicationListeners.java From quarkus-http with Apache License 2.0 | 5 votes |
public void servletRequestAttributeRemoved(final HttpServletRequest request, final String name, final Object value) { if(!started || servletContextAttributeListeners.length == 0) { return; } final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value); for (int i = 0; i < servletRequestAttributeListeners.length; ++i) { this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeRemoved(sre); } }
Example #10
Source File: ApplicationListeners.java From quarkus-http with Apache License 2.0 | 5 votes |
public void servletRequestAttributeReplaced(final HttpServletRequest request, final String name, final Object value) { if(!started || servletContextAttributeListeners.length == 0) { return; } final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value); for (int i = 0; i < servletRequestAttributeListeners.length; ++i) { this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeReplaced(sre); } }
Example #11
Source File: ApplicationContext.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public <T extends EventListener> void addListener(T t) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException( sm.getString("applicationContext.addListener.ise", getContextPath())); } boolean match = false; if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestListener || t instanceof ServletRequestAttributeListener || t instanceof HttpSessionAttributeListener) { context.addApplicationEventListener(t); match = true; } if (t instanceof HttpSessionListener || (t instanceof ServletContextListener && newServletContextListenerAllowed)) { // Add listener directly to the list of instances rather than to // the list of class names. context.addApplicationLifecycleListener(t); match = true; } if (match) return; if (t instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.sclNotAllowed", t.getClass().getName())); } else { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.wrongType", t.getClass().getName())); } }
Example #12
Source File: ApplicationListeners.java From lams with GNU General Public License v2.0 | 5 votes |
public void servletRequestAttributeAdded(final HttpServletRequest request, final String name, final Object value) { if(!started) { return; } final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value); for (int i = 0; i < servletRequestAttributeListeners.length; ++i) { this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeAdded(sre); } }
Example #13
Source File: ApplicationListeners.java From lams with GNU General Public License v2.0 | 5 votes |
public void servletRequestAttributeRemoved(final HttpServletRequest request, final String name, final Object value) { if(!started) { return; } final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value); for (int i = 0; i < servletRequestAttributeListeners.length; ++i) { this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeRemoved(sre); } }
Example #14
Source File: ApplicationListeners.java From lams with GNU General Public License v2.0 | 5 votes |
public void servletRequestAttributeReplaced(final HttpServletRequest request, final String name, final Object value) { if(!started) { return; } final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value); for (int i = 0; i < servletRequestAttributeListeners.length; ++i) { this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeReplaced(sre); } }
Example #15
Source File: ApplicationContext.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public <T extends EventListener> void addListener(T t) { if (!context.getState().equals(LifecycleState.STARTING_PREP)) { throw new IllegalStateException( sm.getString("applicationContext.addListener.ise", getContextPath())); } boolean match = false; if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestListener || t instanceof ServletRequestAttributeListener || t instanceof HttpSessionAttributeListener) { context.addApplicationEventListener(t); match = true; } if (t instanceof HttpSessionListener || (t instanceof ServletContextListener && newServletContextListenerAllowed)) { // Add listener directly to the list of instances rather than to // the list of class names. context.addApplicationLifecycleListener(t); match = true; } if (match) return; if (t instanceof ServletContextListener) { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.sclNotAllowed", t.getClass().getName())); } else { throw new IllegalArgumentException(sm.getString( "applicationContext.addListener.iae.wrongType", t.getClass().getName())); } }
Example #16
Source File: DefaultHttpRequestManager.java From piranha with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public <T extends EventListener> void addListener(T listener) { if (listener instanceof ServletRequestAttributeListener) { attributeListeners.add((ServletRequestAttributeListener) listener); } }