software.amazon.awssdk.core.SdkBytes Java Examples
The following examples show how to use
software.amazon.awssdk.core.SdkBytes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetaStore.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Build an material item for a given material name and version with newly generated * encryption and integrity keys. * * @param materialName material name. * @param version version of the material. * @return newly generated plaintext material item. */ private Map<String, AttributeValue> createMaterialItem(final String materialName, final long version) { final SecretKeySpec encryptionKey = new SecretKeySpec(Utils.getRandom(32), DEFAULT_ENCRYPTION); final SecretKeySpec integrityKey = new SecretKeySpec(Utils.getRandom(32), DEFAULT_INTEGRITY); final Map<String, AttributeValue> plaintext = new HashMap<>(); plaintext.put(DEFAULT_HASH_KEY, AttributeValue.builder().s(materialName).build()); plaintext.put(DEFAULT_RANGE_KEY, AttributeValue.builder().n(Long.toString(version)).build()); plaintext.put(MATERIAL_TYPE_VERSION, AttributeValue.builder().s("0").build()); plaintext.put(ENCRYPTION_KEY_FIELD, AttributeValue.builder().b(SdkBytes.fromByteArray(encryptionKey.getEncoded())).build()); plaintext.put(ENCRYPTION_ALGORITHM_FIELD, AttributeValue.builder().s(encryptionKey.getAlgorithm()).build()); plaintext.put(INTEGRITY_KEY_FIELD, AttributeValue.builder().b(SdkBytes.fromByteArray(integrityKey.getEncoded())).build()); plaintext.put(INTEGRITY_ALGORITHM_FIELD, AttributeValue.builder().s(integrityKey.getAlgorithm()).build()); plaintext.putAll(extraDataSupplier.getAttributes(materialName, version)); return plaintext; }
Example #2
Source File: DynamoDbSignerTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test public void macLists() throws GeneralSecurityException { Map<String, AttributeValue> itemAttributes = new HashMap<>(); Map<String, Set<EncryptionFlags>> attributeFlags = new HashMap<>(); itemAttributes.put("Key1", AttributeValue.builder().ss("Value1", "Value2", "Value3").build()); attributeFlags.put("Key1", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key2", AttributeValue.builder().ns("100", "200", "300").build()); attributeFlags.put("Key2", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key3", AttributeValue.builder().bs(SdkBytes.fromByteArray(new byte[] { 0, 1, 2, 3}), SdkBytes.fromByteArray(new byte[] { 3, 2, 1})).build()); attributeFlags.put("Key3", EnumSet.of(EncryptionFlags.SIGN, EncryptionFlags.ENCRYPT)); byte[] signature = signerRsa.calculateSignature(itemAttributes, attributeFlags, new byte[0], macKey); signerRsa.verifySignature(itemAttributes, attributeFlags, new byte[0], macKey, ByteBuffer.wrap(signature)); }
Example #3
Source File: JsonProtocolMarshaller.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
void doMarshall(SdkPojo pojo) { for (SdkField<?> field : pojo.sdkFields()) { Object val = field.getValueOrDefault(pojo); if (isBinary(field, val)) { request.contentStreamProvider(((SdkBytes) val)::asInputStream); } else { if (val != null && field.containsTrait(PayloadTrait.class)) { jsonGenerator.writeStartObject(); doMarshall((SdkPojo) val); jsonGenerator.writeEndObject(); } else { MARSHALLER_REGISTRY.getMarshaller(field.location(), field.marshallingType(), val) .marshall(val, marshallerContext, field.locationName(), (SdkField<Object>) field); } } } }
Example #4
Source File: DynamoDbSignerTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = SignatureException.class) public void macChangedFlag() throws GeneralSecurityException { Map<String, AttributeValue> itemAttributes = new HashMap<>(); Map<String, Set<EncryptionFlags>> attributeFlags = new HashMap<>(); itemAttributes.put("Key1", AttributeValue.builder().s("Value1").build()); attributeFlags.put("Key1", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key2", AttributeValue.builder().n("100").build()); attributeFlags.put("Key2", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key3", AttributeValue.builder().b(SdkBytes.fromByteArray(new byte[] { 0, 1, 2, 3})).build()); attributeFlags.put("Key3", EnumSet.of(EncryptionFlags.SIGN, EncryptionFlags.ENCRYPT)); byte[] signature = signerRsa.calculateSignature(itemAttributes, attributeFlags, new byte[0], macKey); attributeFlags.put("Key3", EnumSet.of(EncryptionFlags.SIGN)); signerRsa.verifySignature(itemAttributes, attributeFlags, new byte[0], macKey, ByteBuffer.wrap(signature)); }
Example #5
Source File: DelegatedEncryptionTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@BeforeMethod public void setUp() { prov = new SymmetricStaticProvider(encryptionKey, macKey, Collections.emptyMap()); encryptor = new DynamoDbEncryptor(prov, "encryptor-"); attribs = new HashMap<>(); attribs.put("intValue", AttributeValue.builder().n("123").build()); attribs.put("stringValue", AttributeValue.builder().s("Hello world!").build()); attribs.put("byteArrayValue", AttributeValue.builder().b(SdkBytes.fromByteArray(new byte[] {0, 1, 2, 3, 4, 5})).build()); attribs.put("stringSet", AttributeValue.builder().ss("Goodbye", "Cruel", "World", "?").build()); attribs.put("intSet", AttributeValue.builder().ns("1", "200", "10", "15", "0").build()); attribs.put("hashKey", AttributeValue.builder().n("5").build()); attribs.put("rangeKey", AttributeValue.builder().n("7").build()); attribs.put("version", AttributeValue.builder().n("0").build()); context = EncryptionContext.builder() .tableName("TableName") .hashKeyName("hashKey") .rangeKeyName("rangeKey") .build(); }
Example #6
Source File: SubscribeToShardIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
/** * Puts a random record to the stream. * * @param len The number of bytes to generate for the record. * @return Record data that was put. */ private Optional<SdkBytes> putRecord(int len) { try { SdkBytes data = SdkBytes.fromByteArray(RandomUtils.nextBytes(len)); asyncClient.putRecord(PutRecordRequest.builder() .streamName(streamName) .data(data) .partitionKey(UUID.randomUUID().toString()) .build()) .join(); return Optional.of(data); } catch (Exception e) { e.printStackTrace(); return Optional.empty(); } }
Example #7
Source File: KinesisIntegrationTests.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private PutRecordResponse putRecord(final String streamName, final String data) { PutRecordResponse result = client.putRecord( PutRecordRequest.builder() .streamName(streamName) .partitionKey("foobar") .data(SdkBytes.fromUtf8String(data)) .build()); Assert.assertNotNull(result); Assert.assertNotNull(result.shardId()); Assert.assertNotNull(result.sequenceNumber()); return result; }
Example #8
Source File: AttributeValueCoderTest.java From beam with Apache License 2.0 | 6 votes |
@Test public void shouldPassForMapType() throws IOException { Map<String, AttributeValue> attrMap = new HashMap<>(); attrMap.put("innerMapAttr1", AttributeValue.builder().s("innerMapValue1").build()); attrMap.put( "innerMapAttr2", AttributeValue.builder() .b(SdkBytes.fromByteArray("8976234".getBytes(StandardCharsets.UTF_8))) .build()); AttributeValue expected = AttributeValue.builder().m(attrMap).build(); AttributeValueCoder coder = AttributeValueCoder.of(); ByteArrayOutputStream output = new ByteArrayOutputStream(); coder.encode(expected, output); ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray()); AttributeValue actual = coder.decode(in); Assert.assertEquals(expected, actual); }
Example #9
Source File: XmlProtocolMarshaller.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
void doMarshall(SdkPojo pojo) { for (SdkField<?> field : pojo.sdkFields()) { Object val = field.getValueOrDefault(pojo); if (isBinary(field, val)) { request.contentStreamProvider(((SdkBytes) val)::asInputStream); setContentTypeHeaderIfNeeded("binary/octet-stream"); } else if (isExplicitPayloadMember(field) && val instanceof String) { byte[] content = ((String) val).getBytes(StandardCharsets.UTF_8); request.contentStreamProvider(() -> new ByteArrayInputStream(content)); request.putHeader(CONTENT_LENGTH, Integer.toString(content.length)); } else { MARSHALLER_REGISTRY.getMarshaller(field.location(), field.marshallingType(), val) .marshall(val, marshallerContext, field.locationName(), (SdkField<Object>) field); } } }
Example #10
Source File: KinesisMessageLogReceiverEndpointTest.java From synapse with Apache License 2.0 | 5 votes |
private Record createRecord(String data) { String json = "{\"data\":\"" + data + "\"}"; final Record record = Record.builder() .partitionKey(data) .approximateArrivalTimestamp(clock.instant()) .data(SdkBytes.fromByteArray(json.getBytes(StandardCharsets.UTF_8))) .sequenceNumber(String.valueOf(nextKey.getAndIncrement())) .build(); LOG.info("Created Record " + record); return record; }
Example #11
Source File: QuarkusKmsSyncResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@POST @Path("/encrypt") public String encrypt(String data) { SdkBytes encryptedBytes = kms.encrypt(req -> req.keyId(keyArn).plaintext(SdkBytes.fromUtf8String(data))).ciphertextBlob(); return Base64.encodeBase64String(encryptedBytes.asByteArray()); }
Example #12
Source File: DynamoDbStartKeySerializerTest.java From realworld-serverless-application with Apache License 2.0 | 5 votes |
@Test public void testByte() throws Exception { Map<String, AttributeValue> startKey = new HashMap<>(); startKey.put("Byte", AttributeValue.builder().b(SdkBytes.fromUtf8String("test")).build()); String startKeyString = serializer.serialize(startKey); assertThat(serializer.deserialize(startKeyString)) .isEqualTo(startKey); }
Example #13
Source File: DynamoDbEncryptorTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions =IllegalArgumentException.class) public void badVersionNumber() { Map<String, AttributeValue> encryptedAttributes = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, Collections.unmodifiableMap(attribs), context, asList("hashKey", "rangeKey", "version")); byte[] rawArray = encryptedAttributes.get(encryptor.getMaterialDescriptionFieldName()).b().asByteArray(); assertEquals(0, rawArray[0]); // This will need to be kept in sync with the current version. rawArray[0] = 100; encryptedAttributes.put(encryptor.getMaterialDescriptionFieldName(), AttributeValue.builder().b(SdkBytes.fromByteArray(rawArray)).build()); EncryptionTestHelper.decryptAllFieldsExcept(encryptor, Collections.unmodifiableMap(encryptedAttributes), context, asList("hashKey", "rangeKey", "version")); }
Example #14
Source File: KinesisAppender.java From kinesis-logback-appender with Apache License 2.0 | 5 votes |
@Override protected void putMessage(String message) throws Exception { SdkBytes data = SdkBytes.fromByteArray(message.getBytes(getEncoding())); getClient().putRecord(builder -> builder .partitionKey(UUID.randomUUID().toString()) .streamName(getStreamName()) .data(data) .build()).whenCompleteAsync(asyncCallHandler); }
Example #15
Source File: QuarkusKmsAsyncResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@POST @Path("/decrypt") public Uni<String> decrypt(String data) { return Uni.createFrom().item(SdkBytes.fromByteArray(Base64.decodeBase64(data.getBytes()))) .onItem().produceCompletionStage(msg -> kms.decrypt(req -> req.keyId(keyArn).ciphertextBlob(msg))) .onItem().apply(DecryptResponse::plaintext) .onItem().apply(SdkBytes::asUtf8String); }
Example #16
Source File: SdkPojoSerializer.java From cloudformation-cli-java-plugin with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void writeObject(Object value, SdkField<?> sdkField, JsonGenerator gen, SerializerProvider serializers) throws IOException { MarshallingType<?> type = sdkField.marshallingType(); if (type.equals(MarshallingType.BOOLEAN)) { gen.writeBoolean((Boolean) value); } else if (type.equals(MarshallingType.DOUBLE)) { gen.writeNumber((Double) value); } else if (type.equals(MarshallingType.INTEGER)) { gen.writeNumber((Integer) value); } else if (type.equals(MarshallingType.FLOAT)) { gen.writeNumber((Float) value); } else if (type.equals(MarshallingType.STRING)) { gen.writeString((String) value); } else if (type.equals(MarshallingType.BIG_DECIMAL)) { gen.writeNumber((BigDecimal) value); } else if (type.equals(MarshallingType.SDK_BYTES)) { gen.writeBinary(((SdkBytes) value).asByteArray()); } else if (type.equals(MarshallingType.INSTANT)) { JsonSerializer<Object> serializer = serializers.findValueSerializer(Instant.class); serializer.serialize(value, gen, serializers); } else if (type.equals(MarshallingType.LONG)) { gen.writeNumber((Long) value); } else if (type.equals(MarshallingType.SDK_POJO)) { writeSdkPojo((SdkPojo) value, gen, serializers); } else if (type.equals(MarshallingType.LIST)) { writeSdkList((Collection<Object>) value, sdkField, gen, serializers); } else if (type.equals(MarshallingType.MAP)) { writeSdkMap((Map<String, Object>) value, sdkField, gen, serializers); } }
Example #17
Source File: DetectModerationLabels.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void detectModLabels(RekognitionClient rekClient, String sourceImage) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); // Create an Image object for the source image Image souImage = Image.builder() .bytes(sourceBytes) .build(); DetectModerationLabelsRequest moderationLabelsRequest = DetectModerationLabelsRequest.builder() .image(souImage) .minConfidence(60F) .build(); DetectModerationLabelsResponse moderationLabelsResponse = rekClient.detectModerationLabels(moderationLabelsRequest); // Get the results List<ModerationLabel> labels = moderationLabelsResponse.moderationLabels(); System.out.println("Detected labels for image"); for (ModerationLabel label : labels) { System.out.println("Label: " + label.name() + "\n Confidence: " + label.confidence().toString() + "%" + "\n Parent:" + label.parentName()); } } catch (RekognitionException | FileNotFoundException e) { e.printStackTrace(); System.exit(1); } // snippet-end:[rekognition.java2.detect_mod_labels.main] }
Example #18
Source File: DynamoDbSignerTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = SignatureException.class) public void macChangedAssociatedData() throws GeneralSecurityException { Map<String, AttributeValue> itemAttributes = new HashMap<>(); Map<String, Set<EncryptionFlags>> attributeFlags = new HashMap<>(); itemAttributes.put("Key1", AttributeValue.builder().s("Value1").build()); attributeFlags.put("Key1", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key2", AttributeValue.builder().n("100").build()); attributeFlags.put("Key2", EnumSet.of(EncryptionFlags.SIGN)); itemAttributes.put("Key3", AttributeValue.builder().b(SdkBytes.fromByteArray(new byte[] { 0, 1, 2, 3})).build()); attributeFlags.put("Key3", EnumSet.of(EncryptionFlags.SIGN, EncryptionFlags.ENCRYPT)); byte[] signature = signerRsa.calculateSignature(itemAttributes, attributeFlags, new byte[] {3, 2, 1}, macKey); signerRsa.verifySignature(itemAttributes, attributeFlags, new byte[] {1, 2, 3}, macKey, ByteBuffer.wrap(signature)); }
Example #19
Source File: EncryptedTokenSerializer.java From realworld-serverless-application with Apache License 2.0 | 5 votes |
@Override public String deserialize(final String encodedStartKey) throws InvalidTokenException { try { return kms.decrypt(DecryptRequest.builder() .ciphertextBlob(SdkBytes.fromByteArray(base64Decode(encodedStartKey))) .build()) .plaintext() .asUtf8String(); } catch (InvalidCiphertextException e) { throw new InvalidTokenException("Failed to decrypt token:" + encodedStartKey, e); } }
Example #20
Source File: RedisUpdate.java From reactive-refarch-cloudformation with Apache License 2.0 | 5 votes |
public static void main (String ... args) { KinesisAsyncClient kinesisAsync = createClient(); byte[] msg = prepareData(); SdkBytes payload = SdkBytes.fromByteArray(msg); PutRecordRequest putRecordRequest = PutRecordRequest.builder() .partitionKey("test") .streamName(kinesisStream) .data(payload) .build(); CompletableFuture<PutRecordResponse> future = kinesisAsync.putRecord(putRecordRequest); future.whenComplete((result, e) -> { if (e != null) { System.out.println(e); } else { String sequenceNumber = result.sequenceNumber(); System.out.println("Message sequence number: " + sequenceNumber); } }); }
Example #21
Source File: AwsXmlErrorProtocolUnmarshaller.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Parse the response content into an XML document. If we fail to read the content or the XML is malformed * we still return an empty {@link XmlElement} so that unmarshalling can proceed. In those failure * cases we can't parse out the error code so we'd unmarshall into a generic service exception. * * @param response HTTP response. * @return Pair of the parsed {@link XmlElement} and the raw bytes of the response. */ private Pair<XmlElement, SdkBytes> parseXml(SdkHttpFullResponse response) { SdkBytes bytes = getResponseBytes(response); try { return Pair.of(XmlDomParser.parse(bytes.asInputStream()), bytes); } catch (Exception e) { return Pair.of(XmlElement.empty(), bytes); } }
Example #22
Source File: PresignedGetObjectRequestTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void equalsAndHashCode_differentProperty_signedPayload() { SdkBytes otherSignedPayload = SdkBytes.fromString("other-payload", StandardCharsets.UTF_8); PresignedGetObjectRequest request = generateMaximal(); PresignedGetObjectRequest otherRequest = request.toBuilder().signedPayload(otherSignedPayload).build(); assertThat(request).isNotEqualTo(otherRequest); assertThat(request.hashCode()).isNotEqualTo(otherRequest.hashCode()); }
Example #23
Source File: ServiceIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void testFunctionOperations() throws IOException { // Get function GetFunctionResponse getFunc = lambda.getFunction(r -> r.functionName(FUNCTION_NAME)).join(); checkValid_GetFunctionResponse(getFunc); // Get function configuration GetFunctionConfigurationResponse getConfig = lambda.getFunctionConfiguration(r -> r.functionName(FUNCTION_NAME)).join(); checkValid_GetFunctionConfigurationResponse(getConfig); // List functions ListFunctionsResponse listFunc = lambda.listFunctions(ListFunctionsRequest.builder().build()).join(); Assert.assertFalse(listFunc.functions().isEmpty()); for (FunctionConfiguration funcConfig : listFunc.functions()) { checkValid_FunctionConfiguration(funcConfig); } // Invoke the function InvokeResponse invokeResult = lambda.invoke(InvokeRequest.builder().functionName(FUNCTION_NAME) .invocationType(InvocationType.EVENT).payload(SdkBytes.fromUtf8String("{}")).build()).join(); Assert.assertEquals(202, invokeResult.statusCode().intValue()); Assert.assertNull(invokeResult.logResult()); Assert.assertEquals(0, invokeResult.payload().asByteBuffer().remaining()); invokeResult = lambda.invoke(InvokeRequest.builder().functionName(FUNCTION_NAME) .invocationType(InvocationType.REQUEST_RESPONSE).logType(LogType.TAIL) .payload(SdkBytes.fromUtf8String("{}")).build()).join(); Assert.assertEquals(200, invokeResult.statusCode().intValue()); System.out.println(new String(BinaryUtils.fromBase64(invokeResult.logResult()), StandardCharsets.UTF_8)); Assert.assertEquals("\"Hello World\"", invokeResult.payload().asUtf8String()); }
Example #24
Source File: ShapeModelReflector.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private Object getSimpleMemberValue(JsonNode currentNode, MemberModel memberModel) { if (memberModel.getHttp().getIsStreaming()) { return null; } switch (memberModel.getVariable().getSimpleType()) { case "Long": return currentNode.asLong(); case "Integer": return currentNode.asInt(); case "String": return currentNode.asText(); case "Boolean": return currentNode.asBoolean(); case "Double": return currentNode.asDouble(); case "Instant": return Instant.ofEpochMilli(currentNode.asLong()); case "SdkBytes": return SdkBytes.fromUtf8String(currentNode.asText()); case "Float": return (float) currentNode.asDouble(); case "Character": return asCharacter(currentNode); case "BigDecimal": return new BigDecimal(currentNode.asText()); default: throw new IllegalArgumentException( "Unsupported fieldType " + memberModel.getVariable().getSimpleType()); } }
Example #25
Source File: DelegatedEncryptionTest.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void badVersionNumber() { Map<String, AttributeValue> encryptedAttributes = EncryptionTestHelper.encryptAllFieldsExcept(encryptor, Collections.unmodifiableMap(attribs), context, asList("hashKey", "rangeKey", "version")); byte[] rawArray = encryptedAttributes.get(encryptor.getMaterialDescriptionFieldName()).b().asByteArray(); assertEquals(0, rawArray[0]); // This will need to be kept in sync with the current version. rawArray[0] = 100; encryptedAttributes.put(encryptor.getMaterialDescriptionFieldName(), AttributeValue.builder().b(SdkBytes.fromByteArray(rawArray)).build()); EncryptionTestHelper.decryptAllFieldsExcept(encryptor, Collections.unmodifiableMap(encryptedAttributes), context, asList("hashKey", "rangeKey", "version")); }
Example #26
Source File: ServiceIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public void testOperations() { // create delivery stream CreateDeliveryStreamRequest request = CreateDeliveryStreamRequest.builder() .deliveryStreamName(DEVLIVERY_STREAM_NAME) .s3DestinationConfiguration(S3DestinationConfiguration.builder() .bucketARN(FAKE_S3_BUCKET_ARN) .roleARN(FAKE_IAM_ROLE_ARN) .build()) .build(); firehose.createDeliveryStream(request); // put record String recordId = firehose.putRecord(PutRecordRequest.builder() .deliveryStreamName(DEVLIVERY_STREAM_NAME) .record(Record.builder() .data(SdkBytes.fromByteArray(new byte[] {0, 1, 2})) .build()) .build() ).recordId(); assertNotEmpty(recordId); // put record batch List<PutRecordBatchResponseEntry> entries = firehose.putRecordBatch( PutRecordBatchRequest.builder() .deliveryStreamName(DEVLIVERY_STREAM_NAME) .records(Record.builder().data(SdkBytes.fromByteArray(new byte[] {0})).build(), Record.builder().data(SdkBytes.fromByteArray(new byte[] {1})).build()) .build() ).requestResponses(); assertEquals(2, entries.size()); for (PutRecordBatchResponseEntry entry : entries) { if (entry.errorCode() == null) { assertNotEmpty(entry.recordId()); } else { assertNotEmpty(entry.errorMessage()); } } }
Example #27
Source File: GetExportIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws IOException { IntegrationTestBase.setUp(); restApi = SdkBytes.fromInputStream(GetExportIntegrationTest.class.getResourceAsStream("/PetStore-Alpha-swagger-apigateway.json")); restApiId = apiGateway.importRestApi(r -> r.body(restApi).failOnWarnings(false)).id(); deploymentId = apiGateway.createDeployment(r -> r.stageName(STAGE).restApiId(restApiId)).id(); }
Example #28
Source File: JsonProtocolUnmarshaller.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static <TypeT extends SdkPojo> TypeT unmarshallStructured(SdkPojo sdkPojo, SdkJsonNode jsonContent, JsonUnmarshallerContext context) { for (SdkField<?> field : sdkPojo.sdkFields()) { if (isExplicitPayloadMember(field) && field.marshallingType() == MarshallingType.SDK_BYTES) { field.set(sdkPojo, SdkBytes.fromInputStream(context.response().content().orElse(null))); } else { SdkJsonNode jsonFieldContent = getSdkJsonNode(jsonContent, field); JsonUnmarshaller<Object> unmarshaller = context.getUnmarshaller(field.location(), field.marshallingType()); field.set(sdkPojo, unmarshaller.unmarshall(context, jsonFieldContent, (SdkField<Object>) field)); } } return (TypeT) ((Buildable) sdkPojo).build(); }
Example #29
Source File: TestDirectDeaggregation.java From kinesis-aggregation with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { aggregator = new RecordAggregator(); recordList = new LinkedList<>(); // create 10 random records for testing for (int i = 0; i < c; i++) { // create trackable id String id = UUID.randomUUID().toString(); // create a kinesis model record byte[] data = RandomStringUtils.randomAlphabetic(20).getBytes(); Record r = Record.builder().partitionKey(id) .approximateArrivalTimestamp(new Date(System.currentTimeMillis()).toInstant()) .data(SdkBytes.fromByteArray(data)).build(); recordList.add(r); // add the record to the check set checkset.put(id, r); // add the record to the aggregated AggRecord // create an aggregated set of aggregator.addUserRecord(id, data); } // get the aggregated data aggregated = aggregator.clearAndGet(); assertEquals("Aggregated Record Count Correct", aggregated.getNumUserRecords(), c); }
Example #30
Source File: V1ItemFactory.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private static V1HugeBean fromHugeBean(HugeBean hb) { V1HugeBean b = new V1HugeBean(); b.setHashKey(hb.getHashKey()); b.setStringAttr(hb.getStringAttr()); b.setBinaryAttrV1(hb.getBinaryAttr().asByteBuffer()); b.setListAttr(hb.getListAttr()); b.setMapAttr1V1(hb.getMapAttr1() .entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().asByteBuffer()))); b.setMapAttr2V1(hb.getMapAttr2() .entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().stream().map(SdkBytes::asByteBuffer).collect(Collectors.toList())))); Map<String, List<Map<String, List<ByteBuffer>>>> mapAttr3V1 = hb.getMapAttr3() .entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().stream() .map(m -> m.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, ee -> ee.getValue().stream().map(SdkBytes::asByteBuffer).collect(Collectors.toList()) ))) .collect(Collectors.toList()))); b.setMapAttr3V1(mapAttr3V1); return b; }