Skip to content

Commit

Permalink
Protect resourceAct against NPE
Browse files Browse the repository at this point in the history
Return a 404 instead of 500 if the resource doesn't exist
  • Loading branch information
tcalmant committed Aug 1, 2023
1 parent af35e18 commit 2697a91
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.eclipse.sensinact.core.notification.ClientDataListener;
import org.eclipse.sensinact.core.notification.ClientLifecycleListener;
import org.eclipse.sensinact.core.session.ResourceShortDescription;
import org.eclipse.sensinact.core.session.SensiNactSession;
import org.eclipse.sensinact.northbound.query.api.AbstractQueryDTO;
import org.eclipse.sensinact.northbound.query.api.AbstractResultDTO;
Expand All @@ -34,6 +35,7 @@
import org.eclipse.sensinact.northbound.query.dto.query.QueryListDTO;
import org.eclipse.sensinact.northbound.query.dto.query.QuerySetDTO;
import org.eclipse.sensinact.northbound.query.dto.query.WrappedAccessMethodCallParametersDTO;
import org.eclipse.sensinact.northbound.query.dto.result.ErrorResultDTO;
import org.eclipse.sensinact.northbound.rest.api.IRestNorthbound;

import jakarta.ws.rs.core.Context;
Expand Down Expand Up @@ -276,8 +278,17 @@ private Map<String, Object> extractActParams(final List<Entry<String, Class<?>>>
public AbstractResultDTO resourceAct(final String providerId, final String serviceName, final String rcName,
final WrappedAccessMethodCallParametersDTO parameters) {

final List<Entry<String, Class<?>>> actMethodArgumentsTypes = getSession().describeResourceShort(providerId,
serviceName, rcName).actMethodArgumentsTypes;
final ResourceShortDescription rcDesc = getSession().describeResourceShort(providerId, serviceName, rcName);
if (rcDesc == null) {
// Unknown resource
final ErrorResultDTO error = new ErrorResultDTO();
error.statusCode = 404;
error.error = "Resource not found";
error.uri = String.join("/", providerId, serviceName, rcName);
return error;
}

final List<Entry<String, Class<?>>> actMethodArgumentsTypes = rcDesc.actMethodArgumentsTypes;

final QueryActDTO query = new QueryActDTO();
query.uri = new SensinactPath(providerId, serviceName, rcName);
Expand Down

0 comments on commit 2697a91

Please sign in to comment.