Example usage for org.apache.http.cookie CookieAttributeHandler match

List of usage examples for org.apache.http.cookie CookieAttributeHandler match

Introduction

In this page you can find the example usage for org.apache.http.cookie CookieAttributeHandler match.

Prototype

boolean match(Cookie cookie, CookieOrigin origin);

Source Link

Document

Matches the given value (property of the destination host where request is being submitted) with the corresponding cookie attribute.

Usage

From source file:org.apache.solr.client.solrj.impl.SolrPortAwareCookieSpecTest.java

@Test
public void testDomainInvalidInput() throws Exception {
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    try {/*from   w  w w.  j a  v a  2  s  .c o  m*/
        h.match(null, null);
        Assert.fail("IllegalArgumentException must have been thrown");
    } catch (final IllegalArgumentException ex) {
        // expected
    }
    try {
        h.match(new BasicClientCookie("name", "value"), null);
        Assert.fail("IllegalArgumentException must have been thrown");
    } catch (final IllegalArgumentException ex) {
        // expected
    }
}

From source file:org.apache.solr.client.solrj.impl.SolrPortAwareCookieSpecTest.java

@Test
public void testDomainMatch1() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

    cookie.setDomain(null);//  w ww  .ja  va 2  s . com
    Assert.assertFalse(h.match(cookie, origin));

    cookie.setDomain(".somedomain.com");
    Assert.assertTrue(h.match(cookie, origin));
}

From source file:org.apache.solr.client.solrj.impl.SolrPortAwareCookieSpecTest.java

@Test
public void testDomainMatch2() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.whatever.somedomain.com", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

    cookie.setDomain(".somedomain.com");
    Assert.assertTrue(h.match(cookie, origin));
}

From source file:org.apache.solr.client.solrj.impl.SolrPortAwareCookieSpecTest.java

@Test
public void testDomainHostPortMatch() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("myhost", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

    cookie.setDomain("myhost");
    try {//from  w w w .j  av a 2 s .  co  m
        h.match(cookie, null);
        Assert.fail("IllegalArgumentException should have been thrown, since origin is null.");
    } catch (final IllegalArgumentException ex) {
        // expected
    }

    cookie.setDomain(null);
    Assert.assertFalse(h.match(cookie, origin));

    cookie.setDomain("otherhost");
    Assert.assertFalse(h.match(cookie, origin));

    cookie.setDomain("myhost");
    Assert.assertTrue(h.match(cookie, origin));

    cookie.setDomain("myhost:80");
    Assert.assertTrue(h.match(cookie, origin));

    cookie.setDomain("myhost:8080");
    Assert.assertFalse(h.match(cookie, origin));
}