diff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xml index 6b8aa9d2e8b..7217dc6452a 100755 --- a/example/solr/conf/solrconfig.xml +++ b/example/solr/conf/solrconfig.xml @@ -379,7 +379,12 @@ --> - + + + explicit + true + + diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java index 281dfb58952..1d07cb40414 100644 --- a/src/java/org/apache/solr/core/SolrCore.java +++ b/src/java/org/apache/solr/core/SolrCore.java @@ -39,10 +39,12 @@ import org.apache.solr.request.JSONResponseWriter; import org.apache.solr.request.PythonResponseWriter; import org.apache.solr.request.QueryResponseWriter; import org.apache.solr.request.RubyResponseWriter; +import org.apache.solr.request.SolrParams; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryResponse; import org.apache.solr.request.SolrRequestHandler; import org.apache.solr.request.XMLResponseWriter; +import org.apache.solr.request.SolrParams.EchoParamStyle; import org.apache.solr.schema.IndexSchema; import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.update.DirectUpdateHandler; @@ -649,10 +651,10 @@ public final class SolrCore { public void execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp) { // setup response header and handle request - final NamedList responseHeader = new SimpleOrderedMap(); + final NamedList responseHeader = new SimpleOrderedMap(); rsp.add("responseHeader", responseHeader); handler.handleRequest(req,rsp); - setResponseHeaderValues(responseHeader,req,rsp); + setResponseHeaderValues(handler,responseHeader,req,rsp); log.info(req.getContext().get("path") + " " + req.getParamString()+ " 0 "+ @@ -669,26 +671,36 @@ public final class SolrCore { execute(handler, req, rsp); } - protected void setResponseHeaderValues(NamedList responseHeader,SolrQueryRequest req, SolrQueryResponse rsp) { + protected void setResponseHeaderValues(SolrRequestHandler handler, NamedList responseHeader,SolrQueryRequest req, SolrQueryResponse rsp) { // TODO should check that responseHeader has not been replaced by handler final int qtime=(int)(rsp.getEndTime() - req.getStartTime()); responseHeader.add("status",rsp.getException()==null ? 0 : 500); responseHeader.add("QTime",qtime); + + SolrParams params = req.getParams(); + if( params.getBool(SolrParams.HEADER_ECHO_HANDLER, false) ) { + responseHeader.add("handler", handler.getName() ); + } // Values for echoParams... false/true/all or false/explicit/all ??? - final String EP_PARAM = "echoParams"; - final String EXPLICIT = "explicit"; - final String epValue = req.getParams().get(EP_PARAM); - if (EXPLICIT.equals(epValue)) { + String ep = params.get( SolrParams.HEADER_ECHO_PARAMS, null ); + if( ep != null ) { + EchoParamStyle echoParams = EchoParamStyle.get( ep ); + if( echoParams == null ) { + throw new SolrException(400,"Invalid value '" + ep + "' for " + SolrParams.HEADER_ECHO_PARAMS + + " parameter, use '" + EchoParamStyle.EXPLICIT + "' or '" + EchoParamStyle.ALL + "'" ); + } + if( echoParams == EchoParamStyle.EXPLICIT ) { responseHeader.add("params", req.getOriginalParams().toNamedList()); - } else if(epValue!=null) { - throw new SolrException(400,"Invalid value '" + epValue + "' for " + EP_PARAM + " parameter, use '" + EXPLICIT + "'"); + } + else if( echoParams == EchoParamStyle.ALL ) { + responseHeader.add("params", req.getParams().toNamedList()); + } } } - final public static void log(Throwable e) { SolrException.logOnce(log,null,e); } @@ -761,11 +773,3 @@ public final class SolrCore { } } - - - - - - - - diff --git a/src/java/org/apache/solr/request/SolrParams.java b/src/java/org/apache/solr/request/SolrParams.java index a5ee70d3262..421fbc7ac13 100644 --- a/src/java/org/apache/solr/request/SolrParams.java +++ b/src/java/org/apache/solr/request/SolrParams.java @@ -131,6 +131,35 @@ public abstract class SolrParams { */ public static final String STREAM_CONTENTTYPE = "stream.contentType"; + /** 'true' if the header should include the handler name */ + public static final String HEADER_ECHO_HANDLER = "echoHandler"; + + /** include the parameters in the header **/ + public static final String HEADER_ECHO_PARAMS = "echoParams"; + + /** valid values for: echoParams */ + public enum EchoParamStyle { + EXPLICIT, + ALL, + NONE; + + public static EchoParamStyle get( String v ) { + if( v != null ) { + v = v.toUpperCase(); + if( v.equals( "EXPLICIT" ) ) { + return EXPLICIT; + } + if( v.equals( "ALL") ) { + return ALL; + } + if( v.equals( "NONE") ) { // the same as nothing... + return NONE; + } + } + return null; + } + }; + /** returns the String value of a param, or null if not set */ public abstract String get(String param); @@ -333,3 +362,5 @@ public abstract class SolrParams { } + + diff --git a/src/java/org/apache/solr/util/TestHarness.java b/src/java/org/apache/solr/util/TestHarness.java index 3aa77e40b61..d1f424c245f 100644 --- a/src/java/org/apache/solr/util/TestHarness.java +++ b/src/java/org/apache/solr/util/TestHarness.java @@ -424,7 +424,7 @@ public class TestHarness { } public LocalSolrQueryRequest makeRequest(String ... q) { if (q.length==1) { - return new LocalSolrQueryRequest(TestHarness.this.getCore(), + return new LocalSolrQueryRequest(TestHarness.this.getCore(), q[0], qtype, start, limit, args); } diff --git a/src/test/org/apache/solr/EchoParamsTest.java b/src/test/org/apache/solr/EchoParamsTest.java index d3c0412bb5a..c678da7214b 100644 --- a/src/test/org/apache/solr/EchoParamsTest.java +++ b/src/test/org/apache/solr/EchoParamsTest.java @@ -51,4 +51,17 @@ public class EchoParamsTest extends AbstractSolrTestCase { assertQ(req("foo"),HEADER_XPATH + "/lst[@name='params']/str[@name='wt'][.='xml']"); } + public void testAllEchoParams() { + lrf = h.getRequestFactory + ("crazy_custom_qt", 0, 20, + "version","2.2", + "wt","xml", + "echoParams", "all", + "echoHandler","true" + ); + + assertQ(req("foo"),HEADER_XPATH + "/lst[@name='params']/str[@name='fl'][.='implicit']"); + assertQ(req("foo"),HEADER_XPATH + "/str[@name='handler'][.='org.apache.solr.request.StandardRequestHandler']"); + } + } diff --git a/src/test/test-files/solr/crazy-path-to-config.xml b/src/test/test-files/solr/crazy-path-to-config.xml index 376cc0e3d76..6c8a655c2c3 100644 --- a/src/test/test-files/solr/crazy-path-to-config.xml +++ b/src/test/test-files/solr/crazy-path-to-config.xml @@ -57,7 +57,11 @@ - + + + implicit + +