@Override public void beforeRequest(Request<?> request) { if (request.getOriginalRequest() instanceof SearchRequest && request.getHttpMethod() == HttpMethodName.GET) { request.setHttpMethod(HttpMethodName.POST); final byte[] content = SdkHttpUtils.encodeParameters(request).getBytes(); request.setContent(new ByteArrayInputStream(content)); request.addHeader("Content-Type", "application/x-www-form-urlencoded"); request.addHeader("Content-Length", Integer.toString(content.length)); request.getParameters().clear(); } } }
@Override public void beforeRequest(Request<?> request) { request.addHandlerContext(S3HandlerContextKeys.IS_PAYLOAD_SIGNING_ENABLED, true); if (request.getContent() == null && request.getHttpMethod() == HttpMethodName.POST) { request.setContent(new ByteArrayInputStream(new byte[0])); } } }
private void setContent(Request<?> request, byte[] content, String contentType, boolean setMd5) { request.setContent(new ByteArrayInputStream(content)); request.addHeader("Content-Length", Integer.toString(content.length)); request.addHeader("Content-Type", contentType); if (setMd5) { try { byte[] md5 = Md5Utils.computeMD5Hash(content); String md5Base64 = BinaryUtils.toBase64(md5); request.addHeader("Content-MD5", md5Base64); } catch ( Exception e ) { throw new AmazonClientException("Couldn't compute md5 sum", e); } } }
if (originalRequest == null) originalRequest = new GenericBucketRequest(bucketName); Request<AmazonWebServiceRequest> request = createRequest(bucketName, key, originalRequest, HttpMethodName.PUT); request.addHeader("Content-Type", "application/xml"); request.addHeader("Content-Length", String.valueOf(aclAsXml.length)); request.setContent(new ByteArrayInputStream(aclAsXml));
public Request<UpdateHostedZoneCommentRequest> marshall(UpdateHostedZoneCommentRequest updateHostedZoneCommentRequest) { if (updateHostedZoneCommentRequest == null) { throw new SdkClientException("Invalid argument passed to marshall(...)"); } Request<UpdateHostedZoneCommentRequest> request = new DefaultRequest<UpdateHostedZoneCommentRequest>(updateHostedZoneCommentRequest, "AmazonRoute53"); request.setHttpMethod(HttpMethodName.POST); String uriResourcePath = "/2013-04-01/hostedzone/{Id}"; uriResourcePath = com.amazonaws.transform.PathMarshallers.NON_GREEDY.marshall(uriResourcePath, "Id", updateHostedZoneCommentRequest.getId()); request.setResourcePath(uriResourcePath); try { StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, "https://route53.amazonaws.com/doc/2013-04-01/"); xmlWriter.startElement("UpdateHostedZoneCommentRequest"); if (updateHostedZoneCommentRequest != null) { if (updateHostedZoneCommentRequest.getComment() != null) { xmlWriter.startElement("Comment").value(updateHostedZoneCommentRequest.getComment()).endElement(); } } xmlWriter.endElement(); request.setContent(new StringInputStream(stringWriter.getBuffer().toString())); request.addHeader("Content-Length", Integer.toString(stringWriter.getBuffer().toString().getBytes(UTF8).length)); if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", "application/xml"); } } catch (Throwable t) { throw new SdkClientException("Unable to marshall request to XML: " + t.getMessage(), t); } return request; }
@Override public void setBucketLoggingConfiguration(SetBucketLoggingConfigurationRequest setBucketLoggingConfigurationRequest) throws SdkClientException, AmazonServiceException { setBucketLoggingConfigurationRequest = beforeClientExecution(setBucketLoggingConfigurationRequest); rejectNull(setBucketLoggingConfigurationRequest, "The set bucket logging configuration request object must be specified when enabling server access logging"); String bucketName = setBucketLoggingConfigurationRequest.getBucketName(); BucketLoggingConfiguration loggingConfiguration = setBucketLoggingConfigurationRequest.getLoggingConfiguration(); rejectNull(bucketName, "The bucket name parameter must be specified when enabling server access logging"); rejectNull(loggingConfiguration, "The logging configuration parameter must be specified when enabling server access logging"); Request<SetBucketLoggingConfigurationRequest> request = createRequest(bucketName, null, setBucketLoggingConfigurationRequest, HttpMethodName.PUT); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketLogging"); request.addParameter("logging", null); byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(loggingConfiguration); request.setContent(new ByteArrayInputStream(bytes)); invoke(request, voidResponseHandler, bucketName, null); }
@Override public void setBucketLifecycleConfiguration( SetBucketLifecycleConfigurationRequest setBucketLifecycleConfigurationRequest) { setBucketLifecycleConfigurationRequest = beforeClientExecution(setBucketLifecycleConfigurationRequest); rejectNull(setBucketLifecycleConfigurationRequest, "The set bucket lifecycle configuration request object must be specified."); String bucketName = setBucketLifecycleConfigurationRequest.getBucketName(); BucketLifecycleConfiguration bucketLifecycleConfiguration = setBucketLifecycleConfigurationRequest.getLifecycleConfiguration(); rejectNull(bucketName, "The bucket name parameter must be specified when setting bucket lifecycle configuration."); rejectNull(bucketLifecycleConfiguration, "The lifecycle configuration parameter must be specified when setting bucket lifecycle configuration."); Request<SetBucketLifecycleConfigurationRequest> request = createRequest(bucketName, null, setBucketLifecycleConfigurationRequest, HttpMethodName.PUT); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketLifecycleConfiguration"); request.addParameter("lifecycle", null); byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketLifecycleConfiguration); request.addHeader("Content-Length", String.valueOf(content.length)); request.addHeader("Content-Type", "application/xml"); request.setContent(new ByteArrayInputStream(content)); try { byte[] md5 = Md5Utils.computeMD5Hash(content); String md5Base64 = BinaryUtils.toBase64(md5); request.addHeader("Content-MD5", md5Base64); } catch ( Exception e ) { throw new SdkClientException("Couldn't compute md5 sum", e); } invoke(request, voidResponseHandler, bucketName, null); }
public Request<UpdateTrafficPolicyCommentRequest> marshall(UpdateTrafficPolicyCommentRequest updateTrafficPolicyCommentRequest) { throw new SdkClientException("Invalid argument passed to marshall(...)"); "AmazonRoute53"); request.setHttpMethod(HttpMethodName.POST); uriResourcePath = com.amazonaws.transform.PathMarshallers.NON_GREEDY.marshall(uriResourcePath, "Version", updateTrafficPolicyCommentRequest.getVersion()); request.setResourcePath(uriResourcePath); StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, "https://route53.amazonaws.com/doc/2013-04-01/"); request.setContent(new StringInputStream(stringWriter.getBuffer().toString())); request.addHeader("Content-Length", Integer.toString(stringWriter.getBuffer().toString().getBytes(UTF8).length)); if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", "application/xml"); throw new SdkClientException("Unable to marshall request to XML: " + t.getMessage(), t);
@Override public Request<RawRequest> marshall(RawRequest rawRequestRequest) { if (rawRequestRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } Request<RawRequest> request = new DefaultRequest<>("MyService"); request.setHttpMethod(rawRequestRequest.httpMethod()); request.setResourcePath(rawRequestRequest.path()); request.setContent(rawRequestRequest.payload()); // Custom headers and query params are set later in the runtime if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", protocolFactory.getContentType()); } return request; } }
@Override public void setBucketNotificationConfiguration( SetBucketNotificationConfigurationRequest setBucketNotificationConfigurationRequest) throws SdkClientException, AmazonServiceException { setBucketNotificationConfigurationRequest = beforeClientExecution(setBucketNotificationConfigurationRequest); rejectNull(setBucketNotificationConfigurationRequest, "The set bucket notification configuration request object must be specified."); String bucketName = setBucketNotificationConfigurationRequest.getBucketName(); BucketNotificationConfiguration bucketNotificationConfiguration = setBucketNotificationConfigurationRequest.getNotificationConfiguration(); rejectNull(bucketName, "The bucket name parameter must be specified when setting bucket notification configuration."); rejectNull(bucketNotificationConfiguration, "The notification configuration parameter must be specified when setting bucket notification configuration."); Request<SetBucketNotificationConfigurationRequest> request = createRequest(bucketName, null, setBucketNotificationConfigurationRequest, HttpMethodName.PUT); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketNotificationConfiguration"); request.addParameter("notification", null); byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(bucketNotificationConfiguration); request.setContent(new ByteArrayInputStream(bytes)); invoke(request, voidResponseHandler, bucketName, null); }
@Override public Request<OrigRequest> finishMarshalling() { // Content may already be set if the payload is binary data. if (request.getContent() == null) { // End the implicit request object if needed. if (!hasExplicitPayloadMember) { jsonGenerator.writeEndObject(); } byte[] content = jsonGenerator.getBytes(); request.setContent(new ByteArrayInputStream(content)); if (content.length > 0) { request.addHeader("Content-Length", Integer.toString(content.length)); } } if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", contentType); } return request; }
/** * Sets the optional stream containing the payload data from the byte array * to include for this request. Not all requests will contain payload data. * * @param body The request body represented as a array of bytes. * @return the updated request object. */ public ApiRequest withBody(byte[] body) { request.setContent(new ByteArrayInputStream(body)); return this; }
"The replication configuration parameter must be specified when setting replication configuration."); Request<SetBucketReplicationConfigurationRequest> request = createRequest( bucketName, null, setBucketReplicationConfigurationRequest, HttpMethodName.PUT); .convertToXmlByteArray(bucketReplicationConfiguration); request.addHeader("Content-Length", String.valueOf(bytes.length)); request.addHeader("Content-Type", "application/xml"); request.setContent(new ByteArrayInputStream(bytes)); request.addHeader("Content-MD5", BinaryUtils.toBase64(Md5Utils.computeMD5Hash(bytes))); } catch (Exception e) { throw new SdkClientException( "Not able to compute MD5 of the replication rule configuration. Exception Message : " + e.getMessage(), e);
public Request<CreateQueryLoggingConfigRequest> marshall(CreateQueryLoggingConfigRequest createQueryLoggingConfigRequest) { throw new SdkClientException("Invalid argument passed to marshall(...)"); request.setHttpMethod(HttpMethodName.POST); request.setResourcePath(uriResourcePath); StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, "https://route53.amazonaws.com/doc/2013-04-01/"); request.setContent(new StringInputStream(stringWriter.getBuffer().toString())); request.addHeader("Content-Length", Integer.toString(stringWriter.getBuffer().toString().getBytes(UTF8).length)); if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", "application/xml"); throw new SdkClientException("Unable to marshall request to XML: " + t.getMessage(), t);
public Request<DescribeEndpointsRequest> marshall( DescribeEndpointsRequest describeEndpointsRequest) { if (describeEndpointsRequest == null) { throw new AmazonClientException( "Invalid argument passed to marshall(DescribeEndpointsRequest)"); } Request<DescribeEndpointsRequest> request = new DefaultRequest<DescribeEndpointsRequest>( describeEndpointsRequest, "AmazonDynamoDB"); String target = "DynamoDB_20120810.DescribeEndpoints"; request.addHeader("X-Amz-Target", target); request.setHttpMethod(HttpMethodName.POST); String uriResourcePath = "/"; request.setResourcePath(uriResourcePath); request.addHeader("Content-Length", "0"); request.setContent(new ByteArrayInputStream(new byte[0])); if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", "application/x-amz-json-1.0"); } return request; } }
@Override public SetPublicAccessBlockResult setPublicAccessBlock(SetPublicAccessBlockRequest setPublicAccessBlockRequest) { setPublicAccessBlockRequest = beforeClientExecution(setPublicAccessBlockRequest); rejectNull(setPublicAccessBlockRequest, "The request object must be specified."); String bucketName = setPublicAccessBlockRequest.getBucketName(); PublicAccessBlockConfiguration config = setPublicAccessBlockRequest.getPublicAccessBlockConfiguration(); rejectNull(bucketName, "The bucket name parameter must be specified when setting public block configuration."); rejectNull(config, "The PublicAccessBlockConfiguration parameter must be specified when setting public block"); Request<SetPublicAccessBlockRequest> request = createRequest(bucketName, null, setPublicAccessBlockRequest, HttpMethodName.PUT); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutPublicAccessBlock"); request.addParameter("publicAccessBlock", null); byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(config); request.setContent(new ByteArrayInputStream(bytes)); return invoke(request, new Unmarshallers.SetPublicAccessBlockUnmarshaller(), bucketName, null); }
private void setContent(Request<?> request, byte[] content, String contentType, boolean setMd5) { request.setContent(new ByteArrayInputStream(content)); request.addHeader("Content-Length", Integer.toString(content.length)); request.addHeader("Content-Type", contentType); if (setMd5) { try { final byte[] md5 = Md5Utils.computeMD5Hash(content); final String md5Base64 = BinaryUtils.toBase64(md5); request.addHeader("Content-MD5", md5Base64); } catch ( final Exception e ) { throw new AmazonClientException("Couldn't compute md5 sum", e); } } }
/** * Sets the optional stream containing the payload data from a string * content to include for this request. Not all requests will contain * payload data. * * @param body the request body represented as a string. * @return the updated request object. */ public ApiRequest withBody(String body) { final byte[] contentBytes = body.getBytes(StringUtils.UTF8); request.setContent(new ByteArrayInputStream(contentBytes)); return this; }
"The request payment configuration parameter must be specified when setting the Requester Pays."); Request<SetRequestPaymentConfigurationRequest> request = createRequest( bucketName, null, setRequestPaymentConfigurationRequest, HttpMethodName.PUT); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketRequestPayment"); request.addParameter("requestPayment", null); request.addHeader("Content-Type", "application/xml"); request.setContent(new ByteArrayInputStream(bytes));
public Request<CreateReusableDelegationSetRequest> marshall(CreateReusableDelegationSetRequest createReusableDelegationSetRequest) { throw new SdkClientException("Invalid argument passed to marshall(...)"); "AmazonRoute53"); request.setHttpMethod(HttpMethodName.POST); request.setResourcePath(uriResourcePath); StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, "https://route53.amazonaws.com/doc/2013-04-01/"); request.setContent(new StringInputStream(stringWriter.getBuffer().toString())); request.addHeader("Content-Length", Integer.toString(stringWriter.getBuffer().toString().getBytes(UTF8).length)); if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", "application/xml"); throw new SdkClientException("Unable to marshall request to XML: " + t.getMessage(), t);