use of software.amazon.eventstream.HeaderValue in project aws-sdk-java-v2 by aws.
the class SelectObjectContentTest method encodedEvents.
private byte[] encodedEvents(List<SelectObjectContentEventStream> events) {
ByteArrayOutputStream eventStreamBytes = new ByteArrayOutputStream();
MarshallingVisitor marshaller = new MarshallingVisitor();
events.stream().map(e -> {
marshaller.reset();
e.accept(marshaller);
Map<String, HeaderValue> headers = new HashMap<>();
headers.put(":message-type", HeaderValue.fromString("event"));
headers.put(":event-type", HeaderValue.fromString(e.sdkEventType().toString()));
return new Message(headers, marshaller.marshalledBytes());
}).forEach(m -> m.encode(eventStreamBytes));
return eventStreamBytes.toByteArray();
}
use of software.amazon.eventstream.HeaderValue in project aws-sdk-java-v2 by aws.
the class BaseEventStreamAsyncAws4Signer method getDataFrameSigner.
private Function<ByteBuffer, ByteBuffer> getDataFrameSigner(String headerSignature, AwsCredentials credentials, Aws4SignerRequestParams signerRequestParams) {
return new Function<ByteBuffer, ByteBuffer>() {
final Aws4SignerRequestParams requestParams = signerRequestParams;
/**
* Initiate rolling signature with header signature
*/
String priorSignature = headerSignature;
@Override
public ByteBuffer apply(ByteBuffer byteBuffer) {
/**
* Signing Date
*/
Map<String, HeaderValue> nonSignatureHeaders = new HashMap<>();
Instant signingInstant = requestParams.getSigningClock().instant();
nonSignatureHeaders.put(EVENT_STREAM_DATE, HeaderValue.fromTimestamp(signingInstant));
/**
* Derive Signing Key
*/
AwsCredentials sanitizedCredentials = sanitizeCredentials(credentials);
byte[] signingKey = deriveSigningKey(sanitizedCredentials, signingInstant, requestParams.getRegionName(), requestParams.getServiceSigningName());
/**
* Calculate rolling signature
*/
byte[] payload = byteBuffer.array();
byte[] signatureBytes = signEventStream(priorSignature, signingKey, signingInstant, requestParams, nonSignatureHeaders, payload);
priorSignature = BinaryUtils.toHex(signatureBytes);
/**
* Add signing layer event-stream headers
*/
Map<String, HeaderValue> headers = new HashMap<>(nonSignatureHeaders);
// Signature headers
headers.put(EVENT_STREAM_SIGNATURE, HeaderValue.fromByteArray(signatureBytes));
/**
* Encode signed event to byte
*/
Message signedMessage = new Message(sortHeaders(headers), payload);
if (LOG.isLoggingLevelEnabled("trace")) {
LOG.trace(() -> "Signed message: " + toDebugString(signedMessage, false));
} else {
LOG.debug(() -> "Signed message: " + toDebugString(signedMessage, true));
}
return signedMessage.toByteBuffer();
}
};
}
Aggregations