use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.
the class ProviderServiceFactoryTest method testSAAJProviderCodeFirst.
@Test
public void testSAAJProviderCodeFirst() throws Exception {
JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
bean.setServiceClass(SAAJProvider.class);
bean.setBus(getBus());
bean.setInvoker(new JAXWSMethodInvoker(new SAAJProvider()));
Service service = bean.create();
assertEquals("SAAJProviderService", service.getName().getLocalPart());
InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
assertNotNull(intf);
assertEquals(1, intf.getOperations().size());
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setBus(getBus());
svrFactory.setServiceFactory(bean);
String address = "local://localhost:9000/test";
svrFactory.setAddress(address);
ServerImpl server = (ServerImpl) svrFactory.create();
Endpoint endpoint = server.getEndpoint();
Binding binding = endpoint.getBinding();
assertTrue(binding instanceof SoapBinding);
SoapBindingInfo sb = (SoapBindingInfo) endpoint.getEndpointInfo().getBinding();
assertEquals("document", sb.getStyle());
assertEquals(false, bean.isWrapped());
assertEquals(1, sb.getOperations().size());
Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID, "/org/apache/cxf/jaxws/sayHi.xml");
addNamespace("j", "http://service.jaxws.cxf.apache.org/");
assertValid("/s:Envelope/s:Body/j:sayHi", res);
}
use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.
the class JAXRSServerFactoryBean method create.
/**
* Creates the JAX-RS Server instance
* @return the server
*/
public Server create() {
ClassLoaderHolder origLoader = null;
try {
Bus bus = getBus();
ClassLoader loader = bus.getExtension(ClassLoader.class);
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
serviceFactory.setBus(bus);
checkResources(true);
if (serviceFactory.getService() == null) {
serviceFactory.create();
}
Endpoint ep = createEndpoint();
getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_SERVER_CREATE, server);
server = new ServerImpl(getBus(), ep, getDestinationFactory(), getBindingFactory());
Invoker invoker = serviceFactory.getInvoker();
if (invoker == null) {
ep.getService().setInvoker(createInvoker());
} else {
ep.getService().setInvoker(invoker);
}
ServerProviderFactory factory = setupFactory(ep);
ep.put(Application.class.getName(), appProvider);
factory.setRequestPreprocessor(new RequestPreprocessor(languageMappings, extensionMappings));
ep.put(Bus.class.getName(), getBus());
if (documentLocation != null) {
ep.put(JAXRSUtils.DOC_LOCATION, documentLocation);
}
if (rc != null) {
ep.put("org.apache.cxf.jaxrs.comparator", rc);
}
checkPrivateEndpoint(ep);
applyBusFeatures(getBus());
applyFeatures();
updateClassResourceProviders(ep);
injectContexts(factory);
factory.applyDynamicFeatures(getServiceFactory().getClassResourceInfo());
getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED, server, null, null);
if (start) {
try {
server.start();
} catch (RuntimeException re) {
// prevent resource leak
server.destroy();
throw re;
}
}
} catch (EndpointException e) {
throw new ServiceConstructionException(e);
} catch (BusException e) {
throw new ServiceConstructionException(e);
} catch (IOException e) {
throw new ServiceConstructionException(e);
} catch (Exception e) {
throw new ServiceConstructionException(e);
} finally {
if (origLoader != null) {
origLoader.reset();
}
}
return server;
}
Aggregations