Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setProvider()
The following examples show how to use
org.apache.cxf.jaxrs.JAXRSServerFactoryBean#setProvider() .
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: Swagger2NonAnnotatedServiceDescriptionTest.java From cxf with Apache License 2.0 | 6 votes |
@Override protected void run() { final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookStore.class); sf.setResourceClasses(BookStoreStylesheetsSwagger2.class); sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore())); sf.setProvider(new JacksonJsonProvider()); final Swagger2Feature feature = createSwagger2Feature(); //FIXME swagger-jaxrs 1.5.3 can't handle a self-recursive subresource like Book // so we need to exclude "org.apache.cxf.systest.jaxrs" for now. feature.setResourcePackage("org.apache.cxf.systest.jaxrs.description.group1"); feature.setScanAllResources(true); sf.setFeatures(Arrays.asList(feature)); sf.setAddress("http://localhost:" + port + "/"); sf.create(); }
Example 2
Source File: JAXRSClientServerValidationTest.java From cxf with Apache License 2.0 | 6 votes |
protected void run() { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookStoreWithValidation.class); sf.setResourceProvider(BookStoreWithValidation.class, new SingletonResourceProvider(new BookStoreWithValidation())); sf.setProvider(new ValidationExceptionMapper() { @Override public Response toResponse(ValidationException exception) { Response r = super.toResponse(exception); return JAXRSUtils.toResponseBuilder( r.getStatus()).type("application/xml").entity(new Book("Validation", 123L)).build(); } }); sf.setAddress("http://localhost:" + PORT + "/"); BeanValidationInInterceptor in = new JAXRSBeanValidationInInterceptor(); in.setProvider(new BeanValidationProvider(new JAXRSParameterNameProvider())); sf.setInInterceptors(Arrays.< Interceptor< ? extends Message > >asList( in)); sf.setOutInterceptors(Arrays.< Interceptor< ? extends Message > >asList( new JAXRSBeanValidationOutInterceptor())); sf.create(); }
Example 3
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 4
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 5
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 6
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 7
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 8
Source File: RxJavaObservableServer.java From cxf with Apache License 2.0 | 5 votes |
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.setProvider(new JacksonJsonProvider()); new ObservableCustomizer().customize(sf); sf.getOutInterceptors().add(new LoggingOutInterceptor()); sf.setResourceClasses(RxJavaObservableService.class); sf.setResourceProvider(RxJavaObservableService.class, new SingletonResourceProvider(new RxJavaObservableService(), true)); sf.setAddress("http://localhost:" + PORT + "/"); server = sf.create(); }
Example 9
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 10
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 11
Source File: RxJava2ObservableServer.java From cxf with Apache License 2.0 | 5 votes |
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(RxJava2ObservableService.class); sf.setResourceProvider(RxJava2ObservableService.class, new SingletonResourceProvider(new RxJava2ObservableService(), true)); sf.setAddress("http://localhost:" + PORT + "/"); server = sf.create(); }
Example 12
Source File: RxJava2FlowableServer.java From cxf with Apache License 2.0 | 5 votes |
private JAXRSServerFactoryBean createFactoryBean(Bus bus, boolean useStreamingSubscriber, String relAddress) { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.getProperties(true).put("useStreamingSubscriber", useStreamingSubscriber); sf.setProvider(new JacksonJsonProvider()); new ReactiveIOCustomizer().customize(sf); sf.getOutInterceptors().add(new LoggingOutInterceptor()); sf.setResourceClasses(RxJava2FlowableService.class); sf.setResourceProvider(RxJava2FlowableService.class, new SingletonResourceProvider(new RxJava2FlowableService(), true)); sf.setAddress("http://localhost:" + PORT + relAddress); return sf; }
Example 13
Source File: AppConfig.java From cxf with Apache License 2.0 | 5 votes |
@Bean org.apache.cxf.endpoint.Server server() { final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean (); factory.setFeatures(Arrays.asList(openApiFeature())); factory.setServiceBean(sampleResource()); factory.setAddress("http://localhost:9000/"); factory.setProvider(new JsonbJaxrsProvider<>()); return factory.create(); }
Example 14
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 15
Source File: JsrJsonpProviderTest.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookJsonStore.class); sf.setResourceProvider(BookJsonStore.class, new SingletonResourceProvider(new BookJsonStore())); sf.setProvider(new JsrJsonpProvider()); sf.setAddress("http://localhost:" + PORT + "/"); sf.create(); }
Example 16
Source File: OpenApiCustomizerTest.java From cxf with Apache License 2.0 | 5 votes |
@Override protected void run() { final JAXRSServerFactoryBean sf = RuntimeDelegate .getInstance() .createEndpoint(new BookStoreApplication(), JAXRSServerFactoryBean.class); 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 + "/api"); sf.create(); }
Example 17
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 18
Source File: ReactorServer.java From cxf with Apache License 2.0 | 5 votes |
@Override 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.getProperties(true).put("useStreamingSubscriber", false); sf.setProvider(new JacksonJsonProvider()); new ReactorCustomizer().customize(sf); sf.setResourceClasses(FluxService.class, MonoService.class); sf.setResourceProvider(FluxService.class, new SingletonResourceProvider(new FluxService(), true)); sf.setResourceProvider(MonoService.class, new SingletonResourceProvider(new MonoService(), true)); sf.setAddress("http://localhost:" + PORT + "/reactor"); server1 = sf.create(); JAXRSServerFactoryBean sf2 = new JAXRSServerFactoryBean(); sf2.setProvider(new JacksonJsonProvider()); sf2.setProvider(new IllegalArgumentExceptionMapper()); new ReactorCustomizer().customize(sf2); sf2.setResourceClasses(FluxService.class); sf2.setResourceProvider(FluxService.class, new SingletonResourceProvider(new FluxService(), true)); sf2.setAddress("http://localhost:" + PORT + "/reactor2"); server2 = sf2.create(); }
Example 19
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); }
Example 20
Source File: JAXRSClientServerUserResourceDefaultTest.java From cxf with Apache License 2.0 | 4 votes |
protected void run() { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setInvoker(new CustomModelInvoker()); sf.setProvider(new PreMatchContainerRequestFilter()); sf.setAddress("http://localhost:" + PORT + "/"); sf.getServiceFactory().setDefaultModelClass(DefaultResource.class); UserResource ur = new UserResource(); ur.setPath("/default"); UserOperation op = new UserOperation(); op.setPath("/books/{id}"); op.setName("getBook"); op.setVerb("GET"); Parameter param = new Parameter(ParameterType.PATH, "id"); param.setJavaType(Long.class); op.setParameters(Collections.singletonList(param)); UserOperation op2 = new UserOperation(); op2.setPath("echobook"); op2.setName("echo"); op2.setVerb("POST"); op2.setParameters(Collections.singletonList(new Parameter(ParameterType.REQUEST_BODY, null))); UserOperation op3 = new UserOperation(); op3.setPath("echobookdefault"); op3.setName("echoDefault"); op3.setVerb("POST"); Parameter echoDefaultParam = new Parameter(ParameterType.REQUEST_BODY, null); echoDefaultParam.setJavaType(SAXSource.class); op3.setParameters(Collections.singletonList(echoDefaultParam)); List<UserOperation> ops = new ArrayList<>(); ops.add(op); ops.add(op2); ops.add(op3); ur.setOperations(ops); sf.setModelBeans(ur); server = sf.create(); }