Search in sources :

Example 46 with Application

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();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) Application(javax.ws.rs.core.Application)

Example 47 with Application

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;
}
Also used : Application(javax.ws.rs.core.Application)

Example 48 with Application

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));
}
Also used : ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) Properties(java.util.Properties) Application(javax.ws.rs.core.Application)

Example 49 with Application

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);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) BeanContext(org.apache.openejb.BeanContext) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) Application(javax.ws.rs.core.Application) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 50 with Application

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);
}
Also used : Array(java.lang.reflect.Array) OASModelReader(org.eclipse.microprofile.openapi.OASModelReader) Path(javax.ws.rs.Path) ProcessBean(javax.enterprise.inject.spi.ProcessBean) HashMap(java.util.HashMap) Application(javax.ws.rs.core.Application) AnnotatedTypeElement(org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedTypeElement) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) AnnotationProcessor(org.apache.geronimo.microprofile.openapi.impl.processor.AnnotationProcessor) BeforeBeanDiscovery(javax.enterprise.inject.spi.BeforeBeanDiscovery) Observes(javax.enterprise.event.Observes) Map(java.util.Map) Yaml(org.apache.geronimo.microprofile.openapi.impl.loader.yaml.Yaml) Instance(javax.enterprise.inject.Instance) Collectors.toSet(java.util.stream.Collectors.toSet) GeronimoOpenAPIConfig(org.apache.geronimo.microprofile.openapi.config.GeronimoOpenAPIConfig) AnnotatedMethodElement(org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedMethodElement) NamingStrategy(org.apache.geronimo.microprofile.openapi.impl.processor.spi.NamingStrategy) Annotated(javax.enterprise.inject.spi.Annotated) Extension(javax.enterprise.inject.spi.Extension) Optional.ofNullable(java.util.Optional.ofNullable) FilterImpl(org.apache.geronimo.microprofile.openapi.impl.filter.FilterImpl) Collection(java.util.Collection) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) CDI(javax.enterprise.inject.spi.CDI) JacksonOpenAPIYamlBodyWriter(org.apache.geronimo.microprofile.openapi.jaxrs.JacksonOpenAPIYamlBodyWriter) InvocationTargetException(java.lang.reflect.InvocationTargetException) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) Stream(java.util.stream.Stream) Type(java.lang.reflect.Type) PathsImpl(org.apache.geronimo.microprofile.openapi.impl.model.PathsImpl) DefaultLoader(org.apache.geronimo.microprofile.openapi.impl.loader.DefaultLoader) Annotation(java.lang.annotation.Annotation) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) ServletContext(javax.servlet.ServletContext) OASConfig(org.eclipse.microprofile.openapi.OASConfig) OASFilter(org.eclipse.microprofile.openapi.OASFilter) Bean(javax.enterprise.inject.spi.Bean) GeronimoOpenAPIExtension(org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension) RegisterRestClient(org.eclipse.microprofile.rest.client.inject.RegisterRestClient) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) BeanManager(javax.enterprise.inject.spi.BeanManager) AnnotatedElement(java.lang.reflect.AnnotatedElement) FilterImpl(org.apache.geronimo.microprofile.openapi.impl.filter.FilterImpl) OASModelReader(org.eclipse.microprofile.openapi.OASModelReader) PathsImpl(org.apache.geronimo.microprofile.openapi.impl.model.PathsImpl) ServletContext(javax.servlet.ServletContext) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) DefaultLoader(org.apache.geronimo.microprofile.openapi.impl.loader.DefaultLoader) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

Application (javax.ws.rs.core.Application)63 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)12 ApplicationInfo (org.apache.cxf.jaxrs.model.ApplicationInfo)12 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 Set (java.util.Set)7 ServletException (javax.servlet.ServletException)7 Annotation (java.lang.annotation.Annotation)5 List (java.util.List)5 Map (java.util.Map)5 ApplicationPath (javax.ws.rs.ApplicationPath)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)4 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)3 Method (java.lang.reflect.Method)3 Type (java.lang.reflect.Type)3 Collection (java.util.Collection)3