Java Code Examples for org.apache.cxf.jaxrs.JAXRSServerFactoryBean

The following are top voted examples for showing how to use org.apache.cxf.jaxrs.JAXRSServerFactoryBean. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jwala   File: WebServiceConfig.java   Source Code and License 6 votes vote down vote up
@Bean
public Server getJaxRestServer(final GroupServiceRest groupServiceRest, final JvmServiceRest jvmServiceRest) {
    final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();

    factory.setAddress("/v2.0");

    final List<Object> serviceBeans = new ArrayList<>();
    serviceBeans.add(groupServiceRest);
    serviceBeans.add(jvmServiceRest);
    factory.setServiceBeans(serviceBeans);

    List<Object> providers = new ArrayList<>();
    providers.add(getJacksonJsonProvider());
    providers.add(getInternalServerErrorHandler());
    factory.setProviders(providers);
    return factory.create();
}
 
Example 2
Project: oasp-tutorial-sources   File: ServiceConfig.java   Source Code and License 6 votes vote down vote up
@Bean
public Server jaxRsServer() {

  // List<Object> restServiceBeans = new
  // ArrayList<>(this.applicationContext.getBeansOfType(RestService.class).values());
  Collection<Object> restServices = findRestServices();
  if (restServices.isEmpty()) {
    LOG.info("No REST Services have been found. Rest Endpoint will not be enabled in CXF.");
    return null;
  }
  Collection<Object> providers = this.applicationContext.getBeansWithAnnotation(Provider.class).values();

  JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
  factory.setBus(springBus());
  factory.setAddress(URL_FOLDER_REST);
  // factory.set
  factory.setServiceBeans(new ArrayList<>(restServices));
  factory.setProviders(new ArrayList<>(providers));

  return factory.create();
}
 
Example 3
Project: GeoCrawler   File: NutchServer.java   Source Code and License 6 votes vote down vote up
private NutchServer() {
  configManager = new ConfManagerImpl();
  BlockingQueue<Runnable> runnables = Queues.newArrayBlockingQueue(JOB_CAPACITY);
  NutchServerPoolExecutor executor = new NutchServerPoolExecutor(10, JOB_CAPACITY, 1, TimeUnit.HOURS, runnables);
  jobManager = new JobManagerImpl(new JobFactory(), configManager, executor);
  fetchNodeDb = FetchNodeDb.getInstance();

  sf = new JAXRSServerFactoryBean();
  BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class);
  JAXRSBindingFactory factory = new JAXRSBindingFactory();
  factory.setBus(sf.getBus());
  manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory);
  sf.setResourceClasses(getClasses());
  sf.setResourceProviders(getResourceProviders());
  sf.setProvider(new JacksonJaxbJsonProvider());

}
 
Example 4
Project: microbule   File: DefaultJaxrsServerFactory.java   Source Code and License 6 votes vote down vote up
@Override
public JaxrsServer createJaxrsServer(Class<?> serviceInterface, Object serviceImplementation) {
    final String serviceName = namingStrategy.get().serviceName(serviceInterface);
    final Config serverConfig = configService.createServerConfig(serviceInterface, serviceName);
    final String baseAddress = serverConfig.value(BASE_ADDRESS_PROP).orElse(StringUtils.EMPTY);
    final String serverAddress = serverConfig.value(SERVER_ADDRESS_PROP).orElse(namingStrategy.get().serverAddress(serviceInterface));
    final String fullAddress = baseAddress + serverAddress;
    LOGGER.info("Starting {} JAX-RS server ({})...", serviceInterface.getSimpleName(), fullAddress);

    final DefaultJaxrsServiceDescriptor descriptor = new DefaultJaxrsServiceDescriptor(serviceInterface, serviceName);
    decorate(descriptor, serverConfig);
    final JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(BusFactory.getDefaultBus(true));
    sf.setServiceBean(serviceImplementation);

    sf.setAddress(fullAddress);
    sf.setFeatures(descriptor.getFeatures());
    sf.setProviders(descriptor.getProviders());
    final Server server = sf.create();
    LOGGER.info("Successfully started {} JAX-RS server ({}).", serviceInterface.getSimpleName(), serverAddress);
    return server::destroy;
}
 
Example 5
Project: metasfresh-procurement-webui   File: SyncConfiguration.java   Source Code and License 6 votes vote down vote up
@Bean
public Server serverEndPoint(final SpringBus bus)
{
	final JacksonJaxbJsonProvider jacksonJaxbJsonProvider = new JacksonJaxbJsonProvider();

	final JMSConfigFeature jmsConfigFeature = createJMSConfigFeature();

	final JAXRSServerFactoryBean svrFactory = new JAXRSServerFactoryBean();
	svrFactory.setBus(bus);
	svrFactory.setResourceClasses(AgentSync.class);

	svrFactory.getFeatures().add(jmsConfigFeature);
	svrFactory.getFeatures().add(loggingFeature);

	svrFactory.setProvider(jacksonJaxbJsonProvider);
	svrFactory.setAddress("/");
	svrFactory.setTransportId("http://cxf.apache.org/transports/jms");

	final Server server = svrFactory.create();
	return server;
}
 
Example 6
Project: restful-api-cxf-spring-java   File: CxfConfig.java   Source Code and License 6 votes vote down vote up
@Bean
  @DependsOn("cxf")
  public Server jaxRsServer() {
      JAXRSServerFactoryBean serverFactory = RuntimeDelegate.getInstance().createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
      
      //factory.setServiceBean(new DenialCategoryRest());
      
// get all the class annotated with @JaxrsService
      List<Object> beans = configUtil.findBeans( JaxrsService.class );

if (beans.size() > 0) {
	
	// add all the CXF service classes into the CXF stack
	serverFactory.setServiceBeans( beans );
	serverFactory.setAddress("/"+ serverFactory.getAddress());
	serverFactory.setBus(springBus);
	serverFactory.setStart(true);
	
	// set JSON as the response serializer
	JacksonJsonProvider provider = new JacksonJsonProvider();
	serverFactory.setProvider(provider);
       
}
      
return serverFactory.create();
  }
 
Example 7
Project: django   File: CamelCatalogRestTest.java   Source Code and License 6 votes vote down vote up
@Before
public void setup() {
    catalog = new CamelCatalogRest();

    port = AvailablePortFinder.getNextAvailable(9000);

    // setup Apache CXF REST server
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(CamelCatalogRest.class);
    sf.setResourceProvider(CamelCatalogRest.class, new SingletonResourceProvider(catalog));
    // to use jackson for json
    sf.setProvider(JacksonJsonProvider.class);
    sf.setAddress("http://localhost:" + port);

    // create and start the CXF server (non blocking)
    server = sf.create();
    server.start();
}
 
Example 8
Project: Camel   File: CxfRsEndpoint.java   Source Code and License 6 votes vote down vote up
protected void setupJAXRSServerFactoryBean(JAXRSServerFactoryBean sfb) {
    // address
    if (getAddress() != null) {
        sfb.setAddress(getAddress());
    }
    processResourceModel(sfb);
    if (getResourceClasses() != null) {
        sfb.setResourceClasses(getResourceClasses());
    }

    // setup the resource providers for interfaces
    List<ClassResourceInfo> cris = sfb.getServiceFactory().getClassResourceInfo();
    for (ClassResourceInfo cri : cris) {
        final Class<?> serviceClass = cri.getServiceClass();
        if (serviceClass.isInterface()) {
            cri.setResourceProvider(new CamelResourceProvider(serviceClass));
        }
    }
    setupCommonFactoryProperties(sfb);
    sfb.setStart(false);
    getNullSafeCxfRsEndpointConfigurer().configure(sfb);
}
 
Example 9
Project: Camel   File: CxfRsEndpointTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCxfRsEndpointSetProvider() throws Exception {

    String endpointUri = "cxfrs://http://localhost:" + CTX + ""
                         + "?resourceClass=org.apache.camel.component.cxf.jaxrs.testbean.CustomerService";

    CxfRsComponent component = new CxfRsComponent(context);
    CxfRsEndpoint endpoint = (CxfRsEndpoint)component.createEndpoint(endpointUri);
    JSONProvider<?> jsonProvider = new JSONProvider<Object>();
    jsonProvider.setDropRootElement(true);
    jsonProvider.setSupportUnwrapped(true);
    endpoint.setProvider(jsonProvider);
    JAXRSServerFactoryBean sfb = endpoint.createJAXRSServerFactoryBean();
    assertEquals("Get a wrong proider size", 1, sfb.getProviders().size());
    JAXRSClientFactoryBean cfb = endpoint.createJAXRSClientFactoryBean();
    assertEquals("Get a wrong proider size", 1, cfb.getProviders().size());
}
 
Example 10
Project: bamboobsc   File: CxfServerBean.java   Source Code and License 6 votes vote down vote up
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 11
Project: camelinaction2   File: RestOrderServer.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // create dummy backend
    DummyOrderService dummy = new DummyOrderService();
    dummy.setupDummyOrders();

    // create CXF REST service and inject the dummy backend
    RestOrderService rest = new RestOrderService();
    rest.setOrderService(dummy);

    // setup Apache CXF REST server on port 9000
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(RestOrderService.class);
    sf.setResourceProvider(RestOrderService.class, new SingletonResourceProvider(rest));
    sf.setAddress("http://localhost:9000/");

    // create and start the CXF server (non blocking)
    Server server = sf.create();
    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 CXF server
    server.stop();
    System.exit(0);
}
 
Example 12
Project: metasfresh   File: JaxRsSpringEndpointTests.java   Source Code and License 6 votes vote down vote up
private void performJmsTransportTest(final String springBeanXml) throws IOException, URISyntaxException, Exception
{
	final BrokerService broker = setupJmsBroker();

	//
	// now we get the jax-rs endpoint from the xml config
	try (ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { springBeanXml }))
	{
		final JAXRSServerFactoryBean sfb = (JAXRSServerFactoryBean)ctx.getBean("jaxrs:server:jms");

		final Server server = sfb.getServer();
		assertThat(server, notNullValue()); // it's important that we can obtain the server bean
		assertThat(server.isStarted(), is(true)); // for all we care, we could also start the server, but we need to know if we have to or not

		runJmsClient();

		server.destroy();
		assertThat(server.isStarted(), is(false));
	}
	finally
	{
		broker.stop();
	}
}
 
Example 13
Project: BrewControlServer   File: BrewControl.java   Source Code and License 6 votes vote down vote up
/**
 * Helper method to start all rest services on a Jettison server as supplied
 * by the Apache cxf libraries.
 * 
 * @throws Exception
 */
private static void startServices() throws Exception {
	List<JSONProvider> providers = new ArrayList<JSONProvider>();
	JSONProvider jsonProvider = new JSONProvider();
	// jsonProvider.setSerializeAsArray(false);
	// jsonProvider.setConvertTypesToStrings(true);
	Map<String, String> map = new HashMap<String, String>();
	map.put("http://www.goodrick.ch", "brewcontrol");
	jsonProvider.setNamespaceMap(map);
	providers.add(jsonProvider);

	JAXRSServerFactoryBean factoryBean = new JAXRSServerFactoryBean();
	factoryBean.setResourceClasses(RestService.class, MashingService.class, InfoService.class);
	factoryBean.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
	factoryBean.setAddress("http://" + getNetworkAddress() + ":8080/");
	factoryBean.setProviders(providers);
	factoryBean.create();
}
 
Example 14
Project: sakai   File: AbstractCXFTest.java   Source Code and License 6 votes vote down vote up
/**
 * 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 15
Project: logspace   File: CxfAgentTest.java   Source Code and License 6 votes vote down vote up
@Before
public void startServer() {
    JAXRSServerFactoryBean serverFactory = new JAXRSServerFactoryBean();
    serverFactory.setResourceClasses(TestCxfResource.class);

    // add custom providers if any
    serverFactory.setProviders(new ArrayList<Object>());

    serverFactory.setResourceProvider(TestCxfResource.class, new SingletonResourceProvider(new TestCxfResource(), true));
    serverFactory.setAddress(ENDPOINT_ADDRESS);

    serverFactory.getInInterceptors().add(new CxfInAgent());
    serverFactory.getOutInterceptors().add(this.buildCxfOutAgent());

    this.server = serverFactory.create();
}
 
Example 16
Project: cxf-plus   File: CXFPlusServlet.java   Source Code and License 6 votes vote down vote up
private void doPublishRestful(Map<Class<?>, ResourceProvider> springResources) {
		JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
		sf.setBus(getBus());
		for (Entry<Class<?>, ResourceProvider> e : springResources.entrySet()) {
			sf.setResourceClasses(e.getKey());
			sf.setResourceProvider(e.getKey(), e.getValue());
			log.info("Publishing JAX-RS Service {} at {}", e, httpPrefix + restBasePath);
		}
		sf.setAddress(httpPrefix + restBasePath);
//		if (restUseFastJson == 1) {
//			sf.setProvider(new FastJSONProvider(false, restJsonWithClassname));
//		} else {
			sf.setProvider(new FastJSONProvider(true, restJsonWithClassname));
//		}
		sf.getInInterceptors().add(new LoggingInInterceptor());
		sf.getOutInterceptors().add(new LoggingOutInterceptor());
		sf.create();

	}
 
Example 17
Project: sakai   File: AbstractCXFTest.java   Source Code and License 6 votes vote down vote up
/**
 * 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 18
Project: osmdroid   File: TileServer.java   Source Code and License 6 votes vote down vote up
/**
 * this files up a CXF based Jetty server to host tile rest service
 * @throws Exception 
 */
private static void startServer() throws Exception {
     JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
     sf.setResourceClasses(TileFetcher.class);

     List<Object> providers = new ArrayList<Object>();
     // add custom providers if any
     providers.add(new org.apache.cxf.jaxrs.provider.JAXBElementProvider());
     providers.add(new org.apache.cxf.jaxrs.provider.json.JSONProvider());
     sf.setProviders(providers);

     sf.setResourceProvider(TileFetcher.class,
             new SingletonResourceProvider(new TileFetcher(), true));
     sf.setAddress(ENDPOINT_ADDRESS);

     server = sf.create();

}
 
Example 19
Project: osgi-sample   File: Activator.java   Source Code and License 6 votes vote down vote up
@Override
public Object addingService(ServiceReference serviceReference) {
    final Object trackedService = context.getService(serviceReference);

    if (trackedService instanceof EntityService) {
        final EntityServiceRest restApi = new EntityServiceRest();
        restApi.setEntityService((EntityService) trackedService);

        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setResourceClasses(restApi.getClass());
        sf.setResourceProvider(restApi.getClass(), new SingletonResourceProvider(restApi));
        sf.setAddress("/entity");
        sf.setProvider(new JacksonJsonProvider());
        server = sf.create();
    }

    return trackedService;
}
 
Example 20
Project: camunda-bpm-platform   File: CXFServerBootstrap.java   Source Code and License 6 votes vote down vote up
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 21
Project: dss-demonstrations   File: CXFConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public Server createServerValidationRestService() {
	JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
	sfb.setServiceBean(restValidationService());
	sfb.setAddress(REST_VALIDATION);
	sfb.setProvider(jacksonJsonProvider());
	return sfb.create();
}
 
Example 22
Project: dss-demonstrations   File: CXFConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public Server createServerSigningRestService() {
	JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
	sfb.setServiceBean(restServerSigningService());
	sfb.setAddress(REST_SERVER_SIGNING);
	sfb.setProvider(jacksonJsonProvider());
	return sfb.create();
}
 
Example 23
Project: dss-demonstrations   File: CXFConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public Server createOneDocumentSignatureRestService() {
	JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
	sfb.setServiceBean(restSignatureService());
	sfb.setAddress(REST_SIGNATURE_ONE_DOCUMENT);
	sfb.setProvider(jacksonJsonProvider());
	return sfb.create();
}
 
Example 24
Project: dss-demonstrations   File: CXFConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public Server createMultipleDocumentRestService() {
	JAXRSServerFactoryBean sfb = new JAXRSServerFactoryBean();
	sfb.setServiceBean(restMultipleDocumentsSignatureService());
	sfb.setAddress(REST_SIGNATURE_MULTIPLE_DOCUMENTS);
	sfb.setProvider(jacksonJsonProvider());
	return sfb.create();
}
 
Example 25
Project: jwala   File: AemWebServiceConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
public Server getV1JaxResServer() {
    final JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
    factory.setAddress("/v1.0");
    factory.setServiceBeans(getV1ServiceBeans());
    factory.setProviders(getV1Providers());
    return factory.create();
}
 
Example 26
Project: microservices-transactions-tcc   File: WebServicesConfiguration.java   Source Code and License 5 votes vote down vote up
@Bean
public Server rsServer() {
    JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setAddress("/");
    endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new ExceptionRestHandler()));
    
    Map<Object, Object> mappings = new HashMap<Object, Object>();
    mappings.put("json", "application/json");
    endpoint.setExtensionMappings(mappings);
    
    Swagger2Feature swagger2Feature = new Swagger2Feature();
    swagger2Feature.setTitle(title);
    swagger2Feature.setDescription(description);
    swagger2Feature.setVersion(version);
    swagger2Feature.setContact(contact);
    swagger2Feature.setSchemes(schemes.split(","));
    swagger2Feature.setBasePath(basePath);
    swagger2Feature.setResourcePackage(resourcePackage);
    swagger2Feature.setPrettyPrint(prettyPrint);
    swagger2Feature.setScan(scan);
    
    endpoint.setFeatures(Arrays.asList(new LoggingFeature(), swagger2Feature));
    endpoint.setServiceBeans(Arrays.asList(tccCoordinatorService, compositeController));
    
    return endpoint.create();
}
 
Example 27
Project: brave-osgi-example   File: SimpleResource.java   Source Code and License 5 votes vote down vote up
@Activate
public void activate() {
    JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
    factory.setServiceClass(SimpleResource.class);
    factory.setResourceProvider(SimpleResource.class, new SingletonResourceProvider(this));
    factory.setProviders(singletonList(BraveTracingFeature.create(brave)));
    factory.setAddress("/simple");
    server = factory.create();
}
 
Example 28
Project: SoapUI-Cookbook   File: Server.java   Source Code and License 5 votes vote down vote up
protected Server(String filePath) throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(TestDataResourceImpl.class);
    sf.setResourceProvider(TestDataResourceImpl.class, 
        new SingletonResourceProvider(new TestDataResourceImpl(filePath)));
    sf.setAddress("http://localhost:9000/");
    sf.create();
}
 
Example 29
Project: SoapUI-Cookbook   File: Server.java   Source Code and License 5 votes vote down vote up
protected Server() throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(InvoiceServiceCRUDV1ResourceImpl.class);
    sf.setResourceProvider(InvoiceServiceCRUDV1ResourceImpl.class, 
        new SingletonResourceProvider(new InvoiceServiceCRUDV1ResourceImpl()));
    sf.setAddress("http://localhost:9000/");
    sf.create();
}
 
Example 30
Project: SoapUI-Cookbook   File: Server.java   Source Code and License 5 votes vote down vote up
protected Server() throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(InvoiceserviceV1ResourceImpl.class);
    sf.setResourceProvider(InvoiceserviceV1ResourceImpl.class, 
        new SingletonResourceProvider(new InvoiceserviceV1ResourceImpl()));
    sf.setAddress("http://localhost:9000/");
    sf.create();
}
 
Example 31
Project: go-artifactory-scm-plugin   File: IntegrationTests.java   Source Code and License 5 votes vote down vote up
@BeforeClass
public static void startServer() throws Exception {
	JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
	SERVER_URL = "http://localhost:" + port + "/" + CONTEXT_ROOT + "/" + JAX_RS_CONTEXT;
	APP_URL = SERVER_URL + "/" + APP_NAME + "/";
	sf.setAddress(SERVER_URL);

	List<Class<?>> resourceClasses = new ArrayList<>();
	resourceClasses.add(ArtiTestJaxrsResource.class);
	sf.setResourceClasses(resourceClasses);

	server = sf.create();
}
 
Example 32
Project: spring-boot-cxf-jaxrs   File: SampleRestApplication.java   Source Code and License 5 votes vote down vote up
@Bean
public Server rsServer() {
    // setup CXF-RS
    JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
    endpoint.setBus(bus);
    endpoint.setServiceBeans(Arrays.<Object>asList(new HelloServiceImpl()));
    endpoint.setAddress("/");
    endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
    return endpoint.create();
}
 
Example 33
Project: restful-api-cxf-spring-java   File: CxfTestConfig.java   Source Code and License 5 votes vote down vote up
@Bean
  @DependsOn("cxf")
  public Server jaxRsServer() {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
// sf.setResourceClasses( MyJaxrsResource.class );

List<Object> providers = new ArrayList<Object>();
// add custom providers if any
sf.setProviders(providers);

// factory.setServiceBean(new DenialCategoryRest());

// get all the class annotated with @JaxrsService
List<Object> beans = configUtil.findBeans(JaxrsService.class);
// List<Class> beansClasses = configUtil.findClasses( JaxrsService.class
// );

if (beans.size() > 0) {

	// add all the CXF service classes into the CXF stack
	//sf.setResourceClasses(UserRestImpl.class);
	sf.setServiceBeans(beans);
	sf.setAddress("http://localhost:8080/api");
	sf.setBus(springBus);
	sf.setStart(true);

	// set JSON as the response serializer
	JacksonJsonProvider provider = new JacksonJsonProvider();
	sf.setProvider(provider);

}

return sf.create();
  }
 
Example 34
Project: product-ei   File: CoffeeConfig.java   Source Code and License 5 votes vote down vote up
@Bean
 public org.apache.cxf.endpoint.Server jaxRsServer() {
     JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
     factory.setServiceBeans( Arrays.< Object >asList(starbucksOutletService()) );
     factory.setAddress( "/" + factory.getAddress() );
List<Object> providers = new ArrayList<Object>();
     providers.add(jsonProvider());
     providers.add(new OrderReader());
     factory.setProviders(providers);
     //factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
     return factory.create();
 }
 
Example 35
Project: product-ei   File: AppConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
    factory.setServiceBeans( Arrays.< Object >asList( peopleRestService() ) );
    factory.setAddress( "/" + factory.getAddress() );
    factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
    return factory.create();
}
 
Example 36
Project: product-ei   File: MusicConfig.java   Source Code and License 5 votes vote down vote up
@Bean
public Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
    factory.setServiceBeans( Arrays.< Object >asList(musicRestService()) );
    factory.setAddress( "/" + factory.getAddress() );
    factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
    return factory.create();
}
 
Example 37
Project: product-ei   File: CustomerConfig.java   Source Code and License 5 votes vote down vote up
@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 38
Project: product-ei   File: Server.java   Source Code and License 5 votes vote down vote up
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 39
Project: aries-jax-rs-whiteboard   File: CXFJaxRsServiceRegistrator.java   Source Code and License 5 votes vote down vote up
public <T> T createEndpoint(Application app, Class<T> endpointType) {
    JAXRSServerFactoryBean bean =
        RuntimeDelegate.getInstance().createEndpoint(
            app, JAXRSServerFactoryBean.class);

    if (JAXRSServerFactoryBean.class.isAssignableFrom(endpointType)) {
        return endpointType.cast(bean);
    }
    bean.setStart(false);
    Server server = bean.create();
    return endpointType.cast(server);
}
 
Example 40
Project: django   File: CamelCatalogSwaggerTest.java   Source Code and License 5 votes vote down vote up
@Before
public void setup() {
    catalog = new CamelCatalogRest();

    port = AvailablePortFinder.getNextAvailable(9000);

    // setup Apache CXF REST server
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(CamelCatalogRest.class);
    sf.setResourceProvider(CamelCatalogRest.class, new SingletonResourceProvider(catalog));

    Swagger2Feature swagger = new Swagger2Feature();
    swagger.setBasePath("/");
    swagger.setScanAllResources(false);
    swagger.setPrettyPrint(true);
    swagger.setSupportSwaggerUi(true);
    swagger.setTitle("Camel Catalog REST Api");
    swagger.setDescription("REST Api for the Camel Catalog");
    swagger.setVersion(catalog.getCatalogVersion());
    swagger.setContact("Apache Camel");
    sf.getFeatures().add(swagger);

    // to use jackson for json
    sf.setProvider(JacksonJsonProvider.class);
    sf.setAddress("http://localhost:" + port);

    // create and start the CXF server (non blocking)
    server = sf.create();
    server.start();
}