From 4618a5a0fee3cb5ecf32ef42960bd7f9bb81237c Mon Sep 17 00:00:00 2001
From: Steven Rowe
Date: Wed, 6 Mar 2013 04:50:33 +0000
Subject: [PATCH] SOLR-4503: Add REST API methods to get schema information:
fields, dynamicFields, fieldTypes, and copyFields. Restlet 2.1.1 is
integrated and is used to service these requests. Also fixes bugs in dynamic
copyField logic described in SOLR-3798. Also fixes a bug with proxied
SolrCloud requests (SOLR-4210) when using the GET method.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1453161 13f79535-47bb-0310-9956-ffa450edef68
---
dev-tools/maven/pom.xml.template | 11 +
.../maven/solr/core/src/java/pom.xml.template | 10 +
dev-tools/maven/solr/pom.xml.template | 7 +
.../util/AbstractAnalysisFactory.java | 11 +-
lucene/ivy-settings.xml | 2 +
solr/CHANGES.txt | 8 +
solr/NOTICE.txt | 12 +
solr/core/ivy.xml | 4 +-
.../solrj/embedded/JettySolrRunner.java | 27 +
.../java/org/apache/solr/core/SolrCore.java | 51 +-
.../solr/response/SolrQueryResponse.java | 14 +
.../apache/solr/rest/BaseFieldResource.java | 106 +++
.../solr/rest/BaseFieldTypeResource.java | 61 ++
.../apache/solr/rest/BaseSchemaResource.java | 215 ++++++
.../rest/CopyFieldCollectionResource.java | 160 +++++
.../solr/rest/DefaultSchemaResource.java | 57 ++
.../rest/DynamicFieldCollectionResource.java | 95 +++
.../solr/rest/DynamicFieldResource.java | 89 +++
.../solr/rest/FieldCollectionResource.java | 96 +++
.../org/apache/solr/rest/FieldResource.java | 92 +++
.../rest/FieldTypeCollectionResource.java | 135 ++++
.../apache/solr/rest/FieldTypeResource.java | 114 ++++
.../java/org/apache/solr/rest/GETable.java | 27 +
.../org/apache/solr/rest/SchemaRestApi.java | 84 +++
.../java/org/apache/solr/rest/package.html | 27 +
.../solr/schema/AbstractSubTypeFieldType.java | 2 +-
.../org/apache/solr/schema/CurrencyField.java | 2 +-
.../org/apache/solr/schema/FieldType.java | 255 +++++++-
.../solr/schema/FieldTypePluginLoader.java | 35 +-
.../org/apache/solr/schema/IndexSchema.java | 434 ++++++------
.../org/apache/solr/schema/SchemaField.java | 75 ++-
.../org/apache/solr/schema/TextField.java | 10 +-
.../apache/solr/servlet/ResponseUtils.java | 71 ++
.../solr/servlet/SolrDispatchFilter.java | 86 +--
.../processor/LogUpdateProcessorFactory.java | 35 +-
.../solr/collection1/conf/schema-rest.xml | 619 ++++++++++++++++++
.../handler/admin/LukeRequestHandlerTest.java | 3 +-
.../solr/rest/SchemaRestletTestBase.java | 37 ++
.../rest/TestCopyFieldCollectionResource.java | 140 ++++
.../TestDynamicFieldCollectionResource.java | 62 ++
.../solr/rest/TestDynamicFieldResource.java | 70 ++
.../rest/TestFieldCollectionResource.java | 62 ++
.../apache/solr/rest/TestFieldResource.java | 94 +++
.../rest/TestFieldTypeCollectionResource.java | 37 ++
.../solr/rest/TestFieldTypeResource.java | 89 +++
solr/licenses/org.restlet-2.1.1.jar.sha1 | 1 +
solr/licenses/org.restlet-LICENSE-ASL.txt | 201 ++++++
solr/licenses/org.restlet-NOTICE.txt | 2 +
.../org.restlet.ext.servlet-2.1.1.jar.sha1 | 1 +
.../org.restlet.ext.servlet-LICENSE-ASL.txt | 201 ++++++
.../org.restlet.ext.servlet-NOTICE.txt | 2 +
.../org/apache/solr/SolrJettyTestBase.java | 17 +-
.../org/apache/solr/util/BaseTestHarness.java | 269 ++++++++
.../solr/util/RESTfulServerProvider.java | 21 +
.../org/apache/solr/util/RestTestBase.java | 327 +++++++++
.../org/apache/solr/util/RestTestHarness.java | 120 ++++
.../org/apache/solr/util/TestHarness.java | 236 +------
solr/webapp/web/WEB-INF/web.xml | 14 +
58 files changed, 4556 insertions(+), 589 deletions(-)
create mode 100644 solr/core/src/java/org/apache/solr/rest/BaseFieldResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/BaseFieldTypeResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/BaseSchemaResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/CopyFieldCollectionResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/DefaultSchemaResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/DynamicFieldCollectionResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/DynamicFieldResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/FieldCollectionResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/FieldResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/FieldTypeCollectionResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/FieldTypeResource.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/GETable.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/SchemaRestApi.java
create mode 100644 solr/core/src/java/org/apache/solr/rest/package.html
create mode 100644 solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java
create mode 100755 solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
create mode 100644 solr/core/src/test/org/apache/solr/rest/SchemaRestletTestBase.java
create mode 100644 solr/core/src/test/org/apache/solr/rest/TestCopyFieldCollectionResource.java
create mode 100644 solr/core/src/test/org/apache/solr/rest/TestDynamicFieldCollectionResource.java
create mode 100644 solr/core/src/test/org/apache/solr/rest/TestDynamicFieldResource.java
create mode 100644 solr/core/src/test/org/apache/solr/rest/TestFieldCollectionResource.java
create mode 100644 solr/core/src/test/org/apache/solr/rest/TestFieldResource.java
create mode 100644 solr/core/src/test/org/apache/solr/rest/TestFieldTypeCollectionResource.java
create mode 100644 solr/core/src/test/org/apache/solr/rest/TestFieldTypeResource.java
create mode 100644 solr/licenses/org.restlet-2.1.1.jar.sha1
create mode 100644 solr/licenses/org.restlet-LICENSE-ASL.txt
create mode 100644 solr/licenses/org.restlet-NOTICE.txt
create mode 100644 solr/licenses/org.restlet.ext.servlet-2.1.1.jar.sha1
create mode 100644 solr/licenses/org.restlet.ext.servlet-LICENSE-ASL.txt
create mode 100644 solr/licenses/org.restlet.ext.servlet-NOTICE.txt
create mode 100644 solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
create mode 100644 solr/test-framework/src/java/org/apache/solr/util/RESTfulServerProvider.java
create mode 100644 solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
create mode 100644 solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
diff --git a/dev-tools/maven/pom.xml.template b/dev-tools/maven/pom.xml.template
index 3e32f341fbf..57a7e8f2ba7 100644
--- a/dev-tools/maven/pom.xml.template
+++ b/dev-tools/maven/pom.xml.template
@@ -49,6 +49,7 @@
1.34.2.32.1
+ 2.1.11
@@ -390,6 +391,16 @@
jetty-webapp${jetty.version}
+
+ org.restlet.jee
+ org.restlet
+ ${restlet.version}
+
+
+ org.restlet.jee
+ org.restlet.ext.servlet
+ ${restlet.version}
+ org.slf4jjcl-over-slf4j
diff --git a/dev-tools/maven/solr/core/src/java/pom.xml.template b/dev-tools/maven/solr/core/src/java/pom.xml.template
index 2becc355fa2..a7df88e1b8f 100644
--- a/dev-tools/maven/solr/core/src/java/pom.xml.template
+++ b/dev-tools/maven/solr/core/src/java/pom.xml.template
@@ -135,6 +135,16 @@
commons-fileuploadcommons-fileupload
+
+ org.restlet.jee
+ org.restlet
+ ${restlet.version}
+
+
+ org.restlet.jee
+ org.restlet.ext.servlet
+ ${restlet.version}
+ org.slf4jjcl-over-slf4j
diff --git a/dev-tools/maven/solr/pom.xml.template b/dev-tools/maven/solr/pom.xml.template
index 00d0238bd9d..06e16d7fa3d 100644
--- a/dev-tools/maven/solr/pom.xml.template
+++ b/dev-tools/maven/solr/pom.xml.template
@@ -76,6 +76,13 @@
2006
+
+
+ maven-restlet
+ Public online Restlet repository
+ http://maven.restlet.org
+
+ org.slf4j
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AbstractAnalysisFactory.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AbstractAnalysisFactory.java
index e43b5c5ef35..23831e202d1 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AbstractAnalysisFactory.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AbstractAnalysisFactory.java
@@ -29,6 +29,7 @@ import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@@ -49,6 +50,9 @@ import java.util.regex.PatternSyntaxException;
*/
public abstract class AbstractAnalysisFactory {
+ /** The original args, before init() processes them */
+ private Map originalArgs;
+
/** The init args */
protected Map args;
@@ -59,12 +63,17 @@ public abstract class AbstractAnalysisFactory {
* Initialize this factory via a set of key-value pairs.
*/
public void init(Map args) {
- this.args = args;
+ originalArgs = Collections.unmodifiableMap(args);
+ this.args = new HashMap(args);
}
public Map getArgs() {
return args;
}
+
+ public Map getOriginalArgs() {
+ return originalArgs;
+ }
/** this method can be called in the {@link org.apache.lucene.analysis.util.TokenizerFactory#create(java.io.Reader)}
* or {@link org.apache.lucene.analysis.util.TokenFilterFactory#create(org.apache.lucene.analysis.TokenStream)} methods,
diff --git a/lucene/ivy-settings.xml b/lucene/ivy-settings.xml
index 76faa7b6204..a78d6643480 100644
--- a/lucene/ivy-settings.xml
+++ b/lucene/ivy-settings.xml
@@ -30,6 +30,7 @@
+
@@ -48,6 +49,7 @@
+
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c8c2a5229d9..2ede7bc3dfc 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -105,6 +105,10 @@ New Features
"natural" value, converted to an optionally specified currency to
override the default for the field type.
(hossman)
+
+* SOLR-4503: Add REST API methods, via Restlet integration, for reading schema
+ elements, at /schema/fields/, /schema/dynamicfields/, /schema/fieldtypes/,
+ and /schema/copyfields/. (Steve Rowe)
Bug Fixes
----------------------
@@ -209,6 +213,10 @@ Bug Fixes
* SOLR-4518: Improved CurrencyField error messages when attempting to
use a Currency that is not supported by the current JVM. (hossman)
+
+* SOLR-3798: Fix copyField implementation in IndexSchema to handle
+ dynamic field references that aren't string-equal to the name of
+ the referenced dynamic field. (Steve Rowe)
Optimizations
----------------------
diff --git a/solr/NOTICE.txt b/solr/NOTICE.txt
index a5c50c03e5d..a8d5e66b6d2 100644
--- a/solr/NOTICE.txt
+++ b/solr/NOTICE.txt
@@ -503,3 +503,15 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=========================================================================
+== Restlet Notice ==
+=========================================================================
+
+Copyright (C) 2005-2013 Restlet S.A.S.
+
+Restlet is a registered trademark of Restlet S.A.S.
+
+This product contains software developed by the Restlet project.
+
+See http://www.restlet.org/
diff --git a/solr/core/ivy.xml b/solr/core/ivy.xml
index a82ebd00ece..159dcca1551 100644
--- a/solr/core/ivy.xml
+++ b/solr/core/ivy.xml
@@ -30,6 +30,8 @@
-
+
+
+
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 ef51db65ba6..20cc190be62 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
@@ -18,9 +18,13 @@
package org.apache.solr.client.solrj.embedded;
import java.io.IOException;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedList;
+import java.util.Map;
import java.util.Random;
+import java.util.SortedMap;
+import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicLong;
import java.net.URL;
@@ -39,8 +43,10 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.server.ssl.SslConnector;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
@@ -49,6 +55,7 @@ import org.eclipse.jetty.server.handler.GzipHandler;
import org.eclipse.jetty.server.session.HashSessionIdManager;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
@@ -87,6 +94,9 @@ public class JettySolrRunner {
private String coreNodeName;
+ /** Maps servlet holders (i.e. factories: class + init params) to path specs */
+ private SortedMap extraServlets = new TreeMap();
+
public static class DebugFilter implements Filter {
public int requestsToKeep = 10;
private AtomicLong nRequests = new AtomicLong();
@@ -151,6 +161,19 @@ public class JettySolrRunner {
this.schemaFilename = schemaFileName;
}
+ /**
+ * Constructor taking an ordered list of additional (servlet holder -> path spec) mappings
+ * to add to the servlet context
+ */
+ public JettySolrRunner(String solrHome, String context, int port,
+ String solrConfigFilename, String schemaFileName, boolean stopAtShutdown,
+ SortedMap extraServlets) {
+ if (null != extraServlets) { this.extraServlets.putAll(extraServlets); }
+ this.init(solrHome, context, port, stopAtShutdown);
+ this.solrConfigFilename = solrConfigFilename;
+ this.schemaFilename = schemaFileName;
+ }
+
private void init(String solrHome, String context, int port, boolean stopAtShutdown) {
this.context = context;
server = new Server(port);
@@ -285,6 +308,10 @@ public class JettySolrRunner {
// FilterHolder fh = new FilterHolder(filter);
debugFilter = root.addFilter(DebugFilter.class, "*", EnumSet.of(DispatcherType.REQUEST) );
dispatchFilter = root.addFilter(SolrDispatchFilter.class, "*", EnumSet.of(DispatcherType.REQUEST) );
+ for (ServletHolder servletHolder : extraServlets.keySet()) {
+ String pathSpec = extraServlets.get(servletHolder);
+ root.addServlet(servletHolder, pathSpec);
+ }
if (solrConfigFilename != null) System.clearProperty("solrconfig");
if (schemaFilename != null) System.clearProperty("schema");
System.clearProperty("solr.solr.home");
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index 4fed422e7a3..6827e769392 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -1781,7 +1781,6 @@ public final class SolrCore implements SolrInfoMBean {
}
}
-
public void execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp) {
if (handler==null) {
String msg = "Null Request Handler '" +
@@ -1791,45 +1790,40 @@ public final class SolrCore implements SolrInfoMBean {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, msg);
}
- // setup response header and handle request
- final NamedList
*
* @param fieldName may be an explicitly created field, or a name that
- * excercies a dynamic field.
+ * exercises a dynamic field.
* @return null if field is not defined.
* @see #getField(String)
* @see #getFieldTypeNoEx
@@ -1024,7 +1054,7 @@ public final class IndexSchema {
* the specified field name
*
* @param fieldName may be an explicitly created field, or a name that
- * excercies a dynamic field.
+ * exercises a dynamic field.
* @throws SolrException if no such field exists
* @see #getField(String)
* @see #getFieldTypeNoEx
@@ -1033,7 +1063,7 @@ public final class IndexSchema {
for (DynamicField df : dynamicFields) {
if (df.matches(fieldName)) return df.prototype.getType();
}
- throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"undefined field "+fieldName);
+ throw new SolrException(ErrorCode.BAD_REQUEST,"undefined field "+fieldName);
}
private FieldType dynFieldType(String fieldName) {
@@ -1062,6 +1092,11 @@ public final class IndexSchema {
}
}
}
+ for (DynamicCopy dynamicCopy : dynamicCopyFields) {
+ if (dynamicCopy.getDestFieldName().equals(destField)) {
+ sf.add(getField(dynamicCopy.getRegex()));
+ }
+ }
return sf.toArray(new SchemaField[sf.size()]);
}
@@ -1080,8 +1115,7 @@ public final class IndexSchema {
}
}
List fixedCopyFields = copyFieldsMap.get(sourceField);
- if (fixedCopyFields != null)
- {
+ if (null != fixedCopyFields) {
result.addAll(fixedCopyFields);
}
@@ -1093,17 +1127,7 @@ public final class IndexSchema {
*
* @since solr 1.3
*/
- public boolean isCopyFieldTarget( SchemaField f )
- {
+ public boolean isCopyFieldTarget( SchemaField f ) {
return copyFieldTargetCounts.containsKey( f );
}
-
- /**
- * Is the given field name a wildcard? I.e. does it begin or end with *?
- * @return true/false
- */
- private static boolean isWildCard(String name) {
- return name.startsWith("*") || name.endsWith("*");
- }
-
}
diff --git a/solr/core/src/java/org/apache/solr/schema/SchemaField.java b/solr/core/src/java/org/apache/solr/schema/SchemaField.java
index 173d6fa6e23..8d6c42105de 100644
--- a/solr/core/src/java/org/apache/solr/schema/SchemaField.java
+++ b/solr/core/src/java/org/apache/solr/schema/SchemaField.java
@@ -20,10 +20,14 @@ package org.apache.solr.schema;
import org.apache.solr.common.SolrException;
import org.apache.lucene.index.StorableField;
import org.apache.lucene.search.SortField;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.common.util.StrUtils;
import org.apache.solr.search.QParser;
import org.apache.solr.response.TextResponseWriter;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
@@ -34,11 +38,18 @@ import java.io.IOException;
*
*/
public final class SchemaField extends FieldProperties {
+ private static final String FIELD_NAME = "name";
+ private static final String TYPE_NAME = "type";
+ private static final String DEFAULT_VALUE = "default";
+
final String name;
final FieldType type;
final int properties;
final String defaultValue;
boolean required = false; // this can't be final since it may be changed dynamically
+
+ /** Declared field property overrides */
+ Map args = Collections.emptyMap();
/** Create a new SchemaField with the given name and type,
@@ -52,7 +63,8 @@ public final class SchemaField extends FieldProperties {
* of the properties of the prototype except the field name.
*/
public SchemaField(SchemaField prototype, String name) {
- this(name, prototype.type, prototype.properties, prototype.defaultValue );
+ this(name, prototype.type, prototype.properties, prototype.defaultValue);
+ args = prototype.args;
}
/** Create a new SchemaField with the given name and type,
@@ -186,10 +198,12 @@ public final class SchemaField extends FieldProperties {
static SchemaField create(String name, FieldType ft, Map props) {
String defaultValue = null;
- if( props.containsKey( "default" ) ) {
- defaultValue = props.get( "default" );
+ if (props.containsKey(DEFAULT_VALUE)) {
+ defaultValue = props.get(DEFAULT_VALUE);
}
- return new SchemaField(name, ft, calcProps(name, ft, props), defaultValue );
+ SchemaField field = new SchemaField(name, ft, calcProps(name, ft, props), defaultValue);
+ field.args = new HashMap(props);
+ return field;
}
/**
@@ -285,10 +299,51 @@ public final class SchemaField extends FieldProperties {
public boolean equals(Object obj) {
return(obj instanceof SchemaField) && name.equals(((SchemaField)obj).name);
}
+
+ /**
+ * Get a map of property name -> value for this field. If showDefaults is true,
+ * include default properties (those inherited from the declared property type and
+ * not overridden in the field declaration).
+ */
+ public SimpleOrderedMap getNamedPropertyValues(boolean showDefaults) {
+ SimpleOrderedMap properties = new SimpleOrderedMap();
+ properties.add(FIELD_NAME, getName());
+ properties.add(TYPE_NAME, getType().getTypeName());
+ if (showDefaults) {
+ if (null != getDefaultValue()) {
+ properties.add(DEFAULT_VALUE, getDefaultValue());
+ }
+ properties.add(getPropertyName(INDEXED), indexed());
+ properties.add(getPropertyName(STORED), stored());
+ properties.add(getPropertyName(DOC_VALUES), hasDocValues());
+ properties.add(getPropertyName(STORE_TERMVECTORS), storeTermVector());
+ properties.add(getPropertyName(STORE_TERMPOSITIONS), storeTermPositions());
+ properties.add(getPropertyName(STORE_TERMOFFSETS), storeTermOffsets());
+ properties.add(getPropertyName(OMIT_NORMS), omitNorms());
+ properties.add(getPropertyName(OMIT_TF_POSITIONS), omitTermFreqAndPositions());
+ properties.add(getPropertyName(OMIT_POSITIONS), omitPositions());
+ properties.add(getPropertyName(STORE_OFFSETS), storeOffsetsWithPositions());
+ properties.add(getPropertyName(MULTIVALUED), multiValued());
+ if (sortMissingFirst()) {
+ properties.add(getPropertyName(SORT_MISSING_FIRST), sortMissingFirst());
+ } else if (sortMissingLast()) {
+ properties.add(getPropertyName(SORT_MISSING_LAST), sortMissingLast());
+ }
+ properties.add(getPropertyName(REQUIRED), isRequired());
+ properties.add(getPropertyName(TOKENIZED), isTokenized());
+ // The BINARY property is always false
+ // properties.add(getPropertyName(BINARY), isBinary());
+ } else {
+ for (Map.Entry arg : args.entrySet()) {
+ String key = arg.getKey();
+ String value = arg.getValue();
+ if (key.equals(DEFAULT_VALUE)) {
+ properties.add(key, value);
+ } else {
+ properties.add(key, StrUtils.parseBool(value, false));
+ }
+ }
+ }
+ return properties;
+ }
}
-
-
-
-
-
-
diff --git a/solr/core/src/java/org/apache/solr/schema/TextField.java b/solr/core/src/java/org/apache/solr/schema/TextField.java
index 39e786bbf80..6e3c73f2cce 100644
--- a/solr/core/src/java/org/apache/solr/schema/TextField.java
+++ b/solr/core/src/java/org/apache/solr/schema/TextField.java
@@ -19,8 +19,6 @@ package org.apache.solr.schema;
import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
import org.apache.lucene.search.*;
-import org.apache.lucene.index.GeneralField;
-import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.StorableField;
import org.apache.lucene.index.Term;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
@@ -58,6 +56,7 @@ public class TextField extends FieldType {
* @see #setMultiTermAnalyzer
*/
protected Analyzer multiTermAnalyzer=null;
+ private boolean isExplicitMultiTermAnalyzer = false;
@Override
protected void init(IndexSchema schema, Map args) {
@@ -331,4 +330,11 @@ public class TextField extends FieldType {
}
+ public void setIsExplicitMultiTermAnalyzer(boolean isExplicitMultiTermAnalyzer) {
+ this.isExplicitMultiTermAnalyzer = isExplicitMultiTermAnalyzer;
+ }
+
+ public boolean isExplicitMultiTermAnalyzer() {
+ return isExplicitMultiTermAnalyzer;
+ }
}
diff --git a/solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java b/solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java
new file mode 100644
index 00000000000..8422691db01
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/servlet/ResponseUtils.java
@@ -0,0 +1,71 @@
+package org.apache.solr.servlet;
+/*
+ * 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.
+ */
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.NamedList;
+import org.slf4j.Logger;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * Response helper methods.
+ */
+public class ResponseUtils {
+ private ResponseUtils() {}
+
+ /**
+ * Adds the given Throwable's message to the given NamedList.
+ *
+ * If the response code is not a regular code, the Throwable's
+ * stack trace is both logged and added to the given NamedList.
+ *
+ * Status codes less than 100 are adjusted to be 500.
+ */
+ public static int getErrorInfo(Throwable ex, NamedList info, Logger log) {
+ int code = 500;
+ if (ex instanceof SolrException) {
+ code = ((SolrException)ex).code();
+ }
+
+ for (Throwable th = ex; th != null; th = th.getCause()) {
+ String msg = th.getMessage();
+ if (msg != null) {
+ info.add("msg", msg);
+ break;
+ }
+ }
+
+ // For any regular code, don't include the stack trace
+ if (code == 500 || code < 100) {
+ StringWriter sw = new StringWriter();
+ ex.printStackTrace(new PrintWriter(sw));
+ SolrException.log(log, null, ex);
+ info.add("trace", sw.toString());
+
+ // non standard codes have undefined results with various servers
+ if (code < 100) {
+ log.warn("invalid return code: " + code);
+ code = 500;
+ }
+ }
+
+ info.add("code", code);
+ return code;
+ }
+}
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
index c927de3e127..5715d923111 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
@@ -23,8 +23,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -248,6 +246,20 @@ public class SolrDispatchFilter implements Filter
parsers.put(config, parser );
}
+ // Handle /schema/* paths via Restlet
+ if( path.startsWith("/schema") ) {
+ solrReq = parser.parse(core, path, req);
+ SolrRequestInfo.setRequestInfo(new SolrRequestInfo(solrReq, new SolrQueryResponse()));
+ if( path.equals(req.getServletPath()) ) {
+ // avoid endless loop - pass through to Restlet via webapp
+ chain.doFilter(request, response);
+ } else {
+ // forward rewritten URI (without path prefix and core/collection name) to Restlet
+ req.getRequestDispatcher(path).forward(request, response);
+ }
+ return;
+ }
+
// Determine the handler from the url path if not set
// (we might already have selected the cores handler)
if( handler == null && path.length() > 1 ) { // don't match "" or "/" as valid path
@@ -353,13 +365,17 @@ public class SolrDispatchFilter implements Filter
try {
con.connect();
- InputStream is = req.getInputStream();
- OutputStream os = con.getOutputStream();
- try {
- IOUtils.copyLarge(is, os);
- } finally {
- IOUtils.closeQuietly(os);
- IOUtils.closeQuietly(is); // TODO: I thought we weren't supposed to explicitly close servlet streams
+ InputStream is;
+ OutputStream os;
+ if ("POST".equals(req.getMethod())) {
+ is = req.getInputStream();
+ os = con.getOutputStream(); // side effect: method is switched to POST
+ try {
+ IOUtils.copyLarge(is, os);
+ } finally {
+ IOUtils.closeQuietly(os);
+ IOUtils.closeQuietly(is); // TODO: I thought we weren't supposed to explicitly close servlet streams
+ }
}
resp.setStatus(con.getResponseCode());
@@ -491,19 +507,11 @@ public class SolrDispatchFilter implements Filter
private void handleAdminRequest(HttpServletRequest req, ServletResponse response, SolrRequestHandler handler,
SolrQueryRequest solrReq) throws IOException {
SolrQueryResponse solrResp = new SolrQueryResponse();
- final NamedList responseHeader = new SimpleOrderedMap();
- solrResp.add("responseHeader", responseHeader);
- NamedList toLog = solrResp.getToLog();
- toLog.add("webapp", req.getContextPath());
- toLog.add("path", solrReq.getContext().get("path"));
- toLog.add("params", "{" + solrReq.getParamString() + "}");
+ SolrCore.preDecorateResponse(solrReq, solrResp);
handler.handleRequest(solrReq, solrResp);
- SolrCore.setResponseHeaderValues(handler, solrReq, solrResp);
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < toLog.size(); i++) {
- String name = toLog.getName(i);
- Object val = toLog.getVal(i);
- sb.append(name).append("=").append(val).append(" ");
+ SolrCore.postDecorateResponse(handler, solrReq, solrResp);
+ if (log.isInfoEnabled() && solrResp.getToLog().size() > 0) {
+ log.info(solrResp.getToLogAsString("[admin] "));
}
QueryResponseWriter respWriter = SolrCore.DEFAULT_RESPONSE_WRITERS.get(solrReq.getParams().get(CommonParams.WT));
if (respWriter == null) respWriter = SolrCore.DEFAULT_RESPONSE_WRITERS.get("standard");
@@ -521,7 +529,7 @@ public class SolrDispatchFilter implements Filter
if (solrRsp.getException() != null) {
NamedList info = new SimpleOrderedMap();
- int code = getErrorInfo(solrRsp.getException(),info);
+ int code = ResponseUtils.getErrorInfo(solrRsp.getException(), info, log);
solrRsp.add("error", info);
((HttpServletResponse) response).setStatus(code);
}
@@ -543,38 +551,6 @@ public class SolrDispatchFilter implements Filter
//else http HEAD request, nothing to write out, waited this long just to get ContentType
}
- protected int getErrorInfo(Throwable ex, NamedList info) {
- int code=500;
- if( ex instanceof SolrException ) {
- code = ((SolrException)ex).code();
- }
-
- String msg = null;
- for (Throwable th = ex; th != null; th = th.getCause()) {
- msg = th.getMessage();
- if (msg != null) break;
- }
- if(msg != null) {
- info.add("msg", msg);
- }
-
- // For any regular code, don't include the stack trace
- if( code == 500 || code < 100 ) {
- StringWriter sw = new StringWriter();
- ex.printStackTrace(new PrintWriter(sw));
- SolrException.log(log, null, ex);
- info.add("trace", sw.toString());
-
- // non standard codes have undefined results with various servers
- if( code < 100 ) {
- log.warn( "invalid return code: "+code );
- code = 500;
- }
- }
- info.add("code", new Integer(code));
- return code;
- }
-
protected void execute( HttpServletRequest req, SolrRequestHandler handler, SolrQueryRequest sreq, SolrQueryResponse rsp) {
// a custom filter could add more stuff to the request before passing it on.
// for example: sreq.getContext().put( "HttpServletRequest", req );
@@ -615,7 +591,7 @@ public class SolrDispatchFilter implements Filter
}
catch( Throwable t ) { // This error really does not matter
SimpleOrderedMap info = new SimpleOrderedMap();
- int code=getErrorInfo(ex, info);
+ int code = ResponseUtils.getErrorInfo(ex, info, log);
response.sendError( code, info.toString() );
}
}
diff --git a/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
index 7ca1bac8af1..4194df61ed2 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
@@ -179,35 +179,24 @@ class LogUpdateProcessor extends UpdateRequestProcessor {
if (next != null) next.finish();
// LOG A SUMMARY WHEN ALL DONE (INFO LEVEL)
-
+ if (log.isInfoEnabled()) {
+ StringBuilder sb = new StringBuilder(rsp.getToLogAsString(req.getCore().getLogId()));
- NamedList stdLog = rsp.getToLog();
+ rsp.getToLog().clear(); // make it so SolrCore.exec won't log this again
- StringBuilder sb = new StringBuilder(req.getCore().getLogId());
-
- for (int i=0; i maxNumToLog) {
+ adds.add("... (" + numAdds + " adds)");
}
- sb.append(val).append(' ');
- }
+ if (deletes != null && numDeletes > maxNumToLog) {
+ deletes.add("... (" + numDeletes + " deletes)");
+ }
+ long elapsed = rsp.getEndTime() - req.getStartTime();
- stdLog.clear(); // make it so SolrCore.exec won't log this again
-
- // if id lists were truncated, show how many more there were
- if (adds != null && numAdds > maxNumToLog) {
- adds.add("... (" + numAdds + " adds)");
+ sb.append(toLog).append(" 0 ").append(elapsed);
+ log.info(sb.toString());
}
- if (deletes != null && numDeletes > maxNumToLog) {
- deletes.add("... (" + numDeletes + " deletes)");
- }
- long elapsed = rsp.getEndTime() - req.getStartTime();
-
- sb.append(toLog).append(" 0 ").append(elapsed);
- log.info(sb.toString());
}
}
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml b/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
new file mode 100755
index 00000000000..cec4f612b05
--- /dev/null
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-rest.xml
@@ -0,0 +1,619 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text
+ id
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java
index ff7a1427d47..5b9b7fe3b7b 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/LukeRequestHandlerTest.java
@@ -191,8 +191,7 @@ public class LukeRequestHandlerTest extends AbstractSolrTestCase {
field("text") + "/arr[@name='copySources']/str[.='subject']",
field("title") + "/arr[@name='copyDests']/str[.='text']",
field("title") + "/arr[@name='copyDests']/str[.='title_stemmed']",
- // :TODO: SOLR-3798
- //dynfield("bar_copydest_*") + "/arr[@name='copySource']/str[.='foo_copysource_*']",
+ dynfield("bar_copydest_*") + "/arr[@name='copySources']/str[.='foo_copysource_*']",
dynfield("foo_copysource_*") + "/arr[@name='copyDests']/str[.='bar_copydest_*']");
assertEquals(xml, null, r);
}
diff --git a/solr/core/src/test/org/apache/solr/rest/SchemaRestletTestBase.java b/solr/core/src/test/org/apache/solr/rest/SchemaRestletTestBase.java
new file mode 100644
index 00000000000..d03feb6ec04
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/rest/SchemaRestletTestBase.java
@@ -0,0 +1,37 @@
+package org.apache.solr.rest;
+/*
+ * 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.
+ */
+
+import org.apache.solr.util.RestTestBase;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.BeforeClass;
+import org.restlet.ext.servlet.ServerServlet;
+
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+abstract public class SchemaRestletTestBase extends RestTestBase {
+ @BeforeClass
+ public static void init() throws Exception {
+ final SortedMap extraServlets = new TreeMap();
+ final ServletHolder schemaRestApi = new ServletHolder("SchemaRestApi", ServerServlet.class);
+ schemaRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SchemaRestApi");
+ extraServlets.put(schemaRestApi, "/schema/*");
+
+ createJettyAndHarness(TEST_HOME(), "solrconfig.xml", "schema-rest.xml", "/solr", true, extraServlets);
+ }
+}
diff --git a/solr/core/src/test/org/apache/solr/rest/TestCopyFieldCollectionResource.java b/solr/core/src/test/org/apache/solr/rest/TestCopyFieldCollectionResource.java
new file mode 100644
index 00000000000..2c13c541d2a
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/rest/TestCopyFieldCollectionResource.java
@@ -0,0 +1,140 @@
+package org.apache.solr.rest;
+/*
+ * 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.
+ */
+
+import org.junit.Test;
+
+public class TestCopyFieldCollectionResource extends SchemaRestletTestBase {
+ @Test
+ public void testGetAllCopyFields() throws Exception {
+ assertQ("/schema/copyfields?indent=on&wt=xml",
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='title']"
+ +" and str[@name='dest'][.='title_stemmed']"
+ +" and int[@name='maxChars'][.='200']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='title']"
+ +" and str[@name='dest'][.='dest_sub_no_ast_s']"
+ +" and str[@name='destDynamicBase'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_i']"
+ +" and str[@name='dest'][.='title']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_i']"
+ +" and str[@name='dest'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_i']"
+ +" and str[@name='dest'][.='*_dest_sub_s']"
+ +" and str[@name='destDynamicBase'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_i']"
+ +" and str[@name='dest'][.='dest_sub_no_ast_s']"
+ +" and str[@name='destDynamicBase'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_src_sub_i']"
+ +" and str[@name='sourceDynamicBase'][.='*_i']"
+ +" and str[@name='dest'][.='title']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_src_sub_i']"
+ +" and str[@name='sourceDynamicBase'][.='*_i']"
+ +" and str[@name='dest'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_src_sub_i']"
+ +" and str[@name='sourceDynamicBase'][.='*_i']"
+ +" and str[@name='dest'][.='*_dest_sub_s']"
+ +" and str[@name='destDynamicBase'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_src_sub_i']"
+ +" and str[@name='sourceDynamicBase'][.='*_i']"
+ +" and str[@name='dest'][.='dest_sub_no_ast_s']"
+ +" and str[@name='destDynamicBase'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='src_sub_no_ast_i']"
+ +" and str[@name='sourceDynamicBase'][.='*_i']"
+ +" and str[@name='dest'][.='title']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='src_sub_no_ast_i']"
+ +" and str[@name='sourceDynamicBase'][.='*_i']"
+ +" and str[@name='dest'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='src_sub_no_ast_i']"
+ +" and str[@name='sourceDynamicBase'][.='*_i']"
+ +" and str[@name='dest'][.='*_dest_sub_s']"
+ +" and str[@name='destDynamicBase'][.='*_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='src_sub_no_ast_i']"
+ +" and str[@name='sourceDynamicBase'][.='*_i']"
+ +" and str[@name='dest'][.='dest_sub_no_ast_s']"
+ +" and str[@name='destDynamicBase'][.='*_s']]");
+ }
+
+ @Test
+ public void testJsonGetAllCopyFields() throws Exception {
+ assertJQ("/schema/copyfields?indent=on&wt=json",
+ "/copyfields/[6]=={'source':'title','dest':'dest_sub_no_ast_s','destDynamicBase':'*_s'}",
+
+ "/copyfields/[7]=={'source':'*_i','dest':'title'}",
+ "/copyfields/[8]=={'source':'*_i','dest':'*_s'}",
+ "/copyfields/[9]=={'source':'*_i','dest':'*_dest_sub_s','destDynamicBase':'*_s'}",
+ "/copyfields/[10]=={'source':'*_i','dest':'dest_sub_no_ast_s','destDynamicBase':'*_s'}",
+
+ "/copyfields/[11]=={'source':'*_src_sub_i','sourceDynamicBase':'*_i','dest':'title'}",
+ "/copyfields/[12]=={'source':'*_src_sub_i','sourceDynamicBase':'*_i','dest':'*_s'}",
+ "/copyfields/[13]=={'source':'*_src_sub_i','sourceDynamicBase':'*_i','dest':'*_dest_sub_s','destDynamicBase':'*_s'}",
+ "/copyfields/[14]=={'source':'*_src_sub_i','sourceDynamicBase':'*_i','dest':'dest_sub_no_ast_s','destDynamicBase':'*_s'}",
+
+ "/copyfields/[15]=={'source':'src_sub_no_ast_i','sourceDynamicBase':'*_i','dest':'title'}",
+ "/copyfields/[16]=={'source':'src_sub_no_ast_i','sourceDynamicBase':'*_i','dest':'*_s'}",
+ "/copyfields/[17]=={'source':'src_sub_no_ast_i','sourceDynamicBase':'*_i','dest':'*_dest_sub_s','destDynamicBase':'*_s'}",
+ "/copyfields/[18]=={'source':'src_sub_no_ast_i','sourceDynamicBase':'*_i','dest':'dest_sub_no_ast_s','destDynamicBase':'*_s'}");
+
+ }
+
+ @Test
+ public void testRestrictSource() throws Exception {
+ assertQ("/schema/copyfields/?indent=on&wt=xml&source.fl=title,*_i,*_src_sub_i,src_sub_no_ast_i",
+ "count(/response/arr[@name='copyfields']/lst) = 16", // 4 + 4 + 4 + 4
+ "count(/response/arr[@name='copyfields']/lst/str[@name='source'][.='title']) = 4",
+ "count(/response/arr[@name='copyfields']/lst/str[@name='source'][.='*_i']) = 4",
+ "count(/response/arr[@name='copyfields']/lst/str[@name='source'][.='*_src_sub_i']) = 4",
+ "count(/response/arr[@name='copyfields']/lst/str[@name='source'][.='src_sub_no_ast_i']) = 4");
+ }
+
+ @Test
+ public void testRestrictDest() throws Exception {
+ assertQ("/schema/copyfields/?indent=on&wt=xml&dest.fl=title,*_s,*_dest_sub_s,dest_sub_no_ast_s",
+ "count(/response/arr[@name='copyfields']/lst) = 13", // 3 + 3 + 3 + 4
+ "count(/response/arr[@name='copyfields']/lst/str[@name='dest'][.='title']) = 3",
+ "count(/response/arr[@name='copyfields']/lst/str[@name='dest'][.='*_s']) = 3",
+ "count(/response/arr[@name='copyfields']/lst/str[@name='dest'][.='*_dest_sub_s']) = 3",
+ "count(/response/arr[@name='copyfields']/lst/str[@name='dest'][.='dest_sub_no_ast_s']) = 4");
+ }
+
+ @Test
+ public void testRestrictSourceAndDest() throws Exception {
+ assertQ("/schema/copyfields/?indent=on&wt=xml&source.fl=title,*_i&dest.fl=title,dest_sub_no_ast_s",
+ "count(/response/arr[@name='copyfields']/lst) = 3",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='title']"
+ +" and str[@name='dest'][.='dest_sub_no_ast_s']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_i']"
+ +" and str[@name='dest'][.='title']]",
+
+ "/response/arr[@name='copyfields']/lst[ str[@name='source'][.='*_i']"
+ +" and str[@name='dest'][.='dest_sub_no_ast_s']]");
+ }
+}
diff --git a/solr/core/src/test/org/apache/solr/rest/TestDynamicFieldCollectionResource.java b/solr/core/src/test/org/apache/solr/rest/TestDynamicFieldCollectionResource.java
new file mode 100644
index 00000000000..8bcb2157b45
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/rest/TestDynamicFieldCollectionResource.java
@@ -0,0 +1,62 @@
+package org.apache.solr.rest;
+/*
+ * 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.
+ */
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class TestDynamicFieldCollectionResource extends SchemaRestletTestBase {
+ @Test
+ public void testGetAllDynamicFields() throws Exception {
+ assertQ("/schema/dynamicfields?indent=on&wt=xml",
+ "(/response/arr[@name='dynamicfields']/lst/str[@name='name'])[1] = '*_coordinate'",
+ "(/response/arr[@name='dynamicfields']/lst/str[@name='name'])[2] = 'ignored_*'",
+ "(/response/arr[@name='dynamicfields']/lst/str[@name='name'])[3] = '*_mfacet'",
+ "count(//copySources/str)=count(//copyDests/str)");
+ }
+
+ @Test
+ public void testGetTwoDynamicFields() throws IOException {
+ assertQ("/schema/dynamicfields?indent=on&wt=xml&fl=*_i,*_s",
+ "count(/response/arr[@name='dynamicfields']/lst/str[@name='name']) = 2",
+ "(/response/arr[@name='dynamicfields']/lst/str[@name='name'])[1] = '*_i'",
+ "(/response/arr[@name='dynamicfields']/lst/str[@name='name'])[2] = '*_s'");
+ }
+
+ @Test
+ public void testNotFoundDynamicFields() throws IOException {
+ assertQ("/schema/dynamicfields?indent=on&wt=xml&fl=*_not_in_there,this_one_isnt_either_*",
+ "count(/response/arr[@name='dynamicfields']) = 1",
+ "count(/response/arr[@name='dynamicfields']/lst/str[@name='name']) = 0");
+ }
+
+ @Test
+ public void testJsonGetAllDynamicFields() throws Exception {
+ assertJQ("/schema/dynamicfields?indent=on",
+ "/dynamicfields/[0]/name=='*_coordinate'",
+ "/dynamicfields/[1]/name=='ignored_*'",
+ "/dynamicfields/[2]/name=='*_mfacet'");
+ }
+
+ @Test
+ public void testJsonGetTwoDynamicFields() throws Exception {
+ assertJQ("/schema/dynamicfields?indent=on&fl=*_i,*_s&wt=xml", // assertJQ will fix the wt param to be json
+ "/dynamicfields/[0]/name=='*_i'",
+ "/dynamicfields/[1]/name=='*_s'");
+ }
+}
diff --git a/solr/core/src/test/org/apache/solr/rest/TestDynamicFieldResource.java b/solr/core/src/test/org/apache/solr/rest/TestDynamicFieldResource.java
new file mode 100644
index 00000000000..bc0694fc5cc
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/rest/TestDynamicFieldResource.java
@@ -0,0 +1,70 @@
+package org.apache.solr.rest;
+/*
+ * 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.
+ */
+
+import org.junit.Test;
+
+public class TestDynamicFieldResource extends SchemaRestletTestBase {
+ @Test
+ public void testGetDynamicField() throws Exception {
+ assertQ("/schema/dynamicfields/*_i?indent=on&wt=xml&showDefaults=on",
+ "count(/response/lst[@name='dynamicfield']) = 1",
+ "/response/lst[@name='dynamicfield']/str[@name='name'] = '*_i'",
+ "/response/lst[@name='dynamicfield']/str[@name='type'] = 'int'",
+ "/response/lst[@name='dynamicfield']/bool[@name='indexed'] = 'true'",
+ "/response/lst[@name='dynamicfield']/bool[@name='stored'] = 'true'",
+ "/response/lst[@name='dynamicfield']/bool[@name='docValues'] = 'false'",
+ "/response/lst[@name='dynamicfield']/bool[@name='termVectors'] = 'false'",
+ "/response/lst[@name='dynamicfield']/bool[@name='termPositions'] = 'false'",
+ "/response/lst[@name='dynamicfield']/bool[@name='termOffsets'] = 'false'",
+ "/response/lst[@name='dynamicfield']/bool[@name='omitNorms'] = 'true'",
+ "/response/lst[@name='dynamicfield']/bool[@name='omitTermFreqAndPositions'] = 'true'",
+ "/response/lst[@name='dynamicfield']/bool[@name='omitPositions'] = 'false'",
+ "/response/lst[@name='dynamicfield']/bool[@name='storeOffsetsWithPositions'] = 'false'",
+ "/response/lst[@name='dynamicfield']/bool[@name='multiValued'] = 'false'",
+ "/response/lst[@name='dynamicfield']/bool[@name='required'] = 'false'",
+ "/response/lst[@name='dynamicfield']/bool[@name='tokenized'] = 'false'");
+ }
+
+ @Test
+ public void testGetNotFoundDynamicField() throws Exception {
+ assertQ("/schema/dynamicfields/*not_in_there?indent=on&wt=xml",
+ "count(/response/lst[@name='dynamicfield']) = 0",
+ "/response/lst[@name='responseHeader']/int[@name='status'] = '404'",
+ "/response/lst[@name='error']/int[@name='code'] = '404'");
+ }
+
+ @Test
+ public void testJsonGetDynamicField() throws Exception {
+ assertJQ("/schema/dynamicfields/*_i?indent=on&showDefaults=on",
+ "/dynamicfield/name=='*_i'",
+ "/dynamicfield/type=='int'",
+ "/dynamicfield/indexed==true",
+ "/dynamicfield/stored==true",
+ "/dynamicfield/docValues==false",
+ "/dynamicfield/termVectors==false",
+ "/dynamicfield/termPositions==false",
+ "/dynamicfield/termOffsets==false",
+ "/dynamicfield/omitNorms==true",
+ "/dynamicfield/omitTermFreqAndPositions==true",
+ "/dynamicfield/omitPositions==false",
+ "/dynamicfield/storeOffsetsWithPositions==false",
+ "/dynamicfield/multiValued==false",
+ "/dynamicfield/required==false",
+ "/dynamicfield/tokenized==false");
+ }
+}
diff --git a/solr/core/src/test/org/apache/solr/rest/TestFieldCollectionResource.java b/solr/core/src/test/org/apache/solr/rest/TestFieldCollectionResource.java
new file mode 100644
index 00000000000..40c256182e2
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/rest/TestFieldCollectionResource.java
@@ -0,0 +1,62 @@
+package org.apache.solr.rest;
+/*
+ * 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.
+ */
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class TestFieldCollectionResource extends SchemaRestletTestBase {
+ @Test
+ public void testGetAllFields() throws Exception {
+ assertQ("/schema/fields?indent=on&wt=xml",
+ "(/response/arr[@name='fields']/lst/str[@name='name'])[1] = 'custstopfilt'",
+ "(/response/arr[@name='fields']/lst/str[@name='name'])[2] = 'lowerfilt'",
+ "(/response/arr[@name='fields']/lst/str[@name='name'])[3] = 'test_basictv'",
+ "count(//copySources/str) = count(//copyDests/str)");
+ }
+
+ @Test
+ public void testGetTwoFields() throws IOException {
+ assertQ("/schema/fields?indent=on&wt=xml&fl=id,_version_",
+ "count(/response/arr[@name='fields']/lst/str[@name='name']) = 2",
+ "(/response/arr[@name='fields']/lst/str[@name='name'])[1] = 'id'",
+ "(/response/arr[@name='fields']/lst/str[@name='name'])[2] = '_version_'");
+ }
+
+ @Test
+ public void testNotFoundFields() throws IOException {
+ assertQ("/schema/fields?indent=on&wt=xml&fl=not_in_there,this_one_either",
+ "count(/response/arr[@name='fields']) = 1",
+ "count(/response/arr[@name='fields']/lst/str[@name='name']) = 0");
+ }
+
+ @Test
+ public void testJsonGetAllFields() throws Exception {
+ assertJQ("/schema/fields?indent=on",
+ "/fields/[0]/name=='custstopfilt'",
+ "/fields/[1]/name=='lowerfilt'",
+ "/fields/[2]/name=='test_basictv'");
+ }
+
+ @Test
+ public void testJsonGetTwoFields() throws Exception {
+ assertJQ("/schema/fields?indent=on&fl=id,_version_&wt=xml", // assertJQ should fix the wt param to be json
+ "/fields/[0]/name=='id'",
+ "/fields/[1]/name=='_version_'");
+ }
+}
diff --git a/solr/core/src/test/org/apache/solr/rest/TestFieldResource.java b/solr/core/src/test/org/apache/solr/rest/TestFieldResource.java
new file mode 100644
index 00000000000..d55b644fb40
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/rest/TestFieldResource.java
@@ -0,0 +1,94 @@
+package org.apache.solr.rest;
+/*
+ * 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.
+ */
+
+import org.junit.Test;
+
+public class TestFieldResource extends SchemaRestletTestBase {
+ @Test
+ public void testGetField() throws Exception {
+ assertQ("/schema/fields/test_postv?indent=on&wt=xml&showDefaults=true",
+ "count(/response/lst[@name='field']) = 1",
+ "count(/response/lst[@name='field']/*) = 15",
+ "/response/lst[@name='field']/str[@name='name'] = 'test_postv'",
+ "/response/lst[@name='field']/str[@name='type'] = 'text'",
+ "/response/lst[@name='field']/bool[@name='indexed'] = 'true'",
+ "/response/lst[@name='field']/bool[@name='stored'] = 'true'",
+ "/response/lst[@name='field']/bool[@name='docValues'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='termVectors'] = 'true'",
+ "/response/lst[@name='field']/bool[@name='termPositions'] = 'true'",
+ "/response/lst[@name='field']/bool[@name='termOffsets'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='omitNorms'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='omitTermFreqAndPositions'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='omitPositions'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='storeOffsetsWithPositions'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='multiValued'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='required'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='tokenized'] = 'true'");
+ }
+
+ @Test
+ public void testGetNotFoundField() throws Exception {
+ assertQ("/schema/fields/not_in_there?indent=on&wt=xml",
+ "count(/response/lst[@name='field']) = 0",
+ "/response/lst[@name='responseHeader']/int[@name='status'] = '404'",
+ "/response/lst[@name='error']/int[@name='code'] = '404'");
+ }
+
+ @Test
+ public void testJsonGetField() throws Exception {
+ assertJQ("/schema/fields/test_postv?indent=on&showDefaults=true",
+ "/field/name=='test_postv'",
+ "/field/type=='text'",
+ "/field/indexed==true",
+ "/field/stored==true",
+ "/field/docValues==false",
+ "/field/termVectors==true",
+ "/field/termPositions==true",
+ "/field/termOffsets==false",
+ "/field/omitNorms==false",
+ "/field/omitTermFreqAndPositions==false",
+ "/field/omitPositions==false",
+ "/field/storeOffsetsWithPositions==false",
+ "/field/multiValued==false",
+ "/field/required==false",
+ "/field/tokenized==true");
+ }
+
+ @Test
+ public void testGetFieldIncludeDynamic() throws Exception {
+ assertQ("/schema/fields/some_crazy_name_i?indent=on&wt=xml&includeDynamic=true",
+ "/response/lst[@name='field']/str[@name='name'] = 'some_crazy_name_i'",
+ "/response/lst[@name='field']/str[@name='dynamicBase'] = '*_i'");
+ }
+
+ @Test
+ public void testGetFieldDontShowDefaults() throws Exception {
+ String[] tests = {
+ "count(/response/lst[@name='field']) = 1",
+ "count(/response/lst[@name='field']/*) = 7",
+ "/response/lst[@name='field']/str[@name='name'] = 'id'",
+ "/response/lst[@name='field']/str[@name='type'] = 'string'",
+ "/response/lst[@name='field']/bool[@name='indexed'] = 'true'",
+ "/response/lst[@name='field']/bool[@name='stored'] = 'true'",
+ "/response/lst[@name='field']/bool[@name='multiValued'] = 'false'",
+ "/response/lst[@name='field']/bool[@name='required'] = 'true'"
+ };
+ assertQ("/schema/fields/id?indent=on&wt=xml", tests);
+ assertQ("/schema/fields/id?indent=on&wt=xml&showDefaults=false", tests);
+ }
+}
diff --git a/solr/core/src/test/org/apache/solr/rest/TestFieldTypeCollectionResource.java b/solr/core/src/test/org/apache/solr/rest/TestFieldTypeCollectionResource.java
new file mode 100644
index 00000000000..b6320a3fd04
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/rest/TestFieldTypeCollectionResource.java
@@ -0,0 +1,37 @@
+package org.apache.solr.rest;
+/*
+ * 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.
+ */
+
+import org.junit.Test;
+
+public class TestFieldTypeCollectionResource extends SchemaRestletTestBase {
+ @Test
+ public void testGetAllFieldTypes() throws Exception {
+ assertQ("/schema/fieldtypes?indent=on&wt=xml",
+ "(/response/arr[@name='fieldTypes']/lst/str[@name='name'])[1] = 'HTMLstandardtok'",
+ "(/response/arr[@name='fieldTypes']/lst/str[@name='name'])[2] = 'HTMLwhitetok'",
+ "(/response/arr[@name='fieldTypes']/lst/str[@name='name'])[3] = 'boolean'");
+ }
+
+ @Test
+ public void testJsonGetAllFieldTypes() throws Exception {
+ assertJQ("/schema/fieldtypes?indent=on",
+ "/fieldTypes/[0]/name=='HTMLstandardtok'",
+ "/fieldTypes/[1]/name=='HTMLwhitetok'",
+ "/fieldTypes/[2]/name=='boolean'");
+ }
+}
diff --git a/solr/core/src/test/org/apache/solr/rest/TestFieldTypeResource.java b/solr/core/src/test/org/apache/solr/rest/TestFieldTypeResource.java
new file mode 100644
index 00000000000..13d491f7c50
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/rest/TestFieldTypeResource.java
@@ -0,0 +1,89 @@
+package org.apache.solr.rest;
+/*
+ * 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
+ * limit ations under the License.
+ */
+
+import org.junit.Test;
+
+public class TestFieldTypeResource extends SchemaRestletTestBase {
+ @Test
+ public void testGetFieldType() throws Exception {
+ assertQ("/schema/fieldtypes/float?indent=on&wt=xml&showDefaults=true",
+ "count(/response/lst[@name='fieldType']) = 1",
+ "count(/response/lst[@name='fieldType']/*) = 18",
+ "/response/lst[@name='fieldType']/str[@name='name'] = 'float'",
+ "/response/lst[@name='fieldType']/str[@name='class'] = 'solr.TrieFloatField'",
+ "/response/lst[@name='fieldType']/str[@name='precisionStep'] ='0'",
+ "/response/lst[@name='fieldType']/bool[@name='indexed'] = 'true'",
+ "/response/lst[@name='fieldType']/bool[@name='stored'] = 'true'",
+ "/response/lst[@name='fieldType']/bool[@name='docValues'] = 'false'",
+ "/response/lst[@name='fieldType']/bool[@name='termVectors'] = 'false'",
+ "/response/lst[@name='fieldType']/bool[@name='termPositions'] = 'false'",
+ "/response/lst[@name='fieldType']/bool[@name='termOffsets'] = 'false'",
+ "/response/lst[@name='fieldType']/bool[@name='omitNorms'] = 'true'",
+ "/response/lst[@name='fieldType']/bool[@name='omitTermFreqAndPositions'] = 'true'",
+ "/response/lst[@name='fieldType']/bool[@name='omitPositions'] = 'false'",
+ "/response/lst[@name='fieldType']/bool[@name='storeOffsetsWithPositions'] = 'false'",
+ "/response/lst[@name='fieldType']/bool[@name='multiValued'] = 'false'",
+ "/response/lst[@name='fieldType']/bool[@name='tokenized'] = 'true'",
+ "/response/lst[@name='fieldType']/arr[@name='fields']/str = 'weight'",
+ "/response/lst[@name='fieldType']/arr[@name='dynamicFields']/str = '*_f'");
+ }
+
+ @Test
+ public void testGetNotFoundFieldType() throws Exception {
+ assertQ("/schema/fieldtypes/not_in_there?indent=on&wt=xml",
+ "count(/response/lst[@name='fieldtypes']) = 0",
+ "/response/lst[@name='responseHeader']/int[@name='status'] = '404'",
+ "/response/lst[@name='error']/int[@name='code'] = '404'");
+ }
+
+ @Test
+ public void testJsonGetFieldType() throws Exception {
+ assertJQ("/schema/fieldtypes/float?indent=on&showDefaults=on", // assertJQ will add "&wt=json"
+ "/fieldType/name=='float'",
+ "/fieldType/class=='solr.TrieFloatField'",
+ "/fieldType/precisionStep=='0'",
+ "/fieldType/indexed==true",
+ "/fieldType/stored==true",
+ "/fieldType/docValues==false",
+ "/fieldType/termVectors==false",
+ "/fieldType/termPositions==false",
+ "/fieldType/termOffsets==false",
+ "/fieldType/omitNorms==true",
+ "/fieldType/omitTermFreqAndPositions==true",
+ "/fieldType/omitPositions==false",
+ "/fieldType/storeOffsetsWithPositions==false",
+ "/fieldType/multiValued==false",
+ "/fieldType/tokenized==true",
+ "/fieldType/fields==['weight']",
+ "/fieldType/dynamicFields==['*_f']");
+ }
+
+ @Test
+ public void testGetFieldTypeDontShowDefaults() throws Exception {
+ assertQ("/schema/fieldtypes/teststop?wt=xml&indent=on",
+ "count(/response/lst[@name='fieldType']/*) = 5",
+ "/response/lst[@name='fieldType']/str[@name='name'] = 'teststop'",
+ "/response/lst[@name='fieldType']/str[@name='class'] = 'solr.TextField'",
+ "/response/lst[@name='fieldType']/lst[@name='analyzer']/lst[@name='tokenizer']/str[@name='class'] = 'solr.LowerCaseTokenizerFactory'",
+ "/response/lst[@name='fieldType']/lst[@name='analyzer']/arr[@name='filters']/lst/str[@name='class'][.='solr.StandardFilterFactory']",
+ "/response/lst[@name='fieldType']/lst[@name='analyzer']/arr[@name='filters']/lst/str[@name='class'][.='solr.StopFilterFactory']",
+ "/response/lst[@name='fieldType']/lst[@name='analyzer']/arr[@name='filters']/lst/str[@name='words'][.='stopwords.txt']",
+ "/response/lst[@name='fieldType']/arr[@name='fields']/str[.='teststop']",
+ "/response/lst[@name='fieldType']/arr[@name='dynamicFields']");
+ }
+}
diff --git a/solr/licenses/org.restlet-2.1.1.jar.sha1 b/solr/licenses/org.restlet-2.1.1.jar.sha1
new file mode 100644
index 00000000000..4b0aa1ff96f
--- /dev/null
+++ b/solr/licenses/org.restlet-2.1.1.jar.sha1
@@ -0,0 +1 @@
+e12c23b962c925f2681729afa1e40066a350ad27
diff --git a/solr/licenses/org.restlet-LICENSE-ASL.txt b/solr/licenses/org.restlet-LICENSE-ASL.txt
new file mode 100644
index 00000000000..261eeb9e9f8
--- /dev/null
+++ b/solr/licenses/org.restlet-LICENSE-ASL.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
diff --git a/solr/licenses/org.restlet-NOTICE.txt b/solr/licenses/org.restlet-NOTICE.txt
new file mode 100644
index 00000000000..c7839b55efa
--- /dev/null
+++ b/solr/licenses/org.restlet-NOTICE.txt
@@ -0,0 +1,2 @@
+This product includes software developed by
+the Restlet project (http://www.restlet.org).
\ No newline at end of file
diff --git a/solr/licenses/org.restlet.ext.servlet-2.1.1.jar.sha1 b/solr/licenses/org.restlet.ext.servlet-2.1.1.jar.sha1
new file mode 100644
index 00000000000..a51aa82c0ec
--- /dev/null
+++ b/solr/licenses/org.restlet.ext.servlet-2.1.1.jar.sha1
@@ -0,0 +1 @@
+72baf27dc19d98f43c362ded582db408433373ee
diff --git a/solr/licenses/org.restlet.ext.servlet-LICENSE-ASL.txt b/solr/licenses/org.restlet.ext.servlet-LICENSE-ASL.txt
new file mode 100644
index 00000000000..261eeb9e9f8
--- /dev/null
+++ b/solr/licenses/org.restlet.ext.servlet-LICENSE-ASL.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
diff --git a/solr/licenses/org.restlet.ext.servlet-NOTICE.txt b/solr/licenses/org.restlet.ext.servlet-NOTICE.txt
new file mode 100644
index 00000000000..154ac0a6b49
--- /dev/null
+++ b/solr/licenses/org.restlet.ext.servlet-NOTICE.txt
@@ -0,0 +1,2 @@
+This product includes software developed by
+the SimpleXML project (http://simple.sourceforge.net).
\ No newline at end of file
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 473771e84b8..e737cee7c02 100755
--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
@@ -24,11 +24,18 @@ import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.util.ExternalPaths;
import java.io.File;
+import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import org.apache.solr.util.RESTfulServerProvider;
+import org.apache.solr.util.RestTestHarness;
+import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.restlet.ext.servlet.ServerServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -92,7 +99,9 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
public static SolrServer server = null;
public static String context;
- public static JettySolrRunner createJetty(String solrHome, String configFile, String context) throws Exception {
+ public static JettySolrRunner createJetty(String solrHome, String configFile, String schemaFile, String context,
+ boolean stopAtShutdown, SortedMap extraServlets)
+ throws Exception {
// creates the data dir
initCore(null, null, solrHome);
@@ -103,7 +112,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
context = context==null ? "/solr" : context;
SolrJettyTestBase.context = context;
- jetty = new JettySolrRunner(solrHome, context, 0, configFile, null);
+ jetty = new JettySolrRunner(solrHome, context, 0, configFile, schemaFile, stopAtShutdown, extraServlets);
jetty.start();
port = jetty.getLocalPort();
@@ -111,6 +120,10 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
return jetty;
}
+ public static JettySolrRunner createJetty(String solrHome, String configFile, String context) throws Exception {
+ return createJetty(solrHome, configFile, null, context, true, null);
+ }
+
@AfterClass
public static void afterSolrJettyTestBase() throws Exception {
diff --git a/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
new file mode 100644
index 00000000000..74d7dc1ef71
--- /dev/null
+++ b/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
@@ -0,0 +1,269 @@
+package org.apache.solr.util;
+/*
+ * 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.
+ */
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.util.XML;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+
+abstract public class BaseTestHarness {
+ private final ThreadLocal builderTL = new ThreadLocal();
+ private final ThreadLocal xpathTL = new ThreadLocal();
+
+ public DocumentBuilder getXmlDocumentBuilder() {
+ try {
+ DocumentBuilder builder = builderTL.get();
+ if (builder == null) {
+ builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ builderTL.set(builder);
+ }
+ return builder;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public XPath getXpath() {
+ try {
+ XPath xpath = xpathTL.get();
+ if (xpath == null) {
+ xpath = XPathFactory.newInstance().newXPath();
+ xpathTL.set(xpath);
+ }
+ return xpath;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /**
+ * A helper method which validates a String against an array of XPath test
+ * strings.
+ *
+ * @param xml The xml String to validate
+ * @param tests Array of XPath strings to test (in boolean mode) on the xml
+ * @return null if all good, otherwise the first test that fails.
+ */
+ public String validateXPath(String xml, String... tests)
+ throws XPathExpressionException, SAXException {
+
+ if (tests==null || tests.length == 0) return null;
+
+ Document document = null;
+ try {
+ document = getXmlDocumentBuilder().parse(new ByteArrayInputStream
+ (xml.getBytes("UTF-8")));
+ } catch (UnsupportedEncodingException e1) {
+ throw new RuntimeException("Totally weird UTF-8 exception", e1);
+ } catch (IOException e2) {
+ throw new RuntimeException("Totally weird io exception", e2);
+ }
+
+ for (String xp : tests) {
+ xp=xp.trim();
+ Boolean bool = (Boolean) getXpath().evaluate(xp, document, XPathConstants.BOOLEAN);
+
+ if (!bool) {
+ return xp;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * A helper that creates an xml <doc> containing all of the
+ * fields and values specified
+ *
+ * @param fieldsAndValues 0 and Even numbered args are fields names odds are field values.
+ */
+ public static StringBuffer makeSimpleDoc(String... fieldsAndValues) {
+
+ try {
+ StringWriter w = new StringWriter();
+ w.append("");
+ for (int i = 0; i < fieldsAndValues.length; i+=2) {
+ XML.writeXML(w, "field", fieldsAndValues[i + 1], "name",
+ fieldsAndValues[i]);
+ }
+ w.append("");
+ return w.getBuffer();
+ } catch (IOException e) {
+ throw new RuntimeException
+ ("this should never happen with a StringWriter", e);
+ }
+ }
+
+ /**
+ * Generates a delete by query xml string
+ * @param q Query that has not already been xml escaped
+ * @param args The attributes of the delete tag
+ */
+ public static String deleteByQuery(String q, String... args) {
+ try {
+ StringWriter r = new StringWriter();
+ XML.writeXML(r, "query", q);
+ return delete(r.getBuffer().toString(), args);
+ } catch(IOException e) {
+ throw new RuntimeException
+ ("this should never happen with a StringWriter", e);
+ }
+ }
+
+ /**
+ * Generates a delete by id xml string
+ * @param id ID that has not already been xml escaped
+ * @param args The attributes of the delete tag
+ */
+ public static String deleteById(String id, String... args) {
+ try {
+ StringWriter r = new StringWriter();
+ XML.writeXML(r, "id", id);
+ return delete(r.getBuffer().toString(), args);
+ } catch(IOException e) {
+ throw new RuntimeException
+ ("this should never happen with a StringWriter", e);
+ }
+ }
+
+ /**
+ * Generates a delete xml string
+ * @param val text that has not already been xml escaped
+ * @param args 0 and Even numbered args are params, Odd numbered args are XML escaped values.
+ */
+ private static String delete(String val, String... args) {
+ try {
+ StringWriter r = new StringWriter();
+ XML.writeUnescapedXML(r, "delete", val, (Object[]) args);
+ return r.getBuffer().toString();
+ } catch(IOException e) {
+ throw new RuntimeException
+ ("this should never happen with a StringWriter", e);
+ }
+ }
+
+ /**
+ * Helper that returns an <optimize> String with
+ * optional key/val pairs.
+ *
+ * @param args 0 and Even numbered args are params, Odd numbered args are values.
+ */
+ public static String optimize(String... args) {
+ return simpleTag("optimize", args);
+ }
+
+ private static String simpleTag(String tag, String... args) {
+ try {
+ StringWriter r = new StringWriter();
+
+ // this is annoying
+ if (null == args || 0 == args.length) {
+ XML.writeXML(r, tag, null);
+ } else {
+ XML.writeXML(r, tag, null, (Object[])args);
+ }
+ return r.getBuffer().toString();
+ } catch (IOException e) {
+ throw new RuntimeException
+ ("this should never happen with a StringWriter", e);
+ }
+ }
+
+ /**
+ * Helper that returns an <commit> String with
+ * optional key/val pairs.
+ *
+ * @param args 0 and Even numbered args are params, Odd numbered args are values.
+ */
+ public static String commit(String... args) {
+ return simpleTag("commit", args);
+ }
+
+ /** Reloads the core */
+ abstract public void reload() throws Exception;
+
+ /**
+ * Processes an "update" (add, commit or optimize) and
+ * returns the response as a String.
+ *
+ * This method does NOT commit after the request.
+ *
+ * @param xml The XML of the update
+ * @return The XML response to the update
+ */
+ abstract public String update(String xml);
+
+ /**
+ * Validates that an "update" (add, commit or optimize) results in success.
+ *
+ * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
+ *
+ * @param xml The XML of the update
+ * @return null if successful, otherwise the XML response to the update
+ */
+ public String validateUpdate(String xml) throws SAXException {
+ return checkUpdateStatus(xml, "0");
+ }
+
+ /**
+ * Validates that an "update" (add, commit or optimize) results in success.
+ *
+ * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
+ *
+ * @param xml The XML of the update
+ * @return null if successful, otherwise the XML response to the update
+ */
+ public String validateErrorUpdate(String xml) throws SAXException {
+ try {
+ return checkUpdateStatus(xml, "1");
+ } catch (SolrException e) {
+ // return ((SolrException)e).getMessage();
+ return null; // success
+ }
+ }
+
+ /**
+ * Validates that an "update" (add, commit or optimize) results in success.
+ *
+ * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
+ *
+ * @param xml The XML of the update
+ * @return null if successful, otherwise the XML response to the update
+ */
+ public String checkUpdateStatus(String xml, String code) throws SAXException {
+ try {
+ String res = update(xml);
+ String valid = validateXPath(res, "//int[@name='status']="+code );
+ return (null == valid) ? null : res;
+ } catch (XPathExpressionException e) {
+ throw new RuntimeException
+ ("?!? static xpath has bug?", e);
+ }
+ }
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RESTfulServerProvider.java b/solr/test-framework/src/java/org/apache/solr/util/RESTfulServerProvider.java
new file mode 100644
index 00000000000..d87a1d3044f
--- /dev/null
+++ b/solr/test-framework/src/java/org/apache/solr/util/RESTfulServerProvider.java
@@ -0,0 +1,21 @@
+package org.apache.solr.util;
+/*
+ * 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.
+ */
+
+public interface RESTfulServerProvider {
+ public String getBaseURL();
+}
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
new file mode 100644
index 00000000000..7cc995f7b8c
--- /dev/null
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
@@ -0,0 +1,327 @@
+package org.apache.solr.util;
+/*
+ * 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.
+ */
+
+import org.apache.solr.JSONTestUtil;
+import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.common.SolrException;
+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.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;
+
+ public static void createJettyAndHarness
+ (String solrHome, String configFile, String schemaFile, String context,
+ boolean stopAtShutdown, SortedMap extraServlets) throws Exception {
+
+ createJetty(solrHome, configFile, schemaFile, context, stopAtShutdown, extraServlets);
+
+ restTestHarness = new RestTestHarness(new RESTfulServerProvider() {
+ @Override
+ public String getBaseURL() {
+ return jetty.getBaseUrl().toString();
+ }
+ });
+ }
+
+ /** Validates an update XML String is successful
+ */
+ public static void assertU(String update) {
+ assertU(null, update);
+ }
+
+ /** Validates an update XML String is successful
+ */
+ public static void assertU(String message, String update) {
+ checkUpdateU(message, update, true);
+ }
+
+ /** Validates an update XML String failed
+ */
+ public static void assertFailedU(String update) {
+ assertFailedU(null, update);
+ }
+
+ /** Validates an update XML String failed
+ */
+ public static void assertFailedU(String message, String update) {
+ checkUpdateU(message, update, false);
+ }
+
+ /** Checks the success or failure of an update message
+ */
+ private static void checkUpdateU(String message, String update, boolean shouldSucceed) {
+ try {
+ String m = (null == message) ? "" : message + " ";
+ if (shouldSucceed) {
+ String response = restTestHarness.validateUpdate(update);
+ if (response != null) fail(m + "update was not successful: " + response);
+ } else {
+ String response = restTestHarness.validateErrorUpdate(update);
+ if (response != null) fail(m + "update succeeded, but should have failed: " + response);
+ }
+ } catch (SAXException e) {
+ throw new RuntimeException("Invalid XML", e);
+ }
+ }
+
+ /**
+ * Validates a query matches some XPath test expressions
+ *
+ * @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
+ */
+ public static void assertQ(String request, String... tests) {
+ try {
+ int queryStartPos = request.indexOf('?');
+ String query;
+ String path;
+ if (-1 == queryStartPos) {
+ query = "";
+ path = request;
+ } else {
+ query = request.substring(queryStartPos + 1);
+ path = request.substring(0, queryStartPos);
+ }
+ query = setParam(query, "wt", "xml");
+ request = path + '?' + setParam(query, "indent", "on");
+
+ String response = restTestHarness.query(request);
+
+ // TODO: should the facet handling below be converted to parse the URL?
+ /*
+ if (req.getParams().getBool("facet", false)) {
+ // add a test to ensure that faceting did not throw an exception
+ // internally, where it would be added to facet_counts/exception
+ String[] allTests = new String[tests.length+1];
+ System.arraycopy(tests,0,allTests,1,tests.length);
+ allTests[0] = "*[count(//lst[@name='facet_counts']/*[@name='exception'])=0]";
+ tests = allTests;
+ }
+ */
+
+ String results = restTestHarness.validateXPath(response, tests);
+
+ if (null != results) {
+ String msg = "REQUEST FAILED: xpath=" + results
+ + "\n\txml response was: " + response
+ + "\n\trequest was:" + request;
+
+ log.error(msg);
+ throw new RuntimeException(msg);
+ }
+
+ } catch (XPathExpressionException e1) {
+ throw new RuntimeException("XPath is invalid", e1);
+ } catch (Exception e2) {
+ SolrException.log(log, "REQUEST FAILED: " + request, e2);
+ throw new RuntimeException("Exception during query", e2);
+ }
+ }
+
+ /**
+ * Makes a query request and returns the JSON string response
+ *
+ * @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
+ */
+ public static String JQ(String request) throws Exception {
+ int queryStartPos = request.indexOf('?');
+ String query;
+ String path;
+ if (-1 == queryStartPos) {
+ query = "";
+ path = request;
+ } else {
+ query = request.substring(queryStartPos + 1);
+ path = request.substring(0, queryStartPos);
+ }
+ query = setParam(query, "wt", "json");
+ request = path + '?' + setParam(query, "indent", "on");
+
+ String response;
+ boolean failed=true;
+ try {
+ response = restTestHarness.query(request);
+ failed = false;
+ } finally {
+ if (failed) {
+ log.error("REQUEST FAILED: " + request);
+ }
+ }
+
+ return response;
+ }
+
+ /**
+ * Validates a query matches some JSON test expressions using the default double delta tolerance.
+ * @see org.apache.solr.JSONTestUtil#DEFAULT_DELTA
+ * @see #assertJQ(String,double,String...)
+ */
+ public static void assertJQ(String request, String... tests) throws Exception {
+ assertJQ(request, JSONTestUtil.DEFAULT_DELTA, tests);
+ }
+
+ /**
+ * Validates a query matches some JSON test expressions and closes the
+ * query. The text expression is of the form path:JSON. To facilitate
+ * easy embedding in Java strings, the JSON can have double quotes
+ * replaced with single quotes.
+ *
+ * Please use this with care: this makes it easy to match complete
+ * structures, but doing so can result in fragile tests if you are
+ * matching more than what you want to test.
+ *
If the param is already included with the given value, the request is returned unchanged.
+ *
If the param is not already included, it is added with the given value.
+ *
If the param is already included, but with a different value, the value is replaced with the given value.
+ *
If the param is already included multiple times, they are replaced with a single param with given value.
+ *
+ *
+ * The passed-in valueToSet should NOT be URL encoded, as it will be URL encoded by this method.
+ *
+ * @param query The query portion of a request URL, e.g. "wt=json&indent=on&fl=id,_version_"
+ * @param paramToSet The parameter name to insure the presence of in the returned request
+ * @param valueToSet The parameter value to insure in the returned request
+ * @return The query with the given param set to the given value
+ */
+ private static String setParam(String query, String paramToSet, String valueToSet) {
+ if (null == valueToSet) {
+ valueToSet = "";
+ }
+ try {
+ StringBuilder builder = new StringBuilder();
+ if (null == query || query.trim().isEmpty()) {
+ // empty query -> return "paramToSet=valueToSet"
+ builder.append(paramToSet);
+ builder.append('=');
+ StrUtils.partialURLEncodeVal(builder, valueToSet);
+ return builder.toString();
+ }
+ MultiMapSolrParams requestParams = SolrRequestParsers.parseQueryString(query);
+ String[] values = requestParams.getParams(paramToSet);
+ if (null == values) {
+ // paramToSet isn't present in the request -> append "¶mToSet=valueToSet"
+ builder.append(query);
+ builder.append('&');
+ builder.append(paramToSet);
+ builder.append('=');
+ StrUtils.partialURLEncodeVal(builder, valueToSet);
+ return builder.toString();
+ }
+ if (1 == values.length && valueToSet.equals(values[0])) {
+ // paramToSet=valueToSet is already in the query - just return the query as-is.
+ return query;
+ }
+ // More than one value for paramToSet on the request, or paramToSet's value is not valueToSet
+ // -> rebuild the query
+ boolean isFirst = true;
+ for (Map.Entry entry : requestParams.getMap().entrySet()) {
+ String key = entry.getKey();
+ String[] valarr = entry.getValue();
+
+ if ( ! key.equals(paramToSet)) {
+ for (String val : valarr) {
+ builder.append(isFirst ? "" : '&');
+ isFirst = false;
+ builder.append(key);
+ builder.append('=');
+ StrUtils.partialURLEncodeVal(builder, null == val ? "" : val);
+ }
+ }
+ }
+ builder.append(isFirst ? "" : '&');
+ builder.append(paramToSet);
+ builder.append('=');
+ StrUtils.partialURLEncodeVal(builder, valueToSet);
+ return builder.toString();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
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
new file mode 100644
index 00000000000..14278b3ca8d
--- /dev/null
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
@@ -0,0 +1,120 @@
+package org.apache.solr.util;
+/*
+ * 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.
+ */
+
+import org.apache.commons.io.IOUtils;
+import org.eclipse.jetty.util.IO;
+
+import javax.xml.xpath.XPathExpressionException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+
+/**
+ * Facilitates testing Solr's REST API via a provided embedded Jetty
+ */
+public class RestTestHarness extends BaseTestHarness {
+ private RESTfulServerProvider serverProvider;
+
+ public RestTestHarness(RESTfulServerProvider serverProvider) {
+ this.serverProvider = serverProvider;
+ }
+
+ public String getBaseURL() {
+ return serverProvider.getBaseURL();
+ }
+
+ /**
+ * Validates a "query" response against an array of XPath test strings
+ *
+ * @param request the Query to process
+ * @return null if all good, otherwise the first test that fails.
+ * @exception Exception any exception in the response.
+ * @exception java.io.IOException if there is a problem writing the XML
+ */
+ public String validateQuery(String request, String... tests)
+ throws Exception {
+
+ String res = query(request);
+ return validateXPath(res, tests);
+ }
+
+ /**
+ * Processes a "query" using a URL path (with no context path) + optional query params,
+ * e.g. "/schema/fields?indent=on"
+ *
+ * @param request the URL path and optional query params
+ * @return The response to the query
+ * @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();
+ }
+
+ public String checkQueryStatus(String xml, String code) throws Exception {
+ try {
+ String response = query(xml);
+ String valid = validateXPath(response, "//int[@name='status']="+code );
+ return (null == valid) ? null : response;
+ } catch (XPathExpressionException e) {
+ throw new RuntimeException("?!? static xpath has bug?", e);
+ }
+ }
+
+ @Override
+ public void reload() throws Exception {
+ String xml = checkQueryStatus("/admin/cores?action=RELOAD", "0");
+ if (null != xml) {
+ throw new RuntimeException("RELOAD failed:\n" + xml);
+ }
+ }
+
+ /**
+ * Processes an "update" (add, commit or optimize) and
+ * returns the response as a String.
+ *
+ * @param xml The XML of the update
+ * @return The XML response to the update
+ */
+ @Override
+ public String update(String xml) {
+ try {
+ return query("/update?stream.base=" + URLEncoder.encode(xml, "UTF-8"));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
index 097bcf66169..6c0146ce230 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
@@ -20,7 +20,6 @@ package org.apache.solr.util;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.XML;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.CoreContainer;
@@ -38,22 +37,11 @@ import org.apache.solr.response.QueryResponseWriter;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.servlet.DirectSolrConnection;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
import org.apache.solr.common.util.NamedList.NamedListEntry;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
@@ -70,11 +58,9 @@ import java.util.Map;
*
*
*/
-public class TestHarness {
+public class TestHarness extends BaseTestHarness {
String coreName;
protected volatile CoreContainer container;
- private final ThreadLocal builderTL = new ThreadLocal();
- private final ThreadLocal xpathTL = new ThreadLocal();
public UpdateRequestHandler updater;
/**
@@ -138,32 +124,6 @@ public class TestHarness {
}
}
- private DocumentBuilder getXmlDocumentBuilder() {
- try {
- DocumentBuilder builder = builderTL.get();
- if (builder == null) {
- builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- builderTL.set(builder);
- }
- return builder;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- private XPath getXpath() {
- try {
- XPath xpath = xpathTL.get();
- if (xpath == null) {
- xpath = XPathFactory.newInstance().newXPath();
- xpathTL.set(xpath);
- }
- return xpath;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
// Creates a container based on infos needed to create one core
static class Initializer extends CoreContainer.Initializer {
String coreName;
@@ -270,55 +230,6 @@ public class TestHarness {
}
- /**
- * Validates that an "update" (add, commit or optimize) results in success.
- *
- * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
- *
- * @param xml The XML of the update
- * @return null if successful, otherwise the XML response to the update
- */
- public String validateUpdate(String xml) throws SAXException {
- return checkUpdateStatus(xml, "0");
- }
-
- /**
- * Validates that an "update" (add, commit or optimize) results in success.
- *
- * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
- *
- * @param xml The XML of the update
- * @return null if successful, otherwise the XML response to the update
- */
- public String validateErrorUpdate(String xml) throws SAXException {
- try {
- return checkUpdateStatus(xml, "1");
- } catch (SolrException e) {
- // return ((SolrException)e).getMessage();
- return null; // success
- }
- }
-
- /**
- * Validates that an "update" (add, commit or optimize) results in success.
- *
- * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
- *
- * @param xml The XML of the update
- * @return null if successful, otherwise the XML response to the update
- */
- public String checkUpdateStatus(String xml, String code) throws SAXException {
- try {
- String res = update(xml);
- String valid = validateXPath(res, "//int[@name='status']="+code );
- return (null == valid) ? null : res;
- } catch (XPathExpressionException e) {
- throw new RuntimeException
- ("?!? static xpath has bug?", e);
- }
- }
-
-
/**
* Validates a "query" response against an array of XPath test strings
*
@@ -397,43 +308,6 @@ public class TestHarness {
}
}
-
- /**
- * A helper method which valides a String against an array of XPath test
- * strings.
- *
- * @param xml The xml String to validate
- * @param tests Array of XPath strings to test (in boolean mode) on the xml
- * @return null if all good, otherwise the first test that fails.
- */
- public String validateXPath(String xml, String... tests)
- throws XPathExpressionException, SAXException {
-
- if (tests==null || tests.length == 0) return null;
-
- Document document=null;
- try {
- document = getXmlDocumentBuilder().parse(new ByteArrayInputStream
- (xml.getBytes("UTF-8")));
- } catch (UnsupportedEncodingException e1) {
- throw new RuntimeException("Totally weird UTF-8 exception", e1);
- } catch (IOException e2) {
- throw new RuntimeException("Totally weird io exception", e2);
- }
-
- for (String xp : tests) {
- xp=xp.trim();
- Boolean bool = (Boolean) getXpath().evaluate(xp, document,
- XPathConstants.BOOLEAN);
-
- if (!bool) {
- return xp;
- }
- }
- return null;
-
- }
-
/**
* Shuts down and frees any resources
*/
@@ -451,114 +325,6 @@ public class TestHarness {
}
}
- /**
- * A helper that creates an xml <doc> containing all of the
- * fields and values specified
- *
- * @param fieldsAndValues 0 and Even numbered args are fields names odds are field values.
- */
- public static StringBuffer makeSimpleDoc(String... fieldsAndValues) {
-
- try {
- StringWriter w = new StringWriter();
- w.append("");
- for (int i = 0; i < fieldsAndValues.length; i+=2) {
- XML.writeXML(w, "field", fieldsAndValues[i+1], "name",
- fieldsAndValues[i]);
- }
- w.append("");
- return w.getBuffer();
- } catch (IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
- }
- }
-
- /**
- * Generates a delete by query xml string
- * @param q Query that has not already been xml escaped
- * @param args The attributes of the delete tag
- */
- public static String deleteByQuery(String q, String... args) {
- try {
- StringWriter r = new StringWriter();
- XML.writeXML(r, "query", q);
- return delete(r.getBuffer().toString(), args);
- } catch(IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
- }
- }
-
- /**
- * Generates a delete by id xml string
- * @param id ID that has not already been xml escaped
- * @param args The attributes of the delete tag
- */
- public static String deleteById(String id, String... args) {
- try {
- StringWriter r = new StringWriter();
- XML.writeXML(r, "id", id);
- return delete(r.getBuffer().toString(), args);
- } catch(IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
- }
- }
-
- /**
- * Generates a delete xml string
- * @param val text that has not already been xml escaped
- * @param args 0 and Even numbered args are params, Odd numbered args are XML escaped values.
- */
- private static String delete(String val, String... args) {
- try {
- StringWriter r = new StringWriter();
- XML.writeUnescapedXML(r, "delete", val, (Object[])args);
- return r.getBuffer().toString();
- } catch(IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
- }
- }
-
- /**
- * Helper that returns an <optimize> String with
- * optional key/val pairs.
- *
- * @param args 0 and Even numbered args are params, Odd numbered args are values.
- */
- public static String optimize(String... args) {
- return simpleTag("optimize", args);
- }
-
- private static String simpleTag(String tag, String... args) {
- try {
- StringWriter r = new StringWriter();
-
- // this is annoying
- if (null == args || 0 == args.length) {
- XML.writeXML(r, tag, null);
- } else {
- XML.writeXML(r, tag, null, (Object[])args);
- }
- return r.getBuffer().toString();
- } catch (IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
- }
- }
-
- /**
- * Helper that returns an <commit> String with
- * optional key/val pairs.
- *
- * @param args 0 and Even numbered args are params, Odd numbered args are values.
- */
- public static String commit(String... args) {
- return simpleTag("commit", args);
- }
-
public LocalRequestFactory getRequestFactory(String qtype,
int start,
int limit) {
diff --git a/solr/webapp/web/WEB-INF/web.xml b/solr/webapp/web/WEB-INF/web.xml
index a42b48bb7fc..85ff4a25b30 100644
--- a/solr/webapp/web/WEB-INF/web.xml
+++ b/solr/webapp/web/WEB-INF/web.xml
@@ -125,6 +125,15 @@
${context}/#/~logging
+
+
+ SchemaRestApi
+ org.restlet.ext.servlet.ServerServlet
+
+ org.restlet.application
+ org.apache.solr.rest.SchemaRestApi
+
+ RedirectOldAdminUI
@@ -153,6 +162,11 @@
LoadAdminUI/admin.html
+
+
+ SchemaRestApi
+ /schema/*
+ .xsl