Skip to content

Commit

Permalink
chore: fix NPE when dataplane is null on data plane signaling client (#…
Browse files Browse the repository at this point in the history
…4039)

* chore: fix NPE when dataplane is null on data plane signaling client

* chore: test refactor
  • Loading branch information
wolf4ood authored Mar 25, 2024
1 parent 08df476 commit fd81ffc
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public DataPlaneSignalingClient(EdcHttpClient httpClient, TypeTransformerRegistr
@WithSpan
@Override
public StatusResult<DataFlowResponseMessage> start(DataFlowStartMessage message) {
return send(message, dataPlane.getUrl().toString(), message.getProcessId(), this::handleStartResponse);
return Optional.ofNullable(dataPlane)
.map(instance -> send(message, instance.getUrl().toString(), message.getProcessId(), this::handleStartResponse))
.orElseGet(() -> StatusResult.failure(FATAL_ERROR, noDataPlaneInstanceFound(message)));
}

@Override
Expand All @@ -84,6 +86,13 @@ public StatusResult<Void> terminate(String transferProcessId) {
return send(message, url, transferProcessId, r -> StatusResult.success());
}

private String noDataPlaneInstanceFound(DataFlowStartMessage message) {
var source = message.getSourceDataAddress().getType();
var destination = message.getDestinationDataAddress().getType();
var processId = message.getProcessId();
return "Unable to process transfer %s: No data plane found for source: %s and destination: %s".formatted(processId, source, destination);
}

private <T> StatusResult<T> send(Object message, String url, String processId, Function<Response, StatusResult<T>> handleStartResponse) {
var requestBuilder = transformerRegistry.transform(message, JsonObject.class)
.compose(jsonLd::compact)
Expand Down
Loading

0 comments on commit fd81ffc

Please sign in to comment.