use of javax.ws.rs.ApplicationPath in project japid42 by branaway.
the class JaxrsRouter method init.
public static void init(Application app, play.GlobalSettings g) {
parentClassloader = app.classloader();
classes = RouterUtils.classes(parentClassloader);
global = g;
ApplicationPath appPathAnno = global.getClass().getAnnotation(ApplicationPath.class);
if (appPathAnno != null)
appPath = appPathAnno.value();
routerClasses = parseRouterClasses(classes);
String string = app.configuration().getString(ASSET_SERVING);
if (string != null)
assetServing = string.split(",");
}
use of javax.ws.rs.ApplicationPath in project cxf by apache.
the class OpenApiCustomizer method customize.
public OpenAPIConfiguration customize(final OpenAPIConfiguration configuration) {
if (configuration == null) {
return configuration;
}
if (dynamicBasePath) {
final MessageContext ctx = createMessageContext();
// If the JAX-RS application with custom path is defined, it might be present twice, in the
// request URI as well as in each resource operation URI. To properly represent server URL,
// the application path should be removed from it.
final String url = StringUtils.removeEnd(StringUtils.substringBeforeLast(ctx.getUriInfo().getRequestUri().toString(), "/"), applicationPath);
final Collection<Server> servers = configuration.getOpenAPI().getServers();
if (servers == null || servers.stream().noneMatch(s -> s.getUrl().equalsIgnoreCase(url))) {
configuration.getOpenAPI().setServers(Collections.singletonList(new Server().url(url)));
}
}
return configuration;
}
use of javax.ws.rs.ApplicationPath in project cxf by apache.
the class ResourceUtils method createApplication.
@SuppressWarnings("unchecked")
public static JAXRSServerFactoryBean createApplication(Application app, boolean ignoreAppPath, boolean staticSubresourceResolution, boolean useSingletonResourceProvider, Bus bus) {
Set<Object> singletons = app.getSingletons();
verifySingletons(singletons);
List<Class<?>> resourceClasses = new ArrayList<>();
List<Object> providers = new ArrayList<>();
List<Feature> features = new ArrayList<>();
Map<Class<?>, ResourceProvider> map = new HashMap<>();
// or singleton provider classes
for (Class<?> cls : app.getClasses()) {
if (isValidApplicationClass(cls, singletons)) {
if (isValidProvider(cls)) {
providers.add(createProviderInstance(cls));
} else if (Feature.class.isAssignableFrom(cls)) {
features.add(createFeatureInstance((Class<? extends Feature>) cls));
} else {
resourceClasses.add(cls);
if (useSingletonResourceProvider) {
map.put(cls, new SingletonResourceProvider(createProviderInstance(cls)));
} else {
map.put(cls, new PerRequestResourceProvider(cls));
}
}
}
}
// we can get either a provider or resource class here
for (Object o : singletons) {
if (isValidProvider(o.getClass())) {
providers.add(o);
} else if (o instanceof Feature) {
features.add((Feature) o);
} else {
resourceClasses.add(o.getClass());
map.put(o.getClass(), new SingletonResourceProvider(o));
}
}
JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
if (bus != null) {
bean.setBus(bus);
}
String address = "/";
if (!ignoreAppPath) {
ApplicationPath appPath = locateApplicationPath(app.getClass());
if (appPath != null) {
address = appPath.value();
}
}
if (!address.startsWith("/")) {
address = "/" + address;
}
bean.setAddress(address);
bean.setStaticSubresourceResolution(staticSubresourceResolution);
bean.setResourceClasses(resourceClasses);
bean.setProviders(providers);
bean.getFeatures().addAll(features);
for (Map.Entry<Class<?>, ResourceProvider> entry : map.entrySet()) {
bean.setResourceProvider(entry.getKey(), entry.getValue());
}
Map<String, Object> appProps = app.getProperties();
if (appProps != null) {
bean.getProperties(true).putAll(appProps);
}
bean.setApplication(app);
return bean;
}
use of javax.ws.rs.ApplicationPath in project cxf by apache.
the class OpenApiCustomizer method setApplicationInfo.
public void setApplicationInfo(ApplicationInfo application) {
if (application != null && application.getProvider() != null) {
final Class<?> clazz = application.getProvider().getClass();
final ApplicationPath path = ResourceUtils.locateApplicationPath(clazz);
if (path != null) {
applicationPath = path.value();
if (!applicationPath.startsWith("/")) {
applicationPath = "/" + applicationPath;
}
if (applicationPath.endsWith("/")) {
applicationPath = applicationPath.substring(0, applicationPath.lastIndexOf('/'));
}
}
}
}
use of javax.ws.rs.ApplicationPath in project cxf by apache.
the class JaxrsServletContainerInitializer method onStartup.
@Override
public void onStartup(final Set<Class<?>> classes, final ServletContext ctx) throws ServletException {
Application app = null;
String servletName = null;
String servletMapping = null;
final Class<?> appClass = findCandidate(classes);
if (appClass != null) {
// Custom servlets using non-standard mechanisms to create Application will not be detected
if (isApplicationServletAvailable(ctx, appClass)) {
return;
}
try {
app = (Application) appClass.newInstance();
} catch (Throwable t) {
throw new ServletException(t);
}
// Servlet name is the application class name
servletName = appClass.getName();
ApplicationPath appPath = ResourceUtils.locateApplicationPath(appClass);
// a servlet registration with an application implementation class name
if (appPath != null) {
servletMapping = appPath.value() + "/*";
} else {
servletMapping = getServletMapping(ctx, servletName);
}
}
// resource and provider classes
if (app == null || (app.getClasses().isEmpty() && app.getSingletons().isEmpty())) {
// Custom servlets using non-standard mechanisms to create Application will not be detected
if (isCxfServletAvailable(ctx)) {
return;
}
final Map<Class<? extends Annotation>, Collection<Class<?>>> providersAndResources = groupByAnnotations(classes);
if (!providersAndResources.get(Path.class).isEmpty() || !providersAndResources.get(Provider.class).isEmpty()) {
if (app == null) {
// Servlet name is a JAX-RS Application class name
servletName = JAXRS_APPLICATION_SERVLET_NAME;
// Servlet mapping is obtained from a servlet registration
// with a JAX-RS Application class name
servletMapping = getServletMapping(ctx, servletName);
}
final Map<String, Object> appProperties = app != null ? app.getProperties() : Collections.emptyMap();
app = new Application() {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> set = new HashSet<>();
set.addAll(providersAndResources.get(Path.class));
set.addAll(providersAndResources.get(Provider.class));
return set;
}
@Override
public Map<String, Object> getProperties() {
return appProperties;
}
};
}
}
if (app == null) {
return;
}
CXFNonSpringJaxrsServlet cxfServlet = new CXFNonSpringJaxrsServlet(app);
final Dynamic servlet = ctx.addServlet(servletName, cxfServlet);
servlet.addMapping(servletMapping);
}
Aggregations