use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project fabric8 by jboss-fuse.
the class CxfRsFailOverClientServerTest method testClientServer.
@Test
public void testClientServer() throws Exception {
assertNotNull(bus);
// The bus is load the feature
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setResourceClasses(CustomerService.class);
factory.setAddress("http://localhost:9000/fail/server");
factory.setBus(bus);
factory.create();
factory = new JAXRSServerFactoryBean();
factory.setServiceClass(CustomerService.class);
factory.setResourceClasses(CustomerService.class);
factory.setBus(bus);
factory.create();
// sleep a while to let the service be published
for (int i = 0; i < 100; i++) {
if (!feature.getLoadBalanceStrategy().getAlternateAddressList().isEmpty()) {
break;
}
Thread.sleep(100);
}
JAXRSClientFactoryBean clientFactory = new JAXRSClientFactoryBean();
clientFactory.setServiceClass(CustomerServiceResources.class);
// The address is not the actual address that the client will access
clientFactory.setAddress("http://someotherplace");
List<AbstractFeature> features = new ArrayList<>();
// add the instance of FabricLoadBalancerFeature into features list
features.add(feature);
// we need to setup the feature on the clientfactory
clientFactory.setFeatures(features);
// set this interceptor to simulate the Transport level exception
List<Interceptor<? extends Message>> outInterceptor = clientFactory.getOutInterceptors();
outInterceptor.add(new TransportFailureInterceptor());
clientFactory.setOutInterceptors(outInterceptor);
CustomerServiceResources proxy = clientFactory.create(CustomerServiceResources.class);
Customer response = proxy.getCustomer("123");
assertEquals("Get a wrong customer name", "John", response.getName());
response = proxy.getCustomer("123");
assertEquals("Get a wrong customer name", "John", response.getName());
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project alliance by codice.
the class MockNsili method startWebServer.
public void startWebServer(int port) {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(MockWebService.class);
sf.setAddress("http://localhost:" + port + "/");
sf.create();
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project tomee by apache.
the class CXFNonSpringJaxrsServlet method createServerFromApplication.
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.getFeatures().addAll(features);
bean.setBus(getBus());
bean.setApplicationInfo(providerApp);
bean.create();
}
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project tomee by apache.
the class CXFNonSpringJaxrsServlet method createServerFromApplication.
protected void createServerFromApplication(ServletConfig servletConfig) throws ServletException {
Application app = getApplication();
JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, isIgnoreApplicationPath(servletConfig), 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.getFeatures().addAll(features);
bean.setBus(getBus());
bean.setApplication(getApplication());
bean.create();
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project tomee by apache.
the class CxfRsHttpListener method deploy.
private void deploy(final String contextRoot, final Class<?> clazz, final String address, final ResourceProvider rp, final Object serviceBean, final Application application, final Invoker invoker, final Collection<Object> additionalProviders, final ServiceConfiguration configuration, final WebBeansContext webBeansContext) {
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(CxfUtil.initBusLoader());
try {
final JAXRSServerFactoryBean factory = newFactory(address, createServiceJmxName(clazz.getClassLoader()), createEndpointName(application));
configureFactory(additionalProviders, configuration, factory, webBeansContext, application);
factory.setResourceClasses(clazz);
context = contextRoot;
if (context == null) {
context = "";
}
if (!context.startsWith("/")) {
context = "/" + context;
}
if (rp != null) {
factory.setResourceProvider(rp);
}
if (application != null) {
factory.setApplication(application);
}
if (invoker != null) {
factory.setInvoker(invoker);
}
if (serviceBean != null) {
factory.setServiceBean(serviceBean);
} else {
factory.setServiceClass(clazz);
}
factory.setTransportId("http://cxf.apache.org/transports/http/sse");
server = factory.create();
destination = (HttpDestination) server.getDestination();
fireServerCreated(oldLoader);
} finally {
if (oldLoader != null) {
CxfUtil.clearBusLoader(oldLoader);
}
}
}
Aggregations