Move SchemaExportContext
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / RootResourceDiscoveryServiceImpl.java
1 /*
2  * Copyright (c) 2020 ZTE Corp. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import javax.ws.rs.Path;
13 import javax.ws.rs.core.Response;
14 import javax.ws.rs.core.Response.Status;
15 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RootResourceDiscoveryService;
16
17 @Path("/")
18 public final class RootResourceDiscoveryServiceImpl implements RootResourceDiscoveryService {
19     private final String restconfRoot;
20
21     public RootResourceDiscoveryServiceImpl(final String restconfRoot) {
22         this.restconfRoot = requireNonNull(restconfRoot);
23     }
24
25     @Override
26     public Response readXrdData() {
27         return Response.status(Status.OK)
28             .entity("<?xml version='1.0' encoding='UTF-8'?>\n"
29                 + "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"
30                 + "     <Link rel='restconf' href='/" + restconfRoot + "'/>\n"
31                 + "</XRD>")
32             .build();
33     }
34
35     @Override
36     public Response readJsonData() {
37         return Response.status(Status.OK)
38             .entity("{\n"
39                 + " \"links\" :\n"
40                 + " {\n"
41                 + "     \"rel\" : \"restconf\",\n"
42                 + "     \"href\" : \"/" + restconfRoot + "\"\n"
43                 + " }\n"
44                 + "}")
45             .build();
46     }
47 }
48