2 * Copyright (c) 2020 ZTE Corp. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
10 import static java.util.Objects.requireNonNull;
12 import javax.ws.rs.GET;
13 import javax.ws.rs.Path;
14 import javax.ws.rs.Produces;
15 import javax.ws.rs.core.MediaType;
16 import javax.ws.rs.core.Response;
17 import javax.ws.rs.core.Response.Status;
18 import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
21 * Controller for determining the {@code Root Resource} of the RESTCONF API. This interface serves up a
22 * {@code host-meta} document as defined in
23 * <a href="https://tools.ietf.org/html/rfc8040#section-3">RFC6415 section 3</a>.
25 // FIXME: this really should be the endpoint's job to aggregate these. Once JAX-RS (or any other wiring) can provide it,
26 // integrate with that framework, so we co-exist with others.
28 public final class RootResourceDiscoveryServiceImpl {
29 private final String restconfRoot;
31 public RootResourceDiscoveryServiceImpl(final String restconfRoot) {
32 this.restconfRoot = requireNonNull(restconfRoot);
36 * Root Resource Discovery as an XRD.
38 * @see <a href="https://tools.ietf.org/html/rfc8040#section-3.1">RFC8040, section 3.1</a>
42 @Produces(MediaTypes.APPLICATION_XRD_XML)
43 public Response readXrdData() {
44 return Response.status(Status.OK)
45 .entity("<?xml version='1.0' encoding='UTF-8'?>\n"
46 + "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"
47 + " <Link rel='restconf' href='/" + restconfRoot + "'/>\n"
53 * Root Resource Discovery as a JRD.
55 * @see <a href="https://tools.ietf.org/html/rfc6415#appendix-A">RFC6415, appendix A</a>
58 @Path("/host-meta.json")
59 @Produces(MediaType.APPLICATION_JSON)
60 public Response readJsonData() {
61 return Response.status(Status.OK)
64 + " \"rel\" : \"restconf\",\n"
65 + " \"href\" : \"/" + restconfRoot + "\"\n"