use of javax.ws.rs.core.Application in project tomee by apache.
the class CXFNonSpringJaxrsServlet method createServerFromApplication.
protected void createServerFromApplication(ServletConfig servletConfig) throws ServletException {
Application app = getApplication();
JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, isIgnoreApplicationPath(servletConfig), 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.setApplication(getApplication());
bean.create();
}
use of javax.ws.rs.core.Application in project tomee by apache.
the class ClassResourceInfo method getSubResource.
public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass, Object instance, boolean resolveContexts, Message message) {
SubresourceKey key = new SubresourceKey(typedClass, instanceClass);
ClassResourceInfo cri = subResources.get(key);
if (cri == null) {
cri = ResourceUtils.createClassResourceInfo(typedClass, instanceClass, this, false, resolveContexts, getBus());
if (cri != null) {
if (message != null) {
cri.initBeanParamInfo(ServerProviderFactory.getInstance(message));
}
subResources.putIfAbsent(key, cri);
}
}
// from within singleton root resources (not default)
if (resolveContexts && cri != null && cri.isSingleton() && instance != null && cri.contextsAvailable()) {
synchronized (this) {
if (!injectedSubInstances.contains(instance.toString())) {
Application app = null;
if (message != null) {
ProviderInfo<?> appProvider = (ProviderInfo<?>) message.getExchange().getEndpoint().get(Application.class.getName());
if (appProvider != null) {
app = (Application) appProvider.getProvider();
}
}
InjectionUtils.injectContextProxiesAndApplication(cri, instance, app, null);
injectedSubInstances.add(instance.toString());
}
}
}
return cri;
}
use of javax.ws.rs.core.Application in project tomee by apache.
the class RESTService method deployApplication.
private void deployApplication(final AppInfo appInfo, final String contextRoot, final Map<String, EJBRestServiceInfo> restEjbs, final ClassLoader classLoader, final Collection<Injection> injections, final WebBeansContext owbCtx, final Context context, final Collection<Object> additionalProviders, final Collection<IdPropertiesInfo> pojoConfigurations, final Application application, final String prefix) {
// get configuration
Properties configuration;
if (InternalApplication.class.equals(application.getClass())) {
final Application original = InternalApplication.class.cast(application).getOriginal();
if (original == null) {
configuration = PojoUtil.findConfiguration(pojoConfigurations, "jaxrs-application");
} else {
configuration = PojoUtil.findConfiguration(pojoConfigurations, original.getClass().getName());
}
} else {
configuration = PojoUtil.findConfiguration(pojoConfigurations, application.getClass().getName());
}
if (configuration == null) {
// try a constant (common in half of cases)
configuration = PojoUtil.findConfiguration(pojoConfigurations, "jaxrs-application");
}
if (configuration != null) {
LOGGER.info("Registered JAX-RS Configuration: " + configuration);
}
final String base = getAddress(contextRoot);
final String nopath;
if (base.endsWith("/") && prefix.startsWith("/")) {
nopath = base + prefix.substring(1);
} else {
nopath = base + prefix;
}
final RsHttpListener listener = createHttpListener();
final String host = findHost(contextRoot, appInfo.webApps);
final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(appInfo.appId, contextRoot, listener, classLoader, nopath.substring(NOPATH_PREFIX.length() - 1), host, auth, realm);
services.add(new DeployedService(address.complete, contextRoot, application.getClass().getName(), appInfo.appId));
// app config
listener.deployApplication(// app config
application, // app config
address.complete.substring(0, address.complete.length() - wildcard.length()), // app config
nopath.substring(NOPATH_PREFIX.length(), nopath.length() - wildcard.length()), // app config
additionalProviders, // app config
restEjbs, // injection/webapp context
classLoader, // injection/webapp context
injections, // injection/webapp context
context, // injection/webapp context
owbCtx, // deployment config
new ServiceConfiguration(configuration, appInfo.services));
}
use of javax.ws.rs.core.Application in project tomee by apache.
the class RESTService method afterApplicationCreated.
public void afterApplicationCreated(@Observes final AssemblerAfterApplicationCreated event) {
if (!enabled)
return;
final AppInfo appInfo = event.getApp();
if ("false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxrs.on", "true"))) {
return;
}
quickCheckIfOldDeploymentShouldBeUsedFromEjbConfig(appInfo);
if (deployedApplications.add(appInfo)) {
if (appInfo.webApps.size() == 0) {
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
final ClassLoader appClassLoader = getClassLoader(containerSystem.getAppContext(appInfo.appId).getClassLoader());
Thread.currentThread().setContextClassLoader(appClassLoader);
try {
final Map<String, EJBRestServiceInfo> restEjbs = getRestEjbs(appInfo, null);
if (restEjbs.isEmpty()) {
return;
}
final Collection<Object> providers;
if (useDiscoveredProviders(appInfo)) {
providers = appProviders(appInfo.jaxRsProviders, appClassLoader);
} else {
providers = new ArrayList<>();
}
if ("true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY, APPLICATION_DEPLOYMENT))) {
final Application application = new InternalApplication(null);
addEjbToApplication(application, restEjbs);
// merge configurations at app level since a single deployment is available
final List<IdPropertiesInfo> pojoConfigurations = new ArrayList<>();
BeanContext comp = null;
for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
if (comp != null) {
break;
}
if (bean.ejbClass.equals(BeanContext.Comp.class.getName())) {
comp = containerSystem.getBeanContext(bean.ejbDeploymentId);
break;
}
}
if (ejbJar.pojoConfigurations != null) {
pojoConfigurations.addAll(ejbJar.pojoConfigurations);
}
}
if (appInfo.pojoConfigurations != null) {
pojoConfigurations.addAll(appInfo.pojoConfigurations);
}
final Map.Entry<String, EJBRestServiceInfo> next = restEjbs.entrySet().iterator().next();
if (comp == null) {
comp = next.getValue().context;
}
deployApplication(appInfo, next.getValue().path, restEjbs, comp.getClassLoader(), comp.getInjections(), containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), comp.getJndiContext(), providers, pojoConfigurations, application, wildcard);
} else {
for (final Map.Entry<String, EJBRestServiceInfo> ejb : restEjbs.entrySet()) {
final BeanContext ctx = ejb.getValue().context;
if (BeanType.MANAGED.equals(ctx.getComponentType())) {
deployPojo(appInfo.appId, "", ejb.getValue().path, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), ctx.getJndiContext(), containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), providers, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
} else {
deployEJB(appInfo.appId, "", ejb.getValue().path, ctx, providers, appInfo.services);
}
}
}
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
} else {
for (final WebAppInfo webApp : appInfo.webApps) {
afterApplicationCreated(appInfo, webApp);
}
}
}
}
use of javax.ws.rs.core.Application in project tomee by apache.
the class TomEEOpenAPIExtension method createOpenApi.
private OpenAPI createOpenApi(final Class<?> application, final Stream<Class<?>> beans) {
final CDI<Object> current = CDI.current();
final OpenAPI api = ofNullable(config.read(OASConfig.MODEL_READER, null)).map(value -> newInstance(current, value)).map(it -> OASModelReader.class.cast(it).buildModel()).orElseGet(() -> current.select(DefaultLoader.class).get().loadDefaultApi());
final BeanManager beanManager = current.getBeanManager();
processor.processApplication(api, new ElementImpl(beanManager.createAnnotatedType(application)));
if (skipScan) {
return api.paths(new PathsImpl());
}
// adds the context path to the base
final Instance<ServletContext> servletContextInstance = current.select(ServletContext.class);
final boolean appendContextPath = Boolean.valueOf(config.read("application.append-context-path", "true"));
String contextPath = "";
if (appendContextPath && !servletContextInstance.isAmbiguous() && !servletContextInstance.isUnsatisfied()) {
contextPath = servletContextInstance.get().getContextPath();
}
final String base = contextPath + processor.getApplicationBinding(application);
processor.beforeProcessing();
beans.filter(c -> (excludeClasses == null || !excludeClasses.contains(c.getName()))).filter(c -> (excludePackages == null || excludePackages.stream().noneMatch(it -> c.getName().startsWith(it)))).map(beanManager::createAnnotatedType).forEach(at -> processor.processClass(base, api, new ElementImpl(at), at.getMethods().stream().map(MethodElementImpl::new)));
return ofNullable(config.read(OASConfig.FILTER, null)).map(it -> newInstance(current, it)).map(i -> new FilterImpl(OASFilter.class.cast(i)).filter(api)).orElse(api);
}
Aggregations