Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setBus()
The following examples show how to use
org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setBus() .
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: AbstractSpringConfigurationFactory.java From cxf with Apache License 2.0 | 6 votes |
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 2
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 3
Source File: CXFNonSpringJaxrsServlet.java From cxf 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.getFeatures().addAll(features); bean.setBus(getBus()); bean.setApplication(getApplication()); bean.create(); }
Example 4
Source File: CxfConfig.java From coditori with Apache License 2.0 | 5 votes |
@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 5
Source File: JaxRsTestActivator.java From cxf with Apache License 2.0 | 5 votes |
@Override protected Server createServer() { Bus bus = BusFactory.newInstance().createBus(); bus.setExtension(JaxRsTestActivator.class.getClassLoader(), ClassLoader.class); JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setBus(bus); sf.setResourceClasses(BookStore.class); sf.setAddress("/jaxrs"); return sf.create(); }
Example 6
Source File: CompletableFutureServer.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(CompletableFutureService.class); sf.setResourceProvider(CompletableFutureService.class, new SingletonResourceProvider(new CompletableFutureService(), true)); sf.setAddress("http://localhost:" + PORT + "/"); sf.setProvider(new MappedExceptionMapper()); server = sf.create(); BusFactory.setDefaultBus(null); BusFactory.setThreadDefaultBus(null); }
Example 7
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 8
Source File: BookCxfContinuationServlet3Server.java From cxf with Apache License 2.0 | 5 votes |
private JAXRSServerFactoryBean serverFactory(Bus bus) { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setBus(bus); sf.setResourceClasses(BookCxfContinuationStore.class); sf.setResourceProvider(BookCxfContinuationStore.class, new SingletonResourceProvider(new BookCxfContinuationStore())); sf.setAddress("/"); return sf; }
Example 9
Source File: BookServerWebSocket.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(BookStoreWebSocket.class, BookStorePerRequest.class); sf.setProvider(new StreamingResponseProvider<Book>()); sf.setResourceProvider(BookStoreWebSocket.class, new SingletonResourceProvider(new BookStoreWebSocket(), true)); sf.setAddress("ws://localhost:" + port + "/websocket"); server = sf.create(); BusFactory.setDefaultBus(null); BusFactory.setThreadDefaultBus(null); }
Example 10
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 11
Source File: BookServerAsyncClient.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); sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true)); sf.setAddress("http://localhost:" + PORT + "/"); sf.setProvider(new BooleanReaderWriter()); sf.getProperties(true).put("default.content.type", "*/*"); server = sf.create(); BusFactory.setDefaultBus(null); BusFactory.setThreadDefaultBus(null); }
Example 12
Source File: SampleRestApplication.java From cxf with Apache License 2.0 | 5 votes |
@Bean public Server rsServer() { JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); endpoint.setBus(bus); endpoint.setServiceBeans(Arrays.<Object>asList(new HelloServiceImpl1(), new HelloServiceImpl2())); endpoint.setAddress("/"); endpoint.setFeatures(Arrays.asList(createOpenApiFeature(), new LoggingFeature())); return endpoint.create(); }
Example 13
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 14
Source File: CxfConfig.java From coditori with Apache License 2.0 | 5 votes |
@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 15
Source File: CxfRsHttpListener.java From tomee with Apache License 2.0 | 5 votes |
private JAXRSServerFactoryBean newFactory(final String prefix, final String service, final String endpoint) { final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean() { @Override protected Endpoint createEndpoint() throws BusException, EndpointException { final Endpoint created = super.createEndpoint(); created.put(ManagedEndpoint.SERVICE_NAME, service); created.put(ManagedEndpoint.ENDPOINT_NAME, endpoint); return created; } }; factory.setDestinationFactory(transportFactory); factory.setBus(CxfUtil.getBus()); factory.setAddress(prefix); return factory; }
Example 16
Source File: RESTServiceExporter.java From rice with Educational Community License v2.0 | 4 votes |
/** * This publishes the cxf service onto the cxf bus. * * @param serviceImpl * @throws Exception */ @Override public void publishService(ServiceDefinition serviceDefinition, Object serviceImpl, String address) { RestServiceDefinition restServiceDef = (RestServiceDefinition)serviceDefinition; LOG.info("Creating JAXRSService " + restServiceDef.getServiceName()); JAXRSServerFactoryBean svrFactory = new JAXRSServerFactoryBean(); svrFactory.setBus(getCXFBus()); List<Object> resources = restServiceDef.getResources(); if (resources != null && !resources.isEmpty()) { svrFactory.setServiceBeans(resources); } else { try { Class<?> resourceClass = this.getClass().getClassLoader().loadClass(restServiceDef.getResourceClass()); svrFactory.setResourceClasses(resourceClass); svrFactory.setResourceProvider(resourceClass, new SingletonResourceProvider(serviceImpl)); } catch (ClassNotFoundException e) { throw new RiceRuntimeException("Failed to publish the service because resource class could not be loaded: " + restServiceDef.getResourceClass(), e); } } svrFactory.setServiceName(restServiceDef.getServiceName()); svrFactory.setAddress(address); svrFactory.setExtensionMappings(restServiceDef.getExtensionMappings()); svrFactory.setLanguageMappings(restServiceDef.getLanguageMappings()); List<Object> providers = restServiceDef.getProviders(); if (providers != null) { svrFactory.setProviders(providers); } BindingFactoryManager bindingFactoryManager = getCXFBus().getExtension(BindingFactoryManager.class); JAXRSBindingFactory bindingFactory = new JAXRSBindingFactory(); bindingFactory.setBus(getCXFBus()); bindingFactoryManager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, bindingFactory); //Set logging interceptors if (LOG.isDebugEnabled()) { svrFactory.getInInterceptors().add(new LoggingInInterceptor()); } // svrFactory.getInInterceptors().add(new RESTConnector.VerifyingInInterceptor()); if (LOG.isDebugEnabled()) { svrFactory.getOutInterceptors().add(new LoggingOutInterceptor()); } // svrFactory.getOutInterceptors().add(new RESTConnector.SigningOutInterceptor()); svrFactory.setPublishedEndpointUrl(restServiceDef.getEndpointUrl().toExternalForm()); svrFactory.create(); }
Example 17
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 18
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 19
Source File: BookServer.java From cxf with Apache License 2.0 | 4 votes |
protected void run() { Bus bus = BusFactory.getDefaultBus(); bus.setProperty(ExceptionMapper.class.getName(), new BusMapperExceptionMapper()); setBus(bus); JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setBus(bus); sf.setResourceClasses(BookStore.class, SimpleBookStore.class, BookStorePerRequest.class); List<Object> providers = new ArrayList<>(); //default lifecycle is per-request, change it to singleton BinaryDataProvider<Object> p = new BinaryDataProvider<>(); p.setProduceMediaTypes(Collections.singletonList("application/bar")); p.setEnableBuffering(true); p.setReportByteArraySize(true); providers.add(p); providers.add(new BookStore.PrimitiveIntArrayReaderWriter()); providers.add(new BookStore.PrimitiveDoubleArrayReaderWriter()); providers.add(new BookStore.StringArrayBodyReaderWriter()); providers.add(new BookStore.StringListBodyReaderWriter()); providers.add(new StreamingResponseProvider<Object>()); providers.add(new ContentTypeModifyingMBW()); JAXBElementProvider<?> jaxbProvider = new JAXBElementProvider<>(); Map<String, String> jaxbElementClassMap = new HashMap<>(); jaxbElementClassMap.put(BookNoXmlRootElement.class.getName(), "BookNoXmlRootElement"); jaxbProvider.setJaxbElementClassMap(jaxbElementClassMap); providers.add(jaxbProvider); providers.add(new FormatResponseHandler()); providers.add(new GenericHandlerWriter()); providers.add(new FaultyRequestHandler()); providers.add(new SearchContextProvider()); providers.add(new QueryContextProvider()); providers.add(new BlockingRequestFilter()); providers.add(new FaultyResponseFilter()); providers.add(new BlockedExceptionMapper()); providers.add(new ParamConverterImpl()); sf.setProviders(providers); List<Interceptor<? extends Message>> inInts = new ArrayList<>(); inInts.add(new CustomInFaultyInterceptor()); inInts.add(new LoggingInInterceptor()); sf.setInInterceptors(inInts); List<Interceptor<? extends Message>> outInts = new ArrayList<>(); outInts.add(new CustomOutInterceptor()); outInts.add(new LoggingOutInterceptor()); sf.setOutInterceptors(outInts); List<Interceptor<? extends Message>> outFaultInts = new ArrayList<>(); outFaultInts.add(new CustomOutFaultInterceptor()); sf.setOutFaultInterceptors(outFaultInts); sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true)); sf.setAddress("http://localhost:" + PORT + "/"); sf.getProperties(true).put("org.apache.cxf.jaxrs.mediaTypeCheck.strict", true); sf.getProperties().put("search.visitor", new SQLPrinterVisitor<SearchBean>("books")); sf.getProperties().put("org.apache.cxf.http.header.split", true); sf.getProperties().put("default.content.type", "*/*"); sf.getProperties().putAll(properties); server = sf.create(); BusFactory.setDefaultBus(null); BusFactory.setThreadDefaultBus(null); }
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(); }