Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions python/rpdk/java/templates/generate/HandlerWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ public void testEntrypoint(
e.printStackTrace();
response = ProgressEvent.defaultFailureHandler(e, HandlerErrorCode.InternalFailure);
} finally {
final String output = this.serializer.serialize(response);
outputStream.write(output.getBytes(Charset.forName("UTF-8")));
outputStream.close();
writeResponse(outputStream, response);
}
}

Expand Down
23 changes: 12 additions & 11 deletions src/main/java/software/amazon/cloudformation/LambdaWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,29 +367,30 @@ public void handleRequest(final InputStream inputStream, final OutputStream outp

}

private void writeResponse(final OutputStream outputStream, final ProgressEvent<ResourceT, CallbackT> response)
protected void writeResponse(final OutputStream outputStream, final ProgressEvent<ResourceT, CallbackT> response)
throws IOException {
ResourceT model = response.getResourceModel();
if (model != null) {
JSONObject modelObject = new JSONObject(this.serializer.serialize(model));

if (response.getResourceModel() != null) {
// strip write only properties on final results, we will need the intact model
// while provisioning
if (response.getStatus() != OperationStatus.IN_PROGRESS) {
ResourceTypeSchema.load(provideResourceSchemaJSONObject()).removeWriteOnlyProperties(modelObject);
response.setResourceModel(sanitizeModel(response.getResourceModel()));
}

ResourceT sanitizedModel = this.serializer.deserializeStrict(modelObject.toString(), getModelTypeReference());

response.setResourceModel(sanitizedModel);
}

String output = this.serializer.serialize(response);
outputStream.write(output.getBytes(StandardCharsets.UTF_8));
outputStream.close();
}

private void validateModel(final JSONObject modelObject) throws ValidationException, IOException {
protected ResourceT sanitizeModel(final ResourceT model) throws IOException {
// strip write only properties on final results, we will need the intact model
// while provisioning
final JSONObject modelObject = new JSONObject(this.serializer.serialize(model));
ResourceTypeSchema.load(provideResourceSchemaJSONObject()).removeWriteOnlyProperties(modelObject);
return this.serializer.deserializeStrict(modelObject.toString(), getModelTypeReference());
}

protected void validateModel(final JSONObject modelObject) throws ValidationException, IOException {
JSONObject resourceSchemaJSONObject = provideResourceSchemaJSONObject();
if (resourceSchemaJSONObject == null) {
throw new TerminalException("Unable to validate incoming model as no schema was provided.");
Expand Down