Search in sources :

Example 91 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.

the class SseEventSourceImplTest method startNotAuthorizedServer.

private static void startNotAuthorizedServer(Type type) {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setAddress(LOCAL_ADDRESS + type.name());
    sf.setServiceBean(new ProtectedEventServer());
    SERVERS.put(type, sf.create());
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Example 92 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.

the class SseEventSourceImplTest method startUnavailableServer.

private static void startUnavailableServer(Type type) {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setAddress(LOCAL_ADDRESS + type.name());
    sf.setServiceBean(new StatusServer(503, type));
    SERVERS.put(type, sf.create());
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean)

Example 93 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean 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();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Annotation(java.lang.annotation.Annotation) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) Provider(javax.ws.rs.ext.Provider) Collection(java.util.Collection) Application(javax.ws.rs.core.Application)

Example 94 with JAXRSServerFactoryBean

use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project cxf by apache.

the class CXFNonSpringJaxrsServlet method init.

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    if (getApplication() != null) {
        createServerFromApplication(servletConfig);
        return;
    }
    String applicationClass = servletConfig.getInitParameter(JAXRS_APPLICATION_PARAM);
    if (applicationClass != null) {
        createServerFromApplication(applicationClass, servletConfig);
        return;
    }
    String splitChar = getParameterSplitChar(servletConfig);
    JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
    bean.setBus(getBus());
    String address = servletConfig.getInitParameter(SERVICE_ADDRESS_PARAM);
    if (address == null) {
        address = "/";
    }
    bean.setAddress(address);
    bean.setStaticSubresourceResolution(getStaticSubResolutionValue(servletConfig));
    String modelRef = servletConfig.getInitParameter(USER_MODEL_PARAM);
    if (modelRef != null) {
        bean.setModelRef(modelRef.trim());
    }
    setDocLocation(bean, servletConfig);
    setSchemasLocations(bean, servletConfig);
    setAllInterceptors(bean, servletConfig, splitChar);
    setInvoker(bean, servletConfig);
    Map<Class<?>, Map<String, List<String>>> resourceClasses = getServiceClasses(servletConfig, modelRef != null, splitChar);
    Map<Class<?>, ResourceProvider> resourceProviders = getResourceProviders(servletConfig, resourceClasses);
    List<?> providers = getProviders(servletConfig, splitChar);
    bean.setResourceClasses(new ArrayList<Class<?>>(resourceClasses.keySet()));
    bean.setProviders(providers);
    for (Map.Entry<Class<?>, ResourceProvider> entry : resourceProviders.entrySet()) {
        bean.setResourceProvider(entry.getKey(), entry.getValue());
    }
    setExtensions(bean, servletConfig);
    List<? extends Feature> features = getFeatures(servletConfig, splitChar);
    bean.getFeatures().addAll(features);
    bean.create();
}
Also used : PerRequestResourceProvider(org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) HashMap(java.util.HashMap) Map(java.util.Map)

Example 95 with JAXRSServerFactoryBean

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

Aggregations

JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)126 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)65 Bus (org.apache.cxf.Bus)21 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)18 ArrayList (java.util.ArrayList)15 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)14 Test (org.junit.Test)13 HashMap (java.util.HashMap)10 Server (org.apache.cxf.endpoint.Server)10 Application (javax.ws.rs.core.Application)9 Before (org.junit.Before)8 Map (java.util.Map)7 IOException (java.io.IOException)5 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)5 ResourceProvider (org.apache.cxf.jaxrs.lifecycle.ResourceProvider)5 Bean (org.springframework.context.annotation.Bean)5 InputStream (java.io.InputStream)4 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)4 Feature (org.apache.cxf.feature.Feature)4 JAXRSBindingFactory (org.apache.cxf.jaxrs.JAXRSBindingFactory)4