List of usage examples for com.amazonaws AmazonServiceException getStatusCode
public int getStatusCode()
From source file:com.netflix.spinnaker.kork.aws.AwsMetricsSupport.java
License:Apache License
static String[] buildExceptionTags(AmazonWebServiceRequest originalRequest, Exception exception) { final AmazonServiceException ase = amazonServiceException(exception); String targetAccountId = DEFAULT_UNKNOWN; if (ase.getHttpHeaders() != null) { targetAccountId = ase.getHttpHeaders().get("targetAccountId"); }//from w ww . ja v a 2 s .c om return new String[] { "requestType", originalRequest.getClass().getSimpleName(), "statusCode", Integer.toString(ase.getStatusCode()), "errorCode", Optional.ofNullable(ase.getErrorCode()).orElse(DEFAULT_UNKNOWN), "serviceName", Optional.ofNullable(ase.getServiceName()).orElse(DEFAULT_UNKNOWN), "errorType", Optional.ofNullable(ase.getErrorType()).orElse(AmazonServiceException.ErrorType.Unknown).name(), "accountId", Optional.ofNullable(targetAccountId).orElse(DEFAULT_UNKNOWN) }; }
From source file:com.neu.cloud.Controller.FifthUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase5-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {/* w w w.j a v a 2 s . c om*/ System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.neu.cloud.Controller.FirstUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase1-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {//www . j a v a 2 s. c o m System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.neu.cloud.Controller.FourthUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase4-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {/*from w w w .j a v a 2 s .co m*/ System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.neu.cloud.Controller.SecondUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase2-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {/*from w w w .j av a2s . c om*/ System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.neu.cloud.Controller.ThirdUseCaseController.java
private void uploadInS3(String uploadFilePath, String uploadFileName, String dateForFolder) { String bucketName = "reports-sppard"; String keyName = "UseCase3-" + dateForFolder + "/" + uploadFileName; AmazonS3 s3client = new AmazonS3Client( new BasicAWSCredentials("AKIAJ2E67YVFQ5PZSWQA", "xiVuejpUofGonrsiy2owvu/wgeNKq5nYjxYVC0ma")); try {/* w w w .jav a2 s .c o m*/ System.out.println("Uploading a new object to S3 from a file\n"); File file = new File(uploadFilePath + uploadFileName); s3client.putObject(new PutObjectRequest(bucketName, keyName, file)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.nike.cerberus.operation.core.UpdateStackOperation.java
License:Apache License
@Override public void run(final UpdateStackCommand command) { final String stackId = configStore.getStackId(command.getStackName()); final Class<? extends LaunchConfigParameters> parametersClass = stackParameterMap .get(command.getStackName()); final Map<String, String> parameters; if (parametersClass != null) { parameters = getUpdateLaunchConfigParameters(command.getStackName(), command, parametersClass); } else if (StackName.BASE == command.getStackName()) { parameters = getUpdatedBaseStackParameters(command); } else {// w ww .ja v a2 s .c om throw new IllegalArgumentException("The specified stack does not support the update stack command!"); } parameters.putAll(command.getDynamicParameters()); try { logger.info("Starting the update for {}.", command.getStackName().getName()); if (command.isOverwriteTemplate()) { cloudFormationService.updateStack(stackId, parameters, stackTemplatePathMap.get(command.getStackName()), true); } else { cloudFormationService.updateStack(stackId, parameters, true); } final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.UPDATE_COMPLETE, StackStatus.UPDATE_COMPLETE_CLEANUP_IN_PROGRESS, StackStatus.UPDATE_ROLLBACK_COMPLETE)); if (endStatus == StackStatus.ROLLBACK_COMPLETE) { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } logger.info("Update complete."); } catch (AmazonServiceException ase) { if (ase.getStatusCode() == 400 && StringUtils.equalsIgnoreCase(ase.getErrorMessage(), "No updates are to be performed.")) { logger.warn("CloudFormation reported no changes detected."); } else { throw ase; } } }
From source file:com.nike.cerberus.service.CloudFormationService.java
License:Apache License
/** * Returns the current status of the named stack. * * @param stackId Stack ID.//from w ww. ja va 2 s. co m * @return Stack status data. */ @Nullable public StackStatus getStackStatus(final String stackId) { final DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackId); try { final DescribeStacksResult result = cloudFormationClient.describeStacks(request); if (result.getStacks().size() > 0) { final String status = result.getStacks().get(0).getStackStatus(); if (StringUtils.isNotBlank(status)) { return StackStatus.fromValue(status); } } } catch (final AmazonServiceException ase) { // Stack doesn't exist, just return with no status if (ase.getStatusCode() != 400) { throw ase; } } return null; }
From source file:com.nike.cerberus.service.CloudFormationService.java
License:Apache License
/** * Returns the events for a named stack. * * @param stackId Stack ID./* w ww. j ava 2 s. c om*/ * @return Collection of events */ public List<StackEvent> getStackEvents(final String stackId) { final DescribeStackEventsRequest request = new DescribeStackEventsRequest().withStackName(stackId); try { final DescribeStackEventsResult result = cloudFormationClient.describeStackEvents(request); return result.getStackEvents(); } catch (final AmazonServiceException ase) { // Stack doesn't exist, just return with no status if (ase.getStatusCode() != 400) { throw ase; } } return Collections.emptyList(); }
From source file:com.onemenu.server.util.awsnotification.SNSMobilePush.java
License:Open Source License
public static void pushIOSNotification(String message, String deviceToken, Map<String, Object> customData, int badge) throws IOException { AmazonSNS sns = new AmazonSNSClient(new PropertiesCredentials( SNSMobilePush.class.getClassLoader().getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); if (logger.isDebugEnabled()) { logger.debug("===========================================\n"); logger.debug("Getting Started with Amazon SNS IOS"); logger.debug("===========================================\n"); }/*from www.ja va 2 s .c om*/ try { SNSMobilePush push = new SNSMobilePush(sns); String applicationName = ConfigCache.getValue(ConfigKey.APPLICATION_NAME, "One-Menu"); String _message = MessageGenerator.getAppleMessage(message, null, badge, customData); boolean isSandBox = Boolean.parseBoolean(ConfigCache.getValue(ConfigKey.IS_SAND_BOX, "true")); Platform platform = null; String Certificate = null; String Private_Key = null; if (isSandBox) { platform = Platform.APNS_SANDBOX; Certificate = S_Certificate; Private_Key = S_Private_Key; } else { platform = Platform.APNS; Certificate = P_Certificate; Private_Key = P_Private_Key; } push.snsClientWrapper.notification(platform, Certificate, Private_Key, deviceToken, applicationName, attributesMap, _message); } catch (AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, but was rejected with an error response for some reason."); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { logger.error("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SNS, such as not " + "being able to access the network."); logger.error("Error Message: " + ace.getMessage()); } }