Example usage for com.amazonaws DefaultRequest getServiceName

List of usage examples for com.amazonaws DefaultRequest getServiceName

Introduction

In this page you can find the example usage for com.amazonaws DefaultRequest getServiceName.

Prototype

public String getServiceName() 

Source Link

Usage

From source file:org.springframework.vault.authentication.AwsIamAuthentication.java

License:Apache License

private static String getSignedHeaders(AwsIamAuthenticationOptions options) {

    Map<String, String> headers = createIamRequestHeaders(options);

    AWS4Signer signer = new AWS4Signer();

    DefaultRequest<String> request = new DefaultRequest<>("sts");

    request.setContent(new ByteArrayInputStream(REQUEST_BODY.getBytes()));
    request.setHeaders(headers);//from  w w w.j a  v a2  s .  c  o  m
    request.setHttpMethod(HttpMethodName.POST);
    request.setEndpoint(options.getEndpointUri());

    signer.setServiceName(request.getServiceName());
    signer.sign(request, options.getCredentialsProvider().getCredentials());

    Map<String, Object> map = new LinkedHashMap<>();

    for (Entry<String, String> entry : request.getHeaders().entrySet()) {
        map.put(entry.getKey(), Collections.singletonList(entry.getValue()));
    }

    try {
        return OBJECT_MAPPER.writeValueAsString(map);
    } catch (JsonProcessingException e) {
        throw new IllegalStateException("Cannot serialize headers to JSON", e);
    }
}