get content-type from request writer

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@421669 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2006-07-13 17:22:21 +00:00
parent 20711a9227
commit bf363aafc7
3 changed files with 12 additions and 7 deletions

View File

@ -24,6 +24,11 @@ import java.io.IOException;
* @version $Id$
*/
public interface QueryResponseWriter {
public static String CONTENT_TYPE_XML_UTF8="text/xml;charset=UTF-8";
public static String CONTENT_TYPE_TEXT_UTF8="text/plain;charset=UTF-8";
public static String CONTENT_TYPE_TEXT_ASCII="text/plain;charset=US-ASCII";
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException;
public String getContentType(SolrQueryRequest request, SolrQueryResponse response);
}

View File

@ -28,6 +28,10 @@ public class XMLResponseWriter implements QueryResponseWriter {
public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
XMLWriter.writeResponse(writer,req,rsp);
}
public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
return CONTENT_TYPE_XML_UTF8;
}
}

View File

@ -43,8 +43,6 @@ public class SolrServlet extends HttpServlet {
final Logger log = Logger.getLogger(SolrServlet.class.getName());
SolrCore core;
private static String CONTENT_TYPE="text/xml;charset=UTF-8";
public void init() throws ServletException {
log.info("SolrServlet.init()");
@ -90,13 +88,11 @@ public class SolrServlet extends HttpServlet {
try {
solrRsp = new SolrQueryResponse();
solrReq = new SolrServletRequest(core, request);
// log.severe("REQUEST PARAMS:" + solrReq.getParamString());
core.execute(solrReq, solrRsp);
if (solrRsp.getException() == null) {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
response.setContentType(responseWriter.getContentType(solrReq, solrRsp));
PrintWriter out = response.getWriter();
responseWriter.write(out, solrReq, solrRsp);
} else {
Exception e = solrRsp.getException();
@ -122,7 +118,7 @@ public class SolrServlet extends HttpServlet {
try {
// hmmm, what if this was already set to text/xml?
try{
response.setContentType(CONTENT_TYPE);
response.setContentType(QueryResponseWriter.CONTENT_TYPE_TEXT_UTF8);
// response.setCharacterEncoding("UTF-8");
} catch (Exception e) {}
try{response.setStatus(rc);} catch (Exception e) {}