public Request<ListTablesRequest> marshall(ListTablesRequest listTablesRequest) { if (listTablesRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } Request<ListTablesRequest> request = new DefaultRequest<ListTablesRequest>(listTablesRequest, "AmazonDynamoDBv2"); String target = "DynamoDB_20120810.ListTables"; request.addHeader("X-Amz-Target", target); request.addHeader("Content-Type", "application/x-amz-json-1.0"); 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 (listTablesRequest.getExclusiveStartTableName() != null) { jsonWriter .key("ExclusiveStartTableName") .value(listTablesRequest.getExclusiveStartTableName()); } if (listTablesRequest.getLimit() != null) { jsonWriter.key("Limit").value(listTablesRequest.getLimit()); } 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; }
/** Marshall the given parameter object, and output to a JSONWriter */ public void marshall(ItemCollectionMetrics itemCollectionMetrics, JSONWriter jsonWriter) { if (itemCollectionMetrics == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } try { jsonWriter.object(); java.util.Map<String, AttributeValue> itemCollectionKeyMap = itemCollectionMetrics.getItemCollectionKey(); if (itemCollectionKeyMap != null) { jsonWriter.key("ItemCollectionKey"); jsonWriter.object(); for (Map.Entry<String, AttributeValue> itemCollectionKeyMapValue : itemCollectionKeyMap.entrySet()) { if (itemCollectionKeyMapValue.getValue() != null) { jsonWriter.key(itemCollectionKeyMapValue.getKey()); AttributeValueJsonMarshaller.getInstance() .marshall(itemCollectionKeyMapValue.getValue(), jsonWriter); } } jsonWriter.endObject(); } java.util.List<Double> sizeEstimateRangeGBList = itemCollectionMetrics.getSizeEstimateRangeGB(); if (sizeEstimateRangeGBList != null) { jsonWriter.key("SizeEstimateRangeGB"); jsonWriter.array(); for (Double sizeEstimateRangeGBListValue : sizeEstimateRangeGBList) { if (sizeEstimateRangeGBListValue != null) { jsonWriter.value(sizeEstimateRangeGBListValue); } } jsonWriter.endArray(); } jsonWriter.endObject(); } catch (Throwable t) { throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t); } }
public Request<GetRecordsRequest> marshall(GetRecordsRequest getRecordsRequest) { if (getRecordsRequest == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } Request<GetRecordsRequest> request = new DefaultRequest<GetRecordsRequest>(getRecordsRequest, "AmazonDynamoDBStreams"); request.addHeader("X-Amz-Target", "DynamoDBStreams_20120810.GetRecords"); request.setHttpMethod(HttpMethodName.POST); request.setResourcePath(""); try { StringWriter stringWriter = new StringWriter(); JSONWriter jsonWriter = new JSONWriter(stringWriter); jsonWriter.object(); if (getRecordsRequest.getShardIterator() != null) { jsonWriter.key("ShardIterator").value(getRecordsRequest.getShardIterator()); } if (getRecordsRequest.getLimit() != null) { jsonWriter.key("Limit").value(getRecordsRequest.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.0"); } catch (Throwable t) { throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t); } return request; }
/** Marshall the given parameter object, and output to a JSONWriter */ public void marshall(KeySchemaElement keySchemaElement, JSONWriter jsonWriter) { if (keySchemaElement == null) { throw new AmazonClientException("Invalid argument passed to marshall(...)"); } try { jsonWriter.object(); if (keySchemaElement.getAttributeName() != null) { jsonWriter.key("AttributeName").value(keySchemaElement.getAttributeName()); } if (keySchemaElement.getKeyType() != null) { jsonWriter.key("KeyType").value(keySchemaElement.getKeyType()); } jsonWriter.endObject(); } catch (Throwable t) { throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t); } }