lucene-solr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uri Boness (JIRA)" <j...@apache.org>
Subject [jira] Commented: (SOLR-1123) Change the JSONResponseWriter content type
Date Wed, 20 May 2009 13:10:45 GMT

    [ https://issues.apache.org/jira/browse/SOLR-1123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12711133#action_12711133
] 

Uri Boness commented on SOLR-1123:
----------------------------------

I think that would be the best option. The problem right now is in the current class hierarchy
of the response writers. Basically, I think the QueryResponseWriter interface should change
to:

{code}
public interface QueryResponseWriter extends NamedListInitializedPlugin {
 
  public void write(OutputStream out, SolrQueryRequest request, SolrQueryResponse response)
throws IOException;

  public String getContentType(SolrQueryRequest request, SolrQueryResponse response);

}
{code}

Note: this interface will play nicer with the binary response writer

Then we can have an AbstractTextResponseWriter which will serve as a parent for all non-binary
response writers:

{code}
public abstract class AbstractTextResponseWriter extends NamedListInitializedPlugin {

  public final static String CONTENT_TYPE_PARAM = "contentType";
  public static String DEFAULT_CONTENT_TYPE="text/plain; charset=UTF-8";
  
  private final String contentType;
  
  protected AbstractTextResponseWriter() {
    this(DEFAULT_CONTENT_TYPE);
  }

  protected AbstractTextResponseWriter(String defaultContentType) {
    this.contentType = defaultContentType;
  }

  public void init(NamedList args) {
    String configuredContentType = (String) args.get(CONTENT_TYPE_PARAM);
    if (configuredContentType != null) {
      contentType = configuredContentType;;
    }
  }

  public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
    return contentType;
  }
 
  public final void write(OutputStream out, SolrQueryRequest request, SolrQueryResponse response)
throws IOException {
    OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
    write(writer, request, response);
  }

  protected abstract void write(Writer writer, SolrQueryRequest request, SolrQueryResponse
response) throws IOException;

}
{code}

This will make it easy for every response writer to define its default content type, yet it
will still allow to override this default using the "contentType" parameter in solrconfig.
(I assume here that there's no need to customize the content type for the binary response
writer as it's internal and specific for the current implementation).

> Change the JSONResponseWriter content type
> ------------------------------------------
>
>                 Key: SOLR-1123
>                 URL: https://issues.apache.org/jira/browse/SOLR-1123
>             Project: Solr
>          Issue Type: Improvement
>            Reporter: Uri Boness
>             Fix For: 1.5
>
>         Attachments: JSON_contentType_incl_tests.patch
>
>
> Currently the jSON content type is not used. Instead the palin/text content type is used.
The reason for this as I understand is to enable viewing the json response as as text in the
browser. While this is valid argument, I do believe that there should at least be an option
to configure this writer to use the JSON content type. According to [RFC4627|http://www.ietf.org/rfc/rfc4627.txt]
the json content type needs to be application/json (and not text/x-json). The reason this
can be very helpful is that today you have plugins for browsers (e.g. [JSONView|http://brh.numbera.com/software/jsonview])
that can render any page with application/json content type in a user friendly manner (just
like xml is supported).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message