Search in sources :

Example 1 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 2 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 3 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class ServiceImpl method initialize.

final void initialize(Bus b, URL url, WebServiceFeature... f) {
    if (b == null) {
        b = BusFactory.getThreadDefaultBus(true);
    }
    serviceFeatures = f;
    bus = b;
    handlerResolver = new HandlerResolverImpl(bus, serviceName, clazz);
    if (null == url && null != bus) {
        ServiceContractResolverRegistry registry = bus.getExtension(ServiceContractResolverRegistry.class);
        if (null != registry) {
            URI uri = registry.getContractLocation(serviceName);
            if (null != uri) {
                try {
                    url = uri.toURL();
                } catch (MalformedURLException e) {
                    LOG.log(Level.FINE, "resolve qname failed", serviceName);
                    throw new WebServiceException(e);
                }
            }
        }
    }
    wsdlURL = url == null ? null : url.toString();
    if (url != null) {
        try {
            initializePorts();
        } catch (ServiceConstructionException e) {
            throw new WebServiceException(e);
        }
    }
}
Also used : HandlerResolverImpl(org.apache.cxf.jaxws.handler.HandlerResolverImpl) MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) ServiceContractResolverRegistry(org.apache.cxf.endpoint.ServiceContractResolverRegistry) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) URI(java.net.URI)

Example 4 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class AbstractJAXWSMethodInvoker method getProviderServiceObjectMethod.

private Method getProviderServiceObjectMethod(Method m, Class<?> serviceObjectClass) {
    if (!Provider.class.isAssignableFrom(serviceObjectClass)) {
        return m;
    }
    Class<?> currentSvcClass = serviceObjectClass;
    Class<?> genericType = null;
    while (currentSvcClass != null) {
        genericType = getProviderGenericType(currentSvcClass);
        if (genericType != null) {
            break;
        }
        // Check superclass until top
        currentSvcClass = currentSvcClass.getSuperclass();
    }
    // Should never happens
    if (genericType == null) {
        return m;
    }
    try {
        return serviceObjectClass.getMethod("invoke", genericType);
    } catch (Exception e) {
        throw new ServiceConstructionException(e);
    }
}
Also used : ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) ExecutionException(java.util.concurrent.ExecutionException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Provider(javax.xml.ws.Provider)

Example 5 with ServiceConstructionException

use of org.apache.cxf.service.factory.ServiceConstructionException in project cxf by apache.

the class JAXWSMethodDispatcher method bind.

public void bind(OperationInfo o, Method... methods) {
    Method[] newMethods = new Method[methods.length];
    int i = 0;
    for (Method m : methods) {
        try {
            newMethods[i] = getImplementationMethod(m);
            i++;
        } catch (NoSuchMethodException e) {
            if (m.getName().endsWith("Async") && (Future.class.equals(m.getReturnType()) || Response.class.equals(m.getReturnType()))) {
                newMethods[i] = m;
                i++;
                continue;
            }
            Class<?> endpointClass = implInfo.getImplementorClass();
            Message msg = new Message("SEI_METHOD_NOT_FOUND", LOG, m.getName(), endpointClass.getName());
            throw new ServiceConstructionException(msg, e);
        }
    }
    super.bind(o, newMethods);
}
Also used : Message(org.apache.cxf.common.i18n.Message) Method(java.lang.reflect.Method) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Endpoint(org.apache.cxf.endpoint.Endpoint)

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