Example usage for org.apache.solr.client.solrj SolrServerException getRootCause

List of usage examples for org.apache.solr.client.solrj SolrServerException getRootCause

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrServerException getRootCause.

Prototype

public Throwable getRootCause() 

Source Link

Usage

From source file:com.liferay.portal.search.solr.internal.server.SolrServerWrapper.java

License:Open Source License

public SolrPingResponse ping() throws IOException, SolrServerException {
    try {//from   w w  w. j av  a  2s .c  om
        return _solrServer.ping();
    } catch (SolrServerException sse) {
        if (sse.getRootCause() instanceof IOException) {
            _solrServerFactory.killServer(this);
        }

        throw sse;
    }
}

From source file:com.liferay.portal.search.solr.internal.server.SolrServerWrapper.java

License:Open Source License

public NamedList<Object> request(SolrRequest solrRequest) throws IOException, SolrServerException {

    try {//  www .  j  a va  2  s . c om
        incrementInvocationCount();

        return _solrServer.request(solrRequest);
    } catch (SolrServerException sse) {
        if (sse.getRootCause() instanceof IOException) {
            _solrServerFactory.killServer(this);
        }

        throw sse;
    }
}

From source file:cz.brmlab.yodaqa.provider.solr.Solr.java

License:Apache License

public SolrDocumentList runQuery(String q, int results) throws SolrServerException {
    SolrQuery query = new SolrQuery();
    query.setQuery(escapeQuery(q));//from   www  . java  2s .c om
    query.setRows(results);
    query.setFields("*", "score");
    QueryResponse rsp;
    while (true) {
        try {
            rsp = server.query(query, METHOD.POST);
            break; // Success!
        } catch (SolrServerException e) {
            if (e.getRootCause() instanceof IOException)
                notifyRetry(e);
            else
                throw e;
        }
    }
    return rsp.getResults();
}

From source file:cz.brmlab.yodaqa.provider.solr.Solr.java

License:Apache License

public SolrDocumentList runQuery(SolrQuery query, int results) throws SolrServerException {
    QueryResponse rsp;/*from   w ww  . j  a v  a 2  s.c  om*/
    while (true) {
        try {
            rsp = server.query(query);
            break; // Success!
        } catch (SolrServerException e) {
            if (e.getRootCause() instanceof IOException)
                notifyRetry(e);
            else
                throw e;
        }
    }
    return rsp.getResults();
}

From source file:cz.brmlab.yodaqa.provider.solr.Solr.java

License:Apache License

public String getDocText(String id) throws SolrServerException {
    String q = "id:" + id;
    SolrQuery query = new SolrQuery();
    query.setQuery(q);/*w  w  w. j  av  a  2  s.  c o  m*/
    query.setFields("text");
    QueryResponse rsp;
    while (true) {
        try {
            rsp = server.query(query);
            break; // Success!
        } catch (SolrServerException e) {
            if (e.getRootCause() instanceof IOException)
                notifyRetry(e);
            else
                throw e;
        }
    }

    String docText = "";
    if (rsp.getResults().getNumFound() > 0) {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        ArrayList<String> results = (ArrayList) rsp.getResults().get(0).getFieldValues("text");
        docText = results.get(0);
    }
    return docText;
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache.java

License:Open Source License

public void doSynchronousRebuild() {
    //try to rebuild a couple times since the Solr server may not yet be up.

    int attempts = 0;
    int maxTries = 3;
    SolrServerException exception = null;

    while (attempts < maxTries) {
        try {/*from  w w w  .  j a  v a2s. c  om*/
            attempts++;
            rebuildCacheUsingSolr(this);
            break;
        } catch (SolrServerException e) {
            exception = e;
            try {
                Thread.sleep(250);
            } catch (InterruptedException e1) {
                /*ignore interrupt*/}
        }
    }

    if (exception != null)
        log.error("Could not rebuild cache. " + exception.getRootCause().getMessage());
}

From source file:edu.cornell.mannlib.vitro.webapp.search.solr.SolrIndexer.java

License:Open Source License

/**
 * Returns true if there are documents in the index, false if there are none,
 * and returns false on failure to connect to server.
 *///from  w  ww  .  ja v  a2s  .  c o m
public boolean isIndexEmpty() {
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    try {
        QueryResponse rsp = server.query(query);
        SolrDocumentList docs = rsp.getResults();
        if (docs == null || docs.size() == 0) {
            return true;
        }
    } catch (SolrServerException e) {
        log.error("Could not connect to solr server", e.getRootCause());
    }
    return false;
}

From source file:org.apache.sentry.tests.e2e.solr.AbstractSolrSentryTestCase.java

License:Apache License

protected void verifyCollectionQueryFailure(String userName, String collectionName, String queryStr)
        throws SolrServerException, IOException {
    String tmp = getAuthenticatedUser();
    try {/*www. jav a 2  s .  c om*/
        setAuthenticationUser(userName);
        cluster.getSolrClient().query(collectionName, new SolrQuery(queryStr));
        fail("This collection query request should have failed with authorization error.");

    } catch (SolrServerException ex) {
        assertTrue(ex.getRootCause() instanceof RemoteSolrException);
        assertEquals(HttpServletResponse.SC_FORBIDDEN, ((RemoteSolrException) ex.getRootCause()).code());
    } finally {
        setAuthenticationUser(tmp);
    }
}

From source file:org.gbif.common.search.service.SolrSearchService.java

License:Apache License

/**
 * Issues a SolrQuery and converts the response to a SearchResponse object. Besides, the facets and paging
 * parameter and responses are handled in the request and response objects.
 *
 * @param searchRequest the searchRequest that contains the search parameters
 * @return the SearchResponse of the search operation
 *//*from w  ww. j  ava 2  s. c o  m*/
@Override
public SearchResponse<T, P> search(final R searchRequest) {

    try {
        // Defensive copy: done because the build method is not thread safe.
        SolrQueryBuilder<ST, P> requestBuilder = searchQueryBuilder.getCopy();
        SolrQuery solrQuery = requestBuilder.build(searchRequest);

        // Executes the search operation in Solr
        LOG.info("Solr query executed: {}", solrQuery);
        final QueryResponse queryResponse = solrServer.query(solrQuery);

        // Defensive copy: done because the build method is not thread safe.
        return responseBuilder.getCopy().build(searchRequest, queryResponse);
    } catch (SolrServerException e) {
        if (e.getRootCause() instanceof IllegalArgumentException) {
            LOG.error("Bad search request", e);
            throw (IllegalArgumentException) e.getRootCause();
        } else {
            LOG.error("Error executing the search operation", e);
            throw new SearchException(e);
        }
    }
}

From source file:org.sleuthkit.autopsy.keywordsearch.Server.java

License:Open Source License

/**
 * Tests if there's a Solr server running by sending it a core-status
 * request./*w w w  .java 2  s.c  o  m*/
 *
 * @return false if the request failed with a connection error, otherwise
 * true
 */
synchronized boolean isRunning() throws KeywordSearchModuleException {
    try {
        // making a status request here instead of just doing solrServer.ping(), because
        // that doesn't work when there are no cores

        //TODO check if port avail and return false if it is

        //TODO handle timeout in cases when some other type of server on that port
        CoreAdminRequest.getStatus(null, solrServer);

        logger.log(Level.INFO, "Solr server is running"); //NON-NLS
    } catch (SolrServerException ex) {

        Throwable cause = ex.getRootCause();

        // TODO: check if SocketExceptions should actually happen (is
        // probably caused by starting a connection as the server finishes
        // shutting down)
        if (cause instanceof ConnectException || cause instanceof SocketException) { //|| cause instanceof NoHttpResponseException) {
            logger.log(Level.INFO, "Solr server is not running, cause: {0}", cause.getMessage()); //NON-NLS
            return false;
        } else {
            throw new KeywordSearchModuleException(
                    NbBundle.getMessage(this.getClass(), "Server.isRunning.exception.errCheckSolrRunning.msg"),
                    ex);
        }
    } catch (SolrException ex) {
        // Just log 404 errors for now...
        logger.log(Level.INFO, "Solr server is not running", ex); //NON-NLS
        return false;
    } catch (IOException ex) {
        throw new KeywordSearchModuleException(
                NbBundle.getMessage(this.getClass(), "Server.isRunning.exception.errCheckSolrRunning.msg2"),
                ex);
    }

    return true;
}