private SdkHttpFullRequest finishMarshalling(SdkPojo pojo) { // Content may already be set if the payload is binary data. if (hasPayloadMembers(pojo) && request.contentStreamProvider() == null && marshallerContext.xmlGenerator() != null) { String content = marshallerContext.xmlGenerator().stringWriter().getBuffer().toString(); if (!content.isEmpty()) { request.contentStreamProvider(() -> new StringInputStream(content)); request.putHeader("Content-Length", Integer.toString(content.getBytes(StandardCharsets.UTF_8).length)); setContentTypeHeaderIfNeeded("application/xml"); } } return request.build(); }
private SdkHttpFullRequest finishMarshalling(SdkPojo pojo) { // Content may already be set if the payload is binary data. if (hasPayloadMembers(pojo) && request.contentStreamProvider() == null && marshallerContext.xmlGenerator() != null) { String content = marshallerContext.xmlGenerator().stringWriter().getBuffer().toString(); if (!content.isEmpty()) { request.contentStreamProvider(() -> new StringInputStream(content)); request.putHeader("Content-Length", Integer.toString(content.getBytes(StandardCharsets.UTF_8).length)); setContentTypeHeaderIfNeeded("application/xml"); } } return request.build(); }
void doMarshall(SdkPojo pojo) { for (SdkField<?> field : pojo.sdkFields()) { Object val = field.getValueOrDefault(pojo); if (isBinary(field, val)) { request.contentStreamProvider(((SdkBytes) val)::asInputStream); setContentTypeHeaderIfNeeded("binary/octet-stream"); } else if (isExplicitPayloadMember(field) && val instanceof String) { byte[] content = ((String) val).getBytes(StandardCharsets.UTF_8); request.contentStreamProvider(() -> new ByteArrayInputStream(content)); request.putHeader(CONTENT_LENGTH, Integer.toString(content.length)); } else { MARSHALLER_REGISTRY.getMarshaller(field.location(), field.marshallingType(), val) .marshall(val, marshallerContext, field.locationName(), (SdkField<Object>) field); } } }
void doMarshall(SdkPojo pojo) { for (SdkField<?> field : pojo.sdkFields()) { Object val = field.getValueOrDefault(pojo); if (isBinary(field, val)) { request.contentStreamProvider(((SdkBytes) val)::asInputStream); setContentTypeHeaderIfNeeded("binary/octet-stream"); } else if (isExplicitPayloadMember(field) && val instanceof String) { byte[] content = ((String) val).getBytes(StandardCharsets.UTF_8); request.contentStreamProvider(() -> new ByteArrayInputStream(content)); request.putHeader(CONTENT_LENGTH, Integer.toString(content.length)); } else { MARSHALLER_REGISTRY.getMarshaller(field.location(), field.marshallingType(), val) .marshall(val, marshallerContext, field.locationName(), (SdkField<Object>) field); } } }