2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.solr.response;
20
import java.io.Writer;
21
import java.io.IOException;
23
import org.apache.solr.common.util.NamedList;
24
import org.apache.solr.request.SolrQueryRequest;
25
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
28
* Implementations of <code>QueryResponseWriter</code> are used to format responses to query requests.
30
* Different <code>QueryResponseWriter</code>s are registered with the <code>SolrCore</code>.
31
* One way to register a QueryResponseWriter with the core is through the <code>solrconfig.xml</code> file.
33
* Example <code>solrconfig.xml</code> entry to register a <code>QueryResponseWriter</code> implementation to
34
* handle all queries with a writer type of "simple":
37
* <queryResponseWriter name="simple" class="foo.SimpleResponseWriter" />
40
* A single instance of any registered QueryResponseWriter is created
41
* via the default constructor and is reused for all relevant queries.
43
* @version $Id: QueryResponseWriter.java 1075192 2011-02-28 00:50:09Z uschindler $
45
public interface QueryResponseWriter extends NamedListInitializedPlugin {
46
public static String CONTENT_TYPE_XML_UTF8="application/xml; charset=UTF-8";
47
public static String CONTENT_TYPE_TEXT_UTF8="text/plain; charset=UTF-8";
48
public static String CONTENT_TYPE_TEXT_ASCII="text/plain; charset=US-ASCII";
51
* Write a SolrQueryResponse, this method must be thread save.
54
* Information about the request (in particular: formating options) may be
55
* obtained from <code>req</code> but the dominant source of information
56
* should be <code>rsp</code>.
58
* There are no mandatory actions that write must perform.
59
* An empty write implementation would fulfill
60
* all interface obligations.
63
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException;
66
* Return the applicable Content Type for a request, this method
67
* must be thread safe.
70
* QueryResponseWriter's must implement this method to return a valid
71
* HTTP Content-Type header for the request, that will logically
72
* correspond with the output produced by the write method.
74
* @return a Content-Type string, which may not be null.
76
public String getContentType(SolrQueryRequest request, SolrQueryResponse response);
78
/** <code>init</code> will be called just once, immediately after creation.
79
* <p>The args are user-level initialization parameters that
80
* may be specified when declaring a response writer in
83
public void init(NamedList args);