You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ch...@apache.org on 2011/11/21 03:59:10 UTC

svn commit: r1204329 - in /lucene/dev/branches/branch_3x/solr: CHANGES.txt core/ core/src/java/org/apache/solr/response/JSONResponseWriter.java example/solr/conf/solrconfig.xml

Author: chrism
Date: Mon Nov 21 02:59:10 2011
New Revision: 1204329

URL: http://svn.apache.org/viewvc?rev=1204329&view=rev
Log:
SOLR-1123: Changed JSONResponseWriter content-type to be application/json by default

Modified:
    lucene/dev/branches/branch_3x/solr/CHANGES.txt
    lucene/dev/branches/branch_3x/solr/core/   (props changed)
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
    lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml

Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1204329&r1=1204328&r2=1204329&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Mon Nov 21 02:59:10 2011
@@ -161,6 +161,10 @@ Bug Fixes
 * SOLR-2849: Fix dependencies in Maven POMs. (David Smiley via Steve Rowe)
 
 * SOLR-2591: Remove commitLockTimeout option from solrconfig.xml (Luca Cavanna via Martijn van Groningen)
+
+* 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)
   
 ==================  3.4.0  ==================
 

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java?rev=1204329&r1=1204328&r2=1204329&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java (original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java Mon Nov 21 02:59:10 2011
@@ -41,9 +41,13 @@ import java.util.*;
  */
 
 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 {
@@ -56,12 +60,10 @@ public class JSONResponseWriter implemen
   }
 
   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 {
 
   // cache the calendar instance in case we are writing many dates...

Modified: lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml?rev=1204329&r1=1204328&r2=1204329&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml (original)
+++ lucene/dev/branches/branch_3x/solr/example/solr/conf/solrconfig.xml Mon Nov 21 02:59:10 2011
@@ -1537,6 +1537,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...
     -->