当前位置: 首页>>代码示例>>Java>>正文


Java MalformedCookieException类代码示例

本文整理汇总了Java中org.apache.http.cookie.MalformedCookieException的典型用法代码示例。如果您正苦于以下问题:Java MalformedCookieException类的具体用法?Java MalformedCookieException怎么用?Java MalformedCookieException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MalformedCookieException类属于org.apache.http.cookie包,在下文中一共展示了MalformedCookieException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: afterPropertiesSet

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
	cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider> create().register("easy", new CookieSpecProvider() {
		public CookieSpec create(HttpContext context) {
			return new DefaultCookieSpec() {
				@Override
				public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException {
				}
			};
		}
	}).build();

	requestConfig = RequestConfig.custom().setCookieSpec("easy")
			.setConnectionRequestTimeout(propertyConfigurer.getIntValue("connection.request.timeout"))
			.setSocketTimeout(propertyConfigurer.getIntValue("socket_timeout"))
			.setConnectTimeout(propertyConfigurer.getIntValue("connection_timeout")).build();
}
 
开发者ID:JK-River,项目名称:RobotServer,代码行数:18,代码来源:HttpService.java

示例2: parse

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
/**
 * Parse cookie version attribute.
 */
public void parse(final SetCookie cookie, final String value)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (value == null) {
        throw new MalformedCookieException(
                "Missing value for version attribute");
    }
    int version = -1;
    try {
        version = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        version = -1;
    }
    if (version < 0) {
        throw new MalformedCookieException("Invalid cookie version.");
    }
    cookie.setVersion(version);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:RFC2965VersionAttributeHandler.java

示例3: parse

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
public void parse(final SetCookie cookie, final String value)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (value == null) {
        throw new MalformedCookieException("Missing value for max-age attribute");
    }
    int age;
    try {
        age = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        throw new MalformedCookieException ("Invalid max-age attribute: "
                + value);
    }
    if (age < 0) {
        throw new MalformedCookieException ("Negative max-age attribute: "
                + value);
    }
    cookie.setExpiryDate(new Date(System.currentTimeMillis() + age * 1000L));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:BasicMaxAgeHandler.java

示例4: parse

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
@Override
public List<Cookie> parse(
        final Header header,
        CookieOrigin origin) throws MalformedCookieException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE2)) {
        throw new MalformedCookieException("Unrecognized cookie header '"
                + header.toString() + "'");
    }
    origin = adjustEffectiveHost(origin);
    HeaderElement[] elems = header.getElements();
    return createCookies(elems, origin);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:RFC2965Spec.java

示例5: validate

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
public void validate(
        final Cookie cookie,
        final CookieOrigin origin) throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (cookie.getVersion() > 0) {
        if (cookie instanceof SetCookie2) {
            getStrict().validate(cookie, origin);
        } else {
            getObsoleteStrict().validate(cookie, origin);
        }
    } else {
        getCompat().validate(cookie, origin);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:BestMatchSpec.java

示例6: parsePortAttribute

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:RFC2965PortAttributeHandler.java

示例7: validate

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    int port = origin.getPort();
    if (cookie instanceof ClientCookie
            && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
        if (!portMatch(port, cookie.getPorts())) {
            throw new CookieRestrictionViolationException(
                    "Port attribute violates RFC 2965: "
                    + "Request port not found in cookie's port list.");
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:RFC2965PortAttributeHandler.java

示例8: parse

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
/**
 * Parse cookie domain attribute.
 */
public void parse(final SetCookie cookie, String domain)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (domain == null) {
        throw new MalformedCookieException(
                "Missing value for domain attribute");
    }
    if (domain.trim().length() == 0) {
        throw new MalformedCookieException(
                "Blank value for domain attribute");
    }
    domain = domain.toLowerCase(Locale.ENGLISH);
    if (!domain.startsWith(".")) {
        // Per RFC 2965 section 3.2.2
        // "... If an explicitly specified value does not start with
        // a dot, the user agent supplies a leading dot ..."
        // That effectively implies that the domain attribute
        // MAY NOT be an IP address of a host name
        domain = '.' + domain;
    }
    cookie.setDomain(domain);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:RFC2965DomainAttributeHandler.java

示例9: parse

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
public void parse(final SetCookie cookie, final String value)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (value == null) {
        throw new MalformedCookieException("Missing value for version attribute");
    }
    if (value.trim().length() == 0) {
        throw new MalformedCookieException("Blank value for version attribute");
    }
    try {
       cookie.setVersion(Integer.parseInt(value));
    } catch (NumberFormatException e) {
        throw new MalformedCookieException("Invalid version: "
            + e.getMessage());
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:RFC2109VersionHandler.java

示例10: validate

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    super.validate(cookie, origin);
    // Perform Netscape Cookie draft specific validation
    String host = origin.getHost();
    String domain = cookie.getDomain();
    if (host.contains(".")) {
        int domainParts = new StringTokenizer(domain, ".").countTokens();

        if (isSpecialDomain(domain)) {
            if (domainParts < 2) {
                throw new CookieRestrictionViolationException("Domain attribute \""
                    + domain
                    + "\" violates the Netscape cookie specification for "
                    + "special domains");
            }
        } else {
            if (domainParts < 3) {
                throw new CookieRestrictionViolationException("Domain attribute \""
                    + domain
                    + "\" violates the Netscape cookie specification");
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:NetscapeDomainHandler.java

示例11: parsePortAttribute

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
/**
 * 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 {
    final StringTokenizer st = new StringTokenizer(portValue, ",");
    final 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 (final NumberFormatException e) {
        throw new MalformedCookieException ("Invalid Port "
                                            + "attribute: " + e.getMessage());
    }
    return ports;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:29,代码来源:RFC2965PortAttributeHandlerHC4.java

示例12: testRFC2109VersionValidate

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
@Test
public void testRFC2109VersionValidate() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
    final CookieAttributeHandler h = new RFC2109VersionHandler();

    cookie.setVersion(12);
    h.validate(cookie, origin);

    cookie.setVersion(-12);
    try {
        h.validate(cookie, origin);
        Assert.fail("MalformedCookieException must have been thrown");
    } catch (final MalformedCookieException ex) {
        // expected
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestRFC2109CookieAttribHandlers.java

示例13: testSecondDomainLevelCookie

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
/**
 * Tests if that invalid second domain level cookie gets
 * rejected in the strict mode, but gets accepted in the
 * browser compatibility mode.
 */
@Test
public void testSecondDomainLevelCookie() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", null);
    cookie.setDomain(".sourceforge.net");
    cookie.setAttribute(ClientCookie.DOMAIN_ATTR, cookie.getDomain());
    cookie.setPath("/");
    cookie.setAttribute(ClientCookie.PATH_ATTR, cookie.getPath());

    final CookieSpec cookiespec = new RFC2109Spec();
    final CookieOrigin origin = new CookieOrigin("sourceforge.net", 80, "/", false);
    try {
        cookiespec.validate(cookie, origin);
        Assert.fail("MalformedCookieException should have been thrown");
    } catch (final MalformedCookieException e) {
        // Expected
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestCookieRFC2109Spec.java

示例14: parse

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
public void parse(final SetCookie cookie, final String value)
        throws MalformedCookieException {
    Args.notNull(cookie, "Cookie");
    if (value == null) {
        throw new MalformedCookieException("Missing value for version attribute");
    }
    if (value.trim().length() == 0) {
        throw new MalformedCookieException("Blank value for version attribute");
    }
    try {
       cookie.setVersion(Integer.parseInt(value));
    } catch (final NumberFormatException e) {
        throw new MalformedCookieException("Invalid version: "
            + e.getMessage());
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:17,代码来源:RFC2109VersionHandlerHC4.java

示例15: testNetscapeDomainValidate3

import org.apache.http.cookie.MalformedCookieException; //导入依赖的package包/类
@Test
public void testNetscapeDomainValidate3() throws Exception {
    final BasicClientCookie cookie = new BasicClientCookie("name", "value");
    final CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
    final CookieAttributeHandler h = new NetscapeDomainHandler();

    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
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestNetscapeCookieAttribHandlers.java


注:本文中的org.apache.http.cookie.MalformedCookieException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。