Search in sources :

Example 1 with MalformedCookieException

use of org.apache.http.cookie.MalformedCookieException in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainValidate1.

@Test
public void testDomainValidate1() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain("somehost");
    h.validate(cookie, origin);
    cookie.setDomain("otherhost");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 2 with MalformedCookieException

use of org.apache.http.cookie.MalformedCookieException in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainHostPortValidate.

@Test
public void testDomainHostPortValidate() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain("somehost:80");
    h.validate(cookie, origin);
    cookie.setDomain("somehost:1234");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 3 with MalformedCookieException

use of org.apache.http.cookie.MalformedCookieException in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainValidate2.

@Test
public void testDomainValidate2() 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(".somedomain.com");
    h.validate(cookie, origin);
    cookie.setDomain(".otherdomain.com");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
    cookie.setDomain("www.otherdomain.com");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 4 with MalformedCookieException

use of org.apache.http.cookie.MalformedCookieException in project lucene-solr by apache.

the class SolrPortAwareCookieSpecTest method testDomainValidate3.

@Test
public void testDomainValidate3() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
    final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
    cookie.setDomain(".a.com");
    h.validate(cookie, origin);
    cookie.setDomain(".com");
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException ex) {
    // expected
    }
}
Also used : CookieAttributeHandler(org.apache.http.cookie.CookieAttributeHandler) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) CookieOrigin(org.apache.http.cookie.CookieOrigin) Test(org.junit.Test)

Example 5 with MalformedCookieException

use of org.apache.http.cookie.MalformedCookieException in project robovm by robovm.

the class RFC2965PortAttributeHandler method parsePortAttribute.

/**
     * Parses the given Port attribute value (e.g. "8000,8001,8002")
     * into an array of ports.
     *
     * @param portValue port attribute value
     * @return parsed array of ports
     * @throws MalformedCookieException if there is a problem in
     *          parsing due to invalid portValue.
     */
private static int[] parsePortAttribute(final String portValue) throws MalformedCookieException {
    StringTokenizer st = new StringTokenizer(portValue, ",");
    int[] ports = new int[st.countTokens()];
    try {
        int i = 0;
        while (st.hasMoreTokens()) {
            ports[i] = Integer.parseInt(st.nextToken().trim());
            if (ports[i] < 0) {
                throw new MalformedCookieException("Invalid Port attribute.");
            }
            ++i;
        }
    } catch (NumberFormatException e) {
        throw new MalformedCookieException("Invalid Port " + "attribute: " + e.getMessage());
    }
    return ports;
}
Also used : StringTokenizer(java.util.StringTokenizer) MalformedCookieException(org.apache.http.cookie.MalformedCookieException)

Aggregations

MalformedCookieException (org.apache.http.cookie.MalformedCookieException)30 CookieAttributeHandler (org.apache.http.cookie.CookieAttributeHandler)11 HeaderElement (org.apache.http.HeaderElement)9 Cookie (org.apache.http.cookie.Cookie)9 ArrayList (java.util.ArrayList)6 StringTokenizer (java.util.StringTokenizer)6 FormattedHeader (org.apache.http.FormattedHeader)6 NameValuePair (org.apache.http.NameValuePair)6 CookieOrigin (org.apache.http.cookie.CookieOrigin)6 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)6 ParserCursor (org.apache.http.message.ParserCursor)6 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)6 Test (org.junit.Test)5 Date (java.util.Date)4 ClientCookie (org.apache.http.cookie.ClientCookie)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Header (org.apache.http.Header)3 BasicHeader (org.apache.http.message.BasicHeader)1