diff --git a/CHANGES.txt b/CHANGES.txt
index 56ab3581124..e85b8ea7873 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -148,6 +148,11 @@ New Features
and a bevy of new and renamed options (see the wiki).
(Mike Krimerman, Scott Taber via klaas).
+29. SOLR-408: Added PingRequestHandler and deprecated SolrCore.getPingQueryRequest().
+ Ping requests should be configured using standard RequestHandler syntax in
+ solrconfig.xml rather then using the syntax.
+ (Karsten Sperling via ryan)
+
Changes in runtime behavior
diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java b/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
index 33eacd354a4..d21b14731be 100644
--- a/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
+++ b/client/java/solrj/src/org/apache/solr/client/solrj/request/SolrPing.java
@@ -34,18 +34,19 @@ import org.apache.solr.common.util.ContentStream;
*/
public class SolrPing extends RequestBase
{
+ private ModifiableSolrParams params;
+
public SolrPing()
{
super( METHOD.GET, "/admin/ping" );
+ params = new ModifiableSolrParams();
}
public Collection getContentStreams() {
return null;
}
- public SolrParams getParams() {
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set( "q", "solrpingquery" );
+ public ModifiableSolrParams getParams() {
return params;
}
diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java b/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java
index 8bac75ca198..db86963d8fc 100644
--- a/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java
+++ b/client/java/solrj/test/org/apache/solr/client/solrj/SolrExampleTests.java
@@ -28,6 +28,7 @@ import junit.framework.Assert;
import org.apache.solr.client.solrj.request.DirectXmlRequest;
import org.apache.solr.client.solrj.request.LukeRequest;
+import org.apache.solr.client.solrj.request.SolrPing;
import org.apache.solr.client.solrj.response.LukeResponse;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
@@ -255,7 +256,6 @@ abstract public class SolrExampleTests extends SolrExampleTestBase
assertNumFound( "*:*", 0 ); // make sure it got out
}
-
public void testLukeHandler() throws Exception
{
SolrServer server = getSolrServer();
@@ -281,4 +281,28 @@ abstract public class SolrExampleTests extends SolrExampleTestBase
rsp = luke.process( server );
assertNotNull( rsp.getFieldTypeInfo() );
}
+
+
+ public void testPingHandler() throws Exception
+ {
+ SolrServer server = getSolrServer();
+
+ // Empty the database...
+ server.deleteByQuery( "*:*" );// delete everything!
+ server.commit();
+ assertNumFound( "*:*", 0 ); // make sure it got in
+
+ // should be ok
+ server.ping();
+
+ try {
+ SolrPing ping = new SolrPing();
+ ping.getParams().set( "qt", "unknown handler!" );
+ ping.process( server );
+ fail( "sent unknown query type!" );
+ }
+ catch( Exception ex ) {
+ // expected
+ }
+ }
}
diff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xml
index 39ee7496d04..d727465d7fe 100755
--- a/example/solr/conf/solrconfig.xml
+++ b/example/solr/conf/solrconfig.xml
@@ -455,6 +455,15 @@
+
+
+
+ standard
+ solrpingquery
+ all
+
+
+
@@ -523,12 +532,7 @@
solr
solrconfig.xml schema.xml admin-extra.html
-
-
- qt=standard&q=solrpingquery
-
+
diff --git a/src/java/org/apache/solr/core/SolrConfig.java b/src/java/org/apache/solr/core/SolrConfig.java
index c1da047c60b..942120b789f 100644
--- a/src/java/org/apache/solr/core/SolrConfig.java
+++ b/src/java/org/apache/solr/core/SolrConfig.java
@@ -18,6 +18,7 @@
package org.apache.solr.core;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.handler.PingRequestHandler;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
@@ -151,7 +152,9 @@ public class SolrConfig extends Config {
// default & main index configurations
public final SolrIndexConfig defaultIndexConfig;
public final SolrIndexConfig mainIndexConfig;
+
// ping query request parameters
+ @Deprecated
private final NamedList pingQueryParams;
static private NamedList readPingQueryParams(SolrConfig config) {
@@ -172,7 +175,10 @@ public class SolrConfig extends Config {
/**
* Returns a Request object based on the admin/pingQuery section
* of the Solr config file.
+ *
+ * @use {@link PingRequestHandler} instead
*/
+ @Deprecated
public SolrQueryRequest getPingQueryRequest(SolrCore core) {
return new LocalSolrQueryRequest(core, pingQueryParams);
}
diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java
index 875a3ff168a..2ef4c5c5282 100644
--- a/src/java/org/apache/solr/core/SolrCore.java
+++ b/src/java/org/apache/solr/core/SolrCore.java
@@ -42,6 +42,7 @@ import org.apache.solr.common.params.CommonParams.EchoParamStyle;
import org.apache.solr.common.util.DOMUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.handler.PingRequestHandler;
import org.apache.solr.highlight.SolrHighlighter;
import org.apache.solr.request.JSONResponseWriter;
import org.apache.solr.request.PythonResponseWriter;
@@ -235,7 +236,7 @@ public final class SolrCore {
/**
- * @return the last core initalized. If you are using multiple cores,
+ * @return the last core initialized. If you are using multiple cores,
* this is not a function to use.
*/
@Deprecated
@@ -389,7 +390,10 @@ public final class SolrCore {
/**
* Returns a Request object based on the admin/pingQuery section
* of the Solr config file.
+ *
+ * @use {@link PingRequestHandler} instead
*/
+ @Deprecated
public SolrQueryRequest getPingQueryRequest() {
return solrConfig.getPingQueryRequest(this);
}
diff --git a/src/java/org/apache/solr/handler/PingRequestHandler.java b/src/java/org/apache/solr/handler/PingRequestHandler.java
new file mode 100644
index 00000000000..1a5c93d5733
--- /dev/null
+++ b/src/java/org/apache/solr/handler/PingRequestHandler.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.handler;
+
+import java.io.File;
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrQueryResponse;
+import org.apache.solr.request.SolrRequestHandler;
+
+
+/**
+ * Ping solr core
+ *
+ * @since solr 1.3
+ */
+public class PingRequestHandler extends RequestHandlerBase
+{
+ @Override
+ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
+ {
+ SolrParams params = req.getParams();
+ SolrParams required = params.required();
+ SolrCore core = req.getCore();
+
+ // Check if the service is available
+ String healthcheck = core.getSolrConfig().get("admin/healthcheck/text()", null );
+ if( healthcheck != null && !new File(healthcheck).exists() ) {
+ throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Service disabled", true);
+ }
+
+ // Get the RequestHandler
+ String qt = required.get( CommonParams.QT );
+ SolrRequestHandler handler = core.getRequestHandler( qt );
+ if( handler == null ) {
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
+ "Unknown RequestHandler: "+qt );
+ }
+
+ // Execute the ping query and catch any possible exception
+ Throwable ex = null;
+ try {
+ SolrQueryResponse pingrsp = new SolrQueryResponse();
+ core.execute(handler, req, pingrsp );
+ ex = pingrsp.getException();
+ }
+ catch( Throwable th ) {
+ ex = th;
+ }
+
+ // Send an error or an 'OK' message (response code will be 200)
+ if( ex != null ) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Ping query caused exception: "+ex.getMessage(), ex );
+ }
+ rsp.add( "status", "OK" );
+ }
+
+
+ //////////////////////// SolrInfoMBeans methods //////////////////////
+
+ @Override
+ public String getVersion() {
+ return "$Revision$";
+ }
+
+ @Override
+ public String getDescription() {
+ return "Reports application health to a load-balancer";
+ }
+
+ @Override
+ public String getSourceId() {
+ return "$Id$";
+ }
+
+ @Override
+ public String getSource() {
+ return "$URL$";
+ }
+}
diff --git a/src/webapp/WEB-INF/web.xml b/src/webapp/WEB-INF/web.xml
index f3eaa2a0268..13669b3eae9 100644
--- a/src/webapp/WEB-INF/web.xml
+++ b/src/webapp/WEB-INF/web.xml
@@ -64,6 +64,7 @@
2
+
ping
/admin/ping.jsp
@@ -79,6 +80,7 @@
/update/*
+
ping
/admin/ping
diff --git a/src/webapp/resources/admin/ping.jsp b/src/webapp/resources/admin/ping.jsp
index a85775c5f9e..6987f0d671f 100644
--- a/src/webapp/resources/admin/ping.jsp
+++ b/src/webapp/resources/admin/ping.jsp
@@ -29,6 +29,10 @@
<%
+//
+// Deprecated -- use PingRequestHandler
+//
+
Object ocore = request.getAttribute("org.apache.solr.SolrCore");
SolrCore core = ocore instanceof SolrCore? (SolrCore) ocore : SolrCore.getSolrCore();