use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.
the class ServerFactoryBean method create.
public Server create() {
ClassLoaderHolder orig = null;
try {
Server server = null;
try {
if (bus != null) {
ClassLoader loader = bus.getExtension(ClassLoader.class);
if (loader != null) {
orig = ClassLoaderUtils.setThreadContextClassloader(loader);
}
}
if (getServiceFactory().getProperties() == null) {
getServiceFactory().setProperties(getProperties());
} else if (getProperties() != null) {
getServiceFactory().getProperties().putAll(getProperties());
}
if (serviceBean != null && getServiceClass() == null) {
setServiceClass(ClassHelper.getRealClass(bus, serviceBean));
}
if (invoker != null) {
getServiceFactory().setInvoker(invoker);
} else if (serviceBean != null) {
invoker = createInvoker();
getServiceFactory().setInvoker(invoker);
}
Endpoint ep = createEndpoint();
getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_SERVER_CREATE, server, serviceBean, serviceBean == null ? getServiceClass() == null ? getServiceFactory().getServiceClass() : getServiceClass() : getServiceClass() == null ? ClassHelper.getRealClass(getBus(), getServiceBean()) : getServiceClass());
server = new ServerImpl(getBus(), ep, getDestinationFactory(), getBindingFactory());
if (ep.getService().getInvoker() == null) {
if (invoker == null) {
ep.getService().setInvoker(createInvoker());
} else {
ep.getService().setInvoker(invoker);
}
}
} catch (EndpointException e) {
throw new ServiceConstructionException(e);
} catch (BusException e) {
throw new ServiceConstructionException(e);
} catch (IOException e) {
throw new ServiceConstructionException(e);
}
if (serviceBean != null) {
Class<?> cls = ClassHelper.getRealClass(getServiceBean());
if (getServiceClass() == null || cls.equals(getServiceClass())) {
initializeAnnotationInterceptors(server.getEndpoint(), cls);
} else {
initializeAnnotationInterceptors(server.getEndpoint(), cls, getServiceClass());
}
} else if (getServiceClass() != null) {
initializeAnnotationInterceptors(server.getEndpoint(), getServiceClass());
}
applyFeatures(server);
getServiceFactory().sendEvent(FactoryBeanListener.Event.SERVER_CREATED, server, serviceBean, serviceBean == null ? getServiceClass() == null ? getServiceFactory().getServiceClass() : getServiceClass() : getServiceClass() == null ? ClassHelper.getRealClass(getServiceBean()) : getServiceClass());
if (start) {
try {
server.start();
} catch (RuntimeException re) {
// prevent resource leak
server.destroy();
throw re;
}
}
getServiceFactory().reset();
return server;
} finally {
if (orig != null) {
orig.reset();
}
}
}
use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.
the class EngineLifecycleTest method testUpDownWithServlets.
@Test
public void testUpDownWithServlets() throws Exception {
setUpBus(true);
Bus bus = (Bus) applicationContext.getBean("cxf");
ServerRegistry sr = bus.getExtension(ServerRegistry.class);
ServerImpl si = (ServerImpl) sr.getServers().get(0);
JettyHTTPDestination jhd = (JettyHTTPDestination) si.getDestination();
JettyHTTPServerEngine e = (JettyHTTPServerEngine) jhd.getEngine();
org.eclipse.jetty.server.Server jettyServer = e.getServer();
Handler[] contexts = jettyServer.getChildHandlersByClass(WebAppContext.class);
WebAppContext servletContext = null;
for (Handler h : contexts) {
WebAppContext wac = (WebAppContext) h;
if (wac.getContextPath().equals("/jsunit")) {
servletContext = wac;
break;
}
}
servletContext.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/bloop");
getTestHtml();
invokeService();
shutdownService();
verifyNoServer(PORT2);
verifyNoServer(PORT1);
}
use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.
the class SoapBindingSelectionTest method testMultipleSoapBindings.
@Test
public void testMultipleSoapBindings() throws Exception {
ServerFactoryBean svrBean1 = new ServerFactoryBean();
svrBean1.setAddress("http://localhost/Hello");
svrBean1.setServiceClass(HelloService.class);
svrBean1.setServiceBean(new HelloServiceImpl());
svrBean1.setBus(getBus());
svrBean1.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {
public void handleMessage(Message message) throws Fault {
service1Invoked = true;
}
});
svrBean1.create();
ServerFactoryBean svrBean2 = new ServerFactoryBean();
svrBean2.setAddress("http://localhost/Hello");
svrBean2.setServiceClass(HelloService.class);
svrBean2.setServiceBean(new HelloServiceImpl());
svrBean2.setBus(getBus());
svrBean2.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {
public void handleMessage(Message message) throws Fault {
service2Invoked = true;
}
});
SoapBindingConfiguration config = new SoapBindingConfiguration();
config.setVersion(Soap12.getInstance());
svrBean2.setBindingConfig(config);
ServerImpl server2 = (ServerImpl) svrBean2.create();
Destination d = server2.getDestination();
MessageObserver mo = d.getMessageObserver();
assertTrue(mo instanceof MultipleEndpointObserver);
MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
assertEquals(2, meo.getEndpoints().size());
Node nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap11.xml");
assertEquals("http://schemas.xmlsoap.org/soap/envelope/", getNs(nd));
assertTrue(service1Invoked);
assertFalse(service2Invoked);
service1Invoked = false;
nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
assertFalse(service1Invoked);
assertTrue(service2Invoked);
server2.stop();
server2.start();
nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
assertFalse(service1Invoked);
assertTrue(service2Invoked);
}
use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.
the class EndpointImpl method doPublish.
/**
* Performs the publication action by setting up a {@link Server}
* instance based on this endpoint's configuration.
*
* @param addr the optional endpoint address.
*
* @throws IllegalStateException if the endpoint cannot be published/republished
* @throws SecurityException if permission checking is enabled and policy forbids publishing
* @throws WebServiceException if there is an error publishing the endpoint
*
* @see #checkPublishPermission()
* @see #checkPublishable()
* @see #getServer(String)
*/
protected void doPublish(String addr) {
checkPublishPermission();
checkPublishable();
ServerImpl serv = null;
ClassLoaderHolder loader = null;
try {
if (bus != null) {
ClassLoader newLoader = bus.getExtension(ClassLoader.class);
if (newLoader != null) {
loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
}
}
serv = getServer(addr);
if (addr != null) {
EndpointInfo endpointInfo = serv.getEndpoint().getEndpointInfo();
if (endpointInfo.getAddress() == null || !endpointInfo.getAddress().contains(addr)) {
endpointInfo.setAddress(addr);
}
if (publishedEndpointUrl != null) {
endpointInfo.setProperty(WSDLGetUtils.PUBLISHED_ENDPOINT_URL, publishedEndpointUrl);
}
if (publishedEndpointUrl != null && wsdlLocation != null) {
// early update the publishedEndpointUrl so that endpoints in the same app sharing the same wsdl
// do not require all of them to be queried for wsdl before the wsdl is finally fully updated
Definition def = endpointInfo.getService().getProperty(WSDLServiceBuilder.WSDL_DEFINITION, Definition.class);
if (def == null) {
def = bus.getExtension(WSDLManager.class).getDefinition(wsdlLocation);
}
new WSDLGetUtils().updateWSDLPublishedEndpointAddress(def, endpointInfo);
}
if (null != properties) {
for (Entry<String, Object> entry : properties.entrySet()) {
endpointInfo.setProperty(entry.getKey(), entry.getValue());
}
}
this.address = endpointInfo.getAddress();
}
serv.start();
publishable = false;
} catch (Exception ex) {
try {
stop();
} catch (Exception e) {
// Nothing we can do.
}
throw new WebServiceException(ex);
} finally {
if (loader != null) {
loader.reset();
}
}
}
use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.
the class ProviderServiceFactoryTest method testXMLBindingFromCode.
@Test
public void testXMLBindingFromCode() throws Exception {
JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
bean.setServiceClass(DOMSourcePayloadProvider.class);
bean.setBus(getBus());
bean.setInvoker(new JAXWSMethodInvoker(new DOMSourcePayloadProvider()));
Service service = bean.create();
assertEquals("DOMSourcePayloadProviderService", service.getName().getLocalPart());
InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
assertNotNull(intf);
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setBus(getBus());
svrFactory.setServiceFactory(bean);
String address = "http://localhost:9000/test";
svrFactory.setAddress(address);
svrFactory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
ServerImpl server = (ServerImpl) svrFactory.create();
assertEquals(1, service.getServiceInfos().get(0).getEndpoints().size());
Endpoint endpoint = server.getEndpoint();
Binding binding = endpoint.getBinding();
assertTrue(binding instanceof XMLBinding);
Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID, "/org/apache/cxf/jaxws/provider/sayHi.xml");
addNamespace("j", "http://service.jaxws.cxf.apache.org/");
assertValid("/j:sayHi", res);
}
Aggregations