use of javax.ws.rs.core.Application in project cxf by apache.
the class AbstractSpringComponentScanServer method createJaxRsServer.
@Override
protected Server createJaxRsServer() {
JAXRSServerFactoryBean factoryBean = null;
String[] beanNames = applicationContext.getBeanNamesForAnnotation(ApplicationPath.class);
if (beanNames.length > 0) {
Set<String> componentScanPackagesSet = parseSetProperty(componentScanPackages);
Set<String> componentScanBeansSet = parseSetProperty(componentScanBeans);
for (String beanName : beanNames) {
if (isComponentMatched(beanName, componentScanPackagesSet, componentScanBeansSet)) {
Application app = applicationContext.getBean(beanName, Application.class);
factoryBean = createFactoryBeanFromApplication(app);
for (String cxfBeanName : applicationContext.getBeanNamesForAnnotation(org.apache.cxf.annotations.Provider.class)) {
if (isComponentMatched(cxfBeanName, componentScanPackagesSet, componentScanBeansSet)) {
addCxfProvider(getProviderBean(cxfBeanName));
}
}
break;
}
}
}
if (!StringUtils.isEmpty(classesScanPackages)) {
try {
final Map<Class<? extends Annotation>, Collection<Class<?>>> appClasses = ClasspathScanner.findClasses(classesScanPackages, ApplicationPath.class);
List<Application> apps = CastUtils.cast(JAXRSServerFactoryBeanDefinitionParser.createBeansFromDiscoveredClasses(super.applicationContext, appClasses.get(ApplicationPath.class), null));
if (!apps.isEmpty()) {
factoryBean = createFactoryBeanFromApplication(apps.get(0));
final Map<Class<? extends Annotation>, Collection<Class<?>>> cxfClasses = ClasspathScanner.findClasses(classesScanPackages, org.apache.cxf.annotations.Provider.class);
addCxfProvidersFromClasses(cxfClasses.get(org.apache.cxf.annotations.Provider.class));
}
} catch (Exception ex) {
throw new ServiceConstructionException(ex);
}
}
if (factoryBean != null) {
setFactoryCxfProviders(factoryBean);
return factoryBean.create();
}
return super.createJaxRsServer();
}
use of javax.ws.rs.core.Application in project cxf by apache.
the class CXFNonSpringJaxrsServlet method createSingletonInstance.
protected Object createSingletonInstance(Class<?> cls, Map<String, List<String>> props, ServletConfig sc) throws ServletException {
Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
if (c == null) {
throw new ServletException("No valid constructor found for " + cls.getName());
}
boolean isApplication = Application.class.isAssignableFrom(c.getDeclaringClass());
try {
final ProviderInfo<? extends Object> provider;
if (c.getParameterTypes().length == 0) {
if (isApplication) {
provider = new ApplicationInfo((Application) c.newInstance(), getBus());
} else {
provider = new ProviderInfo<>(c.newInstance(), getBus(), false, true);
}
} else {
Map<Class<?>, Object> values = new HashMap<>();
values.put(ServletContext.class, sc.getServletContext());
values.put(ServletConfig.class, sc);
provider = ProviderFactory.createProviderFromConstructor(c, values, getBus(), isApplication, true);
}
Object instance = provider.getProvider();
injectProperties(instance, props);
configureSingleton(instance);
return isApplication ? provider : instance;
} catch (InstantiationException ex) {
ex.printStackTrace();
throw new ServletException("Resource class " + cls.getName() + " can not be instantiated");
} catch (IllegalAccessException ex) {
ex.printStackTrace();
throw new ServletException("Resource class " + cls.getName() + " can not be instantiated due to IllegalAccessException");
} catch (InvocationTargetException ex) {
ex.printStackTrace();
throw new ServletException("Resource class " + cls.getName() + " can not be instantiated due to InvocationTargetException");
}
}
use of javax.ws.rs.core.Application in project cxf by apache.
the class CXFNonSpringJaxrsServlet method createApplicationInfo.
protected ApplicationInfo createApplicationInfo(String appClassName, ServletConfig servletConfig) throws ServletException {
Application customApp = createApplicationInstance(appClassName, servletConfig);
if (customApp != null) {
return new ApplicationInfo(customApp, getBus());
}
Map<String, List<String>> props = new HashMap<>();
appClassName = getClassNameAndProperties(appClassName, props);
Class<?> appClass = loadApplicationClass(appClassName);
ApplicationInfo appInfo = (ApplicationInfo) createSingletonInstance(appClass, props, servletConfig);
Map<String, Object> servletProps = new HashMap<>();
ServletContext servletContext = servletConfig.getServletContext();
for (Enumeration<String> names = servletContext.getInitParameterNames(); names.hasMoreElements(); ) {
String name = names.nextElement();
servletProps.put(name, servletContext.getInitParameter(name));
}
for (Enumeration<String> names = servletConfig.getInitParameterNames(); names.hasMoreElements(); ) {
String name = names.nextElement();
servletProps.put(name, servletConfig.getInitParameter(name));
}
appInfo.setOverridingProps(servletProps);
return appInfo;
}
use of javax.ws.rs.core.Application in project cxf 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();
}
}
use of javax.ws.rs.core.Application in project cxf by apache.
the class DefaultApplicationFactory method createApplicationOrDefault.
/**
* Detects the application (if present) or creates the default application (in case the scan is disabled).
*/
public static Application createApplicationOrDefault(final Server server, final ServerProviderFactory factory, final JAXRSServiceFactoryBean sfb, final Bus bus, final Set<String> resourcePackages, final boolean scan) {
ApplicationInfo appInfo = null;
if (!scan) {
appInfo = factory.getApplicationProvider();
if (appInfo == null) {
appInfo = createApplicationInfo(sfb, resourcePackages, bus);
server.getEndpoint().put(Application.class.getName(), appInfo);
}
}
return (appInfo == null) ? null : appInfo.getProvider();
}
Aggregations