Example usage for org.apache.http.client.protocol HttpClientContext create

List of usage examples for org.apache.http.client.protocol HttpClientContext create

Introduction

In this page you can find the example usage for org.apache.http.client.protocol HttpClientContext create.

Prototype

public static HttpClientContext create() 

Source Link

Usage

From source file:org.xwiki.contrib.repository.pypi.internal.searching.PypiPackageListIndexUpdateTask.java

public PypiPackageListIndexUpdateTask(AtomicReference<File> pypiPackageListIndexDirectory,
        PypiExtensionRepository pypiExtensionRepository, Environment environment,
        HttpClientFactory httpClientFactory, Logger logger) {
    this.pypiPackageListIndexDirectory = pypiPackageListIndexDirectory;
    this.pypiExtensionRepository = pypiExtensionRepository;
    this.environment = environment;
    this.httpClientFactory = httpClientFactory;
    this.localContext = HttpClientContext.create();
    this.logger = logger;
}

From source file:org.opensaml.security.httpclient.HttpClientSecuritySupportTest.java

@Test
public void testMarshalNullSecurityParameters() {
    HttpClientContext context = HttpClientContext.create();

    HttpClientSecuritySupport.marshalSecurityParameters(context, null, false);

    Assert.assertNull(context.getCredentialsProvider());
    Assert.assertNull(context.getAttribute(CONTEXT_KEY_TRUST_ENGINE));
    Assert.assertNull(context.getAttribute(CONTEXT_KEY_CRITERIA_SET));
    Assert.assertNull(context.getAttribute(CONTEXT_KEY_TLS_PROTOCOLS));
    Assert.assertNull(context.getAttribute(CONTEXT_KEY_TLS_CIPHER_SUITES));
    Assert.assertNull(context.getAttribute(CONTEXT_KEY_CLIENT_TLS_CREDENTIAL));
    Assert.assertNull(context.getAttribute(CONTEXT_KEY_HOSTNAME_VERIFIER));
}

From source file:org.modeshape.web.jcr.rest.AbstractRestTest.java

@Before
public void beforeEach() throws Exception {
    httpClient = HttpClientBuilder.create().build();
    httpContext = HttpClientContext.create();
}

From source file:org.apache.cloudstack.cloudian.client.CloudianClient.java

public CloudianClient(final String host, final Integer port, final String scheme, final String username,
        final String password, final boolean validateSSlCertificate, final int timeout)
        throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
    final CredentialsProvider provider = new BasicCredentialsProvider();
    provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    final HttpHost adminHost = new HttpHost(host, port, scheme);
    final AuthCache authCache = new BasicAuthCache();
    authCache.put(adminHost, new BasicScheme());

    this.adminApiUrl = adminHost.toURI();
    this.httpContext = HttpClientContext.create();
    this.httpContext.setCredentialsProvider(provider);
    this.httpContext.setAuthCache(authCache);

    final RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000)
            .setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build();

    if (!validateSSlCertificate) {
        final SSLContext sslcontext = SSLUtils.getSSLContext();
        sslcontext.init(null, new X509TrustManager[] { new TrustAllManager() }, new SecureRandom());
        final SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext,
                NoopHostnameVerifier.INSTANCE);
        this.httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider)
                .setDefaultRequestConfig(config).setSSLSocketFactory(factory).build();
    } else {/*from w w  w. j av  a  2 s .  c  o m*/
        this.httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider)
                .setDefaultRequestConfig(config).build();
    }
}

From source file:org.xwiki.contrib.repository.npm.internal.NpmExtensionRepository.java

public ExtensionRepository setUpRepository(ExtensionRepositoryDescriptor extensionRepositoryDescriptor) {
    setDescriptor(extensionRepositoryDescriptor);
    this.localContext = HttpClientContext.create();
    return this;
}

From source file:sabina.integration.TestScenario.java

TestScenario(String backend, int port, boolean secure, boolean externalFiles) {
    this.port = port;
    this.backend = backend;
    this.secure = secure;
    this.externalFiles = externalFiles;

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(getSslFactory(),
            ALLOW_ALL_HOSTNAME_VERIFIER);

    Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.INSTANCE)
            .register("https", sslConnectionSocketFactory).build();

    HttpClientConnectionManager connManager = new BasicHttpClientConnectionManager(socketFactoryRegistry,
            new ManagedHttpClientConnectionFactory());

    RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.NETSCAPE).build();
    cookieStore = new BasicCookieStore();
    HttpClientContext context = HttpClientContext.create();
    context.setCookieStore(cookieStore);

    this.httpClient = HttpClients.custom().setSchemePortResolver(h -> {
        Args.notNull(h, "HTTP host");
        final int port1 = h.getPort();
        if (port1 > 0) {
            return port1;
        }//  w  w  w. java 2  s.c o m

        final String name = h.getSchemeName();
        if (name.equalsIgnoreCase("http")) {
            return port1;
        } else if (name.equalsIgnoreCase("https")) {
            return port1;
        } else {
            throw new UnsupportedSchemeException("unsupported protocol: " + name);
        }
    }).setConnectionManager(connManager).setDefaultRequestConfig(globalConfig).build();
}

From source file:org.pentaho.di.core.util.HttpClientUtil.java

/**
 * Returns context with AuthCache or null in case of any exception was thrown.
 *
 * @param host/*from w  w  w . j  a v  a  2  s.c  o m*/
 * @param port
 * @param user
 * @param password
 * @param schema
 * @return {@link org.apache.http.client.protocol.HttpClientContext HttpClientContext}
 */
public static HttpClientContext createPreemptiveBasicAuthentication(String host, int port, String user,
        String password, String schema) {
    HttpClientContext localContext = null;
    try {
        HttpHost target = new HttpHost(host, port, schema);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(target.getHostName(), target.getPort()),
                new UsernamePasswordCredentials(user, password));

        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate BASIC scheme object and add it to the local
        // auth cache
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(target, basicAuth);

        // Add AuthCache to the execution context
        localContext = HttpClientContext.create();
        localContext.setAuthCache(authCache);
    } catch (Exception e) {
        return null;
    }
    return localContext;
}

From source file:org.datagator.api.client.backend.DataGatorService.java

public DataGatorService() {
    super();
    log.info("Initializing service without authorization");
    this.context = HttpClientContext.create();
}

From source file:com.ontotext.s4.gdbaas.createRepo.service.GdbaasClient.java

/**
 * Sets up a HTTPContext for authentication
 *//*ww  w.jav a 2s . c o  m*/
private void setupContext() {
    ctx = HttpClientContext.create();
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(keyId, password);
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, creds);
    ctx.setCredentialsProvider(credsProvider);
}