Java Code Examples for javax.ws.rs.core.Application#getProperties()

The following examples show how to use javax.ws.rs.core.Application#getProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DPCXFNonSpringJaxrsServlet.java    From JaxRSProviders with Apache License 2.0 4 votes vote down vote up
@Override
protected void createServerFromApplication(ServletConfig servletConfig) throws ServletException {
	Application app = new DPCXFApplication();

	configurable.register(new DPCXFContainerResponseFilter(), ContainerResponseFilter.class);

	List<Class<?>> resourceClasses = new ArrayList<>();
	Map<Class<?>, ResourceProvider> map = new HashMap<>();
	List<Feature> features = new ArrayList<>();

	for (Object o : app.getSingletons()) {
		ResourceProvider rp = new SingletonResourceProvider(o);
		for (Class<?> c : app.getClasses()) {
			resourceClasses.add(c);
			map.put(c, rp);
		}
	}

	JAXRSServerFactoryBean bean = createJAXRSServerFactoryBean();
	bean.setBus(getBus());
	bean.setAddress("/");

	bean.setResourceClasses(resourceClasses);
	bean.setFeatures(features);

	for (Map.Entry<Class<?>, ResourceProvider> entry : map.entrySet()) {
		bean.setResourceProvider(entry.getKey(), entry.getValue());
	}

	Map<String, Object> appProps = app.getProperties();
	if (appProps != null) {
		bean.getProperties(true).putAll(appProps);
	}

	bean.setApplication(app);

	CXFServerConfiguration configuration = (CXFServerConfiguration) this.configurable.getConfiguration();
	bean.setProviders(new ArrayList<Object>(configuration.getExtensions()));

	bean.create();
}
 
Example 2
Source File: ResourceUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static JAXRSServerFactoryBean createApplication(Application app,
                                                       boolean ignoreAppPath,
                                                       boolean staticSubresourceResolution,
                                                       boolean useSingletonResourceProvider,
                                                       Bus bus) {

    Set<Object> singletons = app.getSingletons();
    verifySingletons(singletons);

    List<Class<?>> resourceClasses = new ArrayList<>();
    List<Object> providers = new ArrayList<>();
    List<Feature> features = new ArrayList<>();
    Map<Class<?>, ResourceProvider> map = new HashMap<>();

    // Note, app.getClasses() returns a list of per-request classes
    // or singleton provider classes
    for (Class<?> cls : app.getClasses()) {
        if (isValidApplicationClass(cls, singletons)) {
            if (isValidProvider(cls)) {
                providers.add(createProviderInstance(cls));
            } else if (Feature.class.isAssignableFrom(cls)) {
                features.add(createFeatureInstance((Class<? extends Feature>) cls));
            } else {
                resourceClasses.add(cls);
                if (useSingletonResourceProvider) {
                    map.put(cls, new SingletonResourceProvider(createProviderInstance(cls)));
                } else {
                    map.put(cls, new PerRequestResourceProvider(cls));
                }
            }
        }
    }

    // we can get either a provider or resource class here
    for (Object o : singletons) {
        if (isValidProvider(o.getClass())) {
            providers.add(o);
        } else if (o instanceof Feature) {
            features.add((Feature) o);
        } else {
            resourceClasses.add(o.getClass());
            map.put(o.getClass(), new SingletonResourceProvider(o));
        }
    }

    JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
    if (bus != null) {
        bean.setBus(bus);
    }

    String address = "/";
    if (!ignoreAppPath) {
        ApplicationPath appPath = locateApplicationPath(app.getClass());
        if (appPath != null) {
            address = appPath.value();
        }
    }
    if (!address.startsWith("/")) {
        address = "/" + address;
    }
    bean.setAddress(address);
    bean.setStaticSubresourceResolution(staticSubresourceResolution);
    bean.setResourceClasses(resourceClasses);
    bean.setProviders(providers);
    bean.getFeatures().addAll(features);
    for (Map.Entry<Class<?>, ResourceProvider> entry : map.entrySet()) {
        bean.setResourceProvider(entry.getKey(), entry.getValue());
    }
    Map<String, Object> appProps = app.getProperties();
    if (appProps != null) {
        bean.getProperties(true).putAll(appProps);
    }
    bean.setApplication(app);
    return bean;
}