Search in sources :

Example 31 with ServiceConstructionException

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

the class ReflectionServiceFactoryBean method createBareMessage.

protected void createBareMessage(ServiceInfo serviceInfo, OperationInfo opInfo, boolean isOut) {
    MessageInfo message = isOut ? opInfo.getOutput() : opInfo.getInput();
    final List<MessagePartInfo> messageParts = message.getMessageParts();
    if (messageParts.isEmpty()) {
        return;
    }
    Method method = (Method) opInfo.getProperty(METHOD);
    int paraNumber = 0;
    for (MessagePartInfo mpi : messageParts) {
        SchemaInfo schemaInfo = null;
        QName qname = (QName) mpi.getProperty(ELEMENT_NAME);
        if (messageParts.size() == 1 && qname == null) {
            qname = !isOut ? getInParameterName(opInfo, method, -1) : getOutParameterName(opInfo, method, -1);
            if (qname.getLocalPart().startsWith("arg") || qname.getLocalPart().startsWith("return")) {
                qname = isOut ? new QName(qname.getNamespaceURI(), method.getName() + "Response") : new QName(qname.getNamespaceURI(), method.getName());
            }
        } else if (isOut && messageParts.size() > 1 && qname == null) {
            while (!isOutParam(method, paraNumber)) {
                paraNumber++;
            }
            qname = getOutParameterName(opInfo, method, paraNumber);
        } else if (qname == null) {
            qname = getInParameterName(opInfo, method, paraNumber);
        }
        for (SchemaInfo s : serviceInfo.getSchemas()) {
            if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
                schemaInfo = s;
                break;
            }
        }
        final XmlSchema schema;
        if (schemaInfo == null) {
            schemaInfo = getOrCreateSchema(serviceInfo, qname.getNamespaceURI(), true);
            schema = schemaInfo.getSchema();
        } else {
            schema = schemaInfo.getSchema();
            if (schema != null && schema.getElementByName(qname) != null) {
                mpi.setElement(true);
                mpi.setElementQName(qname);
                mpi.setXmlSchema(schema.getElementByName(qname));
                paraNumber++;
                continue;
            }
        }
        // cached element is now invalid
        schemaInfo.setElement(null);
        XmlSchemaElement el = new XmlSchemaElement(schema, true);
        el.setName(qname.getLocalPart());
        el.setNillable(true);
        if (mpi.isElement()) {
            XmlSchemaElement oldEl = (XmlSchemaElement) mpi.getXmlSchema();
            if (null != oldEl && !oldEl.getQName().equals(qname)) {
                el.setSchemaTypeName(oldEl.getSchemaTypeName());
                el.setSchemaType(oldEl.getSchemaType());
                if (oldEl.getSchemaTypeName() != null) {
                    addImport(schema, oldEl.getSchemaTypeName().getNamespaceURI());
                }
            }
            mpi.setElement(true);
            mpi.setXmlSchema(el);
            mpi.setElementQName(qname);
            mpi.setConcreteName(qname);
            continue;
        }
        if (null == mpi.getTypeQName() && mpi.getXmlSchema() == null) {
            throw new ServiceConstructionException(new Message("UNMAPPABLE_PORT_TYPE", LOG, method.getDeclaringClass().getName(), method.getName(), mpi.getName()));
        }
        if (mpi.getTypeQName() != null) {
            el.setSchemaTypeName(mpi.getTypeQName());
        } else {
            el.setSchemaType((XmlSchemaType) mpi.getXmlSchema());
        }
        mpi.setXmlSchema(el);
        mpi.setConcreteName(qname);
        if (mpi.getTypeQName() != null) {
            addImport(schema, mpi.getTypeQName().getNamespaceURI());
        }
        mpi.setElement(true);
        mpi.setElementQName(qname);
        paraNumber++;
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) XmlSchema(org.apache.ws.commons.schema.XmlSchema) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) Method(java.lang.reflect.Method) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MessageInfo(org.apache.cxf.service.model.MessageInfo) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 32 with ServiceConstructionException

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

the class WSDLServiceFactory method create.

public Service create() {
    List<ServiceInfo> services;
    if (serviceName == null) {
        try {
            WSDLServiceBuilder builder = new WSDLServiceBuilder(getBus());
            builder.setAllowElementRefs(allowRefs);
            services = builder.buildServices(definition);
        } catch (XmlSchemaException ex) {
            throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
        }
        if (services.isEmpty()) {
            throw new ServiceConstructionException(new Message("NO_SERVICE_EXC", LOG));
        }
        // @@TODO  - this isn't good, need to return all the services
        serviceName = services.get(0).getName();
        // get all the service info's that match that first one.
        Iterator<ServiceInfo> it = services.iterator();
        while (it.hasNext()) {
            if (!it.next().getName().equals(serviceName)) {
                it.remove();
            }
        }
    } else {
        javax.wsdl.Service wsdlService = definition.getService(serviceName);
        if (wsdlService == null) {
            if ((!PartialWSDLProcessor.isServiceExisted(definition, serviceName)) && (!PartialWSDLProcessor.isBindingExisted(definition, serviceName)) && (PartialWSDLProcessor.isPortTypeExisted(definition, serviceName))) {
                try {
                    Map<QName, PortType> portTypes = CastUtils.cast(definition.getAllPortTypes());
                    String existPortName = null;
                    PortType portType = null;
                    for (Map.Entry<QName, PortType> entry : portTypes.entrySet()) {
                        existPortName = entry.getKey().getLocalPart();
                        if (serviceName.getLocalPart().contains(existPortName)) {
                            portType = entry.getValue();
                            break;
                        }
                    }
                    WSDLFactory factory = WSDLFactory.newInstance();
                    ExtensionRegistry extReg = factory.newPopulatedExtensionRegistry();
                    Binding binding = PartialWSDLProcessor.doAppendBinding(definition, existPortName, portType, extReg);
                    definition.addBinding(binding);
                    wsdlService = PartialWSDLProcessor.doAppendService(definition, existPortName, extReg, binding);
                    definition.addService(wsdlService);
                } catch (Exception e) {
                    throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
                }
            } else {
                throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
            }
        }
        try {
            services = new WSDLServiceBuilder(getBus()).buildServices(definition, wsdlService, endpointName);
            if (services.isEmpty()) {
                throw new ServiceConstructionException(new Message("NO_SUCH_ENDPOINT_EXC", LOG, endpointName));
            }
        } catch (XmlSchemaException ex) {
            throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
        }
    }
    ServiceImpl service = new ServiceImpl(services);
    setService(service);
    return service;
}
Also used : Binding(javax.wsdl.Binding) Message(org.apache.cxf.common.i18n.Message) XmlSchemaException(org.apache.ws.commons.schema.XmlSchemaException) QName(javax.xml.namespace.QName) ServiceImpl(org.apache.cxf.service.ServiceImpl) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) XmlSchemaException(org.apache.ws.commons.schema.XmlSchemaException) WSDLException(javax.wsdl.WSDLException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) WSDLFactory(javax.wsdl.factory.WSDLFactory) Map(java.util.Map) PortType(javax.wsdl.PortType)

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