Java Code Examples for org.apache.cxf.jaxrs.utils.ResourceUtils#createApplication()

The following examples show how to use org.apache.cxf.jaxrs.utils.ResourceUtils#createApplication() . 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: CXFNonSpringJaxrsServlet.java    From JaxRSProviders with Apache License 2.0 6 votes vote down vote up
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.setFeatures(features);

    bean.setBus(getBus());
    bean.setApplication(getApplication());
    bean.create();
}
 
Example 2
Source File: BrooklynRestResourceTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected synchronized void startServer() throws Exception {
    if (server == null) {
        setUpResources();
        
        // needed to enable session support
        serverEngine = new JettyHTTPServerEngineFactory().createJettyHTTPServerEngine(
            ENDPOINT_ADDRESS_HOST, ENDPOINT_ADDRESS_PORT, "http"); 
        serverEngine.setSessionSupport(true);
        JAXRSServerFactoryBean sf = ResourceUtils.createApplication(createRestApp(), true,false,false, BusFactory.getDefaultBus());
        if (clientProviders == null) {
            clientProviders = sf.getProviders();
        }
        configureCXF(sf);
        
        sf.setAddress(getEndpointAddress());
        sf.setFeatures(ImmutableList.of(new org.apache.cxf.feature.LoggingFeature()));
        server = sf.create();
    }
}
 
Example 3
Source File: CXFNonSpringJaxrsServlet.java    From cxf with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: CXFNonSpringJaxrsServlet.java    From JaxRSProviders with Apache License 2.0 5 votes vote down vote up
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.setFeatures(features);

        bean.setBus(getBus());
        bean.setApplicationInfo(providerApp);
        bean.create();
    }
}
 
Example 5
Source File: JAXRSCdiResourceExtension.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Create the JAXRSServerFactoryBean from the application and all discovered service and provider instances.
 * @param application application instance
 * @param services all discovered services
 * @param providers all discovered providers
 * @return JAXRSServerFactoryBean instance
 */
private JAXRSServerFactoryBean createFactoryInstance(final Application application, final List< ? > services,
        final List< ? > providers, final List< ? extends Feature > features) {

    final JAXRSServerFactoryBean instance = 
        ResourceUtils.createApplication(application, false, false, false, bus);
    instance.setServiceBeans(new ArrayList<>(services));
    instance.setProviders(providers);
    instance.setProviders(loadExternalProviders());
    instance.setFeatures(features);

    return instance;
}
 
Example 6
Source File: JAXRSCdiResourceExtension.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Create the JAXRSServerFactoryBean from the objects declared by application itself.
 * @param application application instance
 * @return JAXRSServerFactoryBean instance
 */
private JAXRSServerFactoryBean createFactoryInstance(final Application application, final BeanManager beanManager) {
    final JAXRSServerFactoryBean instance =
        ResourceUtils.createApplication(application, false, false, false, bus);
    final ClassifiedClasses classified = classes2singletons(application, beanManager);

    instance.setProviders(classified.getProviders());
    instance.getFeatures().addAll(classified.getFeatures());

    for (final ResourceProvider resourceProvider: classified.getResourceProviders()) {
        instance.setResourceProvider(resourceProvider.getResourceClass(), resourceProvider);
    }

    return instance;
}
 
Example 7
Source File: CXFNonSpringJaxrsServlet.java    From cxf with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 8
Source File: RuntimeDelegateImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T createEndpoint(Application app, Class<T> endpointType)
    throws IllegalArgumentException, UnsupportedOperationException {
    if (app == null || (!Server.class.isAssignableFrom(endpointType)
        && !JAXRSServerFactoryBean.class.isAssignableFrom(endpointType))) {
        throw new IllegalArgumentException();
    }
    JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, false, false, false, null);
    if (JAXRSServerFactoryBean.class.isAssignableFrom(endpointType)) {
        return endpointType.cast(bean);
    }
    bean.setStart(false);
    Server server = bean.create();
    return endpointType.cast(server);
}
 
Example 9
Source File: ClassResourceInfoTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameBindings() {
    Application app = new TestApplication();
    JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, true, true, false, null);
    ClassResourceInfo cri = bean.getServiceFactory().getClassResourceInfo().get(0);
    Set<String> names = cri.getNameBindings();
    assertEquals(Collections.singleton(CustomNameBinding.class.getName()), names);
}
 
Example 10
Source File: AbstractSpringComponentScanServer.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected JAXRSServerFactoryBean createFactoryBeanFromApplication(Application app) {
    return ResourceUtils.createApplication(app, false, true, false, getBus());
}