0
如果我嘗試從運行在webapp中的JSP或Servlet嘗試連接到Zookeeper,則出現錯誤。我正在使用Weblogic應用程序服務器。我的JSP使用SolrJ類CloudSolrServer連接到Zookeeper。SolrJ - 從JSP連接到Zookeeper時出錯
<%@page import="java.io.IOException" %>
<%@page import="java.io.PrintStream" %>
<%@page import="java.util.List" %>
<%@page import="java.util.Map" %>
<%@page import="org.apache.solr.client.solrj.SolrQuery" %>
<%@page import="org.apache.solr.client.solrj.SolrQuery.ORDER" %>
<%@page import="org.apache.solr.client.solrj.SolrServerException" %>
<%@page import="org.apache.solr.client.solrj.impl.CloudSolrServer" %>
<%@page import="org.apache.solr.client.solrj.response.QueryResponse" %>
<%@page import="org.apache.solr.client.solrj.response.SpellCheckResponse" %>
<%@page import="org.apache.solr.client.solrj.response.SpellCheckResponse.Suggestion" %>
<%@page import="org.apache.solr.common.SolrDocument" %>
<%@page import="org.apache.solr.common.SolrDocumentList" %>
<%
String zkHost = "host:2181";
CloudSolrServer server = new CloudSolrServer(zkHost);
SolrQuery params = new SolrQuery();
String q = "some query";
params.set("collection", new String[] { "my_collection" });
params.set("q", new String[] { "text_en:" + q });
params.set("fl", new String[] { "*,score" });
params.set("start", new String[] { "0" });
params.set("rows", new String[] { "10" });
params.setHighlightSimplePre("<em>");
params.setHighlightSimplePost("</em>");
params.addHighlightField("name");
params.setHighlight(true);
params.setSortField("score", SolrQuery.ORDER.desc);
params.set("timeAllowed", new String[] { "30000" });
params.set("wt", new String[] { "json" });
QueryResponse response2 = null;
try {
response2 = server.query(params);
} catch (SolrServerException e) {
out.println(e.getMessage());
e.printStackTrace(response.getWriter());
e.printStackTrace();
} catch (Exception e) {
out.println(e.getMessage());
e.printStackTrace(response.getWriter());
e.printStackTrace();
} finally {
server.shutdown();
}
%>
我在執行JSP頁面時遇到錯誤。
org.apache.solr.client.solrj.SolrServerException: Error executing query
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:98)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
at jsp_servlet._solr.__solrtest._jspService(__solrtest.java:102)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3748)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3714)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2283)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2182)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1491)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.lang.RuntimeException: java.util.concurrent.TimeoutException: Could not connect to ZooKeeper host:2181 within 10000 ms
at org.apache.solr.common.cloud.SolrZkClient.<init>(SolrZkClient.java:142)
at org.apache.solr.common.cloud.SolrZkClient.<init>(SolrZkClient.java:88)
at org.apache.solr.common.cloud.ZkStateReader.<init>(ZkStateReader.java:150)
at org.apache.solr.client.solrj.impl.CloudSolrServer.connect(CloudSolrServer.java:240)
at org.apache.solr.client.solrj.impl.CloudSolrServer.request(CloudSolrServer.java:501)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)
... 22 more
Caused by: java.util.concurrent.TimeoutException: Could not connect to ZooKeeper host:2181 within 10000 ms
at org.apache.solr.common.cloud.ConnectionManager.waitForConnected(ConnectionManager.java:169)
at org.apache.solr.common.cloud.SolrZkClient.<init>(SolrZkClient.java:134)
... 27 more
我試圖增加超時,但沒有幫助。另外我知道它不是超時的問題,因爲從獨立的java程序執行時,相同的代碼工作正常。但是,它在Weblogic中運行的Web應用程序中執行時會失敗。我試圖將其轉換爲一個servlet並得到相同的錯誤。
注 - 此問題與http://zookeeper-user.578899.n2.nabble.com/While-Connecting-to-Solr-through-the-Zookeeper-im-getting-this-error-td7581579類似。沒有被回答的HTML。 – Sri999