本文整理匯總了Java中org.apache.cxf.jaxrs.JAXRSServerFactoryBean類的典型用法代碼示例。如果您正苦於以下問題:Java JAXRSServerFactoryBean類的具體用法?Java JAXRSServerFactoryBean怎麽用?Java JAXRSServerFactoryBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JAXRSServerFactoryBean類屬於org.apache.cxf.jaxrs包,在下文中一共展示了JAXRSServerFactoryBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getJaxRestServer
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
@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();
}
示例2: jaxRsServer
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
@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();
}
示例3: NutchServer
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
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());
}
示例4: createJaxrsServer
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
@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;
}
示例5: serverEndPoint
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
@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;
}
示例6: jaxRsServer
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
@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();
}
示例7: setup
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
@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();
}
示例8: setupJAXRSServerFactoryBean
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
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);
}
示例9: testCxfRsEndpointSetProvider
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
@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());
}
示例10: publishRest
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
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;
}
示例11: main
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
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);
}
示例12: performJmsTransportTest
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
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();
}
}
示例13: startServices
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
/**
* 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();
}
示例14: startServer
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
/**
* 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();
}
示例15: startServer
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; //導入依賴的package包/類
@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();
}