List of usage examples for org.apache.solr.client.solrj.impl HttpClientUtil createClient
public static CloseableHttpClient createClient(SolrParams params)
From source file:com.comm.sr.common.solr.SolrQueryService.java
public SolrQueryService(CacheService<String, String> cacheService, Properties settings) { super(cacheService, settings); try {//from ww w .jav a2 s. c o m String zkHost = settings.getProperty("solrcloud.zkHost"); int max_connections = Integer.parseInt(settings.getProperty("solrcloud.max_connections")); int max_connections_per_host = Integer .parseInt(settings.getProperty("solrcloud.max_connections_per_host")); int zkConnectTimeout = Integer.parseInt(settings.getProperty("solrcloud.zkConnectTimeout")); int zkClientTimeout = Integer.parseInt(settings.getProperty("solrcloud.zkClientTimeout")); ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, max_connections); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, max_connections_per_host); HttpClient client = HttpClientUtil.createClient(params); LBHttpSolrServer lbServer = new LBHttpSolrServer(client); cloudSolrServer = new CloudSolrServer(zkHost, lbServer); cloudSolrServer.setZkConnectTimeout(zkConnectTimeout); cloudSolrServer.setZkClientTimeout(zkClientTimeout); } catch (Exception e) { } }
From source file:com.comm.sr.service.solr.SolrUpdateService.java
private void populateCloudServers() throws MalformedURLException { String collectNames = solrProperties.getString("solrcloud.collectionNames"); String[] collectionNames_ = collectNames.split(","); for (String collectionNames_1 : collectionNames_) { CloudSolrServer cloudSolrServer = null; String zkHost = solrProperties.getString("solrcloud.zkHost"); int max_connections = Integer.parseInt(solrProperties.getString("solrcloud.max_connections")); int max_connections_per_host = Integer .parseInt(solrProperties.getString("solrcloud.max_connections_per_host")); int zkConnectTimeout = Integer.parseInt(solrProperties.getString("solrcloud.zkConnectTimeout")); int zkClientTimeout = Integer.parseInt(solrProperties.getString("solrcloud.zkClientTimeout")); ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, max_connections); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, max_connections_per_host); HttpClient client = HttpClientUtil.createClient(params); LBHttpSolrServer lbServer = new LBHttpSolrServer(client); cloudSolrServer = new CloudSolrServer(zkHost, lbServer); cloudSolrServer.setZkConnectTimeout(zkConnectTimeout); cloudSolrServer.setZkClientTimeout(zkClientTimeout); cloudSolrServer.setDefaultCollection(collectionNames_1); serverMap.put(collectionNames_1, cloudSolrServer); }//from w ww . j a v a 2 s .co m }
From source file:com.frank.search.solr.server.support.HttpSolrClientFactoryBean.java
License:Apache License
private void createCloudClient() { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections);// 1000 params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);// 5000 params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, timeout); params.set(HttpClientUtil.PROP_SO_TIMEOUT, timeout); HttpClient client = HttpClientUtil.createClient(params); LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient(client); CloudSolrClient cloudSolrClient = new CloudSolrClient(url, lbHttpSolrClient); if (zkClientTimeout != null) { cloudSolrClient.setZkClientTimeout(zkClientTimeout.intValue()); }// w ww . ja va2 s . co m if (zkConnectTimeout != null) { cloudSolrClient.setZkConnectTimeout(zkConnectTimeout.intValue()); } if (StringUtils.isNoneBlank(collection)) { cloudSolrClient.setDefaultCollection(collection); } cloudSolrClient.connect(); this.setSolrClient(cloudSolrClient); }
From source file:com.ilscipio.scipio.solr.util.ScipioHttpSolrClient.java
License:Apache License
/** * Creates a new client from URL and username/password, where all operations will use * the given auth.//from w w w . j a v a 2 s .c o m * <p> * DEV NOTE: Implementation must be maintained with the superclass; the default values * are taken from {@link HttpSolrClient.Builder} and are subject to change at solrj updates. */ public static HttpSolrClient create(String baseURL, HttpClient httpClient, String solrUsername, String solrPassword, Integer maxConnections, Integer maxConnectionsPerHost, Integer connectTimeout, Integer socketTimeout) { if (httpClient == null) { ModifiableSolrParams params = new ModifiableSolrParams(); if (maxConnections != null) { params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); } if (maxConnectionsPerHost != null) { params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); } params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, true); httpClient = HttpClientUtil.createClient(params); } // DEV NOTE: the defaults must match what HttpSolrClient.Builder does! Must keep up to date! HttpSolrClient client = new ScipioHttpSolrClient(baseURL, httpClient, new BinaryResponseParser(), false, new ModifiableSolrParams(), solrUsername, solrPassword); // TODO: In Solr 7, these are deprecated and moved to Builder/constructor if (connectTimeout != null) { client.setConnectionTimeout(connectTimeout); } if (socketTimeout != null) { client.setSoTimeout(socketTimeout); } return client; }
From source file:com.mustardgrain.solr.SolrClient.java
License:Apache License
/** The provided httpClient should use a multi-threaded connection manager */ public SolrClient(HttpClient httpClient, ResponseParser parser, String... solrServerUrl) throws MalformedURLException { clientIsInternal = (httpClient == null); this.parser = parser; if (httpClient == null) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_USE_RETRY, false); this.httpClient = HttpClientUtil.createClient(params); } else {//from w w w .jav a 2s. c om this.httpClient = httpClient; } for (String s : solrServerUrl) { ServerWrapper wrapper = new ServerWrapper(makeServer(s)); aliveServers.put(wrapper.getKey(), wrapper); serverStats.put(wrapper.getKey(), new SolrStats()); } updateAliveList(); startStatsExecutor(); registerMBean(); }
From source file:com.nkang.kxmoment.util.SolrUtils.HttpSolrServer.java
License:Apache License
public HttpSolrServer(String baseURL, HttpClient client, ResponseParser parser) { this.baseUrl = baseURL; if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); }//from www . j a v a2 s.co m if (baseUrl.indexOf('?') >= 0) { throw new RuntimeException( "Invalid base url for solrj. The base URL must not contain parameters: " + baseUrl); } if (client != null) { httpClient = client; internalClient = false; } else { internalClient = true; ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 128); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 32); params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, followRedirects); httpClient = HttpClientUtil.createClient(params); } this.parser = parser; }
From source file:com.thinkaurelius.titan.diskstorage.solr.Solr5Index.java
License:Apache License
public Solr5Index(final Configuration config) throws BackendException { Preconditions.checkArgument(config != null); configuration = config;/*from w ww . j a va 2s. c om*/ mode = Mode.parse(config.get(SOLR_MODE)); dynFields = config.get(DYNAMIC_FIELDS); keyFieldIds = parseKeyFieldsForCollections(config); maxResults = config.get(GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE); ttlField = config.get(TTL_FIELD); waitSearcher = config.get(WAIT_SEARCHER); if (mode == Mode.CLOUD) { String zookeeperUrl = config.get(Solr5Index.ZOOKEEPER_URL); CloudSolrClient cloudServer = new CloudSolrClient(zookeeperUrl, true); cloudServer.connect(); solrClient = cloudServer; } else if (mode == Mode.HTTP) { HttpClient clientParams = HttpClientUtil.createClient(new ModifiableSolrParams() { { add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, config.get(HTTP_MAX_CONNECTIONS_PER_HOST).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS, config.get(HTTP_GLOBAL_MAX_CONNECTIONS).toString()); } }); solrClient = new LBHttpSolrClient(clientParams, config.get(HTTP_URLS)); } else { throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode); } }
From source file:org.apache.manifoldcf.agents.output.solr.HttpPoster.java
License:Apache License
/** Initialize the SolrCloud http poster. *//* w ww. j av a 2s . c om*/ public HttpPoster(String zookeeperHosts, String collection, int zkClientTimeout, int zkConnectTimeout, String updatePath, String removePath, String statusPath, String allowAttributeName, String denyAttributeName, String idAttributeName, String modifiedDateAttributeName, String createdDateAttributeName, String indexedDateAttributeName, String fileNameAttributeName, String mimeTypeAttributeName, String contentAttributeName, Long maxDocumentLength, String commitWithin, boolean useExtractUpdateHandler) throws ManifoldCFException { // These are the paths to the handlers in Solr that deal with the actions we need to do this.postUpdateAction = updatePath; this.postRemoveAction = removePath; this.postStatusAction = statusPath; this.commitWithin = commitWithin; this.allowAttributeName = allowAttributeName; this.denyAttributeName = denyAttributeName; this.idAttributeName = idAttributeName; this.modifiedDateAttributeName = modifiedDateAttributeName; this.createdDateAttributeName = createdDateAttributeName; this.indexedDateAttributeName = indexedDateAttributeName; this.fileNameAttributeName = fileNameAttributeName; this.mimeTypeAttributeName = mimeTypeAttributeName; this.contentAttributeName = contentAttributeName; this.useExtractUpdateHandler = useExtractUpdateHandler; this.maxDocumentLength = maxDocumentLength; try { CloudSolrServer cloudSolrServer = new CloudSolrServer(zookeeperHosts, new ModifiedLBHttpSolrServer(HttpClientUtil.createClient(null))); cloudSolrServer.setZkClientTimeout(zkClientTimeout); cloudSolrServer.setZkConnectTimeout(zkConnectTimeout); cloudSolrServer.setDefaultCollection(collection); // Set the solrj instance we want to use solrServer = cloudSolrServer; } catch (MalformedURLException e) { throw new ManifoldCFException(e.getMessage(), e); } }
From source file:org.apache.nifi.processors.solr.SolrUtils.java
License:Apache License
public static SolrClient createSolrClient(final PropertyContext context, final String solrLocation) { final Integer socketTimeout = context.getProperty(SOLR_SOCKET_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS) .intValue();/*ww w . j a va 2 s .co m*/ final Integer connectionTimeout = context.getProperty(SOLR_CONNECTION_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); final Integer maxConnections = context.getProperty(SOLR_MAX_CONNECTIONS).asInteger(); final Integer maxConnectionsPerHost = context.getProperty(SOLR_MAX_CONNECTIONS_PER_HOST).asInteger(); final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE) .asControllerService(SSLContextService.class); final String jaasClientAppName = context.getProperty(JAAS_CLIENT_APP_NAME).getValue(); final ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_SO_TIMEOUT, socketTimeout); params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections); params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost); // has to happen before the client is created below so that correct configurer would be set if neeeded if (!StringUtils.isEmpty(jaasClientAppName)) { System.setProperty("solr.kerberos.jaas.appname", jaasClientAppName); HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } final HttpClient httpClient = HttpClientUtil.createClient(params); if (sslContextService != null) { final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED); final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext); final Scheme httpsScheme = new Scheme("https", 443, sslSocketFactory); httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme); } if (SOLR_TYPE_STANDARD.equals(context.getProperty(SOLR_TYPE).getValue())) { return new HttpSolrClient(solrLocation, httpClient); } else { final String collection = context.getProperty(COLLECTION).evaluateAttributeExpressions().getValue(); final Integer zkClientTimeout = context.getProperty(ZK_CLIENT_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); final Integer zkConnectionTimeout = context.getProperty(ZK_CONNECTION_TIMEOUT) .asTimePeriod(TimeUnit.MILLISECONDS).intValue(); CloudSolrClient cloudSolrClient = new CloudSolrClient(solrLocation, httpClient); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(zkClientTimeout); cloudSolrClient.setZkConnectTimeout(zkConnectionTimeout); return cloudSolrClient; } }
From source file:org.janusgraph.diskstorage.solr.SolrIndex.java
License:Apache License
public SolrIndex(final Configuration config) throws BackendException { Preconditions.checkArgument(config != null); configuration = config;// w w w. j a v a 2s. c o m mode = Mode.parse(config.get(SOLR_MODE)); kerberosEnabled = config.get(KERBEROS_ENABLED); dynFields = config.get(DYNAMIC_FIELDS); keyFieldIds = parseKeyFieldsForCollections(config); batchSize = config.get(INDEX_MAX_RESULT_SET_SIZE); ttlField = config.get(TTL_FIELD); waitSearcher = config.get(WAIT_SEARCHER); if (kerberosEnabled) { logger.debug("Kerberos is enabled. Configuring SOLR for Kerberos."); configureSolrClientsForKerberos(); } else { logger.debug("Kerberos is NOT enabled."); logger.debug("KERBEROS_ENABLED name is " + KERBEROS_ENABLED.getName() + " and it is" + (KERBEROS_ENABLED.isOption() ? " " : " not") + " an option."); logger.debug("KERBEROS_ENABLED type is " + KERBEROS_ENABLED.getType().name()); } final ModifiableSolrParams clientParams = new ModifiableSolrParams(); switch (mode) { case CLOUD: final String[] zookeeperUrl = config.get(SolrIndex.ZOOKEEPER_URL); // Process possible zookeeper chroot. e.g. localhost:2181/solr // chroot has to be the same assuming one Zookeeper ensemble. // Parse from the last string. If found, take it as the chroot. String chroot = null; for (int i = zookeeperUrl.length - 1; i >= 0; i--) { int chrootIndex = zookeeperUrl[i].indexOf("/"); if (chrootIndex != -1) { String hostAndPort = zookeeperUrl[i].substring(0, chrootIndex); if (chroot == null) { chroot = zookeeperUrl[i].substring(chrootIndex); } zookeeperUrl[i] = hostAndPort; } } final CloudSolrClient.Builder builder = new CloudSolrClient.Builder() .withLBHttpSolrClientBuilder(new LBHttpSolrClient.Builder() .withHttpSolrClientBuilder( new HttpSolrClient.Builder().withInvariantParams(clientParams)) .withBaseSolrUrls(config.get(HTTP_URLS))) .withZkHost(Arrays.asList(zookeeperUrl)).sendUpdatesOnlyToShardLeaders(); if (chroot != null) { builder.withZkChroot(chroot); } final CloudSolrClient cloudServer = builder.build(); cloudServer.connect(); solrClient = cloudServer; break; case HTTP: clientParams.add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); clientParams.add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString()); clientParams.add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, config.get(HTTP_MAX_CONNECTIONS_PER_HOST).toString()); clientParams.add(HttpClientUtil.PROP_MAX_CONNECTIONS, config.get(HTTP_GLOBAL_MAX_CONNECTIONS).toString()); final HttpClient client = HttpClientUtil.createClient(clientParams); solrClient = new LBHttpSolrClient.Builder().withHttpClient(client) .withBaseSolrUrls(config.get(HTTP_URLS)).build(); break; default: throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode); } }