Example usage for javax.servlet.http Cookie getPath

List of usage examples for javax.servlet.http Cookie getPath

Introduction

In this page you can find the example usage for javax.servlet.http Cookie getPath.

Prototype

public String getPath() 

Source Link

Document

Returns the path on the server to which the browser returns this cookie.

Usage

From source file:io.syndesis.credential.CredentialFlowStateHelper.java

static javax.ws.rs.core.Cookie toJaxRsCookie(final Cookie cookie) {
    return new javax.ws.rs.core.Cookie(cookie.getName(), cookie.getValue(), cookie.getPath(),
            cookie.getDomain());//from  ww w .ja va2 s.  c  o m
}

From source file:com.woonoz.proxy.servlet.CookieFormatter.java

public static CookieFormatter createFromServletCookie(javax.servlet.http.Cookie cookie) {
    return new CookieFormatter(cookie.getName(), cookie.getValue(), cookie.getPath());
}

From source file:com.hortonworks.example.util.Util.java

public static String getCookieInfo(HttpServletRequest request, String name) {
    String info = null;//from  w w w  .  j a  v a  2  s .  c  o m
    Cookie cookie = getCookie(request, name);
    if (cookie != null) {
        info = String.format("[value=%s,domain=%s,path=%s,expiry=%d]", cookie.getValue(), cookie.getDomain(),
                cookie.getPath(), cookie.getMaxAge());
    }
    return info;
}

From source file:com.activecq.api.utils.CookieUtil.java

/**
 * Removes all cookies for the domain/*from   www . j av a 2  s  . c om*/
 *
 * @param request Request to get the Cookies to drop
 * @param response Response to expire the Cookies on
 */
public static int dropAllCookies(HttpServletRequest request, HttpServletResponse response) {
    int count = 0;
    Cookie[] cookies = request.getCookies();

    if (cookies == null) {
        return 0;
    }

    for (Cookie cookie : cookies) {
        cookie.setMaxAge(0);
        cookie.setPath(cookie.getPath());

        addCookie(cookie, response);
        count++;
    }

    return count;
}

From source file:com.google.gsa.valve.modules.utils.CookieManagement.java

/**
 * Transforms Servlet cookies into Apache Cookies
 * // w  ww .  j ava2s.c o m
 * @param servletCookie servlet cookie
 * 
 * @return apache cookie
 */
public static org.apache.commons.httpclient.Cookie transformServletCookie(
        javax.servlet.http.Cookie servletCookie) {

    org.apache.commons.httpclient.Cookie newCookie = null;

    if (servletCookie != null) {
        newCookie = new org.apache.commons.httpclient.Cookie(servletCookie.getDomain(), servletCookie.getName(),
                servletCookie.getValue(), servletCookie.getPath() != null ? servletCookie.getPath() : "/",
                servletCookie.getMaxAge(), servletCookie.getSecure());
    }
    return newCookie;
}

From source file:com.activecq.api.utils.CookieUtil.java

/**
 * Remove the Cookies whose names match the provided Regex from Response
 *
 * @param request Request to get the Cookies to drop
 * @param response Response to expire the Cookies on
 * @param regexes Regex to find Cookies to drop
 * @return Number of Cookies dropped/*from   ww  w .j av  a  2  s. c  o m*/
 */
public static int dropCookiesByRegexArray(HttpServletRequest request, HttpServletResponse response,
        String[] regexes) {
    int count = 0;
    if (regexes == null) {
        return count;
    }
    List<Cookie> cookies = new ArrayList<Cookie>();

    for (final String regex : regexes) {
        cookies.addAll(getCookies(request, regex));
        //cookies = CollectionUtils.union(cookies, getCookies(request, regex));
    }

    for (final Cookie cookie : cookies) {
        if (cookie == null) {
            continue;
        }

        cookie.setMaxAge(0);
        cookie.setPath(cookie.getPath());

        addCookie(cookie, response);
        count++;
    }

    return count;
}

From source file:com.activecq.api.utils.CookieUtil.java

/**
 * Remove the named Cookies from Response
 *
 * @param request Request to get the Cookies to drop
 * @param response Response to expire the Cookies on
 * @param cookieNames Names of cookies to drop
 * @return Number of Cookies dropped/*from  w  w w  .  j a  v  a 2s .c om*/
 */
public static int dropCookies(HttpServletRequest request, HttpServletResponse response, String... cookieNames) {
    int count = 0;
    if (cookieNames == null) {
        return count;
    }

    for (final String cookieName : cookieNames) {
        Cookie cookie = getCookie(request, cookieName);
        if (cookie == null) {
            continue;
        }

        cookie.setMaxAge(0);
        cookie.setPath(cookie.getPath());

        addCookie(cookie, response);
        count++;
    }

    return count;
}

From source file:com.aurel.track.master.ModuleBL.java

public static Cookie sendPOSTRequest(String urlString) {
    Cookie responseCookie = null;//from  ww  w.j  av  a2 s  . c o m
    try {
        HttpClient httpclient = new DefaultHttpClient();//HttpClients.createDefault();
        HttpPost httppost = new HttpPost(urlString);
        // Request parameters and other properties.
        //Execute and get the response.
        HttpContext localContext = new BasicHttpContext();
        CookieStore cookieStore = new BasicCookieStore();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        HttpResponse response = httpclient.execute(httppost, localContext);

        if (cookieStore.getCookies().size() > 0) {
            List<org.apache.http.cookie.Cookie> cookies = cookieStore.getCookies();
            for (org.apache.http.cookie.Cookie cookie : cookies) {
                if (cookie.getName().equals("JSESSIONID")) {
                    responseCookie = new Cookie(cookie.getName(), cookie.getValue());
                    responseCookie.setPath(cookie.getPath());
                    responseCookie.setDomain(cookie.getDomain());
                }
            }
        }
        if (response.getEntity() != null) {
            response.getEntity().consumeContent();
        }

    } catch (Exception ex) {
        LOGGER.debug(ExceptionUtils.getStackTrace(ex));
    }
    return responseCookie;
}

From source file:net.bluehornreader.web.WebUtils.java

public static String cookieAsString(Cookie cookie) {
    StringBuilder bld = new StringBuilder();
    bld.append("Name=").append(cookie.getName()).append(" ");
    bld.append("Value=").append(cookie.getValue()).append(" ");
    bld.append("Domain=").append(cookie.getDomain()).append(" ");
    bld.append("MaxAge=").append(cookie.getMaxAge()).append(" ");
    bld.append("Path=").append(cookie.getPath()).append(" ");
    bld.append("Secure=").append(cookie.getSecure()).append(" ");
    bld.append("Comment=").append(cookie.getComment()).append(" ");
    bld.append("Version=").append(cookie.getVersion()).append(" ");
    return bld.toString().trim();
}

From source file:com.activecq.api.utils.CookieUtil.java

/**
 * <p>//from  w w  w. j  a v a2  s .c o  m
 * Extend the cookie life.
 * <p></p>
 * This can be used when a cookie should be valid for X minutes from the last point of activity.
 * <p></p>
 * This method will leave expired or deleted cookies alone.
 * </p>
 * @param request Request to get the Cookie from
 * @param response Response to write the extended Cookie to
 * @param cookieName Name of Cookie to extend the life of
 * @param expiry New Cookie expiry
 */
public static boolean extendCookieLife(HttpServletRequest request, HttpServletResponse response,
        String cookieName, int expiry) {
    Cookie cookie = getCookie(request, cookieName);
    if (cookie == null) {
        return false;
    }

    if (cookie.getMaxAge() <= 0) {
        return false;
    }

    cookie.setMaxAge(expiry);
    cookie.setPath(cookie.getPath());

    addCookie(cookie, response);

    return true;
}