ということで、ひとまず BlazeDS が使用している下記の3つのイベントリスナインタフェースを対象に実験してみました。
import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionListener;
開発環境上での実行結果
sessionCreated : id = 16es70wx6934m attributeAdded : name = foo, value = bar attributeReplaced : name = foo, value = bar attributeRemoved : name = foo, value = hoge valueBound : name = fumyo, value = null attributeAdded : name = fumyo, value = listenertest.ApplicationLifecycleListener@1977b9b valueUnbound : name = fumyo, value = null attributeRemoved : name = fumyo, value = listenertest.ApplicationLifecycleListener@1977b9b sessionDestroyed : id = 16es70wx6934m
本番環境での実行結果
sessionCreated : id = 8xj_3ZWLJhJRl4nrVAzsCw attributeAdded : name = foo, value = bar attributeReplaced : name = foo, value = bar attributeRemoved : name = foo, value = hoge valueBound : name = fumyo, value = null attributeAdded : name = fumyo, value = listenertest.ApplicationLifecycleListener@13b625b valueUnbound : name = fumyo, value = null attributeRemoved : name = fumyo, value = listenertest.ApplicationLifecycleListener@13b625b sessionDestroyed : id = 8xj_3ZWLJhJRl4nrVAzsCw
なんと、GAE/J 上で、上記のリスナーは完全に動作しているようです。(`・ω・´)
テスト用サーブレットのソース
package listenertest; import java.io.IOException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @SuppressWarnings("serial") public class ListenertestServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { HttpSession session = req.getSession(true); session.setAttribute("foo", "bar"); session.setAttribute("foo", "hoge"); session.removeAttribute("foo"); session.setAttribute("fumyo", new ApplicationLifecycleListener()); session.removeAttribute("fumyo"); session.invalidate(); resp.setContentType("text/plain"); resp.getWriter().println("Test complete!"); } }
テスト用リスナーのソース
package listenertest; import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; public class ApplicationLifecycleListener implements HttpSessionListener, HttpSessionAttributeListener, HttpSessionBindingListener { @Override public void sessionCreated(HttpSessionEvent event) { System.err.println("sessionCreated : id = " + event.getSession().getId()); } @Override public void sessionDestroyed(HttpSessionEvent event) { System.err.println("sessionDestroyed : id = " + event.getSession().getId()); } @Override public void attributeAdded(HttpSessionBindingEvent event) { System.err.println("attributeAdded : name = " + event.getName() + ", value = " + event.getValue()); } @Override public void attributeRemoved(HttpSessionBindingEvent event) { System.err.println("attributeRemoved : name = " + event.getName() + ", value = " + event.getValue()); } @Override public void attributeReplaced(HttpSessionBindingEvent event) { System.err.println("attributeReplaced : name = " + event.getName() + ", value = " + event.getValue()); } @Override public void valueBound(HttpSessionBindingEvent event) { System.err.println("valueBound : name = " + event.getName() + ", value = " + event.getValue()); } @Override public void valueUnbound(HttpSessionBindingEvent event) { System.err.println("valueUnbound : name = " + event.getName() + ", value = " + event.getValue()); } }
0 件のコメント:
コメントを投稿