Author: jleroux
Date: Sun Apr 10 17:21:49 2016
New Revision: 1738443
URL: http://svn.apache.org/viewvc?rev=1738443&view=rev
Log:
Reverts changes in SolrUtil.java which slipped in with r1738407 for "Update the
passport component to use httpclient/core-4.4.1 instead of
commons-httpclient-3.1" - https://issues.apache.org/jira/browse/OFBIZ-6755
This was unrelated with the passport fix and should not have been committed
with it and then backported
Modified:
ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java
Modified:
ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java?rev=1738443&r1=1738442&r2=1738443&view=diff
==============================================================================
---
ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java
(original)
+++
ofbiz/branches/release15.12/specialpurpose/solr/src/org/ofbiz/solr/SolrUtil.java
Sun Apr 10 17:21:49 2016
@@ -18,20 +18,12 @@
*******************************************************************************/
package org.ofbiz.solr;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
@@ -42,7 +34,6 @@ import org.ofbiz.base.component.Componen
import org.ofbiz.base.component.ComponentException;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilGenerics;
-import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericEntityException;
@@ -50,7 +41,7 @@ import org.ofbiz.entity.GenericEntityExc
/**
* Solr utility class.
*/
-public final class SolrUtil {
+public abstract class SolrUtil {
public static final String module = SolrUtil.class.getName();
private static String[] solrProdAttribute = { "productId", "internalName",
"manu", "size", "smallImage", "mediumImage", "largeImage", "listPrice",
"defaultPrice", "inStock", "isVirtual" };
@@ -58,22 +49,6 @@ public final class SolrUtil {
public static final String solrConfigName = "solrconfig.properties";
public static final String solrUrl = makeSolrWebappUrl();
- protected static final String socketTimeoutString =
UtilProperties.getPropertyValue(solrConfigName, "solr.client.socket.timeout");
-
- protected static final String connectionTimeoutString =
UtilProperties.getPropertyValue(solrConfigName,
"solr.client.connection.timeout");
-
- protected static final String clientUsername =
UtilProperties.getPropertyValue(solrConfigName, "solr.client.username");
-
- protected static final String clientPassword =
UtilProperties.getPropertyValue(solrConfigName, "solr.client.password");
-
- protected static final Integer socketTimeout = getSocketTimeout();
-
- protected static final Integer connectionTimeout = getConnectionTimeout();
-
- protected static final String trustSelfSignedCertString =
UtilProperties.getPropertyValue(solrConfigName,
"solr.client.trust.selfsigned.cert", "false");
-
- protected static final boolean trustSelfSignedCert =
getTrustSelfSignedCert();
-
public static String makeSolrWebappUrl() {
final String solrWebappProtocol =
UtilProperties.getPropertyValue(solrConfigName, "solr.webapp.protocol");
final String solrWebappDomainName =
UtilProperties.getPropertyValue(solrConfigName, "solr.webapp.domainName");
@@ -83,42 +58,14 @@ public final class SolrUtil {
String solrPort;
if (UtilValidate.isNotEmpty(solrWebappPortOverride)) {
solrPort = solrWebappPortOverride;
- } else {
+ }
+ else {
solrPort = UtilProperties.getPropertyValue("url",
("https".equals(solrWebappProtocol) ? "port.https" : "port.http"));
}
return solrWebappProtocol + "://" + solrWebappDomainName + ":" +
solrPort + solrWebappPath;
}
- private static Integer getSocketTimeout() {
- if (UtilValidate.isNotEmpty(socketTimeoutString)) {
- try {
- return Integer.parseInt(socketTimeoutString);
- } catch (Exception e) {
- return null;
- }
- }
- return null;
- }
-
- private static Integer getConnectionTimeout() {
- if (UtilValidate.isNotEmpty(connectionTimeoutString)) {
- try {
- return Integer.parseInt(connectionTimeoutString);
- } catch (Exception e) {
- return null;
- }
- }
- return null;
- }
-
- private static boolean getTrustSelfSignedCert() {
- if ("true".equals(trustSelfSignedCertString)) {
- return true;
- }
- return false;
- }
-
public static boolean isSolrEcaEnabled() {
Boolean ecaEnabled = null;
String sysProp = System.getProperty("ofbiz.solr.eca.enabled");
@@ -234,18 +181,18 @@ public final class SolrUtil {
return doc1;
}
- public static Map<String, Object> categoriesAvailable(String catalogId,
String categoryId, String productId, boolean displayproducts, int viewIndex,
int viewSize, String solrIndexName) {
- return categoriesAvailable(catalogId, categoryId, productId, null,
displayproducts, viewIndex, viewSize, solrIndexName);
+ public static Map<String, Object> categoriesAvailable(String catalogId,
String categoryId, String productId, boolean displayproducts, int viewIndex,
int viewSize) {
+ return
categoriesAvailable(catalogId,categoryId,productId,null,displayproducts,viewIndex,viewSize);
}
- public static Map<String, Object> categoriesAvailable(String catalogId,
String categoryId, String productId, String facetPrefix, boolean
displayproducts, int viewIndex, int viewSize, String solrIndexName) {
+ public static Map<String, Object> categoriesAvailable(String catalogId,
String categoryId, String productId, String facetPrefix, boolean
displayproducts, int viewIndex, int viewSize) {
// create the data model
Map<String, Object> result = new HashMap<String, Object>();
HttpSolrClient client = null;
QueryResponse returnMap = new QueryResponse();
try {
// do the basic query
- client = getHttpSolrClient(solrIndexName);
+ client = new HttpSolrClient(solrUrl);
// create Query Object
String query = "inStock[1 TO *]";
if (categoryId != null)
@@ -288,48 +235,4 @@ public final class SolrUtil {
return result;
}
- public static SolrUtil getInstance() {
- return new SolrUtil();
- }
-
- public static HttpSolrClient getHttpSolrClient(String solrIndexName)
throws ClientProtocolException, IOException {
- HttpClientContext httpContext = HttpClientContext.create();
-
- CloseableHttpClient httpClient = null;
- if (trustSelfSignedCert) {
- httpClient = UtilHttp.getAllowAllHttpClient();
- } else {
- httpClient = HttpClients.createDefault();
- }
-
- RequestConfig requestConfig = null;
- if (UtilValidate.isNotEmpty(socketTimeout) &&
UtilValidate.isNotEmpty(connectionTimeout)) {
- requestConfig = RequestConfig.custom()
- .setSocketTimeout(socketTimeout)
- .setConnectTimeout(connectionTimeout)
- .setRedirectsEnabled(true)
- .build();
- } else if (UtilValidate.isNotEmpty(socketTimeout)) {
- requestConfig = RequestConfig.custom()
- .setSocketTimeout(socketTimeout)
- .setRedirectsEnabled(true)
- .build();
- } else if (UtilValidate.isNotEmpty(connectionTimeout)) {
- requestConfig = RequestConfig.custom()
- .setConnectTimeout(connectionTimeout)
- .setRedirectsEnabled(true)
- .build();
- } else {
- requestConfig = RequestConfig.custom()
- .setRedirectsEnabled(true)
- .build();
- }
-
- HttpGet httpLogin = new HttpGet(solrUrl + "/control/login?USERNAME=" +
clientUsername + "&PASSWORD=" + clientPassword);
- httpLogin.setConfig(requestConfig);
- CloseableHttpResponse loginResponse = httpClient.execute(httpLogin,
httpContext);
- loginResponse.close();
- return new HttpSolrClient(solrUrl + "/" + solrIndexName, httpClient);
- }
-
}