Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-3854: SSL support for SolrCloud

Mark Robert Millerde6514e21445
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 0b59a79c259..bff4c3187a5 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -182,6 +182,9 @@ New Features
* SOLR-5672: Add logParamsList parameter to support reduced logging.
(Christine Poerschke via Mark Miller)
+* SOLR-3854: SSL support for SolrCloud. (Sami Siren, hossman, Steve Davids,
+ Alexey Serba, Mark Miller)
+
Bug Fixes
----------------------
diff --git a/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml b/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml
index 6a6cdda13e6..98a31e6d668 100644
--- a/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml
+++ b/solr/contrib/clustering/src/test-files/clustering/solr/solr.xml
@@ -25,5 +25,9 @@
host="${host:}" hostPort="${hostPort:}" hostContext="${hostContext:}"
zkClientTimeout="${zkClientTimeout:15000}">
<core name="collection1" shard="${shard:}" collection="${collection:collection1}" instanceDir="collection1"/>
+
+ <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
+ </shardHandlerFactory>
</cores>
</solr>
diff --git a/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xml b/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xml
index ee072013336..4088f521d08 100644
--- a/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xml
+++ b/solr/contrib/dataimporthandler/src/test-files/dih/solr/solr.xml
@@ -25,5 +25,8 @@
host="${host:}" hostPort="${hostPort:}" hostContext="${hostContext:}"
zkClientTimeout="${zkClientTimeout:15000}">
<core name="collection1" shard="${shard:}" collection="${collection:collection1}" instanceDir="collection1"/>
+ <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
+ </shardHandlerFactory>
</cores>
</solr>
\ No newline at end of file
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java
index 8092bde4516..cd101fb926e 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestContentStreamDataSource.java
@@ -69,7 +69,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
params.set("command", "full-import");
params.set("clean", "false");
req.setParams(params);
- String url = "http://127.0.0.1:" + jetty.getLocalPort() + "/solr";
+ String url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + jetty.getLocalPort() + "/solr";
HttpSolrServer solrServer = new HttpSolrServer(url);
solrServer.request(req);
ModifiableSolrParams qparams = new ModifiableSolrParams();
@@ -89,7 +89,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
"clean", "false", UpdateParams.COMMIT, "false",
UpdateParams.COMMIT_WITHIN, "1000");
req.setParams(params);
- String url = "http://127.0.0.1:" + jetty.getLocalPort() + "/solr";
+ String url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + jetty.getLocalPort() + "/solr";
HttpSolrServer solrServer = new HttpSolrServer(url);
solrServer.request(req);
Thread.sleep(100);
@@ -181,7 +181,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
private JettySolrRunner createJetty(SolrInstance instance) throws Exception {
System.setProperty("solr.data.dir", instance.getDataDir());
- JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), "/solr", 0);
+ JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), "/solr", 0, null, null, true, null, sslConfig);
jetty.start();
return jetty;
}
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
index 431f8188690..dac92cfcab0 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
@@ -95,7 +95,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
}
private String getSourceUrl() {
- return "http://127.0.0.1:" + jetty.getLocalPort() + "/solr";
+ return "http" + (isSSLMode() ? "s" : "") +"://127.0.0.1:" + jetty.getLocalPort() + "/solr";
}
//TODO: fix this test to close its directories
@@ -348,7 +348,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
private JettySolrRunner createJetty(SolrInstance instance) throws Exception {
System.setProperty("solr.data.dir", instance.getDataDir());
- JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), "/solr", 0);
+ JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), "/solr", 0, null, null, true, null, sslConfig);
jetty.start();
return jetty;
}
diff --git a/solr/contrib/map-reduce/src/test-files/solr/minimr/solr.xml b/solr/contrib/map-reduce/src/test-files/solr/minimr/solr.xml
index 6c8b43f75ed..56f7ce78a39 100644
--- a/solr/contrib/map-reduce/src/test-files/solr/minimr/solr.xml
+++ b/solr/contrib/map-reduce/src/test-files/solr/minimr/solr.xml
@@ -35,6 +35,7 @@
<core name="collection1" instanceDir="." shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"
coreNodeName="${coreNodeName:}"/>
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:120000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/contrib/map-reduce/src/test-files/solr/mrunit/solr.xml b/solr/contrib/map-reduce/src/test-files/solr/mrunit/solr.xml
index 6c8b43f75ed..56f7ce78a39 100644
--- a/solr/contrib/map-reduce/src/test-files/solr/mrunit/solr.xml
+++ b/solr/contrib/map-reduce/src/test-files/solr/mrunit/solr.xml
@@ -35,6 +35,7 @@
<core name="collection1" instanceDir="." shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"
coreNodeName="${coreNodeName:}"/>
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:120000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/contrib/map-reduce/src/test-files/solr/solr.xml b/solr/contrib/map-reduce/src/test-files/solr/solr.xml
index 4604f60476f..3c6317e2caf 100644
--- a/solr/contrib/map-reduce/src/test-files/solr/solr.xml
+++ b/solr/contrib/map-reduce/src/test-files/solr/solr.xml
@@ -35,6 +35,7 @@
<core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"
coreNodeName="${coreNodeName:}"/>
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:120000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/contrib/morphlines-core/src/test-files/solr/solr-no-core.xml b/solr/contrib/morphlines-core/src/test-files/solr/solr-no-core.xml
index 476b5bc7a10..e1d217bc7e9 100644
--- a/solr/contrib/morphlines-core/src/test-files/solr/solr-no-core.xml
+++ b/solr/contrib/morphlines-core/src/test-files/solr/solr-no-core.xml
@@ -32,6 +32,7 @@
<shardHandlerFactory name="shardHandlerFactory"
class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:120000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/contrib/morphlines-core/src/test-files/solr/solr-stress-new.xml b/solr/contrib/morphlines-core/src/test-files/solr/solr-stress-new.xml
index 3f8b213eab5..f750b30dc21 100644
--- a/solr/contrib/morphlines-core/src/test-files/solr/solr-stress-new.xml
+++ b/solr/contrib/morphlines-core/src/test-files/solr/solr-stress-new.xml
@@ -28,6 +28,7 @@
</solrcloud>
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:120000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/contrib/morphlines-core/src/test-files/solr/solr-stress-old.xml b/solr/contrib/morphlines-core/src/test-files/solr/solr-stress-old.xml
index 6bc1c35e888..a18f1f27cf0 100644
--- a/solr/contrib/morphlines-core/src/test-files/solr/solr-stress-old.xml
+++ b/solr/contrib/morphlines-core/src/test-files/solr/solr-stress-old.xml
@@ -51,6 +51,7 @@
<core name="00018_core" instanceDir="00018_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
<core name="00019_core" instanceDir="00019_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:120000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/contrib/morphlines-core/src/test-files/solr/solr.xml b/solr/contrib/morphlines-core/src/test-files/solr/solr.xml
index 4604f60476f..3c6317e2caf 100644
--- a/solr/contrib/morphlines-core/src/test-files/solr/solr.xml
+++ b/solr/contrib/morphlines-core/src/test-files/solr/solr.xml
@@ -35,6 +35,7 @@
<core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"
coreNodeName="${coreNodeName:}"/>
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:120000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java
index d83e890ea83..b97a1783261 100644
--- a/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java
+++ b/solr/contrib/morphlines-core/src/test/org/apache/solr/morphlines/solr/AbstractSolrMorphlineZkTestBase.java
@@ -155,7 +155,7 @@ public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistri
throws Exception {
JettySolrRunner jetty = new JettySolrRunner(solrHome.getAbsolutePath(),
- context, 0, solrConfigOverride, schemaOverride);
+ context, 0, solrConfigOverride, schemaOverride, true, null, sslConfig);
jetty.setShards(shardList);
diff --git a/solr/core/ivy.xml b/solr/core/ivy.xml
index 06806ff40a6..015a515d111 100644
--- a/solr/core/ivy.xml
+++ b/solr/core/ivy.xml
@@ -48,6 +48,7 @@
<dependency org="org.easymock" name="easymock" rev="${/org.easymock/easymock}" conf="test->*"/>
<dependency org="cglib" name="cglib-nodep" rev="${/cglib/cglib-nodep}" conf="test->*"/>
<dependency org="org.objenesis" name="objenesis" rev="${/org.objenesis/objenesis}" conf="test->*"/>
+ <dependency org="org.apache.httpcomponents" name="httpclient" rev="${/org.apache.httpcomponents/httpclient}" conf="test->*"/>
<dependency org="org.apache.hadoop" name="hadoop-common" rev="${/org.apache.hadoop/hadoop-common}" conf="compile.hadoop->*"/>
<!--
diff --git a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
index 7dc0e0e4c88..7df53a8beec 100644
--- a/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
+++ b/solr/core/src/java/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
@@ -193,10 +193,11 @@ public class JettySolrRunner {
this.extraRequestFilters = new TreeMap<Class,String>(extraRequestFilters.comparator());
this.extraRequestFilters.putAll(extraRequestFilters);
}
- this.init(solrHome, context, port, stopAtShutdown);
this.solrConfigFilename = solrConfigFilename;
this.schemaFilename = schemaFileName;
this.sslConfig = sslConfig;
+
+ this.init(solrHome, context, port, stopAtShutdown);
}
public static class SSLConfig {
@@ -359,19 +360,18 @@ public class JettySolrRunner {
sslcontext.setKeyStorePath(sslConfig.keyStore);
}
if (null != sslConfig.keyStorePassword) {
- sslcontext.setKeyStorePassword(System
- .getProperty("solr.javax.net.ssl.keyStorePassword"));
+ sslcontext.setKeyStorePassword(sslConfig.keyStorePassword);
}
if (null != sslConfig.trustStore) {
sslcontext.setTrustStore(System
- .getProperty("solr.javax.net.ssl.trustStore"));
+ .getProperty(sslConfig.trustStore));
}
if (null != sslConfig.trustStorePassword) {
sslcontext.setTrustStorePassword(sslConfig.trustStorePassword);
}
sslcontext.setNeedClientAuth(sslConfig.clientAuth);
} else {
- boolean jettySsl = Boolean.getBoolean("tests.jettySsl");
+ boolean jettySsl = Boolean.getBoolean(System.getProperty("tests.jettySsl"));
if (jettySsl) {
if (null != System.getProperty("javax.net.ssl.keyStore")) {
diff --git a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
index c8fc0dec16e..b52a1eeb758 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
@@ -141,7 +141,7 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
zkController.getZkStateReader());
this.zkController = zkController;
this.cc = cc;
- syncStrategy = new SyncStrategy(cc.getUpdateShardHandler());
+ syncStrategy = new SyncStrategy(cc);
}
@Override
diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
index f1abce6837f..7cc349ebe0b 100644
--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
@@ -511,7 +511,6 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
ShardRequest sreq = new ShardRequest();
sreq.purpose = 1;
- if (baseUrl.startsWith("http://")) baseUrl = baseUrl.substring(7);
sreq.shards = new String[] {baseUrl};
sreq.actualShards = sreq.shards;
sreq.params = new ModifiableSolrParams(new MapSolrParams(m));
@@ -765,9 +764,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
ShardRequest sreq = new ShardRequest();
params.set("qt", adminPath);
sreq.purpose = 1;
- String replica = zkStateReader.getZkClient()
- .getBaseUrlForNodeName(nodeName);
- if (replica.startsWith("http://")) replica = replica.substring(7);
+ String replica = zkStateReader.getBaseUrlForNodeName(nodeName);
sreq.shards = new String[]{replica};
sreq.actualShards = sreq.shards;
sreq.params = params;
@@ -971,7 +968,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
for (String subShardName : subShardNames) {
// wait for parent leader to acknowledge the sub-shard core
log.info("Asking parent leader to wait for: " + subShardName + " to be alive on: " + nodeName);
- String coreNodeName = waitForCoreNodeName(collection, zkStateReader.getZkClient().getBaseUrlForNodeName(nodeName), subShardName);
+ String coreNodeName = waitForCoreNodeName(collection, zkStateReader.getBaseUrlForNodeName(nodeName), subShardName);
CoreAdminRequest.WaitForState cmd = new CoreAdminRequest.WaitForState();
cmd.setCoreName(subShardName);
cmd.setNodeName(nodeName);
@@ -1080,7 +1077,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
sendShardRequest(subShardNodeName, params);
- String coreNodeName = waitForCoreNodeName(collection, zkStateReader.getZkClient().getBaseUrlForNodeName(subShardNodeName), shardName);
+ String coreNodeName = waitForCoreNodeName(collection, zkStateReader.getBaseUrlForNodeName(subShardNodeName), shardName);
// wait for the replicas to be seen as active on sub shard leader
log.info("Asking sub shard leader to wait for: " + shardName + " to be alive on: " + subShardNodeName);
CoreAdminRequest.WaitForState cmd = new CoreAdminRequest.WaitForState();
@@ -1417,7 +1414,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
String tempCollectionReplica1 = tempSourceCollectionName + "_" + tempSourceSlice.getName() + "_replica1";
String coreNodeName = waitForCoreNodeName(clusterState.getCollection(tempSourceCollectionName),
- zkStateReader.getZkClient().getBaseUrlForNodeName(sourceLeader.getNodeName()), tempCollectionReplica1);
+ zkStateReader.getBaseUrlForNodeName(sourceLeader.getNodeName()), tempCollectionReplica1);
// wait for the replicas to be seen as active on temp source leader
log.info("Asking source leader to wait for: " + tempCollectionReplica1 + " to be alive on: " + sourceLeader.getNodeName());
CoreAdminRequest.WaitForState cmd = new CoreAdminRequest.WaitForState();
@@ -1454,7 +1451,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
sendShardRequest(targetLeader.getNodeName(), params);
coreNodeName = waitForCoreNodeName(clusterState.getCollection(tempSourceCollectionName),
- zkStateReader.getZkClient().getBaseUrlForNodeName(targetLeader.getNodeName()), tempCollectionReplica2);
+ zkStateReader.getBaseUrlForNodeName(targetLeader.getNodeName()), tempCollectionReplica2);
// wait for the replicas to be seen as active on temp source leader
log.info("Asking temp source leader to wait for: " + tempCollectionReplica2 + " to be alive on: " + targetLeader.getNodeName());
cmd = new CoreAdminRequest.WaitForState();
@@ -1518,8 +1515,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
ShardRequest sreq = new ShardRequest();
params.set("qt", adminPath);
sreq.purpose = 1;
- String replica = zkStateReader.getZkClient().getBaseUrlForNodeName(nodeName);
- if (replica.startsWith("http://")) replica = replica.substring(7);
+ String replica = zkStateReader.getBaseUrlForNodeName(nodeName);
sreq.shards = new String[]{replica};
sreq.actualShards = sreq.shards;
sreq.params = params;
@@ -1653,9 +1649,7 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
ShardRequest sreq = new ShardRequest();
params.set("qt", adminPath);
sreq.purpose = 1;
- String replica = zkStateReader.getZkClient()
- .getBaseUrlForNodeName(nodeName);
- if (replica.startsWith("http://")) replica = replica.substring(7);
+ String replica = zkStateReader.getBaseUrlForNodeName(nodeName);
sreq.shards = new String[] {replica};
sreq.actualShards = sreq.shards;
sreq.params = params;
@@ -1753,8 +1747,6 @@ public class OverseerCollectionProcessor implements Runnable, ClosableThread {
// yes, they must use same admin handler path everywhere...
cloneParams.set("qt", adminPath);
sreq.purpose = 1;
- // TODO: this sucks
- if (replica.startsWith("http://")) replica = replica.substring(7);
sreq.shards = new String[] {replica};
sreq.actualShards = sreq.shards;
sreq.params = cloneParams;
diff --git a/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java b/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java
index 138a51c48f8..270bb0a1204 100644
--- a/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java
+++ b/solr/core/src/java/org/apache/solr/cloud/SyncStrategy.java
@@ -34,9 +34,9 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.handler.component.HttpShardHandlerFactory;
import org.apache.solr.handler.component.ShardHandler;
import org.apache.solr.handler.component.ShardRequest;
import org.apache.solr.handler.component.ShardResponse;
@@ -62,10 +62,10 @@ public class SyncStrategy {
private final ExecutorService updateExecutor;
- public SyncStrategy(UpdateShardHandler updateShardHandler) {
+ public SyncStrategy(CoreContainer cc) {
+ UpdateShardHandler updateShardHandler = cc.getUpdateShardHandler();
client = updateShardHandler.getHttpClient();
-
- shardHandler = new HttpShardHandlerFactory().getShardHandler(client);
+ shardHandler = cc.getShardHandlerFactory().getShardHandler();
updateExecutor = updateShardHandler.getUpdateExecutor();
}
@@ -245,9 +245,6 @@ public class SyncStrategy {
sreq.coreName = coreName;
sreq.baseUrl = baseUrl;
sreq.purpose = 1;
- // TODO: this sucks
- if (replica.startsWith("http://"))
- replica = replica.substring(7);
sreq.shards = new String[]{replica};
sreq.actualShards = sreq.shards;
sreq.params = new ModifiableSolrParams();
diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
index 3b83db45e8b..41ca765abb6 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -59,6 +59,7 @@ import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.cloud.ZooKeeperException;
import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.URLUtil;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
@@ -87,10 +88,6 @@ public final class ZkController {
static final String NEWL = System.getProperty("line.separator");
-
- private final static Pattern URL_POST = Pattern.compile("https?://(.*)");
- private final static Pattern URL_PREFIX = Pattern.compile("(https?://).*");
-
private final boolean SKIP_AUTO_RECOVERY = Boolean.getBoolean("solrcloud.skip.autorecovery");
private final DistributedQueue overseerJobQueue;
@@ -149,7 +146,6 @@ public final class ZkController {
private final String localHostPort; // example: 54065
private final String localHostContext; // example: solr
- private final String localHost; // example: http://127.0.0.1
private final String hostName; // example: 127.0.0.1
private final String nodeName; // example: 127.0.0.1:54065_solr
private final String baseURL; // example: http://127.0.0.1:54065/solr
@@ -187,11 +183,7 @@ public final class ZkController {
this.zkServerAddress = zkServerAddress;
this.localHostPort = locaHostPort;
this.localHostContext = localHostContext;
- this.localHost = getHostAddress(localHost);
- this.baseURL = this.localHost + ":" + this.localHostPort +
- (this.localHostContext.isEmpty() ? "" : ("/" + this.localHostContext));
-
- this.hostName = getHostNameFromAddress(this.localHost);
+ this.hostName = normalizeHostName(localHost);
this.nodeName = generateNodeName(this.hostName,
this.localHostPort,
this.localHostContext);
@@ -285,6 +277,8 @@ public final class ZkController {
leaderElector = new LeaderElector(zkClient);
zkStateReader = new ZkStateReader(zkClient);
+ this.baseURL = zkStateReader.getBaseUrlForNodeName(this.nodeName);
+
init(registerOnReconnect);
}
@@ -463,9 +457,9 @@ public final class ZkController {
return bytes;
}
- // normalize host to url_prefix://host
+ // normalize host removing any url scheme.
// input can be null, host, or url_prefix://host
- private String getHostAddress(String host) throws IOException {
+ private String normalizeHostName(String host) throws IOException {
if (host == null || host.length() == 0) {
String hostaddress;
@@ -495,30 +489,15 @@ public final class ZkController {
"Error while looking for a better host name than 127.0.0.1", e);
}
}
- host = "http://" + hostaddress;
+ host = hostaddress;
} else {
- Matcher m = URL_PREFIX.matcher(host);
- if (!m.matches()) {
- host = "http://" + host;
+ if(URLUtil.hasScheme(host)) {
+ host = URLUtil.removeScheme(host);
}
}
return host;
}
-
- // extract host from url_prefix://host
- private String getHostNameFromAddress(String addr) {
- Matcher m = URL_POST.matcher(addr);
- if (m.matches()) {
- return m.group(1);
- } else {
- log.error("Unrecognized host:" + addr);
- throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
- "Unrecognized host:" + addr);
- }
- }
-
-
public String getHostName() {
return hostName;
@@ -1584,7 +1563,7 @@ public final class ZkController {
* @param hostPort - must consist only of digits, must not be null or the empty string
* @param hostContext - should not begin or end with a slash (leading/trailin slashes will be ignored), must not be null, may be the empty string to denote the root context
* @lucene.experimental
- * @see SolrZkClient#getBaseUrlForNodeName
+ * @see ZkStateReader#getBaseUrlForNodeName
*/
static String generateNodeName(final String hostName,
final String hostPort,
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
index 25cd688af03..709c3cd9d73 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
@@ -824,7 +824,7 @@ public class CoreAdminHandler extends RequestHandlerBase {
try {
core = coreContainer.getCore(cname);
if (core != null) {
- syncStrategy = new SyncStrategy(core.getCoreDescriptor().getCoreContainer().getUpdateShardHandler());
+ syncStrategy = new SyncStrategy(core.getCoreDescriptor().getCoreContainer());
Map<String,Object> props = new HashMap<String,Object>();
props.put(ZkStateReader.BASE_URL_PROP, zkController.getBaseUrl());
diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
index c345675e4c6..22166e15ef4 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
@@ -378,8 +378,6 @@ public class HttpShardHandler extends ShardHandler {
sliceShardsStr.append('|');
}
String url = ZkCoreNodeProps.getCoreUrl(replica);
- if (url.startsWith("http://"))
- url = url.substring(7);
sliceShardsStr.append(url);
}
diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
index b8c343807ef..3f91f172d83 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
@@ -16,16 +16,17 @@ package org.apache.solr.handler.component;
* limitations under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.apache.http.client.HttpClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.LBHttpSolrServer;
import org.apache.solr.client.solrj.request.QueryRequest;
-import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.StrUtils;
+import org.apache.solr.common.util.URLUtil;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.util.DefaultSolrThreadFactory;
import org.slf4j.Logger;
@@ -46,7 +47,8 @@ import java.util.concurrent.TimeUnit;
public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.apache.solr.util.plugin.PluginInfoInitialized {
protected static Logger log = LoggerFactory.getLogger(HttpShardHandlerFactory.class);
-
+ private static final String DEFAULT_SCHEME = "http";
+
// We want an executor that doesn't take up any resources if
// it's not used, so it could be created statically for
// the distributed search component if desired.
@@ -73,7 +75,7 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.
int queueSize = -1;
boolean accessPolicy = false;
- private String scheme = "http://"; //current default values
+ private String scheme = null;
private final Random r = new Random();
@@ -114,8 +116,10 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.
public void init(PluginInfo info) {
NamedList args = info.initArgs;
this.soTimeout = getParameter(args, HttpClientUtil.PROP_SO_TIMEOUT, soTimeout);
- this.scheme = getParameter(args, INIT_URL_SCHEME, "http://");
- this.scheme = (this.scheme.endsWith("://")) ? this.scheme : this.scheme + "://";
+ this.scheme = getParameter(args, INIT_URL_SCHEME, null);
+ if(StringUtils.endsWith(this.scheme, "://")) {
+ this.scheme = StringUtils.removeEnd(this.scheme, "://");
+ }
this.connectionTimeout = getParameter(args, HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout);
this.maxConnectionsPerHost = getParameter(args, HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);
this.corePoolSize = getParameter(args, INIT_CORE_POOL_SIZE, corePoolSize);
@@ -204,7 +208,7 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.
/**
* Creates a randomized list of urls for the given shard.
*
- * @param shard the urls for the shard (minus "http://"), separated by '|'
+ * @param shard the urls for the shard, separated by '|'
* @return A list of valid urls (including protocol) that are replicas for the shard
*/
public List<String> makeURLList(String shard) {
@@ -212,7 +216,7 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.
// convert shard to URL
for (int i=0; i<urls.size(); i++) {
- urls.set(i, scheme + urls.get(i));
+ urls.set(i, buildUrl(urls.get(i)));
}
//
@@ -232,4 +236,19 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.
public CompletionService newCompletionService() {
return new ExecutorCompletionService<ShardResponse>(commExecutor);
}
+
+ /**
+ * Rebuilds the URL replacing the URL scheme of the passed URL with the
+ * configured scheme replacement.If no scheme was configured, the passed URL's
+ * scheme is left alone.
+ */
+ private String buildUrl(String url) {
+ if(!URLUtil.hasScheme(url)) {
+ return StringUtils.defaultIfEmpty(scheme, DEFAULT_SCHEME) + "://" + url;
+ } else if(StringUtils.isNotEmpty(scheme)) {
+ return scheme + "://" + URLUtil.removeScheme(url);
+ }
+
+ return url;
+ }
}
diff --git a/solr/core/src/java/org/apache/solr/handler/component/ShardHandlerFactory.java b/solr/core/src/java/org/apache/solr/handler/component/ShardHandlerFactory.java
index 12710292145..ab0e3c50925 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/ShardHandlerFactory.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/ShardHandlerFactory.java
@@ -40,7 +40,6 @@ public abstract class ShardHandlerFactory {
* @return a new, initialized ShardHandlerFactory instance
*/
public static ShardHandlerFactory newInstance(PluginInfo info, SolrResourceLoader loader) {
-
if (info == null)
info = DEFAULT_SHARDHANDLER_INFO;
diff --git a/solr/core/src/java/org/apache/solr/update/PeerSync.java b/solr/core/src/java/org/apache/solr/update/PeerSync.java
index 2a7459d10d7..f94a4a3220d 100644
--- a/solr/core/src/java/org/apache/solr/update/PeerSync.java
+++ b/solr/core/src/java/org/apache/solr/update/PeerSync.java
@@ -139,7 +139,7 @@ public class PeerSync {
uhandler = core.getUpdateHandler();
ulog = uhandler.getUpdateLog();
// TODO: shutdown
- shardHandlerFactory = new HttpShardHandlerFactory();
+ shardHandlerFactory = (HttpShardHandlerFactory) core.getCoreDescriptor().getCoreContainer().getShardHandlerFactory();
shardHandler = shardHandlerFactory.getShardHandler(client);
}
@@ -269,9 +269,6 @@ public class PeerSync {
private void requestVersions(String replica) {
SyncShardRequest sreq = new SyncShardRequest();
sreq.purpose = 1;
- // TODO: this sucks
- if (replica.startsWith("http://"))
- replica = replica.substring(7);
sreq.shards = new String[]{replica};
sreq.actualShards = sreq.shards;
sreq.params = new ModifiableSolrParams();
diff --git a/solr/core/src/test-files/solr/solr-multicore.xml b/solr/core/src/test-files/solr/solr-multicore.xml
index abb308ec997..d4ba9ebe9b0 100644
--- a/solr/core/src/test-files/solr/solr-multicore.xml
+++ b/solr/core/src/test-files/solr/solr-multicore.xml
@@ -67,4 +67,7 @@
<core name="core0" instanceDir="core0" />
<core name="core1" instanceDir="core1" />
</cores>
+ <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
+ </shardHandlerFactory>
</solr>
diff --git a/solr/core/src/test-files/solr/solr-no-core.xml b/solr/core/src/test-files/solr/solr-no-core.xml
index 256b0870c95..e5ebfddbe5a 100644
--- a/solr/core/src/test-files/solr/solr-no-core.xml
+++ b/solr/core/src/test-files/solr/solr-no-core.xml
@@ -32,6 +32,7 @@
<shardHandlerFactory name="shardHandlerFactory"
class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:90000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/core/src/test-files/solr/solr.xml b/solr/core/src/test-files/solr/solr.xml
index d99bb4a6483..3327ce7034d 100644
--- a/solr/core/src/test-files/solr/solr.xml
+++ b/solr/core/src/test-files/solr/solr.xml
@@ -35,6 +35,7 @@
<core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"
coreNodeName="${coreNodeName:}"/>
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
<int name="socketTimeout">${socketTimeout:90000}</int>
<int name="connTimeout">${connTimeout:15000}</int>
</shardHandlerFactory>
diff --git a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java
index 293c31d9ad5..0551eac1dbe 100644
--- a/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java
@@ -138,7 +138,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
query.set("collection", "testalias");
JettySolrRunner jetty = jettys.get(random().nextInt(jettys.size()));
int port = jetty.getLocalPort();
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:" + port + context + "/testalias");
+ HttpSolrServer server = new HttpSolrServer(getBaseUrl() + port + context + "/testalias");
res = server.query(query);
assertEquals(3, res.getResults().getNumFound());
@@ -146,7 +146,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
query = new SolrQuery("*:*");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
- server = new HttpSolrServer("http://127.0.0.1:" + port + context + "/testalias");
+ server = new HttpSolrServer(getBaseUrl() + port + context + "/testalias");
res = server.query(query);
assertEquals(3, res.getResults().getNumFound());
@@ -173,7 +173,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
query.set("collection", "testalias");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
- server = new HttpSolrServer("http://127.0.0.1:" + port + context + "/testalias");
+ server = new HttpSolrServer(getBaseUrl() + port + context + "/testalias");
res = server.query(query);
assertEquals(5, res.getResults().getNumFound());
@@ -181,7 +181,7 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
query = new SolrQuery("*:*");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
- server = new HttpSolrServer("http://127.0.0.1:" + port + context + "/testalias");
+ server = new HttpSolrServer(getBaseUrl() + port + context + "/testalias");
res = server.query(query);
assertEquals(5, res.getResults().getNumFound());
@@ -243,6 +243,10 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
assertTrue(sawException);
}
+ private String getBaseUrl() {
+ return (isSSLMode() ? "https" : "http") + "://127.0.0.1:";
+ }
+
private void createAlias(String alias, String collections)
throws SolrServerException, IOException {
if (random().nextBoolean()) {
diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
index 36a470cffaf..7b2fb8d2a8c 100644
--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
@@ -20,13 +20,12 @@ package org.apache.solr.cloud;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.io.IOUtils;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
@@ -444,12 +443,9 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
public void run() {
String masterUrl = client.getBaseURL() + "/replication?command="
+ ReplicationHandler.CMD_DETAILS;
- URL url;
- InputStream stream = null;
+
try {
- url = new URL(masterUrl);
- stream = url.openStream();
- response = IOUtils.toString(stream, "UTF-8");
+ response = client.getHttpClient().execute(new HttpGet(masterUrl), new BasicResponseHandler());
if (response.contains("<str name=\"status\">success</str>")) {
Matcher m = p.matcher(response);
if (!m.find()) {
@@ -458,12 +454,9 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
success = true;
}
- stream.close();
} catch (Exception e) {
e.printStackTrace();
fail = e.getMessage();
- } finally {
- IOUtils.closeQuietly(stream);
}
};
diff --git a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
index f3ca7f74317..45845af56db 100644
--- a/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
@@ -440,7 +440,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
// each replica should also give the same numDocs
ArrayList<String> replicaAlts = new ArrayList<String>(replicaJetties.size() * 2);
for (CloudJettyRunner replicaJetty : shardToJetty.get(shard)) {
- String replica = removeProtocol(replicaJetty.url);
+ String replica = replicaJetty.url;
query.set("shards", replica);
// replicas already shuffled, use this in the alternative check below
@@ -484,7 +484,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
ArrayList<String> replicas = new ArrayList<String>(7);
for (CloudJettyRunner replicaJetty : shardToJetty.get(shard)) {
if (0 == random().nextInt(3) || 0 == replicas.size()) {
- replicas.add(removeProtocol(replicaJetty.url));
+ replicas.add(replicaJetty.url);
}
}
Collections.shuffle(replicas, random());
@@ -1201,11 +1201,4 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
// insurance
DirectUpdateHandler2.commitOnClose = true;
}
-
- /**
- * Given a URL as a string, removes the leading protocol from that string
- */
- private static String removeProtocol(String url) {
- return url.replaceFirst("^[^:/]{1,20}:/+","");
- }
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java
index 17b72e4e5c7..3c5fcbc16eb 100644
--- a/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/FullSolrCloudDistribCmdsTest.java
@@ -438,7 +438,7 @@ public class FullSolrCloudDistribCmdsTest extends AbstractFullDistribZkTestBase
long beforeCount = results.getResults().getNumFound();
int cnt = TEST_NIGHTLY ? 2933 : 313;
try {
- suss.setConnectionTimeout(15000);
+ suss.setConnectionTimeout(30000);
for (int i = 0; i < cnt; i++) {
index_specific(suss, id, docId++, "text_t", "some text so that it not's negligent work to parse this doc, even though it's still a pretty short doc");
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java
index e3be35c2e10..e24b45b9c7a 100644
--- a/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java
@@ -207,7 +207,7 @@ public class OverseerCollectionProcessorTest extends SolrTestCaseJ4 {
final String address = "localhost:" + (8963 + i) + "_solr";
liveNodes.add(address);
- solrZkClientMock.getBaseUrlForNodeName(address);
+ zkStateReaderMock.getBaseUrlForNodeName(address);
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
diff --git a/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java b/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java
index 530d405d2a8..8b37dd9a06b 100644
--- a/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/OverseerRolesTest.java
@@ -17,42 +17,37 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
-import com.google.protobuf.TextFormat;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.MAX_SHARDS_PER_NODE;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.REPLICATION_FACTOR;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.getSortedNodeNames;
+import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.request.QueryRequest;
-import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.CollectionParams.CollectionAction;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.SolrParams;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.data.Stat;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.solr.cloud.OverseerCollectionProcessor.MAX_SHARDS_PER_NODE;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.REPLICATION_FACTOR;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.getSortedNodeNames;
-import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
-import static org.apache.solr.common.params.CollectionParams.CollectionAction;
@LuceneTestCase.Slow
public class OverseerRolesTest extends AbstractFullDistribZkTestBase{
private CloudSolrServer client;
+ static {
+ sslConfig = null;
+ }
+
@BeforeClass
public static void beforeThisClass2() throws Exception {
diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java
index 9c186321759..2ea2a2d2fb2 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java
@@ -32,11 +32,10 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
-import java.io.IOException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.TimeoutException;
@Slow
public class ZkControllerTest extends SolrTestCaseJ4 {
@@ -99,49 +98,59 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
- SolrZkClient zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT);
+ ZkStateReader zkStateReader = new ZkStateReader(server.getZkAddress(), TIMEOUT, TIMEOUT);
try {
-
// getBaseUrlForNodeName
assertEquals("http://zzz.xxx:1234/solr",
- zkClient.getBaseUrlForNodeName("zzz.xxx:1234_solr"));
+ zkStateReader.getBaseUrlForNodeName("zzz.xxx:1234_solr"));
assertEquals("http://xxx:99",
- zkClient.getBaseUrlForNodeName("xxx:99_"));
+ zkStateReader.getBaseUrlForNodeName("xxx:99_"));
assertEquals("http://foo-bar.baz.org:9999/some_dir",
- zkClient.getBaseUrlForNodeName("foo-bar.baz.org:9999_some_dir"));
+ zkStateReader.getBaseUrlForNodeName("foo-bar.baz.org:9999_some_dir"));
assertEquals("http://foo-bar.baz.org:9999/solr/sub_dir",
- zkClient.getBaseUrlForNodeName("foo-bar.baz.org:9999_solr%2Fsub_dir"));
+ zkStateReader.getBaseUrlForNodeName("foo-bar.baz.org:9999_solr%2Fsub_dir"));
// generateNodeName + getBaseUrlForNodeName
assertEquals("http://foo:9876/solr",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo","9876","solr")));
assertEquals("http://foo:9876/solr",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo","9876","/solr")));
assertEquals("http://foo:9876/solr",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo","9876","/solr/")));
assertEquals("http://foo.bar.com:9876/solr/sub_dir",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo.bar.com","9876","solr/sub_dir")));
assertEquals("http://foo.bar.com:9876/solr/sub_dir",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo.bar.com","9876","/solr/sub_dir/")));
assertEquals("http://foo-bar:9876",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo-bar","9876","")));
assertEquals("http://foo-bar:9876",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo-bar","9876","/")));
assertEquals("http://foo-bar.com:80/some_dir",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo-bar.com","80","some_dir")));
assertEquals("http://foo-bar.com:80/some_dir",
- zkClient.getBaseUrlForNodeName
+ zkStateReader.getBaseUrlForNodeName
(ZkController.generateNodeName("foo-bar.com","80","/some_dir")));
+
+ //Verify the URL Scheme is taken into account
+ zkStateReader.getZkClient().create(ZkStateReader.CLUSTER_PROPS,
+ ZkStateReader.toJSON(Collections.singletonMap("urlScheme", "https")), CreateMode.PERSISTENT, true);
+
+ assertEquals("https://zzz.xxx:1234/solr",
+ zkStateReader.getBaseUrlForNodeName("zzz.xxx:1234_solr"));
+
+ assertEquals("https://foo-bar.com:80/some_dir",
+ zkStateReader.getBaseUrlForNodeName
+ (ZkController.generateNodeName("foo-bar.com","80","/some_dir")));
} finally {
- zkClient.close();
+ zkStateReader.close();
}
} finally {
server.shutdown();
diff --git a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java
index b08440d968c..f603fdf8048 100644
--- a/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java
+++ b/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java
@@ -17,9 +17,20 @@
package org.apache.solr.core;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Random;
+import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
import org.apache.commons.io.FileUtils;
import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.UpdateRequest;
@@ -28,23 +39,10 @@ import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Random;
-import java.util.TreeMap;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-
/**
* Incorporate the open/close stress tests into unit tests.
*/
@@ -74,7 +72,12 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
List<HttpSolrServer> queryServers = new ArrayList<HttpSolrServer>(queryThreads);
static String savedFactory;
+
+ @BeforeClass
+ public static void beforeClass() {
+ }
+
@Before
public void setupServer() throws Exception {
coreCounts = new TreeMap<String, Long>();
@@ -84,7 +87,7 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
solrHomeDirectory = new File(TEMP_DIR, "OpenCloseCoreStressTest_");
FileUtils.deleteDirectory(solrHomeDirectory); // Ensure that a failed test didn't leave something lying around.
- jetty = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), "/solr", 0);
+ jetty = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), "/solr", 0, null, null, true, null, sslConfig);
}
@After
@@ -132,7 +135,7 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
private void getServers() throws Exception {
jetty.start();
- url = "http://127.0.0.1:" + jetty.getLocalPort() + "/solr/";
+ url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + jetty.getLocalPort() + "/solr/";
// Mostly to keep annoying logging messages from being sent out all the time.
diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
index b6975daac48..16266c6d1b2 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
@@ -72,6 +72,7 @@ import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.util.FileUtils;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -99,7 +100,16 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
// index from previous test method
static int nDocs = 500;
+ static {
+ // does not yet work with ssl
+ sslConfig = null;
+ }
+
+ @BeforeClass
+ public static void beforeClass() {
+ }
+
@Before
public void setUp() throws Exception {
super.setUp();
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
index 62cdfd41249..f718331b98c 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
@@ -11,6 +11,7 @@ import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
+import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -44,21 +45,6 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
@BeforeClass
public static void beforeTest() throws Exception {
solrHome = createSolrHome();
- createJetty(solrHome.getAbsolutePath(), null, null);
-
- String url = jetty.getBaseUrl().toString();
- collection1 = new HttpSolrServer(url);
- collection2 = new HttpSolrServer(url + "/collection2");
-
- String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
- String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
- shard1 = urlCollection1.replaceAll("http://", "");
- shard2 = urlCollection2.replaceAll("http://", "");
-
- //create second core
- CoreAdminRequest.Create req = new CoreAdminRequest.Create();
- req.setCoreName("collection2");
- collection1.request(req);
}
private static File createSolrHome() throws Exception {
@@ -70,12 +56,6 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
@AfterClass
public static void afterTest() throws Exception {
- collection1.shutdown();
- collection2.shutdown();
- collection1 = null;
- collection2 = null;
- jetty.stop();
- jetty=null;
cleanUpJettyHome(solrHome);
}
@@ -83,6 +63,20 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
@Override
public void setUp() throws Exception {
super.setUp();
+ createJetty(solrHome.getAbsolutePath(), null, null);
+ String url = jetty.getBaseUrl().toString();
+ collection1 = new HttpSolrServer(url);
+ collection2 = new HttpSolrServer(url + "/collection2");
+
+ String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
+ String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
+ shard1 = urlCollection1.replaceAll("http" + (sslConfig == null || !sslConfig.useSsl ? "" : "s") + "://", "");
+ shard2 = urlCollection2.replaceAll("http" + (sslConfig == null || !sslConfig.useSsl ? "" : "s") + "://", "");
+
+ //create second core
+ CoreAdminRequest.Create req = new CoreAdminRequest.Create();
+ req.setCoreName("collection2");
+ collection1.request(req);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
@@ -97,6 +91,17 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
}
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ collection1.shutdown();
+ collection2.shutdown();
+ collection1 = null;
+ collection2 = null;
+ jetty.stop();
+ jetty=null;
+ }
+
@Test
@SuppressWarnings("unchecked")
public void testSimpleSearch() throws Exception {
diff --git a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
index 1217ecefeeb..01fd6185d78 100644
--- a/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
+++ b/solr/core/src/test/org/apache/solr/request/TestRemoteStreaming.java
@@ -49,6 +49,11 @@ public class TestRemoteStreaming extends SolrJettyTestBase {
private static final File solrHomeDirectory = new File(TEMP_DIR, "TestRemoteStreaming");
+ static {
+ // does not yet work with ssl
+ sslConfig = null;
+ }
+
@BeforeClass
public static void beforeTest() throws Exception {
//this one has handleSelect=true which a test here needs
diff --git a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
index 3cec999981f..87cc757e4e1 100644
--- a/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/CacheHeaderTest.java
@@ -23,17 +23,17 @@ import java.io.Writer;
import java.util.Arrays;
import java.util.Date;
-import com.google.common.base.Charsets;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.cookie.DateUtils;
+import org.apache.lucene.util._TestUtil;
import org.apache.solr.common.params.CommonParams;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.apache.lucene.util._TestUtil;
+import com.google.common.base.Charsets;
/**
* A test case for the several HTTP cache headers emitted by Solr
@@ -41,6 +41,11 @@ import org.apache.lucene.util._TestUtil;
public class CacheHeaderTest extends CacheHeaderTestBase {
private static final File solrHomeDirectory = new File(TEMP_DIR, "CacheHeaderTest");
+ static {
+ // does not yet work with ssl
+ sslConfig = null;
+ }
+
@BeforeClass
public static void beforeTest() throws Exception {
setupJettyTestHome(solrHomeDirectory, "collection1");
diff --git a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
index 3b1ef9bfc33..07018c3092b 100644
--- a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
@@ -60,9 +60,13 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
private AtomicInteger id = new AtomicInteger();
+ static {
+ // no ssl currently because distrib updates read scheme from zk and no zk in this test
+ sslConfig = null;
+ }
+
@BeforeClass
public static void beforeClass() throws Exception {
-
// we can't use the Randomized merge policy because the test depends on
// being able to call optimize to have all deletes expunged.
System.setProperty("solr.tests.mergePolicy", LogDocMergePolicy.class.getName());
diff --git a/solr/example/multicore/solr.xml b/solr/example/multicore/solr.xml
index 27079019bd6..4e27135ee73 100644
--- a/solr/example/multicore/solr.xml
+++ b/solr/example/multicore/solr.xml
@@ -31,5 +31,10 @@
<cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">
<core name="core0" instanceDir="core0" />
<core name="core1" instanceDir="core1" />
+
+ <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
+ <str name="urlScheme">${urlScheme:}</str>
+ </shardHandlerFactory>
</cores>
+
</solr>
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java
index e2f9c813840..5a162203b7f 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrServer.java
@@ -526,12 +526,7 @@ public class CloudSolrServer extends SolrServer {
|| request.getPath().equals("/admin/cores")) {
Set<String> liveNodes = clusterState.getLiveNodes();
for (String liveNode : liveNodes) {
- int splitPointBetweenHostPortAndContext = liveNode.indexOf("_");
- theUrlList.add("http://"
- + liveNode.substring(0, splitPointBetweenHostPortAndContext)
- + "/"
- + URLDecoder.decode(liveNode, "UTF-8").substring(
- splitPointBetweenHostPortAndContext + 1));
+ theUrlList.add(zkStateReader.getBaseUrlForNodeName(liveNode));
}
} else {
String collection = reqParams.get("collection", defaultCollection);
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
index ac7638b7897..b7c0680bf55 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java
@@ -93,6 +93,10 @@ public class HttpClientUtil {
configurer = newConfigurer;
}
+ public static HttpClientConfigurer getConfigurer() {
+ return configurer;
+ }
+
/**
* Creates new http client by using the provided configuration.
*
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
index 54cc3c8aaed..f765542403f 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZkClient.java
@@ -490,28 +490,6 @@ public class SolrZkClient {
return setData(path, data, retryOnConnLoss);
}
- /**
- * Returns the baseURL corrisponding to a given node's nodeName --
- * NOTE: does not (currently) imply that the nodeName (or resulting
- * baseURL) exists in the cluster.
- * @lucene.experimental
- */
- public String getBaseUrlForNodeName(final String nodeName) {
- final int _offset = nodeName.indexOf("_");
- if (_offset < 0) {
- throw new IllegalArgumentException("nodeName does not contain expected '_' seperator: " + nodeName);
- }
- final String hostAndPort = nodeName.substring(0,_offset);
- try {
- final String path = URLDecoder.decode(nodeName.substring(1+_offset),
- "UTF-8");
- return "http://" + hostAndPort + (path.isEmpty() ? "" : ("/" + path));
- } catch (UnsupportedEncodingException e) {
- throw new IllegalStateException("JVM Does not seem to support UTF-8", e);
- }
- }
-
-
/**
* Fills string with printout of current ZooKeeper layout.
*/
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index b59675b2606..c1e1a16f684 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -18,6 +18,8 @@ package org.apache.solr.common.cloud;
*/
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -619,4 +621,28 @@ public class ZkStateReader {
}
}
+ /**
+ * Returns the baseURL corrisponding to a given node's nodeName --
+ * NOTE: does not (currently) imply that the nodeName (or resulting
+ * baseURL) exists in the cluster.
+ * @lucene.experimental
+ */
+ public String getBaseUrlForNodeName(final String nodeName) {
+ final int _offset = nodeName.indexOf("_");
+ if (_offset < 0) {
+ throw new IllegalArgumentException("nodeName does not contain expected '_' seperator: " + nodeName);
+ }
+ final String hostAndPort = nodeName.substring(0,_offset);
+ try {
+ final String path = URLDecoder.decode(nodeName.substring(1+_offset), "UTF-8");
+ String urlScheme = (String) getClusterProps().get("urlScheme");
+ if(urlScheme == null) {
+ urlScheme = "http";
+ }
+ return urlScheme + "://" + hostAndPort + (path.isEmpty() ? "" : ("/" + path));
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException("JVM Does not seem to support UTF-8", e);
+ }
+ }
+
}
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/URLUtil.java b/solr/solrj/src/java/org/apache/solr/common/util/URLUtil.java
new file mode 100644
index 00000000000..6d273ecdffe
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/common/util/URLUtil.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.common.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class URLUtil {
+
+ public final static Pattern URL_PREFIX = Pattern.compile("^([a-z]*?://).*");
+
+ public static String removeScheme(String url) {
+ Matcher matcher = URL_PREFIX.matcher(url);
+ if (matcher.matches()) {
+ return url.substring(matcher.group(1).length());
+ }
+
+ return url;
+ }
+
+ public static boolean hasScheme(String url) {
+ Matcher matcher = URL_PREFIX.matcher(url);
+ return matcher.matches();
+ }
+
+ public static String getScheme(String url) {
+ Matcher matcher = URL_PREFIX.matcher(url);
+ if (matcher.matches()) {
+ return matcher.group(1);
+ }
+
+ return null;
+ }
+
+}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
index 1d272e332db..f1541605596 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
@@ -259,7 +259,7 @@ public class TestLBHttpSolrServer extends SolrTestCaseJ4 {
}
public String getUrl() {
- return "http://127.0.0.1:" + port + "/solr";
+ return "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + port + "/solr";
}
public String getSchemaFile() {
@@ -314,7 +314,7 @@ public class TestLBHttpSolrServer extends SolrTestCaseJ4 {
}
public void startJetty() throws Exception {
- jetty = new JettySolrRunner(getHomeDir(), "/solr", port, "bad_solrconfig.xml", null);
+ jetty = new JettySolrRunner(getHomeDir(), "/solr", port, "bad_solrconfig.xml", null, true, null, sslConfig);
System.setProperty("solr.data.dir", getDataDir());
jetty.start();
int newPort = jetty.getLocalPort();
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java
index 61eaad6afbf..e356a81bbfa 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java
@@ -52,7 +52,7 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
System.clearProperty("solr.directoryFactory");
super.setUp();
- jetty = new JettySolrRunner(getSolrHome(), context, 0 );
+ jetty = new JettySolrRunner(getSolrHome(), context, 0, null, null, true, null, sslConfig);
jetty.start(false);
port = jetty.getLocalPort();
@@ -93,7 +93,7 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
{
try {
// setup the server...
- String url = "http://127.0.0.1:"+port+context+"/"+name;
+ String url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:"+port+context+"/"+name;
HttpSolrServer s = new HttpSolrServer( url );
s.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
s.setDefaultMaxConnectionsPerHost(100);
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
index 3bd3b99c502..81387f46257 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
@@ -43,7 +43,7 @@ public class SolrExampleJettyTest extends SolrExampleTests {
{
try {
// setup the server...
- String url = "http://127.0.0.1/?core=xxx";
+ String url = "http" + (isSSLMode() ? "s" : "") + "://127.0.0.1/?core=xxx";
HttpSolrServer s = new HttpSolrServer( url );
Assert.fail( "CommonsHttpSolrServer should not allow a path with a parameter: "+s.getBaseURL() );
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
index 51b4c179ea1..9bd9f11b471 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
@@ -146,7 +146,7 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {
public void testConnectionRefused() throws MalformedURLException {
int unusedPort = findUnusedPort(); // XXX even if fwe found an unused port
// it might not be unused anymore
- HttpSolrServer server = new HttpSolrServer("http://127.0.0.1:" + unusedPort
+ HttpSolrServer server = new HttpSolrServer("http" + (isSSLMode() ? "s" : "") + "://127.0.0.1:" + unusedPort
+ "/solr");
server.setConnectionTimeout(500);
SolrQuery q = new SolrQuery("*:*");
diff --git a/solr/solrj/src/test/org/apache/solr/common/util/URLUtilTest.java b/solr/solrj/src/test/org/apache/solr/common/util/URLUtilTest.java
new file mode 100644
index 00000000000..7c98999f563
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/common/util/URLUtilTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.common.util;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class URLUtilTest {
+
+ @Test
+ public void test() {
+ assertTrue(URLUtil.hasScheme("http://host:1234/"));
+ assertTrue(URLUtil.hasScheme("https://host/"));
+ assertFalse(URLUtil.hasScheme("host/"));
+ assertFalse(URLUtil.hasScheme("host:8989"));
+ assertEquals("foo/", URLUtil.removeScheme("https://foo/"));
+ assertEquals("foo:8989/", URLUtil.removeScheme("https://foo:8989/"));
+ assertEquals("http://", URLUtil.getScheme("http://host:1928"));
+ assertEquals("https://", URLUtil.getScheme("https://host:1928"));
+ }
+
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
index 463c2938aec..6b4316e1754 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -36,8 +36,9 @@ import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.search.FieldCache;
-import org.apache.lucene.util. _TestUtil;
import org.apache.lucene.util.Constants;
+import org.apache.lucene.util._TestUtil;
+import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -45,7 +46,6 @@ import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
-import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
@@ -55,8 +55,8 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.schema.TrieDateField;
import org.apache.solr.util.AbstractSolrTestCase;
import org.eclipse.jetty.servlet.ServletHolder;
-import org.junit.BeforeClass;
import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -123,7 +123,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
log.info("Setting hostContext system property: " + hc);
System.setProperty("hostContext", hc);
}
-
+
/**
* Clears the "hostContext" system property
* @see #initHostContext
@@ -369,14 +369,14 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
boolean stopAtShutdown = true;
JettySolrRunner jetty = new JettySolrRunner
(solrHome.getAbsolutePath(), context, 0, solrConfigOverride, schemaOverride, stopAtShutdown,
- getExtraServlets(), null, getExtraRequestFilters());
+ getExtraServlets(), sslConfig, getExtraRequestFilters());
jetty.setShards(shardList);
jetty.setDataDir(dataDir);
if (explicitCoreNodeName) {
jetty.setCoreNodeName(Integer.toString(nodeCnt.incrementAndGet()));
}
jetty.start();
-
+
return jetty;
}
@@ -393,7 +393,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
protected SolrServer createNewSolrServer(int port) {
try {
// setup the server...
- String url = "http://127.0.0.1:" + port + context;
+ String urlScheme = isSSLMode() ? "https" : "http";
+ String url = urlScheme + "://127.0.0.1:" + port + context;
HttpSolrServer s = new HttpSolrServer(url);
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
s.setSoTimeout(60000);
@@ -931,4 +932,5 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
FileUtils.copyFile(new File(getSolrHome(), solrxml), new File(jettyHome, "solr.xml"));
}
}
+
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
index 996ed5505a8..d55d4c13f11 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
@@ -38,72 +38,16 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
{
private static Logger log = LoggerFactory.getLogger(SolrJettyTestBase.class);
- private static File TEST_KEYSTORE;
- static {
- TEST_KEYSTORE = (null == ExternalPaths.SOURCE_HOME)
- ? null : new File(ExternalPaths.SOURCE_HOME, "example/etc/solrtest.keystore");
- }
-
- private static void initSSLConfig(SSLConfig sslConfig, String keystorePath) {
- sslConfig.useSsl = false;
- sslConfig.clientAuth = false;
- sslConfig.keyStore = keystorePath;
- sslConfig.keyStorePassword = "secret";
- sslConfig.trustStore = keystorePath;
- sslConfig.trustStorePassword = "secret";
- }
-
- /**
- * Returns the File object for the example keystore used when this baseclass randomly
- * uses SSL. May be null ifthis test does not appear to be running as part of the
- * standard solr distribution and does not have access to the example configs.
- *
- * @lucene.internal
- */
- protected static File getExampleKeystoreFile() {
- return TEST_KEYSTORE;
- }
@BeforeClass
public static void beforeSolrJettyTestBase() throws Exception {
-
-
- // only randomize SSL if we are a solr test with access to the example keystore
- if (null == getExampleKeystoreFile()) {
- log.info("Solr's example keystore not defined (not a solr test?) skipping SSL randomization");
- return;
- }
-
- assertTrue("test keystore does not exist, randomized ssl testing broken: " +
- getExampleKeystoreFile().getAbsolutePath(),
- getExampleKeystoreFile().exists() );
-
}
public static JettySolrRunner jetty;
public static int port;
public static SolrServer server = null;
public static String context;
-
- public static SSLConfig getSSLConfig() {
- SSLConfig sslConfig = new SSLConfig();
-
- final boolean trySsl = random().nextBoolean();
- final boolean trySslClientAuth = random().nextBoolean();
-
- log.info("Randomized ssl ({}) and clientAuth ({})", trySsl,
- trySslClientAuth);
- String keystorePath = null == TEST_KEYSTORE ? null : TEST_KEYSTORE
- .getAbsolutePath();
- initSSLConfig(sslConfig, keystorePath);
-
- sslConfig.useSsl = trySsl;
- sslConfig.clientAuth = trySslClientAuth;
-
- initSSLConfig(sslConfig, keystorePath);
- return sslConfig;
- }
public static JettySolrRunner createJetty(String solrHome, String configFile, String schemaFile, String context,
boolean stopAtShutdown, SortedMap<ServletHolder,String> extraServlets)
@@ -118,7 +62,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
context = context==null ? "/solr" : context;
SolrJettyTestBase.context = context;
- jetty = new JettySolrRunner(solrHome, context, 0, configFile, schemaFile, stopAtShutdown, extraServlets, getSSLConfig());
+ jetty = new JettySolrRunner(solrHome, context, 0, configFile, schemaFile, stopAtShutdown, extraServlets, sslConfig);
jetty.start();
port = jetty.getLocalPort();
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index 9f60f3c1b78..ed9ead0d8d4 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -24,6 +24,10 @@ import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -42,6 +46,11 @@ import javax.xml.xpath.XPathExpressionException;
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.FileUtils;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
+import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.index.IndexWriterConfig;
@@ -49,6 +58,9 @@ import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.QuickPatchThreadsFilter;
import org.apache.lucene.util._TestUtil;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner.SSLConfig;
+import org.apache.solr.client.solrj.impl.HttpClientConfigurer;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.cloud.IpTables;
import org.apache.solr.common.SolrDocument;
@@ -77,6 +89,7 @@ import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.util.AbstractSolrTestCase;
+import org.apache.solr.util.ExternalPaths;
import org.apache.solr.util.RevertDefaultThreadHandlerRule;
import org.apache.solr.util.TestHarness;
import org.junit.AfterClass;
@@ -110,6 +123,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
private static String coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;
public static int DEFAULT_CONNECTION_TIMEOUT = 30000; // default socket connection timeout in ms
+ protected static volatile SSLConfig sslConfig = new SSLConfig();
@ClassRule
public static TestRule solrClassRules =
@@ -132,6 +146,32 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
startTrackingZkClients();
ignoreException("ignore_exception");
newRandomConfig();
+ sslConfig = getSSLConfig();
+
+
+ if(sslConfig != null && sslConfig.useSsl) {
+ // SolrCloud tests should usually clear this
+ System.setProperty("urlScheme", "https");
+
+ // Turn off two-way SSL since it isn't configured below...
+ sslConfig.clientAuth = false;
+ HttpClientUtil.setConfigurer(new HttpClientConfigurer(){
+ @SuppressWarnings("deprecation")
+ protected void configure(DefaultHttpClient httpClient, SolrParams config) {
+ super.configure(httpClient, config);
+ SchemeRegistry registry = httpClient.getConnectionManager().getSchemeRegistry();
+ // Make sure no tests cheat by using HTTP
+ registry.unregister("http");
+ try {
+ // Don't complain that we are using self-signed certs during the test
+ registry.register(new Scheme("https", 443, new SSLSocketFactory(new TrustSelfSignedStrategy())));
+ } catch (KeyManagementException | UnrecoverableKeyException
+ | NoSuchAlgorithmException | KeyStoreException ex) {
+ throw new IllegalStateException("Unable to setup https scheme for HTTPClient to test SSL.", ex);
+ }
+ }
+ });
+ }
}
@AfterClass
@@ -147,9 +187,44 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
System.clearProperty("tests.shardhandler.randomSeed");
System.clearProperty("enable.update.log");
System.clearProperty("useCompoundFile");
+ System.clearProperty("urlScheme");
+
+ if(sslConfig != null && sslConfig.useSsl) {
+ HttpClientUtil.setConfigurer(new HttpClientConfigurer());
+ }
IpTables.unblockAllPorts();
}
+
+ private static File TEST_KEYSTORE;
+ static {
+ TEST_KEYSTORE = (null == ExternalPaths.SOURCE_HOME)
+ ? null : new File(ExternalPaths.SOURCE_HOME, "example/etc/solrtest.keystore");
+ }
+
+ protected boolean isSSLMode() {
+ return sslConfig != null && sslConfig.useSsl;
+ }
+
+ private static void initSSLConfig(SSLConfig sslConfig, String keystorePath) {
+ sslConfig.useSsl = false;
+ sslConfig.clientAuth = false;
+ sslConfig.keyStore = keystorePath;
+ sslConfig.keyStorePassword = "secret";
+ sslConfig.trustStore = keystorePath;
+ sslConfig.trustStorePassword = "secret";
+ }
+
+ /**
+ * Returns the File object for the example keystore used when this baseclass randomly
+ * uses SSL. May be null ifthis test does not appear to be running as part of the
+ * standard solr distribution and does not have access to the example configs.
+ *
+ * @lucene.internal
+ */
+ protected static File getExampleKeystoreFile() {
+ return TEST_KEYSTORE;
+ }
private static boolean changedFactory = false;
private static String savedFactory;
@@ -177,6 +252,39 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
}
}
+ private static SSLConfig getSSLConfig() {
+ // test has disabled
+ if (sslConfig == null) {
+ SSLConfig sslConfig = new SSLConfig();
+ return sslConfig;
+ }
+
+ // only randomize SSL if we are a solr test with access to the example keystore
+ if (null == getExampleKeystoreFile()) {
+ log.info("Solr's example keystore not defined (not a solr test?) skipping SSL randomization");
+ return null;
+ }
+
+ assertTrue("test keystore does not exist, randomized ssl testing broken: " +
+ getExampleKeystoreFile().getAbsolutePath(),
+ getExampleKeystoreFile().exists() );
+
+ SSLConfig sslConfig = new SSLConfig();
+
+ final boolean trySsl = random().nextBoolean();
+ final boolean trySslClientAuth = false; // TODO: random().nextBoolean();
+
+ log.info("Randomized ssl ({}) and clientAuth ({})", trySsl,
+ trySslClientAuth);
+ String keystorePath = null == TEST_KEYSTORE ? null : TEST_KEYSTORE
+ .getAbsolutePath();
+ initSSLConfig(sslConfig, keystorePath);
+
+ sslConfig.useSsl = trySsl;
+ sslConfig.clientAuth = trySslClientAuth;
+
+ return sslConfig;
+ }
protected static MockTokenizer whitespaceMockTokenizer(Reader input) throws IOException {
MockTokenizer mockTokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, false);
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
index 5a8c3e8d46a..729868eb7d9 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
@@ -28,6 +28,7 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -40,11 +41,13 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.lucene.util.LuceneTestCase.Slow;
+import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner.SSLConfig;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.QueryRequest;
@@ -70,6 +73,7 @@ import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.update.DirectUpdateHandler2;
+import org.apache.zookeeper.CreateMode;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -202,6 +206,19 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
} else {
System.clearProperty("numShards");
}
+
+ if (isSSLMode()) {
+ System.clearProperty("urlScheme");
+ ZkStateReader zkStateReader = new ZkStateReader(zkServer.getZkAddress(),
+ AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT);
+ try {
+ zkStateReader.getZkClient().create(ZkStateReader.CLUSTER_PROPS,
+ ZkStateReader.toJSON(Collections.singletonMap("urlScheme","https")),
+ CreateMode.PERSISTENT, true);
+ } finally {
+ zkStateReader.close();
+ }
+ }
}
@BeforeClass
@@ -454,7 +471,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
String solrConfigOverride) throws Exception {
JettySolrRunner jetty = new JettySolrRunner(getSolrHome(), context, 0,
- solrConfigOverride, null, false, getExtraServlets(), null, getExtraRequestFilters());
+ solrConfigOverride, null, false, getExtraServlets(), sslConfig, getExtraRequestFilters());
jetty.setShards(shardList);
jetty.setDataDir(getDataDir(dataDir));
jetty.start();
@@ -468,7 +485,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
solrHome = getRelativeSolrHomePath(solrHome);
}
- JettySolrRunner jetty = new JettySolrRunner(solrHome.getPath(), context, 0, solrConfigOverride, schemaOverride, false, getExtraServlets(), null, getExtraRequestFilters());
+ JettySolrRunner jetty = new JettySolrRunner(solrHome.getPath(), context, 0, solrConfigOverride, schemaOverride, false, getExtraServlets(), sslConfig, getExtraRequestFilters());
jetty.setShards(shardList);
jetty.setDataDir(getDataDir(dataDir));
jetty.start();
@@ -1659,7 +1676,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
protected SolrServer createNewSolrServer(int port) {
try {
// setup the server...
- String url = "http://127.0.0.1:" + port + context +
+ String urlScheme = isSSLMode() ? "https" : "http";
+ String url = urlScheme + "://127.0.0.1:" + port + context +
(context.endsWith("/") ? "" : "/") + DEFAULT_COLLECTION;
HttpSolrServer s = new HttpSolrServer(url);
s.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
@@ -1773,6 +1791,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
return commondCloudSolrServer;
}
+
public static String getUrlFromZk(ClusterState clusterState, String collection) {
Map<String,Slice> slices = clusterState.getCollection(collection).getSlicesMap();
@@ -1821,4 +1840,4 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
fail("Could not find the new collection - " + exp.code() + " : " + collectionClient.getBaseURL());
}
-}
+}
\ No newline at end of file
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
index 9d551a99101..b26e07c9f30 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
@@ -16,6 +16,12 @@ package org.apache.solr.util;
* limitations under the License.
*/
+import java.io.IOException;
+import java.util.Map;
+import java.util.SortedMap;
+
+import javax.xml.xpath.XPathExpressionException;
+
import org.apache.solr.JSONTestUtil;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.common.SolrException;
@@ -23,19 +29,20 @@ import org.apache.solr.common.params.MultiMapSolrParams;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.servlet.SolrRequestParsers;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
-import javax.xml.xpath.XPathExpressionException;
-import java.io.IOException;
-import java.util.Map;
-import java.util.SortedMap;
-
abstract public class RestTestBase extends SolrJettyTestBase {
private static final Logger log = LoggerFactory.getLogger(RestTestBase.class);
protected static RestTestHarness restTestHarness;
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // sslConfig = null;
+ }
+
public static void createJettyAndHarness
(String solrHome, String configFile, String schemaFile, String context,
boolean stopAtShutdown, SortedMap<ServletHolder,String> extraServlets) throws Exception {
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
index 8d293c3d6e5..42207cb6577 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
@@ -16,23 +16,30 @@ package org.apache.solr.util;
* limitations under the License.
*/
-import org.apache.commons.io.IOUtils;
-
-import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.StringWriter;
-import java.net.HttpURLConnection;
-import java.net.URL;
import java.net.URLEncoder;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.util.EntityUtils;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
+import org.apache.solr.common.params.ModifiableSolrParams;
+
/**
* Facilitates testing Solr's REST API via a provided embedded Jetty
*/
public class RestTestHarness extends BaseTestHarness {
private RESTfulServerProvider serverProvider;
+ private HttpClient httpClient = HttpClientUtil.createClient(new
+ ModifiableSolrParams());
public RestTestHarness(RESTfulServerProvider serverProvider) {
this.serverProvider = serverProvider;
@@ -83,22 +90,7 @@ public class RestTestHarness extends BaseTestHarness {
* @exception Exception any exception in the response.
*/
public String query(String request) throws Exception {
- URL url = new URL(getBaseURL() + request);
- HttpURLConnection connection = (HttpURLConnection)url.openConnection();
- InputStream inputStream = null;
- StringWriter strWriter;
- try {
- try {
- inputStream = connection.getInputStream();
- } catch (IOException e) {
- inputStream = connection.getErrorStream();
- }
- strWriter = new StringWriter();
- IOUtils.copy(new InputStreamReader(inputStream, "UTF-8"), strWriter);
- } finally {
- IOUtils.closeQuietly(inputStream);
- }
- return strWriter.toString();
+ return getResponse(new HttpGet(getBaseURL() + request));
}
/**
@@ -110,27 +102,11 @@ public class RestTestHarness extends BaseTestHarness {
* @return The response to the PUT request
*/
public String put(String request, String content) throws IOException {
- URL url = new URL(getBaseURL() + request);
- HttpURLConnection connection = (HttpURLConnection)url.openConnection();
- connection.setDoOutput(true);
- connection.setRequestMethod("PUT");
- OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
- out.write(content);
- out.close();
- InputStream inputStream = null;
- StringWriter stringWriter;
- try {
- try {
- inputStream = connection.getInputStream();
- } catch (IOException e) {
- inputStream = connection.getErrorStream();
- }
- stringWriter = new StringWriter();
- IOUtils.copy(new InputStreamReader(inputStream, "UTF-8"), stringWriter);
- } finally {
- IOUtils.closeQuietly(inputStream);
- }
- return stringWriter.toString();
+ HttpPut httpPut = new HttpPut(getBaseURL() + request);
+ httpPut.setEntity(new StringEntity(content, ContentType.create(
+ "application/json", "utf-8")));
+
+ return getResponse(httpPut);
}
/**
@@ -142,29 +118,11 @@ public class RestTestHarness extends BaseTestHarness {
* @return The response to the PUT request
*/
public String post(String request, String content) throws IOException {
- URL url = new URL(getBaseURL() + request);
- HttpURLConnection connection = (HttpURLConnection)url.openConnection();
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
-
- OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
- out.write(content);
- out.close();
- InputStream inputStream = null;
- StringWriter stringWriter;
- try {
- try {
- inputStream = connection.getInputStream();
- } catch (IOException e) {
- inputStream = connection.getErrorStream();
- }
- stringWriter = new StringWriter();
- IOUtils.copy(new InputStreamReader(inputStream, "UTF-8"), stringWriter);
- } finally {
- IOUtils.closeQuietly(inputStream);
- }
- return stringWriter.toString();
+ HttpPost httpPost = new HttpPost(getBaseURL() + request);
+ httpPost.setEntity(new StringEntity(content, ContentType.create(
+ "application/json", "utf-8")));
+
+ return getResponse(httpPost);
}
@@ -202,4 +160,14 @@ public class RestTestHarness extends BaseTestHarness {
throw new RuntimeException(e);
}
}
+
+ private String getResponse(HttpUriRequest request) throws IOException {
+ HttpEntity entity = null;
+ try {
+ entity = httpClient.execute(request).getEntity();
+ return EntityUtils.toString(entity, "UTF-8");
+ } finally {
+ EntityUtils.consumeQuietly(entity);
+ }
+ }
}