SOLR-3005: Fixed JSONResponseWriter content type disappearing when only default writers used

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1243870 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christopher John Male 2012-02-14 10:58:43 +00:00
parent d537ecf07f
commit e36f317d7b
3 changed files with 14 additions and 4 deletions

View File

@ -420,6 +420,9 @@ Other Changes
* SOLR-2105: Remove support for deprecated "update.processor" (since 3.2), in favor of * SOLR-2105: Remove support for deprecated "update.processor" (since 3.2), in favor of
"update.chain" (janhoy) "update.chain" (janhoy)
* SOLR-3005: Default QueryResponseWriters are now initialized via init() with an empty
NamedList. (Gasol Wu, Chris Male)
Documentation Documentation
---------------------- ----------------------

View File

@ -1650,8 +1650,13 @@ public final class SolrCore implements SolrInfoMBean {
} }
} }
NamedList emptyList = new NamedList();
for (Map.Entry<String, QueryResponseWriter> entry : DEFAULT_RESPONSE_WRITERS.entrySet()) { for (Map.Entry<String, QueryResponseWriter> entry : DEFAULT_RESPONSE_WRITERS.entrySet()) {
if(responseWriters.get(entry.getKey()) == null) responseWriters.put(entry.getKey(), entry.getValue()); if(responseWriters.get(entry.getKey()) == null) {
responseWriters.put(entry.getKey(), entry.getValue());
// call init so any logic in the default writers gets invoked
entry.getValue().init(emptyList);
}
} }
// configure the default response writer; this one should never be null // configure the default response writer; this one should never be null

View File

@ -40,13 +40,15 @@ import org.apache.solr.search.ReturnFields;
*/ */
public class JSONResponseWriter implements QueryResponseWriter { public class JSONResponseWriter implements QueryResponseWriter {
static String CONTENT_TYPE_JSON_UTF8="application/json; charset=UTF-8"; static String CONTENT_TYPE_JSON_UTF8 = "application/json; charset=UTF-8";
private String contentType; private String contentType = CONTENT_TYPE_JSON_UTF8;
public void init(NamedList namedList) { public void init(NamedList namedList) {
String contentType = (String) namedList.get("content-type"); String contentType = (String) namedList.get("content-type");
this.contentType = (contentType != null) ? contentType : CONTENT_TYPE_JSON_UTF8; if (contentType != null) {
this.contentType = contentType;
}
} }
public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {