Is there a way to Identify session overflow , similar to IBM Webspehere supported in JBoss?

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Application Platform (EAP) 5.1

Issue

Currenytly IBM provides us a wrapper on top of the HTTPSession as IBMSession and we could check if there is a session overflow. Can we do this with Jboss ?

IBMSession ibmSession =(IBMSession) httpRequest.getSession(true);
        if(ibmSession.isOverflow()){
    do some operation of redirect etc … 
}

Resolution

There is no out of the box way to do that with EAP 5.

It is possible however to do that using a custom servlet filter. Adding this filter to your web application will cause it to return a OverflowSession rather than throwing an exception as normal, which you can then attempt to cast to in your application.

package example;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSession;

public class SessionOverflowFilter implements Filter {
    public void init(FilterConfig arg0) throws ServletException {

    }

    public void destroy() {

    }

    public void doFilter(ServletRequest req, ServletResponse resp,
            FilterChain chain) throws IOException, ServletException {
        chain.doFilter(new RequestWrapper((HttpServletRequest) req), resp);

    }

    static class RequestWrapper extends HttpServletRequestWrapper {
        public RequestWrapper(HttpServletRequest request) {
            super(request);
        }

        @Override
        public HttpSession getSession(boolean create) {
            try {
                return super.getSession(create);
            } catch (IllegalStateException e) {
                return new OverflowSession();
            }
        }

        @Override
        public HttpSession getSession() {
            try {
                return super.getSession();
            } catch (IllegalStateException e) {
                return new OverflowSession();
            }
        }
    }
}
package example;

import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;

class OverflowSession implements HttpSession {
    public long getCreationTime() {
        throw new IllegalStateException();
    }

    public String getId() {
        throw new IllegalStateException();
    }

    public long getLastAccessedTime() {
        throw new IllegalStateException();
    }

    public ServletContext getServletContext() {
        throw new IllegalStateException();
    }

    public void setMaxInactiveInterval(int interval) {
        throw new IllegalStateException();
    }

    public int getMaxInactiveInterval() {
        throw new IllegalStateException();
    }

    public HttpSessionContext getSessionContext() {
        throw new IllegalStateException();
    }

    public Object getAttribute(String name) {
        throw new IllegalStateException();
    }

    public Object getValue(String name) {
        throw new IllegalStateException();
    }

    public Enumeration<String> getAttributeNames() {
        throw new IllegalStateException();
    }

    public String[] getValueNames() {
        throw new IllegalStateException();
    }

    public void setAttribute(String name, Object value) {
        throw new IllegalStateException();
    }

    public void putValue(String name, Object value) {
        throw new IllegalStateException();
    }

    public void removeAttribute(String name) {
        throw new IllegalStateException();
    }

    public void removeValue(String name) {
        throw new IllegalStateException();
    }

    public void invalidate() {
        throw new IllegalStateException();
    }

    public boolean isNew() {
        throw new IllegalStateException();
    }

}

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.