Java 类org.apache.http.cookie.CookieSpecProvider 实例源码

项目:RobotServer    文件:HttpService.java   
@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();
}
项目:remote-files-sync    文件:InternalHttpClient.java   
public InternalHttpClient(
        final ClientExecChain execChain,
        final HttpClientConnectionManager connManager,
        final HttpRoutePlanner routePlanner,
        final Lookup<CookieSpecProvider> cookieSpecRegistry,
        final Lookup<AuthSchemeProvider> authSchemeRegistry,
        final CookieStore cookieStore,
        final CredentialsProvider credentialsProvider,
        final RequestConfig defaultConfig,
        final List<Closeable> closeables) {
    super();
    Args.notNull(execChain, "HTTP client exec chain");
    Args.notNull(connManager, "HTTP connection manager");
    Args.notNull(routePlanner, "HTTP route planner");
    this.execChain = execChain;
    this.connManager = connManager;
    this.routePlanner = routePlanner;
    this.cookieSpecRegistry = cookieSpecRegistry;
    this.authSchemeRegistry = authSchemeRegistry;
    this.cookieStore = cookieStore;
    this.credentialsProvider = credentialsProvider;
    this.defaultConfig = defaultConfig;
    this.closeables = closeables;
}
项目:purecloud-iot    文件:CookieSpecRegistries.java   
/**
 * Creates a builder containing the default registry entries, using the provided public suffix matcher.
 */
public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder(final PublicSuffixMatcher publicSuffixMatcher) {
    final CookieSpecProvider defaultProvider = new DefaultCookieSpecProvider(publicSuffixMatcher);
    final CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider(
            RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher);
    final CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider(
            RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher);
    return RegistryBuilder.<CookieSpecProvider>create()
            .register(CookieSpecs.DEFAULT, defaultProvider)
            .register("best-match", defaultProvider)
            .register("compatibility", defaultProvider)
            .register(CookieSpecs.STANDARD, laxStandardProvider)
            .register(CookieSpecs.STANDARD_STRICT, strictStandardProvider)
            .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
            .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider());
}
项目:purecloud-iot    文件:InternalHttpClient.java   
public InternalHttpClient(
        final ClientExecChain execChain,
        final HttpClientConnectionManager connManager,
        final HttpRoutePlanner routePlanner,
        final Lookup<CookieSpecProvider> cookieSpecRegistry,
        final Lookup<AuthSchemeProvider> authSchemeRegistry,
        final CookieStore cookieStore,
        final CredentialsProvider credentialsProvider,
        final RequestConfig defaultConfig,
        final List<Closeable> closeables) {
    super();
    Args.notNull(execChain, "HTTP client exec chain");
    Args.notNull(connManager, "HTTP connection manager");
    Args.notNull(routePlanner, "HTTP route planner");
    this.execChain = execChain;
    this.connManager = connManager;
    this.routePlanner = routePlanner;
    this.cookieSpecRegistry = cookieSpecRegistry;
    this.authSchemeRegistry = authSchemeRegistry;
    this.cookieStore = cookieStore;
    this.credentialsProvider = credentialsProvider;
    this.defaultConfig = defaultConfig;
    this.closeables = closeables;
}
项目:purecloud-iot    文件:TestRequestAddCookies.java   
@Before
public void setUp() {
    this.target = new HttpHost("localhost.local", 80);
    this.cookieStore = new BasicCookieStore();
    final BasicClientCookie2 cookie1 = new BasicClientCookie2("name1", "value1");
    cookie1.setVersion(1);
    cookie1.setDomain("localhost.local");
    cookie1.setPath("/");
    this.cookieStore.addCookie(cookie1);
    final BasicClientCookie2 cookie2 = new BasicClientCookie2("name2", "value2");
    cookie2.setVersion(1);
    cookie2.setDomain("localhost.local");
    cookie2.setPath("/");
    this.cookieStore.addCookie(cookie2);

    this.cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
        .register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider())
        .register(CookieSpecs.STANDARD, new RFC2965SpecProvider())
        .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
        .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
        .build();
}
项目:purecloud-iot    文件:TestInternalHttpClient.java   
@SuppressWarnings("unchecked")
@Test
public void testExecuteLocalContext() throws Exception {
    final HttpGet httpget = new HttpGet("http://somehost/stuff");
    final HttpClientContext context = HttpClientContext.create();

    final Lookup<CookieSpecProvider> localCookieSpecRegistry = Mockito.mock(Lookup.class);
    final Lookup<AuthSchemeProvider> localAuthSchemeRegistry = Mockito.mock(Lookup.class);
    final CookieStore localCookieStore = Mockito.mock(CookieStore.class);
    final CredentialsProvider localCredentialsProvider = Mockito.mock(CredentialsProvider.class);
    final RequestConfig localConfig = RequestConfig.custom().build();

    context.setCookieSpecRegistry(localCookieSpecRegistry);
    context.setAuthSchemeRegistry(localAuthSchemeRegistry);
    context.setCookieStore(localCookieStore);
    context.setCredentialsProvider(localCredentialsProvider);
    context.setRequestConfig(localConfig);

    client.execute(httpget, context);

    Assert.assertSame(localCookieSpecRegistry, context.getCookieSpecRegistry());
    Assert.assertSame(localAuthSchemeRegistry, context.getAuthSchemeRegistry());
    Assert.assertSame(localCookieStore, context.getCookieStore());
    Assert.assertSame(localCredentialsProvider, context.getCredentialsProvider());
    Assert.assertSame(localConfig, context.getRequestConfig());
}
项目:Visit    文件:InternalHttpClient.java   
public InternalHttpClient(
        final ClientExecChain execChain,
        final HttpClientConnectionManager connManager,
        final HttpRoutePlanner routePlanner,
        final Lookup<CookieSpecProvider> cookieSpecRegistry,
        final Lookup<AuthSchemeProvider> authSchemeRegistry,
        final CookieStore cookieStore,
        final CredentialsProvider credentialsProvider,
        final RequestConfig defaultConfig,
        final List<Closeable> closeables) {
    super();
    Args.notNull(execChain, "HTTP client exec chain");
    Args.notNull(connManager, "HTTP connection manager");
    Args.notNull(routePlanner, "HTTP route planner");
    this.execChain = execChain;
    this.connManager = connManager;
    this.routePlanner = routePlanner;
    this.cookieSpecRegistry = cookieSpecRegistry;
    this.authSchemeRegistry = authSchemeRegistry;
    this.cookieStore = cookieStore;
    this.credentialsProvider = credentialsProvider;
    this.defaultConfig = defaultConfig;
    this.closeables = closeables;
}
项目:ZTLib    文件:InternalHttpClient.java   
public InternalHttpClient(
        final ClientExecChain execChain,
        final HttpClientConnectionManager connManager,
        final HttpRoutePlanner routePlanner,
        final Lookup<CookieSpecProvider> cookieSpecRegistry,
        final Lookup<AuthSchemeProvider> authSchemeRegistry,
        final CookieStore cookieStore,
        final CredentialsProvider credentialsProvider,
        final RequestConfig defaultConfig,
        final List<Closeable> closeables) {
    super();
    Args.notNull(execChain, "HTTP client exec chain");
    Args.notNull(connManager, "HTTP connection manager");
    Args.notNull(routePlanner, "HTTP route planner");
    this.execChain = execChain;
    this.connManager = connManager;
    this.routePlanner = routePlanner;
    this.cookieSpecRegistry = cookieSpecRegistry;
    this.authSchemeRegistry = authSchemeRegistry;
    this.cookieStore = cookieStore;
    this.credentialsProvider = credentialsProvider;
    this.defaultConfig = defaultConfig;
    this.closeables = closeables;
}
项目:jspider    文件:HttpClientFactory.java   
protected Lookup<CookieSpecProvider> createCookieSpecRegistry() {
    CookieSpecProvider cookieSpecProvider = createCookieSpecProvider();
    Registry<CookieSpecProvider> cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
            .register(NoopCookieSpecProvider.NAME, cookieSpecProvider)
            .build();
    return cookieSpecRegistry;
}
项目:tip    文件:HttpsClient.java   
public void setCookieStore(String path, String md5) throws ClassNotFoundException, IOException {
    context = HttpClientContext.create();
    Registry<CookieSpecProvider> registry = RegistryBuilder  
               .<CookieSpecProvider> create()  
               .register(CookieSpecs.DEFAULT, new DefaultCookieSpecProvider()).build();
    context.setCookieSpecRegistry(registry);

    context.setCookieStore(loadCookies(path, md5));
}
项目:itunesconnect-api    文件:Utils.java   
public static Executor createExecutor(CookieStore cookieStore) {
    @SuppressWarnings("deprecation") final Registry<CookieSpecProvider> cookieSpecRegistry =
            RegistryBuilder.<CookieSpecProvider>create().register(CookieSpecs.DEFAULT, new BrowserCompatSpecFactory()).build();
    final CloseableHttpClient client = HttpClients.custom()
            .setDefaultCookieSpecRegistry(cookieSpecRegistry)
            .setDefaultCookieStore(cookieStore)
            .build();
    return Executor.newInstance(client);
}
项目:ZhihuSpider    文件:HttpUtil.java   
public static HttpClientContext getHttpClientContext() {
    HttpClientContext context = null;
    context = HttpClientContext.create();
    Registry<CookieSpecProvider> registry = RegistryBuilder
            .<CookieSpecProvider>create()
            .register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
            .register(CookieSpecs.BROWSER_COMPATIBILITY,
                    new BrowserCompatSpecFactory()).build();
    context.setCookieSpecRegistry(registry);
    return context;
}
项目:jspider    文件:HttpClientFactory.java   
protected CookieSpecProvider createCookieSpecProvider() {
    return new NoopCookieSpecProvider();
}
项目:karate    文件:LenientCookieSpec.java   
public static Registry<CookieSpecProvider> registry() {
    CookieSpecProvider specProvider = (HttpContext hc) -> new LenientCookieSpec();
    return RegistryBuilder.<CookieSpecProvider>create()
            .register(KARATE, specProvider).build();
}
项目:remote-files-sync    文件:HttpClientContext.java   
public Lookup<CookieSpecProvider> getCookieSpecRegistry() {
    return getLookup(COOKIESPEC_REGISTRY, CookieSpecProvider.class);
}
项目:remote-files-sync    文件:HttpClientContext.java   
public void setCookieSpecRegistry(final Lookup<CookieSpecProvider> lookup) {
    setAttribute(COOKIESPEC_REGISTRY, lookup);
}
项目:remote-files-sync    文件:HttpClientBuilder.java   
/**
 * Assigns default {@link org.apache.http.cookie.CookieSpec} registry which will
 * be used for request execution if not explicitly set in the client execution
 * context.
 */
public final HttpClientBuilder setDefaultCookieSpecRegistry(
        final Lookup<CookieSpecProvider> cookieSpecRegistry) {
    this.cookieSpecRegistry = cookieSpecRegistry;
    return this;
}
项目:purecloud-iot    文件:ClientCustomPublicSuffixList.java   
public final static void main(String[] args) throws Exception {

        // Use PublicSuffixMatcherLoader to load public suffix list from a file,
        // resource or from an arbitrary URL
        PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(
                new URL("https://publicsuffix.org/list/effective_tld_names.dat"));

        // Please use the publicsuffix.org URL to download the list no more than once per day !!!
        // Please consider making a local copy !!!

        DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher);

        RFC6265CookieSpecProvider cookieSpecProvider = new RFC6265CookieSpecProvider(publicSuffixMatcher);
        Lookup<CookieSpecProvider> cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
                .register(CookieSpecs.DEFAULT, cookieSpecProvider)
                .register(CookieSpecs.STANDARD, cookieSpecProvider)
                .register(CookieSpecs.STANDARD_STRICT, cookieSpecProvider)
                .build();

        CloseableHttpClient httpclient = HttpClients.custom()
                .setSSLHostnameVerifier(hostnameVerifier)
                .setDefaultCookieSpecRegistry(cookieSpecRegistry)
                .build();
        try {

            HttpGet httpget = new HttpGet("https://httpbin.org/");

            System.out.println("executing request " + httpget.getRequestLine());

            CloseableHttpResponse response = httpclient.execute(httpget);
            try {
                HttpEntity entity = response.getEntity();

                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                EntityUtils.consume(entity);
            } finally {
                response.close();
            }
        } finally {
            httpclient.close();
        }
    }
项目:purecloud-iot    文件:HttpClientContext.java   
public Lookup<CookieSpecProvider> getCookieSpecRegistry() {
    return getLookup(COOKIESPEC_REGISTRY, CookieSpecProvider.class);
}
项目:purecloud-iot    文件:HttpClientContext.java   
public void setCookieSpecRegistry(final Lookup<CookieSpecProvider> lookup) {
    setAttribute(COOKIESPEC_REGISTRY, lookup);
}
项目:purecloud-iot    文件:CookieSpecRegistries.java   
/**
 * Creates a builder containing the default registry entries with the default public suffix matcher.
 */
public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder() {
    return createDefaultBuilder(PublicSuffixMatcherLoader.getDefault());
}
项目:purecloud-iot    文件:CookieSpecRegistries.java   
/**
 * Creates the default registry, using the default public suffix matcher.
 */
public static Lookup<CookieSpecProvider> createDefault() {
    return createDefault(PublicSuffixMatcherLoader.getDefault());
}
项目:purecloud-iot    文件:CookieSpecRegistries.java   
/**
 * Creates the default registry with the provided public suffix matcher
 */
public static Lookup<CookieSpecProvider> createDefault(final PublicSuffixMatcher publicSuffixMatcher) {
    return createDefaultBuilder(publicSuffixMatcher).build();
}
项目:Visit    文件:HttpClientContext.java   
public Lookup<CookieSpecProvider> getCookieSpecRegistry() {
    return getLookup(COOKIESPEC_REGISTRY, CookieSpecProvider.class);
}
项目:Visit    文件:HttpClientContext.java   
public void setCookieSpecRegistry(final Lookup<CookieSpecProvider> lookup) {
    setAttribute(COOKIESPEC_REGISTRY, lookup);
}
项目:Visit    文件:HttpClientBuilder.java   
/**
 * Assigns default {@link org.apache.http.cookie.CookieSpec} registry which will
 * be used for request execution if not explicitly set in the client execution
 * context.
 */
public final HttpClientBuilder setDefaultCookieSpecRegistry(
        final Lookup<CookieSpecProvider> cookieSpecRegistry) {
    this.cookieSpecRegistry = cookieSpecRegistry;
    return this;
}
项目:uw-android    文件:ClientCustomPublicSuffixList.java   
public final static void main(String[] args) throws Exception {

        // Use PublicSuffixMatcherLoader to load public suffix list from a file,
        // resource or from an arbitrary URL
        PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(
                new URL("https://publicsuffix.org/list/effective_tld_names.dat"));

        // Please use the publicsuffix.org URL to download the list no more than once per day !!!
        // Please consider making a local copy !!!

        DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher);

        RFC6265CookieSpecProvider cookieSpecProvider = new RFC6265CookieSpecProvider(publicSuffixMatcher);
        Lookup<CookieSpecProvider> cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create()
                .register(CookieSpecs.DEFAULT, cookieSpecProvider)
                .register(CookieSpecs.STANDARD, cookieSpecProvider)
                .register(CookieSpecs.STANDARD_STRICT, cookieSpecProvider)
                .build();

        CloseableHttpClient httpclient = HttpClients.custom()
                .setSSLHostnameVerifier(hostnameVerifier)
                .setDefaultCookieSpecRegistry(cookieSpecRegistry)
                .build();
        try {

            HttpGet httpget = new HttpGet("https://remotehost/");

            System.out.println("executing request " + httpget.getRequestLine());

            CloseableHttpResponse response = httpclient.execute(httpget);
            try {
                HttpEntity entity = response.getEntity();

                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                EntityUtils.consume(entity);
            } finally {
                response.close();
            }
        } finally {
            httpclient.close();
        }
    }
项目:ZTLib    文件:HttpClientContext.java   
public Lookup<CookieSpecProvider> getCookieSpecRegistry() {
    return getLookup(COOKIESPEC_REGISTRY, CookieSpecProvider.class);
}
项目:ZTLib    文件:HttpClientContext.java   
public void setCookieSpecRegistry(final Lookup<CookieSpecProvider> lookup) {
    setAttribute(COOKIESPEC_REGISTRY, lookup);
}
项目:ZTLib    文件:HttpClientBuilder.java   
/**
 * Assigns default {@link org.apache.http.cookie.CookieSpec} registry which will
 * be used for request execution if not explicitly set in the client execution
 * context.
 */
public final HttpClientBuilder setDefaultCookieSpecRegistry(
        final Lookup<CookieSpecProvider> cookieSpecRegistry) {
    this.cookieSpecRegistry = cookieSpecRegistry;
    return this;
}
项目:purecloud-iot    文件:HttpClientBuilder.java   
/**
 * Assigns default {@link org.apache.http.cookie.CookieSpec} registry which will
 * be used for request execution if not explicitly set in the client execution
 * context.
 *
 * @see org.apache.http.impl.client.CookieSpecRegistries
 *
 */
public final HttpClientBuilder setDefaultCookieSpecRegistry(
        final Lookup<CookieSpecProvider> cookieSpecRegistry) {
    this.cookieSpecRegistry = cookieSpecRegistry;
    return this;
}