[Java programming language only]

Example: Overriding the session ID with the sessionIdOverrideClass interface

You can override the retrieved session ID of an application. The default is to use the ID derived from the HttpSession.getId() method.

Client-based preload example

public class CustomSessionID implements com.ibm.websphere.xs.sessionmanager.SessionIDOverride {

    public void init(InitializationContext ctx) {
    }

    public void destroy() {
    }

    public String getID(SessionIDContext ctx) {
        HttpServletRequest req = ctx.getRequest();

        String sessionId = (String) req.getAttribute("AppID");
        if (sessionId != null) {
            // sessionId is stored in the request as attribute "AppID" for this user
            return sessionId;
        }
        
        Cookie[] cookies = req.getCookies();
        if (cookies != null) {
            for (int i = 0; i < cookies.length; i ++) {
                if (cookies[i].getName().equals("AppID")) {
	    // if the request does not yet contain the AppID attribute, then the "AppID" cookie must exist
                    return cookies[i].getValue();
                }
            }
        }
        return null;
    }
}