use of javax.ws.rs.core.Application in project com-liferay-apio-architect by liferay.
the class ApioApplicationRegistrar method activate.
@Activate
public void activate(BundleContext bundleContext) {
Application application = bundleContext.getService(_serviceReference);
Dictionary<String, Object> properties = new Hashtable<>();
String[] propertyKeys = _serviceReference.getPropertyKeys();
for (String key : propertyKeys) {
Object value = _serviceReference.getProperty(key);
properties.put(key, value);
}
properties.put("osgi.jaxrs.application.base", "/");
properties.put("osgi.jaxrs.name", ".default");
_serviceRegistration = bundleContext.registerService(Application.class, application, properties);
PersonModel.compute();
BlogPostingModel.compute();
BlogPostingCommentModel.compute();
}
use of javax.ws.rs.core.Application in project Payara by payara.
the class OpenApiContext method generateResourceMapping.
/**
* Generates a map listing the location each resource class is mapped to.
*/
private Map<String, Set<Type>> generateResourceMapping() {
Set<Type> classList = new HashSet<>();
Map<String, Set<Type>> mapping = new HashMap<>();
for (Type type : allowedTypes) {
if (type instanceof ClassModel) {
ClassModel classModel = (ClassModel) type;
if (classModel.getAnnotation(ApplicationPath.class.getName()) != null) {
// Produce the mapping
AnnotationModel annotation = classModel.getAnnotation(ApplicationPath.class.getName());
String key = annotation.getValue("value", String.class);
Set<Type> resourceClasses = new HashSet<>();
mapping.put(key, resourceClasses);
try {
Class<?> clazz = appClassLoader.loadClass(classModel.getName());
Application app = (Application) clazz.newInstance();
// Add all classes contained in the application
resourceClasses.addAll(app.getClasses().stream().map(Class::getName).filter(// Remove all Jersey providers
name -> !name.startsWith("org.glassfish.jersey")).map(allTypes::getBy).filter(Objects::nonNull).collect(toSet()));
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
LOGGER.log(WARNING, "Unable to initialise application class.", ex);
}
} else {
classList.add(classModel);
}
}
}
// If there is one application and it's empty, add all classes
if (mapping.keySet().size() == 1) {
Set<Type> classes = mapping.values().iterator().next();
if (classes.isEmpty()) {
classes.addAll(classList);
}
}
// If there is no application, add all classes to the context root.
if (mapping.isEmpty()) {
mapping.put("/", classList);
}
return mapping;
}
use of javax.ws.rs.core.Application in project tomee by apache.
the class MPJWTInitializer method onStartup.
@Override
public void onStartup(final Set<Class<?>> classes, final ServletContext ctx) throws ServletException {
if (classes == null || classes.isEmpty()) {
// no class having @LoginConfig on it
return;
}
for (Class<?> clazz : classes) {
final LoginConfig loginConfig = clazz.getAnnotation(LoginConfig.class);
if (loginConfig.authMethod() == null && !"MP-JWT".equals(loginConfig.authMethod())) {
continue;
}
if (!Application.class.isAssignableFrom(clazz)) {
continue;
// do we really want Application?
// See https://github.com/eclipse/microprofile-jwt-auth/issues/70 to clarify this point
}
final FilterRegistration.Dynamic mpJwtFilter = ctx.addFilter("mp-jwt-filter", MPJWTFilter.class);
mpJwtFilter.setAsyncSupported(true);
mpJwtFilter.addMappingForUrlPatterns(null, false, "/*");
// no need to add it more than once
break;
}
}
use of javax.ws.rs.core.Application in project tomee by apache.
the class JAXRSServerFactoryBean method injectContexts.
protected void injectContexts(ServerProviderFactory factory, ApplicationInfo fallback) {
// Sometimes the application provider (ApplicationInfo) is injected through
// the endpoint, not JAXRSServerFactoryBean (like for example OpenApiFeature
// or Swagger2Feature do). As such, without consulting the endpoint, the injection
// may not work properly.
final ApplicationInfo appInfoProvider = (appProvider == null) ? fallback : appProvider;
final Application application = appInfoProvider == null ? null : appInfoProvider.getProvider();
for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
if (cri.isSingleton()) {
InjectionUtils.injectContextProxiesAndApplication(cri, cri.getResourceProvider().getInstance(null), application, factory);
}
}
if (application != null) {
InjectionUtils.injectContextProxiesAndApplication(appInfoProvider, application, null, null);
}
}
use of javax.ws.rs.core.Application in project tomee by apache.
the class CXFNonSpringJaxrsServlet method createServerFromApplication.
protected void createServerFromApplication(String applicationNames, ServletConfig servletConfig) throws ServletException {
boolean ignoreApplicationPath = isIgnoreApplicationPath(servletConfig);
String[] classNames = applicationNames.split(getParameterSplitChar(servletConfig));
if (classNames.length > 1 && ignoreApplicationPath) {
throw new ServletException("\"" + IGNORE_APP_PATH_PARAM + "\" parameter must be set to false for multiple Applications be supported");
}
for (String cName : classNames) {
ApplicationInfo providerApp = createApplicationInfo(cName, servletConfig);
Application app = providerApp.getProvider();
JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, ignoreApplicationPath, getStaticSubResolutionValue(servletConfig), isAppResourceLifecycleASingleton(app, servletConfig), getBus());
String splitChar = getParameterSplitChar(servletConfig);
setAllInterceptors(bean, servletConfig, splitChar);
setInvoker(bean, servletConfig);
setExtensions(bean, servletConfig);
setDocLocation(bean, servletConfig);
setSchemasLocations(bean, servletConfig);
List<?> providers = getProviders(servletConfig, splitChar);
bean.setProviders(providers);
List<? extends Feature> features = getFeatures(servletConfig, splitChar);
bean.getFeatures().addAll(features);
bean.setBus(getBus());
bean.setApplicationInfo(providerApp);
bean.create();
}
}
Aggregations