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:org.drftpd.util.HttpUtils.java

public static String retrieveHttpAsString(String url) throws HttpException, IOException {
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000)
            .setConnectionRequestTimeout(5000).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(requestConfig)
            .setUserAgent(_userAgent).build();
    HttpGet httpGet = new HttpGet(url);
    httpGet.setConfig(requestConfig);//  w  ww  .  j av  a  2 s. c  o  m
    CloseableHttpResponse response = null;
    try {
        response = httpclient.execute(httpGet);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            throw new HttpException("Error " + statusCode + " for URL " + url);
        }
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);
        EntityUtils.consume(entity);
        return data;
    } catch (IOException e) {
        throw new IOException("Error for URL " + url, e);
    } finally {
        if (response != null) {
            response.close();
        }
        httpclient.close();
    }
}

From source file:com.mirth.connect.util.HttpUtil.java

/**
 * Applies global settings to any Apache HttpComponents HttpClientBuilder.<br/>
 * <br/>//ww w. j  ava 2  s . co m
 * As of version 4.5, the default cookie specifications used by Apache HttpClient are more
 * strict in order to abide by RFC 6265. As part of this change, domain parameters in cookies
 * are checked against a public ICANN suffix matcher before they are allowed to be added to
 * outgoing requests. However this may cause clients to fail to connect if they are using custom
 * hostnames like "mycustomhost". To prevent that, we're building our own CookieSpecProvider
 * registry, and setting that on the client. Look at CookieSpecRegistries to see how the default
 * registry is built. The only difference now is that DefaultCookieSpecProvider is being
 * constructed without a PublicSuffixMatcher.
 */
public static void configureClientBuilder(HttpClientBuilder clientBuilder) {
    PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.getDefault();
    clientBuilder.setPublicSuffixMatcher(publicSuffixMatcher);
    RegistryBuilder<CookieSpecProvider> cookieSpecBuilder = RegistryBuilder.<CookieSpecProvider>create();
    CookieSpecProvider defaultProvider = new DefaultCookieSpecProvider();
    CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider(
            RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher);
    CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider(
            RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher);
    cookieSpecBuilder.register(CookieSpecs.DEFAULT, defaultProvider);
    cookieSpecBuilder.register("best-match", defaultProvider);
    cookieSpecBuilder.register("compatibility", defaultProvider);
    cookieSpecBuilder.register(CookieSpecs.STANDARD, laxStandardProvider);
    cookieSpecBuilder.register(CookieSpecs.STANDARD_STRICT, strictStandardProvider);
    cookieSpecBuilder.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider());
    cookieSpecBuilder.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider());
    clientBuilder.setDefaultCookieSpecRegistry(cookieSpecBuilder.build());
}

From source file:org.ligoj.app.http.security.DigestAuthenticationFilter.java

@Override
public Authentication attemptAuthentication(final HttpServletRequest request,
        final HttpServletResponse response) {
    final String token = request.getParameter("token");

    if (token != null) {
        // Token is the last part of URL

        // First get the cookie
        final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
        clientBuilder.setDefaultRequestConfig(
                RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build());

        // Do the POST
        try (CloseableHttpClient httpClient = clientBuilder.build()) {
            final HttpPost httpPost = new HttpPost(getSsoPostUrl());
            httpPost.setEntity(new StringEntity(token, StandardCharsets.UTF_8.name()));
            httpPost.setHeader("Content-Type", "application/json");
            final HttpResponse httpResponse = httpClient.execute(httpPost);
            if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) {
                return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(
                        EntityUtils.toString(httpResponse.getEntity()), "N/A", new ArrayList<>()));
            }/*from www . j a v a 2s  . co m*/
        } catch (final IOException e) {
            log.warn("Local SSO server is not available", e);
        }

    }
    throw new BadCredentialsException("Invalid user or password");
}

From source file:org.frontcache.agent.FrontCacheAgent.java

public FrontCacheAgent(String frontcacheURL) {
    final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(3000)
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();

    ConnectionKeepAliveStrategy keepAliveStrategy = new ConnectionKeepAliveStrategy() {
        @Override// ww  w .j a v a  2  s.  c  om
        public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
            HeaderElementIterator it = new BasicHeaderElementIterator(
                    response.headerIterator(HTTP.CONN_KEEP_ALIVE));
            while (it.hasNext()) {
                HeaderElement he = it.nextElement();
                String param = he.getName();
                String value = he.getValue();
                if (value != null && param.equalsIgnoreCase("timeout")) {
                    return Long.parseLong(value) * 1000;
                }
            }
            return 10 * 1000;
        }
    };

    client = HttpClients.custom().setDefaultRequestConfig(requestConfig)
            .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false))
            .setKeepAliveStrategy(keepAliveStrategy).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();

    this.frontCacheURL = frontcacheURL;

    if (frontcacheURL.endsWith("/"))
        this.frontCacheURI = frontcacheURL + IO_URI;
    else
        this.frontCacheURI = frontcacheURL + "/" + IO_URI;
}

From source file:com.match_tracker.twitter.TwitterSearch.java

public TwitterSearch(URL twitterSearchAuthUrl) throws MalformedURLException {
    RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
    HttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(globalConfig).build();
    Unirest.setHttpClient(httpclient);//w  w  w.ja v a2s.c  o m

    this.twitterSearchURL = new URL(twitterSearchAuthUrl, SEARCH_API);
}

From source file:com.github.yongchristophertang.engine.web.WebTemplateBuilder.java

/**
 * Set cookie policy to {@link org.apache.http.client.config.CookieSpecs#IGNORE_COOKIES}
 *//*from www .j a  v a2s .c  om*/
public WebTemplateBuilder noCookie() {
    builder.setCookieSpec(CookieSpecs.IGNORE_COOKIES);
    return this;
}

From source file:reconf.infra.http.layer.SimpleHttpClient.java

private static RequestConfig createBasicHttpParams(long timeout, TimeUnit timeUnit) {
    int timemillis = (int) TimeUnit.MILLISECONDS.convert(timeout, timeUnit);
    return RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .setStaleConnectionCheckEnabled(false).setConnectTimeout(timemillis).setSocketTimeout(timemillis)
            .setConnectionRequestTimeout(timemillis).build();
}

From source file:fredboat.util.rest.SearchUtil.java

private static AudioPlayerManager initPlayerManager() {
    DefaultAudioPlayerManager manager = new DefaultAudioPlayerManager();
    YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager();
    youtubeAudioSourceManager.configureRequests(
            config -> RequestConfig.copy(config).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build());
    manager.registerSourceManager(youtubeAudioSourceManager);
    manager.registerSourceManager(new SoundCloudAudioSourceManager());
    return manager;
}

From source file:net.sf.jasperreports.phantomjs.ProcessConnection.java

public ProcessConnection(ProcessDirector director, PhantomJSProcess process) {
    this.process = process;

    HttpClientBuilder clientBuilder = HttpClients.custom();

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

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

    this.httpClient = clientBuilder.build();
}

From source file:com.jaspersoft.studio.data.adapter.JSSBuiltinDataFileServiceFactory.java

@Override
public DataFileService createService(JasperReportsContext context, DataFile dataFile) {
    if (dataFile instanceof RepositoryDataLocation) {
        return new RepositoryDataLocationService(context, (RepositoryDataLocation) dataFile);
    }//from ww w . j  a  va 2s .c  o  m
    if (dataFile instanceof HttpDataLocation) {
        return new HttpDataService(context, (HttpDataLocation) dataFile) {
            @Override
            protected CloseableHttpClient createHttpClient(Map<String, Object> parameters) {
                HttpClientBuilder clientBuilder = HttpClients.custom();
                HttpUtils.setupProxy(clientBuilder);
                // 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);

                HttpClientContext clientContext = HttpClientContext.create();

                setAuthentication(parameters, clientContext);

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