Example usage for org.apache.http.client.config CookieSpecs IGNORE_COOKIES

List of usage examples for org.apache.http.client.config CookieSpecs IGNORE_COOKIES

Introduction

In this page you can find the example usage for org.apache.http.client.config CookieSpecs IGNORE_COOKIES.

Prototype

String IGNORE_COOKIES

To view the source code for org.apache.http.client.config CookieSpecs IGNORE_COOKIES.

Click Source Link

Document

The policy that ignores cookies.

Usage

From source file:fredboat.audio.player.AbstractPlayer.java

public static AudioPlayerManager registerSourceManagers(AudioPlayerManager mng) {
    mng.registerSourceManager(new PlaylistImportSourceManager());
    //Determine which Source managers are enabled
    //By default, all are enabled except HttpAudioSources
    if (Config.CONFIG.isYouTubeEnabled()) {
        YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager();
        youtubeAudioSourceManager.configureRequests(
                config -> RequestConfig.copy(config).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build());
        mng.registerSourceManager(youtubeAudioSourceManager);
    }/*w  ww.j ava  2s.co m*/
    if (Config.CONFIG.isSoundCloudEnabled()) {
        mng.registerSourceManager(new SoundCloudAudioSourceManager());
    }
    if (Config.CONFIG.isBandCampEnabled()) {
        mng.registerSourceManager(new BandcampAudioSourceManager());
    }
    if (Config.CONFIG.isTwitchEnabled()) {
        mng.registerSourceManager(new TwitchStreamAudioSourceManager());
    }
    if (Config.CONFIG.isVimeoEnabled()) {
        mng.registerSourceManager(new VimeoAudioSourceManager());
    }
    if (Config.CONFIG.isMixerEnabled()) {
        mng.registerSourceManager(new BeamAudioSourceManager());
    }
    if (Config.CONFIG.isSpotifyEnabled()) {
        mng.registerSourceManager(new SpotifyPlaylistSourceManager());
    }
    if (Config.CONFIG.isHttpEnabled()) {
        //add new source managers above the HttpAudio one, because it will either eat your request or throw an exception
        //so you will never reach a source manager below it
        mng.registerSourceManager(new HttpSourceManager());
    }
    return mng;
}

From source file:com.moviejukebox.tools.YamjHttpClientBuilder.java

@SuppressWarnings("resource")
private static YamjHttpClient buildHttpClient() {
    LOG.trace("Create new YAMJ http client");

    // create proxy
    HttpHost proxy = null;//from w  w w .  j  a v a2  s.  com
    CredentialsProvider credentialsProvider = null;

    if (StringUtils.isNotBlank(PROXY_HOST) && PROXY_PORT > 0) {
        proxy = new HttpHost(PROXY_HOST, PROXY_PORT);

        if (StringUtils.isNotBlank(PROXY_USERNAME) && StringUtils.isNotBlank(PROXY_PASSWORD)) {
            credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(new AuthScope(PROXY_HOST, PROXY_PORT),
                    new UsernamePasswordCredentials(PROXY_USERNAME, PROXY_PASSWORD));
        }
    }

    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT_SOCKET).build());
    connManager.setMaxTotal(20);
    connManager.setDefaultMaxPerRoute(2);

    CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(1000).setMaxObjectSize(8192).build();

    HttpClientBuilder builder = CachingHttpClientBuilder.create().setCacheConfig(cacheConfig)
            .setConnectionManager(connManager).setProxy(proxy)
            .setDefaultCredentialsProvider(credentialsProvider)
            .setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(TIMEOUT_READ)
                    .setConnectTimeout(TIMEOUT_CONNECT).setSocketTimeout(TIMEOUT_SOCKET)
                    .setCookieSpec(CookieSpecs.IGNORE_COOKIES).setProxy(proxy).build());

    // show status
    showStatus();

    // build the client
    YamjHttpClient wrapper = new YamjHttpClient(builder.build(), connManager);
    wrapper.setUserAgentSelector(new WebBrowserUserAgentSelector());
    wrapper.addGroupLimit(".*", 1); // default limit, can be overwritten

    // First we have to read/create the rules
    String maxDownloadSlots = PropertiesUtil.getProperty("mjb.MaxDownloadSlots");
    if (StringUtils.isNotBlank(maxDownloadSlots)) {
        LOG.debug("Using download limits: {}", maxDownloadSlots);

        Pattern pattern = Pattern.compile(",?\\s*([^=]+)=(\\d+)");
        Matcher matcher = pattern.matcher(maxDownloadSlots);
        while (matcher.find()) {
            String group = matcher.group(1);
            try {
                final Integer maxResults = Integer.valueOf(matcher.group(2));
                wrapper.addGroupLimit(group, maxResults);
                LOG.trace("Added download slot '{}' with max results {}", group, maxResults);
            } catch (NumberFormatException error) {
                LOG.debug("Rule '{}' is no valid regexp, ignored", group);
            }
        }
    }

    return wrapper;
}

From source file:co.paralleluniverse.fibers.dropwizard.FiberHttpClientBuilder.java

/**
 * Map the parameters in HttpClientConfiguration to a BasicHttpParams object
 *
 * @return a BasicHttpParams object from the HttpClientConfiguration
 *///w ww . j  a  v a2 s  .  co  m
protected RequestConfig createHttpParams() {
    RequestConfig.Builder rcb = RequestConfig.custom();
    rcb.setCookieSpec(CookieSpecs.BEST_MATCH);
    if (configuration.isCookiesEnabled())
        rcb.setCookieSpec(CookieSpecs.BEST_MATCH);
    else
        rcb.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
    rcb.setStaleConnectionCheckEnabled(false);
    return rcb.build();
}

From source file:br.com.jbugbrasil.bot.service.jbossbooks.JBossBooksService.java

private CloseableHttpClient client() {
    RequestConfig config = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
    return HttpClients.custom().setDefaultRequestConfig(config).build();
}

From source file:net.yacy.cora.protocol.http.HTTPClient.java

private static RequestConfig initRequestConfig() {
    final RequestConfig.Builder builder = RequestConfig.custom();
    // IMPORTANT - if not set to 'false' then servers do not process the request until a time-out of 2 seconds
    builder.setExpectContinueEnabled(false);
    // timeout in milliseconds until a connection is established in milliseconds
    builder.setConnectionRequestTimeout(default_timeout);
    builder.setConnectTimeout(default_timeout);
    // SO_TIMEOUT: maximum period inactivity between two consecutive data packets in milliseconds
    builder.setSocketTimeout(default_timeout);
    // ignore cookies, cause this may cause segfaults in default cookiestore and is not needed
    builder.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
    builder.setRedirectsEnabled(true);/*from  ww w .ja  v a2  s .  c  o  m*/
    builder.setRelativeRedirectsAllowed(true);
    return builder.build();
}

From source file:com.tremolosecurity.config.util.UnisonConfigManagerImpl.java

private void initSSL() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException,
        KeyStoreException, CertificateException, FileNotFoundException, IOException {
    if (this.getKeyManagerFactory() == null) {
        return;//from ww  w .j av  a  2s. com
    }

    KeyStore cacerts = KeyStore.getInstance(KeyStore.getDefaultType());

    String cacertsPath = System.getProperty("javax.net.ssl.trustStore");
    if (cacertsPath == null) {
        cacertsPath = System.getProperty("java.home") + "/lib/security/cacerts";
    }

    cacerts.load(new FileInputStream(cacertsPath), null);

    Enumeration<String> enumer = cacerts.aliases();
    while (enumer.hasMoreElements()) {
        String alias = enumer.nextElement();
        java.security.cert.Certificate cert = cacerts.getCertificate(alias);
        this.ks.setCertificateEntry(alias, cert);
    }

    SSLContext sslctx = SSLContexts.custom().loadTrustMaterial(this.ks)
            .loadKeyMaterial(this.ks, this.cfg.getKeyStorePassword().toCharArray()).build();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslctx,
            SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    PlainConnectionSocketFactory sf = PlainConnectionSocketFactory.getSocketFactory();
    httpClientRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", sf)
            .register("https", sslsf).build();

    globalHttpClientConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .setRedirectsEnabled(false).setAuthenticationEnabled(false).build();

}

From source file:de.codecentric.boot.admin.zuul.filters.route.SimpleHostRoutingFilter.java

protected CloseableHttpClient newClient() {
    final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT.get())
            .setConnectTimeout(CONNECTION_TIMEOUT.get()).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();

    HttpClientBuilder httpClientBuilder = HttpClients.custom();
    if (!this.sslHostnameValidationEnabled) {
        httpClientBuilder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
    }/*  ww w .j  a  va 2  s .co  m*/
    return httpClientBuilder.setConnectionManager(newConnectionManager()).useSystemProperties()
            .setDefaultRequestConfig(requestConfig)
            .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false))
            .setRedirectStrategy(new RedirectStrategy() {
                @Override
                public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context)
                        throws ProtocolException {
                    return false;
                }

                @Override
                public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response,
                        HttpContext context) throws ProtocolException {
                    return null;
                }
            }).build();
}

From source file:org.duniter.core.client.service.HttpServiceImpl.java

protected RequestConfig createRequestConfig(int timeout) {
    return RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout).setMaxRedirects(1)
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
}

From source file:net.sf.jasperreports.data.http.HttpDataService.java

protected CloseableHttpClient createHttpClient(Map<String, Object> parameters) {
    HttpClientBuilder clientBuilder = HttpClients.custom();

    // single connection
    BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager();
    clientBuilder.setConnectionManager(connManager);

    // ignore cookies for now
    RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
    clientBuilder.setDefaultRequestConfig(requestConfig);

    setAuthentication(parameters, clientBuilder);

    CloseableHttpClient client = clientBuilder.build();
    return client;
}

From source file:com.norconex.collector.http.client.impl.GenericHttpClientFactory.java

protected RequestConfig createRequestConfig() {
    RequestConfig.Builder builder = RequestConfig.custom().setConnectTimeout(connectionTimeout)
            .setSocketTimeout(socketTimeout).setConnectionRequestTimeout(connectionRequestTimeout)
            .setMaxRedirects(maxRedirects).setStaleConnectionCheckEnabled(!staleConnectionCheckDisabled)
            .setExpectContinueEnabled(expectContinueEnabled);
    if (cookiesDisabled) {
        builder.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
    } else {/*from ww w.ja  v a2  s .c  o  m*/
        builder.setCookieSpec(CookieSpecs.BEST_MATCH);
    }
    if (maxRedirects <= 0) {
        builder.setRedirectsEnabled(false);
    }
    if (StringUtils.isNotBlank(localAddress)) {
        try {
            builder.setLocalAddress(InetAddress.getByName(localAddress));
        } catch (UnknownHostException e) {
            throw new CollectorException("Invalid local address: " + localAddress, e);
        }
    }
    return builder.build();
}