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

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

Introduction

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

Prototype

public SolrServerException(String message, Throwable cause) 

Source Link

Usage

From source file:io.redlink.solrlib.SolrCoreContainer.java

License:Apache License

/**
 * Get a SolrClient for the provided SolrCoreDescriptor.
 * <strong>Note:</strong> the caller is responsible for closing the returned SolrClient to avoid resource leakage.
 * @param coreName the core to connect to
 * @return a SolrClient/*  www. ja v  a  2 s . c o m*/
 * @throws SolrServerException if the initialisation of the requested core failed
 */
public SolrClient getSolrClient(String coreName) throws SolrServerException {
    try {
        // Wait for the CoreContainer to be online
        awaitInitCompletion();
        // Check for and propagate any exception during CoreContainer initialisation
        if (initException != null) {
            throw new SolrServerException("Exception initializing SolrCoreContainer", initException);
        }

        // Check for and propagate any core-specific exception during CoreContainer initialisation
        final Throwable coreInitException = this.coreInitExceptions.get(coreName);
        if (coreInitException != null) {
            throw new SolrServerException("Exception initializing core " + coreName, coreInitException);
        }

        // Wait for the core-initialisation to be completed
        awaitCoreInitCompletion(coreName);
        // Check for and propagate any core-specific exception during core initialisation
        final Throwable coreInitExceptionDuringCallback = this.coreInitExceptions.get(coreName);
        if (coreInitExceptionDuringCallback != null) {
            throw new SolrServerException("Exception initializing core " + coreName,
                    coreInitExceptionDuringCallback);
        }
        return createSolrClient(coreName);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IllegalStateException("Could not retrieve SolrClient '" + coreName + "'", e);
    }
}

From source file:org.apache.blur.slur.SolrLookingBlurServer.java

License:Apache License

@Override
public QueryResponse query(SolrParams params) throws SolrServerException {
    QueryResponse response = new QueryResponse();
    long start = System.currentTimeMillis();

    try {//ww  w .j a v a  2s  .c  o m
        BlurQuery blurQuery = BlurQueryHelper.from(params);
        BlurResults results = client().query(tableName, blurQuery);
        NamedList<Object> resp = new NamedList<Object>();

        resp.add("response", BlurResultHelper.from(results));

        response.setResponse(resp);
    } catch (Exception e) {
        throw new SolrServerException("Unable to complete query", e);
    }

    response.setElapsedTime((System.currentTimeMillis() - start));

    return response;
}

From source file:org.apache.blur.slur.SolrLookingBlurServer.java

License:Apache License

@SuppressWarnings("unchecked")
private <T extends SolrResponseBase> T respond(Class<T> typ, Command command) throws SolrServerException {
    SolrResponseBase response;//from w  w w .  ja  v  a  2 s .com
    long start = System.currentTimeMillis();
    try {
        response = typ.newInstance();

        command.process();
    } catch (Exception e) {
        throw new SolrServerException("Unable to complete update request.", e);
    }
    response.setElapsedTime((System.currentTimeMillis() - start));
    return (T) response;
}

From source file:org.springframework.data.solr.core.SolrExceptionTranslatorTest.java

License:Apache License

@Test
public void testWithParseException() {
    SolrServerException solrServerException = new SolrServerException("meessage",
            new SolrException(ErrorCode.BAD_REQUEST,
                    new org.apache.lucene.queryparser.classic.ParseException("parse execption message")));

    Assert.assertThat(// ww w . j a va  2 s.c  om
            exceptionTranslator.translateExceptionIfPossible(new RuntimeException(solrServerException)),
            IsInstanceOf.instanceOf(InvalidDataAccessApiUsageException.class));
}

From source file:org.springframework.data.solr.core.SolrExceptionTranslatorTest.java

License:Apache License

private SolrServerException createSolrServerExceptionFor(ErrorCode errorCode, String message) {
    return new SolrServerException("wrapper exception", new SolrException(errorCode, message));
}

From source file:org.springframework.data.solr.core.SolrExceptionTranslatorTests.java

License:Apache License

@Test
public void testWithParseException() {
    SolrServerException solrServerException = new SolrServerException("meessage", new SolrException(
            ErrorCode.BAD_REQUEST, new org.apache.solr.parser.ParseException("parse execption message")));

    Assert.assertThat(/*from  w w  w .  j a v  a  2s  .  co  m*/
            exceptionTranslator.translateExceptionIfPossible(new RuntimeException(solrServerException)),
            IsInstanceOf.instanceOf(InvalidDataAccessApiUsageException.class));
}

From source file:org.springframework.data.solr.core.SolrExceptionTranslatorTests.java

License:Apache License

/**
 * @see DATASOLR-158/*w w  w .j  a v a  2 s.c o m*/
 */
@Test
public void shouldConvertConnectExceptionCorrectly() {

    SolrServerException ex = new SolrServerException("message",
            new java.net.ConnectException("Cannot connect to server"));
    Assert.assertThat(exceptionTranslator.translateExceptionIfPossible(new RuntimeException(ex)),
            IsInstanceOf.instanceOf(DataAccessResourceFailureException.class));
}

From source file:org.springframework.data.solr.core.SolrTemplateTest.java

License:Apache License

@Test(expected = DataAccessException.class)
public void testPingThrowsException() throws SolrServerException, IOException {
    Mockito.when(solrServerMock.ping())//from w w  w.  ja v a 2s  . c  o  m
            .thenThrow(new SolrServerException("error", new SolrException(ErrorCode.NOT_FOUND, "not found")));
    solrTemplate.ping();
}

From source file:org.springframework.data.solr.core.SolrTemplateTest.java

License:Apache License

@Test(expected = InvalidDataAccessApiUsageException.class)
public void testQueryThrowsParseException() throws SolrServerException {
    Mockito.when(solrServerMock.query(Matchers.any(SolrParams.class))).thenThrow(new SolrServerException(
            "error", new SolrException(ErrorCode.BAD_REQUEST, new ParseException("parse error"))));
    solrTemplate.executeSolrQuery(new SolrQuery());
}

From source file:org.springframework.data.solr.SolrRealtimeGetRequest.java

License:Apache License

@Override
public QueryResponse process(SolrServer server) throws SolrServerException, IOException {

    try {// w  ww .j a  v  a  2s  .c om
        long startTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
        QueryResponse res = new QueryResponse(server.request(this), server);
        long endTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
        res.setElapsedTime(endTime - startTime);
        return res;
    } catch (SolrServerException e) {
        throw e;
    } catch (SolrException s) {
        throw s;
    } catch (Exception e) {
        throw new SolrServerException("Error executing query", e);
    }
}