From 4aac232d4c70207a15013088bf056565262f1da8 Mon Sep 17 00:00:00 2001 From: Jakub Morvay Date: Fri, 8 Feb 2019 19:14:42 +0100 Subject: [PATCH] Get rid of string payload RestconfService#invokeRpc This method was deprecated a while ago and should not be used and provided. invokeRpc method with NormalizedNodeContext payload is enough and should be used on all occasions. Change-Id: I3098861d6fd9c4923d8b5fd291344865b977d8a2 Signed-off-by: Jakub Morvay --- .../netconf/sal/rest/api/RestconfService.java | 19 --------------- .../rest/impl/RestconfCompositeWrapper.java | 6 ----- .../impl/JSONRestconfServiceImpl.java | 2 +- .../sal/restconf/impl/RestconfImpl.java | 13 ++++------- .../StatisticsRestconfServiceWrapper.java | 6 ----- .../impl/test/InvokeRpcMethodTest.java | 23 +++++-------------- 6 files changed, 11 insertions(+), 58 deletions(-) diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/api/RestconfService.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/api/RestconfService.java index cb72d328c8..d110de8fdf 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/api/RestconfService.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/api/RestconfService.java @@ -9,7 +9,6 @@ package org.opendaylight.netconf.sal.rest.api; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; import javax.ws.rs.Encoded; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -169,24 +168,6 @@ public interface RestconfService { NormalizedNodeContext invokeRpc(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload, @Context UriInfo uriInfo); - /** - * Invoke RPC with default empty payload. - * - * @param identifier module name and rpc identifier string for the desired operation - * @param noPayload the body of the operation - * @param uriInfo URI info - * @return {@link NormalizedNodeContext} - * @deprecated Method is not used and will be removed - */ - @POST - @Path("/operations/{identifier:.+}") - @Produces({ Draft02.MediaTypes.OPERATION + JSON, Draft02.MediaTypes.OPERATION + XML, - Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON, - MediaType.APPLICATION_XML, MediaType.TEXT_XML }) - @Deprecated // method isn't use anywhere - NormalizedNodeContext invokeRpc(@Encoded @PathParam("identifier") String identifier, - @DefaultValue("") String noPayload, @Context UriInfo uriInfo); - /** * Get target data resource from config data store. * diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfCompositeWrapper.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfCompositeWrapper.java index 5242aeb2c8..fedae5df01 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfCompositeWrapper.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/rest/impl/RestconfCompositeWrapper.java @@ -64,12 +64,6 @@ public class RestconfCompositeWrapper implements RestconfService, SchemaRetrieva return this.restconf.invokeRpc(identifier, payload, uriInfo); } - @Override - @Deprecated - public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) { - return this.restconf.invokeRpc(identifier, noPayload, uriInfo); - } - @Override public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) { return this.restconf.readConfigurationData(identifier, uriInfo); diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java index f63bee7c04..9c64e0df29 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java @@ -178,7 +178,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService { outputContext = restconfService.invokeRpc(uriPath, inputContext, null); } else { - outputContext = restconfService.invokeRpc(uriPath, "", null); + outputContext = restconfService.invokeRpc(uriPath, null, null); } if (outputContext.getData() != null) { diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java index 60fcfff518..e6cb1c16da 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java @@ -8,7 +8,6 @@ package org.opendaylight.netconf.sal.restconf.impl; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.CharMatcher; import com.google.common.base.Preconditions; import com.google.common.base.Predicates; import com.google.common.base.Splitter; @@ -435,7 +434,7 @@ public final class RestconfImpl implements RestconfService { final UriInfo uriInfo) { if (payload == null) { // no payload specified, reroute this to no payload invokeRpc implementation - return invokeRpc(identifier, "", uriInfo); + return invokeRpc(identifier, uriInfo); } final SchemaPath type = payload.getInstanceIdentifierContext().getSchemaNode().getPath(); @@ -485,14 +484,10 @@ public final class RestconfImpl implements RestconfService { resultData, QueryParametersParser.parseWriterParameters(uriInfo)); } - @Override - public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) { - if (noPayload != null && !CharMatcher.whitespace().matchesAllOf(noPayload)) { - throw new RestconfDocumentedException("Content must be empty.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); - } + private NormalizedNodeContext invokeRpc(final String identifier, final UriInfo uriInfo) { - String identifierEncoded = null; DOMMountPoint mountPoint = null; + final String identifierEncoded; final SchemaContext schemaContext; if (identifier.contains(ControllerContext.MOUNT)) { // mounted RPC call - look up mount instance. @@ -516,7 +511,7 @@ public final class RestconfImpl implements RestconfService { final String identifierDecoded = this.controllerContext.urlPathArgDecode(identifierEncoded); - RpcDefinition rpc = null; + RpcDefinition rpc; if (mountPoint == null) { rpc = this.controllerContext.getRpcDefinition(identifierDecoded); } else { diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java index 77e4f53c17..33830d150c 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/StatisticsRestconfServiceWrapper.java @@ -93,12 +93,6 @@ public final class StatisticsRestconfServiceWrapper implements RestconfService { return this.delegate.invokeRpc(identifier, payload, uriInfo); } - @Override - public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) { - this.rpc.incrementAndGet(); - return this.delegate.invokeRpc(identifier, noPayload, uriInfo); - } - @SuppressWarnings("checkstyle:IllegalCatch") @Override public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) { diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java index dbdca84473..e9741e2a0e 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java @@ -165,7 +165,7 @@ public class InvokeRpcMethodTest { .when(brokerFacade).invokeRpc(eq(type), isNull()); try { - this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo); + this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo); fail("Expected an exception to be thrown."); } catch (final RestconfDocumentedException e) { verifyRestconfDocumentedException(e, 0, ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, @@ -209,7 +209,7 @@ public class InvokeRpcMethodTest { doReturn(immediateFluentFuture(result)).when(brokerFacade).invokeRpc(eq(path), isNull()); try { - this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo); + this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo); fail("Expected an exception to be thrown."); } catch (final RestconfDocumentedException e) { verifyRestconfDocumentedException(e, 0, ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED, Optional.of("foo"), @@ -229,28 +229,17 @@ public class InvokeRpcMethodTest { doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(eq(path), isNull()); - final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:cancel-toast", "", uriInfo); + final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo); assertNotNull(output); assertEquals(null, output.getData()); // additional validation in the fact that the restconfImpl does not // throw an exception. } - @Test - public void testInvokeRpcMethodExpectingNoPayloadButProvidePayload() { - try { - this.restconfImpl.invokeRpc("toaster:cancel-toast", " a payload ", uriInfo); - fail("Expected an exception"); - } catch (final RestconfDocumentedException e) { - verifyRestconfDocumentedException(e, 0, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, - Optional.absent(), Optional.absent()); - } - } - @Test public void testInvokeRpcMethodWithBadMethodName() { try { - this.restconfImpl.invokeRpc("toaster:bad-method", "", uriInfo); + this.restconfImpl.invokeRpc("toaster:bad-method", null, uriInfo); fail("Expected an exception"); } catch (final RestconfDocumentedException e) { verifyRestconfDocumentedException(e, 0, ErrorType.RPC, ErrorTag.UNKNOWN_ELEMENT, @@ -303,7 +292,7 @@ public class InvokeRpcMethodTest { @Test public void testThrowExceptionWhenSlashInModuleName() { try { - this.restconfImpl.invokeRpc("toaster/slash", "", uriInfo); + this.restconfImpl.invokeRpc("toaster/slash", null, uriInfo); fail("Expected an exception."); } catch (final RestconfDocumentedException e) { verifyRestconfDocumentedException(e, 0, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE, @@ -346,7 +335,7 @@ public class InvokeRpcMethodTest { doReturn(immediateFluentFuture(result)).when(brokerFacade).invokeRpc(eq(rpcDef.getPath()), isNull()); - final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:testOutput", "", uriInfo); + final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:testOutput", null, uriInfo); assertNotNull(output); assertNotNull(output.getData()); assertSame(container, output.getData()); -- 2.36.6