Example usage for com.amazonaws AmazonClientException AmazonClientException

List of usage examples for com.amazonaws AmazonClientException AmazonClientException

Introduction

In this page you can find the example usage for com.amazonaws AmazonClientException AmazonClientException.

Prototype

public AmazonClientException(Throwable t) 

Source Link

Usage

From source file:com.ivona.services.tts.model.transform.lexicons.GetLexiconPostRequestMarshaller.java

License:Open Source License

private void setRequestPayload(Request<GetLexiconRequest> request, GetLexiconRequest getLexiconRequest) {
    StringWriter stringWriter = new StringWriter();
    JSONWriter jsonWriter = new JSONWriter(stringWriter);

    try {/*from w ww  .j a va 2s  .c om*/
        jsonWriter.object();

        if (MarshallerHelper.stringIsNotBlank(getLexiconRequest.getLexiconName())) {
            jsonWriter.key("Name").value(getLexiconRequest.getLexiconName());
        } else {
            throw new AmazonClientException("null or empty lexicon name passed to marshall(...)");
        }

        jsonWriter.endObject();

        String snippet = stringWriter.toString();
        byte[] content = snippet.getBytes(UTF_8);
        request.setContent(new StringInputStream(snippet));
        request.addHeader("Content-Length", Integer.toString(content.length));
    } catch (JSONException e) {
        throw new AmazonClientException("Unable to marshall request to JSON", e);
    } catch (UnsupportedEncodingException e) {
        throw new AmazonClientException("Unable to marshall request to JSON", e);
    }
}

From source file:com.ivona.services.tts.model.transform.lexicons.ListLexiconsPostRequestMarshaller.java

License:Open Source License

public Request<ListLexiconsRequest> marshall(ListLexiconsRequest listLexiconsRequest) {
    if (listLexiconsRequest == null) {
        throw new AmazonClientException("null listLexiconsRequest passed to marshall(...)");
    }/*  ww w .  jav a2s  .com*/

    Request<ListLexiconsRequest> request = new DefaultRequest<ListLexiconsRequest>(listLexiconsRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    setRequestPayload(request, listLexiconsRequest);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}

From source file:com.ivona.services.tts.model.transform.lexicons.PutLexiconPostRequestMarshaller.java

License:Open Source License

public Request<PutLexiconRequest> marshall(PutLexiconRequest putLexiconRequest) {
    if (putLexiconRequest == null) {
        throw new AmazonClientException("null putLexiconRequest passed to marshall(...)");
    }/*from   w  w  w.j  av  a 2s  . c  o m*/

    Request<PutLexiconRequest> request = new DefaultRequest<PutLexiconRequest>(putLexiconRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    setRequestPayload(request, putLexiconRequest);
    request.setResourcePath(RESOURCE_PATH);

    return request;
}

From source file:com.ivona.services.tts.model.transform.lexicons.PutLexiconPostRequestMarshaller.java

License:Open Source License

private void setRequestPayload(Request<PutLexiconRequest> request, PutLexiconRequest putLexiconRequest) {
    StringWriter stringWriter = new StringWriter();
    JSONWriter jsonWriter = new JSONWriter(stringWriter);

    try {//from w w  w. j av  a  2  s  .  c  om
        jsonWriter.object();
        Lexicon lexicon = putLexiconRequest.getLexicon();
        if (lexicon != null) {
            jsonWriter.key(JSON_KEY_LEXICON);
            jsonWriter.object();

            if (MarshallerHelper.stringIsNotBlank(lexicon.getName())) {
                jsonWriter.key(JSON_KEY_NAME).value(lexicon.getName());
            } else {
                throw new AmazonClientException("null or empty lexicon name passed to marshall(...)");
            }

            if (MarshallerHelper.stringIsNotBlank(lexicon.getContents())) {
                jsonWriter.key(JSON_KEY_CONTENTS).value(lexicon.getContents());
            } else {
                throw new AmazonClientException("null or empty lexicon contents passed to marshall(...)");
            }

            jsonWriter.endObject();
        } else {
            throw new AmazonClientException("null lexicon object passed to marshall(...)");
        }
        jsonWriter.endObject();

        String snippet = stringWriter.toString();
        byte[] content = snippet.getBytes(UTF_8);
        request.setContent(new StringInputStream(snippet));
        request.addHeader("Content-Length", Integer.toString(content.length));
    } catch (JSONException e) {
        throw new AmazonClientException("Unable to marshall request to JSON", e);
    } catch (UnsupportedEncodingException e) {
        throw new AmazonClientException("Unable to marshall request to JSON", e);
    }
}

From source file:com.ivona.services.tts.model.transform.listvoices.ListVoicesGetRequestMarshaller.java

License:Open Source License

public Request<ListVoicesRequest> marshall(ListVoicesRequest listVoicesRequest) {

    if (listVoicesRequest == null) {
        throw new AmazonClientException("null listVoicesRequest passed to marshall(...)");
    }/*w  ww  .j a  va2 s.co m*/

    Request<ListVoicesRequest> request = new DefaultRequest<ListVoicesRequest>(listVoicesRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.GET);
    request.setResourcePath(RESOURCE_PATH);

    setRequestParameters(request, listVoicesRequest);

    return request;
}

From source file:com.ivona.services.tts.model.transform.listvoices.ListVoicesPostRequestMarshaller.java

License:Open Source License

public Request<ListVoicesRequest> marshall(ListVoicesRequest listVoicesRequest) {

    if (listVoicesRequest == null) {
        throw new AmazonClientException("null listVoicesRequest passed to marshall(...)");
    }/*from   w  w  w.j av a  2 s. c  om*/

    Request<ListVoicesRequest> request = new DefaultRequest<ListVoicesRequest>(listVoicesRequest,
            IvonaSpeechCloudClient.SERVICE_NAME);
    request.setHttpMethod(HttpMethodName.POST);
    request.setResourcePath(RESOURCE_PATH);
    setRequestPayload(request, listVoicesRequest);
    return request;
}

From source file:com.optimalbi.AmazonAccount.java

License:Apache License

private void configure() throws AmazonClientException {
    services = new HashSet<>();
    if (getCredentials() == null) {
        throw new AmazonClientException("No credentials provided");
    }/*from   w w  w.  java 2  s . c  o m*/
}

From source file:com.optimalbi.AmazonAccount.java

License:Apache License

private void populateEc2() throws AmazonClientException {
    for (Region region : getRegions()) {
        try {//from   ww  w .j  a  va  2 s  .c om
            //                services.addAll(Ec2Service.populateServices(region, getCredentials(), getLogger(), pricing));
            AmazonEC2Client ec2 = new AmazonEC2Client(getCredentials().getCredentials());
            ec2.setRegion(region);
            DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
            List<Reservation> reservations = describeInstancesRequest.getReservations();
            Set<Instance> inst = new HashSet<>();
            for (Reservation reservation : reservations) {
                inst.addAll(reservation.getInstances());
            }

            getLogger().info("EC2, Adding " + inst.size() + " instances from " + region.getName());

            for (Instance i : inst) {
                Service temp = new LocalEc2Service(i.getInstanceId(), getCredentials(), region, ec2,
                        getLogger());
                if (servicePricings != null && servicePricings.size() > 0) {
                    temp.attachPricing(servicePricings.get(region).getEc2Pricing());
                }
                services.add(temp);
            }

        } catch (AmazonClientException e) {
            throw new AmazonClientException(region.getName() + " " + e.getMessage());
        }
        completed.set(completed.get() + 1);
    }

}

From source file:com.optimalbi.AmazonAccount.java

License:Apache License

private void populateRedshift() throws AmazonClientException {
    for (Region region : getRegions()) {
        try {/*w w w .  ja va  2s  . c  o  m*/
            if (region.isServiceSupported(ServiceAbbreviations.RedShift)) {
                //                    services.addAll(RedshiftService.populateServices(region, getCredentials(), getLogger()));
                AmazonRedshiftClient redshift = new AmazonRedshiftClient(getCredentials().getCredentials());
                redshift.setRegion(region);

                DescribeClustersResult clusterResult;
                List<Cluster> clusters;
                try {
                    clusterResult = redshift.describeClusters();
                    clusters = clusterResult.getClusters();
                } catch (Exception e) {
                    throw new AmazonClientException("Failed to get clusters " + e.getMessage());
                }

                getLogger().info("Redshift, Adding " + clusters.size() + " clusters from " + region.getName());
                for (Cluster cluster : clusters) {
                    getLogger().info("Cluster: " + cluster.getClusterIdentifier());
                    LocalRedshiftService temp = new LocalRedshiftService(cluster.getDBName(), getCredentials(),
                            region, cluster, getLogger());
                    if (servicePricings != null && servicePricings.size() > 0) {
                        temp.attachPricing(servicePricings.get(region).getRedshiftPricing());
                    }
                    services.add(temp);
                }
            } else {
                getLogger().info("Redshift, NOPE from " + region.getName());
            }
        } catch (AmazonClientException e) {
            throw new AmazonClientException(region.getName() + " " + e.getMessage());
        }
        completed.set(completed.get() + 1);
    }
}

From source file:com.optimalbi.AmazonAccount.java

License:Apache License

private void populateRDS() throws AmazonClientException {
    for (Region region : getRegions()) {
        try {/*from   www.  j  a  v  a2  s  .c o m*/
            if (region.isServiceSupported(ServiceAbbreviations.RDS)) {
                AmazonRDSClient rds = new AmazonRDSClient(getCredentials().getCredentials());
                rds.setRegion(region);

                DescribeDBInstancesResult result = rds.describeDBInstances();
                List<DBInstance> instances = result.getDBInstances();

                getLogger().info("RDS, Adding " + instances.size() + " instances from " + region.getName());

                for (DBInstance i : instances) {
                    LocalRDSService temp;
                    if (i.getDBName() != null) {
                        temp = new LocalRDSService(i.getDBName(), getCredentials(), region, i, getLogger());
                    } else {
                        temp = new LocalRDSService(i.getDBInstanceIdentifier(), getCredentials(), region, i,
                                getLogger());
                    }
                    if (servicePricings != null && servicePricings.size() > 0) {
                        if (servicePricings.get(region).getRDSPricing() != null) {
                            temp.attachPricing(servicePricings.get(region).getRDSPricing());
                        }
                    }
                    services.add(temp);
                }
            } else {
                getLogger().info("RDS, NOPE from " + region.getName());
            }
        } catch (AmazonClientException e) {
            throw new AmazonClientException(region.getName() + " " + e.getMessage());
        }
        completed.set(completed.get() + 1);
    }
}