Java Code Examples for software.amazon.awssdk.core.SdkBytes#fromUtf8String()
The following examples show how to use
software.amazon.awssdk.core.SdkBytes#fromUtf8String() .
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: KmsResource.java From quarkus with Apache License 2.0 | 6 votes |
@GET @Path("async") @Produces(TEXT_PLAIN) public CompletionStage<String> testAsync() { LOG.info("Testing Async KMS client"); SdkBytes textToEncrypt = SdkBytes.fromUtf8String(TEXT); //Create master key CompletableFuture<String> masterKeyId = kmsAsyncClient.createKey() .thenApply(resp -> resp.keyMetadata().keyId()) .thenCompose(keyId -> kmsAsyncClient.generateDataKey(req -> req.keyId(keyId).keySpec(DataKeySpec.AES_256))) .thenApply(GenerateDataKeyResponse::keyId); //Encrypt & Decrypt return masterKeyId .thenCompose(keyId -> kmsAsyncClient.encrypt(req -> req.keyId(keyId).plaintext(textToEncrypt)) .thenApply(EncryptResponse::ciphertextBlob) .thenCompose(encryptedBytes -> kmsAsyncClient .decrypt(req -> req.ciphertextBlob(encryptedBytes).keyId(keyId))) .thenApply(DecryptResponse::plaintext) .thenApply(BytesWrapper::asUtf8String)); }
Example 2
Source File: ServiceIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private void updateThingShadow_ValidRequest_ReturnsValidResponse(String thingName) throws Exception { SdkBytes originalPayload = SdkBytes.fromUtf8String("{ \"state\": {\"reported\":{ \"r\": {}}}}"); UpdateThingShadowRequest request = UpdateThingShadowRequest.builder().thingName(thingName).payload(originalPayload).build(); UpdateThingShadowResponse result = iot.updateThingShadow(request); // Comes back with some extra metadata so we assert it's bigger than the original assertThat(result.payload().asByteBuffer().capacity(), greaterThan(originalPayload.asByteBuffer().capacity())); assertPayloadIsValid(originalPayload, result.payload()); }
Example 3
Source File: BinaryAttributeConvertersTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void sdkBytesAttributeConverterBehaves() { SdkBytesAttributeConverter converter = SdkBytesAttributeConverter.create(); SdkBytes bytes = SdkBytes.fromUtf8String(""); assertThat(transformFrom(converter, bytes).b()).isSameAs(bytes); assertThat(transformTo(converter, EnhancedAttributeValue.fromBytes(bytes).toAttributeValue())).isSameAs(bytes); }
Example 4
Source File: ModelSerializationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void jacksonSerializationWorksForPopulatedRequestModels() throws IOException { SdkBytes blob = SdkBytes.fromUtf8String("foo"); SimpleStruct simpleStruct = SimpleStruct.builder().stringMember("foo").build(); StructWithTimestamp structWithTimestamp = StructWithTimestamp.builder().nestedTimestamp(Instant.EPOCH).build(); StructWithNestedBlobType structWithNestedBlob = StructWithNestedBlobType.builder().nestedBlob(blob).build(); RecursiveStructType recursiveStruct = RecursiveStructType.builder() .recursiveStruct(RecursiveStructType.builder().build()) .build(); BaseType baseType = BaseType.builder().baseMember("foo").build(); SubTypeOne subtypeOne = SubTypeOne.builder().subTypeOneMember("foo").build(); validateJacksonSerialization(AllTypesRequest.builder() .stringMember("foo") .integerMember(5) .booleanMember(true) .floatMember(5F) .doubleMember(5D) .longMember(5L) .simpleList("foo", "bar") .listOfMaps(singletonList(singletonMap("foo", "bar"))) .listOfStructs(simpleStruct) .mapOfStringToIntegerList(singletonMap("foo", singletonList(5))) .mapOfStringToStruct(singletonMap("foo", simpleStruct)) .timestampMember(Instant.EPOCH) .structWithNestedTimestampMember(structWithTimestamp) .blobArg(blob) .structWithNestedBlob(structWithNestedBlob) .blobMap(singletonMap("foo", blob)) .listOfBlobs(blob, blob) .recursiveStruct(recursiveStruct) .polymorphicTypeWithSubTypes(baseType) .polymorphicTypeWithoutSubTypes(subtypeOne) .enumMember("foo") .listOfEnumsWithStrings("foo", "bar") .mapOfEnumToEnumWithStrings(singletonMap("foo", "bar")) .build()); }
Example 5
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 6
Source File: ServiceIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Test(expected = InvalidRequestException.class) public void updateThingShadow_MalformedPayload_ThrowsServiceException() throws Exception { SdkBytes payload = SdkBytes.fromUtf8String("{ }"); UpdateThingShadowRequest request = UpdateThingShadowRequest.builder().thingName(THING_NAME).payload(payload).build(); iot.updateThingShadow(request); }
Example 7
Source File: AwsXmlErrorProtocolUnmarshaller.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
/** * @return Dummy XML document to allow unmarshalling when response can't be read/parsed. */ private SdkBytes emptyXmlBytes() { return SdkBytes.fromUtf8String("<eof/>"); }
Example 8
Source File: LambdaInvoke.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static void main(String[] args) { if (args.length < 1) { System.out.println("Please specify a function name"); System.exit(1); } // snippet-start:[lambda.java2.invoke.main] /* Function names appear as arn:aws:lambda:us-west-2:335556330391:function:HelloFunction you can retrieve the value by looking at the function in the AWS Console */ String functionName = args[0]; InvokeResponse res = null ; try { Region region = Region.US_WEST_2; LambdaClient awsLambda = LambdaClient.builder().region(region).build(); //Need a SdkBytes instance for the payload SdkBytes payload = SdkBytes.fromUtf8String("{\n" + " \"Hello \": \"Paris\",\n" + " \"countryCode\": \"FR\"\n" + "}" ) ; //Setup an InvokeRequest InvokeRequest request = InvokeRequest.builder() .functionName(functionName) .payload(payload) .build(); //Invoke the Lambda function res = awsLambda.invoke(request); //Get the response String value = res.payload().asUtf8String() ; //write out the response System.out.println(value); } catch(ServiceException e) { e.getStackTrace(); } // snippet-end:[lambda.java2.invoke.main] }