javax.servlet.http.HttpSessionBindingListener Java Examples
The following examples show how to use
javax.servlet.http.HttpSessionBindingListener.
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: 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 #2
Source File: MockHttpSession.java From java-technology-stack with MIT License | 6 votes |
@Override public void setAttribute(String name, @Nullable Object value) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); if (value != null) { Object oldValue = this.attributes.put(name, value); if (value != oldValue) { if (oldValue instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } } else { removeAttribute(name); } }
Example #3
Source File: SessionListenerBridge.java From quarkus-http with Apache License 2.0 | 6 votes |
@Override public void attributeUpdated(final Session session, final String name, final Object value, final Object old) { if (name.startsWith(IO_UNDERTOW)) { return; } final HttpSessionImpl httpSession = SecurityActions.forSession(session, servletContext, false); if (old != value) { if (old instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) old).valueUnbound(new HttpSessionBindingEvent(httpSession, name, old)); } applicationListeners.httpSessionAttributeReplaced(httpSession, name, old); } if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(httpSession, name, value)); } }
Example #4
Source File: MockHttpSession.java From spring-analysis-note with MIT License | 6 votes |
@Override public void setAttribute(String name, @Nullable Object value) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); if (value != null) { Object oldValue = this.attributes.put(name, value); if (value != oldValue) { if (oldValue instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } } else { removeAttribute(name); } }
Example #5
Source File: MockHttpSession.java From spring-analysis-note with MIT License | 6 votes |
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #6
Source File: MockHttpSession.java From spring-analysis-note with MIT License | 6 votes |
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #7
Source File: MockHttpSession.java From java-technology-stack with MIT License | 6 votes |
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #8
Source File: MockHttpSession.java From java-technology-stack with MIT License | 6 votes |
@Override public void setAttribute(String name, @Nullable Object value) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); if (value != null) { Object oldValue = this.attributes.put(name, value); if (value != oldValue) { if (oldValue instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } } else { removeAttribute(name); } }
Example #9
Source File: MockHttpSession.java From java-technology-stack with MIT License | 6 votes |
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #10
Source File: VertxWrappedSessionUT.java From vertx-vaadin with MIT License | 6 votes |
@Test public void shouldUnbindOnInvalidate() throws Exception { Map<String, Object> sampleData = new HashMap<>(); HttpSessionBindingListener mockA = mock(HttpSessionBindingListener.class); HttpSessionBindingListener mockC = mock(HttpSessionBindingListener.class); sampleData.put("a", mockA); sampleData.put("b", "b"); sampleData.put("c", mockC); sampleData.put("b", "b"); when(session.data()).thenReturn(sampleData); vertxWrappedSession.invalidate(); verify(session).destroy(); ArgumentCaptor<HttpSessionBindingEvent> sessionBindingEventCaptor = ArgumentCaptor.forClass(HttpSessionBindingEvent.class); verify(mockA).valueUnbound(sessionBindingEventCaptor.capture()); verify(mockC).valueUnbound(sessionBindingEventCaptor.capture()); assertThat(sessionBindingEventCaptor.getAllValues()).hasSize(2); assertHttpSessionBindingEvent("a", mockA, sessionBindingEventCaptor.getAllValues().get(0)); assertHttpSessionBindingEvent("c", mockC, sessionBindingEventCaptor.getAllValues().get(1)); }
Example #11
Source File: SessionListenerBridge.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void attributeUpdated(final Session session, final String name, final Object value, final Object old) { if (name.startsWith(IO_UNDERTOW)) { return; } final HttpSessionImpl httpSession = SecurityActions.forSession(session, servletContext, false); if (old != value) { if (old instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) old).valueUnbound(new HttpSessionBindingEvent(httpSession, name, old)); } applicationListeners.httpSessionAttributeReplaced(httpSession, name, old); } if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(httpSession, name, value)); } }
Example #12
Source File: TestHttpSessionNotifier.java From HttpSessionReplacer with MIT License | 6 votes |
@Test public void testSessionDestroyed() { HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class); String dummy = "dummy"; when(session.getAttribute("binding")).thenReturn(bindingListener); when(session.getAttribute("attribute")).thenReturn(dummy); when(session.getAttributeNamesWithValues()).thenReturn(Arrays.asList("binding", "attribute")); HttpSessionListener listener = mock(HttpSessionListener.class); descriptor.addHttpSessionListener(listener); notifier.sessionDestroyed(session, false); verify(bindingListener).valueUnbound(any(HttpSessionBindingEvent.class)); verify(listener).sessionDestroyed(any(HttpSessionEvent.class)); HttpSessionListener listener2 = mock(HttpSessionListener.class); HttpSessionBindingListener bindingListener2 = mock(HttpSessionBindingListener.class); when(session.getAttribute("binding2")).thenReturn(bindingListener2); when(session.getAttributeNamesWithValues()).thenReturn(Arrays.asList("binding", "attribute", "binding2")); descriptor.addHttpSessionListener(listener2); notifier.sessionDestroyed(session, false); verify(listener, times(2)).sessionDestroyed(any(HttpSessionEvent.class)); verify(bindingListener, times(2)).valueUnbound(any(HttpSessionBindingEvent.class)); verify(bindingListener2).valueUnbound(any(HttpSessionBindingEvent.class)); verify(listener2).sessionDestroyed(any(HttpSessionEvent.class)); }
Example #13
Source File: MockHttpSession.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<String, Serializable>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #14
Source File: MockHttpSession.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<String, Serializable>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #15
Source File: MockHttpSession.java From live-chat-engine with Apache License 2.0 | 6 votes |
/** * Serialize the attributes of this session into an object that can * be turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap state = new HashMap(); for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #16
Source File: EntityHttpServletRequest.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Serialize the attributes of this session into an object that can * be turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Object> state = new HashMap<String, Object>(); for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, value); } else { if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #17
Source File: EntityHttpServletRequest.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Serialize the attributes of this session into an object that can * be turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Object> state = new HashMap<String, Object>(); for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, value); } else { if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #18
Source File: MockHttpSession.java From gocd with Apache License 2.0 | 6 votes |
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
Example #19
Source File: VertxWrappedSessionUT.java From vertx-vaadin with MIT License | 6 votes |
@Test public void shouldUnbindOnInvalidate() throws Exception { Map<String, Object> sampleData = new HashMap<>(); HttpSessionBindingListener mockA = mock(HttpSessionBindingListener.class); HttpSessionBindingListener mockC = mock(HttpSessionBindingListener.class); sampleData.put("a", mockA); sampleData.put("b", "b"); sampleData.put("c", mockC); sampleData.put("b", "b"); when(session.data()).thenReturn(sampleData); vertxWrappedSession.invalidate(); verify(session).destroy(); ArgumentCaptor<HttpSessionBindingEvent> sessionBindingEventCaptor = ArgumentCaptor.forClass(HttpSessionBindingEvent.class); verify(mockA).valueUnbound(sessionBindingEventCaptor.capture()); verify(mockC).valueUnbound(sessionBindingEventCaptor.capture()); assertThat(sessionBindingEventCaptor.getAllValues()).hasSize(2); assertHttpSessionBindingEvent("a", mockA, sessionBindingEventCaptor.getAllValues().get(0)); assertHttpSessionBindingEvent("c", mockC, sessionBindingEventCaptor.getAllValues().get(1)); }
Example #20
Source File: MockHttpSession.java From spring-analysis-note with MIT License | 6 votes |
@Override public void setAttribute(String name, @Nullable Object value) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); if (value != null) { Object oldValue = this.attributes.put(name, value); if (value != oldValue) { if (oldValue instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } } else { removeAttribute(name); } }
Example #21
Source File: MockHttpSession.java From live-chat-engine with Apache License 2.0 | 5 votes |
@Override public void removeAttribute(String name) { Object value = this.attributes.remove(name); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } }
Example #22
Source File: HttpSessionImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public synchronized void removeAttribute(String name) { if (invalid) { throw new IllegalStateException("Invalid session"); } final Object value = attributes.removeAttribute(name); if (value != null && value instanceof HttpSessionBindingListener) { final HttpSessionBindingListener listener = (HttpSessionBindingListener) value; listener.valueUnbound(new HttpSessionBindingEvent(this, name)); } }
Example #23
Source File: HttpSessionImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public synchronized void setAttribute(String name, Object value) { if (invalid) { throw new IllegalStateException("Invalid session"); } attributes.setAttribute(name, value); if (value instanceof HttpSessionBindingListener) { final HttpSessionBindingListener listener = (HttpSessionBindingListener) value; listener.valueBound(new HttpSessionBindingEvent(this, name)); } }
Example #24
Source File: MockHttpSession.java From live-chat-engine with Apache License 2.0 | 5 votes |
@Override public void setAttribute(String name, Object value) { if (value != null) { this.attributes.put(name, value); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } else { removeAttribute(name); } }
Example #25
Source File: MockHttpSession.java From live-chat-engine with Apache License 2.0 | 5 votes |
/** * Clear all of this session's attributes. */ public void clearAttributes() { for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } }
Example #26
Source File: MockHttpSession.java From spring-analysis-note with MIT License | 5 votes |
@Override public void removeAttribute(String name) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); Object value = this.attributes.remove(name); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } }
Example #27
Source File: EntityHttpServletRequest.java From sakai with Educational Community License v2.0 | 5 votes |
public void setAttribute(String name, Object value) { if (name == null) { throw new IllegalArgumentException("name must not be null"); } if (value != null) { this.attributes.put(name, value); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } else { removeAttribute(name); } }
Example #28
Source File: EntityHttpServletRequest.java From sakai with Educational Community License v2.0 | 5 votes |
public void removeAttribute(String name) { if (name == null) { throw new IllegalArgumentException("name must not be null"); } Object value = this.attributes.remove(name); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } }
Example #29
Source File: MockHttpSession.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Clear all of this session's attributes. */ public void clearAttributes() { for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } }
Example #30
Source File: MockPortletSession.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected void doClearAttributes(Map<String, Object> attributes) { for (Iterator<Map.Entry<String, Object>> it = attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound( new HttpSessionBindingEvent(new MockHttpSession(), name, value)); } } }