Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setResourceClasses()
The following examples show how to use
org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setResourceClasses() .
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: 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 2
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 3
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 4
Source File: FormBehaviorTest.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(FormResource.class); sf.setProvider(new FormReaderInterceptor()); sf.setAddress("http://localhost:" + PORT + "/"); sf.create(); }
Example 5
Source File: BookCxfContinuationServer.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookCxfContinuationStore.class); sf.setResourceProvider(BookCxfContinuationStore.class, new SingletonResourceProvider(new BookCxfContinuationStore())); sf.setAddress("http://localhost:" + PORT + "/"); sf.create(); }
Example 6
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 7
Source File: Server.java From cxf with Apache License 2.0 | 5 votes |
protected Server(String[] args) throws Exception { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(StreamingService.class); String receiverType = args.length == 1 && "-receiverType=queue".equals(args[0]) ? "queue" : "string"; sf.setResourceProvider(StreamingService.class, new SingletonResourceProvider(new StreamingService(receiverType))); sf.setAddress("http://localhost:9000/spark"); sf.create(); }
Example 8
Source File: AbstractOpenApiServiceDescriptionTest.java From cxf with Apache License 2.0 | 5 votes |
@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 9
Source File: OpenApiNonAnnotatedServiceDescriptionTest.java From cxf with Apache License 2.0 | 5 votes |
@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 10
Source File: OpenApiCustomizerSubclassTest.java From cxf with Apache License 2.0 | 5 votes |
@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 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: Server.java From product-ei with Apache License 2.0 | 5 votes |
protected Server() throws Exception { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(CustomerService.class); sf.setResourceProvider(CustomerService.class, new SingletonResourceProvider(new CustomerService())); sf.setAddress("http://localhost:9000/"); sf.create(); }
Example 13
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 14
Source File: JaxrsHeaderPropagationTest.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(JaxrsResource.class); sf.setResourceProvider(JaxrsResource.class, new SingletonResourceProvider(new JaxrsResource())); sf.setAddress("http://localhost:" + PORT + "/"); sf.setPublishedEndpointUrl("/"); sf.create(); }
Example 15
Source File: LoggingServer.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(), false)); sf.setAddress("http://localhost:" + PORT + "/"); sf.getFeatures().add(new LoggingFeature()); sf.create(); }
Example 16
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 17
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 18
Source File: ClientCacheTest.java From cxf with Apache License 2.0 | 5 votes |
@BeforeClass public static void bind() throws Exception { final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(TheServer.class); sf.setResourceProvider(TheServer.class, new SingletonResourceProvider(new TheServer(), false)); sf.setTransportId(LocalTransportFactory.TRANSPORT_ID); sf.setAddress(ADDRESS); server = sf.create(); }
Example 19
Source File: AnyObjectServiceTest.java From syncope with Apache License 2.0 | 4 votes |
@BeforeEach public void setup() { if (SERVER == null) { AnyObjectDAO anyObjectDAO = mock(AnyObjectDAO.class); AnyObjectLogic logic = mock(AnyObjectLogic.class); when(logic.search(any(SearchCond.class), anyInt(), anyInt(), anyList(), anyString(), anyBoolean())). thenAnswer(ic -> { AnyObjectTO printer1 = new AnyObjectTO(); printer1.setKey(UUID.randomUUID().toString()); printer1.setName("printer1"); printer1.setType("PRINTER"); printer1.getPlainAttrs().add(new Attr.Builder("location").value("here").build()); AnyObjectTO printer2 = new AnyObjectTO(); printer2.setKey(UUID.randomUUID().toString()); printer2.setName("printer2"); printer2.setType("PRINTER"); printer2.getPlainAttrs().add(new Attr.Builder("location").value("there").build()); return Pair.of(2, Arrays.asList(printer1, printer2)); }); when(logic.create(any(AnyObjectCR.class), anyBoolean())).thenAnswer(ic -> { AnyObjectTO anyObjectTO = new AnyObjectTO(); EntityTOUtils.toAnyTO(ic.getArgument(0), anyObjectTO); anyObjectTO.setKey(UUID.randomUUID().toString()); ProvisioningResult<AnyObjectTO> result = new ProvisioningResult<>(); result.setEntity(anyObjectTO); return result; }); SearchCondVisitor searchCondVisitor = mock(SearchCondVisitor.class); when(searchCondVisitor.getQuery()).thenReturn(new SearchCond()); @SuppressWarnings("unchecked") SearchCondition<SearchBean> sc = mock(SearchCondition.class); doNothing().when(sc).accept(any()); SearchContext searchContext = mock(SearchContext.class); when(searchContext.getCondition(anyString(), eq(SearchBean.class))).thenReturn(sc); UriInfo uriInfo = mock(UriInfo.class); when(uriInfo.getAbsolutePathBuilder()).thenReturn(new UriBuilderImpl()); when(uriInfo.getQueryParameters()).thenReturn(new MetadataMap<>()); MessageContext messageContext = mock(MessageContext.class); MockHttpServletRequest httpRequest = new MockHttpServletRequest(); httpRequest.addHeader(RESTHeaders.NULL_PRIORITY_ASYNC, "false"); when(messageContext.getHttpServletRequest()).thenReturn(httpRequest); when(messageContext.getHttpServletResponse()).thenReturn(new MockHttpServletResponse()); Request request = mock(Request.class); when(request.evaluatePreconditions(any(Date.class))).thenReturn(Response.notModified()); when(messageContext.getRequest()).thenReturn(request); AnyObjectServiceImpl service = new AnyObjectServiceImpl(); ReflectionTestUtils.setField(service, "anyObjectDAO", anyObjectDAO); ReflectionTestUtils.setField(service, "logic", logic); ReflectionTestUtils.setField(service, "searchCondVisitor", searchCondVisitor); ReflectionTestUtils.setField(service, "searchContext", searchContext); ReflectionTestUtils.setField(service, "uriInfo", uriInfo); ReflectionTestUtils.setField(service, "messageContext", messageContext); JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setAddress(LOCAL_ADDRESS); sf.setResourceClasses(AnyObjectService.class); sf.setResourceProvider( AnyObjectService.class, new SingletonResourceProvider(service, true)); sf.setInInterceptors(Arrays.asList(gzipInInterceptor, validationInInterceptor)); sf.setOutInterceptors(Arrays.asList(gzipOutInterceptor)); sf.setProviders(Arrays.asList(dateParamConverterProvider, jsonProvider, xmlProvider, yamlProvider, exceptionMapper, searchContextProvider, addETagFilter)); SERVER = sf.create(); } assertNotNull(SERVER); }
Example 20
Source File: RestOrderServer.java From camelinaction2 with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { // create dummy backend DummyOrderService dummy = new DummyOrderService(); dummy.setupDummyOrders(); // create a Camel route that routes the REST services OrderRoute route = new OrderRoute(); route.setOrderService(dummy); // create CamelContext and add the route CamelContext camel = new DefaultCamelContext(); camel.addRoutes(route); // create a ProducerTemplate that the CXF REST service will use to integrate with Camel ProducerTemplate producer = camel.createProducerTemplate(); // create CXF REST service and inject the Camel ProducerTemplate // which we use to call the Camel route RestOrderService rest = new RestOrderService(); rest.setProducerTemplate(producer); // setup Apache CXF REST server on port 9000 JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(RestOrderService.class); sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest)); // to use jackson for json sf.setProvider(JacksonJsonProvider.class); sf.setAddress("http://localhost:9000/"); // create the CXF server Server server = sf.create(); // start Camel and CXF (non blocking) camel.start(); server.start(); // keep the JVM running Console console = System.console(); System.out.println("Server started on http://localhost:9000/"); System.out.println(""); // If you run the main class from IDEA/Eclipse then you may not have a console, which is null) if (console != null) { System.out.println(" Press ENTER to stop server"); console.readLine(); } else { System.out.println(" Stopping after 5 minutes or press ctrl + C to stop"); Thread.sleep(5 * 60 * 1000); } // stop Camel and CXF server camel.stop(); server.stop(); System.exit(0); }