Example usage for org.apache.commons.lang3.exception ContextedRuntimeException ContextedRuntimeException

List of usage examples for org.apache.commons.lang3.exception ContextedRuntimeException ContextedRuntimeException

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ContextedRuntimeException ContextedRuntimeException.

Prototype

public ContextedRuntimeException(final Throwable cause) 

Source Link

Document

Instantiates ContextedRuntimeException with cause, but without message.

Usage

From source file:ServerMultipart.java

private static void multipartUpload(ServerSideMultipartManager multipart) {
    String uploadObject = "/" + mantaUsername + "/stor/multipart";

    // We catch network errors and handle them here
    try {//from   ww  w.jav a 2  s. c  o  m
        ServerSideMultipartUpload upload = multipart.initiateUpload(uploadObject);
        MantaMultipartUploadPart part1 = multipart.uploadPart(upload, 1, RandomUtils.nextBytes(5242880));
        MantaMultipartUploadPart part2 = multipart.uploadPart(upload, 2, RandomUtils.nextBytes(1000000));

        // Complete the process by instructing Manta to assemble the final object from its parts
        MantaMultipartUploadTuple[] parts = new MantaMultipartUploadTuple[] { part1, part2 };
        Stream<MantaMultipartUploadTuple> partsStream = Arrays.stream(parts);
        multipart.complete(upload, partsStream);

        System.out.println(uploadObject + " is now assembled!");
    } catch (IOException e) {
        // This catch block is for general network failures
        // For example, ServerSideMultipartUpload.initiateUpload can throw an IOException

        ContextedRuntimeException exception = new ContextedRuntimeException(
                "A network error occurred when doing a multipart upload to Manta.");
        exception.setContextValue("path", uploadObject);

        throw exception;
    }
}

From source file:com.rodaxsoft.mailgun.ListMember.java

@Override
public String getType() {

    if (address != null) {
        try {//from  w  w  w  .  j  a v  a2 s . c o  m
            return new InternetAddress(address, name).getType();
        } catch (UnsupportedEncodingException e) {
            throw new ContextedRuntimeException(e);
        }
    } else {
        return null;
    }
}

From source file:ClientEncryptionServerMultipart.java

private static void multipartUpload(EncryptedServerSideMultipartManager multipart) {
    String uploadObject = "/" + mantaUsername + "/stor/multipart";

    // We catch network errors and handle them here
    try {/* w ww . j a  v a 2  s. c o m*/
        MantaMetadata metadata = new MantaMetadata();
        metadata.put("e-secretkey", "My Secret Value");
        EncryptedMultipartUpload<ServerSideMultipartUpload> upload = multipart.initiateUpload(uploadObject,
                metadata);
        MantaMultipartUploadPart part1 = multipart.uploadPart(upload, 1, RandomUtils.nextBytes(5242880));
        MantaMultipartUploadPart part2 = multipart.uploadPart(upload, 2, RandomUtils.nextBytes(1000000));

        // Complete the process by instructing Manta to assemble the final object from its parts
        MantaMultipartUploadTuple[] parts = new MantaMultipartUploadTuple[] { part1, part2 };
        Stream<MantaMultipartUploadTuple> partsStream = Arrays.stream(parts);
        multipart.complete(upload, partsStream);

        System.out.println(uploadObject + " is now assembled!");
    } catch (IOException e) {
        // This catch block is for general network failures
        // For example, ServerSideMultipartUpload.initiateUpload can throw an IOException

        ContextedRuntimeException exception = new ContextedRuntimeException(
                "A network error occurred when doing a multipart upload to Manta.");
        exception.setContextValue("path", uploadObject);

        throw exception;
    }
}

From source file:com.rodaxsoft.mailgun.ListMemberRequest.java

/**
 * Set the list member email address/* w  ww .j a v a  2s.  c  o  m*/
 * @param address The email address to set
 * @return ListMemberRequest object
 * @throws ContextedRuntimeException if the address format is invalid.
 * 
 */
public ListMemberRequest setAddress(String address) {
    try {
        new InternetAddress(address, true);
    } catch (AddressException e) {
        throw new ContextedRuntimeException(e).addContextValue("address", address).addContextValue("position",
                e.getPos());
    }

    parameters.put(ADDRESS_KEY, address);
    return this;
}

From source file:com.rodaxsoft.mailgun.converters.CampaignConverter.java

@Override
public <T> T convert(Class<T> type, Object value) {

    Campaign campaign = null;/*from  w w w .j av a 2 s  . c  o  m*/

    if (value instanceof JSONObject) {

        JSONObject json = (JSONObject) value;

        Transformer<String, String> keyTransformer;
        keyTransformer = new KeyTransformer();

        @SuppressWarnings("unchecked")
        final Map<String, Object> copy = new HashMap<>(json);
        Map<String, Object> transformed;
        transformed = TransformedMap.transformedMap(copy, keyTransformer, null);

        campaign = new Campaign();
        try {
            BeanUtils.populate(campaign, transformed);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new ContextedRuntimeException(e);
        }
    }

    return type.cast(campaign);
}

From source file:com.rodaxsoft.mailgun.ListMember.java

/**
 * Sets the email address/*from ww  w.  ja  v  a2s.c  o m*/
 * @param address The email address to set
 * @throws ContextedRuntimeException if the email address format is invalid
 */
public void setAddress(String address) {

    try {
        new InternetAddress(address, true);
    } catch (AddressException e) {
        throw new ContextedRuntimeException(e).addContextValue("address", address).addContextValue("position",
                e.getPos());
    }

    this.address = address;
}

From source file:JobsBasedMultipart.java

private static void multipartUpload(MantaClient mantaClient) {
    // instantiated with a reference to the class the actually connects to Manta
    JobsMultipartManager multipart = new JobsMultipartManager(mantaClient);

    String uploadObject = "/username/stor/test/file";

    /* I'm using File objects below, but I could be using byte[] arrays,
     * Strings, or InputStreams as well. */
    File part1file = new File("part-1.data");
    File part2file = new File("part-2.data");
    File part3file = new File("part-3.data");

    // We can set any metadata for the final object
    MantaMetadata metadata = new MantaMetadata();
    metadata.put("m-test-metadata", "any value");

    // We can set any header for the final object
    MantaHttpHeaders headers = new MantaHttpHeaders();
    headers.setContentType("text/plain");

    // We catch network errors and handle them here
    try {//  w  ww .  j av  a  2 s . c o m
        // We get a response object
        JobsMultipartUpload upload = multipart.initiateUpload(uploadObject);

        // It contains a UUID transaction id
        UUID id = upload.getId();
        // It also contains the path of the final object
        String uploadPath = upload.getPath();

        // Everywhere below that we specified "upload" we could also just
        // use the upload transaction id

        List<MantaMultipartUploadPart> parts = new ArrayList<>();

        // We can add the parts in any order
        MantaMultipartUploadPart part2 = multipart.uploadPart(upload, 2, part2file);
        // Each put of a part is a synchronous operation
        MantaMultipartUploadPart part1 = multipart.uploadPart(upload, 1, part1file);
        // Although in a later version we could make an async option
        MantaMultipartUploadPart part3 = multipart.uploadPart(upload, 3, part3file);

        parts.add(part1);
        parts.add(part3);
        parts.add(part2);

        // If we want to give up now, we could always abort
        // multipart.abort(upload);

        // We've uploaded all of the parts, now lets join them
        multipart.complete(upload, parts.stream());

        // If we want to pause execution until it is committed
        int timesToPoll = 10;
        multipart.waitForCompletion(upload, Duration.ofSeconds(5), timesToPoll, uuid -> {
            throw new RuntimeException("Multipart completion timed out");
        });

    } catch (MantaClientHttpResponseException e) {
        // This catch block is for when we actually have a response code from Manta

        // We can handle specific HTTP responses here
        if (e.getStatusCode() == 503) {
            System.out.println("Manta is unavailable. Please try again");
            return;
        }

        // We could rethrow as a more detailed exception as below
        throw new RuntimeException(e);
    } catch (IOException e) {
        // This catch block is for general network failures
        // Note: MantaClientHttpResponseException inherits from IOException
        // so if it is not explicitly caught, it would go to this block

        ContextedRuntimeException exception = new ContextedRuntimeException(
                "A network error occurred when doing a multipart upload to"
                        + "Manta. See context for details.");
        // We should all of the diagnostic context that we need
        exception.setContextValue("parts", "[part-1.data, part-2.data, part-3.data]");

        // We rethrow the exception with additional detail
        throw exception;
    }
}

From source file:com.codspire.mojo.artifactlookup.ProcessResponse.java

/**
 * /*from  www .  j  a  v  a2s.  co  m*/
 * @param repository
 * @return
 */
protected String getAPIEndpoint(String origRepository) {
    String endpoint = null;
    String repository = cleanupRepositoryURL(origRepository);

    if (repository.contains(plugInConfig.getString(MAVEN_CENTRAL_REPO_DOMAIN_1))
            || repository.contains(plugInConfig.getString(MAVEN_CENTRAL_REPO_DOMAIN_2))) {
        endpoint = plugInConfig.getString(MAVEN_CENTRAL_REPO_SEARCH_ENDPOINT);
    } else if (repository.endsWith(plugInConfig.getString(SONATYPE_REPO_URL_ENDS_WITH))) {
        endpoint = repository.replace(plugInConfig.getString(SONATYPE_REPO_URL_ENDS_WITH),
                plugInConfig.getString(SONATYPE_REPO_SEARCH_ENDPOINT_ENDS_WITH));
    } else {
        throw new ContextedRuntimeException("Endpoint could not be determined for " + repository);
    }
    return endpoint;
}

From source file:com.rodaxsoft.mailgun.ListMember.java

/**
 * Return a String representation of this address object.
 *//* w  w  w.j a  v a 2  s  . c o  m*/
@Override
public String toString() {
    if (address != null) {
        try {
            return new InternetAddress(address, name).toString();
        } catch (UnsupportedEncodingException e) {
            throw new ContextedRuntimeException(e);
        }
    }

    else {
        return null;
    }
}

From source file:com.codspire.mojo.artifactlookup.ArtifactLookupMojo.java

/**
 * Validates if the "artifactLocation" is correct.
 *///from   w w w . j a v a 2 s . c  o m
protected void validateArtifactLocation() {
    if (artifactLocation == null || !artifactLocation.exists()) {
        throw new ContextedRuntimeException(
                "ERROR: artifactLocation property is invalid. Please provide -DartifactLocation=<file or folder path>");
    }
}