Search in sources :

Example 6 with ServiceConstructionException

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);
    }
}
Also used : Path(javax.ws.rs.Path) Collection(java.util.Collection) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Annotation(java.lang.annotation.Annotation) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Provider(javax.ws.rs.ext.Provider)

Example 7 with ServiceConstructionException

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);
}
Also used : ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Annotation(java.lang.annotation.Annotation) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) Provider(javax.ws.rs.ext.Provider) Collection(java.util.Collection)

Example 8 with ServiceConstructionException

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);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DOMSource(javax.xml.transform.dom.DOMSource) DOMResult(javax.xml.transform.dom.DOMResult) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) IOException(java.io.IOException) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) CachedContextAndSchemas(org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas)

Example 9 with ServiceConstructionException

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);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) Method(java.lang.reflect.Method) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) BusException(org.apache.cxf.BusException)

Example 10 with ServiceConstructionException

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);
    }
}
Also used : ResourceManager(org.apache.cxf.resource.ResourceManager) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) BusException(org.apache.cxf.BusException) MalformedURLException(java.net.MalformedURLException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) EndpointException(org.apache.cxf.endpoint.EndpointException) DataBinding(org.apache.cxf.databinding.DataBinding) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NamespaceMap(org.apache.ws.commons.schema.utils.NamespaceMap)

Aggregations

ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)32 Message (org.apache.cxf.common.i18n.Message)10 Endpoint (org.apache.cxf.endpoint.Endpoint)8 Method (java.lang.reflect.Method)7 QName (javax.xml.namespace.QName)7 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)7 BusException (org.apache.cxf.BusException)5 Annotation (java.lang.annotation.Annotation)4 Collection (java.util.Collection)4 Bus (org.apache.cxf.Bus)4 EndpointException (org.apache.cxf.endpoint.EndpointException)4 IOException (java.io.IOException)3 Application (javax.ws.rs.core.Application)3 Provider (javax.ws.rs.ext.Provider)3 JAXBContext (javax.xml.bind.JAXBContext)3 JAXBException (javax.xml.bind.JAXBException)3 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)3 MalformedURLException (java.net.MalformedURLException)2