预期的 MIME 类型 application/xml 但得到 text/html
Expected mime type application/xml but got text/html
我在 eclipse 中尝试 solrj 但我收到了这个错误消息:
org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Expected mime type application/xml but got text/html
at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:512)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:210)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:206)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:91)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
at pack.SearchServlet.service(SearchServlet.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
下面是我的代码:
queryString=request.getParameter("query");
keywords=queryString.split(" ");
server=new HttpSolrServer(url);
server.setMaxRetries(1);
server.setConnectionTimeout(5000);
server.setParser(new XMLResponseParser());
server.setSoTimeout(1000);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false);
server.setAllowCompression(true);
query=new SolrQuery();
query.setQuery("title:"+keywords[0]+" OR content"+keywords[0]);
query.setStart(0);
query.setRows(8);
query.setHighlight(true);
query.addHighlightField("content");
query.addHighlightField("title");
queryResponse=server.query(query);
查看 Solr 服务器控制台或日志文件。很可能你得到了 URL 错误并返回了 HTML 错误页面而不是 Solr 响应。服务器日志中应该有特定错误。
我猜您正在使用相当现代的 solrj 与相当古老的 solr 对话。 This bug 提到 mime 类型比较过于严格的问题。
最简单(但可能不是最好)的解决方案可能是降级您的 solrj 文件。我不知道问题是什么时候发生的,但我知道我的东西可以与 solr-solrj-4.3.1.jar
运行 一起用于 solr 1.4 安装。
我通过扩展 XMLResponseParser
、覆盖 getContentType
并将其用作响应解析器来解决这个问题。
protected class QESXMLResponseParser extends XMLResponseParser {
public QESXMLResponseParser() {
super();
}
@Override
public String getContentType() {
return "text/xml; charset=UTF-8";
}
}
然后,只需更改您的代码以使用 "new parser"
server.setConnectionTimeout(5000);
server.setParser(new QESXMLResponseParser());
server.setSoTimeout(1000);
我在 eclipse 中尝试 solrj 但我收到了这个错误消息:
org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Expected mime type application/xml but got text/html
at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:512)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:210)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:206)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:91)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
at pack.SearchServlet.service(SearchServlet.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
下面是我的代码:
queryString=request.getParameter("query");
keywords=queryString.split(" ");
server=new HttpSolrServer(url);
server.setMaxRetries(1);
server.setConnectionTimeout(5000);
server.setParser(new XMLResponseParser());
server.setSoTimeout(1000);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false);
server.setAllowCompression(true);
query=new SolrQuery();
query.setQuery("title:"+keywords[0]+" OR content"+keywords[0]);
query.setStart(0);
query.setRows(8);
query.setHighlight(true);
query.addHighlightField("content");
query.addHighlightField("title");
queryResponse=server.query(query);
查看 Solr 服务器控制台或日志文件。很可能你得到了 URL 错误并返回了 HTML 错误页面而不是 Solr 响应。服务器日志中应该有特定错误。
我猜您正在使用相当现代的 solrj 与相当古老的 solr 对话。 This bug 提到 mime 类型比较过于严格的问题。
最简单(但可能不是最好)的解决方案可能是降级您的 solrj 文件。我不知道问题是什么时候发生的,但我知道我的东西可以与 solr-solrj-4.3.1.jar
运行 一起用于 solr 1.4 安装。
我通过扩展 XMLResponseParser
、覆盖 getContentType
并将其用作响应解析器来解决这个问题。
protected class QESXMLResponseParser extends XMLResponseParser {
public QESXMLResponseParser() {
super();
}
@Override
public String getContentType() {
return "text/xml; charset=UTF-8";
}
}
然后,只需更改您的代码以使用 "new parser"
server.setConnectionTimeout(5000);
server.setParser(new QESXMLResponseParser());
server.setSoTimeout(1000);