All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.restconf.nb.jaxrs.JaxRsWebHostMetadata Maven / Gradle / Ivy

/*
 * 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.jaxrs;

import static java.util.Objects.requireNonNull;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.opendaylight.restconf.api.MediaTypes;

/**
 * Controller for determining the {@code Root Resource} of the RESTCONF API. This interface serves up a
 * {@code host-meta} document as defined in
 * RFC6415 The host-meta Document.
 */
// FIXME: this really should be the endpoint's job to aggregate these. Once JAX-RS (or any other wiring) can provide it,
//        integrate with that framework, so we co-exist with others.
@Path("/")
public final class JaxRsWebHostMetadata {
    private final String restconfRoot;

    public JaxRsWebHostMetadata(final String restconfRoot) {
        this.restconfRoot = requireNonNull(restconfRoot);
    }

    /**
     * Root Resource Discovery as an XRD.
     *
     * @see RFC8040, section 3.1
     */
    @GET
    @Path("/host-meta")
    @Produces(MediaTypes.APPLICATION_XRD_XML)
    public Response readXrdData() {
        return Response.status(Status.OK)
            .entity("\n"
                + "\n"
                + "  \n"
                + "")
            .build();
    }

    /**
     * Root Resource Discovery as a JRD.
     *
     *  @see RFC6415, appendix A
     */
    @GET
    @Path("/host-meta.json")
    @Produces(MediaType.APPLICATION_JSON)
    public Response readJsonData() {
        return Response.status(Status.OK)
            .entity("{\n"
                + "  \"links\" : {\n"
                + "    \"rel\" : \"restconf\",\n"
                + "    \"href\" : \"/" + restconfRoot + "\"\n"
                + "  }\n"
                + "}")
            .build();
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy