@Test public void testIAMFailure() { assertEquals("The IAM policy must allow the action s3:GetBucketLocation on the resource arn:aws:s3:::endpoint-9a527d70-d432-4601-b24b-735e721b82c9.", new S3ExceptionMappingService().map("The IAM policy must allow the action s3:GetBucketLocation on the resource arn:aws:s3:::endpoint-9a527d70-d432-4601-b24b-735e721b82c9", new ServiceException("message")).getMessage()); assertEquals("Message. Please contact your web hosting service provider for assistance.", new S3ExceptionMappingService().map("The IAM policy must allow the action s3:GetBucketLocation on the resource arn:aws:s3:::endpoint-9a527d70-d432-4601-b24b-735e721b82c9", new ServiceException("message")).getDetail()); }
@Override public BackgroundException map(final ServiceException e) { if(e.getCause() instanceof ServiceException) { return this.map((ServiceException) e.getCause()); } final StringBuilder buffer = new StringBuilder(); if(StringUtils.isNotBlank(e.getErrorMessage())) { this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage())); } else { this.append(buffer, e.getResponseStatus()); this.append(buffer, e.getMessage()); } switch(e.getResponseCode()) { case HttpStatus.SC_FORBIDDEN: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "SignatureDoesNotMatch": case "InvalidAccessKeyId": case "InvalidClientTokenId": case "InvalidSecurity": case "MissingClientTokenId": case "MissingAuthenticationToken": return new LoginFailureException(buffer.toString(), e); } } case HttpStatus.SC_BAD_REQUEST: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "RequestTimeout": return new ConnectionTimeoutException(buffer.toString(), e); case "ExpiredToken": case "InvalidToken": return new ExpiredTokenException(buffer.toString(), e); } } } if(e.getCause() instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) e.getCause()); } if(e.getCause() instanceof SAXException) { return new InteroperabilityException(buffer.toString(), e); } if(-1 == e.getResponseCode()) { return new InteroperabilityException(buffer.toString(), e); } return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(e.getResponseCode(), buffer.toString())); }
S3ExceptionMappingService extends AbstractExceptionMappingService<ServiceException> { @Override public BackgroundException map(final ServiceException e) { if(e.getCause() instanceof ServiceException) { return this.map((ServiceException) e.getCause()); } final StringBuilder buffer = new StringBuilder(); if(StringUtils.isNotBlank(e.getErrorMessage())) { this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage())); } else { this.append(buffer, e.getResponseStatus()); this.append(buffer, e.getMessage()); } switch(e.getResponseCode()) { case HttpStatus.SC_FORBIDDEN: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "SignatureDoesNotMatch": case "InvalidAccessKeyId": case "InvalidClientTokenId": case "InvalidSecurity": case "MissingClientTokenId": case "MissingAuthenticationToken": return new LoginFailureException(buffer.toString(), e); } } case HttpStatus.SC_BAD_REQUEST: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "RequestTimeout": return new ConnectionTimeoutException(buffer.toString(), e); case "ExpiredToken": case "InvalidToken": return new ExpiredTokenException(buffer.toString(), e); } } } if(e.getCause() instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) e.getCause()); } if(e.getCause() instanceof SAXException) { return new InteroperabilityException(buffer.toString(), e); } if(-1 == e.getResponseCode()) { return new InteroperabilityException(buffer.toString(), e); } return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(e.getResponseCode(), buffer.toString())); } }
S3ExceptionMappingService extends AbstractExceptionMappingService<ServiceException> { @Override public BackgroundException map(final ServiceException e) { if(e.getCause() instanceof ServiceException) { return this.map((ServiceException) e.getCause()); } final StringBuilder buffer = new StringBuilder(); if(StringUtils.isNotBlank(e.getErrorMessage())) { this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage())); } else { this.append(buffer, e.getResponseStatus()); this.append(buffer, e.getMessage()); } switch(e.getResponseCode()) { case HttpStatus.SC_FORBIDDEN: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "SignatureDoesNotMatch": case "InvalidAccessKeyId": case "InvalidClientTokenId": case "InvalidSecurity": case "MissingClientTokenId": case "MissingAuthenticationToken": return new LoginFailureException(buffer.toString(), e); } } case HttpStatus.SC_BAD_REQUEST: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "RequestTimeout": return new ConnectionTimeoutException(buffer.toString(), e); case "ExpiredToken": case "InvalidToken": return new ExpiredTokenException(buffer.toString(), e); } } } if(e.getCause() instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) e.getCause()); } if(e.getCause() instanceof SAXException) { return new InteroperabilityException(buffer.toString(), e); } if(-1 == e.getResponseCode()) { return new InteroperabilityException(buffer.toString(), e); } return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(e.getResponseCode(), buffer.toString())); }  }
S3ExceptionMappingService extends AbstractExceptionMappingService<ServiceException> { @Override public BackgroundException map(final ServiceException e) { if(e.getCause() instanceof ServiceException) { return this.map((ServiceException) e.getCause()); } final StringBuilder buffer = new StringBuilder(); if(StringUtils.isNotBlank(e.getErrorMessage())) { this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage())); } else { this.append(buffer, e.getResponseStatus()); this.append(buffer, e.getMessage()); } switch(e.getResponseCode()) { case HttpStatus.SC_FORBIDDEN: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "SignatureDoesNotMatch": case "InvalidAccessKeyId": case "InvalidClientTokenId": case "InvalidSecurity": case "MissingClientTokenId": case "MissingAuthenticationToken": return new LoginFailureException(buffer.toString(), e); } } case HttpStatus.SC_BAD_REQUEST: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "RequestTimeout": return new ConnectionTimeoutException(buffer.toString(), e); case "ExpiredToken": case "InvalidToken": return new ExpiredTokenException(buffer.toString(), e); } } } if(e.getCause() instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) e.getCause()); } if(e.getCause() instanceof SAXException) { return new InteroperabilityException(buffer.toString(), e); } if(-1 == e.getResponseCode()) { return new InteroperabilityException(buffer.toString(), e); } return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(e.getResponseCode(), buffer.toString())); }  @Override BackgroundException map(final ServiceException e); }
S3ExceptionMappingService extends AbstractExceptionMappingService<ServiceException> { @Override public BackgroundException map(final ServiceException e) { if(e.getCause() instanceof ServiceException) { return this.map((ServiceException) e.getCause()); } final StringBuilder buffer = new StringBuilder(); if(StringUtils.isNotBlank(e.getErrorMessage())) { this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage())); } else { this.append(buffer, e.getResponseStatus()); this.append(buffer, e.getMessage()); } switch(e.getResponseCode()) { case HttpStatus.SC_FORBIDDEN: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "SignatureDoesNotMatch": case "InvalidAccessKeyId": case "InvalidClientTokenId": case "InvalidSecurity": case "MissingClientTokenId": case "MissingAuthenticationToken": return new LoginFailureException(buffer.toString(), e); } } case HttpStatus.SC_BAD_REQUEST: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "RequestTimeout": return new ConnectionTimeoutException(buffer.toString(), e); case "ExpiredToken": case "InvalidToken": return new ExpiredTokenException(buffer.toString(), e); } } } if(e.getCause() instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) e.getCause()); } if(e.getCause() instanceof SAXException) { return new InteroperabilityException(buffer.toString(), e); } if(-1 == e.getResponseCode()) { return new InteroperabilityException(buffer.toString(), e); } return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(e.getResponseCode(), buffer.toString())); }  @Override BackgroundException map(final ServiceException e);  }