X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Frestconf%2Fimpl%2FJSONRestconfServiceImpl.java;h=f6359a68b85c5014cf41aa0dde5bd6e789af366a;hb=17d4a56409775e872c9d55371e633472d621fe7d;hp=77c6dc99c641023f5e37bb29921e959163b64655;hpb=0b0cb96c38914b815bb7386ddfd721fc32cb8514;p=netconf.git diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java index 77c6dc99c6..f6359a68b8 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java @@ -14,9 +14,15 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.annotation.Annotation; +import java.net.URI; import java.nio.charset.StandardCharsets; +import java.util.Collections; import java.util.List; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.PathSegment; +import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader; @@ -42,7 +48,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab @SuppressWarnings("checkstyle:IllegalCatch") @Override - public void put(final String uriPath, final String payload, final UriInfo uriInfo) throws OperationFailedException { + public void put(final String uriPath, final String payload) throws OperationFailedException { Preconditions.checkNotNull(payload, "payload can't be null"); LOG.debug("put: uriPath: {}, payload: {}", uriPath, payload); @@ -54,7 +60,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab LOG.debug("Parsed NormalizedNode: {}", context.getData()); try { - RestconfImpl.getInstance().updateConfigurationData(uriPath, context, uriInfo); + RestconfImpl.getInstance().updateConfigurationData(uriPath, context, new SimpleUriInfo(uriPath)); } catch (final Exception e) { propagateExceptionAs(uriPath, e, "PUT"); } @@ -62,7 +68,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab @SuppressWarnings("checkstyle:IllegalCatch") @Override - public void post(final String uriPath, final String payload, final UriInfo uriInfo) + public void post(final String uriPath, final String payload) throws OperationFailedException { Preconditions.checkNotNull(payload, "payload can't be null"); @@ -75,7 +81,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab LOG.debug("Parsed NormalizedNode: {}", context.getData()); try { - RestconfImpl.getInstance().createConfigurationData(uriPath, context, uriInfo); + RestconfImpl.getInstance().createConfigurationData(uriPath, context, new SimpleUriInfo(uriPath)); } catch (final Exception e) { propagateExceptionAs(uriPath, e, "POST"); } @@ -95,12 +101,13 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab @SuppressWarnings("checkstyle:IllegalCatch") @Override - public Optional get(final String uriPath, final LogicalDatastoreType datastoreType, final UriInfo uriInfo) + public Optional get(final String uriPath, final LogicalDatastoreType datastoreType) throws OperationFailedException { LOG.debug("get: uriPath: {}", uriPath); try { NormalizedNodeContext readData; + final SimpleUriInfo uriInfo = new SimpleUriInfo(uriPath); if (datastoreType == LogicalDatastoreType.CONFIGURATION) { readData = RestconfImpl.getInstance().readConfigurationData(uriPath, uriInfo); } else { @@ -225,4 +232,113 @@ public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseab } } } + + private static class SimpleUriInfo implements UriInfo { + private final String path; + private final MultivaluedMap queryParams; + + SimpleUriInfo(String path) { + this(path, new MultivaluedHashMap<>()); + } + + SimpleUriInfo(String path, MultivaluedMap queryParams) { + this.path = path; + this.queryParams = queryParams; + } + + @Override + public String getPath() { + return path; + } + + @Override + public String getPath(boolean decode) { + return path; + } + + @Override + public List getPathSegments() { + throw new UnsupportedOperationException(); + } + + @Override + public List getPathSegments(boolean decode) { + throw new UnsupportedOperationException(); + } + + @Override + public URI getRequestUri() { + return URI.create(path); + } + + @Override + public UriBuilder getRequestUriBuilder() { + return UriBuilder.fromUri(getRequestUri()); + } + + @Override + public URI getAbsolutePath() { + return getRequestUri(); + } + + @Override + public UriBuilder getAbsolutePathBuilder() { + return UriBuilder.fromUri(getAbsolutePath()); + } + + @Override + public URI getBaseUri() { + return URI.create(""); + } + + @Override + public UriBuilder getBaseUriBuilder() { + return UriBuilder.fromUri(getBaseUri()); + } + + @Override + public MultivaluedMap getPathParameters() { + return new MultivaluedHashMap<>(); + } + + @Override + public MultivaluedMap getPathParameters(boolean decode) { + return getPathParameters(); + } + + @Override + public MultivaluedMap getQueryParameters() { + return queryParams; + } + + @Override + public MultivaluedMap getQueryParameters(boolean decode) { + return getQueryParameters(); + } + + @Override + public List getMatchedURIs() { + return Collections.emptyList(); + } + + @Override + public List getMatchedURIs(boolean decode) { + return getMatchedURIs(); + } + + @Override + public List getMatchedResources() { + return Collections.emptyList(); + } + + @Override + public URI resolve(URI uri) { + return uri; + } + + @Override + public URI relativize(URI uri) { + return uri; + } + } }