public Request<CreateSnapshotRequest> marshall(CreateSnapshotRequest createSnapshotRequest) {
    if (createSnapshotRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<CreateSnapshotRequest> request =
        new DefaultRequest<CreateSnapshotRequest>(createSnapshotRequest, "AWSStorageGateway");
    String target = "StorageGateway_20130630.CreateSnapshot";
    request.addHeader("X-Amz-Target", target);
    request.addHeader("Content-Type", "application/x-amz-json-1.1");

    request.setHttpMethod(HttpMethodName.POST);

    String uriResourcePath = "";

    uriResourcePath = uriResourcePath.replaceAll("//", "/");

    if (uriResourcePath.contains("?")) {
      String queryString = uriResourcePath.substring(uriResourcePath.indexOf("?") + 1);
      uriResourcePath = uriResourcePath.substring(0, uriResourcePath.indexOf("?"));

      for (String s : queryString.split("[;&]")) {
        String[] nameValuePair = s.split("=");
        if (nameValuePair.length == 2) {
          request.addParameter(nameValuePair[0], nameValuePair[1]);
        } else {
          request.addParameter(s, null);
        }
      }
    }

    request.setResourcePath(uriResourcePath);

    try {
      StringWriter stringWriter = new StringWriter();
      JSONWriter jsonWriter = new JSONWriter(stringWriter);

      jsonWriter.object();

      if (createSnapshotRequest.getVolumeARN() != null) {
        jsonWriter.key("VolumeARN").value(createSnapshotRequest.getVolumeARN());
      }
      if (createSnapshotRequest.getSnapshotDescription() != null) {
        jsonWriter.key("SnapshotDescription").value(createSnapshotRequest.getSnapshotDescription());
      }

      jsonWriter.endObject();

      String snippet = stringWriter.toString();
      byte[] content = snippet.getBytes("UTF-8");
      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);
    }

    return request;
  }
  @Override
  protected void masterOperation(
      final CreateSnapshotRequest request,
      ClusterState state,
      final ActionListener<CreateSnapshotResponse> listener)
      throws ElasticSearchException {
    SnapshotsService.SnapshotRequest snapshotRequest =
        new SnapshotsService.SnapshotRequest(
                "create_snapshot[" + request.snapshot() + "]",
                request.snapshot(),
                request.repository())
            .indices(request.indices())
            .indicesOptions(request.indicesOptions())
            .settings(request.settings())
            .includeGlobalState(request.includeGlobalState())
            .masterNodeTimeout(request.masterNodeTimeout());
    snapshotsService.createSnapshot(
        snapshotRequest,
        new SnapshotsService.CreateSnapshotListener() {
          @Override
          public void onResponse() {
            if (request.waitForCompletion()) {
              snapshotsService.addListener(
                  new SnapshotsService.SnapshotCompletionListener() {
                    SnapshotId snapshotId =
                        new SnapshotId(request.repository(), request.snapshot());

                    @Override
                    public void onSnapshotCompletion(SnapshotId snapshotId, SnapshotInfo snapshot) {
                      if (this.snapshotId.equals(snapshotId)) {
                        listener.onResponse(new CreateSnapshotResponse(snapshot));
                        snapshotsService.removeListener(this);
                      }
                    }

                    @Override
                    public void onSnapshotFailure(SnapshotId snapshotId, Throwable t) {
                      if (this.snapshotId.equals(snapshotId)) {
                        listener.onFailure(t);
                        snapshotsService.removeListener(this);
                      }
                    }
                  });
            } else {
              listener.onResponse(new CreateSnapshotResponse());
            }
          }

          @Override
          public void onFailure(Throwable t) {
            listener.onFailure(t);
          }
        });
  }
  public Request<CreateSnapshotRequest> marshall(CreateSnapshotRequest createSnapshotRequest) {

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

    Request<CreateSnapshotRequest> request =
        new DefaultRequest<CreateSnapshotRequest>(createSnapshotRequest, "AWSStorageGateway");
    request.addHeader("X-Amz-Target", "StorageGateway_20130630.CreateSnapshot");

    request.setHttpMethod(HttpMethodName.POST);

    request.setResourcePath("");

    try {
      final StructuredJsonGenerator jsonGenerator =
          SdkJsonProtocolFactory.createWriter(false, "1.1");

      jsonGenerator.writeStartObject();

      if (createSnapshotRequest.getVolumeARN() != null) {
        jsonGenerator.writeFieldName("VolumeARN").writeValue(createSnapshotRequest.getVolumeARN());
      }
      if (createSnapshotRequest.getSnapshotDescription() != null) {
        jsonGenerator
            .writeFieldName("SnapshotDescription")
            .writeValue(createSnapshotRequest.getSnapshotDescription());
      }

      jsonGenerator.writeEndObject();

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

    return request;
  }