/** * @return HTTP status code of response. */ public int httpStatusCode() { return httpMetadata.getHttpStatusCode(); }
/** * Static factory to create an {@link SdkHttpMetadata} from the details in a {@link * HttpResponse}. */ public static SdkHttpMetadata from(HttpResponse httpResponse) { return new SdkHttpMetadata(httpResponse.getHeaders(), httpResponse.getStatusCode()); }
/** * @return x-amzn-RequestId generated by the API Gateway frontend. Uniquely identifies a request * and can be used for troubleshooting server side issues. */ public String requestId() { return httpMetadata.getHttpHeaders().get(HEADER_REQUEST_ID); }
@SuppressWarnings("unchecked") private <T> T fillInResponseMetadata(AmazonWebServiceResponse<T> awsResponse, HttpResponse httpResponse) { final T result = awsResponse.getResult(); if (result instanceof AmazonWebServiceResult<?>) { ((AmazonWebServiceResult) result) .setSdkResponseMetadata(awsResponse.getResponseMetadata()) .setSdkHttpMetadata(SdkHttpMetadata.from(httpResponse)); } return result; }
@Override public T handle(HttpResponse httpResponse) throws Exception { T result = delegate.handle(httpResponse).getResult(); result.sdkResponseMetadata(new SdkResponseMetadata(SdkHttpMetadata.from(httpResponse))); return result; }
/** * @return HTTP status code of response. */ public int httpStatusCode() { return httpMetadata.getHttpStatusCode(); } }
@Override public RawResult unmarshall(JsonUnmarshallerContext in) throws IOException { HttpResponse response = in.getHttpResponse(); RawResult result = new RawResult(); result.sdkResponseMetadata(new SdkResponseMetadata(SdkHttpMetadata.from(response))); try { resultContentConsumer.consume(result, response.getContent()); } finally { response.getContent().close(); } return result; } }
/** * Static factory to create an {@link SdkHttpMetadata} from the details in a {@link * HttpResponse}. */ public static SdkHttpMetadata from(HttpResponse httpResponse) { return new SdkHttpMetadata(httpResponse.getHeaders(), httpResponse.getStatusCode()); }
/** * @return x-amzn-RequestId generated by the API Gateway frontend. Uniquely identifies a request * and can be used for troubleshooting server side issues. */ public String requestId() { return httpMetadata.getHttpHeaders().get(HEADER_REQUEST_ID); }
private void addPolicy(List<String> accountsToAuthorize) { if(accountsToAuthorize == null || accountsToAuthorize.isEmpty()) { logger.info("No additional security policies attached for the queue " + queueName); return; } logger.info("Authorizing " + accountsToAuthorize + " to the queue " + queueName); Map<String, String> attributes = new HashMap<>(); attributes.put("Policy", getPolicy(accountsToAuthorize)); SetQueueAttributesResult result = client.setQueueAttributes(queueURL, attributes); logger.info("policy attachment result: " + result); logger.info("policy attachment result: status=" + result.getSdkHttpMetadata().getHttpStatusCode()); }
@Override public SdkBaseException handle(HttpResponse response) throws Exception { JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory); BaseException exception = createException(response.getStatusCode(), jsonContent); exception.sdkHttpMetadata(new SdkErrorHttpMetadata(SdkHttpMetadata.from(response), jsonContent.getRawContent())); exception.setMessage(messageParser.parseErrorMessage(jsonContent.getJsonNode())); // Wrap in ASE, will be unwrapped when caught in the service client. return (SdkBaseException) exception; }
/** * Static factory to create an {@link SdkHttpMetadata} from the details in a {@link * HttpResponse}. */ public static SdkHttpMetadata from(HttpResponse httpResponse) { return new SdkHttpMetadata(httpResponse.getHeaders(), httpResponse.getStatusCode()); }
/** * Get a specific header from the error response. * * @param headerName Header to retrieve. * @return Optional of header value. */ public Optional<String> header(String headerName) { return Optional.ofNullable(httpMetadata.getHttpHeaders().get(headerName)); }
private void addPolicy(List<String> accountsToAuthorize) { if(accountsToAuthorize == null || accountsToAuthorize.isEmpty()) { logger.info("No additional security policies attached for the queue " + queueName); return; } logger.info("Authorizing " + accountsToAuthorize + " to the queue " + queueName); Map<String, String> attributes = new HashMap<>(); attributes.put("Policy", getPolicy(accountsToAuthorize)); SetQueueAttributesResult result = client.setQueueAttributes(queueURL, attributes); logger.info("policy attachment result: " + result); logger.info("policy attachment result: status=" + result.getSdkHttpMetadata().getHttpStatusCode()); }
@SuppressWarnings("unchecked") private <T> T fillInResponseMetadata(AmazonWebServiceResponse<T> awsResponse, HttpResponse httpResponse) { final T result = awsResponse.getResult(); if (result instanceof AmazonWebServiceResult<?>) { ((AmazonWebServiceResult) result) .setSdkResponseMetadata(awsResponse.getResponseMetadata()) .setSdkHttpMetadata(SdkHttpMetadata.from(httpResponse)); } return result; }
/** * Get a specific header from the HTTP response. * * @param headerName Header to retrieve. * @return Optional of header value. */ public Optional<String> header(String headerName) { return Optional.ofNullable(httpMetadata.getHttpHeaders().get(headerName)); }
private static boolean streamExists(AmazonKinesis client, String streamName) { try { DescribeStreamResult describeStreamResult = client.describeStream(streamName); return (describeStreamResult != null && describeStreamResult.getSdkHttpMetadata().getHttpStatusCode() == 200); } catch (Exception e) { LOG.warn("Error checking whether stream {} exists.", streamName, e); } return false; }
@SuppressWarnings("unchecked") private <T> T fillInResponseMetadata(AmazonWebServiceResponse<T> awsResponse, HttpResponse httpResponse) { final T result = awsResponse.getResult(); if (result instanceof AmazonWebServiceResult<?>) { ((AmazonWebServiceResult) result) .setSdkResponseMetadata(awsResponse.getResponseMetadata()) .setSdkHttpMetadata(SdkHttpMetadata.from(httpResponse)); } return result; }
@SuppressWarnings({"checkstyle:illegalCatch"}) private static boolean topicExists(AmazonSNS client, String topicName) { try { GetTopicAttributesResult topicAttributesResult = client.getTopicAttributes(topicName); return topicAttributesResult != null && topicAttributesResult.getSdkHttpMetadata().getHttpStatusCode() == 200; } catch (Exception e) { LOG.warn("Error checking whether topic {} exists.", topicName, e); throw e; } } }
@Override public DescribeStreamResult describeStream(String streamName, String exclusiveStartShardId) { int nextShardId = 0; if (exclusiveStartShardId != null) { nextShardId = parseInt(exclusiveStartShardId) + 1; } boolean hasMoreShards = nextShardId + 1 < shardedData.size(); List<Shard> shards = new ArrayList<>(); if (nextShardId < shardedData.size()) { shards.add(new Shard().withShardId(Integer.toString(nextShardId))); } HttpResponse response = new HttpResponse(null, null); response.setStatusCode(200); DescribeStreamResult result = new DescribeStreamResult(); result.setSdkHttpMetadata(SdkHttpMetadata.from(response)); result.withStreamDescription( new StreamDescription() .withHasMoreShards(hasMoreShards) .withShards(shards) .withStreamName(streamName)); return result; }