public Request<LookupEventsRequest> marshall(LookupEventsRequest lookupEventsRequest) {

    if (lookupEventsRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<LookupEventsRequest> request =
        new DefaultRequest<LookupEventsRequest>(lookupEventsRequest, "AWSCloudTrail");
    request.addHeader(
        "X-Amz-Target", "com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.LookupEvents");

    request.setHttpMethod(HttpMethodName.POST);

    request.setResourcePath("");

    try {
      final StructuredJsonGenerator jsonGenerator = protocolFactory.createGenerator();

      jsonGenerator.writeStartObject();

      com.amazonaws.internal.SdkInternalList<LookupAttribute> lookupAttributesList =
          (com.amazonaws.internal.SdkInternalList<LookupAttribute>)
              lookupEventsRequest.getLookupAttributes();
      if (!lookupAttributesList.isEmpty() || !lookupAttributesList.isAutoConstruct()) {
        jsonGenerator.writeFieldName("LookupAttributes");
        jsonGenerator.writeStartArray();
        for (LookupAttribute lookupAttributesListValue : lookupAttributesList) {
          if (lookupAttributesListValue != null) {

            LookupAttributeJsonMarshaller.getInstance()
                .marshall(lookupAttributesListValue, jsonGenerator);
          }
        }
        jsonGenerator.writeEndArray();
      }
      if (lookupEventsRequest.getStartTime() != null) {
        jsonGenerator.writeFieldName("StartTime").writeValue(lookupEventsRequest.getStartTime());
      }
      if (lookupEventsRequest.getEndTime() != null) {
        jsonGenerator.writeFieldName("EndTime").writeValue(lookupEventsRequest.getEndTime());
      }
      if (lookupEventsRequest.getMaxResults() != null) {
        jsonGenerator.writeFieldName("MaxResults").writeValue(lookupEventsRequest.getMaxResults());
      }
      if (lookupEventsRequest.getNextToken() != null) {
        jsonGenerator.writeFieldName("NextToken").writeValue(lookupEventsRequest.getNextToken());
      }

      jsonGenerator.writeEndObject();

      byte[] content = jsonGenerator.getBytes();
      request.setContent(new ByteArrayInputStream(content));
      request.addHeader("Content-Length", Integer.toString(content.length));
      request.addHeader("Content-Type", protocolFactory.getContentType());
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }
Пример #2
0
  /** Marshall the given parameter object, and output to a SdkJsonGenerator */
  public void marshall(Tag tag, StructuredJsonGenerator jsonGenerator) {

    if (tag == null) {
      throw new SdkClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonGenerator.writeStartObject();

      if (tag.getKey() != null) {
        jsonGenerator.writeFieldName("Key").writeValue(tag.getKey());
      }
      if (tag.getValue() != null) {
        jsonGenerator.writeFieldName("Value").writeValue(tag.getValue());
      }

      jsonGenerator.writeEndObject();
    } catch (Throwable t) {
      throw new SdkClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
  /** Marshall the given parameter object, and output to a SdkJsonGenerator */
  public void marshall(Resource resource, StructuredJsonGenerator jsonGenerator) {

    if (resource == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonGenerator.writeStartObject();

      if (resource.getResourceType() != null) {
        jsonGenerator.writeFieldName("ResourceType").writeValue(resource.getResourceType());
      }
      if (resource.getResourceName() != null) {
        jsonGenerator.writeFieldName("ResourceName").writeValue(resource.getResourceName());
      }

      jsonGenerator.writeEndObject();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }