Apache Lucene open-source search software
SOLR-1123: Changed JSONResponseWriter content-type to be application/json by default
Christopher John Malef55c72f92880
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 20d7caf28ac..14b6fa0c831 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -360,6 +360,10 @@ Other Changes* SOLR-2862: More explicit lexical resources location logged if Carrot2 clusteringextension is used. Fixed solr. impl. of IResource and IResourceLookup. (Dawid Weiss)+* SOLR-1123: Changed JSONResponseWriter to now use application/json as its Content-Type+ by default. However the Content-Type can be overwritten and is set to text/plain in+ the example configuration. (Chris Male)+Documentation----------------------diff --git a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.javaindex 4a9e0f81a82..c14a2a57a23 100644--- a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java+++ b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java@@ -40,9 +40,13 @@ import org.apache.solr.search.ReturnFields;*/public class JSONResponseWriter implements QueryResponseWriter {- static String CONTENT_TYPE_JSON_UTF8="text/x-json; charset=UTF-8";+ static String CONTENT_TYPE_JSON_UTF8="application/json; charset=UTF-8";- public void init(NamedList n) {+ private String contentType;++ public void init(NamedList namedList) {+ String contentType = (String) namedList.get("content-type");+ this.contentType = (contentType != null) ? contentType : CONTENT_TYPE_JSON_UTF8;}public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {@@ -55,12 +59,10 @@ public class JSONResponseWriter implements QueryResponseWriter {}public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {- // using the text/plain allows this to be viewed in the browser easily- return CONTENT_TYPE_TEXT_UTF8;+ return contentType;}}-class JSONWriter extends TextResponseWriter {private String namedListStyle;private String wrapperFunction;diff --git a/solr/example/solr/conf/solrconfig.xml b/solr/example/solr/conf/solrconfig.xmlindex cc8a5f304f0..b3df56e5915 100755--- a/solr/example/solr/conf/solrconfig.xml+++ b/solr/example/solr/conf/solrconfig.xml@@ -1572,6 +1572,15 @@<queryResponseWriter name="phps" class="solr.PHPSerializedResponseWriter"/><queryResponseWriter name="csv" class="solr.CSVResponseWriter"/>-->++ <queryResponseWriter name="json" class="solr.JSONResponseWriter">+ <!-- For the purposes of the tutorial, JSON responses are written as+ plain text so that they are easy to read in *any* browser.+ If you expect a MIME type of "application/json" just remove this override.+ -->+ <str name="content-type">text/plain; charset=UTF-8</str>+ </queryResponseWriter>+<!--Custom response writers can be declared as needed...-->