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

io.quarkus.resteasy.reactive.links.runtime.hal.ResteasyReactiveHalService Maven / Gradle / Ivy

Go to download

Web Links support for Quarkus REST. Inject web links into response HTTP headers by annotating your endpoint resources.

There is a newer version: 3.17.5
Show newest version
package io.quarkus.resteasy.reactive.links.runtime.hal;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Link;

import io.quarkus.hal.HalLink;
import io.quarkus.hal.HalService;
import io.quarkus.resteasy.reactive.links.RestLinksProvider;

@RequestScoped
public class ResteasyReactiveHalService extends HalService {
    private final RestLinksProvider linksProvider;

    @Inject
    public ResteasyReactiveHalService(RestLinksProvider linksProvider) {
        this.linksProvider = linksProvider;
    }

    @Override
    protected Map getClassLinks(Class entityType) {
        return linksToMap(linksProvider.getTypeLinks(entityType));
    }

    @Override
    protected Map getInstanceLinks(Object entity) {
        return linksToMap(linksProvider.getInstanceLinks(entity));
    }

    private Map linksToMap(Collection refLinks) {
        Map links = new HashMap<>();
        for (Link link : refLinks) {
            links.put(link.getRel(), new HalLink(link.getUri().toString()));
        }

        return links;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy