Example usage for org.apache.http.conn.ssl DefaultHostnameVerifier DefaultHostnameVerifier

List of usage examples for org.apache.http.conn.ssl DefaultHostnameVerifier DefaultHostnameVerifier

Introduction

In this page you can find the example usage for org.apache.http.conn.ssl DefaultHostnameVerifier DefaultHostnameVerifier.

Prototype

public DefaultHostnameVerifier() 

Source Link

Usage

From source file:org.apache.pulsar.client.admin.PulsarAdmin.java

public PulsarAdmin(String serviceUrl, ClientConfigurationData clientConfigData, int connectTimeout,
        TimeUnit connectTimeoutUnit, int readTimeout, TimeUnit readTimeoutUnit) throws PulsarClientException {
    this.connectTimeout = connectTimeout;
    this.connectTimeoutUnit = connectTimeoutUnit;
    this.readTimeout = readTimeout;
    this.readTimeoutUnit = readTimeoutUnit;
    this.clientConfigData = clientConfigData;
    this.auth = clientConfigData != null ? clientConfigData.getAuthentication() : new AuthenticationDisabled();
    LOG.debug("created: serviceUrl={}, authMethodName={}", serviceUrl,
            auth != null ? auth.getAuthMethodName() : null);

    if (auth != null) {
        auth.start();//w w  w  . j  av  a2  s  . c o  m
    }

    ClientConfig httpConfig = new ClientConfig();
    httpConfig.property(ClientProperties.FOLLOW_REDIRECTS, true);
    httpConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 8);
    httpConfig.register(MultiPartFeature.class);

    ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(httpConfig)
            .connectTimeout(this.connectTimeout, this.connectTimeoutUnit)
            .readTimeout(this.readTimeout, this.readTimeoutUnit).register(JacksonConfigurator.class)
            .register(JacksonFeature.class);

    boolean useTls = false;

    if (clientConfigData != null && StringUtils.isNotBlank(clientConfigData.getServiceUrl())
            && clientConfigData.getServiceUrl().startsWith("https://")) {
        useTls = true;
        try {
            SSLContext sslCtx = null;

            X509Certificate trustCertificates[] = SecurityUtility
                    .loadCertificatesFromPemFile(clientConfigData.getTlsTrustCertsFilePath());

            // Set private key and certificate if available
            AuthenticationDataProvider authData = auth.getAuthData();
            if (authData.hasDataForTls()) {
                sslCtx = SecurityUtility.createSslContext(clientConfigData.isTlsAllowInsecureConnection(),
                        trustCertificates, authData.getTlsCertificates(), authData.getTlsPrivateKey());
            } else {
                sslCtx = SecurityUtility.createSslContext(clientConfigData.isTlsAllowInsecureConnection(),
                        trustCertificates);
            }

            clientBuilder.sslContext(sslCtx);
            if (clientConfigData.isTlsHostnameVerificationEnable()) {
                clientBuilder.hostnameVerifier(new DefaultHostnameVerifier());
            } else {
                // Disable hostname verification
                clientBuilder.hostnameVerifier(NoopHostnameVerifier.INSTANCE);
            }
        } catch (Exception e) {
            try {
                if (auth != null) {
                    auth.close();
                }
            } catch (IOException ioe) {
                LOG.error("Failed to close the authentication service", ioe);
            }
            throw new PulsarClientException.InvalidConfigurationException(e.getMessage());
        }
    }

    this.client = clientBuilder.build();

    this.serviceUrl = serviceUrl;
    root = client.target(serviceUrl);

    this.clusters = new ClustersImpl(root, auth);
    this.brokers = new BrokersImpl(root, auth);
    this.brokerStats = new BrokerStatsImpl(root, auth);
    this.tenants = new TenantsImpl(root, auth);
    this.properties = new TenantsImpl(root, auth);
    ;
    this.namespaces = new NamespacesImpl(root, auth);
    this.topics = new TopicsImpl(root, auth);
    this.nonPersistentTopics = new NonPersistentTopicsImpl(root, auth);
    this.resourceQuotas = new ResourceQuotasImpl(root, auth);
    this.lookups = new LookupImpl(root, auth, useTls);
    this.functions = new FunctionsImpl(root, auth);
    this.source = new SourceImpl(root, auth);
    this.sink = new SinkImpl(root, auth);
    this.worker = new WorkerImpl(root, auth);
    this.schemas = new SchemasImpl(root, auth);
    this.bookies = new BookiesImpl(root, auth);
}

From source file:org.apache.pulsar.client.impl.ClientCnx.java

public ClientCnx(ClientConfigurationData conf, EventLoopGroup eventLoopGroup, int protocolVersion) {
    super(conf.getKeepAliveIntervalSeconds(), TimeUnit.SECONDS);
    checkArgument(conf.getMaxLookupRequest() > conf.getConcurrentLookupRequest());
    this.pendingLookupRequestSemaphore = new Semaphore(conf.getConcurrentLookupRequest(), true);
    this.waitingLookupRequests = Queues
            .newArrayBlockingQueue((conf.getMaxLookupRequest() - conf.getConcurrentLookupRequest()));
    this.authentication = conf.getAuthentication();
    this.eventLoopGroup = eventLoopGroup;
    this.maxNumberOfRejectedRequestPerConnection = conf.getMaxNumberOfRejectedRequestPerConnection();
    this.operationTimeoutMs = conf.getOperationTimeoutMs();
    this.state = State.None;
    this.isTlsHostnameVerificationEnable = conf.isTlsHostnameVerificationEnable();
    this.hostnameVerifier = new DefaultHostnameVerifier();
    this.protocolVersion = protocolVersion;
    this.timeoutTask = this.eventLoopGroup.scheduleAtFixedRate(() -> checkRequestTimeout(), operationTimeoutMs,
            operationTimeoutMs, TimeUnit.MILLISECONDS);
}