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
}
}
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
}
}
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
}
}
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
}
}
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;
}
Aggregations