List of usage examples for com.amazonaws AmazonServiceException setErrorType
public void setErrorType(ErrorType errorType)
From source file:com.msi.dns53.client.DNS53Client.java
License:Apache License
@SuppressWarnings("unchecked") public void exceptionMapper(ClientResponse response, String resultXml) throws AmazonServiceException { ErrorResponsePOJO er = null;/*from w w w.j a v a 2s . c o m*/ try { StringReader reader = new StringReader(resultXml); JAXBContext context = JAXBContext.newInstance(ErrorResponsePOJO.class); Unmarshaller unmarshaller = context.createUnmarshaller(); er = (ErrorResponsePOJO) unmarshaller.unmarshal(reader); } catch (JAXBException e) { e.printStackTrace(); throw new AmazonClientException("There was a problem parsing the error response xml with JAXB.", e); } if (er == null || er.getError() == null || er.getRequestId() == null || er.getError().getCode() == null || er.getError().getMessage() == null || er.getError().getType() == null) { throw new AmazonClientException( "Error response xml did not contain expected elements although it is well formed."); } String errCode = er.getError().getCode(); Class<AmazonServiceException> clazz = null; Constructor<AmazonServiceException> c = null; AmazonServiceException exception = null; try { String clazzName = ExceptionMap.getExceptionMap().getMap().get(errCode); clazz = (Class<AmazonServiceException>) Class.forName(clazzName); c = (Constructor<AmazonServiceException>) clazz.getConstructor(String.class); exception = (AmazonServiceException) c.newInstance(new Object[] { er.getError().getMessage() }); } catch (NullPointerException e) { exception = new AmazonServiceException(er.getError().getMessage()); } catch (Exception e) { e.printStackTrace(); throw new AmazonClientException("Client could not determine the type of the error response."); } if (exception == null) { throw new AmazonClientException( "Client encountered a problem while it was mapping the error response."); } exception.setErrorCode(er.getError().getCode()); ErrorType et = ErrorType.Unknown; if ("Sender".equals(er.getError().getType())) { et = ErrorType.Service; } exception.setErrorType(et); exception.setRequestId(er.getRequestId()); exception.setStatusCode(response.getStatus()); exception.setServiceName("DNS53"); throw exception; }
From source file:com.netflix.spinnaker.clouddriver.aws.security.AmazonClientInvocationHandler.java
License:Apache License
private <T> List<T> describe(AmazonWebServiceRequest request, String idKey, final String object, final Class<T> singleType) { lastModified.set(null);//from w w w. ja v a 2s .c om try { JavaType singleMeta = objectMapper.getTypeFactory().constructParametrizedType(Metadata.class, Metadata.class, singleType); Collection<String> ids = getRequestIds(request, idKey); Long mtime = null; List<T> results = new ArrayList<>(); if (ids.isEmpty()) { final byte[] json = getJson(object, null); JavaType listMeta = objectMapper.getTypeFactory().constructParametrizedType(List.class, List.class, singleMeta); List<Metadata<T>> metadataResults = objectMapper.readValue(json, listMeta); for (Metadata<T> meta : metadataResults) { mtime = mtime == null ? meta.mtime : Math.min(mtime, meta.mtime); results.add(meta.data); } } else { for (String id : ids) { final byte[] json = getJson(object, id); Metadata<T> result = objectMapper.readValue(json, singleMeta); mtime = mtime == null ? result.mtime : Math.min(mtime, result.mtime); results.add(result.data); } } lastModified.set(mtime); return results; } catch (Exception e) { AmazonServiceException ex = new AmazonServiceException( "400 Bad Request -- Edda could not find one of the managed objects requested.", e); ex.setStatusCode(400); ex.setServiceName(serviceName); ex.setErrorType(AmazonServiceException.ErrorType.Unknown); throw ex; } }
From source file:com.netflix.spinnaker.clouddriver.aws.security.sdkclient.AmazonClientInvocationHandler.java
License:Apache License
private <T> List<T> describe(AmazonWebServiceRequest request, String idKey, final String object, final Class<T> singleType) { lastModified.set(null);/*from w ww . jav a2s .com*/ final Map<String, String> metricTags = new HashMap<>(this.metricTags); metricTags.put("collection", object); try { final Collection<String> ids = getRequestIds(request, idKey); metricTags.put("collectionMode", ids.isEmpty() ? "full" : "byId"); final JavaType singleMeta = objectMapper.getTypeFactory().constructParametrizedType(Metadata.class, Metadata.class, singleType); Long mtime = null; final List<T> results = new ArrayList<>(); final Id deserializeJsonTimer = registry.createId("edda.deserializeJson", metricTags); final Id resultSizeCounter = registry.createId("edda.resultSize", metricTags); if (ids.isEmpty()) { HttpEntity entity = getHttpEntity(metricTags, object, null); try { final JavaType listMeta = objectMapper.getTypeFactory().constructParametrizedType(List.class, List.class, singleMeta); final List<Metadata<T>> metadataResults = registry.timer(deserializeJsonTimer) .record(() -> objectMapper.readValue(entity.getContent(), listMeta)); for (Metadata<T> meta : metadataResults) { mtime = mtime == null ? meta.mtime : Math.min(mtime, meta.mtime); results.add(meta.data); } } finally { EntityUtils.consume(entity); } } else { for (String id : ids) { HttpEntity entity = getHttpEntity(metricTags, object, id); try { final Metadata<T> result = registry.timer(deserializeJsonTimer) .record(() -> objectMapper.readValue(entity.getContent(), singleMeta)); mtime = mtime == null ? result.mtime : Math.min(mtime, result.mtime); results.add(result.data); } finally { EntityUtils.consume(entity); } } } registry.counter(resultSizeCounter).increment(results.size()); lastModified.set(mtime); return results; } catch (Exception e) { log.error(e.getMessage() + " (retries exhausted)"); registry.counter(registry.createId("edda.failures", metricTags)).increment(); final AmazonServiceException ex = new AmazonServiceException( "400 Bad Request -- Edda could not find one of the managed objects requested.", e); ex.setStatusCode(400); ex.setServiceName(serviceName); ex.setErrorType(AmazonServiceException.ErrorType.Unknown); throw ex; } }
From source file:com.netflix.spinnaker.kork.aws.AwsMetricsSupport.java
License:Apache License
static AmazonServiceException amazonServiceException(Exception exception, String serviceName, int statusCode) { if (exception instanceof AmazonServiceException) { return (AmazonServiceException) exception; }/*from w ww . j ava2s .com*/ final AmazonServiceException ase = new AmazonServiceException(exception.getMessage(), exception); ase.setStatusCode(statusCode); ase.setErrorCode(DEFAULT_UNKNOWN); ase.setServiceName(serviceName); ase.setErrorType(AmazonServiceException.ErrorType.Unknown); return ase; }