All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.search.elasticsearch.client.impl.ServerUris Maven / Gradle / Ivy

There is a newer version: 5.11.12.Final
Show newest version
/*
 * Hibernate Search, full-text search for your domain model
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.search.elasticsearch.client.impl;

import org.apache.http.HttpHost;
import org.hibernate.search.elasticsearch.logging.impl.Log;
import org.hibernate.search.util.logging.impl.LoggerFactory;
import java.lang.invoke.MethodHandles;

final class ServerUris {

	private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() );

	private final HttpHost[] hosts;
	private final boolean anyHostRequiresSSL;

	private ServerUris(HttpHost[] hosts, boolean anyHostRequiresSSL) {
		this.hosts = hosts;
		this.anyHostRequiresSSL = anyHostRequiresSSL;
	}

	static ServerUris fromString(String serverUrisString) {
		String[] serverUris = serverUrisString.trim().split( "\\s" );
		HttpHost[] hosts = new HttpHost[serverUris.length];
		boolean anyHostRequiresSSL = false;
		for ( int i = 0 ; i < serverUris.length ; ++i ) {
			HttpHost host = HttpHost.create( serverUris[i] );
			hosts[i] = host;
			String scheme = host.getSchemeName();
			if ( "https".equals( scheme ) ) {
				anyHostRequiresSSL = true;
			}
		}
		return new ServerUris( hosts, anyHostRequiresSSL );
	}

	HttpHost[] asHostsArray() {
		return hosts;
	}

	boolean isAnyRequiringSSL() {
		return anyHostRequiresSSL;
	}

	void warnPasswordsOverHttp() {
		for ( HttpHost host : hosts ) {
			if ( "http".equals( host.getSchemeName() ) ) {
				log.usingPasswordOverHttp( host.toURI() );
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy