Example usage for javax.servlet.http HttpSession getValue

List of usage examples for javax.servlet.http HttpSession getValue

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getValue.

Prototype

@Deprecated
public Object getValue(String name);

Source Link

Usage

From source file:org.codehaus.wadi.web.TestHttpSession.java

public void testGetValue(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    String key = "foo";
    Object val = new Listener();
    session.setAttribute(key, val);
    events.clear();//  w  w w  . ja va  2s  .c  o  m

    assertTrue(session.getValue(key) == val);
}

From source file:org.codehaus.wadi.web.TestHttpSession.java

public void testReplaceAttribute(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    assertTrue(events.size() == 1); // sessionCreated
    String key = "foo";
    Object oldVal = new Listener();
    Object newVal = new Listener();
    session.setAttribute(key, oldVal);/*  w w w.j a v  a 2 s. c om*/
    assertTrue(events.size() == 3); // valueBound, attributeAdded
    events.clear();

    session.setAttribute(key, newVal);
    assertTrue(events.size() == 3); // valueUnbound, valueBound,
                                    // attributeReplaced
    {
        Pair pair = (Pair) events.get(0);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("valueUnbound"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == oldVal);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("valueBound"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == newVal);
    }
    {
        Pair pair = (Pair) events.get(2);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeReplaced"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == oldVal);
    }
    events.clear();
    assertTrue(events.size() == 0);
    assertTrue(session.getValue(key) == newVal);
}

From source file:org.codehaus.wadi.web.TestHttpSession.java

public void testReplaceValue(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    String key = "foo";
    Object oldVal = new Listener();
    Object newVal = new Listener();
    session.setAttribute(key, oldVal);/*from   w  ww. j  a  va  2s  .  c  o m*/
    events.clear();

    session.putValue(key, newVal);
    {
        Pair pair = (Pair) events.remove(0);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("valueUnbound"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == oldVal);
    }
    {
        Pair pair = (Pair) events.remove(0);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("valueBound"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == newVal);
    }
    {
        Pair pair = (Pair) events.remove(0);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeReplaced"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == oldVal);
    }
    assertTrue(session.getValue(key) == newVal);
    assertTrue(events.size() == 0);
}

From source file:org.codehaus.wadi.web.TestHttpSession.java

public void testNullName(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    try {//from  w w w  . j  a v a  2  s  .  co m
        session.setAttribute(null, "a");
        assertTrue(false);
    } catch (IllegalArgumentException e) {
    }
    try {
        session.getAttribute(null);
        assertTrue(false);
    } catch (IllegalArgumentException e) {
    }
    try {
        session.removeAttribute(null);
        assertTrue(false);
    } catch (IllegalArgumentException e) {
    }
    try {
        session.putValue(null, "a");
        assertTrue(false);
    } catch (IllegalArgumentException e) {
    }
    try {
        session.getValue(null);
        assertTrue(false);
    } catch (IllegalArgumentException e) {
    }
    try {
        session.removeValue(null);
        assertTrue(false);
    } catch (IllegalArgumentException e) {
    }
}

From source file:org.craftercms.studio.impl.v1.service.deployment.DeploymentServiceImpl.java

@Override
public void syncAllContentToPreview(String site) throws ServiceException {
    RepositoryEventMessage message = new RepositoryEventMessage();
    message.setSite(site);//ww w  .java  2  s.c  om
    RequestContext context = RequestContext.getCurrent();
    String sessionTicket = null;
    if (context != null) {
        HttpSession httpSession = context.getRequest().getSession();
        sessionTicket = (String) httpSession.getValue("alf_ticket");
    }
    RepositoryEventContext repositoryEventContext = new RepositoryEventContext(sessionTicket);
    message.setRepositoryEventContext(repositoryEventContext);
    repositoryReactor.notify(EBusConstants.REPOSITORY_PREVIEW_SYNC_EVENT, Event.wrap(message));
}

From source file:org.energy_home.jemma.ah.webui.energyathome.ekitchen.EnergyAtHome.java

public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // we need http scheme!
    if (enableHttps && !request.getScheme().equals("https")) {
        try {/*  w w w .j a  v  a 2 s.  c  o m*/
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } catch (IOException e) {
            // do nothing
        }
        return false;
    }

    String queryString = request.getRequestURI();

    if (queryString.equals(applicationWebAlias + "/conf")
            || (queryString.equals(applicationWebAlias + "/conf/"))) {
        response.sendRedirect(applicationWebAlias + "/conf/index.html");
        return true;
    } else if (queryString.equals(applicationWebAlias) || (queryString.equals(applicationWebAlias + "/"))) {
        response.sendRedirect(applicationWebAlias + "/index.html");
        return true;
    }

    if (enableSecurity) {
        if (useBasic) {
            String auth = request.getHeader("Authorization");

            if (auth == null)
                return failAuthorization(request, response);

            StringTokenizer tokens = new StringTokenizer(auth);
            String authscheme = tokens.nextToken();

            if (!authscheme.equals("Basic"))
                return failAuthorization(request, response);

            String base64credentials = tokens.nextToken();
            String credentials = new String(Base64.decode(base64credentials.getBytes()));
            int colon = credentials.indexOf(':');
            String userid = credentials.substring(0, colon);
            String password = credentials.substring(colon + 1);
            Authorization subject = null;

            try {
                subject = login(request, userid, password);
            } catch (LoginException e) {
                return failAuthorization(request, response);
            }

            request.setAttribute(HttpContext.REMOTE_USER, userid);
            request.setAttribute(HttpContext.AUTHENTICATION_TYPE, authscheme);
            request.setAttribute(HttpContext.AUTHORIZATION, subject);
        } else {
            HttpSession session = request.getSession(true);
            if (queryString.startsWith(applicationWebAlias + "/conf")) {
                // this is a restricted area so performs login

                String a = request.getMethod();
                String submit = request.getParameter("submit");
                if (submit != null) {
                    String username = request.getParameter("username");
                    String password = request.getParameter("password");
                    if (!allowUser(username, password)) {
                        return redirectToLoginPage(request, response);
                    } else {
                        session.putValue("logon.isDone", username);
                        try {
                            String target = (String) session.getValue("login.target");
                            if (target != null)
                                response.sendRedirect(target);
                            else {
                                response.sendRedirect(applicationWebAlias + "/conf/index.html");
                            }
                        } catch (Exception ignored) {
                            return false;
                        }
                    }
                } else {
                    if (queryString.equals(applicationWebAlias + "/conf/login.html")) {
                        return true;
                    } else {
                        //                     session.putValue("login.target", HttpUtils.getRequestURL(request).toString());
                        session.putValue("login.target", applicationWebAlias + "/conf/index.html");
                        Object done = session.getValue("logon.isDone");
                        if (done == null) {
                            if (request.getMethod().equals("GET")) {
                                return redirectToLoginPage(request, response);
                            } else {
                                response.sendError(HttpServletResponse.SC_FORBIDDEN);
                                return false;
                            }
                        }

                    }
                }
            }
        }
    }

    if (request.getRequestURI().endsWith(".png")) {
        response.setHeader("Cache-Control", "public, max-age=10000");
    }

    /*if (request.getRequestURI().endsWith(".js")) {
       response.setHeader("Pragma", "no-cache");
       response.setHeader("Cache-Control", "no-store");
       response.setHeader("Cache-Control", "public, max-age=0");
    }*/

    // response.addHeader(HttpServletResponse, arg1)

    return true;
}