use of software.amazon.awssdk.protocols.json.AwsJsonProtocol in project aws-sdk-java-v2 by aws.
the class JsonProtocolMarshaller method finishMarshalling.
private SdkHttpFullRequest finishMarshalling() {
// Content may already be set if the payload is binary data.
if (request.contentStreamProvider() == null) {
// End the implicit request object if needed.
if (needTopLevelJsonObject()) {
jsonGenerator.writeEndObject();
}
byte[] content = jsonGenerator.getBytes();
if (content != null) {
request.contentStreamProvider(() -> new ByteArrayInputStream(content));
if (content.length > 0) {
request.putHeader(CONTENT_LENGTH, Integer.toString(content.length));
}
}
}
// and not from the original request
if (!request.headers().containsKey(CONTENT_TYPE) && !hasEvent) {
if (hasEventStreamingInput) {
AwsJsonProtocol protocol = protocolMetadata.protocol();
if (protocol == AwsJsonProtocol.AWS_JSON) {
// For RPC formats, this content type will later be pushed down into the `initial-event` in the body
request.putHeader(CONTENT_TYPE, contentType);
} else if (protocol == AwsJsonProtocol.REST_JSON) {
request.putHeader(CONTENT_TYPE, MIMETYPE_EVENT_STREAM);
} else {
throw new IllegalArgumentException("Unknown AwsJsonProtocol: " + protocol);
}
request.removeHeader(CONTENT_LENGTH);
request.putHeader(TRANSFER_ENCODING, CHUNKED);
} else if (contentType != null && !hasStreamingInput && request.headers().containsKey(CONTENT_LENGTH)) {
request.putHeader(CONTENT_TYPE, contentType);
}
}
return request.build();
}
Aggregations