Package javax.servlet.http

Examples of javax.servlet.http.Cookie


   */
  private boolean rejectRequest(HttpServletRequest request, HttpServletResponse response) {
    if (AuthHelper.isRejectDMZRequests()) {
      boolean validBypass = false;
      Cookie[] cookies = request.getCookies();
      Cookie sessionCookie = null;
      if (cookies!=null) {
        for(int i=0; i<cookies.length; i++) {
          Cookie cookie = cookies[i];
          if ("bypassdmzreject".equals(cookie.getName())) {
            // there is a bypassdmzreject cookie set - let's check the time
            try{
              long bypasscreationtime = Long.parseLong(cookie.getValue());
              if (System.currentTimeMillis()-bypasscreationtime<5*60*1000) {
                Tracing.logInfo("Allowing request with valid bypass cookie, sessionId="+request.getRequestedSessionId(), DMZDispatcher.class);
                validBypass = true;
              }
            } catch(NumberFormatException e) {
              // ignore
            }
          } else if ("JSESSIONID".equals(cookie.getName())) {
            sessionCookie = cookie;
          }
        }
      }
      if (!validBypass) {
View Full Code Here


    setHeader("Server", httpConfig.getServerInfo());

    // set session cookie
    HttpSession session = null;
    if (request != null && (session = request.getSession(false)) != null)
      addCookie(new Cookie(HttpUtil.SESSION_COOKIE_KEY, session.getId()));

    // set cookies
    Enumeration e_cookies = cookies.elements();
    while (e_cookies.hasMoreElements())
      setCookieHeader((Cookie) e_cookies.nextElement());
View Full Code Here

  // private methods

  private void handleSession() {

    Cookie sessionCookie =
      (Cookie) base.getCookies().get(HttpUtil.SESSION_COOKIE_KEY);
    if (sessionCookie != null) {
      requestedSessionIdFromCookie = true;
      requestedSessionId = sessionCookie.getValue();
    } else {
      requestedSessionId = base.getSessionIdParameter();
      if (null!=requestedSessionId) {
        requestedSessionIdFromURL = true;
      }
View Full Code Here

   */
  @Override
  public void putPreference(String key, String value) {
    String completeKey = storePath + key;
    if (HttpRequestHolder.getServletResponse() != null) {
      Cookie cookie = new Cookie(completeKey, value);
      cookie.setMaxAge(Integer.MAX_VALUE);
      HttpRequestHolder.getServletResponse().addCookie(cookie);
    }
  }
View Full Code Here

   */
  @Override
  public void removePreference(String key) {
    String completeKey = storePath + key;
    if (HttpRequestHolder.getServletResponse() != null) {
      Cookie cookie = new Cookie(completeKey, "");
      cookie.setMaxAge(0);
      HttpRequestHolder.getServletResponse().addCookie(cookie);
    }
  }
View Full Code Here

      String cookieString = (String) cookieEnumeration.nextElement();

      int version = 0;
      String previousToken = "";
      boolean isValue = false;
      Cookie cookie = null;

      StringTokenizer st = new StringTokenizer(cookieString, "=;,", true);
      while (st.hasMoreElements()) {
        String token = ((String) st.nextElement()).trim();

        if (token.equals("="))
          isValue = true;
        else if (";,".indexOf(token) != -1)
          isValue = false;
        else {
          if (isValue) {
            if (token.charAt(0) == '\"') {
              int index = token.indexOf('\"', 1);
              if (index == -1)
                break;
              token = token.substring(1, index);
            }
            if (previousToken.equals("$Version")) {
              try {
                version = Integer.parseInt(token);
              } catch (Exception e) {
                break;
              }
            } else if (previousToken.equals("$Path")) {
              if (cookie == null)
                break;
              cookie.setPath(token);
            } else if (previousToken.equals("$Domain")) {
              if (cookie == null)
                break;
              cookie.setDomain(token);
            } else {
              cookie = new Cookie(previousToken, token);
              cookie.setVersion(version);
              cookies.put(cookie.getName(), cookie);
            }
          } else
            previousToken = token;
        }
      }
View Full Code Here

      response.setHeader((String) entry.getKey(), (String) entry.getValue());   
    }
   
    for (Iterator i = cookies.entrySet().iterator(); i.hasNext();) {
      Map.Entry entry = (Map.Entry) i.next();     
      response.addCookie(new Cookie((String) entry.getKey(), (String) entry.getValue()));   
    }
   
    request.setCharacterEncoding(requestEncoding);

    childService._getService().action(path, input, output);
View Full Code Here

 
  public void testRollBackHeaders() throws Exception {
    res.setHeader("key", "value");
    assertEquals("value", res.getHeader("key"));
   
    Cookie cookie = new Cookie("key", "value");
    res.addCookie(cookie);
    assertEquals(cookie, res.getCookie("key"));
       
    atomic.rollback();
    assertEquals(null, res.getHeader("key"));
View Full Code Here

    public Cookie getSessionCookie(HttpSession session, String contextPath, boolean requestIsSecure)
    {
//        if (_handler.isUsingCookies())
//        { what's the jetty6 counterpart for isUsingCookies? - nik
            Cookie cookie = _handler.getSessionManager().getHttpOnly() ? new HttpOnlyCookie(SessionManager.__SessionCookieProperty, session.getId()) : new Cookie(
                SessionManager.__SessionCookieProperty, session.getId());
            String domain = getServletContext().getInitParameter(SessionManager.__SessionDomainProperty);
            String maxAge = getServletContext().getInitParameter(SessionManager.__MaxAgeProperty);
            String path = getServletContext().getInitParameter(SessionManager.__SessionPathProperty);
            if (path == null)
                path = getCrossContextSessionIDs() ? "/" : ((JBossSipAppContext)_context).getUniqueName();
            if (path == null || path.length() == 0)
                path = "/";

            if (domain != null)
                cookie.setDomain(domain);
            if (maxAge != null)
                cookie.setMaxAge(Integer.parseInt(maxAge));
            else
                cookie.setMaxAge(-1);

            cookie.setSecure(requestIsSecure && getSecureCookies());
            cookie.setPath(path);

            return cookie;
//        }
//        return null;
    }
View Full Code Here

    Cookie[] cookies = request.getCookies();

    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {
        Cookie cookie = cookies[i];

        if (cookie.getName().equals(_name)) {
          return _regexp == null || _regexp.matcher(cookie.getValue()).find();
        }
      }
    }

    return false;
View Full Code Here

TOP

Related Classes of javax.servlet.http.Cookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.