How to access any HTTP session data in Oracle ADF

How to access any HTTP session data in Oracle ADF

If you have ever wondered how to get access to any HTTP session in your ADF application this post will solve the problem.

The first step is to prepare your HttpSessionListener implementation in a View Controller project.

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class MyAdfSessionListener implements HttpSessionListener {
    private static final Map<String, HttpSession> HTTP_SESSIONS = new HashMap<>();

    public MyAdfSessionListener() {

    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        HttpSession httpSession = httpSessionEvent.getSession();
        HTTP_SESSIONS.put(httpSession.getId(), httpSession);
        //Uncomment the line below for simple debug
        //System.out.println("Session created:" + httpSession.getId());

    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        HttpSession httpSession = httpSessionEvent.getSession();
        //Uncomment the line below for simple debug
        //System.out.println("Session destroyed:" + httpSession.getId());

    public static Map<String, HttpSession> getHttpSessions() {
        return Collections.unmodifiableMap(HTTP_SESSIONS);

    public static HttpSession findHttpSession(String sessionId) {
        return HTTP_SESSIONS.get(sessionId);


After that register it in web.xml  file (1,2,3,4,5)

You can edit web.xml file directly:



Sessions are stored in HTTP_SESSIONS collection. The listener provides two additional static methods which allows you to access to the session data:

  • getHttpSessions – returns valid (current) sessions collection.
  • findHttpSession – returns session object or null if sessionId does’t exists.


The result

Turn on debug by uncommenting System.out lines in the listener. After login you should see something like below



Now you are able to handle any creation and destruction of http session in your application by calling:



The peace of code below prints all active session’s id;

for (HttpSession session: MyAdfSessionListener.getHttpSessions()) {
  //do something with session object
0 0 vote
Article Rating
Notify of
1 Comment
newest most voted
Inline Feedbacks
View all comments
Karl P Henselin
Karl P Henselin
1 year ago

Seems like
should be
Otherwise quite helpful for the problem I was working on.