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

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

Introduction

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

Prototype

public BestMatchSpec() 

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;//from  w  ww .  j a v  a2s  .  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();
}