@Test public void metadata401_shouldThrowException() throws IOException { generateSuccessfulTokenStub(); generateStub(401, "{\"code\":\"401 Unauthorized\",\"message\":\"ERROR_MESSAGE\"}"); try { resourceFetcher.readResource(endpoint); fail("Expected AmazonServiceException"); } catch (AmazonServiceException ase) { assertEquals(401, ase.getStatusCode()); assertEquals("401 Unauthorized", ase.getErrorCode()); assertEquals("ERROR_MESSAGE", ase.getErrorMessage()); } }
@Override public String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy, Map<String, String> headers) { if (SDKGlobalConfiguration.isEc2MetadataDisabled()) { throw new AmazonClientException("EC2 Instance Metadata Service is disabled"); } Map<String, String> newHeaders = addDefaultHeaders(headers); String token = getToken(); if (token != null) { newHeaders.put(TOKEN_HEADER, token); } return doReadResource(endpoint, retryPolicy, newHeaders); }
InstanceMetadataServiceResourceFetcher extends EC2ResourceFetcher { @Override public String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy, Map<String, String> headers) { if (SDKGlobalConfiguration.isEc2MetadataDisabled()) { throw new AmazonClientException("EC2 Instance Metadata Service is disabled"); } Map<String, String> newHeaders = addDefaultHeaders(headers); String token = getToken(); if (token != null) { newHeaders.put(TOKEN_HEADER, token); } return doReadResource(endpoint, retryPolicy, newHeaders); } }
InstanceMetadataServiceResourceFetcher extends EC2ResourceFetcher { @Override public String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy, Map<String, String> headers) { if (SDKGlobalConfiguration.isEc2MetadataDisabled()) { throw new AmazonClientException("EC2 Instance Metadata Service is disabled"); } Map<String, String> newHeaders = addDefaultHeaders(headers); String token = getToken(); if (token != null) { newHeaders.put(TOKEN_HEADER, token); } return doReadResource(endpoint, retryPolicy, newHeaders); } private  InstanceMetadataServiceResourceFetcher(); @SdkTestInternalApi  InstanceMetadataServiceResourceFetcher(ConnectionUtils connectionUtils); }
InstanceMetadataServiceResourceFetcher extends EC2ResourceFetcher { @Override public String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy, Map<String, String> headers) { if (SDKGlobalConfiguration.isEc2MetadataDisabled()) { throw new AmazonClientException("EC2 Instance Metadata Service is disabled"); } Map<String, String> newHeaders = addDefaultHeaders(headers); String token = getToken(); if (token != null) { newHeaders.put(TOKEN_HEADER, token); } return doReadResource(endpoint, retryPolicy, newHeaders); } private  InstanceMetadataServiceResourceFetcher(); @SdkTestInternalApi  InstanceMetadataServiceResourceFetcher(ConnectionUtils connectionUtils); static InstanceMetadataServiceResourceFetcher getInstance(); @Override String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy, Map<String, String> headers); }
InstanceMetadataServiceResourceFetcher extends EC2ResourceFetcher { @Override public String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy, Map<String, String> headers) { if (SDKGlobalConfiguration.isEc2MetadataDisabled()) { throw new AmazonClientException("EC2 Instance Metadata Service is disabled"); } Map<String, String> newHeaders = addDefaultHeaders(headers); String token = getToken(); if (token != null) { newHeaders.put(TOKEN_HEADER, token); } return doReadResource(endpoint, retryPolicy, newHeaders); } private  InstanceMetadataServiceResourceFetcher(); @SdkTestInternalApi  InstanceMetadataServiceResourceFetcher(ConnectionUtils connectionUtils); static InstanceMetadataServiceResourceFetcher getInstance(); @Override String readResource(URI endpoint, CredentialsEndpointRetryPolicy retryPolicy, Map<String, String> headers);  }