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; }