Example usage for io.netty.handler.codec.http.cookie Cookie value

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

Introduction

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

Prototype

String value();

Source Link

Document

Returns the value of this Cookie .

Usage

From source file:cn.wantedonline.puppy.httpserver.component.HttpRequest.java

License:Apache License

public String getCookieValue(String cookieName) {
    Cookie cookie = getCookie(cookieName);
    return AssertUtil.isNull(cookie) ? "" : cookie.value();
}

From source file:com.bay1ts.bay.core.Request.java

License:Apache License

/**
 * @return request cookies (or empty Map if cookies aren't present)
 *//* ww w  . ja v  a2 s  . c o  m*/
public Map<String, String> cookies() {
    Map<String, String> result = new HashMap<>();
    String cookieString = fullHttpRequest.headers().get(HttpHeaderNames.COOKIE);
    Set<Cookie> cookieSet = null;
    if (cookieString != null) {
        cookieSet = ServerCookieDecoder.LAX.decode(cookieString);
    }
    if (cookieSet != null && !cookieSet.isEmpty()) {
        for (Cookie cookie : cookieSet) {
            result.put(cookie.name(), cookie.value());
        }
    }
    //        Cookie[] cookies = fullHttpRequest.getCookies();
    //        if (cookies != null) {
    //            for (Cookie cookie : cookies) {
    //                result.put(cookie.name(), cookie.value());
    //            }
    //        }
    return result;
}

From source file:com.bay1ts.bay.core.Request.java

License:Apache License

/**
 * Gets cookie by name.//from w  w w . j  ava2 s  .com
 *
 * @param name name of the cookie
 * @return cookie value or null if the cookie was not found
 */
public String cookie(String name) {
    String cookieString = fullHttpRequest.headers().get(HttpHeaderNames.COOKIE);
    Set<Cookie> cookieSet = null;
    if (cookieString != null) {
        cookieSet = ServerCookieDecoder.LAX.decode(cookieString);
    }
    if (cookieSet != null && !cookieSet.isEmpty()) {
        for (Cookie cookie : cookieSet) {
            if (cookie.name().equals(name)) {
                return cookie.value();
            }
        }
    }
    return null;
}

From source file:com.vmware.dcp.services.samples.TestSampleAuthenticationService.java

License:Open Source License

private void testAccessTokenRequest(VerificationHost host) {
    // make a request to get the accessToken for the authentication service
    Operation requestOp = Operation.createGet(host, SampleAuthenticationService.SELF_LINK).forceRemote();
    Operation responseOp = host.getTestRequestSender().sendAndWait(requestOp);

    String cookieHeader = responseOp.getResponseHeader(Operation.SET_COOKIE_HEADER);
    assertNotNull(cookieHeader);/*from   w  w  w. jav a2s .c om*/

    // assert the auth token cookie
    Cookie tokenCookie = ClientCookieDecoder.LAX.decode(cookieHeader);
    assertEquals(SampleAuthenticationService.ACCESS_TOKEN, tokenCookie.value());

    // assert the auth token header
    assertEquals(SampleAuthenticationService.ACCESS_TOKEN,
            responseOp.getResponseHeader(Operation.REQUEST_AUTH_TOKEN_HEADER));
}

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

License:Open Source License

/**
 * List cookies that apply for the given request URI.
 *
 * @param uri request URI//w w  w . j  a v a  2 s  .com
 */
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:com.vmware.xenon.common.TestAuthentication.java

License:Open Source License

private void doAuthenticationServiceTokenRequest(VerificationHost host, boolean isSecure) throws Throwable {
    TestRequestSender sender = new TestRequestSender(host);
    host.log("Testing authenticationService token request");

    // make a request to get the accessToken for the authentication service
    Operation requestOp = Operation.createGet(host, TestAuthenticationService.SELF_LINK).forceRemote();
    Operation responseOp = sender.sendAndWait(requestOp);

    String cookieHeader = responseOp.getResponseHeader(SET_COOKIE_HEADER);
    assertNotNull(cookieHeader);//from   w  w w.  j  a v  a 2  s  .c  o  m

    // assert the auth token cookie
    Cookie tokenCookie = ClientCookieDecoder.LAX.decode(cookieHeader);
    assertEquals(TestAuthenticationService.ACCESS_TOKEN, tokenCookie.value());
    assertEquals(isSecure, tokenCookie.isSecure());

    // assert the auth token header
    assertEquals(TestAuthenticationService.ACCESS_TOKEN,
            responseOp.getResponseHeader(Operation.REQUEST_AUTH_TOKEN_HEADER));

    host.log("AuthenticationService token request is working");
}

From source file:com.vmware.xenon.common.TestAuthentication.java

License:Open Source License

private void testExternalAuthTokenRequestMultinode(ServiceHost host) {
    TestRequestSender sender = new TestRequestSender(host);

    // make a request to get the accessToken for the authentication service
    Operation requestOp = Operation.createGet(host, TestAuthenticationService.SELF_LINK).forceRemote();
    Operation responseOp = sender.sendAndWait(requestOp);

    String cookieHeader = responseOp.getResponseHeader(SET_COOKIE_HEADER);
    assertNotNull(cookieHeader);/*from  ww  w. j a  v  a2  s . c o m*/

    // assert the auth token cookie
    Cookie tokenCookie = ClientCookieDecoder.LAX.decode(cookieHeader);
    assertEquals(TestAuthenticationService.ACCESS_TOKEN, tokenCookie.value());

    // assert the auth token header
    assertEquals(TestAuthenticationService.ACCESS_TOKEN,
            responseOp.getResponseHeader(Operation.REQUEST_AUTH_TOKEN_HEADER));
}

From source file:com.vmware.xenon.services.common.authn.TestBasicAuthenticationService.java

License:Open Source License

private boolean validateAuthToken(Operation op) {
    String cookieHeader = op.getResponseHeader(SET_COOKIE_HEADER);
    if (cookieHeader == null) {
        this.host.failIteration(new IllegalStateException("Missing cookie header"));
        return false;
    }/*from  w ww.  java 2s.c  o m*/

    Cookie tokenCookie = ClientCookieDecoder.LAX.decode(cookieHeader);
    if (!AuthenticationConstants.REQUEST_AUTH_TOKEN_COOKIE.equals(tokenCookie.name())) {
        this.host.failIteration(new IllegalStateException("Missing auth cookie"));
        return false;
    }

    if (op.getResponseHeader(Operation.REQUEST_AUTH_TOKEN_HEADER) == null) {
        this.host.failIteration(new IllegalStateException("Missing auth token"));
        return false;
    }

    String authCookie = tokenCookie.value();
    String authToken = op.getResponseHeader(Operation.REQUEST_AUTH_TOKEN_HEADER);

    if (!authCookie.equals(authToken)) {
        this.host.failIteration(new IllegalStateException("Auth token and auth cookie don't match"));
        return false;
    }
    return true;
}

From source file:gribbit.http.request.Request.java

License:Open Source License

/**
 * Get the value of a named cookie, or null if there are no cookies with this value. If there is more than one
 * cookie with the same name, returns the value of the cookie without a specified path, or if all cookies have
 * paths, returns the value of the cookie with the longest path.
 *//*w ww. j a  va  2 s .  c o m*/
public String getCookieValue(String cookieName) {
    Cookie cookie = getCookie(cookieName);
    if (cookie == null) {
        return null;
    } else {
        return cookie.value();
    }
}

From source file:io.syncframework.netty.RequestWrapper.java

License:Apache License

public void setRequest(HttpRequest request) {
    this.request = request;
    this.session = null;

    ////from   ww w. j ava2  s .  co m
    // setting headers...
    //
    for (Entry<String, String> entry : request.headers()) {
        String name = entry.getKey();
        String value = entry.getValue();

        if (log.isTraceEnabled())
            log.trace("header: {} -> {}", name, value);

        if (name.toLowerCase().equals(HttpHeaderNames.COOKIE.toString())) {
            ServerCookieDecoder decoder = ServerCookieDecoder.STRICT;
            Set<Cookie> cookies = decoder.decode(value);
            for (Cookie cookie : cookies) {
                cookieContext.put(cookie.name(), cookie.value());
            }
            continue;
        }

        List<String> values = headers.get(name);
        if (values == null) {
            values = new LinkedList<String>();
        }
        values.add(entry.getValue());
        headers.put(name, values);
    }

    //
    // parameters from the URL
    //
    QueryStringDecoder decoderQuery = new QueryStringDecoder(request.uri());
    Map<String, List<String>> uriAttributes = decoderQuery.parameters();
    for (Entry<String, List<String>> attr : uriAttributes.entrySet()) {
        parameters.put(attr.getKey(), attr.getValue());
    }
}