Search in sources :

Example 1 with PublicSuffixMatcher

use of org.apache.http.conn.util.PublicSuffixMatcher in project fess-crawler by codelibs.

the class HcHttpClient method buildCookieSpecRegistry.

protected Lookup<CookieSpecProvider> buildCookieSpecRegistry() {
    if (cookieSpecRegistry != null) {
        return cookieSpecRegistry;
    }
    final PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.getDefault();
    final CookieSpecProvider defaultProvider = new DefaultCookieSpecProvider(CompatibilityLevel.DEFAULT, publicSuffixMatcher, cookieDatePatterns, false);
    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()).build();
}
Also used : RFC6265CookieSpecProvider(org.apache.http.impl.cookie.RFC6265CookieSpecProvider) IgnoreSpecProvider(org.apache.http.impl.cookie.IgnoreSpecProvider) CookieSpecProvider(org.apache.http.cookie.CookieSpecProvider) DefaultCookieSpecProvider(org.apache.http.impl.cookie.DefaultCookieSpecProvider) RFC6265CookieSpecProvider(org.apache.http.impl.cookie.RFC6265CookieSpecProvider) NetscapeDraftSpecProvider(org.apache.http.impl.cookie.NetscapeDraftSpecProvider) PublicSuffixMatcher(org.apache.http.conn.util.PublicSuffixMatcher) DefaultCookieSpecProvider(org.apache.http.impl.cookie.DefaultCookieSpecProvider)

Example 2 with PublicSuffixMatcher

use of org.apache.http.conn.util.PublicSuffixMatcher in project tech by ffyyhh995511.

the class HttpClientUtil method sendHttpsGet.

/**
 * 发送Get请求Https
 *
 * @param httpPost
 * @return
 */
private String sendHttpsGet(HttpGet httpGet) {
    CloseableHttpClient httpClient = null;
    CloseableHttpResponse response = null;
    HttpEntity entity = null;
    String responseContent = null;
    try {
        // 创建默认的httpClient实例.
        PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(new URL(httpGet.getURI().toString()));
        DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher);
        httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build();
        httpGet.setConfig(requestConfig);
        // 执行请求
        response = httpClient.execute(httpGet);
        entity = response.getEntity();
        responseContent = EntityUtils.toString(entity, "UTF-8");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            // 关闭连接,释放资源
            if (response != null) {
                response.close();
            }
            if (httpClient != null) {
                httpClient.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return responseContent;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) PublicSuffixMatcher(org.apache.http.conn.util.PublicSuffixMatcher) IOException(java.io.IOException) URL(java.net.URL) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 3 with PublicSuffixMatcher

use of org.apache.http.conn.util.PublicSuffixMatcher in project gradle by gradle.

the class HttpClientConfigurer method configureCookieSpecRegistry.

private void configureCookieSpecRegistry(HttpClientBuilder builder) {
    PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.getDefault();
    builder.setPublicSuffixMatcher(publicSuffixMatcher);
    // Add more data patterns to the default configuration to work around https://github.com/gradle/gradle/issues/1596
    final CookieSpecProvider defaultProvider = new DefaultCookieSpecProvider(DefaultCookieSpecProvider.CompatibilityLevel.DEFAULT, publicSuffixMatcher, new String[] { // Netscape expires pattern
    "EEE, dd-MMM-yy HH:mm:ss z", DateUtils.PATTERN_RFC1036, DateUtils.PATTERN_ASCTIME, DateUtils.PATTERN_RFC1123 }, false);
    final CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider(RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher);
    final CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider(RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher);
    builder.setDefaultCookieSpecRegistry(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()).build());
}
Also used : RFC6265CookieSpecProvider(org.apache.http.impl.cookie.RFC6265CookieSpecProvider) IgnoreSpecProvider(org.apache.http.impl.cookie.IgnoreSpecProvider) CookieSpecProvider(org.apache.http.cookie.CookieSpecProvider) DefaultCookieSpecProvider(org.apache.http.impl.cookie.DefaultCookieSpecProvider) RFC6265CookieSpecProvider(org.apache.http.impl.cookie.RFC6265CookieSpecProvider) NetscapeDraftSpecProvider(org.apache.http.impl.cookie.NetscapeDraftSpecProvider) PublicSuffixMatcher(org.apache.http.conn.util.PublicSuffixMatcher) DefaultCookieSpecProvider(org.apache.http.impl.cookie.DefaultCookieSpecProvider)

Example 4 with PublicSuffixMatcher

use of org.apache.http.conn.util.PublicSuffixMatcher in project i2p.i2p by i2p.

the class I2PSSLSocketFactory method getDefaultMatcher.

/**
 *  From Apache PublicSuffixMatcherLoader.getDefault()
 *
 *  https://publicsuffix.org/list/effective_tld_names.dat
 *  What does this get us?
 *  Deciding whether to issue or accept an SSL wildcard certificate for *.public.suffix.
 *
 *  @return null on failure
 *  @since 0.9.20
 */
private static PublicSuffixMatcher getDefaultMatcher(I2PAppContext ctx) {
    synchronized (I2PSSLSocketFactory.class) {
        if (!_matcherLoaded) {
            String geoDir = ctx.getProperty(PROP_GEOIP_DIR, GEOIP_DIR_DEFAULT);
            File geoFile = new File(geoDir);
            if (!geoFile.isAbsolute())
                geoFile = new File(ctx.getBaseDir(), geoDir);
            geoFile = new File(geoFile, PUBLIC_SUFFIX_LIST);
            Log log = ctx.logManager().getLog(I2PSSLSocketFactory.class);
            if (geoFile.exists()) {
                try {
                    // we can't use PublicSuffixMatcherLoader.load() here because we
                    // want to add some of our own and a PublicSuffixMatcher's
                    // underlying PublicSuffixList is immutable and inaccessible
                    long begin = System.currentTimeMillis();
                    InputStream in = null;
                    PublicSuffixList list = new PublicSuffixList(Arrays.asList(ADDITIONAL_TLDS), Collections.<String>emptyList());
                    try {
                        in = new FileInputStream(geoFile);
                        PublicSuffixList list2 = new PublicSuffixListParser().parse(new InputStreamReader(in, "UTF-8"));
                        list = merge(list, list2);
                    } finally {
                        try {
                            if (in != null)
                                in.close();
                        } catch (IOException ioe) {
                        }
                    }
                    DEFAULT_MATCHER = new PublicSuffixMatcher(list.getRules(), list.getExceptions());
                    if (log.shouldWarn())
                        log.warn("Loaded " + geoFile + " in " + (System.currentTimeMillis() - begin) + " ms and created list with " + list.getRules().size() + " entries and " + list.getExceptions().size() + " exceptions");
                } catch (IOException ex) {
                    log.error("Failure loading public suffix list from " + geoFile, ex);
                // DEFAULT_MATCHER remains null
                }
            } else {
                List<String> list = new ArrayList<String>(320);
                addCountries(ctx, list);
                list.addAll(Arrays.asList(DEFAULT_TLDS));
                list.addAll(Arrays.asList(ADDITIONAL_TLDS));
                DEFAULT_MATCHER = new PublicSuffixMatcher(list, null);
                if (log.shouldWarn())
                    log.warn("No public suffix list found at " + geoFile + " - created default with " + list.size() + " entries");
            }
        }
        _matcherLoaded = true;
    }
    return DEFAULT_MATCHER;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PublicSuffixList(org.apache.http.conn.util.PublicSuffixList) PublicSuffixListParser(org.apache.http.conn.util.PublicSuffixListParser) PublicSuffixMatcher(org.apache.http.conn.util.PublicSuffixMatcher) File(java.io.File)

Aggregations

PublicSuffixMatcher (org.apache.http.conn.util.PublicSuffixMatcher)4 IOException (java.io.IOException)2 CookieSpecProvider (org.apache.http.cookie.CookieSpecProvider)2 DefaultCookieSpecProvider (org.apache.http.impl.cookie.DefaultCookieSpecProvider)2 IgnoreSpecProvider (org.apache.http.impl.cookie.IgnoreSpecProvider)2 NetscapeDraftSpecProvider (org.apache.http.impl.cookie.NetscapeDraftSpecProvider)2 RFC6265CookieSpecProvider (org.apache.http.impl.cookie.RFC6265CookieSpecProvider)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 GeneralSecurityException (java.security.GeneralSecurityException)1 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 DefaultHostnameVerifier (org.apache.http.conn.ssl.DefaultHostnameVerifier)1 PublicSuffixList (org.apache.http.conn.util.PublicSuffixList)1 PublicSuffixListParser (org.apache.http.conn.util.PublicSuffixListParser)1