Example usage for io.netty.handler.codec.http Cookie name

List of usage examples for io.netty.handler.codec.http Cookie name

Introduction

In this page you can find the example usage for io.netty.handler.codec.http Cookie name.

Prototype

String name();

Source Link

Document

Returns the name of this Cookie .

Usage

From source file:com.chiorichan.http.HttpCookie.java

License:Mozilla Public License

public HttpCookie(Cookie cookie) {
    this(cookie.name(), cookie.value());
    setDomain(cookie.domain());/*from ww w  .j  a  va  2s  . c om*/
    setExpiration(cookie.maxAge());
    setPath(cookie.path());
    needsUpdating = false;
}

From source file:com.chiorichan.http.HttpRequestWrapper.java

License:Mozilla Public License

HttpRequestWrapper(Channel channel, HttpRequest http, HttpHandler handler, boolean ssl, LogEvent log)
        throws IOException {
    this.channel = channel;
    this.http = http;
    this.handler = handler;
    this.ssl = ssl;
    this.log = log;

    putRequest(this);

    // Set Time of this Request
    requestTime = Timings.epoch();//from w  w  w .java2 s .c  o m

    // Create a matching HttpResponseWrapper
    response = new HttpResponseWrapper(this, log);

    String host = getHostDomain();

    if (host == null || host.length() == 0) {
        parentDomain = "";
        site = SiteManager.instance().getDefaultSite();
    } else if (NetworkFunc.isValidIPv4(host) || NetworkFunc.isValidIPv6(host)) {
        parentDomain = host;
        site = SiteManager.instance().getSiteByIp(host).get(0);
    } else {
        Pair<String, SiteMapping> match = SiteMapping.get(host);

        if (match == null) {
            parentDomain = host;
            site = SiteManager.instance().getDefaultSite();
        } else {
            parentDomain = match.getKey();
            Namespace hostNamespace = new Namespace(host);
            Namespace parentNamespace = new Namespace(parentDomain);
            Namespace childNamespace = hostNamespace.subNamespace(0,
                    hostNamespace.getNodeCount() - parentNamespace.getNodeCount());
            assert hostNamespace.getNodeCount() - parentNamespace.getNodeCount() == childNamespace
                    .getNodeCount();
            childDomain = childNamespace.getNamespace();

            site = match.getValue().getSite();
        }
    }

    if (site == null)
        site = SiteManager.instance().getDefaultSite();

    if (site == SiteManager.instance().getDefaultSite() && getUri().startsWith("/~")) {
        List<String> uris = Splitter.on("/").omitEmptyStrings().splitToList(getUri());
        String siteId = uris.get(0).substring(1);

        Site siteTmp = SiteManager.instance().getSiteById(siteId);
        if (!siteId.equals("wisp") && siteTmp != null) {
            site = siteTmp;
            uri = "/" + Joiner.on("/").join(uris.subList(1, uris.size()));

            // TODO Implement both a virtual and real URI for use in redirects and url_to()
            String[] domains = site.getDomains().keySet().toArray(new String[0]);
            parentDomain = domains.length == 0 ? host : domains[0];
        }
    }

    // log.log( Level.INFO, "SiteId: " + site.getSiteId() + ", ParentDomain: " + parentDomain + ", ChildDomain: " + childDomain );

    try {
        QueryStringDecoder queryStringDecoder = new QueryStringDecoder(http.uri());
        Map<String, List<String>> params = queryStringDecoder.parameters();
        if (!params.isEmpty())
            for (Entry<String, List<String>> p : params.entrySet()) {
                // XXX This is overriding the key, why would their there be multiple values???
                String key = p.getKey();
                List<String> vals = p.getValue();
                for (String val : vals)
                    getMap.put(key, val);
            }
    } catch (IllegalStateException e) {
        log.log(Level.SEVERE, "Failed to decode the GET map because " + e.getMessage());
    }

    // Decode Cookies
    // String var1 = URLDecoder.decode( http.headers().getAndConvert( "Cookie" ), Charsets.UTF_8.displayName() );
    String var1 = http.headers().getAndConvert("Cookie");

    // TODO Find a way to fix missing invalid stuff

    if (var1 != null)
        try {
            Set<Cookie> var2 = CookieDecoder.decode(var1);
            for (Cookie cookie : var2)
                if (cookie.name().startsWith("_ws"))
                    serverCookies.add(new HttpCookie(cookie));
                else
                    cookies.add(new HttpCookie(cookie));
        } catch (IllegalArgumentException | NullPointerException e) {
            //NetworkManager.getLogger().debug( var1 );

            NetworkManager.getLogger().severe("Failed to parse cookie for reason: " + e.getMessage());
            // NetworkManager.getLogger().warning( "There was a problem decoding the request cookie.", e );
            // NetworkManager.getLogger().debug( "Cookie: " + var1 );
            // NetworkManager.getLogger().debug( "Headers: " + Joiner.on( "," ).withKeyValueSeparator( "=" ).join( http.headers() ) );
        }

    initServerVars();
}

From source file:com.soho.framework.server.util.Utils.java

License:Apache License

public static final Collection<Cookie> getCookies(String name, HttpRequest request) {
    String cookieString = request.headers().get(COOKIE);
    if (cookieString != null) {
        List<Cookie> foundCookie = new ArrayList<Cookie>();
        Set<Cookie> cookies = CookieDecoder.decode(cookieString);
        for (Cookie cookie : cookies) {
            if (cookie.name().equals(name))
                foundCookie.add(cookie);
        }/* ww  w.  j  av  a2s  .  co  m*/

        return foundCookie;
    }
    return null;
}

From source file:com.soho.framework.server.util.Utils.java

License:Apache License

public static final Collection<Cookie> getCookies(String name, HttpResponse response) {
    String cookieString = response.headers().get(COOKIE);
    if (cookieString != null) {
        List<Cookie> foundCookie = new ArrayList<Cookie>();
        Set<Cookie> cookies = CookieDecoder.decode(cookieString);
        for (Cookie cookie : cookies) {
            if (cookie.name().equals(name))
                foundCookie.add(cookie);
        }/*w w w  . ja v a2 s  .  com*/

        return foundCookie;
    }
    return null;
}

From source file:com.vmware.dcp.common.http.netty.CookieJar.java

License:Open Source License

/**
 * List cookies that apply for the given request URI.
 *
 * @param uri request URI//from  w  ww .  j ava  2s.  c om
 */
public Map<String, String> list(URI uri) {
    Map<String, String> result = new HashMap<>();

    // Find cookies by the request URI
    String origin = buildOrigin(uri);
    Set<Cookie> byOrigin = this.cookiesByOrigin.get(origin);
    if (byOrigin != null) {
        for (Cookie cookie : byOrigin) {
            // Only add "secure" cookies if request URI has https scheme
            if (cookie.isSecure() && !uri.getScheme().equals(URI_SCHEME_HTTPS)) {
                continue;
            }

            result.put(cookie.name(), cookie.value());
        }
    }

    return result;
}

From source file:org.waarp.gateway.ftp.adminssl.HttpSslHandler.java

License:Open Source License

private void checkSession(Channel channel) {
    String cookieString = request.headers().get(HttpHeaders.Names.COOKIE);
    if (cookieString != null) {
        Set<Cookie> cookies = CookieDecoder.decode(cookieString);
        if (!cookies.isEmpty()) {
            for (Cookie elt : cookies) {
                if (elt.name().equalsIgnoreCase(FTPSESSION)) {
                    admin = elt;/*  w  ww. ja va  2s . c  om*/
                    break;
                }
            }
        }
    }
    if (admin != null) {
        FileBasedAuth auth = sessions.get(admin.value());
        if (auth != null) {
            authentHttp = auth;
        }
        DbSession dbSession = dbSessions.get(admin.value());
        if (dbSession != null) {
            this.dbSession = dbSession;
        }
    } else {
        logger.debug("NoSession: " + uriRequest + ":{}", admin);
    }
}

From source file:org.waarp.gateway.ftp.adminssl.HttpSslHandler.java

License:Open Source License

private void handleCookies(HttpResponse response) {
    String cookieString = request.headers().get(HttpHeaders.Names.COOKIE);
    if (cookieString != null) {
        Set<Cookie> cookies = CookieDecoder.decode(cookieString);
        if (!cookies.isEmpty()) {
            // Reset the sessions if necessary.
            boolean findSession = false;
            for (Cookie cookie : cookies) {
                if (cookie.name().equalsIgnoreCase(FTPSESSION)) {
                    if (newSession) {
                        findSession = false;
                    } else {
                        findSession = true;
                        response.headers().add(HttpHeaders.Names.SET_COOKIE,
                                ServerCookieEncoder.encode(cookie));
                    }/*  w  w  w. j  a  v a2s  .c  o m*/
                } else {
                    response.headers().add(HttpHeaders.Names.SET_COOKIE, ServerCookieEncoder.encode(cookie));
                }
            }
            newSession = false;
            if (!findSession) {
                if (admin != null) {
                    response.headers().add(HttpHeaders.Names.SET_COOKIE, ServerCookieEncoder.encode(admin));
                    logger.debug("AddSession: " + uriRequest + ":{}", admin);
                }
            }
        }
    } else if (admin != null) {
        logger.debug("AddSession: " + uriRequest + ":{}", admin);
        response.headers().add(HttpHeaders.Names.SET_COOKIE, ServerCookieEncoder.encode(admin));
    }
}

From source file:ratpack.http.internal.DefaultRequest.java

License:Apache License

public String oneCookie(String name) {
    Cookie found = null;/* www.j av a 2  s. c  o m*/
    List<Cookie> allFound = null;
    for (Cookie cookie : getCookies()) {
        if (cookie.name().equals(name)) {
            if (found == null) {
                found = cookie;
            } else if (allFound == null) {
                allFound = new ArrayList<>(2);
                allFound.add(found);
            } else {
                allFound.add(cookie);
            }
        }
    }

    if (found == null) {
        return null;
    } else if (allFound != null) {
        StringBuilder s = new StringBuilder("Multiple cookies with name '").append(name).append("': ");
        int i = 0;
        for (Cookie cookie : allFound) {
            s.append(cookie.toString());
            if (++i < allFound.size()) {
                s.append(", ");
            }
        }

        throw new IllegalStateException(s.toString());
    } else {
        return found.value();
    }
}

From source file:ratpack.session.internal.RequestSessionManager.java

License:Apache License

private String getCookieSessionId() {
    if (cookieSessionId == null) {
        Cookie match = null;/*from w  w w . j av a2  s.  c o  m*/

        for (Cookie cookie : context.getRequest().getCookies()) {
            if (cookie.name().equals(COOKIE_NAME)) {
                match = cookie;
                break;
            }
        }

        if (match != null) {
            cookieSessionId = match.value();
        } else {
            cookieSessionId = "";
        }

    }

    return cookieSessionId.equals("") ? null : cookieSessionId;
}