public Request<CreateJobRequest> marshall(CreateJobRequest createJobRequest) { if (createJobRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } Request<CreateJobRequest> request = new DefaultRequest<CreateJobRequest>(createJobRequest, "AmazonElasticTranscoder"); String target = "EtsCustomerService.CreateJob"; request.addHeader("X-Amz-Target", target); request.setHttpMethod(HttpMethodName.POST); String uriResourcePath = "2012-09-25/jobs"; 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) { if (!(nameValuePair[1].isEmpty())) request.addParameter(nameValuePair[0], nameValuePair[1]); } } } request.setResourcePath(uriResourcePath); try { StringWriter stringWriter = new StringWriter(); JSONWriter jsonWriter = new JSONWriter(stringWriter); jsonWriter.object(); if (createJobRequest.getPipelineId() != null) { jsonWriter.key("PipelineId").value(createJobRequest.getPipelineId()); } JobInput input = createJobRequest.getInput(); if (input != null) { jsonWriter.key("Input"); jsonWriter.object(); if (input.getKey() != null) { jsonWriter.key("Key").value(input.getKey()); } if (input.getFrameRate() != null) { jsonWriter.key("FrameRate").value(input.getFrameRate()); } if (input.getResolution() != null) { jsonWriter.key("Resolution").value(input.getResolution()); } if (input.getAspectRatio() != null) { jsonWriter.key("AspectRatio").value(input.getAspectRatio()); } if (input.getInterlaced() != null) { jsonWriter.key("Interlaced").value(input.getInterlaced()); } if (input.getContainer() != null) { jsonWriter.key("Container").value(input.getContainer()); } jsonWriter.endObject(); } CreateJobOutput output = createJobRequest.getOutput(); if (output != null) { jsonWriter.key("Output"); jsonWriter.object(); if (output.getKey() != null) { jsonWriter.key("Key").value(output.getKey()); } if (output.getThumbnailPattern() != null) { jsonWriter.key("ThumbnailPattern").value(output.getThumbnailPattern()); } if (output.getRotate() != null) { jsonWriter.key("Rotate").value(output.getRotate()); } if (output.getPresetId() != null) { jsonWriter.key("PresetId").value(output.getPresetId()); } if (output.getSegmentDuration() != null) { jsonWriter.key("SegmentDuration").value(output.getSegmentDuration()); } com.amazonaws.internal.ListWithAutoConstructFlag<JobWatermark> watermarksList = (com.amazonaws.internal.ListWithAutoConstructFlag<JobWatermark>) (output.getWatermarks()); if (watermarksList != null && !(watermarksList.isAutoConstruct() && watermarksList.isEmpty())) { jsonWriter.key("Watermarks"); jsonWriter.array(); for (JobWatermark watermarksListValue : watermarksList) { if (watermarksListValue != null) { jsonWriter.object(); if (watermarksListValue.getPresetWatermarkId() != null) { jsonWriter .key("PresetWatermarkId") .value(watermarksListValue.getPresetWatermarkId()); } if (watermarksListValue.getInputKey() != null) { jsonWriter.key("InputKey").value(watermarksListValue.getInputKey()); } jsonWriter.endObject(); } } jsonWriter.endArray(); } JobAlbumArt albumArt = output.getAlbumArt(); if (albumArt != null) { jsonWriter.key("AlbumArt"); jsonWriter.object(); if (albumArt.getMergePolicy() != null) { jsonWriter.key("MergePolicy").value(albumArt.getMergePolicy()); } com.amazonaws.internal.ListWithAutoConstructFlag<Artwork> artworkList = (com.amazonaws.internal.ListWithAutoConstructFlag<Artwork>) (albumArt.getArtwork()); if (artworkList != null && !(artworkList.isAutoConstruct() && artworkList.isEmpty())) { jsonWriter.key("Artwork"); jsonWriter.array(); for (Artwork artworkListValue : artworkList) { if (artworkListValue != null) { jsonWriter.object(); if (artworkListValue.getInputKey() != null) { jsonWriter.key("InputKey").value(artworkListValue.getInputKey()); } if (artworkListValue.getMaxWidth() != null) { jsonWriter.key("MaxWidth").value(artworkListValue.getMaxWidth()); } if (artworkListValue.getMaxHeight() != null) { jsonWriter.key("MaxHeight").value(artworkListValue.getMaxHeight()); } if (artworkListValue.getSizingPolicy() != null) { jsonWriter.key("SizingPolicy").value(artworkListValue.getSizingPolicy()); } if (artworkListValue.getPaddingPolicy() != null) { jsonWriter.key("PaddingPolicy").value(artworkListValue.getPaddingPolicy()); } if (artworkListValue.getAlbumArtFormat() != null) { jsonWriter.key("AlbumArtFormat").value(artworkListValue.getAlbumArtFormat()); } jsonWriter.endObject(); } } jsonWriter.endArray(); } jsonWriter.endObject(); } com.amazonaws.internal.ListWithAutoConstructFlag<Clip> compositionList = (com.amazonaws.internal.ListWithAutoConstructFlag<Clip>) (output.getComposition()); if (compositionList != null && !(compositionList.isAutoConstruct() && compositionList.isEmpty())) { jsonWriter.key("Composition"); jsonWriter.array(); for (Clip compositionListValue : compositionList) { if (compositionListValue != null) { jsonWriter.object(); TimeSpan timeSpan = compositionListValue.getTimeSpan(); if (timeSpan != null) { jsonWriter.key("TimeSpan"); jsonWriter.object(); if (timeSpan.getStartTime() != null) { jsonWriter.key("StartTime").value(timeSpan.getStartTime()); } if (timeSpan.getDuration() != null) { jsonWriter.key("Duration").value(timeSpan.getDuration()); } jsonWriter.endObject(); } jsonWriter.endObject(); } } jsonWriter.endArray(); } jsonWriter.endObject(); } com.amazonaws.internal.ListWithAutoConstructFlag<CreateJobOutput> outputsList = (com.amazonaws.internal.ListWithAutoConstructFlag<CreateJobOutput>) (createJobRequest.getOutputs()); if (outputsList != null && !(outputsList.isAutoConstruct() && outputsList.isEmpty())) { jsonWriter.key("Outputs"); jsonWriter.array(); for (CreateJobOutput outputsListValue : outputsList) { if (outputsListValue != null) { jsonWriter.object(); if (outputsListValue.getKey() != null) { jsonWriter.key("Key").value(outputsListValue.getKey()); } if (outputsListValue.getThumbnailPattern() != null) { jsonWriter.key("ThumbnailPattern").value(outputsListValue.getThumbnailPattern()); } if (outputsListValue.getRotate() != null) { jsonWriter.key("Rotate").value(outputsListValue.getRotate()); } if (outputsListValue.getPresetId() != null) { jsonWriter.key("PresetId").value(outputsListValue.getPresetId()); } if (outputsListValue.getSegmentDuration() != null) { jsonWriter.key("SegmentDuration").value(outputsListValue.getSegmentDuration()); } com.amazonaws.internal.ListWithAutoConstructFlag<JobWatermark> watermarksList = (com.amazonaws.internal.ListWithAutoConstructFlag<JobWatermark>) (outputsListValue.getWatermarks()); if (watermarksList != null && !(watermarksList.isAutoConstruct() && watermarksList.isEmpty())) { jsonWriter.key("Watermarks"); jsonWriter.array(); for (JobWatermark watermarksListValue : watermarksList) { if (watermarksListValue != null) { jsonWriter.object(); if (watermarksListValue.getPresetWatermarkId() != null) { jsonWriter .key("PresetWatermarkId") .value(watermarksListValue.getPresetWatermarkId()); } if (watermarksListValue.getInputKey() != null) { jsonWriter.key("InputKey").value(watermarksListValue.getInputKey()); } jsonWriter.endObject(); } } jsonWriter.endArray(); } JobAlbumArt albumArt = outputsListValue.getAlbumArt(); if (albumArt != null) { jsonWriter.key("AlbumArt"); jsonWriter.object(); if (albumArt.getMergePolicy() != null) { jsonWriter.key("MergePolicy").value(albumArt.getMergePolicy()); } com.amazonaws.internal.ListWithAutoConstructFlag<Artwork> artworkList = (com.amazonaws.internal.ListWithAutoConstructFlag<Artwork>) (albumArt.getArtwork()); if (artworkList != null && !(artworkList.isAutoConstruct() && artworkList.isEmpty())) { jsonWriter.key("Artwork"); jsonWriter.array(); for (Artwork artworkListValue : artworkList) { if (artworkListValue != null) { jsonWriter.object(); if (artworkListValue.getInputKey() != null) { jsonWriter.key("InputKey").value(artworkListValue.getInputKey()); } if (artworkListValue.getMaxWidth() != null) { jsonWriter.key("MaxWidth").value(artworkListValue.getMaxWidth()); } if (artworkListValue.getMaxHeight() != null) { jsonWriter.key("MaxHeight").value(artworkListValue.getMaxHeight()); } if (artworkListValue.getSizingPolicy() != null) { jsonWriter.key("SizingPolicy").value(artworkListValue.getSizingPolicy()); } if (artworkListValue.getPaddingPolicy() != null) { jsonWriter.key("PaddingPolicy").value(artworkListValue.getPaddingPolicy()); } if (artworkListValue.getAlbumArtFormat() != null) { jsonWriter.key("AlbumArtFormat").value(artworkListValue.getAlbumArtFormat()); } jsonWriter.endObject(); } } jsonWriter.endArray(); } jsonWriter.endObject(); } com.amazonaws.internal.ListWithAutoConstructFlag<Clip> compositionList = (com.amazonaws.internal.ListWithAutoConstructFlag<Clip>) (outputsListValue.getComposition()); if (compositionList != null && !(compositionList.isAutoConstruct() && compositionList.isEmpty())) { jsonWriter.key("Composition"); jsonWriter.array(); for (Clip compositionListValue : compositionList) { if (compositionListValue != null) { jsonWriter.object(); TimeSpan timeSpan = compositionListValue.getTimeSpan(); if (timeSpan != null) { jsonWriter.key("TimeSpan"); jsonWriter.object(); if (timeSpan.getStartTime() != null) { jsonWriter.key("StartTime").value(timeSpan.getStartTime()); } if (timeSpan.getDuration() != null) { jsonWriter.key("Duration").value(timeSpan.getDuration()); } jsonWriter.endObject(); } jsonWriter.endObject(); } } jsonWriter.endArray(); } jsonWriter.endObject(); } } jsonWriter.endArray(); } if (createJobRequest.getOutputKeyPrefix() != null) { jsonWriter.key("OutputKeyPrefix").value(createJobRequest.getOutputKeyPrefix()); } com.amazonaws.internal.ListWithAutoConstructFlag<CreateJobPlaylist> playlistsList = (com.amazonaws.internal.ListWithAutoConstructFlag<CreateJobPlaylist>) (createJobRequest.getPlaylists()); if (playlistsList != null && !(playlistsList.isAutoConstruct() && playlistsList.isEmpty())) { jsonWriter.key("Playlists"); jsonWriter.array(); for (CreateJobPlaylist playlistsListValue : playlistsList) { if (playlistsListValue != null) { jsonWriter.object(); if (playlistsListValue.getName() != null) { jsonWriter.key("Name").value(playlistsListValue.getName()); } if (playlistsListValue.getFormat() != null) { jsonWriter.key("Format").value(playlistsListValue.getFormat()); } com.amazonaws.internal.ListWithAutoConstructFlag<String> outputKeysList = (com.amazonaws.internal.ListWithAutoConstructFlag<String>) (playlistsListValue.getOutputKeys()); if (outputKeysList != null && !(outputKeysList.isAutoConstruct() && outputKeysList.isEmpty())) { jsonWriter.key("OutputKeys"); jsonWriter.array(); for (String outputKeysListValue : outputKeysList) { if (outputKeysListValue != null) { jsonWriter.value(outputKeysListValue); } } jsonWriter.endArray(); } jsonWriter.endObject(); } } 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)); request.addHeader("Content-Type", "application/x-amz-json-1.0"); } catch (Throwable t) { throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t); } return request; }
public Request<CreatePresetRequest> marshall(CreatePresetRequest createPresetRequest) { if (createPresetRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } Request<CreatePresetRequest> request = new DefaultRequest<CreatePresetRequest>(createPresetRequest, "AmazonElasticTranscoder"); String target = "EtsCustomerService.CreatePreset"; request.addHeader("X-Amz-Target", target); request.addHeader("Content-Type", "application/x-amz-json-1.0"); request.setHttpMethod(HttpMethodName.POST); String uriResourcePath = "2012-09-25/presets"; 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 (createPresetRequest.getName() != null) { jsonWriter.key("Name").value(createPresetRequest.getName()); } if (createPresetRequest.getDescription() != null) { jsonWriter.key("Description").value(createPresetRequest.getDescription()); } if (createPresetRequest.getContainer() != null) { jsonWriter.key("Container").value(createPresetRequest.getContainer()); } VideoParameters video = createPresetRequest.getVideo(); if (video != null) { jsonWriter.key("Video"); jsonWriter.object(); if (video.getCodec() != null) { jsonWriter.key("Codec").value(video.getCodec()); } if (video.getCodecOptions() != null) { jsonWriter.key("CodecOptions"); jsonWriter.object(); for (Map.Entry<String, String> codecOptionsListValue : video.getCodecOptions().entrySet()) { if (codecOptionsListValue.getValue() != null) { jsonWriter.key(codecOptionsListValue.getKey()); jsonWriter.value(codecOptionsListValue.getValue()); } } jsonWriter.endObject(); } if (video.getKeyframesMaxDist() != null) { jsonWriter.key("KeyframesMaxDist").value(video.getKeyframesMaxDist()); } if (video.getFixedGOP() != null) { jsonWriter.key("FixedGOP").value(video.getFixedGOP()); } if (video.getBitRate() != null) { jsonWriter.key("BitRate").value(video.getBitRate()); } if (video.getFrameRate() != null) { jsonWriter.key("FrameRate").value(video.getFrameRate()); } if (video.getMaxFrameRate() != null) { jsonWriter.key("MaxFrameRate").value(video.getMaxFrameRate()); } if (video.getResolution() != null) { jsonWriter.key("Resolution").value(video.getResolution()); } if (video.getAspectRatio() != null) { jsonWriter.key("AspectRatio").value(video.getAspectRatio()); } if (video.getMaxWidth() != null) { jsonWriter.key("MaxWidth").value(video.getMaxWidth()); } if (video.getMaxHeight() != null) { jsonWriter.key("MaxHeight").value(video.getMaxHeight()); } if (video.getDisplayAspectRatio() != null) { jsonWriter.key("DisplayAspectRatio").value(video.getDisplayAspectRatio()); } if (video.getSizingPolicy() != null) { jsonWriter.key("SizingPolicy").value(video.getSizingPolicy()); } if (video.getPaddingPolicy() != null) { jsonWriter.key("PaddingPolicy").value(video.getPaddingPolicy()); } com.amazonaws.internal.ListWithAutoConstructFlag<PresetWatermark> watermarksList = (com.amazonaws.internal.ListWithAutoConstructFlag<PresetWatermark>) (video.getWatermarks()); if (watermarksList != null && !(watermarksList.isAutoConstruct() && watermarksList.isEmpty())) { jsonWriter.key("Watermarks"); jsonWriter.array(); for (PresetWatermark watermarksListValue : watermarksList) { if (watermarksListValue != null) { jsonWriter.object(); if (watermarksListValue.getId() != null) { jsonWriter.key("Id").value(watermarksListValue.getId()); } if (watermarksListValue.getMaxWidth() != null) { jsonWriter.key("MaxWidth").value(watermarksListValue.getMaxWidth()); } if (watermarksListValue.getMaxHeight() != null) { jsonWriter.key("MaxHeight").value(watermarksListValue.getMaxHeight()); } if (watermarksListValue.getSizingPolicy() != null) { jsonWriter.key("SizingPolicy").value(watermarksListValue.getSizingPolicy()); } if (watermarksListValue.getHorizontalAlign() != null) { jsonWriter.key("HorizontalAlign").value(watermarksListValue.getHorizontalAlign()); } if (watermarksListValue.getHorizontalOffset() != null) { jsonWriter.key("HorizontalOffset").value(watermarksListValue.getHorizontalOffset()); } if (watermarksListValue.getVerticalAlign() != null) { jsonWriter.key("VerticalAlign").value(watermarksListValue.getVerticalAlign()); } if (watermarksListValue.getVerticalOffset() != null) { jsonWriter.key("VerticalOffset").value(watermarksListValue.getVerticalOffset()); } if (watermarksListValue.getOpacity() != null) { jsonWriter.key("Opacity").value(watermarksListValue.getOpacity()); } if (watermarksListValue.getTarget() != null) { jsonWriter.key("Target").value(watermarksListValue.getTarget()); } jsonWriter.endObject(); } } jsonWriter.endArray(); } jsonWriter.endObject(); } AudioParameters audio = createPresetRequest.getAudio(); if (audio != null) { jsonWriter.key("Audio"); jsonWriter.object(); if (audio.getCodec() != null) { jsonWriter.key("Codec").value(audio.getCodec()); } if (audio.getSampleRate() != null) { jsonWriter.key("SampleRate").value(audio.getSampleRate()); } if (audio.getBitRate() != null) { jsonWriter.key("BitRate").value(audio.getBitRate()); } if (audio.getChannels() != null) { jsonWriter.key("Channels").value(audio.getChannels()); } AudioCodecOptions codecOptions = audio.getCodecOptions(); if (codecOptions != null) { jsonWriter.key("CodecOptions"); jsonWriter.object(); if (codecOptions.getProfile() != null) { jsonWriter.key("Profile").value(codecOptions.getProfile()); } jsonWriter.endObject(); } jsonWriter.endObject(); } Thumbnails thumbnails = createPresetRequest.getThumbnails(); if (thumbnails != null) { jsonWriter.key("Thumbnails"); jsonWriter.object(); if (thumbnails.getFormat() != null) { jsonWriter.key("Format").value(thumbnails.getFormat()); } if (thumbnails.getInterval() != null) { jsonWriter.key("Interval").value(thumbnails.getInterval()); } if (thumbnails.getResolution() != null) { jsonWriter.key("Resolution").value(thumbnails.getResolution()); } if (thumbnails.getAspectRatio() != null) { jsonWriter.key("AspectRatio").value(thumbnails.getAspectRatio()); } if (thumbnails.getMaxWidth() != null) { jsonWriter.key("MaxWidth").value(thumbnails.getMaxWidth()); } if (thumbnails.getMaxHeight() != null) { jsonWriter.key("MaxHeight").value(thumbnails.getMaxHeight()); } if (thumbnails.getSizingPolicy() != null) { jsonWriter.key("SizingPolicy").value(thumbnails.getSizingPolicy()); } if (thumbnails.getPaddingPolicy() != null) { jsonWriter.key("PaddingPolicy").value(thumbnails.getPaddingPolicy()); } jsonWriter.endObject(); } 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; }