Search in sources :

Example 91 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo 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;
        XmlSchema schema = 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;
            }
        }
        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 92 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class ReflectionServiceFactoryBean method buildServiceFromClass.

protected void buildServiceFromClass() {
    Object o = getBus().getProperty("requireExplicitContractLocation");
    if (o != null && ("true".equals(o) || Boolean.TRUE.equals(o))) {
        throw new ServiceConstructionException(new Message("NO_WSDL_PROVIDED", LOG, getServiceClass().getName()));
    }
    if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Creating Service " + getServiceQName() + " from class " + getServiceClass().getName());
    }
    populateFromClass = true;
    if (Proxy.isProxyClass(this.getServiceClass())) {
        LOG.log(Level.WARNING, "USING_PROXY_FOR_SERVICE", getServiceClass());
    }
    sendEvent(Event.CREATE_FROM_CLASS, getServiceClass());
    ServiceInfo serviceInfo = new ServiceInfo();
    SchemaCollection col = serviceInfo.getXmlSchemaCollection();
    col.getXmlSchemaCollection().setSchemaResolver(new CatalogXmlSchemaURIResolver(this.getBus()));
    col.getExtReg().registerSerializer(MimeAttribute.class, new MimeSerializer());
    ServiceImpl service = new ServiceImpl(serviceInfo);
    setService(service);
    setServiceProperties();
    serviceInfo.setName(getServiceQName());
    serviceInfo.setTargetNamespace(serviceInfo.getName().getNamespaceURI());
    sendEvent(Event.SERVICE_SET, getService());
    createInterface(serviceInfo);
    Set<?> wrapperClasses = this.getExtraClass();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (wrapperClasses != null && !wrapperClasses.isEmpty()) {
            si.setProperty(EXTRA_CLASS, wrapperClasses);
        }
    }
    initializeDataBindings();
    boolean isWrapped = isWrapped() || hasWrappedMethods(serviceInfo.getInterface());
    if (isWrapped) {
        initializeWrappedSchema(serviceInfo);
    }
    for (OperationInfo opInfo : serviceInfo.getInterface().getOperations()) {
        Method m = (Method) opInfo.getProperty(METHOD);
        if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
            createBareMessage(serviceInfo, opInfo, false);
        }
        if (!isWrapped(m) && !isRPC(m) && opInfo.getOutput() != null) {
            createBareMessage(serviceInfo, opInfo, true);
        }
        if (opInfo.hasFaults()) {
            // check to make sure the faults are elements
            for (FaultInfo fault : opInfo.getFaults()) {
                QName qn = (QName) fault.getProperty("elementName");
                MessagePartInfo part = fault.getFirstMessagePart();
                if (!part.isElement()) {
                    part.setElement(true);
                    part.setElementQName(qn);
                    checkForElement(serviceInfo, part);
                }
            }
        }
    }
    if (LOG.isLoggable(Level.FINE) || isValidate()) {
        ServiceModelSchemaValidator validator = new ServiceModelSchemaValidator(serviceInfo);
        validator.walk();
        String validationComplaints = validator.getComplaints();
        if (!"".equals(validationComplaints)) {
            if (isValidate()) {
                LOG.warning(validationComplaints);
            } else {
                LOG.fine(validationComplaints);
            }
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) UnwrappedOperationInfo(org.apache.cxf.service.model.UnwrappedOperationInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) Message(org.apache.cxf.common.i18n.Message) ServiceImpl(org.apache.cxf.service.ServiceImpl) QName(javax.xml.namespace.QName) ServiceModelSchemaValidator(org.apache.cxf.service.ServiceModelSchemaValidator) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) Method(java.lang.reflect.Method) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) MimeSerializer(org.apache.cxf.databinding.source.mime.MimeSerializer) CatalogXmlSchemaURIResolver(org.apache.cxf.catalog.CatalogXmlSchemaURIResolver) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 93 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class SimpleBatchSTSClient method findOperation.

protected BindingOperationInfo findOperation(String suffix) {
    BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
    for (BindingOperationInfo boi : bi.getOperations()) {
        SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
        if (soi != null && soi.getAction() != null && soi.getAction().endsWith(suffix)) {
            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
            Conduit conduit = client.getConduit();
            EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
            setPolicyInternal(effectivePolicy.getPolicy());
            return boi;
        }
    }
    // we can at least find it by name and then set the action and such manually later.
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (boi.getInput().getMessageInfo().getMessageParts().size() > 0) {
            MessagePartInfo mpi = boi.getInput().getMessageInfo().getMessagePart(0);
            if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
                return boi;
            }
        }
    }
    return null;
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 94 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class AegisDatabinding method initializeMessageTypes.

protected void initializeMessageTypes(ServiceInfo s, AbstractMessageContainer container, int partType) {
    if (container == null) {
        return;
    }
    SchemaCollection col = s.getXmlSchemaCollection();
    for (MessagePartInfo part : container.getMessageParts()) {
        if (part.getXmlSchema() == null) {
            if (part.isElement()) {
                XmlSchemaAnnotated tp = col.getElementByQName(part.getElementQName());
                part.setXmlSchema(tp);
            } else {
                XmlSchemaAnnotated tp = col.getTypeByQName(part.getTypeQName());
                part.setXmlSchema(tp);
            }
        }
    }
}
Also used : XmlSchemaAnnotated(org.apache.ws.commons.schema.XmlSchemaAnnotated) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 95 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class SoapOutInterceptor method handleHeaderPart.

private boolean handleHeaderPart(boolean preexistingHeaders, SoapMessage message, String soapPrefix) {
    // add MessagePart to soapHeader if necessary
    boolean endedHeader = false;
    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    if (bop == null) {
        return endedHeader;
    }
    XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
    boolean startedHeader = false;
    BindingOperationInfo unwrappedOp = bop;
    if (bop.isUnwrapped()) {
        unwrappedOp = bop.getWrappedOperation();
    }
    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? unwrappedOp.getInput() : unwrappedOp.getOutput();
    BindingMessageInfo wrappedBmi = client ? bop.getInput() : bop.getOutput();
    if (bmi == null) {
        return endedHeader;
    }
    if (wrappedBmi.getMessageInfo().getMessagePartsNumber() > 0) {
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        if (objs == null) {
            return endedHeader;
        }
        SoapVersion soapVersion = message.getVersion();
        List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
        if (headers == null) {
            return endedHeader;
        }
        for (SoapHeaderInfo header : headers) {
            MessagePartInfo part = header.getPart();
            if (wrappedBmi != bmi) {
                part = wrappedBmi.getMessageInfo().addMessagePart(part.getName());
            }
            if (part.getIndex() >= objs.size()) {
                // The optional out of band header is not a part of parameters of the method
                continue;
            }
            Object arg = objs.get(part);
            if (arg == null) {
                continue;
            }
            objs.remove(part);
            if (!(startedHeader || preexistingHeaders)) {
                try {
                    xtw.writeStartElement(soapPrefix, soapVersion.getHeader().getLocalPart(), soapVersion.getNamespace());
                } catch (XMLStreamException e) {
                    throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
                }
                startedHeader = true;
            }
            DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message);
            dataWriter.write(arg, header.getPart(), xtw);
        }
        if (startedHeader || preexistingHeaders) {
            try {
                xtw.writeEndElement();
                endedHeader = true;
            } catch (XMLStreamException e) {
                throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
            }
        }
    }
    return endedHeader;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapFault(org.apache.cxf.binding.soap.SoapFault) MessageContentsList(org.apache.cxf.message.MessageContentsList) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Exchange(org.apache.cxf.message.Exchange) SoapVersion(org.apache.cxf.binding.soap.SoapVersion) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) DelegatingXMLStreamWriter(org.apache.cxf.staxutils.DelegatingXMLStreamWriter)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)157 QName (javax.xml.namespace.QName)97 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)44 Test (org.junit.Test)38 MessageInfo (org.apache.cxf.service.model.MessageInfo)36 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)27 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 Fault (org.apache.cxf.interceptor.Fault)20 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)18 Endpoint (org.apache.cxf.endpoint.Endpoint)18 MessageContentsList (org.apache.cxf.message.MessageContentsList)18 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)16 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Exchange (org.apache.cxf.message.Exchange)13 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)12 FaultInfo (org.apache.cxf.service.model.FaultInfo)11