Example usage for org.apache.http.impl.cookie BestMatchSpec parse

List of usage examples for org.apache.http.impl.cookie BestMatchSpec parse

Introduction

In this page you can find the example usage for org.apache.http.impl.cookie BestMatchSpec parse.

Prototype

public List<Cookie> parse(final Header header, final CookieOrigin origin) throws MalformedCookieException 

Source Link

Usage

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

@Test
public void testParseCookie() throws MalformedCookieException {
    BestMatchSpec parser = new BestMatchSpec();
    List<Cookie> cookies = parser.parse(
            new BasicHeader("Set-Cookie", "JSESSIONID=F39EC36E999C90604EAFF7A87F88DA58; Path=/"),
            new CookieOrigin("localhost", 80, "/toto", false));
    Assert.assertEquals(cookies.size(), 1);
    Assert.assertEquals(cookies.get(0).getPath(), "/");
    Assert.assertEquals(cookies.get(0).getName(), "JSESSIONID");
    Assert.assertEquals(cookies.get(0).getValue(), "F39EC36E999C90604EAFF7A87F88DA58");
}

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

public String rewriteCookie(String headerValue) throws URISyntaxException, InvalidCookieException {
    BestMatchSpec parser = new BestMatchSpec();
    List<Cookie> cookies;//  www. ja  v a2  s  .c o  m
    try {
        cookies = parser.parse(new BasicHeader("Set-Cookie", headerValue), new CookieOrigin(
                targetServer.getHost(), getPortOrDefault(targetServer), targetServer.getPath(), false));
    } catch (MalformedCookieException e) {
        throw new InvalidCookieException(e);
    }
    if (cookies.size() != 1) {
        throw new InvalidCookieException();
    }
    Cookie cookie = rewriteCookiePathIfNeeded(cookies.get(0));
    CookieFormatter cookieFormatter = CookieFormatter.createFromApacheCookie(cookie);
    return cookieFormatter.asString();
}