Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setProviders()
The following examples show how to use
org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setProviders() .
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 |
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: JAXRSClientServerStreamingTest.java From cxf with Apache License 2.0 | 6 votes |
protected void run() { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookStore.class); sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore())); JAXBElementProvider<?> p1 = new JAXBElementProvider<>(); p1.setEnableBuffering(true); p1.setEnableStreaming(true); JAXBElementProvider<?> p2 = new CustomJaxbProvider(); p2.setProduceMediaTypes(Collections.singletonList("text/xml")); List<Object> providers = new ArrayList<>(); providers.add(p1); providers.add(p2); sf.setProviders(providers); sf.setAddress("http://localhost:" + PORT + "/"); Map<String, Object> properties = new HashMap<>(); properties.put("org.apache.cxf.serviceloader-context", "true"); sf.setProperties(properties); sf.create(); }
Example 3
Source File: WebServiceConfig.java From jwala with Apache License 2.0 | 6 votes |
@Bean public Server getJaxRestServer(final GroupServiceRest groupServiceRest, final JvmServiceRest jvmServiceRest) { final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); factory.setAddress("/v2.0"); final List<Object> serviceBeans = new ArrayList<>(); serviceBeans.add(groupServiceRest); serviceBeans.add(jvmServiceRest); factory.setServiceBeans(serviceBeans); List<Object> providers = new ArrayList<>(); providers.add(getJacksonJsonProvider()); providers.add(getInternalServerErrorHandler()); factory.setProviders(providers); return factory.create(); }
Example 4
Source File: SyncopeCoreTestingServer.java From syncope with Apache License 2.0 | 6 votes |
@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 5
Source File: CxfServerBean.java From bamboobsc with Apache License 2.0 | 6 votes |
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 6
Source File: JAXRSCdiResourceExtension.java From cxf with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: CXFNonSpringJaxrsServlet.java From JaxRSProviders with Apache License 2.0 | 5 votes |
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 8
Source File: UDDIInquiryJAXRSTest.java From juddi with Apache License 2.0 | 5 votes |
private static void startServer() throws Exception { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(UDDIInquiryJAXRS.class); List<Object> providers = new ArrayList<Object>(); // add custom providers if any providers.add(new org.apache.cxf.jaxrs.provider.JAXBElementProvider()); Map<String, Object> properties = new HashMap<String, Object>(); // Create a mapping between the XML namespaces and the JSON prefixes. // The JSON prefix can be "" to specify that you don't want any prefix. HashMap<String, String> nstojns = new HashMap<String, String>(); nstojns.put("urn:uddi-org:api_v3", "urn:uddi-org:api_v3"); nstojns.put("urn:uddi-org:sub_v3", "urn:uddi-org:sub_v3"); nstojns.put("urn:uddi-org:custody_v3", "urn:uddi-org:custody_v3"); nstojns.put("urn:uddi-org:repl_v3", "urn:uddi-org:repl_v3"); nstojns.put("urn:uddi-org:subr_v3", "urn:uddi-org:subr_v3"); nstojns.put("urn:uddi-org:repl_v3", "urn:uddi-org:repl_v3"); nstojns.put("urn:uddi-org:vs_v3", "urn:uddi-org:vs_v3"); nstojns.put("urn:uddi-org:vscache_v3", "urn:uddi-org:vscache_v3"); nstojns.put("urn:uddi-org:policy_v3", "urn:uddi-org:policy_v3"); nstojns.put("urn:uddi-org:policy_instanceParms_v3", "urn:uddi-org:policy_instanceParms_v3"); nstojns.put("http://www.w3.org/2000/09/xmldsig#", "http://www.w3.org/2000/09/xmldsig#"); properties.put("namespaceMap", nstojns); JSONProvider jsonProvider = new org.apache.cxf.jaxrs.provider.json.JSONProvider(); jsonProvider.setNamespaceMap(nstojns); providers.add(jsonProvider); sf.setProviders(providers); sf.setResourceProvider(UDDIInquiryJAXRS.class, new SingletonResourceProvider(new UDDIInquiryJAXRS(), true)); sf.setAddress(ENDPOINT_ADDRESS); server = sf.create(); }
Example 9
Source File: AbstractSpringComponentScanServer.java From cxf with Apache License 2.0 | 5 votes |
protected void setJaxrsResources(JAXRSServerFactoryBean factory) { Set<String> componentScanPackagesSet = parseSetProperty(componentScanPackages); Set<String> componentScanBeansSet = parseSetProperty(componentScanBeans); for (String beanName : applicationContext.getBeanDefinitionNames()) { if (isValidComponent(beanName, Path.class, componentScanPackagesSet, componentScanBeansSet)) { SpringResourceFactory resourceFactory = new SpringResourceFactory(beanName); resourceFactory.setApplicationContext(applicationContext); resourceProviders.add(resourceFactory); } else if (isValidComponent(beanName, Provider.class, componentScanPackagesSet, componentScanBeansSet)) { jaxrsProviders.add(getProviderBean(beanName)); } else if (isValidComponent(beanName, org.apache.cxf.annotations.Provider.class, componentScanPackagesSet, componentScanBeansSet)) { addCxfProvider(getProviderBean(beanName)); } } if (!StringUtils.isEmpty(classesScanPackages)) { try { final Map< Class< ? extends Annotation >, Collection< Class< ? > > > classes = ClasspathScanner.findClasses(classesScanPackages, Provider.class, org.apache.cxf.annotations.Provider.class); jaxrsProviders.addAll(JAXRSServerFactoryBeanDefinitionParser .createBeansFromDiscoveredClasses(applicationContext, classes.get(Provider.class), null)); warnIfDuplicatesAvailable(jaxrsProviders); addCxfProvidersFromClasses(classes.get(org.apache.cxf.annotations.Provider.class)); } catch (Exception ex) { throw new ServiceConstructionException(ex); } } factory.setResourceProviders(getResourceProviders()); factory.setProviders(getJaxrsProviders()); setFactoryCxfProviders(factory); }
Example 10
Source File: CoffeeConfig.java From micro-integrator with Apache License 2.0 | 5 votes |
@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 11
Source File: MusicConfig.java From product-ei with Apache License 2.0 | 5 votes |
@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 12
Source File: CoffeeConfig.java From product-ei with Apache License 2.0 | 5 votes |
@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 13
Source File: CXFNonSpringJaxrsServlet.java From cxf with Apache License 2.0 | 5 votes |
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 14
Source File: AppConfig.java From service-autodiscovery with Apache License 2.0 | 5 votes |
@Bean @DependsOn( "cxf" ) public Server jaxRsServer() { JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class ); factory.setServiceBeans( Arrays.< Object >asList( peopleRestService() ) ); factory.setAddress( factory.getAddress() ); factory.setProviders( Arrays.< Object >asList( jsonProvider() ) ); return factory.create(); }
Example 15
Source File: CustomerConfig.java From micro-integrator with Apache License 2.0 | 5 votes |
@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 16
Source File: BookServer20.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { Bus bus = BusFactory.getDefaultBus(); setBus(bus); JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setBus(bus); sf.setResourceClasses(BookStore.class); List<Object> providers = new ArrayList<>(); providers.add(new PreMatchContainerRequestFilter2()); providers.add(new PreMatchContainerRequestFilter()); providers.add(new PostMatchContainerResponseFilter()); providers.add((Feature) context -> { context.register(new PostMatchContainerResponseFilter3()); return true; }); providers.add(new PostMatchContainerResponseFilter2()); providers.add(new CustomReaderBoundInterceptor()); providers.add(new CustomReaderInterceptor()); providers.add(new CustomWriterInterceptor()); providers.add(new CustomDynamicFeature()); providers.add(new PostMatchContainerRequestFilter()); providers.add(new FaultyContainerRequestFilter()); providers.add(new PreMatchReplaceStreamOrAddress()); providers.add(new ServerTestFeature()); providers.add(new JacksonJaxbJsonProvider()); providers.add(new IOExceptionMapper()); sf.setApplication(new Application()); sf.setProviders(providers); sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true)); sf.setAddress("http://localhost:" + PORT + "/"); server = sf.create(); BusFactory.setDefaultBus(null); BusFactory.setThreadDefaultBus(null); }
Example 17
Source File: ResourceUtils.java From cxf with Apache License 2.0 | 4 votes |
@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; }
Example 18
Source File: CXFNonSpringJaxrsServlet.java From JaxRSProviders with Apache License 2.0 | 4 votes |
@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.setFeatures(features); bean.create(); }
Example 19
Source File: DPCXFNonSpringJaxrsServlet.java From JaxRSProviders with Apache License 2.0 | 4 votes |
@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 20
Source File: CXFNonSpringJaxrsServlet.java From cxf with Apache License 2.0 | 4 votes |
@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(); }