public Request<PutEventsRequest> marshall(PutEventsRequest putEventsRequest) { if (putEventsRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(PutEventsRequest)"); } Request<PutEventsRequest> request = new DefaultRequest<PutEventsRequest>(putEventsRequest, "AmazonMobileAnalytics"); request.setHttpMethod(HttpMethodName.POST); if (putEventsRequest.getClientContext() != null) { request.addHeader( "x-amz-Client-Context", StringUtils.fromString(putEventsRequest.getClientContext())); } if (putEventsRequest.getClientContextEncoding() != null) { request.addHeader( "x-amz-Client-Context-Encoding", StringUtils.fromString(putEventsRequest.getClientContextEncoding())); } String uriResourcePath = "/2014-06-05/events"; request.setResourcePath(uriResourcePath); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gos = new GZIPOutputStream(baos, 8192); Writer writer = new OutputStreamWriter(gos, StringUtils.UTF8); AwsJsonWriter jsonWriter = JsonUtils.getJsonWriter(writer); jsonWriter.beginObject(); if (putEventsRequest.getEvents() != null) { java.util.List<Event> events = putEventsRequest.getEvents(); jsonWriter.name("events"); jsonWriter.beginArray(); for (Event eventsItem : events) { if (eventsItem != null) { EventJsonMarshaller.getInstance().marshall(eventsItem, jsonWriter); } } jsonWriter.endArray(); } jsonWriter.endObject(); jsonWriter.flush(); gos.finish(); writer.close(); byte[] content = baos.toByteArray(); request.setContent(new ByteArrayInputStream(content)); request.addHeader("Content-Length", Integer.toString(content.length)); request.addHeader("Content-Encoding", "gzip"); } catch (Throwable t) { throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t); } if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", "application/x-amz-json-1.0"); } return request; }
public Request<ListUsersRequest> marshall(ListUsersRequest listUsersRequest) { if (listUsersRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(ListUsersRequest)"); } Request<ListUsersRequest> request = new DefaultRequest<ListUsersRequest>(listUsersRequest, "AmazonCognitoIdentityProvider"); String target = "AWSCognitoIdentityProviderService.ListUsers"; request.addHeader("X-Amz-Target", target); request.setHttpMethod(HttpMethodName.POST); String uriResourcePath = "/"; request.setResourcePath(uriResourcePath); try { StringWriter stringWriter = new StringWriter(); AwsJsonWriter jsonWriter = JsonUtils.getJsonWriter(stringWriter); jsonWriter.beginObject(); if (listUsersRequest.getUserPoolId() != null) { String userPoolId = listUsersRequest.getUserPoolId(); jsonWriter.name("UserPoolId"); jsonWriter.value(userPoolId); } if (listUsersRequest.getAttributesToGet() != null) { java.util.List<String> attributesToGet = listUsersRequest.getAttributesToGet(); jsonWriter.name("AttributesToGet"); jsonWriter.beginArray(); for (String attributesToGetItem : attributesToGet) { if (attributesToGetItem != null) { jsonWriter.value(attributesToGetItem); } } jsonWriter.endArray(); } if (listUsersRequest.getLimit() != null) { Integer limit = listUsersRequest.getLimit(); jsonWriter.name("Limit"); jsonWriter.value(limit); } if (listUsersRequest.getPaginationToken() != null) { String paginationToken = listUsersRequest.getPaginationToken(); jsonWriter.name("PaginationToken"); jsonWriter.value(paginationToken); } if (listUsersRequest.getFilter() != null) { String filter = listUsersRequest.getFilter(); jsonWriter.name("Filter"); jsonWriter.value(filter); } jsonWriter.endObject(); jsonWriter.close(); String snippet = stringWriter.toString(); byte[] content = snippet.getBytes(UTF8); request.setContent(new StringInputStream(snippet)); request.addHeader("Content-Length", Integer.toString(content.length)); } catch (Throwable t) { throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t); } if (!request.getHeaders().containsKey("Content-Type")) { request.addHeader("Content-Type", "application/x-amz-json-1.1"); } return request; }