Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setFeatures()

The following examples show how to use org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setFeatures() . 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: Swagger2NonAnnotatedServiceDescriptionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    sf.setResourceClasses(BookStoreStylesheetsSwagger2.class);
    sf.setResourceProvider(BookStore.class,
        new SingletonResourceProvider(new BookStore()));
    sf.setProvider(new JacksonJsonProvider());
    final Swagger2Feature feature = createSwagger2Feature();
    //FIXME swagger-jaxrs 1.5.3 can't handle a self-recursive subresource like Book
    // so we need to exclude "org.apache.cxf.systest.jaxrs" for now.
    feature.setResourcePackage("org.apache.cxf.systest.jaxrs.description.group1");
    feature.setScanAllResources(true);
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + port + "/");
    sf.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: AbstractSpringConfigurationFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server createJaxRsServer() {

        JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
        factory.setAddress(getAddress());
        factory.setTransportId(getTransportId());
        factory.setBus(getBus());

        setJaxrsResources(factory);

        factory.setInInterceptors(getInInterceptors());
        factory.setOutInterceptors(getOutInterceptors());
        factory.setOutFaultInterceptors(getOutFaultInterceptors());
        factory.setFeatures(getFeatures());
        if (!StringUtils.isEmpty(jaxrsExtensions)) {
            factory.setExtensionMappings(CastUtils.cast((Map<?, ?>)parseMapSequence(jaxrsExtensions)));
        }
        finalizeFactorySetup(factory);
        return factory.create();
    }
 
Example 4
Source File: Server.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server() throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(JaxrsODataService.class);
    sf.setResourceProvider(JaxrsODataService.class,
        new SingletonResourceProvider(new JaxrsODataService()));
    sf.setFeatures(Collections.singletonList(new LoggingFeature()));
    sf.setAddress("http://localhost:9000/DemoService");

    sf.create();
}
 
Example 5
Source File: OpenApiContextBasedConfigApplicationOnlyTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void createServerFactory(final String context, final String description, final Class<?> resource) {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setApplication(new Application() {
        @Override
        public Set<Class<?>> getClasses() {
            return Collections.singleton(resource);
        }
    });
    sf.setResourceClasses(resource);
    sf.setProvider(new JacksonJsonProvider());
    final OpenApiFeature feature = createOpenApiFeature(description, resource);
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + PORT + context);
    sf.create();
}
 
Example 6
Source File: OpenApiCustomizerSubclassTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStoreOpenApi.class);
    sf.setResourceClasses(BookStoreStylesheetsOpenApi.class);
    sf.setResourceProvider(BookStoreOpenApi.class,
        new SingletonResourceProvider(new BookStoreOpenApi()));
    sf.setProvider(new JacksonJsonProvider());
    final OpenApiFeature feature = createOpenApiFeature();
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + port + "/");
    sf.create();
}
 
Example 7
Source File: AbstractOpenApiServiceDescriptionTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStoreOpenApi.class);
    sf.setResourceClasses(BookStoreStylesheetsOpenApi.class);
    sf.setResourceProvider(BookStoreOpenApi.class,
        new SingletonResourceProvider(new BookStoreOpenApi()));
    sf.setProvider(new JacksonJsonProvider());
    final OpenApiFeature feature = createOpenApiFeature();
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + port + "/");
    sf.create();
}
 
Example 8
Source File: SwaggerToOpenApiConversionTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStoreSwagger2.class);
    sf.setResourceProvider(BookStoreSwagger2.class,
        new SingletonResourceProvider(new BookStoreSwagger2()));
    sf.setProvider(new SwaggerToOpenApiConversionFilter());
    final Swagger2Feature feature = createSwagger2Feature();
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.create();
}
 
Example 9
Source File: SwaggerUiConfigurationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStoreSwagger2.class);
    sf.setResourceProvider(BookStoreSwagger2.class,
        new SingletonResourceProvider(new BookStoreSwagger2()));
    sf.setProvider(new JacksonJsonProvider());
    final Swagger2Feature feature = new Swagger2Feature();
    feature.setRunAsFilter(false);
    feature.setSwaggerUiConfig(new SwaggerUiConfig().url("/swagger.json"));
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.create();
}
 
Example 10
Source File: RESTLoggingTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Server createService(String serviceURI, Object serviceImpl, LoggingFeature loggingFeature) {
    JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
    factory.setAddress(serviceURI);
    factory.setFeatures(Collections.singletonList(loggingFeature));
    factory.setServiceBean(serviceImpl);
    factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    return factory.create();
}
 
Example 11
Source File: JAXRSServerMetricsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookLibrary.class);
    sf.setResourceProvider(BookLibrary.class, new SingletonResourceProvider(new BookLibrary()));
    sf.setFeatures(Arrays.asList(new MetricsFeature(provider)));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.setProvider(new JacksonJsonProvider());
    sf.create();
}
 
Example 12
Source File: AppConfig.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Bean
org.apache.cxf.endpoint.Server server() {
    final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean ();
    factory.setFeatures(Arrays.asList(openApiFeature()));
    factory.setServiceBean(sampleResource());
    factory.setAddress("http://localhost:9000/");
    factory.setProvider(new JsonbJaxrsProvider<>());
    return factory.create();
}
 
Example 13
Source File: OpenApiNonAnnotatedServiceDescriptionTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    sf.setResourceClasses(BookStoreStylesheetsOpenApi.class);
    sf.setResourceProvider(BookStore.class,
        new SingletonResourceProvider(new BookStore()));
    sf.setProvider(new JacksonJsonProvider());
    final OpenApiFeature feature = createOpenApiFeature();
    feature.setResourcePackages(Collections.singleton("org.apache.cxf.systest.jaxrs.description.group1"));
    feature.setReadAllResources(true);
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + port + "/");
    sf.create();
}
 
Example 14
Source File: OpenApiCustomizerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    final JAXRSServerFactoryBean sf = RuntimeDelegate
        .getInstance()
        .createEndpoint(new BookStoreApplication(), JAXRSServerFactoryBean.class);
    sf.setResourceClasses(BookStoreOpenApi.class);
    sf.setResourceClasses(BookStoreStylesheetsOpenApi.class);
    sf.setResourceProvider(BookStoreOpenApi.class,
        new SingletonResourceProvider(new BookStoreOpenApi()));
    sf.setProvider(new JacksonJsonProvider());
    final OpenApiFeature feature = createOpenApiFeature();
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + port + "/api");
    sf.create();
}
 
Example 15
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 16
Source File: OpenApiContextBasedConfigTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void createServerFactory(final String context, final String description, final Class<?> resource) {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(resource);
    sf.setProvider(new JacksonJsonProvider());
    final OpenApiFeature feature = createOpenApiFeature(description, resource);
    sf.setFeatures(Arrays.asList(feature));
    sf.setAddress("http://localhost:" + PORT + context);
    sf.create();
}
 
Example 17
Source File: CxfConfig.java    From coditori with Apache License 2.0 5 votes vote down vote up
@Bean
public Server rsServer() {
    final JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setProvider(new JacksonJsonProvider());
    endpoint.setBus(bus);
    endpoint.setAddress("/");
    endpoint.setServiceBeans(Arrays.<Object>asList(userController()));
    endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
    return endpoint.create();
}
 
Example 18
Source File: CxfConfig.java    From coditori with Apache License 2.0 5 votes vote down vote up
@Bean
public Server rsServer() {
	final JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
	endpoint.setProvider(new JacksonJsonProvider());
	endpoint.setProvider(getExceptionHandler());
	endpoint.setBus(bus);
	endpoint.setAddress("/");
	endpoint.setServiceBeans(Arrays.<Object>asList(indexController(), userController()));
	endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
	return endpoint.create();
}
 
Example 19
Source File: WebServicesConfiguration.java    From microservices-transactions-tcc with Apache License 2.0 4 votes vote down vote up
@Bean
public Server rsServer() {
    JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setAddress("/");
    endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new ExceptionRestHandler()));
    
    Map<Object, Object> mappings = new HashMap<Object, Object>();
    mappings.put("json", "application/json");
    endpoint.setExtensionMappings(mappings);
    
    Swagger2Feature swagger2Feature = new Swagger2Feature();
    swagger2Feature.setTitle(title);
    swagger2Feature.setDescription(description);
    swagger2Feature.setVersion(version);
    swagger2Feature.setContact(contact);
    swagger2Feature.setSchemes(schemes.split(","));
    swagger2Feature.setBasePath(basePath);
    swagger2Feature.setResourcePackage(resourcePackage);
    swagger2Feature.setPrettyPrint(prettyPrint);
    swagger2Feature.setScan(scan);
    
    endpoint.setFeatures(Arrays.asList(new LoggingFeature(), swagger2Feature));
    endpoint.setServiceBeans(Arrays.asList(tccCoordinatorService, compositeController));
    
    return endpoint.create();
}
 
Example 20
Source File: AbstractSpringComponentScanServer.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void setFactoryCxfProviders(JAXRSServerFactoryBean factory) {
    factory.setFeatures(getFeatures());
    factory.setInInterceptors(getInInterceptors());
    factory.setOutInterceptors(getOutInterceptors());
    factory.setOutFaultInterceptors(getOutFaultInterceptors());
}