SolrJ - 从JSP连接到Zookeeper时出错

时间:2015-11-07 18:20:03

标签: solr solrj

如果我尝试从运行在webapp中的JSP或Servlet连接到Zookeeper,我会收到错误。我正在使用Weblogic Application Server。我的JSP使用SolrJ类CloudSolrServer连接到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并得到了同样的错误。

1 个答案:

答案 0 :(得分:0)

这是Zookeeper 3.4.5中的一个错误。 https://issues.apache.org/jira/browse/ZOOKEEPER-1696

我在Weblogic中部署了zookeeper 3.4.6并使其正常工作。