You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gs...@apache.org on 2013/08/05 12:51:50 UTC
svn commit: r1510425 [3/4] - in
/lucene/dev/branches/solr_guice_restlet/solr: core/
core/src/java/org/apache/solr/ core/src/java/org/apache/solr/core/
core/src/java/org/apache/solr/request/ core/src/java/org/apache/solr/rest/
core/src/java/org/apache/s...
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/FieldTypeSR.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/FieldTypeSR.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/FieldTypeSR.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/FieldTypeSR.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,117 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrException.ErrorCode;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+import org.apache.solr.schema.FieldType;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.schema.SchemaField;
+import org.restlet.representation.Representation;
+import org.restlet.resource.ResourceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * This class responds to requests at /solr/(corename)/schema/fieldtype/(typename)
+ * where "typename" is the name of a field type in the schema.
+ * <p/>
+ * The GET method returns properties for the named field type.
+ */
+public class FieldTypeSR extends BaseFieldTypeResource implements FieldTypeResource {
+ private static final Logger log = LoggerFactory.getLogger(FieldTypeSR.class);
+
+ private String typeName;
+
+ @Inject
+ public FieldTypeSR(SolrQueryRequestDecoder requestDecoder) {
+ super(requestDecoder);
+ }
+
+ @Override
+ public void doInit() throws ResourceException {
+ super.doInit();
+ if (isExisting()) {
+ typeName = (String) getRequestAttributes().get(IndexSchema.NAME);
+ try {
+ typeName = null == typeName ? "" : urlDecode(typeName.trim()).trim();
+ } catch (UnsupportedEncodingException e) {
+ throw new ResourceException(e);
+ }
+ }
+ }
+
+ @Override
+ public Representation get() {
+ try {
+ if (typeName.isEmpty()) {
+ final String message = "Field type name is missing";
+ throw new SolrException(ErrorCode.BAD_REQUEST, message);
+ } else {
+ FieldType fieldType = getSchema().getFieldTypes().get(typeName);
+ if (null == fieldType) {
+ final String message = "Field type '" + typeName + "' not found.";
+ throw new SolrException(ErrorCode.NOT_FOUND, message);
+ }
+ getSolrResponse().add(IndexSchema.FIELD_TYPE, getFieldTypeProperties(fieldType));
+ }
+ } catch (Exception e) {
+ getSolrResponse().setException(e);
+ }
+ handlePostExecution(log);
+
+ return new SolrOutputRepresentation();
+ }
+
+ /**
+ * Returns a field list using the given field type by iterating over all fields
+ * defined in the schema.
+ */
+ @Override
+ protected List<String> getFieldsWithFieldType(FieldType fieldType) {
+ List<String> fields = new ArrayList<String>();
+ for (SchemaField schemaField : getSchema().getFields().values()) {
+ if (schemaField.getType().getTypeName().equals(fieldType.getTypeName())) {
+ fields.add(schemaField.getName());
+ }
+ }
+ Collections.sort(fields);
+ return fields;
+ }
+
+ /**
+ * Returns a dynamic field list using the given field type by iterating over all
+ * dynamic fields defined in the schema.
+ */
+ @Override
+ protected List<String> getDynamicFieldsWithFieldType(FieldType fieldType) {
+ List<String> dynamicFields = new ArrayList<String>();
+ for (SchemaField prototype : getSchema().getDynamicFieldPrototypes()) {
+ if (prototype.getType().getTypeName().equals(fieldType.getTypeName())) {
+ dynamicFields.add(prototype.getName());
+ }
+ }
+ return dynamicFields; // Don't sort these - they're matched in order
+ }
+}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaAPI.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaAPI.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaAPI.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaAPI.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,127 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.solr.rest.API;
+import org.apache.solr.rest.ResourceFinder;
+import org.apache.solr.schema.IndexSchema;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+@Singleton
+public class SchemaAPI extends API {
+ public static final Logger log = LoggerFactory.getLogger(SchemaAPI.class);
+ public static final String FIELDS_PATH = "/{collection}/" + IndexSchema.FIELDS;
+
+ public static final String DYNAMIC_FIELDS = IndexSchema.DYNAMIC_FIELDS.toLowerCase(Locale.ROOT);
+ public static final String DYNAMIC_FIELDS_PATH = "/{collection}/" + DYNAMIC_FIELDS;
+
+ public static final String FIELDTYPES = IndexSchema.FIELD_TYPES.toLowerCase(Locale.ROOT);
+ public static final String FIELDTYPES_PATH = "/{collection}/" + FIELDTYPES;
+
+ public static final String NAME_PATH = "/{collection}/" + IndexSchema.NAME.toLowerCase(Locale.ROOT);
+ public static final String NAME_SEGMENT = "/{collection}/{" + IndexSchema.NAME.toLowerCase(Locale.ROOT) + "}";
+
+ public static final String COPY_FIELDS = IndexSchema.COPY_FIELDS.toLowerCase(Locale.ROOT);
+ public static final String COPY_FIELDS_PATH = "/{collection}/" + COPY_FIELDS;
+
+ public static final String VERSION_PATH = "/{collection}/" + IndexSchema.VERSION.toLowerCase(Locale.ROOT);
+
+ public static final String DEFAULT_SEARCH_FIELD = IndexSchema.DEFAULT_SEARCH_FIELD.toLowerCase(Locale.ROOT);
+ public static final String DEFAULT_SEARCH_FIELD_PATH = "/{collection}/" + DEFAULT_SEARCH_FIELD;
+
+ public static final String SIMILARITY_PATH = "/{collection}/" + IndexSchema.SIMILARITY.toLowerCase(Locale.ROOT);
+
+ public static final String SOLR_QUERY_PARSER = IndexSchema.SOLR_QUERY_PARSER.toLowerCase(Locale.ROOT);
+ public static final String SOLR_QUERY_PARSER_PATH = "/{collection}/" + SOLR_QUERY_PARSER;
+
+ public static final String DEFAULT_OPERATOR = IndexSchema.DEFAULT_OPERATOR.toLowerCase(Locale.ROOT);
+ public static final String DEFAULT_OPERATOR_PATH = SOLR_QUERY_PARSER_PATH + "/" + DEFAULT_OPERATOR;
+
+ public static final String UNIQUE_KEY_FIELD = IndexSchema.UNIQUE_KEY.toLowerCase(Locale.ROOT);
+ public static final String UNIQUE_KEY_FIELD_PATH = "/{collection}/" + UNIQUE_KEY_FIELD;
+
+
+ @Inject
+ public SchemaAPI(ResourceFinder finder) {
+ super(finder);
+ }
+
+
+ @Override
+ protected void initAttachments() {
+ log.info("initAttachments started");
+
+ attach("", SchemaSR.class);
+ // Allow a trailing slash on full-schema requests
+ attach("/", SchemaSR.class);
+
+ attach(FIELDS_PATH, FieldCollectionSR.class);
+ // Allow a trailing slash on collection requests
+ attach(FIELDS_PATH + "/", FieldCollectionSR.class);
+ attach(FIELDS_PATH + NAME_SEGMENT, FieldSR.class);
+
+ attach(DYNAMIC_FIELDS_PATH, DynamicFieldCollectionSR.class);
+ // Allow a trailing slash on collection requests
+ attach(DYNAMIC_FIELDS_PATH + "/", DynamicFieldCollectionSR.class);
+ attach(DYNAMIC_FIELDS_PATH + NAME_SEGMENT, DynamicFieldSR.class);
+
+ attach(FIELDTYPES_PATH, FieldTypeCollectionSR.class);
+ // Allow a trailing slash on collection requests
+ attach(FIELDTYPES_PATH + "/", FieldTypeCollectionSR.class);
+ attach(FIELDTYPES_PATH + NAME_SEGMENT, FieldTypeSR.class);
+
+ attach(COPY_FIELDS_PATH, CopyFieldCollectionSR.class);
+ // Allow a trailing slash on collection requests
+ attach(COPY_FIELDS_PATH + "/", CopyFieldCollectionSR.class);
+
+ attach(NAME_PATH, SchemaNameSR.class);
+
+ attach(VERSION_PATH, SchemaVersionSR.class);
+
+ attach(UNIQUE_KEY_FIELD_PATH, UniqueKeyFieldSR.class);
+
+ attach(DEFAULT_SEARCH_FIELD_PATH, DefaultSearchFieldSR.class);
+
+ attach(SIMILARITY_PATH, SchemaSimilaritySR.class);
+
+ // At present solrQueryParser only contains defaultOperator, but there may be more children in the future
+ attach(SOLR_QUERY_PARSER_PATH, SolrQueryParserSR.class);
+ attach(DEFAULT_OPERATOR_PATH, SolrQueryParserDefaultOperatorSR.class);
+
+ router.attachDefault(DefaultSchemaSR.class);
+
+ log.info("initAttachments complete");
+
+ }
+
+ @Override
+ public String getAPIRoot() {
+ return "/schema";
+ }
+
+ @Override
+ public String getAPIName() {
+ return "SCHEMA";
+ }
+
+
+}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaAPIModule.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaAPIModule.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaAPIModule.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaAPIModule.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,43 @@
+package org.apache.solr.rest.schema;
+
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.rest.APIModule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ *
+ **/
+public class SchemaAPIModule extends APIModule {
+ private transient static Logger log = LoggerFactory.getLogger(SchemaAPIModule.class);
+ //TODO: dynamically generate this
+ private static Class[] resources = {CopyFieldCollectionResource.class,
+ CopyFieldCollectionResource.class, DefaultSchemaResource.class, DefaultSearchFieldResource.class,
+ DynamicFieldCollectionResource.class, DynamicFieldResource.class, FieldCollectionResource.class,
+ FieldResource.class, FieldTypeCollectionResource.class, FieldTypeResource.class,
+ SchemaNameResource.class, SchemaResource.class, SchemaSimilarityResource.class,
+ SchemaVersionResource.class, SolrQueryParserDefaultOperatorResource.class,
+ SolrQueryParserResource.class, UniqueKeyFieldResource.class
+ };
+
+ @Override
+ protected void defineBindings() {
+ for (Class resource : resources) {
+ String implName = resource.getName().replace("Resource", "SR");
+ Class impl = null;
+ try {
+ impl = Class.forName(implName);//TODO: use SolrResourceLoader?
+ } catch (ClassNotFoundException e) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to find: " + implName + " for SchemaAPI binding");
+ }
+ if (impl != null) {
+ bind(resource).to(impl);
+ } else {
+ log.error("Unable to bind " + implName + " to resource: " + resource.getName());
+ }
+ }
+
+ }
+}
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaNameResource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaNameResource.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaNameResource.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaNameResource.java Mon Aug 5 10:51:48 2013
@@ -1,59 +1,14 @@
package org.apache.solr.rest.schema;
-/*
- * 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.rest.GETable;
-import org.apache.solr.schema.IndexSchema;
import org.restlet.representation.Representation;
-import org.restlet.resource.ResourceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
- * This class responds to requests at /solr/(corename)/schema/name
- */
-public class SchemaNameResource extends BaseSchemaResource implements GETable {
- private static final Logger log = LoggerFactory.getLogger(SchemaNameResource.class);
-
- public SchemaNameResource() {
- super();
- }
-
- @Override
- public void doInit() throws ResourceException {
- super.doInit();
- }
-
+ *
+ *
+ **/
+public interface SchemaNameResource extends GETable {
@Override
- public Representation get() {
- try {
- final String schemaName = getSchema().getSchemaName();
- if (null == schemaName) {
- final String message = "Schema has no name";
- throw new SolrException(SolrException.ErrorCode.NOT_FOUND, message);
- }
- getSolrResponse().add(IndexSchema.NAME, schemaName);
- } catch (Exception e) {
- getSolrResponse().setException(e);
- }
- handlePostExecution(log);
-
- return new SolrOutputRepresentation();
- }
+ Representation get();
}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaNameSR.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaNameSR.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaNameSR.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaNameSR.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,61 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+import org.apache.solr.schema.IndexSchema;
+import org.restlet.representation.Representation;
+import org.restlet.resource.ResourceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class responds to requests at /solr/(corename)/schema/name
+ */
+public class SchemaNameSR extends BaseSchemaResource implements SchemaNameResource {
+ private static final Logger log = LoggerFactory.getLogger(SchemaNameSR.class);
+
+ @Inject
+ public SchemaNameSR(SolrQueryRequestDecoder requestDecoder) {
+ super(requestDecoder);
+ }
+
+ @Override
+ public void doInit() throws ResourceException {
+ super.doInit();
+ }
+
+ @Override
+ public Representation get() {
+ try {
+ final String schemaName = getSchema().getSchemaName();
+ if (null == schemaName) {
+ final String message = "Schema has no name";
+ throw new SolrException(SolrException.ErrorCode.NOT_FOUND, message);
+ }
+ getSolrResponse().add(IndexSchema.NAME, schemaName);
+ } catch (Exception e) {
+ getSolrResponse().setException(e);
+ }
+ handlePostExecution(log);
+
+ return new SolrOutputRepresentation();
+ }
+}
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaResource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaResource.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaResource.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaResource.java Mon Aug 5 10:51:48 2013
@@ -1,52 +1,14 @@
package org.apache.solr.rest.schema;
-/*
- * 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.rest.GETable;
-import org.apache.solr.schema.IndexSchema;
import org.restlet.representation.Representation;
-import org.restlet.resource.ResourceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
- * This class responds to requests at /solr/(corename)/schema
- */
-public class SchemaResource extends BaseSchemaResource implements GETable {
- private static final Logger log = LoggerFactory.getLogger(SchemaResource.class);
-
- public SchemaResource() {
- super();
- }
-
- @Override
- public void doInit() throws ResourceException {
- super.doInit();
- }
-
+ *
+ *
+ **/
+public interface SchemaResource extends GETable {
@Override
- public Representation get() {
- try {
- getSolrResponse().add(IndexSchema.SCHEMA, getSchema().getNamedPropertyValues());
- } catch (Exception e) {
- getSolrResponse().setException(e);
- }
- handlePostExecution(log);
-
- return new SolrOutputRepresentation();
- }
+ Representation get();
}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSR.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSR.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSR.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSR.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,54 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+import org.apache.solr.schema.IndexSchema;
+import org.restlet.representation.Representation;
+import org.restlet.resource.ResourceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class responds to requests at /solr/(corename)/schema
+ */
+public class SchemaSR extends BaseSchemaResource implements SchemaResource {
+ private static final Logger log = LoggerFactory.getLogger(SchemaSR.class);
+
+ @Inject
+ public SchemaSR(SolrQueryRequestDecoder requestDecoder) {
+ super(requestDecoder);
+ }
+
+ @Override
+ public void doInit() throws ResourceException {
+ super.doInit();
+ }
+
+ @Override
+ public Representation get() {
+ try {
+ getSolrResponse().add(IndexSchema.SCHEMA, getSchema().getNamedPropertyValues());
+ } catch (Exception e) {
+ getSolrResponse().setException(e);
+ }
+ handlePostExecution(log);
+
+ return new SolrOutputRepresentation();
+ }
+}
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSimilarityResource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSimilarityResource.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSimilarityResource.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSimilarityResource.java Mon Aug 5 10:51:48 2013
@@ -1,55 +1,14 @@
package org.apache.solr.rest.schema;
-/*
- * 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.rest.GETable;
-import org.apache.solr.rest.SolrRestApi;
-import org.apache.solr.schema.IndexSchema;
import org.restlet.representation.Representation;
-import org.restlet.resource.ResourceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
- * This class responds to requests at /solr/(corename)/schema/similarity
- */
-public class SchemaSimilarityResource extends BaseSchemaResource implements GETable {
- private static final Logger log = LoggerFactory.getLogger(SchemaSimilarityResource.class);
-
- public SchemaSimilarityResource() {
- super();
- }
-
- @Override
- public void doInit() throws ResourceException {
- super.doInit();
- }
-
+ *
+ *
+ **/
+public interface SchemaSimilarityResource extends GETable {
@Override
- public Representation get() {
- try {
- getSolrResponse().add(IndexSchema.SIMILARITY, getSchema().getSimilarityFactory().getNamedPropertyValues());
- } catch (Exception e) {
- getSolrResponse().setException(e);
- }
- handlePostExecution(log);
-
- return new SolrOutputRepresentation();
- }
+ Representation get();
}
-
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSimilaritySR.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSimilaritySR.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSimilaritySR.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaSimilaritySR.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,56 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+import org.apache.solr.schema.IndexSchema;
+import org.restlet.representation.Representation;
+import org.restlet.resource.ResourceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class responds to requests at /solr/(corename)/schema/similarity
+ */
+public class SchemaSimilaritySR extends BaseSchemaResource implements SchemaSimilarityResource {
+ private static final Logger log = LoggerFactory.getLogger(SchemaSimilaritySR.class);
+
+ @Inject
+ public SchemaSimilaritySR(SolrQueryRequestDecoder requestDecoder) {
+ super(requestDecoder);
+ }
+
+ @Override
+ public void doInit() throws ResourceException {
+ super.doInit();
+ }
+
+ @Override
+ public Representation get() {
+ try {
+ getSolrResponse().add(IndexSchema.SIMILARITY, getSchema().getSimilarityFactory().getNamedPropertyValues());
+ } catch (Exception e) {
+ getSolrResponse().setException(e);
+ }
+ handlePostExecution(log);
+
+ return new SolrOutputRepresentation();
+ }
+}
+
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaVersionResource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaVersionResource.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaVersionResource.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaVersionResource.java Mon Aug 5 10:51:48 2013
@@ -1,54 +1,14 @@
package org.apache.solr.rest.schema;
-/*
- * 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.rest.GETable;
-import org.apache.solr.rest.SolrRestApi;
-import org.apache.solr.schema.IndexSchema;
import org.restlet.representation.Representation;
-import org.restlet.resource.ResourceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
- * This class responds to requests at /solr/(corename)/schema/version
- */
-public class SchemaVersionResource extends BaseSchemaResource implements GETable {
- private static final Logger log = LoggerFactory.getLogger(SchemaVersionResource.class);
-
- public SchemaVersionResource() {
- super();
- }
-
- @Override
- public void doInit() throws ResourceException {
- super.doInit();
- }
-
+ *
+ *
+ **/
+public interface SchemaVersionResource extends GETable {
@Override
- public Representation get() {
- try {
- getSolrResponse().add(IndexSchema.VERSION, getSchema().getVersion());
- } catch (Exception e) {
- getSolrResponse().setException(e);
- }
- handlePostExecution(log);
-
- return new SolrOutputRepresentation();
- }
+ Representation get();
}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaVersionSR.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaVersionSR.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaVersionSR.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SchemaVersionSR.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,55 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+import org.apache.solr.schema.IndexSchema;
+import org.restlet.representation.Representation;
+import org.restlet.resource.ResourceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class responds to requests at /solr/(corename)/schema/version
+ */
+public class SchemaVersionSR extends BaseSchemaResource implements SchemaVersionResource {
+ private static final Logger log = LoggerFactory.getLogger(SchemaVersionSR.class);
+
+ @Inject
+ public SchemaVersionSR(SolrQueryRequestDecoder requestDecoder) {
+ super(requestDecoder);
+ }
+
+ @Override
+ public void doInit() throws ResourceException {
+ super.doInit();
+ }
+
+ @Override
+ public Representation get() {
+ try {
+ getSolrResponse().add(IndexSchema.VERSION, getSchema().getVersion());
+ } catch (Exception e) {
+ getSolrResponse().setException(e);
+ }
+ handlePostExecution(log);
+
+ return new SolrOutputRepresentation();
+ }
+}
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserDefaultOperatorResource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserDefaultOperatorResource.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserDefaultOperatorResource.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserDefaultOperatorResource.java Mon Aug 5 10:51:48 2013
@@ -1,53 +1,14 @@
package org.apache.solr.rest.schema;
-/*
- * 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.rest.GETable;
-import org.apache.solr.schema.IndexSchema;
import org.restlet.representation.Representation;
-import org.restlet.resource.ResourceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
- * This class responds to requests at /solr/(corename)/schema/solrqueryparser/defaultoperator
- */
-public class SolrQueryParserDefaultOperatorResource extends BaseSchemaResource implements GETable {
- private static final Logger log = LoggerFactory.getLogger(SolrQueryParserDefaultOperatorResource.class);
-
- public SolrQueryParserDefaultOperatorResource() {
- super();
- }
-
- @Override
- public void doInit() throws ResourceException {
- super.doInit();
- }
-
+ *
+ *
+ **/
+public interface SolrQueryParserDefaultOperatorResource extends GETable {
@Override
- public Representation get() {
- try {
- getSolrResponse().add(IndexSchema.DEFAULT_OPERATOR, getSchema().getQueryParserDefaultOperator());
- } catch (Exception e) {
- getSolrResponse().setException(e);
- }
- handlePostExecution(log);
-
- return new SolrOutputRepresentation();
- }
+ Representation get();
}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserDefaultOperatorSR.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserDefaultOperatorSR.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserDefaultOperatorSR.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserDefaultOperatorSR.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,50 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+import org.apache.solr.schema.IndexSchema;
+import org.restlet.representation.Representation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class responds to requests at /solr/(corename)/schema/solrqueryparser/defaultoperator
+ */
+public class SolrQueryParserDefaultOperatorSR extends BaseSchemaResource implements SolrQueryParserDefaultOperatorResource {
+ private static final Logger log = LoggerFactory.getLogger(SolrQueryParserDefaultOperatorSR.class);
+
+ @Inject
+ public SolrQueryParserDefaultOperatorSR(SolrQueryRequestDecoder requestDecoder) {
+ super(requestDecoder);
+ }
+
+
+ @Override
+ public Representation get() {
+ try {
+ getSolrResponse().add(IndexSchema.DEFAULT_OPERATOR, getSchema().getQueryParserDefaultOperator());
+ } catch (Exception e) {
+ getSolrResponse().setException(e);
+ }
+ handlePostExecution(log);
+
+ return new SolrOutputRepresentation();
+ }
+}
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserResource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserResource.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserResource.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserResource.java Mon Aug 5 10:51:48 2013
@@ -1,56 +1,14 @@
package org.apache.solr.rest.schema;
-/*
- * 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.util.SimpleOrderedMap;
+
import org.apache.solr.rest.GETable;
-import org.apache.solr.schema.IndexSchema;
import org.restlet.representation.Representation;
-import org.restlet.resource.ResourceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
- * This class responds to requests at /solr/(corename)/schema/solrqueryparser
- */
-public class SolrQueryParserResource extends BaseSchemaResource implements GETable {
- private static final Logger log = LoggerFactory.getLogger(SolrQueryParserResource.class);
-
- public SolrQueryParserResource() {
- super();
- }
-
- @Override
- public void doInit() throws ResourceException {
- super.doInit();
- }
-
+ *
+ *
+ **/
+public interface SolrQueryParserResource extends GETable {
@Override
- public Representation get() {
- try {
- SimpleOrderedMap<Object> props = new SimpleOrderedMap<Object>();
- props.add(IndexSchema.DEFAULT_OPERATOR, getSchema().getQueryParserDefaultOperator());
- getSolrResponse().add(IndexSchema.SOLR_QUERY_PARSER, props);
- } catch (Exception e) {
- getSolrResponse().setException(e);
- }
- handlePostExecution(log);
-
- return new SolrOutputRepresentation();
- }
+ Representation get();
}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserSR.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserSR.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserSR.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/SolrQueryParserSR.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,58 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+import org.apache.solr.schema.IndexSchema;
+import org.restlet.representation.Representation;
+import org.restlet.resource.ResourceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class responds to requests at /solr/(corename)/schema/solrqueryparser
+ */
+public class SolrQueryParserSR extends BaseSchemaResource implements SolrQueryParserResource {
+ private static final Logger log = LoggerFactory.getLogger(SolrQueryParserSR.class);
+
+ @Inject
+ public SolrQueryParserSR(SolrQueryRequestDecoder requestDecoder) {
+ super(requestDecoder);
+ }
+
+ @Override
+ public void doInit() throws ResourceException {
+ super.doInit();
+ }
+
+ @Override
+ public Representation get() {
+ try {
+ SimpleOrderedMap<Object> props = new SimpleOrderedMap<Object>();
+ props.add(IndexSchema.DEFAULT_OPERATOR, getSchema().getQueryParserDefaultOperator());
+ getSolrResponse().add(IndexSchema.SOLR_QUERY_PARSER, props);
+ } catch (Exception e) {
+ getSolrResponse().setException(e);
+ }
+ handlePostExecution(log);
+
+ return new SolrOutputRepresentation();
+ }
+}
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/UniqueKeyFieldResource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/UniqueKeyFieldResource.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/UniqueKeyFieldResource.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/UniqueKeyFieldResource.java Mon Aug 5 10:51:48 2013
@@ -1,53 +1,14 @@
package org.apache.solr.rest.schema;
-/*
- * 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.rest.GETable;
-import org.apache.solr.schema.IndexSchema;
import org.restlet.representation.Representation;
-import org.restlet.resource.ResourceException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
- * This class responds to requests at /solr/(corename)/schema/uniquekey
- */
-public class UniqueKeyFieldResource extends BaseSchemaResource implements GETable {
- private static final Logger log = LoggerFactory.getLogger(UniqueKeyFieldResource.class);
-
- public UniqueKeyFieldResource() {
- super();
- }
-
- @Override
- public void doInit() throws ResourceException {
- super.doInit();
- }
-
+ *
+ *
+ **/
+public interface UniqueKeyFieldResource extends GETable {
@Override
- public Representation get() {
- try {
- getSolrResponse().add(IndexSchema.UNIQUE_KEY, getSchema().getUniqueKeyField().getName());
- } catch (Exception e) {
- getSolrResponse().setException(e);
- }
- handlePostExecution(log);
-
- return new SolrOutputRepresentation();
- }
+ Representation get();
}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/UniqueKeyFieldSR.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/UniqueKeyFieldSR.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/UniqueKeyFieldSR.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/rest/schema/UniqueKeyFieldSR.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,55 @@
+package org.apache.solr.rest.schema;
+/*
+ * 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 com.google.inject.Inject;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+import org.apache.solr.schema.IndexSchema;
+import org.restlet.representation.Representation;
+import org.restlet.resource.ResourceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class responds to requests at /solr/(corename)/schema/uniquekey
+ */
+public class UniqueKeyFieldSR extends BaseSchemaResource implements UniqueKeyFieldResource {
+ private static final Logger log = LoggerFactory.getLogger(UniqueKeyFieldSR.class);
+
+ @Inject
+ public UniqueKeyFieldSR(SolrQueryRequestDecoder requestDecoder) {
+ super(requestDecoder);
+ }
+
+ @Override
+ public void doInit() throws ResourceException {
+ super.doInit();
+ }
+
+ @Override
+ public Representation get() {
+ try {
+ getSolrResponse().add(IndexSchema.UNIQUE_KEY, getSchema().getUniqueKeyField().getName());
+ } catch (Exception e) {
+ getSolrResponse().setException(e);
+ }
+ handlePostExecution(log);
+
+ return new SolrOutputRepresentation();
+ }
+}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/HttpServletModule.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/HttpServletModule.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/HttpServletModule.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/HttpServletModule.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,32 @@
+package org.apache.solr.servlet;
+
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+
+import java.util.Map;
+
+/**
+ * Bind things that are HttpServlet specific
+ */
+public class HttpServletModule extends AbstractModule {
+
+
+ private final Map<SolrConfig, SolrRequestParsers> parsers;
+
+ public HttpServletModule(Map<SolrConfig, SolrRequestParsers> parsers) {
+ this.parsers = parsers;
+ }
+
+ @Override
+ protected void configure() {
+ bind(SolrQueryRequestDecoder.class).to(HttpServletSQRDecoder.class);
+ }
+
+ @Provides
+ Map<SolrConfig, SolrRequestParsers> providesRequestParsers() {
+ return parsers;
+ }
+}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/HttpServletSQRDecoder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/HttpServletSQRDecoder.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/HttpServletSQRDecoder.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/HttpServletSQRDecoder.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,44 @@
+package org.apache.solr.servlet;
+
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+import org.apache.solr.core.SolrConfig;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryRequestDecoder;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+/**
+ *
+ *
+ **/
+public class HttpServletSQRDecoder implements SolrQueryRequestDecoder {
+
+ protected final HttpServletRequest request;
+ protected final Map<SolrConfig, SolrRequestParsers> parsers;
+
+ @Inject
+ public HttpServletSQRDecoder(HttpServletRequest request, Map<SolrConfig, SolrRequestParsers> parsers) {
+ this.request = request;
+ this.parsers = parsers;
+ }
+
+ @Override
+ public SolrQueryRequest decode() throws Exception {
+ return SolrRequestParsers.DEFAULT.parse(null, request.getServletPath(), request);
+ }
+
+ @Override
+ public SolrQueryRequest decode(SolrCore core) throws Exception {
+ SolrConfig solrConfig = core.getSolrConfig();
+ SolrRequestParsers parser = parsers.get(solrConfig);
+ if (parser == null) {
+ parser = new SolrRequestParsers(solrConfig);
+ parsers.put(solrConfig, parser);
+ }
+ return parser.parse(core, request.getServletPath(), request);
+ }
+}
Added: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/InjectableServlet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/InjectableServlet.java?rev=1510425&view=auto
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/InjectableServlet.java (added)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/InjectableServlet.java Mon Aug 5 10:51:48 2013
@@ -0,0 +1,73 @@
+package org.apache.solr.servlet;
+
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Singleton;
+import org.apache.solr.rest.API;
+import org.apache.solr.rest.APIModule;
+import org.apache.solr.rest.ResourceFinder;
+import org.restlet.Component;
+import org.restlet.data.Protocol;
+import org.restlet.ext.servlet.ServerServlet;
+import org.restlet.routing.VirtualHost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Set;
+
+/**
+ *
+ *
+ **/
+@Singleton
+public class InjectableServlet extends ServerServlet {
+ private transient static Logger log = LoggerFactory.getLogger(InjectableServlet.class);
+ @Inject
+ Injector injector;
+ private Set<APIModule> modules;
+
+ @Inject
+ InjectableServlet(Set<APIModule> modules) {
+ this.modules = modules;
+ //we have everything we need here
+
+ }
+
+
+ @Override
+ protected Component createComponent() {
+ ResourceFinder finder = new ResourceFinder(injector);
+ injector.injectMembers(finder);
+ Component component = new Component();
+ VirtualHost apivhost = new VirtualHost(component.getContext());
+ component.getDefaultHost().attach("/api", apivhost);
+ for (APIModule module : modules) {
+
+ module.initInjectorDependent();
+ API api = injector.getInstance(module.getAPIClass());
+ String apiRoot = api.getAPIRoot();
+ if (apiRoot == null || apiRoot.equals("")) {
+ throw new RuntimeException("API must provide non-null, non-empty getAPIRoot implementation");
+ }
+ //TODO: set up a proper status service
+ //api.setStatusService(statusService);
+ apivhost.attach(apiRoot, api);
+ log.info("Attached " + api.getAPIName() + " to " + apiRoot);
+ }
+ // Define the list of supported client protocols.
+ component.getClients().add(Protocol.HTTP);
+ return component;
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ //TODO: stats here?
+ super.service(request, response);
+
+ }
+}
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java Mon Aug 5 10:51:48 2013
@@ -26,6 +26,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.google.inject.Singleton;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.StringEscapeUtils;
@@ -37,6 +38,7 @@ import org.apache.solr.core.SolrCore;
*
* @since solr 4.0
*/
+@Singleton
public final class LoadAdminUiServlet extends HttpServlet {
@Override
Modified: lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java?rev=1510425&r1=1510424&r2=1510425&view=diff
==============================================================================
--- lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java (original)
+++ lucene/dev/branches/solr_guice_restlet/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java Mon Aug 5 10:51:48 2013
@@ -85,8 +85,9 @@ import java.util.WeakHashMap;
*
* @since solr 1.2
*/
-public class SolrDispatchFilter implements Filter
-{
+//TODO: KILL THIS
+@Deprecated
+public class SolrDispatchFilter implements Filter {
final Logger log;
protected volatile CoreContainer cores;
@@ -94,7 +95,7 @@ public class SolrDispatchFilter implemen
protected String pathPrefix = null; // strip this from the beginning of a path
protected String abortErrorMessage = null;
protected final Map<SolrConfig, SolrRequestParsers> parsers = new WeakHashMap<SolrConfig, SolrRequestParsers>();
-
+
private static final Charset UTF8 = Charset.forName("UTF-8");
public SolrDispatchFilter() {
@@ -104,28 +105,26 @@ public class SolrDispatchFilter implemen
throw new SolrException(
ErrorCode.SERVER_ERROR,
"Could not find necessary SLF4j logging jars. If using Jetty, the SLF4j logging jars need to go in "
- +"the jetty lib/ext directory. For other containers, the corresponding directory should be used. "
- +"For more information, see: http://wiki.apache.org/solr/SolrLogging",
+ + "the jetty lib/ext directory. For other containers, the corresponding directory should be used. "
+ + "For more information, see: http://wiki.apache.org/solr/SolrLogging",
e);
}
}
-
+
@Override
- public void init(FilterConfig config) throws ServletException
- {
+ public void init(FilterConfig config) throws ServletException {
log.info("SolrDispatchFilter.init()");
try {
// web.xml configuration
- this.pathPrefix = config.getInitParameter( "path-prefix" );
+ this.pathPrefix = config.getInitParameter("path-prefix");
this.cores = createCoreContainer();
log.info("user.dir=" + System.getProperty("user.dir"));
- }
- catch( Throwable t ) {
+ } catch (Throwable t) {
// catch this so our filter still works
- log.error( "Could not start Solr. Check solr/home property and the logs");
- SolrCore.log( t );
+ log.error("Could not start Solr. Check solr/home property and the logs");
+ SolrCore.log(t);
}
log.info("SolrDispatchFilter.init() done");
@@ -133,6 +132,7 @@ public class SolrDispatchFilter implemen
/**
* Override this to change CoreContainer initialization
+ *
* @return a CoreContainer to hold this server's cores
*/
protected CoreContainer createCoreContainer() {
@@ -140,42 +140,42 @@ public class SolrDispatchFilter implemen
cores.load();
return cores;
}
-
+
public CoreContainer getCores() {
return cores;
}
-
+
@Override
public void destroy() {
if (cores != null) {
cores.shutdown();
cores = null;
- }
+ }
}
-
+
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
doFilter(request, response, chain, false);
}
-
+
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throws IOException, ServletException {
- if( abortErrorMessage != null ) {
- ((HttpServletResponse)response).sendError( 500, abortErrorMessage );
+ if (abortErrorMessage != null) {
+ ((HttpServletResponse) response).sendError(500, abortErrorMessage);
return;
}
-
+
if (this.cores == null) {
- ((HttpServletResponse)response).sendError( 503, "Server is shutting down" );
+ ((HttpServletResponse) response).sendError(503, "Server is shutting down");
return;
}
CoreContainer cores = this.cores;
SolrCore core = null;
SolrQueryRequest solrReq = null;
Aliases aliases = null;
-
- if( request instanceof HttpServletRequest) {
- HttpServletRequest req = (HttpServletRequest)request;
- HttpServletResponse resp = (HttpServletResponse)response;
+
+ if (request instanceof HttpServletRequest) {
+ HttpServletRequest req = (HttpServletRequest) request;
+ HttpServletResponse resp = (HttpServletResponse) response;
SolrRequestHandler handler = null;
String corename = "";
String origCorename = null;
@@ -183,12 +183,12 @@ public class SolrDispatchFilter implemen
// put the core container in request attribute
req.setAttribute("org.apache.solr.CoreContainer", cores);
String path = req.getServletPath();
- if( req.getPathInfo() != null ) {
+ if (req.getPathInfo() != null) {
// this lets you handle /update/commit when /update is a servlet
path += req.getPathInfo();
}
- if( pathPrefix != null && path.startsWith( pathPrefix ) ) {
- path = path.substring( pathPrefix.length() );
+ if (pathPrefix != null && path.startsWith(pathPrefix)) {
+ path = path.substring(pathPrefix.length());
}
// check for management path
String alternate = cores.getManagementPath();
@@ -196,42 +196,41 @@ public class SolrDispatchFilter implemen
path = path.substring(0, alternate.length());
}
// unused feature ?
- int idx = path.indexOf( ':' );
- if( idx > 0 ) {
+ int idx = path.indexOf(':');
+ if (idx > 0) {
// save the portion after the ':' for a 'handler' path parameter
- path = path.substring( 0, idx );
+ path = path.substring(0, idx);
}
// Check for the core admin page
- if( path.equals( cores.getAdminPath() ) ) {
+ if (path.equals(cores.getAdminPath())) {
handler = cores.getMultiCoreHandler();
- solrReq = SolrRequestParsers.DEFAULT.parse(null,path, req);
+ solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req);
handleAdminRequest(req, response, handler, solrReq);
return;
}
boolean usingAliases = false;
List<String> collectionsList = null;
// Check for the core admin collections url
- if( path.equals( "/admin/collections" ) ) {
+ if (path.equals("/admin/collections")) {
handler = cores.getCollectionsHandler();
- solrReq = SolrRequestParsers.DEFAULT.parse(null,path, req);
+ solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req);
handleAdminRequest(req, response, handler, solrReq);
return;
}
// Check for the core admin info url
- if( path.startsWith( "/admin/info" ) ) {
+ if (path.startsWith("/admin/info")) {
handler = cores.getInfoHandler();
- solrReq = SolrRequestParsers.DEFAULT.parse(null,path, req);
+ solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req);
handleAdminRequest(req, response, handler, solrReq);
return;
- }
- else {
+ } else {
//otherwise, we should find a core from the path
- idx = path.indexOf( "/", 1 );
- if( idx > 1 ) {
+ idx = path.indexOf("/", 1);
+ if (idx > 1) {
// try to get the corename as a request parameter first
- corename = path.substring( 1, idx );
-
+ corename = path.substring(1, idx);
+
// look at aliases
if (cores.isZooKeeperAware()) {
origCorename = corename;
@@ -246,34 +245,34 @@ public class SolrDispatchFilter implemen
}
}
}
-
+
core = cores.getCore(corename);
if (core != null) {
- path = path.substring( idx );
+ path = path.substring(idx);
}
}
if (core == null) {
- if (!cores.isZooKeeperAware() ) {
+ if (!cores.isZooKeeperAware()) {
core = cores.getCore("");
}
}
}
-
+
if (core == null && cores.isZooKeeperAware()) {
// we couldn't find the core - lets make sure a collection was not specified instead
core = getCoreByCollection(cores, corename, path);
-
+
if (core != null) {
// we found a core, update the path
- path = path.substring( idx );
+ path = path.substring(idx);
}
-
+
// if we couldn't find it locally, look on other nodes
if (core == null && idx > 0) {
String coreUrl = getRemotCoreUrl(cores, corename, origCorename);
if (coreUrl != null) {
- path = path.substring( idx );
+ path = path.substring(idx);
remoteQuery(coreUrl + path, req, solrReq, resp);
return;
} else {
@@ -288,7 +287,7 @@ public class SolrDispatchFilter implemen
}
}
}
-
+
// try the default core
if (core == null) {
core = cores.getCore("");
@@ -296,21 +295,21 @@ public class SolrDispatchFilter implemen
}
// With a valid core...
- if( core != null ) {
+ if (core != null) {
final SolrConfig config = core.getSolrConfig();
// get or create/cache the parser for the core
SolrRequestParsers parser = null;
parser = parsers.get(config);
- if( parser == null ) {
+ if (parser == null) {
parser = new SolrRequestParsers(config);
- parsers.put(config, parser );
+ parsers.put(config, parser);
}
// Handle /schema/* paths via Restlet
- if( path.startsWith("/schema") ) {
+ if (path.startsWith("/schema")) {
solrReq = parser.parse(core, path, req);
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(solrReq, new SolrQueryResponse()));
- if( path.equals(req.getServletPath()) ) {
+ if (path.equals(req.getServletPath())) {
// avoid endless loop - pass through to Restlet via webapp
chain.doFilter(request, response);
} else {
@@ -322,52 +321,52 @@ public class SolrDispatchFilter implemen
// 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
- handler = core.getRequestHandler( path );
+ if (handler == null && path.length() > 1) { // don't match "" or "/" as valid path
+ handler = core.getRequestHandler(path);
// no handler yet but allowed to handle select; let's check
- if( handler == null && parser.isHandleSelect() ) {
- if( "/select".equals( path ) || "/select/".equals( path ) ) {
- solrReq = parser.parse( core, path, req );
- String qt = solrReq.getParams().get( CommonParams.QT );
- handler = core.getRequestHandler( qt );
- if( handler == null ) {
- throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt);
+ if (handler == null && parser.isHandleSelect()) {
+ if ("/select".equals(path) || "/select/".equals(path)) {
+ solrReq = parser.parse(core, path, req);
+ String qt = solrReq.getParams().get(CommonParams.QT);
+ handler = core.getRequestHandler(qt);
+ if (handler == null) {
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "unknown handler: " + qt);
}
- if( qt != null && qt.startsWith("/") && (handler instanceof ContentStreamHandlerBase)) {
+ if (qt != null && qt.startsWith("/") && (handler instanceof ContentStreamHandlerBase)) {
//For security reasons it's a bad idea to allow a leading '/', ex: /select?qt=/update see SOLR-3161
//There was no restriction from Solr 1.4 thru 3.5 and it's not supported for update handlers.
- throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Invalid Request Handler ('qt'). Do not use /select to access: "+qt);
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid Request Handler ('qt'). Do not use /select to access: " + qt);
}
}
}
}
// With a valid handler and a valid core...
- if( handler != null ) {
+ if (handler != null) {
// if not a /select, create the request
- if( solrReq == null ) {
- solrReq = parser.parse( core, path, req );
+ if (solrReq == null) {
+ solrReq = parser.parse(core, path, req);
}
if (usingAliases) {
processAliases(solrReq, aliases, collectionsList);
}
-
+
final Method reqMethod = Method.getMethod(req.getMethod());
HttpCacheHeaderUtil.setCacheControlHeader(config, resp, reqMethod);
// unless we have been explicitly told not to, do cache validation
// if we fail cache validation, execute the query
if (config.getHttpCachingConfig().isNever304() ||
!HttpCacheHeaderUtil.doCacheHeaderValidation(solrReq, req, reqMethod, resp)) {
- SolrQueryResponse solrRsp = new SolrQueryResponse();
+ SolrQueryResponse solrRsp = new SolrQueryResponse();
/* even for HEAD requests, we need to execute the handler to
* ensure we don't get an error (and to make sure the correct
* QueryResponseWriter is selected and we get the correct
* Content-Type)
*/
- SolrRequestInfo.setRequestInfo(new SolrRequestInfo(solrReq, solrRsp));
- this.execute( req, handler, solrReq, solrRsp );
- HttpCacheHeaderUtil.checkHttpCachingVeto(solrRsp, resp, reqMethod);
+ SolrRequestInfo.setRequestInfo(new SolrRequestInfo(solrReq, solrRsp));
+ this.execute(req, handler, solrReq, solrRsp);
+ HttpCacheHeaderUtil.checkHttpCachingVeto(solrRsp, resp, reqMethod);
// add info to http headers
//TODO: See SOLR-232 and SOLR-267.
/*try {
@@ -378,36 +377,34 @@ public class SolrDispatchFilter implemen
} catch (ClassCastException cce) {
log.log(Level.WARNING, "exception adding response header log information", cce);
}*/
- QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
- writeResponse(solrRsp, response, responseWriter, solrReq, reqMethod);
+ QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
+ writeResponse(solrRsp, response, responseWriter, solrReq, reqMethod);
}
return; // we are done with a valid handler
}
}
log.debug("no handler or core retrieved for " + path + ", follow through...");
- }
- catch (Throwable ex) {
- sendError( core, solrReq, request, (HttpServletResponse)response, ex );
+ } catch (Throwable ex) {
+ sendError(core, solrReq, request, (HttpServletResponse) response, ex);
return;
- }
- finally {
- if( solrReq != null ) {
+ } finally {
+ if (solrReq != null) {
log.debug("Closing out SolrRequest: {}", solrReq);
solrReq.close();
}
if (core != null) {
core.close();
}
- SolrRequestInfo.clearRequestInfo();
+ SolrRequestInfo.clearRequestInfo();
}
}
// Otherwise let the webapp handle the request
chain.doFilter(request, response);
}
-
+
private void processAliases(SolrQueryRequest solrReq, Aliases aliases,
- List<String> collectionsList) {
+ List<String> collectionsList) {
String collection = solrReq.getParams().get("collection");
if (collection != null) {
collectionsList = StrUtils.splitSmart(collection, ",", true);
@@ -441,24 +438,24 @@ public class SolrDispatchFilter implemen
}
}
}
-
+
private void remoteQuery(String coreUrl, HttpServletRequest req,
- SolrQueryRequest solrReq, HttpServletResponse resp) throws IOException {
+ SolrQueryRequest solrReq, HttpServletResponse resp) throws IOException {
try {
String urlstr = coreUrl;
-
+
String queryString = req.getQueryString();
-
+
urlstr += queryString == null ? "" : "?" + queryString;
-
+
URL url = new URL(urlstr);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod(req.getMethod());
con.setUseCaches(false);
-
+
con.setDoOutput(true);
con.setDoInput(true);
- for (Enumeration e = req.getHeaderNames(); e.hasMoreElements();) {
+ for (Enumeration e = req.getHeaderNames(); e.hasMoreElements(); ) {
String headerName = e.nextElement().toString();
con.setRequestProperty(headerName, req.getHeader(headerName));
}
@@ -478,19 +475,19 @@ public class SolrDispatchFilter implemen
IOUtils.closeQuietly(is); // TODO: I thought we weren't supposed to explicitly close servlet streams
}
}
-
+
resp.setStatus(con.getResponseCode());
-
+
for (Iterator i = con.getHeaderFields().entrySet().iterator(); i
- .hasNext();) {
+ .hasNext(); ) {
Map.Entry mapEntry = (Map.Entry) i.next();
if (mapEntry.getKey() != null) resp.setHeader(mapEntry.getKey()
.toString(), ((List) mapEntry.getValue()).get(0).toString());
}
-
+
resp.setCharacterEncoding(con.getContentEncoding());
resp.setContentType(con.getContentType());
-
+
is = con.getInputStream();
os = resp.getOutputStream();
try {
@@ -508,9 +505,9 @@ public class SolrDispatchFilter implemen
SolrException.ErrorCode.SERVER_ERROR,
"Error trying to proxy request for url: " + coreUrl, e));
}
-
+
}
-
+
private String getRemotCoreUrl(CoreContainer cores, String collectionName, String origCorename) {
ClusterState clusterState = cores.getZkController().getClusterState();
Collection<Slice> slices = clusterState.getActiveSlices(collectionName);
@@ -524,16 +521,16 @@ public class SolrDispatchFilter implemen
slices.addAll(clusterState.getActiveSlices(collection));
}
}
-
+
if (slices == null || slices.size() == 0) {
return null;
}
-
+
Set<String> liveNodes = clusterState.getLiveNodes();
Iterator<Slice> it = slices.iterator();
while (it.hasNext()) {
Slice slice = it.next();
- Map<String,Replica> sliceShards = slice.getReplicasMap();
+ Map<String, Replica> sliceShards = slice.getReplicasMap();
for (ZkNodeProps nodeProps : sliceShards.values()) {
ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
if (liveNodes.contains(coreNodeProps.getNodeName())
@@ -562,21 +559,21 @@ public class SolrDispatchFilter implemen
}
return null;
}
-
+
private SolrCore getCoreByCollection(CoreContainer cores, String corename, String path) {
String collection = corename;
ZkStateReader zkStateReader = cores.getZkController().getZkStateReader();
-
+
ClusterState clusterState = zkStateReader.getClusterState();
- Map<String,Slice> slices = clusterState.getActiveSlicesMap(collection);
+ Map<String, Slice> slices = clusterState.getActiveSlicesMap(collection);
if (slices == null) {
return null;
}
// look for a core on this node
- Set<Entry<String,Slice>> entries = slices.entrySet();
+ Set<Entry<String, Slice>> entries = slices.entrySet();
SolrCore core = null;
done:
- for (Entry<String,Slice> entry : entries) {
+ for (Entry<String, Slice> entry : entries) {
// first see if we have the leader
ZkNodeProps leaderProps = clusterState.getLeader(collection, entry.getKey());
if (leaderProps != null) {
@@ -585,11 +582,11 @@ public class SolrDispatchFilter implemen
if (core != null) {
break done;
}
-
+
// check everyone then
- Map<String,Replica> shards = entry.getValue().getReplicasMap();
- Set<Entry<String,Replica>> shardEntries = shards.entrySet();
- for (Entry<String,Replica> shardEntry : shardEntries) {
+ Map<String, Replica> shards = entry.getValue().getReplicasMap();
+ Set<Entry<String, Replica>> shardEntries = shards.entrySet();
+ for (Entry<String, Replica> shardEntry : shardEntries) {
Replica zkProps = shardEntry.getValue();
core = checkProps(cores, path, zkProps);
if (core != null) {
@@ -601,7 +598,7 @@ public class SolrDispatchFilter implemen
}
private SolrCore checkProps(CoreContainer cores, String path,
- ZkNodeProps zkProps) {
+ ZkNodeProps zkProps) {
String corename;
SolrCore core = null;
if (cores.getZkController().getNodeName().equals(zkProps.getStr(ZkStateReader.NODE_NAME_PROP))) {
@@ -627,12 +624,12 @@ public class SolrDispatchFilter implemen
private void writeResponse(SolrQueryResponse solrRsp, ServletResponse response,
QueryResponseWriter responseWriter, SolrQueryRequest solrReq, Method reqMethod)
- throws IOException {
+ throws IOException {
// Now write it out
final String ct = responseWriter.getContentType(solrReq, solrRsp);
// don't call setContentType on null
- if (null != ct) response.setContentType(ct);
+ if (null != ct) response.setContentType(ct);
if (solrRsp.getException() != null) {
NamedList info = new SimpleOrderedMap();
@@ -640,7 +637,7 @@ public class SolrDispatchFilter implemen
solrRsp.add("error", info);
((HttpServletResponse) response).setStatus(code);
}
-
+
if (Method.HEAD != reqMethod) {
if (responseWriter instanceof BinaryQueryResponseWriter) {
BinaryQueryResponseWriter binWriter = (BinaryQueryResponseWriter) responseWriter;
@@ -648,8 +645,8 @@ public class SolrDispatchFilter implemen
} else {
String charset = ContentStreamBase.getCharsetFromContentType(ct);
Writer out = (charset == null || charset.equalsIgnoreCase("UTF-8"))
- ? new OutputStreamWriter(response.getOutputStream(), UTF8)
- : new OutputStreamWriter(response.getOutputStream(), charset);
+ ? new OutputStreamWriter(response.getOutputStream(), UTF8)
+ : new OutputStreamWriter(response.getOutputStream(), charset);
out = new FastWriter(out);
responseWriter.write(out, solrReq, solrRsp);
out.flush();
@@ -657,49 +654,48 @@ public class SolrDispatchFilter implemen
}
//else http HEAD request, nothing to write out, waited this long just to get ContentType
}
-
- protected void execute( HttpServletRequest req, SolrRequestHandler handler, SolrQueryRequest sreq, SolrQueryResponse rsp) {
+
+ 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 );
// used for logging query stats in SolrCore.execute()
- sreq.getContext().put( "webapp", req.getContextPath() );
- sreq.getCore().execute( handler, sreq, rsp );
+ sreq.getContext().put("webapp", req.getContextPath());
+ sreq.getCore().execute(handler, sreq, rsp);
}
- protected void sendError(SolrCore core,
- SolrQueryRequest req,
- ServletRequest request,
- HttpServletResponse response,
- Throwable ex) throws IOException {
+ protected void sendError(SolrCore core,
+ SolrQueryRequest req,
+ ServletRequest request,
+ HttpServletResponse response,
+ Throwable ex) throws IOException {
try {
SolrQueryResponse solrResp = new SolrQueryResponse();
- if(ex instanceof Exception) {
- solrResp.setException((Exception)ex);
- }
- else {
+ if (ex instanceof Exception) {
+ solrResp.setException((Exception) ex);
+ } else {
solrResp.setException(new RuntimeException(ex));
}
- if(core==null) {
+ if (core == null) {
core = cores.getCore(""); // default core
}
- if(req==null) {
+ if (req == null) {
final SolrParams solrParams;
if (request instanceof HttpServletRequest) {
// use GET parameters if available:
solrParams = SolrRequestParsers.parseQueryString(((HttpServletRequest) request).getQueryString());
} else {
// we have no params at all, use empty ones:
- solrParams = new MapSolrParams(Collections.<String,String>emptyMap());
+ solrParams = new MapSolrParams(Collections.<String, String>emptyMap());
}
- req = new SolrQueryRequestBase(core, solrParams) {};
+ req = new SolrQueryRequestBase(core, solrParams) {
+ };
}
QueryResponseWriter writer = core.getQueryResponseWriter(req);
writeResponse(solrResp, response, writer, req, Method.GET);
- }
- catch( Throwable t ) { // This error really does not matter
+ } catch (Throwable t) { // This error really does not matter
SimpleOrderedMap info = new SimpleOrderedMap();
int code = ResponseUtils.getErrorInfo(ex, info, log);
- response.sendError( code, info.toString() );
+ response.sendError(code, info.toString());
}
}
@@ -710,24 +706,24 @@ public class SolrDispatchFilter implemen
* Set the prefix for all paths. This is useful if you want to apply the
* filter to something other then /*, perhaps because you are merging this
* filter into a larger web application.
- *
+ * <p/>
* For example, if web.xml specifies:
* <pre class="prettyprint">
* {@code
* <filter-mapping>
- * <filter-name>SolrRequestFilter</filter-name>
- * <url-pattern>/xxx/*</url-pattern>
+ * <filter-name>SolrRequestFilter</filter-name>
+ * <url-pattern>/xxx/*</url-pattern>
* </filter-mapping>}
* </pre>
- *
+ * <p/>
* Make sure to set the PathPrefix to "/xxx" either with this function
* or in web.xml.
- *
+ * <p/>
* <pre class="prettyprint">
* {@code
* <init-param>
- * <param-name>path-prefix</param-name>
- * <param-value>/xxx</param-value>
+ * <param-name>path-prefix</param-name>
+ * <param-value>/xxx</param-value>
* </init-param>}
* </pre>
*/