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

nl.vpro.rs.ResteasyApplication Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
/*
 * Copyright (C) 2013 All rights reserved
 * VPRO The Netherlands
 */
package nl.vpro.rs;

import lombok.extern.slf4j.Slf4j;

import java.util.*;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;


/**
 * Static helper to expose a dummy JAX-RS Application. Swagger needs such an application to expose the API docs for
 * the given endpoints.
 * 

* Note, this used to be SwaggerApplication in vpro-shared-swagger. But it's not related to swagger. It has to do with RestEasy. * @author Roelof Jan Koekoek * @since 2.0 */ @Slf4j @ApplicationPath("") public class ResteasyApplication extends Application { private static final Set singletons = new HashSet<>(); private static final Set> classes = new HashSet<>(); private static ResteasyApplication INSTANCE; public ResteasyApplication() { INSTANCE = this; } public static ResteasyApplication getInstance() { return INSTANCE; } @Override public Set> getClasses() { return classes; } @Override public Set getSingletons() { return singletons; } /** * Inject Swagger annotated JAX-RS ap's you want to publish. Swagger only calls #getSingletons on the first * API documentation request, so you must take care that your services get injected before an application accepts * web requests. (Using @PostConstruct on your services is a viable solution) * * @param services */ public static void inject(Object... services) { List list = Arrays.asList(services); log.info("Injecting singletons {}", list); singletons.addAll(list); } public static void classes(Class... classes) { List> list = Arrays.asList(classes); log.info("Injecting classses {}", list); ResteasyApplication.classes.addAll(list); } }