use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class AbstractJaxrsClassesScanServer method setJaxrsResources.
protected void setJaxrsResources(JAXRSServerFactoryBean factory) {
try {
final Map<Class<? extends Annotation>, Collection<Class<?>>> classes = ClasspathScanner.findClasses(basePackages, Provider.class, Path.class);
List<Object> jaxrsServices = JAXRSServerFactoryBeanDefinitionParser.createBeansFromDiscoveredClasses(super.applicationContext, classes.get(Path.class), null);
List<Object> jaxrsProviders = JAXRSServerFactoryBeanDefinitionParser.createBeansFromDiscoveredClasses(super.applicationContext, classes.get(Provider.class), null);
factory.setServiceBeans(jaxrsServices);
factory.setProviders(jaxrsProviders);
} catch (Exception ex) {
throw new ServiceConstructionException(ex);
}
}
use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class AbstractSpringComponentScanServer method setJaxrsResources.
protected void setJaxrsResources(JAXRSServerFactoryBean factory) {
Set<String> componentScanPackagesSet = parseSetProperty(componentScanPackages);
Set<String> componentScanBeansSet = parseSetProperty(componentScanBeans);
for (String beanName : applicationContext.getBeanDefinitionNames()) {
if (isValidComponent(beanName, Path.class, componentScanPackagesSet, componentScanBeansSet)) {
SpringResourceFactory resourceFactory = new SpringResourceFactory(beanName);
resourceFactory.setApplicationContext(applicationContext);
resourceProviders.add(resourceFactory);
} else if (isValidComponent(beanName, Provider.class, componentScanPackagesSet, componentScanBeansSet)) {
jaxrsProviders.add(getProviderBean(beanName));
} else if (isValidComponent(beanName, org.apache.cxf.annotations.Provider.class, componentScanPackagesSet, componentScanBeansSet)) {
addCxfProvider(getProviderBean(beanName));
}
}
if (!StringUtils.isEmpty(classesScanPackages)) {
try {
final Map<Class<? extends Annotation>, Collection<Class<?>>> classes = ClasspathScanner.findClasses(classesScanPackages, Provider.class, org.apache.cxf.annotations.Provider.class);
jaxrsProviders.addAll(JAXRSServerFactoryBeanDefinitionParser.createBeansFromDiscoveredClasses(applicationContext, classes.get(Provider.class), null));
warnIfDuplicatesAvailable(jaxrsProviders);
addCxfProvidersFromClasses(classes.get(org.apache.cxf.annotations.Provider.class));
} catch (Exception ex) {
throw new ServiceConstructionException(ex);
}
}
factory.setResourceProviders(getResourceProviders());
factory.setProviders(getJaxrsProviders());
setFactoryCxfProviders(factory);
}
use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.
the class JAXBDataBinding method initialize.
@SuppressWarnings("unchecked")
public synchronized void initialize(Service service) {
inInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
inFaultInterceptors.addIfAbsent(JAXBAttachmentSchemaValidationHack.INSTANCE);
// context is already set, don't redo it
if (context != null) {
return;
}
contextClasses = new LinkedHashSet<>();
for (ServiceInfo serviceInfo : service.getServiceInfos()) {
JAXBContextInitializer initializer = new JAXBContextInitializer(getBus(), serviceInfo, contextClasses, typeRefs, this.getUnmarshallerProperties());
initializer.walk();
if (serviceInfo.getProperty("extra.class") != null) {
Set<Class<?>> exClasses = serviceInfo.getProperty("extra.class", Set.class);
contextClasses.addAll(exClasses);
}
}
String tns = getNamespaceToUse(service);
final CachedContextAndSchemas cachedContextAndSchemas;
try {
cachedContextAndSchemas = createJAXBContextAndSchemas(contextClasses, tns);
} catch (JAXBException e1) {
throw new ServiceConstructionException(e1);
}
final JAXBContext ctx = cachedContextAndSchemas.getContext();
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "CREATED_JAXB_CONTEXT", new Object[] { ctx, contextClasses });
}
setContext(ctx);
for (ServiceInfo serviceInfo : service.getServiceInfos()) {
SchemaCollection col = serviceInfo.getXmlSchemaCollection();
if (col.getXmlSchemas().length > 1) {
// someone has already filled in the types
justCheckForJAXBAnnotations(serviceInfo);
continue;
}
boolean schemasFromCache = false;
Collection<DOMSource> schemas = getSchemas();
if (schemas == null || schemas.isEmpty()) {
schemas = cachedContextAndSchemas.getSchemas();
if (schemas != null) {
schemasFromCache = true;
}
} else {
schemasFromCache = true;
}
Set<DOMSource> bi = new LinkedHashSet<>();
if (schemas == null) {
schemas = new LinkedHashSet<>();
try {
for (DOMResult r : generateJaxbSchemas()) {
DOMSource src = new DOMSource(r.getNode(), r.getSystemId());
if (isInBuiltInSchemas(r)) {
bi.add(src);
} else {
schemas.add(src);
}
}
// put any builtins at the end. Anything that DOES import them
// will cause it to load automatically and we'll skip them later
schemas.addAll(bi);
} catch (IOException e) {
throw new ServiceConstructionException("SCHEMA_GEN_EXC", LOG, e);
}
}
for (DOMSource r : schemas) {
if (bi.contains(r)) {
String ns = ((Document) r.getNode()).getDocumentElement().getAttribute("targetNamespace");
if (serviceInfo.getSchema(ns) != null) {
continue;
}
}
// StaxUtils.print(r.getNode());
// System.out.println();
addSchemaDocument(serviceInfo, col, (Document) r.getNode(), r.getSystemId());
}
JAXBSchemaInitializer schemaInit = new JAXBSchemaInitializer(serviceInfo, col, context, this.qualifiedSchemas, tns);
schemaInit.walk();
if (cachedContextAndSchemas != null && !schemasFromCache) {
cachedContextAndSchemas.setSchemas(schemas);
}
}
}
use of org.apache.cxf.service.factory.ServiceConstructionException 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.service.factory.ServiceConstructionException in project cxf by apache.
the class ReflectionServiceFactoryBean method createDefaultDataBinding.
protected DataBinding createDefaultDataBinding() {
Object obj = null;
Class<? extends DataBinding> cls = null;
if (getServiceClass() != null) {
org.apache.cxf.annotations.DataBinding db = getServiceClass().getAnnotation(org.apache.cxf.annotations.DataBinding.class);
if (db != null) {
try {
if (!StringUtils.isEmpty(db.ref())) {
return getBus().getExtension(ResourceManager.class).resolveResource(db.ref(), db.value());
}
cls = db.value();
} catch (Exception e) {
LOG.log(Level.WARNING, "Could not create databinding " + db.value().getName(), e);
}
}
}
if (cls == null && getBus() != null) {
obj = getBus().getProperty(DataBinding.class.getName());
}
try {
if (obj == null && cls == null) {
cls = getJAXBClass();
}
if (obj instanceof String) {
cls = ClassLoaderUtils.loadClass(obj.toString(), getClass(), DataBinding.class);
} else if (obj instanceof Class) {
cls = ((Class<?>) obj).asSubclass(DataBinding.class);
}
try {
return cls.getConstructor(Boolean.TYPE, Map.class).newInstance(this.isQualifyWrapperSchema(), this.getProperties());
} catch (NoSuchMethodException nsme) {
// ignore, use the no-arg constructor
}
return cls.newInstance();
} catch (Exception e) {
throw new ServiceConstructionException(e);
}
}
Aggregations