Example usage for org.springframework.core NestedRuntimeException getMostSpecificCause

List of usage examples for org.springframework.core NestedRuntimeException getMostSpecificCause

Introduction

In this page you can find the example usage for org.springframework.core NestedRuntimeException getMostSpecificCause.

Prototype

public Throwable getMostSpecificCause() 

Source Link

Document

Retrieve the most specific cause of this exception, that is, either the innermost cause (root cause) or this exception itself.

Usage

From source file:com.wandrell.example.swss.client.console.ConsoleClient.java

/**
 * Calls the endpoint in the specified URI by using the received client.
 * <p>/* w  w w  .java2s .c om*/
 * This client is expected to be prepared for calling the endpoint, which
 * mostly means being set up for the same security protocol it uses.
 * <p>
 * If an exception occurs while using the client an error warning will be
 * printed in the console.
 *
 * @param client
 *            client which will call the endpoint
 * @param uri
 *            URI for the endpoint
 * @param output
 *            output for the client to print information
 * @param scanner
 *            scanner for the input
 */
private static final void callEndpoint(final EntityClient client, final String uri, final PrintStream output,
        final Scanner scanner) {
    final ExampleEntity entity; // Queried entity
    final Integer id; // Id for the query

    output.println("------------------------------------");
    output.println("Write the id of the entity to query.");
    output.println("The id 1 is always valid.");
    output.println("------------------------------------");

    output.println();
    output.print("Id: ");
    id = getInteger(scanner);
    output.println();

    try {
        entity = client.getEntity(uri, id);

        if ((entity == null) || (entity.getId() < 0)) {
            // No entity found
            output.println(String.format("No entity with id %d exists", id));
        } else {
            // Entity found
            output.println("Found entity.");
            output.println();
            output.println(String.format("Entity id:\t%d", entity.getId()));
            output.println(String.format("Entity name:\t%s", entity.getName()));
        }
    } catch (final NestedRuntimeException e) {
        output.println(String.format("Error: %s", e.getMostSpecificCause().getMessage()));
    } catch (final Exception e) {
        output.println(String.format("Error: %s", e.getMessage()));
    }

    // Waits so the result information can be checked
    waitForEnter(output, scanner);
}

From source file:com.cisco.cta.taxii.adapter.error.ChainHandler.java

@Override
public void handle(Throwable t) {
    try {//from  www .  j a va2 s. c o  m
        throw t;

    } catch (NestedRuntimeException e) {
        try {
            throw e.getMostSpecificCause();
        } catch (BindException bindRootCause) {
            bindExceptionHandler.handle(bindRootCause);
        } catch (Throwable unknownRootCause) {
            fallBackHandler.handle(unknownRootCause);
        }

    } catch (YAMLException target) {
        yamlExceptionHandler.handle(target);

    } catch (IllegalStateException illegal) {
        causeHandler.handle(illegal);

    } catch (Throwable e) {
        fallBackHandler.handle(e);
    }
}

From source file:org.slc.sli.ingestion.handler.EntityPersistHandler.java

boolean update(String collectionName, Entity entity, List<Entity> failed, AbstractMessageReport report,
        ReportStats reportStats, Source nrSource) {
    boolean res = false;

    try {/*from   w w  w . jav a2  s.c  om*/
        res = entityRepository.updateWithRetries(collectionName, entity, totalRetries);
        if (!res) {
            failed.add(entity);
        }
    } catch (MongoException e) {
        NestedRuntimeException wrapper = new NestedRuntimeException("Mongo Exception", e) {
            private static final long serialVersionUID = 1L;
        };
        reportWarnings(wrapper.getMostSpecificCause().getMessage(), collectionName,
                ((SimpleEntity) entity).getSourceFile(), report, reportStats, nrSource);
    }

    return res;
}