Example usage for com.amazonaws AmazonServiceException setRequestId

List of usage examples for com.amazonaws AmazonServiceException setRequestId

Introduction

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

Prototype

public void setRequestId(String requestId) 

Source Link

Document

Sets the AWS requestId for this exception.

Usage

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  ww  .  ja v  a  2  s  .c  om*/
    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.edda.AwsException.java

License:Apache License

public static void raise(int code, String svc, String reqId, String error, String msg) {
    StringBuffer buf = new StringBuffer().append("Status Code: ").append(code).append(", AWS Service: ")
            .append(svc).append(", AWS Request ID: ").append(reqId).append(", AWS Error Code: ").append(error)
            .append(", AWS Error Message:").append(msg);
    AmazonServiceException e = new AmazonServiceException(buf.toString());
    e.setStatusCode(code);/* w  w w.ja  va  2  s. com*/
    e.setServiceName(svc);
    e.setRequestId(reqId);
    e.setErrorCode(error);
    throw e;
}

From source file:com.netflix.edda.EddaAwsClient.java

License:Apache License

protected byte[] doGet(final String uri) {
    try {//w ww .  j  av  a2s. c o  m
        return EddaContext.getContext().getRxHttp().get(mkUrl(uri)).flatMap(response -> {
            if (response.getStatus().code() != 200) {
                AmazonServiceException e = new AmazonServiceException("Failed to fetch " + uri);
                e.setStatusCode(response.getStatus().code());
                e.setErrorCode("Edda");
                e.setRequestId(uri);
                return rx.Observable.error(e);
            }
            return response.getContent().reduce(new ByteArrayOutputStream(), (out, bb) -> {
                try {
                    bb.readBytes(out, bb.readableBytes());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                return out;
            }).map(out -> {
                return out.toByteArray();
            });
        }).toBlocking().toFuture().get(2, TimeUnit.MINUTES);
    } catch (Exception e) {
        throw new RuntimeException("failed to get url: " + uri, e);
    }
}