Skip to content

Commit

Permalink
fix: NPE when returning null CE in Knative Funqy
Browse files Browse the repository at this point in the history
Allows user to return empty response (no CloudEvent) from non-void methods.

Signed-off-by: Matej Vasek <mvasek@redhat.com>
  • Loading branch information
matejvasek committed May 5, 2022
1 parent 8f25706 commit 5180a5a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ public void testGenericInput() {
.body(equalTo("6"));
}

@Test
public void testNullResponse() {
RestAssured.given().contentType("application/json")
.header("ce-id", "test-id")
.header("ce-specversion", "1.0")
.header("ce-type", "test-null-response")
.header("ce-source", "test-source")
.post()
.then()
.statusCode(204);
}

@ParameterizedTest
@MethodSource("provideBinaryEncodingTestArgs")
public void testBinaryEncoding(Map<String, String> headers, String specversion, String dataSchemaHdrName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public CloudEvent<Integer> sum(CloudEvent<List<TestBean>> event) {
.build(data);
}

@Funq
@CloudEventMapping(trigger = "test-null-response")
public CloudEvent<String> returnNull(CloudEvent<Void> ignore) {
return null;
}

public static class TestBean implements Serializable {
private int i;
private String s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ private void processCloudEvent(RoutingContext routingContext) {
outputCloudEvent = (CloudEvent<?>) output;
}

if (outputCloudEvent == null) {
routingContext.response().setStatusCode(204);
routingContext.response().end();
return;
}

String id = outputCloudEvent.id();
if (id == null) {
id = getResponseId();
Expand Down

0 comments on commit 5180a5a

Please sign in to comment.