コード例 #1
0
  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;
  }
  public Request<UpdateMaintenanceStartTimeRequest> marshall(
      UpdateMaintenanceStartTimeRequest updateMaintenanceStartTimeRequest) {

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

    Request<UpdateMaintenanceStartTimeRequest> request =
        new DefaultRequest<UpdateMaintenanceStartTimeRequest>(
            updateMaintenanceStartTimeRequest, "AWSStorageGateway");
    request.addHeader("X-Amz-Target", "StorageGateway_20130630.UpdateMaintenanceStartTime");

    request.setHttpMethod(HttpMethodName.POST);

    request.setResourcePath("");

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

      jsonWriter.object();

      if (updateMaintenanceStartTimeRequest.getGatewayARN() != null) {
        jsonWriter.key("GatewayARN").value(updateMaintenanceStartTimeRequest.getGatewayARN());
      }

      if (updateMaintenanceStartTimeRequest.getHourOfDay() != null) {
        jsonWriter.key("HourOfDay").value(updateMaintenanceStartTimeRequest.getHourOfDay());
      }

      if (updateMaintenanceStartTimeRequest.getMinuteOfHour() != null) {
        jsonWriter.key("MinuteOfHour").value(updateMaintenanceStartTimeRequest.getMinuteOfHour());
      }

      if (updateMaintenanceStartTimeRequest.getDayOfWeek() != null) {
        jsonWriter.key("DayOfWeek").value(updateMaintenanceStartTimeRequest.getDayOfWeek());
      }

      jsonWriter.endObject();

      String snippet = stringWriter.toString();
      byte[] content = snippet.getBytes(UTF8);
      request.setContent(new StringInputStream(snippet));
      request.addHeader("Content-Length", Integer.toString(content.length));
      request.addHeader("Content-Type", "application/x-amz-json-1.1");
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }
  public Request<ListVolumesRequest> marshall(ListVolumesRequest listVolumesRequest) {
    if (listVolumesRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<ListVolumesRequest> request =
        new DefaultRequest<ListVolumesRequest>(listVolumesRequest, "AWSStorageGateway");
    String target = "StorageGateway_20130630.ListVolumes";
    request.addHeader("X-Amz-Target", target);

    request.setHttpMethod(HttpMethodName.POST);
    request.setResourcePath("");

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

      jsonWriter.object();

      if (listVolumesRequest.getGatewayARN() != null) {
        jsonWriter.key("GatewayARN").value(listVolumesRequest.getGatewayARN());
      }
      if (listVolumesRequest.getMarker() != null) {
        jsonWriter.key("Marker").value(listVolumesRequest.getMarker());
      }
      if (listVolumesRequest.getLimit() != null) {
        jsonWriter.key("Limit").value(listVolumesRequest.getLimit());
      }

      jsonWriter.endObject();

      String snippet = stringWriter.toString();
      byte[] content = snippet.getBytes(UTF8);
      request.setContent(new StringInputStream(snippet));
      request.addHeader("Content-Length", Integer.toString(content.length));
      request.addHeader("Content-Type", "application/x-amz-json-1.1");
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }

    return request;
  }
コード例 #4
0
  /** Marshall the given parameter object, and output to a JSONWriter */
  public void marshall(VTLDevice vTLDevice, JSONWriter jsonWriter) {
    if (vTLDevice == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    try {
      jsonWriter.object();

      if (vTLDevice.getVTLDeviceARN() != null) {
        jsonWriter.key("VTLDeviceARN").value(vTLDevice.getVTLDeviceARN());
      }

      if (vTLDevice.getVTLDeviceType() != null) {
        jsonWriter.key("VTLDeviceType").value(vTLDevice.getVTLDeviceType());
      }

      if (vTLDevice.getVTLDeviceVendor() != null) {
        jsonWriter.key("VTLDeviceVendor").value(vTLDevice.getVTLDeviceVendor());
      }

      if (vTLDevice.getVTLDeviceProductIdentifier() != null) {
        jsonWriter
            .key("VTLDeviceProductIdentifier")
            .value(vTLDevice.getVTLDeviceProductIdentifier());
      }

      if (vTLDevice.getDeviceiSCSIAttributes() != null) {
        jsonWriter.key("DeviceiSCSIAttributes");
        DeviceiSCSIAttributesJsonMarshaller.getInstance()
            .marshall(vTLDevice.getDeviceiSCSIAttributes(), jsonWriter);
      }

      jsonWriter.endObject();
    } catch (Throwable t) {
      throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
    }
  }
コード例 #5
0
  public Request<AddUploadBufferRequest> marshall(AddUploadBufferRequest addUploadBufferRequest) {
    if (addUploadBufferRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<AddUploadBufferRequest> request =
        new DefaultRequest<AddUploadBufferRequest>(addUploadBufferRequest, "AWSStorageGateway");
    String target = "StorageGateway_20130630.AddUploadBuffer";
    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 (addUploadBufferRequest.getGatewayARN() != null) {
        jsonWriter.key("GatewayARN").value(addUploadBufferRequest.getGatewayARN());
      }

      com.amazonaws.internal.ListWithAutoConstructFlag<String> diskIdsList =
          (com.amazonaws.internal.ListWithAutoConstructFlag<String>)
              (addUploadBufferRequest.getDiskIds());
      if (diskIdsList != null && !(diskIdsList.isAutoConstruct() && diskIdsList.isEmpty())) {

        jsonWriter.key("DiskIds");
        jsonWriter.array();

        for (String diskIdsListValue : diskIdsList) {
          if (diskIdsListValue != null) {
            jsonWriter.value(diskIdsListValue);
          }
        }
        jsonWriter.endArray();
      }

      jsonWriter.endObject();

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

    return request;
  }