org.hibernate.search.elasticsearch.client.impl.ServerUris Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-elasticsearch Show documentation
Show all versions of hibernate-search-elasticsearch Show documentation
Hibernate Search backend which has indexing operations forwarded to Elasticsearch
The 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() );
}
}
}
}