Package javax.ws.rs.core

Examples of javax.ws.rs.core.Application


    public void setStart(boolean start) {
        this.start = start;
    }

    private void injectContexts() {
        Application application = appProvider == null ? null : appProvider.getProvider();
        for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
            if (cri.isSingleton()) {
                InjectionUtils.injectContextProxiesAndApplication(cri,
                                                    cri.getResourceProvider().getInstance(null),
                                                    application);
View Full Code Here


                String appPrefix = webApp.contextRoot;
                if (!appPrefix.endsWith("/")) {
                    appPrefix += "/";
                }

                Application appInstance;
                Class<?> appClazz;
                try {
                    appClazz = classLoader.loadClass(app);
                    appInstance = Application.class.cast(appClazz.newInstance());
                } catch (Exception e) {
                    throw new OpenEJBRestRuntimeException("can't create class " + app, e);
                }

                ApplicationPath path = appClazz.getAnnotation(ApplicationPath.class);
                if (path != null) {
                    String appPath = path.value();
                    if (appPath.startsWith("/")) {
                        appPrefix += appPath.substring(1);
                    } else {
                        appPrefix += appPath;
                    }
                }

                for (Object o : appInstance.getSingletons()) {
                    if (o == null) {
                        continue;
                    }

                    if (restEjbs.containsKey(o.getClass().getName())) {
                        // no more a singleton if the ejb i not a singleton...but it is a weird case
                        deployEJB(appPrefix, restEjbs.get(o.getClass().getName()).context);
                    } else {
                        deploySingleton(appPrefix, o, appInstance, classLoader);
                    }
                }
                for (Class<?> clazz : appInstance.getClasses()) {
                    if (restEjbs.containsKey(clazz.getName())) {
                        deployEJB(appPrefix, restEjbs.get(clazz.getName()).context);
                    } else {
                        deployPojo(appPrefix, clazz, appInstance, classLoader, injections, context);
                    }
View Full Code Here

            return application;
        }
    }

    private static Application unwrapCustomRootApplication(ResourceConfig resourceConfig) {
        Application app = null;
        while (resourceConfig != null) {
            app = resourceConfig.getApplication();
            if (app == resourceConfig) {
                // resource config is the root app - return null
                return null;
View Full Code Here

        private RuntimeConfig(ResourceConfig original) {
            super(original);

            this.application = original;

            Application customRootApp = ResourceConfig.unwrapCustomRootApplication(original);
            if (customRootApp != null) {
                registerComponentsOf(customRootApp);
            }

            originalRegistrations = Sets.newIdentityHashSet();
View Full Code Here

    /**
     * Create a new Jersey application handler using a default configuration.
     */
    public ApplicationHandler() {
        this(new Application());
    }
View Full Code Here

        // need to handle ResourceConfig and Application separately as invoking forContract() on these
        // will trigger the factories which we don't want at this point
        if (applicationClass == ResourceConfig.class) {
            return new ResourceConfig();
        } else if (applicationClass == Application.class) {
            return new Application();
        } else {
            final Application app = locator.createAndInitialize(applicationClass);
            if (app instanceof ResourceConfig) {
                final ResourceConfig _rc = (ResourceConfig) app;
                final Class<? extends Application> innerAppClass = _rc.getApplicationClass();
                if (innerAppClass != null) {
                    final Application innerApp = createApplication(innerAppClass);
                    _rc.setApplication(innerApp);
                }
            }
            return app;
        }
View Full Code Here

     *
     * @return the original {@link Application} subclass.
     */
    public static Application getWrappedApplication(Application app) {
        while (app instanceof  ResourceConfig) {
            final Application wrappedApplication = ((ResourceConfig) app).getApplication();
            if (wrappedApplication == app) {
                break;
            }
            app = wrappedApplication;
        }
View Full Code Here

                        if (Modifier.isAbstract(clazz.getModifiers())) {
                            continue;
                        }

                        try {
                            final Application app = Application.class.cast(clazz.newInstance());
                            try {
                                final Set<Class<?>> appClasses = app.getClasses();
                                if (!appClasses.isEmpty()) {
                                    classes.addAll(appClasses);
                                } else {
                                    addRestClassesToScannedClasses(webModule, classes, classLoader);
                                }
View Full Code Here

                        clazz = web.getClassLoader().loadClass(app);
                    } catch (final ClassNotFoundException e) {
                        continue; // managed elsewhere, here we just check methods
                    }

                    final Application appInstance;
                    try {
                        appInstance = (Application) clazz.newInstance();
                    } catch (final Exception e) {
                        continue; // managed elsewhere
                    }

                    try {
                        for (final Class<?> rsClass : appInstance.getClasses()) {
                            classes.add(rsClass.getName());
                        }
                        for (final Object rsSingleton : appInstance.getSingletons()) {
                            classes.add(rsSingleton.getClass().getName());
                        }
                    } catch (final RuntimeException npe) {
                        if (appInstance == null) {
                            throw npe;
View Full Code Here

        try {
            boolean deploymentWithApplication = "true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY, APPLICATION_DEPLOYMENT));
            if (deploymentWithApplication) {
                Class<?> appClazz;
                for (final String app : webApp.restApplications) {
                    Application application;
                    boolean appSkipped = false;
                    String prefix = "/";

                    try {
                        appClazz = classLoader.loadClass(app);
                        application = Application.class.cast(appClazz.newInstance());
                        if (owbCtx.getBeanManagerImpl().isInUse()) {
                            try {
                                webContext.inject(application);
                            } catch (final Exception e) {
                                // not important since not required by the spec
                            }
                        }
                    } catch (final Exception e) {
                        throw new OpenEJBRestRuntimeException("can't create class " + app, e);
                    }

                    final Set<Class<?>> classes = application.getClasses();
                    final Set<Object> singletons = application.getSingletons();

                    if (classes.size() + singletons.size() == 0) {
                        appSkipped = true;
                    } else {
                        for (final Class<?> clazz : classes) {
                            if (isProvider(clazz)) {
                                additionalProviders.add(clazz);
                            } else if (!hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) {
                                pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                                if (PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()) != null) {
                                    deploymentWithApplication = false;
                                    logOldDeploymentUsage(clazz.getName());
                                }
                            }
                        }

                        if (deploymentWithApplication) { // don't do it if we detected we should use old deployment
                            for (final Object o : singletons) {
                                final Class<?> clazz = o.getClass();
                                if (isProvider(clazz)) {
                                    additionalProviders.add(o);
                                } else if (!hasEjbAndIsNotAManagedBean(restEjbs, clazz.getName())) {
                                    pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                                    if (PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()) != null) {
                                        deploymentWithApplication = false;
                                        logOldDeploymentUsage(clazz.getName());
                                    }
                                }
                            }
                        }
                    }

                    if (deploymentWithApplication) { // don't do it if we detected we should use old deployment
                        final String path = appPrefix(webApp, appClazz);
                        if (path != null) {
                            prefix += path + wildcard;
                        } else {
                            prefix += wildcard;
                        }
                    }

                    if (deploymentWithApplication) { // don't do it if we detected we should use old deployment
                        if (appSkipped || application == null) {
                            application = new InternalApplication(application);

                            for (final String clazz : webApp.restClass) {
                                try {
                                    final Class<?> loaded = classLoader.loadClass(clazz);
                                    if (!isProvider(loaded)) {
                                        pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                                        if (PojoUtil.findConfiguration(pojoConfigurations, loaded.getName()) != null) {
                                            deploymentWithApplication = false;
                                            logOldDeploymentUsage(loaded.getName());
                                            break;
                                        }
                                        application.getClasses().add(loaded);
                                    } else {
                                        additionalProviders.add(loaded);
                                    }
                                } catch (final Exception e) {
                                    throw new OpenEJBRestRuntimeException("can't load class " + clazz, e);
                                }
                            }
                            if (deploymentWithApplication) {
                                addEjbToApplication(application, restEjbs);
                                if (!prefix.endsWith(wildcard)) {
                                    prefix += wildcard;
                                }
                            }
                        }

                        if (!application.getClasses().isEmpty() || !application.getSingletons().isEmpty()) {
                            pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                            deployApplication(appInfo, webApp.contextRoot, restEjbs, classLoader, injections, owbCtx, context, additionalProviders, pojoConfigurations, application, prefix);
                        }
                    }

                    if (!deploymentWithApplication) {
                        fullServletDeployment(appInfo, webApp, webContext, restEjbs, classLoader, injections, owbCtx, context, additionalProviders, pojoConfigurations);
                    }
                }

                if (webApp.restApplications.isEmpty()) {
                    final Application application = new InternalApplication(null);
                    for (final String clazz : webApp.restClass) {
                        try {
                            final Class<?> loaded = classLoader.loadClass(clazz);
                            if (!isProvider(loaded)) {
                                pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                                if (PojoUtil.findConfiguration(pojoConfigurations, loaded.getName()) != null) {
                                    deploymentWithApplication = false;
                                    logOldDeploymentUsage(loaded.getName());
                                    break;
                                }
                                application.getClasses().add(loaded);
                            } else {
                                additionalProviders.add(loaded);
                            }
                        } catch (final Exception e) {
                            throw new OpenEJBRestRuntimeException("can't load class " + clazz, e);
                        }
                    }
                    addEjbToApplication(application, restEjbs);

                    if (deploymentWithApplication) {
                        if (!application.getClasses().isEmpty() || !application.getSingletons().isEmpty()) {
                            final String path = appPrefix(webApp, application.getClass());
                            final String prefix;
                            if (path != null) {
                                prefix = "/" + path + wildcard;
                            } else {
                                prefix = "/" + wildcard;
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.Application

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.