use of org.apache.cxf.BusException in project cxf by apache.
the class ServiceImpl method createEndpointInfo.
private EndpointInfo createEndpointInfo(AbstractServiceFactoryBean serviceFactory, QName portName, PortInfoImpl portInfo) throws BusException {
EndpointInfo ei = null;
String address = portInfo.getAddress();
String bindingID = BindingID.getBindingID(portInfo.getBindingID());
DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
try {
// the bindingId might be the transportId, just attempt to
// load it to force the factory to load
dfm.getDestinationFactory(bindingID);
} catch (BusException ex) {
// ignore
}
DestinationFactory df = dfm.getDestinationFactoryForUri(address);
String transportId = null;
if (df != null && df.getTransportIds() != null && !df.getTransportIds().isEmpty()) {
transportId = df.getTransportIds().get(0);
} else {
transportId = bindingID;
}
Object config = null;
if (serviceFactory instanceof JaxWsServiceFactoryBean) {
config = new JaxWsSoapBindingConfiguration((JaxWsServiceFactoryBean) serviceFactory);
}
BindingInfo bindingInfo = bus.getExtension(BindingFactoryManager.class).getBindingFactory(bindingID).createBindingInfo(serviceFactory.getService(), bindingID, config);
Service service = serviceFactory.getService();
service.getServiceInfos().get(0).addBinding(bindingInfo);
ei = new EndpointInfo(service.getServiceInfos().get(0), transportId);
ei.setName(portName);
ei.setAddress(address);
ei.setBinding(bindingInfo);
service.getServiceInfos().get(0).addEndpoint(ei);
return ei;
}
use of org.apache.cxf.BusException in project cxf by apache.
the class AbstractWSDLBasedEndpointFactory method createBindingInfo.
protected BindingInfo createBindingInfo() {
BindingFactoryManager mgr = bus.getExtension(BindingFactoryManager.class);
String binding = bindingId;
if (binding == null && bindingConfig != null) {
binding = bindingConfig.getBindingId();
}
if (binding == null) {
// default to soap binding
binding = "http://schemas.xmlsoap.org/soap/";
}
try {
if (binding.contains("/soap")) {
if (bindingConfig == null) {
bindingConfig = createSoapBindingConfig();
}
if (bindingConfig instanceof SoapBindingConfiguration && !((SoapBindingConfiguration) bindingConfig).isSetStyle()) {
((SoapBindingConfiguration) bindingConfig).setStyle(serviceFactory.getStyle());
}
}
bindingFactory = mgr.getBindingFactory(binding);
BindingInfo inf = bindingFactory.createBindingInfo(serviceFactory.getService(), binding, bindingConfig);
for (BindingOperationInfo boi : inf.getOperations()) {
serviceFactory.updateBindingOperation(boi);
Method m = serviceFactory.getMethodDispatcher().getMethod(boi);
serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_OPERATION_CREATED, inf, boi, m);
}
serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_CREATED, inf);
return inf;
} catch (BusException ex) {
throw new ServiceConstructionException(new Message("COULD.NOT.RESOLVE.BINDING", LOG, bindingId), ex);
}
}
use of org.apache.cxf.BusException in project cxf by apache.
the class ClientFactoryBean method create.
public Client create() {
getServiceFactory().reset();
if (getServiceFactory().getProperties() == null) {
getServiceFactory().setProperties(properties);
} else if (properties != null) {
getServiceFactory().getProperties().putAll(properties);
}
Client client = null;
Endpoint ep = null;
try {
ep = createEndpoint();
this.getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_CLIENT_CREATE, ep);
applyProperties(ep);
client = createClient(ep);
initializeAnnotationInterceptors(ep, getServiceClass());
} catch (EndpointException e) {
throw new ServiceConstructionException(e);
} catch (BusException e) {
throw new ServiceConstructionException(e);
}
applyFeatures(client);
this.getServiceFactory().sendEvent(FactoryBeanListener.Event.CLIENT_CREATED, client, ep);
return client;
}
use of org.apache.cxf.BusException 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.BusException in project cxf by apache.
the class WSDLServiceBuilder method buildEndpoint.
public EndpointInfo buildEndpoint(ServiceInfo service, BindingInfo bi, Port port) {
List<?> elements = port.getExtensibilityElements();
String ns = null;
DestinationFactory factory = null;
EndpointInfo ei = null;
if (null != elements && !elements.isEmpty()) {
for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
ns = el.getElementType().getNamespaceURI();
try {
factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
} catch (BusException e) {
// do nothing
}
if (factory != null) {
break;
}
}
if (factory == null) {
ns = ((ExtensibilityElement) elements.get(0)).getElementType().getNamespaceURI();
}
}
if (factory == null) {
// get the transport id from bindingInfo
elements = port.getBinding().getExtensibilityElements();
if (null != elements && !elements.isEmpty()) {
for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
if (el instanceof SOAPBinding) {
ns = ((SOAPBinding) el).getTransportURI();
break;
} else if (el instanceof SOAP12Binding) {
ns = ((SOAP12Binding) el).getTransportURI();
break;
// TODO: this is really ugly, but how to link between
// this binding and this transport ?
}
}
}
if (ns == null) {
if (ignoreUnknownBindings) {
return null;
}
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("MISSING_DESTINATION_FACTORY", LOG, port.getName());
throw new WSDLRuntimeException(msg);
}
try {
factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
} catch (BusException e) {
// do nothing
}
}
if (factory instanceof WSDLEndpointFactory) {
WSDLEndpointFactory wFactory = (WSDLEndpointFactory) factory;
ei = wFactory.createEndpointInfo(bus, service, bi, port.getExtensibilityElements());
}
if (ei == null) {
ei = new EndpointInfo(service, ns);
}
copyDocumentation(ei, port);
ei.setName(new QName(service.getName().getNamespaceURI(), port.getName()));
ei.setBinding(bi);
copyExtensors(ei, port.getExtensibilityElements());
copyExtensionAttributes(ei, port);
service.addEndpoint(ei);
DescriptionInfo d = service.getDescription();
if (null != d) {
d.getDescribed().add(ei);
}
return ei;
}
Aggregations