Clean up Root Resource Discovery implementation 90/96190/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 14 May 2021 18:05:04 +0000 (20:05 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 14 May 2021 18:07:24 +0000 (20:07 +0200)
Move the implementation to other service implementations and make sure
it has configurable root -- which should be coming from WebInitializer.

JIRA: NETCONF-773
Change-Id: I1fd8936d622c0ee51bd151a0ebd34b05dd76d2b0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RootFoundApplication.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RootResourceDiscoveryServiceImpl.java [new file with mode: 0644]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/RootResourceDiscoveryServiceImpl.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RootResourceDiscoveryServiceTest.java [new file with mode: 0644]
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/RRDSImplTest.java [deleted file]

index d0cbef01b1462dd8c41a169bd57e0f3bf50f19ee..4e484924555fbcccb6f5d13d63c235ea718b6382 100644 (file)
@@ -11,10 +11,14 @@ import java.util.Set;
 import javax.ws.rs.core.Application;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocumentedExceptionMapper;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RootResourceDiscoveryService;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.RootResourceDiscoveryServiceImpl;
+import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RootResourceDiscoveryServiceImpl;
 
 public class RootFoundApplication extends Application {
-    private final RootResourceDiscoveryService rrds = new RootResourceDiscoveryServiceImpl();
+    private final RootResourceDiscoveryService rrds;
+
+    public RootFoundApplication(final String restconfRoot) {
+        rrds = new RootResourceDiscoveryServiceImpl(restconfRoot);
+    }
 
     @Override
     public Set<Class<?>> getClasses() {
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RootResourceDiscoveryServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RootResourceDiscoveryServiceImpl.java
new file mode 100644 (file)
index 0000000..5e0e47b
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2020 ZTE Corp. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
+
+import static java.util.Objects.requireNonNull;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RootResourceDiscoveryService;
+
+@Path("/")
+public final class RootResourceDiscoveryServiceImpl implements RootResourceDiscoveryService {
+    private final String restconfRoot;
+
+    public RootResourceDiscoveryServiceImpl(final String restconfRoot) {
+        this.restconfRoot = requireNonNull(restconfRoot);
+    }
+
+    @Override
+    public Response readXrdData() {
+        return Response.status(Status.OK)
+            .entity("<?xml version='1.0' encoding='UTF-8'?>\n"
+                + "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"
+                + "     <Link rel='restconf' href='/" + restconfRoot + "'/>\n"
+                + "</XRD>")
+            .build();
+    }
+
+    @Override
+    public Response readJsonData() {
+        return Response.status(Status.OK)
+            .entity("{\n"
+                + " \"links\" :\n"
+                + " {\n"
+                + "     \"rel\" : \"restconf\",\n"
+                + "     \"href\" : \"/" + restconfRoot + "\"\n"
+                + " }\n"
+                + "}")
+            .build();
+    }
+}
+
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/RootResourceDiscoveryServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/RootResourceDiscoveryServiceImpl.java
deleted file mode 100644 (file)
index f650729..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2020 ZTE Corp. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.services.wrapper;
-
-import javax.ws.rs.Path;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RootResourceDiscoveryService;
-import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
-
-@Path("/")
-public final class RootResourceDiscoveryServiceImpl implements RootResourceDiscoveryService {
-
-    @Override
-    public Response readXrdData() {
-        return Response.status(Status.OK)
-                .entity("<?xml version='1.0' encoding='UTF-8'?>\n"
-                        + "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"
-                        + "     <Link rel='restconf' href='/" + RestconfConstants.BASE_URI_PATTERN + "'/>\n"
-                        + "</XRD>")
-                .build();
-    }
-
-    @Override
-    public Response readJsonData() {
-        return Response.status(Status.OK)
-                .entity("{\n"
-                        + " \"links\" :\n"
-                        + " {\n"
-                        + "     \"rel\" : \"restconf\",\n"
-                        + "     \"href\" : \"/" + RestconfConstants.BASE_URI_PATTERN + "/\"\n"
-                        + " }\n"
-                        + "}")
-                .build();
-    }
-}
-
index 08d9665a41cbb51226277464bbb2476fc473a336..43273eece5abdc040563bd69166be8feb6e49a10 100644 (file)
@@ -37,14 +37,14 @@ import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
  */
 @Singleton
 public class WebInitializer {
-
     private final WebContextRegistration registration;
 
     @Inject
-    public WebInitializer(@Reference WebServer webServer, @Reference WebContextSecurer webContextSecurer,
-            @Reference ServletSupport servletSupport, RestconfApplication webApp,RestconfNotifApplication webAppNotif,
-            @Reference CustomFilterAdapterConfiguration customFilterAdapterConfig,
-            WebSocketInitializer webSocketServlet) throws ServletException {
+    public WebInitializer(@Reference final WebServer webServer, @Reference final WebContextSecurer webContextSecurer,
+            @Reference final ServletSupport servletSupport, final RestconfApplication webApp,
+            final RestconfNotifApplication webAppNotif,
+            @Reference final CustomFilterAdapterConfiguration customFilterAdapterConfig,
+            final WebSocketInitializer webSocketServlet) throws ServletException {
         WebContextBuilder webContextBuilder = WebContext.builder().contextPath("/")
                 .supportsSessions(false)
                 .addServlet(ServletDetails.builder().servlet(servletSupport.createHttpServletBuilder(webApp).build())
@@ -58,7 +58,7 @@ public class WebInitializer {
                         .build())
 
                 .addServlet(ServletDetails.builder().servlet(servletSupport.createHttpServletBuilder(
-                            new RootFoundApplication()).build())
+                            new RootFoundApplication(RestconfConstants.BASE_URI_PATTERN)).build())
                         .addUrlPattern(".well-known/*").name("Rootfound").build())
 
                 // Allows user to add javax.servlet.Filter(s) in front of REST services
diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RootResourceDiscoveryServiceTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RootResourceDiscoveryServiceTest.java
new file mode 100644 (file)
index 0000000..b705292
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class RootResourceDiscoveryServiceTest {
+    @Test
+    public void testJsonData() {
+        assertEquals("{\n"
+            + " \"links\" :\n"
+            + " {\n"
+            + "     \"rel\" : \"restconf\",\n"
+            + "     \"href\" : \"/fooBarBaz\"\n"
+            + " }\n"
+            + "}", new RootResourceDiscoveryServiceImpl("fooBarBaz").readJsonData().getEntity());
+    }
+
+    @Test
+    public void testXrdData() {
+        assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n"
+            + "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"
+            + "     <Link rel='restconf' href='/fooBarBaz'/>\n"
+            + "</XRD>", new RootResourceDiscoveryServiceImpl("fooBarBaz").readXrdData().getEntity());
+    }
+}
diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/RRDSImplTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/RRDSImplTest.java
deleted file mode 100644 (file)
index d3679b3..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.services.wrapper;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class RRDSImplTest {
-    @Test
-    public void testHostMeta() {
-        assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n"
-            + "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"
-            + "     <Link rel='restconf' href='/rests'/>\n"
-            + "</XRD>", new RootResourceDiscoveryServiceImpl().readXrdData().getEntity());
-    }
-}