Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SSEResource robust against missing parameters #2652

Merged
merged 1 commit into from
Dec 29, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import javax.ws.rs.sse.SseEventSink;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.auth.Role;
import org.openhab.core.events.Event;
import org.openhab.core.io.rest.RESTConstants;
Expand Down Expand Up @@ -207,17 +208,21 @@ public void getStateEvents(@Context final SseEventSink sseEventSink, @Context fi
@Operation(operationId = "updateItemListForStateUpdates", summary = "Changes the list of items a SSE connection will receive state updates to.", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "404", description = "Unknown connectionId") })
public Object updateTrackedItems(@PathParam("connectionId") String connectionId,
@Parameter(description = "items") Set<String> itemNames) {
public Object updateTrackedItems(@PathParam("connectionId") @Nullable String connectionId,
@Parameter(description = "items") @Nullable Set<String> itemNames) {
if (connectionId == null) {
return Response.status(Status.NOT_FOUND).build();
}
Optional<SseSinkItemInfo> itemStateInfo = itemStatesBroadcaster.getInfoIf(hasConnectionId(connectionId))
.findFirst();
if (!itemStateInfo.isPresent()) {
return Response.status(Status.NOT_FOUND).build();
}

itemStateInfo.get().updateTrackedItems(itemNames);
Set<String> trackedItemNames = (itemNames == null) ? Set.of() : itemNames;
itemStateInfo.get().updateTrackedItems(trackedItemNames);

OutboundSseEvent itemStateEvent = itemStatesEventBuilder.buildEvent(sse.newEventBuilder(), itemNames);
OutboundSseEvent itemStateEvent = itemStatesEventBuilder.buildEvent(sse.newEventBuilder(), trackedItemNames);
if (itemStateEvent != null) {
itemStatesBroadcaster.sendIf(itemStateEvent, hasConnectionId(connectionId));
}
Expand Down