SOLR-1123: Changed JSONResponseWriter content-type to be application/json by default

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1204327 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christopher John Male 2011-11-21 02:50:39 +00:00
parent b649e35381
commit f55c72f928
3 changed files with 20 additions and 5 deletions

View File

@ -360,6 +360,10 @@ Other Changes
* SOLR-2862: More explicit lexical resources location logged if Carrot2 clustering * SOLR-2862: More explicit lexical resources location logged if Carrot2 clustering
extension is used. Fixed solr. impl. of IResource and IResourceLookup. (Dawid Weiss) extension 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 Documentation
---------------------- ----------------------

View File

@ -40,9 +40,13 @@ import org.apache.solr.search.ReturnFields;
*/ */
public class JSONResponseWriter implements QueryResponseWriter { 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 { 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) { public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
// using the text/plain allows this to be viewed in the browser easily return contentType;
return CONTENT_TYPE_TEXT_UTF8;
} }
} }
class JSONWriter extends TextResponseWriter { class JSONWriter extends TextResponseWriter {
private String namedListStyle; private String namedListStyle;
private String wrapperFunction; private String wrapperFunction;

View File

@ -1572,6 +1572,15 @@
<queryResponseWriter name="phps" class="solr.PHPSerializedResponseWriter"/> <queryResponseWriter name="phps" class="solr.PHPSerializedResponseWriter"/>
<queryResponseWriter name="csv" class="solr.CSVResponseWriter"/> <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... Custom response writers can be declared as needed...
--> -->