本文整理汇总了Java中com.amazonaws.ResponseMetadata类的典型用法代码示例。如果您正苦于以下问题:Java ResponseMetadata类的具体用法?Java ResponseMetadata怎么用?Java ResponseMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResponseMetadata类属于com.amazonaws包,在下文中一共展示了ResponseMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateAndEndSubsegment
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
private void populateAndEndSubsegment(Subsegment currentSubsegment, Request<?> request, Response<?> response) {
if (null != response) {
String requestId = null;
if (response.getAwsResponse() instanceof AmazonWebServiceResult<?>) { // Not all services return responses extending AmazonWebServiceResult (e.g. S3)
ResponseMetadata metadata = ((AmazonWebServiceResult<?>) response.getAwsResponse()).getSdkResponseMetadata();
if (null != metadata) {
requestId = metadata.getRequestId();
if (null != requestId) {
currentSubsegment.putAws(REQUEST_ID_SUBSEGMENT_KEY, requestId);
}
}
} else if (null != response.getHttpResponse()) { // S3 does not follow request id header convention
if (null != response.getHttpResponse().getHeader(S3_REQUEST_ID_HEADER_KEY)) {
currentSubsegment.putAws(REQUEST_ID_SUBSEGMENT_KEY, response.getHttpResponse().getHeader(S3_REQUEST_ID_HEADER_KEY));
}
if (null != response.getHttpResponse().getHeader(S3_EXTENDED_REQUEST_ID_HEADER_KEY)) {
currentSubsegment.putAws(EXTENDED_REQUEST_ID_SUBSEGMENT_KEY, response.getHttpResponse().getHeader(S3_EXTENDED_REQUEST_ID_HEADER_KEY));
}
}
currentSubsegment.putAllAws(extractResponseParameters(request, response.getAwsResponse()));
currentSubsegment.putAllHttp(extractHttpResponseInformation(response.getHttpResponse()));
}
finalizeSubsegment(request);
}
示例2: get
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
public synchronized ResponseMetadata get(Object obj) {
// System.identityHashCode isn't guaranteed to be unique
// on all platforms, but should be reasonable enough to use
// for a few requests at a time. We can always easily move
// to our own unique IDs if needed.
return internalCache.get(System.identityHashCode(obj));
}
示例3: testEviction
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
/** Tests that the cache correctly evicts the oldest entries. */
@Test
public void testEviction() {
ResponseMetadataCache cache = new ResponseMetadataCache(3);
AmazonWebServiceRequest key1 = new TestRequest();
AmazonWebServiceRequest key2 = new TestRequest();
AmazonWebServiceRequest key3 = new TestRequest();
AmazonWebServiceRequest key4 = new TestRequest();
ResponseMetadata metadata1 = newResponseMetadata();
ResponseMetadata metadata2 = newResponseMetadata();
ResponseMetadata metadata3 = newResponseMetadata();
ResponseMetadata metadata4 = newResponseMetadata();
// Fill the cache
cache.add(key1, metadata1);
cache.add(key2, metadata2);
cache.add(key3, metadata3);
// Verify all entries are still there
assertEquals(metadata1, cache.get(key1));
assertEquals(metadata2, cache.get(key2));
assertEquals(metadata3, cache.get(key3));
// Add another and make sure the oldest is evicted
cache.add(key4, metadata4);
assertNull(cache.get(key1));
assertEquals(metadata2, cache.get(key2));
assertEquals(metadata3, cache.get(key3));
assertEquals(metadata4, cache.get(key4));
}
示例4: TestEmpty
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
/** Tests that the cache works correctly with size=0 */
@Test
public void TestEmpty() {
ResponseMetadataCache cache = new ResponseMetadataCache(0);
AmazonWebServiceRequest key = new TestRequest();
ResponseMetadata metadata = newResponseMetadata();
// Add item to the cache, it should be immediately evicted.
cache.add(key, metadata);
// get should return null
assertNull(cache.get(key));
}
示例5: parseResponseMetadata
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
/**
* Parses the S3 response metadata (ex: AWS request ID) from the specified
* response, and returns a AmazonWebServiceResponse<T> object ready for the
* result to be plugged in.
*
* @param response
* The response containing the response metadata to pull out.
*
* @return A new, populated AmazonWebServiceResponse<T> object, ready for
* the result to be plugged in.
*/
protected AmazonWebServiceResponse<T> parseResponseMetadata(HttpResponse response) {
AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
String awsRequestId = response.getHeaders().get(Headers.REQUEST_ID);
String hostId = response.getHeaders().get(Headers.EXTENDED_REQUEST_ID);
String cloudFrontId = response.getHeaders().get(Headers.CLOUD_FRONT_ID);
Map<String, String> metadataMap = new HashMap<String, String>();
metadataMap.put(ResponseMetadata.AWS_REQUEST_ID, awsRequestId);
metadataMap.put(S3ResponseMetadata.HOST_ID, hostId);
metadataMap.put(S3ResponseMetadata.CLOUD_FRONT_ID, cloudFrontId);
awsResponse.setResponseMetadata(new S3ResponseMetadata(metadataMap));
return awsResponse;
}
示例6: getCachedResponseMetadata
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest request) {
Map<String, String> metadata = new HashMap<String, String>();
ResponseMetadata responseMetadata = new ResponseMetadata(metadata);
return responseMetadata;
}
示例7: getCachedResponseMetadata
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest request) {
throw new UnsupportedOperationException("Not supported in mock");
}
示例8: getCachedResponseMetadata
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest amazonWebServiceRequest) {
return null;
}
示例9: handle
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
/**
* @see HttpResponseHandler#handle(HttpResponse)
*/
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
log.trace("Parsing service response JSON");
String CRC32Checksum = response.getHeaders().get("x-amz-crc32");
JsonParser jsonParser = null;
if (shouldParsePayloadAsJson()) {
jsonParser = jsonFactory.createParser(response.getContent());
}
try {
AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
JsonUnmarshallerContext unmarshallerContext = new JsonUnmarshallerContextImpl(
jsonParser, simpleTypeUnmarshallers, customTypeMarshallers, response);
registerAdditionalMetadataExpressions(unmarshallerContext);
T result = responseUnmarshaller.unmarshall(unmarshallerContext);
// Make sure we read all the data to get an accurate CRC32 calculation.
// See https://github.com/aws/aws-sdk-java/issues/1018
if (shouldParsePayloadAsJson() && response.getContent() != null) {
IOUtils.drainInputStream(response.getContent());
}
if (CRC32Checksum != null) {
long serverSideCRC = Long.parseLong(CRC32Checksum);
long clientSideCRC = response.getCRC32Checksum();
if (clientSideCRC != serverSideCRC) {
throw new CRC32MismatchException(
"Client calculated crc32 checksum didn't match that calculated by server side");
}
}
awsResponse.setResult(result);
Map<String, String> metadata = unmarshallerContext.getMetadata();
metadata.put(ResponseMetadata.AWS_REQUEST_ID,
response.getHeaders().get(X_AMZN_REQUEST_ID_HEADER));
awsResponse.setResponseMetadata(new ResponseMetadata(metadata));
log.trace("Done parsing service response");
return awsResponse;
} finally {
if (shouldParsePayloadAsJson()) {
try {
jsonParser.close();
} catch (IOException e) {
log.warn("Error closing json parser", e);
}
}
}
}
示例10: add
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
public void add(Object obj, ResponseMetadata metadata) {
// deliberately left blank
}
示例11: get
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
public ResponseMetadata get(Object obj) {
throw new SdkClientException("Response metadata caching is not enabled");
}
示例12: add
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
public synchronized void add(Object obj, ResponseMetadata metadata) {
if (obj == null) return;
internalCache.put(System.identityHashCode(obj), metadata);
}
示例13: removeEldestEntry
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
protected boolean removeEldestEntry(Entry<Integer,ResponseMetadata> eldest) {
return size() > maxSize;
}
示例14: newResponseMetadata
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
private ResponseMetadata newResponseMetadata() {
HashMap<String, String> metadata = new HashMap<String, String>();
metadata.put("foo", "bar-" + new Random().nextLong());
return new ResponseMetadata(metadata);
}
示例15: getCachedResponseMetadata
import com.amazonaws.ResponseMetadata; //导入依赖的package包/类
@Override
public ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest arg0) {
throw new java.lang.UnsupportedOperationException();
}