org.apache.cxf.jaxrs.JAXRSServerFactoryBean Java Examples
The following examples show how to use
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.
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: MultipartServer.java From cxf with Apache License 2.0 | 6 votes |
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 #2
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 #3
Source File: CXFNonSpringJaxrsServlet.java From JaxRSProviders with Apache License 2.0 | 6 votes |
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 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 #5
Source File: BrooklynRestResourceTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
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 File: CsrfTokenFilterTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@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 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 #8
Source File: SyncopeCoreTestingServer.java From syncope with Apache License 2.0 | 6 votes |
@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 File: JAXRSLocalTransportTest.java From cxf with Apache License 2.0 | 6 votes |
@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 #10
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 #11
Source File: JAXRSUtilsTest.java From cxf with Apache License 2.0 | 6 votes |
@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 #12
Source File: OpenTracingTracingTest.java From cxf with Apache License 2.0 | 6 votes |
@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 #13
Source File: BraveTracingTest.java From cxf with Apache License 2.0 | 6 votes |
@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 #14
Source File: JAXRSClientServerTikaTest.java From cxf with Apache License 2.0 | 6 votes |
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 #15
Source File: AbstractJaxrsClassesScanServer.java From cxf with Apache License 2.0 | 6 votes |
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 #16
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 #17
Source File: Server.java From cxf with Apache License 2.0 | 5 votes |
protected Server() throws Exception { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(CustomerServiceImpl.class); sf.setResourceProvider(CustomerServiceImpl.class, new SingletonResourceProvider(new CustomerServiceImpl())); sf.setAddress("https://localhost:9000/"); sf.create(); }
Example #18
Source File: StatsConfig.java From cxf with Apache License 2.0 | 5 votes |
@Bean @DependsOn("cxf") Server jaxRsServer() { final JAXRSServerFactoryBean factory = RuntimeDelegate .getInstance() .createEndpoint(new StatsApplication(), JAXRSServerFactoryBean.class); factory.setServiceBean(statsRestService); factory.setProvider(new JacksonJsonProvider()); return factory.create(); }
Example #19
Source File: AbstractStreamingResponseExtension.java From cxf with Apache License 2.0 | 5 votes |
@Override public final void customize(JAXRSServerFactoryBean bean) { bean.setInvoker(createInvoker(bean)); StreamingResponseProvider<Object> streamProvider = new StreamingResponseProvider<>(); streamProvider.setProduceMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON)); bean.setProvider(streamProvider); }
Example #20
Source File: JAXRSCdiResourceExtension.java From cxf with Apache License 2.0 | 5 votes |
/** * Look and apply the available JAXRSServerFactoryBean extensions to customize its * creation (f.e. add features, providers, assign transport, ...) * @param beanManager bean manager * @param bean JAX-RS server factory bean about to be created */ private void customize(final BeanManager beanManager, final JAXRSServerFactoryBean bean) { JAXRSServerFactoryCustomizationUtils.customize(bean); final Collection<Bean<?>> extensionBeans = beanManager.getBeans(JAXRSServerFactoryCustomizationExtension.class); for (final Bean<?> extensionBean: extensionBeans) { final JAXRSServerFactoryCustomizationExtension extension = (JAXRSServerFactoryCustomizationExtension)beanManager.getReference( extensionBean, JAXRSServerFactoryCustomizationExtension.class, createCreationalContext(beanManager, extensionBean) ); extension.customize(bean); } }
Example #21
Source File: JAXRSCdiResourceExtension.java From cxf with Apache License 2.0 | 5 votes |
/** * 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 #22
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 #23
Source File: JaxrsPathRegexTest.java From cxf with Apache License 2.0 | 5 votes |
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 #24
Source File: AbstractSwagger2ServiceDescriptionTest.java From cxf with Apache License 2.0 | 5 votes |
@Override protected void run() { final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookStoreSwagger2.class); sf.setResourceClasses(BookStoreStylesheetsSwagger2.class); sf.setResourceProvider(BookStoreSwagger2.class, new SingletonResourceProvider(new BookStoreSwagger2())); sf.setProvider(new JacksonJsonProvider()); final Swagger2Feature feature = createSwagger2Feature(); sf.setFeatures(Arrays.asList(feature)); sf.setAddress("http://localhost:" + port + "/"); sf.setExtensionMappings( Collections.singletonMap("json", "application/json;charset=UTF-8")); sf.create(); }
Example #25
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 #26
Source File: ReactiveIOCustomizer.java From cxf with Apache License 2.0 | 5 votes |
@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 #27
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 #28
Source File: SpringServletContextTest.java From cxf with Apache License 2.0 | 5 votes |
@Bean @DependsOn("cxf") public Server jaxRsServer() { final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); factory.setServiceBeans(Arrays.asList(contextRestService())); factory.setAddress("/services/context"); return factory.create(); }
Example #29
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 #30
Source File: AemWebServiceConfiguration.java From jwala with Apache License 2.0 | 5 votes |
@Bean public Server getV1JaxResServer() { final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); factory.setAddress("/v1.0"); factory.setServiceBeans(getV1ServiceBeans()); factory.setProviders(getV1Providers()); return factory.create(); }