import org.opendaylight.restconf.server.api.OperationsPostResult;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer.DataPath;
+import org.opendaylight.restconf.server.spi.ApiPathNormalizer.InstanceReference;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer.OperationPath;
import org.opendaylight.restconf.server.spi.ApiPathNormalizer.OperationPath.Rpc;
import org.opendaylight.restconf.server.spi.OperationInput;
public @NonNull RestconfFuture<DataPutResult> dataPUT(final ApiPath apiPath, final ResourceBody body,
final Map<String, String> queryParameters) {
- final var path = pathNormalizer.normalizeDataPath(apiPath);
+ final DataPath path;
+ try {
+ path = pathNormalizer.normalizeDataPath(apiPath);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
final Insert insert;
try {
public final @NonNull RestconfFuture<NormalizedNodePayload> dataGET(final ApiPath apiPath,
final DataGetParams params) {
- return dataGET(pathNormalizer.normalizeDataPath(apiPath), params);
+ final DataPath path;
+ try {
+ path = pathNormalizer.normalizeDataPath(apiPath);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
+ return dataGET(path, params);
}
abstract @NonNull RestconfFuture<NormalizedNodePayload> dataGET(DataPath path, DataGetParams params);
if (apiPath.steps().isEmpty()) {
return dataCreatePOST(body.toResource(), queryParameters);
}
- final var path = pathNormalizer.normalizeDataOrActionPath(apiPath);
+ final InstanceReference path;
+ try {
+ path = pathNormalizer.normalizeDataOrActionPath(apiPath);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
if (path instanceof DataPath dataPath) {
try (var resourceBody = body.toResource()) {
return dataCreatePOST(new DataPostPath(databind, dataPath.inference(), dataPath.instance()),
import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
+import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy.StrategyAndPath;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy.StrategyAndTail;
import org.opendaylight.restconf.server.api.DataGetParams;
import org.opendaylight.restconf.server.api.DataPatchPath;
@Override
public RestconfFuture<Empty> dataDELETE(final ApiPath identifier) {
- final var stratAndPath = localStrategy().resolveStrategyPath(identifier);
+ final StrategyAndPath stratAndPath;
+ try {
+ stratAndPath = localStrategy().resolveStrategyPath(identifier);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
return stratAndPath.strategy().delete(stratAndPath.path().instance());
}
@Override
public RestconfFuture<NormalizedNodePayload> dataGET(final ApiPath identifier, final DataGetParams params) {
- final var stratAndTail = localStrategy().resolveStrategy(identifier);
+ final StrategyAndTail stratAndTail;
+ try {
+ stratAndTail = localStrategy().resolveStrategy(identifier);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
return stratAndTail.strategy().dataGET(stratAndTail.tail(), params);
}
@Override
public RestconfFuture<Empty> dataPATCH(final ApiPath identifier, final ResourceBody body) {
- final var strategyAndPath = localStrategy().resolveStrategyPath(identifier);
+ final StrategyAndPath strategyAndPath;
+ try {
+ strategyAndPath = localStrategy().resolveStrategyPath(identifier);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
final var strategy = strategyAndPath.strategy();
final var path = strategyAndPath.path();
return dataPATCH(strategy, new DataPutPath(strategy.databind(), path.inference(), path.instance()), body);
@Override
public RestconfFuture<PatchStatusContext> dataPATCH(final ApiPath identifier, final PatchBody body) {
- final var stratAndPath = localStrategy().resolveStrategyPath(identifier);
+ final StrategyAndPath stratAndPath;
+ try {
+ stratAndPath = localStrategy().resolveStrategyPath(identifier);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
final var strategy = stratAndPath.strategy();
return dataPATCH(strategy, new DataPatchPath(strategy.databind(), stratAndPath.path().instance()), body);
}
@Override
public RestconfFuture<? extends DataPostResult> dataPOST(final ApiPath identifier, final DataPostBody body,
final Map<String, String> queryParameters) {
- final var strategyAndTail = localStrategy().resolveStrategy(identifier);
+ final StrategyAndTail strategyAndTail;
+ try {
+ strategyAndTail = localStrategy().resolveStrategy(identifier);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
return strategyAndTail.strategy().dataPOST(strategyAndTail.tail(), body, queryParameters);
}
@Override
public RestconfFuture<DataPutResult> dataPUT(final ApiPath identifier, final ResourceBody body,
final Map<String, String> queryParameters) {
- final var strategyAndTail = localStrategy().resolveStrategy(identifier);
+ final StrategyAndTail strategyAndTail;
+ try {
+ strategyAndTail = localStrategy().resolveStrategy(identifier);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
return strategyAndTail.strategy().dataPUT(strategyAndTail.tail(), body, queryParameters);
}
@Override
public RestconfFuture<OperationsGetResult> operationsGET(final ApiPath operation) {
- final var strategyAndTail = localStrategy().resolveStrategy(operation);
+ final StrategyAndTail strategyAndTail;
+ try {
+ strategyAndTail = localStrategy().resolveStrategy(operation);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
return strategyAndTail.strategy().operationsGET(strategyAndTail.tail());
}
@Override
public RestconfFuture<OperationsPostResult> operationsPOST(final URI restconfURI, final ApiPath apiPath,
final OperationInputBody body) {
- final var strategyAndTail = localStrategy().resolveStrategy(apiPath);
+ final StrategyAndTail strategyAndTail;
+ try {
+ strategyAndTail = localStrategy().resolveStrategy(apiPath);
+ } catch (RestconfDocumentedException e) {
+ return RestconfFuture.failed(e);
+ }
final var strategy = strategyAndTail.strategy();
return strategy.operationsPOST(restconfURI, strategyAndTail.tail(), body);
}
final var description = new StringBuilder("YANG notifications matching any of {");
var haveFirst = false;
for (var qname : qnames) {
- final var module = modelContext.findModuleStatement(qname.getModule())
- .orElseThrow(() -> new RestconfDocumentedException(qname + " refers to an unknown module",
+ final var optModule = modelContext.findModuleStatement(qname.getModule());
+ if (optModule.isEmpty()) {
+ return RestconfFuture.failed(new RestconfDocumentedException(qname + " refers to an unknown module",
ErrorType.APPLICATION, ErrorTag.INVALID_VALUE));
- final var stmt = module.findSchemaTreeNode(qname)
- .orElseThrow(() -> new RestconfDocumentedException(qname + " refers to an unknown notification",
+ }
+ final var module = optModule.orElseThrow();
+ final var optStmt = module.findSchemaTreeNode(qname);
+ if (optStmt.isEmpty()) {
+ return RestconfFuture.failed(new RestconfDocumentedException(
+ qname + " refers to an unknown notification", ErrorType.APPLICATION, ErrorTag.INVALID_VALUE));
+ }
+ if (!(optStmt.orElseThrow() instanceof NotificationEffectiveStatement)) {
+ return RestconfFuture.failed(new RestconfDocumentedException(qname + " refers to a non-notification",
ErrorType.APPLICATION, ErrorTag.INVALID_VALUE));
- if (!(stmt instanceof NotificationEffectiveStatement)) {
- throw new RestconfDocumentedException(qname + " refers to a non-notification",
- ErrorType.APPLICATION, ErrorTag.INVALID_VALUE);
}
if (haveFirst) {