public Request<CreateKeyRequest> marshall(CreateKeyRequest createKeyRequest) {

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

    Request<CreateKeyRequest> request =
        new DefaultRequest<CreateKeyRequest>(createKeyRequest, "AWSKMS");
    request.addHeader("X-Amz-Target", "TrentService.CreateKey");

    request.setHttpMethod(HttpMethodName.POST);

    request.setResourcePath("");

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

      jsonGenerator.writeStartObject();

      if (createKeyRequest.getPolicy() != null) {
        jsonGenerator.writeFieldName("Policy").writeValue(createKeyRequest.getPolicy());
      }
      if (createKeyRequest.getDescription() != null) {
        jsonGenerator.writeFieldName("Description").writeValue(createKeyRequest.getDescription());
      }
      if (createKeyRequest.getKeyUsage() != null) {
        jsonGenerator.writeFieldName("KeyUsage").writeValue(createKeyRequest.getKeyUsage());
      }
      if (createKeyRequest.getOrigin() != null) {
        jsonGenerator.writeFieldName("Origin").writeValue(createKeyRequest.getOrigin());
      }
      if (createKeyRequest.getBypassPolicyLockoutSafetyCheck() != null) {
        jsonGenerator
            .writeFieldName("BypassPolicyLockoutSafetyCheck")
            .writeValue(createKeyRequest.getBypassPolicyLockoutSafetyCheck());
      }

      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 SdkClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }
Exemplo n.º 2
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof CreateKeyRequest == false) return false;
    CreateKeyRequest other = (CreateKeyRequest) obj;
    if (other.getPolicy() == null ^ this.getPolicy() == null) return false;
    if (other.getPolicy() != null && other.getPolicy().equals(this.getPolicy()) == false)
      return false;
    if (other.getDescription() == null ^ this.getDescription() == null) return false;
    if (other.getDescription() != null
        && other.getDescription().equals(this.getDescription()) == false) return false;
    if (other.getKeyUsage() == null ^ this.getKeyUsage() == null) return false;
    if (other.getKeyUsage() != null && other.getKeyUsage().equals(this.getKeyUsage()) == false)
      return false;
    return true;
  }