Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean#create()
The following examples show how to use
org.apache.cxf.jaxrs.JAXRSServerFactoryBean#create() .
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: AbstractCXFTest.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Starts a local cxf server that listens for defined SOAP operation. * This means that each operation should have its own test. * @param type the implementing type of AbstractWebService, i.e. SakaiLogin.class */ private <T extends AbstractWebService> void startServer(Class<T> type) { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(type); List<Object> providers = new ArrayList<Object>(); // add custom providers if any // CXF supports String, byte[], InputStream, Reader, File, JAXP Source, JAX-RS StreamingOutput, // JAXB-annotated types with application/xml, text/xml and application/json formats as well as JAXBElement sf.setProviders(providers); AbstractWebService service = MockingAbstractWebService.getMockedAbstractWebService(type); addServiceMocks(service); sf.setResourceProvider(type, new SingletonResourceProvider(service, true)); sf.setAddress(getFullEndpointAddress()); server = sf.create(); }
Example 2
Source File: CXFServerBootstrap.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
private void setupServer(Application application) { jaxrsServerFactoryBean = new JAXRSServerFactoryBean(); List<Class<?>> resourceClasses = new ArrayList<Class<?>>(); List<Object> providerInstances = new ArrayList<Object>(); // separate the providers and resources from the application returned classes separateProvidersAndResources(application, resourceClasses, providerInstances); jaxrsServerFactoryBean.setResourceClasses(resourceClasses); jaxrsServerFactoryBean.setProviders(providerInstances); // set up address Properties serverProperties = readProperties(); propertyPort = serverProperties.getProperty(PORT_PROPERTY); jaxrsServerFactoryBean.setAddress("http://localhost:" + propertyPort + ROOT_RESOURCE_PATH); // set start to false so create call does not start server jaxrsServerFactoryBean.setStart(false); server = jaxrsServerFactoryBean.create(); }
Example 3
Source File: AbstractCXFTest.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Starts a local cxf server that listens for defined SOAP operation. * This means that each operation should have its own test. * @param type the implementing type of AbstractWebService, i.e. SakaiLogin.class */ private <T extends AbstractWebService> void startServer(Class<T> type) { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(type); List<Object> providers = new ArrayList<Object>(); // add custom providers if any // CXF supports String, byte[], InputStream, Reader, File, JAXP Source, JAX-RS StreamingOutput, // JAXB-annotated types with application/xml, text/xml and application/json formats as well as JAXBElement sf.setProviders(providers); AbstractWebService service = MockingAbstractWebService.getMockedAbstractWebService(type); addServiceMocks(service); sf.setResourceProvider(type, new SingletonResourceProvider(service, true)); sf.setAddress(getFullEndpointAddress()); server = sf.create(); }
Example 4
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 5
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 6
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 7
Source File: BookServerSub.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setStaticSubresourceResolution(true); sf.setResourceClasses(BookStoreSubObject.class); sf.setResourceProvider(BookStoreSubObject.class, new SingletonResourceProvider(new BookStoreSubObject(), true)); sf.setAddress("http://localhost:" + PORT + "/"); server = sf.create(); }
Example 8
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 9
Source File: CustomerConfig.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(customerService()) ); factory.setAddress( "/" + factory.getAddress() ); factory.setProviders( Arrays.< Object >asList( jsonProvider() ) ); return factory.create(); }
Example 10
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 11
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 12
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 13
Source File: JAXRSPerRequestValidationTest.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookStoreWithValidationPerRequest.class); sf.setProvider(new ValidationExceptionMapper()); sf.setAddress("http://localhost:" + PORT + "/"); sf.setInvoker(new JAXRSBeanValidationInvoker()); sf.create(); }
Example 14
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 15
Source File: BookContinuationServer.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setResourceClasses(BookContinuationStore.class); sf.setResourceProvider(BookContinuationStore.class, new SingletonResourceProvider(new BookContinuationStore())); sf.setAddress("http://localhost:" + PORT + "/"); sf.create(); }
Example 16
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 17
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 18
Source File: BraveTracingTest.java From cxf with Apache License 2.0 | 5 votes |
protected void run() { final Tracing brave = Tracing .newBuilder() .spanReporter(new TestSpanReporter()) .sampler(Sampler.ALWAYS_SAMPLE) .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.create(); }
Example 19
Source File: OpenApiContextBasedConfigApplicationOnlyTest.java From cxf with Apache License 2.0 | 5 votes |
protected void createServerFactory(final String context, final String description, final Class<?> resource) { final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); sf.setApplication(new Application() { @Override public Set<Class<?>> getClasses() { return Collections.singleton(resource); } }); sf.setResourceClasses(resource); sf.setProvider(new JacksonJsonProvider()); final OpenApiFeature feature = createOpenApiFeature(description, resource); sf.setFeatures(Arrays.asList(feature)); sf.setAddress("http://localhost:" + PORT + context); sf.create(); }
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(); }