Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean

The following examples show how to use org.apache.cxf.jaxrs.JAXRSServerFactoryBean. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: cxf   Source File: AbstractJaxrsClassesScanServer.java    License: Apache License 2.0 6 votes vote down vote up
protected void setJaxrsResources(JAXRSServerFactoryBean factory) {
    try {
        final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes =
            ClasspathScanner.findClasses(basePackages, Provider.class, Path.class);

        List<Object> jaxrsServices = JAXRSServerFactoryBeanDefinitionParser
            .createBeansFromDiscoveredClasses(super.applicationContext, classes.get(Path.class), null);
        List<Object> jaxrsProviders = JAXRSServerFactoryBeanDefinitionParser
            .createBeansFromDiscoveredClasses(super.applicationContext, classes.get(Provider.class), null);

        factory.setServiceBeans(jaxrsServices);
        factory.setProviders(jaxrsProviders);
    } catch (Exception ex) {
        throw new ServiceConstructionException(ex);
    }

}
 
Example 2
Source Project: bamboobsc   Source File: CxfServerBean.java    License: Apache License 2.0 6 votes vote down vote up
private static int publishRest(JAXRSServerFactoryBean sf, List<TbSysWsConfig> configs) {
	int c = 0;
	for (TbSysWsConfig config : configs) {
		if (!WSConfig.TYPE_REST.equals(config.getType())) {
			continue;
		}
		try {
			sf.setServiceBean(AppContext.getBean(config.getBeanId()));
			c++;				
		} catch (Exception e) {
			e.printStackTrace();
		}
	}		
	sf.setProviders(getProvider());
	sf.setAddress(WSConfig.getJAXRSServerFactoryBeanAddress());
	return c;
}
 
Example 3
Source Project: JaxRSProviders   Source File: CXFNonSpringJaxrsServlet.java    License: Apache License 2.0 6 votes vote down vote up
protected void setSchemasLocations(JAXRSServerFactoryBean bean, ServletConfig servletConfig) {
    String schemas = servletConfig.getInitParameter(SCHEMAS_PARAM);
    if (schemas == null) {
        return;
    }
    String[] locations = schemas.split(" ");
    List<String> list = new ArrayList<>();
    for (String loc : locations) {
        String theLoc = loc.trim();
        if (!theLoc.isEmpty()) {
            list.add(theLoc);
        }
    }
    if (!list.isEmpty()) {
        bean.setSchemaLocations(list);
    }
}
 
Example 4
Source Project: JaxRSProviders   Source File: CXFNonSpringJaxrsServlet.java    License: 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 5
Source Project: brooklyn-server   Source File: BrooklynRestResourceTest.java    License: 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 6
Source Project: brooklyn-server   Source File: CsrfTokenFilterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void configureCXF(JAXRSServerFactoryBean sf) {
    super.configureCXF(sf);
    
    /*
    TODO how can we turn on sessions??
    
    // normal handler way 
    val webapp = new ServletContextHandler(ServletContextHandler.SESSIONS)
    SessionHandler sh = new SessionHandler();
    webapp.setSessionHandler()

    try {
        // suggested bean way - but only for new servers 
        sf.getBus().getExtension(JettyHTTPServerEngineFactory.class) 
            .createJettyHTTPServerEngine(8000, "http") 
            .setSessionSupport(true);
    } catch (Exception e) {
        throw Exceptions.propagate(e);
    }
    */
}
 
Example 7
Source Project: syncope   Source File: SyncopeCoreTestingServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(final ContextRefreshedEvent event) {
    synchronized (ADDRESS) {
        if (serviceOps.list(NetworkService.Type.CORE).isEmpty()) {
            // 1. start (mocked) Core as embedded CXF
            JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
            sf.setAddress(ADDRESS);
            sf.setResourceClasses(WAClientAppService.class, GoogleMfaAuthTokenService.class);
            sf.setResourceProvider(
                    WAClientAppService.class,
                    new SingletonResourceProvider(new StubWAClientAppService(), true));
            sf.setResourceProvider(
                    GoogleMfaAuthTokenService.class,
                    new SingletonResourceProvider(new StubGoogleMfaAuthTokenService(), true));
            sf.setProviders(List.of(new JacksonJsonProvider()));
            sf.create();

            // 2. register Core in Keymaster
            NetworkService core = new NetworkService();
            core.setType(NetworkService.Type.CORE);
            core.setAddress(ADDRESS);
            serviceOps.register(core);
        }
    }
}
 
Example 8
Source Project: syncope   Source File: SyncopeCoreTestingServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(final ContextRefreshedEvent event) {
    if (AbstractTest.available(9080)) {
        // 1. start (mocked) Core as embedded CXF
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setAddress(ADDRESS);
        sf.setResourceClasses(SRARouteService.class);
        sf.setResourceProvider(SRARouteService.class,
                new SingletonResourceProvider(new StubSRARouteService(), true));
        sf.setProviders(List.of(new JacksonJsonProvider()));
        sf.create();

        // 2. register Core in Keymaster
        NetworkService core = new NetworkService();
        core.setType(NetworkService.Type.CORE);
        core.setAddress(ADDRESS);
        serviceOps.register(core);
    }
}
 
Example 9
Source Project: cxf   Source File: AbstractSpringConfigurationFactory.java    License: 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 10
Source Project: cxf   Source File: JAXRSLocalTransportTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class, BookStoreSpring.class);
    sf.setResourceProvider(BookStore.class,
                           new SingletonResourceProvider(new BookStore(), true));
    sf.setResourceProvider(BookStoreSpring.class,
                           new SingletonResourceProvider(new BookStoreSpring(), true));
    sf.setProvider(new JacksonJsonProvider());
    List<Interceptor<? extends Message>> outInts = new ArrayList<>();
    outInts.add(new CustomOutInterceptor());
    sf.setOutInterceptors(outInts);

    List<Interceptor<? extends Message>> inInts = new ArrayList<>();
    inInts.add(new CustomInFaultyInterceptor());
    sf.setInInterceptors(inInts);

    sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
    sf.setAddress("local://books");
    localServer = sf.create();
}
 
Example 11
Source Project: cxf   Source File: CXFNonSpringJaxrsServlet.java    License: 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 12
Source Project: cxf   Source File: JAXRSUtilsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInjectCustomContext() throws Exception {
    final CustomerContext contextImpl = new CustomerContext() {

        public String get() {
            return "customerContext";
        }

    };
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    Customer customer = new Customer();
    sf.setServiceBeanObjects(customer);
    sf.setProvider(new ContextProvider<CustomerContext>() {
        public CustomerContext createContext(Message message) {
            return contextImpl;
        }
    });
    sf.setStart(false);
    Server s = sf.create();
    assertTrue(customer.getCustomerContext() instanceof ThreadLocalProxy<?>);
    invokeCustomerMethod(sf.getServiceFactory().getClassResourceInfo().get(0),
                         customer, s);
    CustomerContext context = customer.getCustomerContext();
    assertEquals("customerContext", context.get());
}
 
Example 13
Source Project: cxf   Source File: OpenTracingTracingTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void run() {
    final Tracer tracer = new JaegerTracer.Builder("tracer-jaxrs")
        .withSampler(new ConstSampler(true))
        .withReporter(REPORTER)
        .build();

    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore<Scope>()));
    sf.setAddress("http://localhost:" + PORT);
    sf.setProvider(new JacksonJsonProvider());
    sf.setProvider(new OpenTracingFeature(tracer));
    sf.setProvider(new NullPointerExceptionMapper());
    server = sf.create();
}
 
Example 14
Source Project: cxf   Source File: BraveTracingTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void run() {
    final Tracing brave = Tracing
            .newBuilder()
            .spanReporter(new TestSpanReporter())
            .build();

    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore<TraceScope>()));
    sf.setAddress("http://localhost:" + PORT);
    sf.setProvider(new JacksonJsonProvider());
    sf.setProvider(new BraveFeature(brave));
    sf.setProvider(new NullPointerExceptionMapper());
    server = sf.create();
}
 
Example 15
Source Project: cxf   Source File: JAXRSClientServerTikaTest.java    License: Apache License 2.0 6 votes vote down vote up
protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();

    final Map< String, Object > properties = new HashMap<>();
    properties.put("search.query.parameter.name", "$filter");
    properties.put("search.parser", new FiqlParser< SearchBean >(SearchBean.class));
    properties.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy/MM/dd");

    sf.setResourceClasses(BookCatalog.class);
    sf.setResourceProvider(BookCatalog.class, new SingletonResourceProvider(new BookCatalog()));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.setProperties(properties);
    sf.setProvider(new MultipartProvider());
    sf.setProvider(new SearchContextProvider());
    sf.setProvider(new JacksonJsonProvider());

    sf.create();
}
 
Example 16
Source Project: cxf   Source File: MultipartServer.java    License: Apache License 2.0 6 votes vote down vote up
protected void run() {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(MultipartStore.class);

    Map<String, Object> props = new HashMap<>();
    props.put(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, String.valueOf(1024 * 10));
    props.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, String.valueOf(1024 * 5));
    props.put(AttachmentDeserializer.ATTACHMENT_MAX_HEADER_SIZE, String.valueOf(400));
    sf.setProperties(props);
    //default lifecycle is per-request, change it to singleton
    sf.setResourceProvider(MultipartStore.class,
                           new SingletonResourceProvider(new MultipartStore()));
    sf.setAddress("http://localhost:" + PORT + "/");

    server = sf.create();
}
 
Example 17
Source Project: micro-integrator   Source File: CoffeeConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public org.apache.cxf.endpoint.Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance()
            .createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
    factory.setServiceBeans(Arrays.<Object>asList(starbucksOutletService()));
    factory.setAddress("/" + factory.getAddress());
    List<Object> providers = new ArrayList<Object>();
    providers.add(jsonProvider());
    providers.add(new OrderReader());
    factory.setProviders(providers);
    //factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
    return factory.create();
}
 
Example 18
Source Project: micro-integrator   Source File: MusicConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance()
            .createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
    factory.setServiceBeans(Arrays.<Object>asList(musicRestService()));
    factory.setAddress("/" + factory.getAddress());
    factory.setProviders(Arrays.<Object>asList(jsonProvider()));
    return factory.create();
}
 
Example 19
Source Project: micro-integrator   Source File: CustomerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public org.apache.cxf.endpoint.Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance()
            .createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
    factory.setServiceBeans(Arrays.<Object>asList(customerService()));
    factory.setAddress("/" + factory.getAddress());
    factory.setProviders(Arrays.<Object>asList(jsonProvider()));
    return factory.create();
}
 
Example 20
Source Project: cxf   Source File: ReactiveIOCustomizer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Invoker createInvoker(JAXRSServerFactoryBean bean) {
    Boolean useStreamingSubscriber = (Boolean)bean.getProperties(true)
            .getOrDefault("useStreamingSubscriber", null);
    ReactiveIOInvoker invoker = new ReactiveIOInvoker();
    if (useStreamingSubscriber != null) {
        invoker.setUseStreamingSubscriberIfPossible(useStreamingSubscriber);
    }
    return invoker;
}
 
Example 21
Source Project: jwala   Source File: AemWebServiceConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public Server getV1JaxResServer() {
    final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
    factory.setAddress("/v1.0");
    factory.setServiceBeans(getV1ServiceBeans());
    factory.setProviders(getV1Providers());
    return factory.create();
}
 
Example 22
Source Project: cxf   Source File: JaxrsPathRegexTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void run() {
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    sf.setResourceProvider(BookStore.class,
        new SingletonResourceProvider(new BookStore()));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.setPublishedEndpointUrl("/");
    sf.create();
}
 
Example 23
@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 24
Source Project: coditori   Source File: CxfConfig.java    License: 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 25
Source Project: coditori   Source File: CxfConfig.java    License: 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 26
Source Project: product-ei   Source File: CoffeeConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
 public org.apache.cxf.endpoint.Server jaxRsServer() {
     JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
     factory.setServiceBeans( Arrays.< Object >asList(starbucksOutletService()) );
     factory.setAddress( "/" + factory.getAddress() );
List<Object> providers = new ArrayList<Object>();
     providers.add(jsonProvider());
     providers.add(new OrderReader());
     factory.setProviders(providers);
     //factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
     return factory.create();
 }
 
Example 27
Source Project: cxf   Source File: RxJava3ObservableServer.java    License: Apache License 2.0 5 votes vote down vote up
protected void run() {
    Bus bus = BusFactory.getDefaultBus();
    // Make sure default JSONProvider is not loaded
    bus.setProperty("skip.default.json.provider.registration", true);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setInvoker(new ReactiveIOInvoker());
    sf.setProvider(new JacksonJsonProvider());
    sf.getOutInterceptors().add(new LoggingOutInterceptor());
    sf.setResourceClasses(RxJava3ObservableService.class);
    sf.setResourceProvider(RxJava3ObservableService.class,
                           new SingletonResourceProvider(new RxJava3ObservableService(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    server = sf.create();
}
 
Example 28
Source Project: cxf   Source File: ClassResourceInfoTest.java    License: 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 29
Source Project: cxf   Source File: AbstractOpenApiServiceDescriptionTest.java    License: 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 30
Source Project: cxf   Source File: Server.java    License: Apache License 2.0 5 votes vote down vote up
private void createEndpoint(String address) {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), false));
    sf.setAddress(address);
    servers.add(sf.create());
}