Java Code Examples for com.amazonaws.AmazonServiceException#getMessage()

The following examples show how to use com.amazonaws.AmazonServiceException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExceptionHandleAwsClientWrapper.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
protected AutoException handleException(AmazonServiceException exception, Method method, Object[] args) {
    Object request = null;
    if (method.getParameterTypes().length > 0) {
        request = args[0];
    }

    // UserDataにはパスワードが含まれているためマスクする
    if (request instanceof RunInstancesRequest) {
        ((RunInstancesRequest) request).setUserData(null);
    }

    String str = StringUtils.reflectToString(request);

    return new AutoException("EAWS-000003", exception, method.getName(), exception.getErrorCode(),
            exception.getMessage(), str);
}
 
Example 2
Source File: CreateS3BucketTask.java    From aws-ant-tasks with Apache License 2.0 6 votes vote down vote up
public void execute() {
    AmazonS3Client client = getOrCreateClient(AmazonS3Client.class);
    try {
        System.out.println("Creating bucket with name " + bucketName
                + "...");
        client.createBucket(bucketName);
        System.out
                .println("Bucket " + bucketName + " successfuly created.");
    } catch (AmazonServiceException ase) {
        throw new BuildException(
                "AmazonServiceException: Errors in S3 while processing request."
                        + ase.getMessage());
    } catch (AmazonClientException ace) {
        throw new BuildException(
                "AmazonClientException: Errors encountered in the client while"
                        + " making the request or handling the response. "
                        + ace.getMessage());
    } catch (Exception e) {
        throw new BuildException(e.getMessage());
    }
}
 
Example 3
Source File: AwsUploadRepository.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(String path) throws BusinessException {
    if (!Optional.ofNullable(path).isPresent()) {
        throw new BusinessException(Validations.INVALID_PATH.getCode());
    }
    client.getClient(credentials.getCredentials());
    try {
        s3Client.deleteObject(
                new DeleteObjectRequest(cdnConfig.getName(), path)
        );
    } catch (AmazonServiceException e) {
        throw new BusinessException(e.getMessage());
    }
}
 
Example 4
Source File: AwsServiceHelper.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Handles the AmazonServiceException, throws corresponding exception based on status code in amazon exception.
 *
 * @param amazonServiceException the AWS exception that will be handled by this method.
 * @param message the message to include with this exception.
 *
 * @throws IllegalArgumentException the exception to be thrown with a HttpStatus.SC_BAD_REQUEST
 * @throws ObjectNotFoundException the exception to be thrown with a HttpStatus.SC_NOT_FOUND
 */
public void handleAmazonException(AmazonServiceException amazonServiceException, String message) throws IllegalArgumentException, ObjectNotFoundException
{
    if (amazonServiceException.getStatusCode() == HttpStatus.SC_BAD_REQUEST)
    {
        throw new IllegalArgumentException(message + " Reason: " + amazonServiceException.getMessage(), amazonServiceException);
    }
    else if (amazonServiceException.getStatusCode() == HttpStatus.SC_NOT_FOUND)
    {
        throw new ObjectNotFoundException(message + " Reason: " + amazonServiceException.getMessage(), amazonServiceException);
    }

    throw amazonServiceException;
}
 
Example 5
Source File: AWSClients.java    From aws-codedeploy-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Via the default provider chain (i.e., global keys for this Jenkins instance),  return the account ID for the
 * currently authenticated user.
 * @param proxyHost hostname of the proxy to use (if any)
 * @param proxyPort port of the proxy to use (if any)
 * @return 12-digit account id
 */
public static String getAccountId(String proxyHost, int proxyPort) {

    String arn = "";
    try {
        ClientConfiguration clientCfg = new ClientConfiguration();
        if (proxyHost != null && proxyPort > 0 ) {
            clientCfg.setProxyHost(proxyHost);
            clientCfg.setProxyPort(proxyPort);
        }
        AmazonIdentityManagementClient iam = new AmazonIdentityManagementClient(clientCfg);
        GetUserResult user = iam.getUser();
        arn = user.getUser().getArn();
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().compareTo("AccessDenied") == 0) {
            String msg = e.getMessage();
            int arnIdx = msg.indexOf("arn:aws");
            if (arnIdx != -1) {
                int arnSpace = msg.indexOf(" ", arnIdx);
                arn = msg.substring(arnIdx, arnSpace);
            }
        }
    }

    String accountId = arn.split(":")[ARN_ACCOUNT_ID_INDEX];
    return accountId;
}
 
Example 6
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private Set<CloudAccessConfig> getAccessConfigByInstanceProfile(AmazonIdentityManagement client) {
    LOGGER.info("Get all Instance profiles from Amazon");
    String queryFailedMessage = "Could not get instance profiles from Amazon: ";
    try {
        boolean finished = false;
        String marker = null;
        Set<InstanceProfile> instanceProfiles = new LinkedHashSet<>();
        while (!finished) {
            ListInstanceProfilesRequest listInstanceProfilesRequest = new ListInstanceProfilesRequest();
            listInstanceProfilesRequest.setMaxItems(fetchMaxItems);
            if (isNotEmpty(marker)) {
                listInstanceProfilesRequest.setMarker(marker);
            }
            LOGGER.debug("About to fetch instance profiles...");
            ListInstanceProfilesResult listInstanceProfilesResult = client.listInstanceProfiles(listInstanceProfilesRequest);
            List<InstanceProfile> fetchedInstanceProfiles = listInstanceProfilesResult.getInstanceProfiles();
            instanceProfiles.addAll(fetchedInstanceProfiles);
            if (listInstanceProfilesResult.isTruncated()) {
                marker = listInstanceProfilesResult.getMarker();
            } else {
                finished = true;
            }
        }
        LOGGER.debug("The total of {} instance profile(s) has fetched.", instanceProfiles.size());
        return instanceProfiles.stream().map(this::instanceProfileToCloudAccessConfig).collect(Collectors.toSet());
    } catch (AmazonServiceException ase) {
        if (ase.getStatusCode() == UNAUTHORIZED) {
            LOGGER.error("Could not get instance profiles because the user does not have enough permission.", ase);
            throw new CloudConnectorException(ase.getMessage(), ase);
        } else {
            LOGGER.info(queryFailedMessage, ase);
            throw new CloudConnectorException(ase.getMessage(), ase);
        }
    } catch (Exception e) {
        LOGGER.warn(queryFailedMessage, e);
        throw new CloudConnectorException(queryFailedMessage + e.getMessage(), e);
    }
}
 
Example 7
Source File: AwsPlatformResources.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private Set<CloudAccessConfig> getAccessConfigByRole(AmazonIdentityManagement client) {
    LOGGER.info("Get all Roles from Amazon");
    String queryFailedMessage = "Could not get roles from Amazon: ";
    try {
        boolean finished = false;
        String marker = null;
        List<Role> roles = new LinkedList<>();
        while (!finished) {
            ListRolesRequest listRolesRequest = new ListRolesRequest();
            listRolesRequest.setMaxItems(fetchMaxItems);
            if (isNotEmpty(marker)) {
                listRolesRequest.setMarker(marker);
            }
            LOGGER.debug("About to fetch roles...");
            ListRolesResult listRolesResult = client.listRoles(listRolesRequest);
            roles.addAll(listRolesResult.getRoles());
            if (listRolesResult.isTruncated()) {
                marker = listRolesResult.getMarker();
            } else {
                finished = true;
            }
        }
        return roles.stream().map(this::roleToCloudAccessConfig).collect(Collectors.toSet());
    } catch (AmazonServiceException ase) {
        if (ase.getStatusCode() == UNAUTHORIZED) {
            String policyMessage = "Could not get roles because the user does not have enough permission. ";
            LOGGER.error(policyMessage + ase.getMessage(), ase);
            throw new CloudUnauthorizedException(ase.getErrorMessage(), ase);
        } else {
            LOGGER.info(queryFailedMessage + ase.getMessage(), ase);
            throw new CloudConnectorException(ase.getMessage(), ase);
        }
    } catch (Exception e) {
        LOGGER.warn(queryFailedMessage + e.getMessage(), e);
        throw new CloudConnectorException(e.getMessage(), e);
    }
}