Adjust REST HTTP response status codes (#5236)

Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
This commit is contained in:
Nadahar
2026-02-05 18:57:27 +01:00
committed by GitHub
parent cca4f2fcdc
commit 7343711214
5 changed files with 18 additions and 13 deletions
@@ -131,7 +131,8 @@ public class ThingActionsResource implements RESTResource {
if (actionUIDs.isEmpty()) { if (actionUIDs.isEmpty()) {
return; return;
} }
thingActionsMap.computeIfAbsent(thingUID, thingUid -> new ConcurrentHashMap<>()).put(scope, actionUIDs); Objects.requireNonNull(thingActionsMap.computeIfAbsent(thingUID, thingUid -> new ConcurrentHashMap<>()))
.put(scope, actionUIDs);
} }
} }
@@ -165,7 +166,7 @@ public class ThingActionsResource implements RESTResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getAvailableActionsForThing", summary = "Get all available actions for provided thing UID", responses = { @Operation(operationId = "getAvailableActionsForThing", summary = "Get all available actions for provided thing UID", responses = {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ThingActionDTO.class), uniqueItems = true))), @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ThingActionDTO.class), uniqueItems = true))),
@ApiResponse(responseCode = "404", description = "No actions found.") }) @ApiResponse(responseCode = "204", description = "No actions found") })
public Response getActions(@PathParam("thingUID") @Parameter(description = "thingUID") String thingUID, public Response getActions(@PathParam("thingUID") @Parameter(description = "thingUID") String thingUID,
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) { @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) {
Locale locale = localeService.getLocale(language); Locale locale = localeService.getLocale(language);
@@ -174,7 +175,7 @@ public class ThingActionsResource implements RESTResource {
List<ThingActionDTO> actions = new ArrayList<>(); List<ThingActionDTO> actions = new ArrayList<>();
Map<String, List<String>> thingActionsMap = this.thingActionsMap.get(aThingUID); Map<String, List<String>> thingActionsMap = this.thingActionsMap.get(aThingUID);
if (thingActionsMap == null) { if (thingActionsMap == null) {
return Response.status(Response.Status.NOT_FOUND).build(); return Response.noContent().build();
} }
// inspect ThingActions // inspect ThingActions
@@ -155,8 +155,11 @@ public class ConfigurationService {
* @return old config or null if no old config existed * @return old config or null if no old config existed
* @throws IOException if configuration can not be removed * @throws IOException if configuration can not be removed
*/ */
public Configuration delete(String configId) throws IOException { public @Nullable Configuration delete(String configId) throws IOException {
org.osgi.service.cm.Configuration serviceConfiguration = configurationAdmin.getConfiguration(configId, null); org.osgi.service.cm.Configuration serviceConfiguration = configurationAdmin.getConfiguration(configId, null);
if (serviceConfiguration == null) {
return null;
}
Configuration oldConfiguration = toConfiguration(serviceConfiguration.getProperties()); Configuration oldConfiguration = toConfiguration(serviceConfiguration.getProperties());
serviceConfiguration.delete(); serviceConfiguration.delete();
return oldConfiguration; return oldConfiguration;
@@ -140,8 +140,9 @@ public class ChannelTypeResource implements RESTResource {
@Path("/{channelTypeUID}") @Path("/{channelTypeUID}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getChannelTypeByUID", summary = "Gets channel type by UID.", responses = { @Operation(operationId = "getChannelTypeByUID", summary = "Gets channel type by UID.", responses = {
@ApiResponse(responseCode = "200", description = "Channel type with provided channelTypeUID does not exist.", content = @Content(schema = @Schema(implementation = ChannelTypeDTO.class))), @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ChannelTypeDTO.class))),
@ApiResponse(responseCode = "404", description = "No content") }) @ApiResponse(responseCode = "400", description = "Bad request"),
@ApiResponse(responseCode = "404", description = "Channel type with provided channelTypeUID does not exist.") })
public Response getByUID( public Response getByUID(
@PathParam("channelTypeUID") @Parameter(description = "channelTypeUID") String channelTypeUID, @PathParam("channelTypeUID") @Parameter(description = "channelTypeUID") String channelTypeUID,
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) { @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) {
@@ -150,7 +151,7 @@ public class ChannelTypeResource implements RESTResource {
if (channelType != null) { if (channelType != null) {
return Response.ok(convertToChannelTypeDTO(channelType, locale)).build(); return Response.ok(convertToChannelTypeDTO(channelType, locale)).build();
} else { } else {
return Response.noContent().build(); return Response.status(Status.NOT_FOUND).build();
} }
} }
@@ -150,7 +150,7 @@ public class ConfigurableServiceResource implements RESTResource {
if (configurableService != null) { if (configurableService != null) {
return Response.ok(configurableService).build(); return Response.ok(configurableService).build();
} else { } else {
return Response.status(404).build(); return Response.status(Status.NOT_FOUND).build();
} }
} }
@@ -275,8 +275,7 @@ public class ConfigurableServiceResource implements RESTResource {
public Response deleteConfiguration( public Response deleteConfiguration(
@PathParam("serviceId") @Parameter(description = "service ID") String serviceId) { @PathParam("serviceId") @Parameter(description = "service ID") String serviceId) {
try { try {
Configuration oldConfiguration = configurationService.get(serviceId); Configuration oldConfiguration = configurationService.delete(serviceId);
configurationService.delete(serviceId);
return oldConfiguration != null ? Response.ok(oldConfiguration).build() : Response.noContent().build(); return oldConfiguration != null ? Response.ok(oldConfiguration).build() : Response.noContent().build();
} catch (IOException ex) { } catch (IOException ex) {
logger.error("Cannot delete configuration for service {}: {}", serviceId, ex.getMessage(), ex); logger.error("Cannot delete configuration for service {}: {}", serviceId, ex.getMessage(), ex);
@@ -28,6 +28,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@@ -151,8 +152,8 @@ public class ThingTypeResource implements RESTResource {
@Path("/{thingTypeUID}") @Path("/{thingTypeUID}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getThingTypeById", summary = "Gets thing type by UID.", responses = { @Operation(operationId = "getThingTypeById", summary = "Gets thing type by UID.", responses = {
@ApiResponse(responseCode = "200", description = "Thing type with provided thingTypeUID does not exist.", content = @Content(schema = @Schema(implementation = ThingTypeDTO.class))), @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ThingTypeDTO.class))),
@ApiResponse(responseCode = "404", description = "No content") }) @ApiResponse(responseCode = "404", description = "Thing type not found.") })
public Response getByUID(@PathParam("thingTypeUID") @Parameter(description = "thingTypeUID") String thingTypeUID, public Response getByUID(@PathParam("thingTypeUID") @Parameter(description = "thingTypeUID") String thingTypeUID,
@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) { @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) {
Locale locale = localeService.getLocale(language); Locale locale = localeService.getLocale(language);
@@ -160,7 +161,7 @@ public class ThingTypeResource implements RESTResource {
if (thingType != null) { if (thingType != null) {
return Response.ok(convertToThingTypeDTO(thingType, locale)).build(); return Response.ok(convertToThingTypeDTO(thingType, locale)).build();
} else { } else {
return Response.noContent().build(); return Response.status(Status.NOT_FOUND).build();
} }
} }