From: msunal Date: Mon, 25 Nov 2013 12:14:57 +0000 (+0100) Subject: Bug 164 X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~346^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=312e38ea16a563e630b59f12c8459bce8b743eb5;hp=d753f1a9338baeb3aee2d745ddf7541c4be33530 Bug 164 - if URI has bad format then error status 400 is returned - corrected xtend conventions: triple equals for null Change-Id: Idfa58e21942506b7483ca6ecf19aedfd1c1de827 Signed-off-by: Martin Sunal --- diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend index f5b9132532..eb1f6165ca 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend @@ -22,7 +22,7 @@ class BrokerFacade implements DataReader { private DataBrokerService dataService; private new() { - if (INSTANCE != null) { + if (INSTANCE !== null) { throw new IllegalStateException("Already instantiated"); } } @@ -32,7 +32,7 @@ class BrokerFacade implements DataReader { } private def void checkPreconditions() { - if (context == null || dataService == null) { + if (context === null || dataService === null) { throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE) .entity(RestconfProvider::NOT_INITALIZED_MSG).build()) } diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend index c1ee611e07..c2b0ae8bdb 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend @@ -46,7 +46,7 @@ class ControllerContext implements SchemaServiceListener { private new() { - if (INSTANCE != null) { + if (INSTANCE !== null) { throw new IllegalStateException("Already instantiated"); } } @@ -56,7 +56,7 @@ class ControllerContext implements SchemaServiceListener { } private def void checkPreconditions() { - if (schemas == null) { + if (schemas === null) { throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE) .entity(RestconfProvider::NOT_INITALIZED_MSG).build()) } @@ -72,7 +72,7 @@ class ControllerContext implements SchemaServiceListener { pathArgs.remove(0) } val schemaNode = ret.collectPathArguments(pathArgs, restconfInstance.findModule); - if (schemaNode == null) { + if (schemaNode === null) { return null } new InstanceIdWithSchemaNode(ret.toInstance, schemaNode) @@ -92,7 +92,7 @@ class ControllerContext implements SchemaServiceListener { private def getLatestModule(SchemaContext schema, String moduleName) { checkNotNull(schema) - checkArgument(moduleName != null && !moduleName.empty) + checkArgument(moduleName !== null && !moduleName.empty) val modules = schema.modules.filter[m|m.name == moduleName] var latestModule = modules.head for (module : modules) { @@ -134,9 +134,9 @@ class ControllerContext implements SchemaServiceListener { def CharSequence toRestconfIdentifier(QName qname) { checkPreconditions var module = uriToModuleName.get(qname.namespace) - if (module == null) { + if (module === null) { val moduleSchema = schemas.findModuleByNamespaceAndRevision(qname.namespace, qname.revision); - if(moduleSchema == null) throw new IllegalArgumentException() + if(moduleSchema === null) throw new IllegalArgumentException() uriToModuleName.put(qname.namespace, moduleSchema.name) module = moduleSchema.name; } @@ -189,7 +189,7 @@ class ControllerContext implements SchemaServiceListener { } private def toUriString(Object object) { - if(object == null) return ""; + if(object === null) return ""; return URLEncoder.encode(object.toString) } @@ -203,14 +203,14 @@ class ControllerContext implements SchemaServiceListener { val nodeName = nodeRef.toNodeName(); val targetNode = parentNode.getDataChildByName(nodeName); - if (targetNode == null) { + if (targetNode === null) { val children = parentNode.childNodes for (child : children) { if (child instanceof ChoiceNode) { val choice = child as ChoiceNode for (caze : choice.cases) { val result = builder.collectPathArguments(strings, caze as DataNodeContainer); - if (result != null) + if (result !== null) return result } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend index d9ac53589f..a4587fa787 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.xtend @@ -7,6 +7,7 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode import org.opendaylight.yangtools.yang.model.api.DataNodeContainer import org.opendaylight.yangtools.yang.model.api.DataSchemaNode import org.opendaylight.controller.md.sal.common.api.TransactionStatus +import javax.ws.rs.WebApplicationException class RestconfImpl implements RestconfService { @@ -19,7 +20,7 @@ class RestconfImpl implements RestconfService { extension ControllerContext controllerContext private new() { - if (INSTANCE != null) { + if (INSTANCE !== null) { throw new IllegalStateException("Already instantiated"); } } @@ -42,13 +43,13 @@ class RestconfImpl implements RestconfService { } override readData(String identifier) { - val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier + val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier); return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode) } override createConfigurationData(String identifier, CompositeNode payload) { - val identifierWithSchemaNode = identifier.toInstanceIdentifier + val identifierWithSchemaNode = identifier.resolveInstanceIdentifier val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode) val status = broker.commitConfigurationDataPut(identifierWithSchemaNode.instanceIdentifier,value).get(); switch status.result { @@ -58,7 +59,7 @@ class RestconfImpl implements RestconfService { } override updateConfigurationData(String identifier, CompositeNode payload) { - val identifierWithSchemaNode = identifier.toInstanceIdentifier + val identifierWithSchemaNode = identifier.resolveInstanceIdentifier val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode) val status = broker.commitConfigurationDataPut(identifierWithSchemaNode.instanceIdentifier,value).get(); switch status.result { @@ -76,13 +77,13 @@ class RestconfImpl implements RestconfService { } override readConfigurationData(String identifier) { - val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier + val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier); return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode) } override readOperationalData(String identifier) { - val instanceIdentifierWithSchemaNode = identifier.toInstanceIdentifier + val instanceIdentifierWithSchemaNode = identifier.resolveInstanceIdentifier val data = broker.readOperationalData(instanceIdentifierWithSchemaNode.getInstanceIdentifier); return new StructuredData(data, instanceIdentifierWithSchemaNode.schemaNode) } @@ -96,7 +97,7 @@ class RestconfImpl implements RestconfService { } override createOperationalData(String identifier, CompositeNode payload) { - val identifierWithSchemaNode = identifier.toInstanceIdentifier + val identifierWithSchemaNode = identifier.resolveInstanceIdentifier val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode) val status = broker.commitOperationalDataPut(identifierWithSchemaNode.instanceIdentifier,value).get(); switch status.result { @@ -106,7 +107,7 @@ class RestconfImpl implements RestconfService { } override updateOperationalData(String identifier, CompositeNode payload) { - val identifierWithSchemaNode = identifier.toInstanceIdentifier + val identifierWithSchemaNode = identifier.resolveInstanceIdentifier val value = resolveNodeNamespaceBySchema(payload, identifierWithSchemaNode.schemaNode) val status = broker.commitOperationalDataPut(identifierWithSchemaNode.instanceIdentifier,value).get(); switch status.result { @@ -115,6 +116,15 @@ class RestconfImpl implements RestconfService { } } + private def InstanceIdWithSchemaNode resolveInstanceIdentifier(String identifier) { + val identifierWithSchemaNode = identifier.toInstanceIdentifier + if (identifierWithSchemaNode === null) { + throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("URI has bad format") + .build()); + } + return identifierWithSchemaNode + } + private def CompositeNode resolveNodeNamespaceBySchema(CompositeNode node, DataSchemaNode schema) { if (node instanceof CompositeNodeWrapper) { addNamespaceToNodeFromSchemaRecursively(node as CompositeNodeWrapper, schema) @@ -124,7 +134,7 @@ class RestconfImpl implements RestconfService { } private def void addNamespaceToNodeFromSchemaRecursively(NodeWrapper nodeBuilder, DataSchemaNode schema) { - if (nodeBuilder.namespace == null) { + if (nodeBuilder.namespace === null) { nodeBuilder.namespace = schema.QName.namespace } if (nodeBuilder instanceof CompositeNodeWrapper) { diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlProvidersTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlProvidersTest.java index 7b63c5fd94..015dfc8ad9 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlProvidersTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlProvidersTest.java @@ -106,6 +106,16 @@ public class XmlProvidersTest extends JerseyTest { assertEquals(404, response.getStatus()); } + @Test + public void testXmlToCompositeNode400() throws UnsupportedEncodingException, URISyntaxException { + String uri = createUri("/datastore/", "simple-nodes:user/name"); + + when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(null); + + Response response = target(uri).request(MediaTypes.API+RestconfService.XML).get(); + assertEquals(400, response.getStatus()); + } + @Test public void testRpcResultCommitedToStatusCodes() throws UnsupportedEncodingException { InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml");