Search in sources :

Example 36 with MessagePartInfo

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

the class StaxDataBinding method initialize.

public void initialize(Service service) {
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
        if (schemaCollection.getXmlSchemas().length > 1) {
            // Schemas are already populated.
            continue;
        }
        new ServiceModelVisitor(serviceInfo) {

            @Override
            public void begin(MessagePartInfo part) {
                if (part.getTypeQName() != null || part.getElementQName() != null) {
                    return;
                }
                part.setTypeQName(Constants.XSD_ANYTYPE);
            }
        }.walk();
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ServiceModelVisitor(org.apache.cxf.service.ServiceModelVisitor)

Example 37 with MessagePartInfo

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

the class HeaderUtil method getHeaderQNames.

private static Set<QName> getHeaderQNames(BindingMessageInfo bmi) {
    Set<QName> set = new HashSet<>();
    List<MessagePartInfo> mps = bmi.getMessageInfo().getMessageParts();
    List<ExtensibilityElement> extList = bmi.getExtensors(ExtensibilityElement.class);
    if (extList != null) {
        for (ExtensibilityElement ext : extList) {
            if (SOAPBindingUtil.isSOAPHeader(ext)) {
                SoapHeader header = SOAPBindingUtil.getSoapHeader(ext);
                String pn = header.getPart();
                for (MessagePartInfo mpi : mps) {
                    if (pn.equals(mpi.getName().getLocalPart())) {
                        if (mpi.isElement()) {
                            set.add(mpi.getElementQName());
                        } else {
                            set.add(mpi.getTypeQName());
                        }
                        break;
                    }
                }
            }
        }
    }
    return set;
}
Also used : QName(javax.xml.namespace.QName) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) HashSet(java.util.HashSet)

Example 38 with MessagePartInfo

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

the class SoapBindingFactory method createSoapBinding.

private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException {
    boolean isSoap12 = bi.getSoapVersion() instanceof Soap12;
    Bus bs = getBus();
    WSDLManager m = bs.getExtension(WSDLManager.class);
    ExtensionRegistry extensionRegistry = m.getExtensionRegistry();
    SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12);
    soapBinding.setStyle(bi.getStyle());
    soapBinding.setTransportURI(bi.getTransportURI());
    bi.addExtensor(soapBinding);
    for (BindingOperationInfo b : bi.getOperations()) {
        for (BindingFaultInfo faultInfo : b.getFaults()) {
            SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12);
            soapFault.setUse("literal");
            soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart());
            faultInfo.addExtensor(soapFault);
        }
        SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class);
        SoapOperation soapOperation = SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12);
        soapOperation.setSoapActionURI(soi.getAction());
        soapOperation.setStyle(soi.getStyle());
        boolean isRpc = "rpc".equals(soapOperation.getStyle());
        b.addExtensor(soapOperation);
        if (b.getInput() != null) {
            List<String> bodyParts = null;
            List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class);
            if (headerInfos != null && !headerInfos.isEmpty()) {
                bodyParts = new ArrayList<>();
                for (MessagePartInfo part : b.getInput().getMessageParts()) {
                    bodyParts.add(part.getName().getLocalPart());
                }
                for (SoapHeaderInfo headerInfo : headerInfos) {
                    SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12);
                    soapHeader.setMessage(b.getInput().getMessageInfo().getName());
                    soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
                    soapHeader.setUse("literal");
                    bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
                    headerInfo.getPart().setProperty(HEADER, true);
                    b.getInput().addExtensor(soapHeader);
                }
            }
            SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12);
            body.setUse("literal");
            if (isRpc) {
                body.setNamespaceURI(b.getName().getNamespaceURI());
            }
            if (bodyParts != null) {
                body.setParts(bodyParts);
            }
            b.getInput().addExtensor(body);
        }
        if (b.getOutput() != null) {
            List<String> bodyParts = null;
            List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class);
            if (headerInfos != null && !headerInfos.isEmpty()) {
                bodyParts = new ArrayList<>();
                for (MessagePartInfo part : b.getOutput().getMessageParts()) {
                    bodyParts.add(part.getName().getLocalPart());
                }
                for (SoapHeaderInfo headerInfo : headerInfos) {
                    SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12);
                    soapHeader.setMessage(b.getOutput().getMessageInfo().getName());
                    soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
                    soapHeader.setUse("literal");
                    bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
                    b.getOutput().addExtensor(soapHeader);
                }
            }
            SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12);
            body.setUse("literal");
            if (isRpc) {
                body.setNamespaceURI(b.getName().getNamespaceURI());
            }
            if (bodyParts != null) {
                body.setParts(bodyParts);
            }
            b.getOutput().addExtensor(body);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry) WSDLManager(org.apache.cxf.wsdl.WSDLManager) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 39 with MessagePartInfo

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

the class SoapBindingFactory method addSoapBodyPart.

private void addSoapBodyPart(MessageInfo msg, List<MessagePartInfo> bodyParts, String partName) {
    MessagePartInfo mpi = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), partName));
    bodyParts.add(mpi);
}
Also used : QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 40 with MessagePartInfo

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

the class RPCInInterceptor method handleMessage.

public void handleMessage(Message message) {
    if (isGET(message)) {
        LOG.fine("RPCInInterceptor skipped in HTTP GET method");
        return;
    }
    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    if (!StaxUtils.toNextElement(xmlReader)) {
        message.setContent(Exception.class, new RuntimeException("There must be a method name element."));
    }
    String opName = xmlReader.getLocalName();
    if (isRequestor(message) && opName.endsWith("Response")) {
        opName = opName.substring(0, opName.length() - 8);
    }
    final BindingOperationInfo operation;
    if (message.getExchange().getBindingOperationInfo() == null) {
        operation = getOperation(message, new QName(xmlReader.getNamespaceURI(), opName));
        if (operation == null) {
            // it's doc-lit-bare
            new BareInInterceptor().handleMessage(message);
            return;
        }
        setMessage(message, operation);
    } else {
        operation = message.getExchange().getBindingOperationInfo();
        if (!operation.getName().getLocalPart().equals(opName)) {
            String sa = (String) message.get(SoapBindingConstants.SOAP_ACTION);
            throw new Fault("SOAP_ACTION_MISMATCH_OP", LOG, null, sa, opName);
        }
    }
    MessageInfo msg;
    DataReader<XMLStreamReader> dr = getDataReader(message, XMLStreamReader.class);
    if (!isRequestor(message)) {
        msg = operation.getOperationInfo().getInput();
    } else {
        msg = operation.getOperationInfo().getOutput();
    }
    message.put(MessageInfo.class, msg);
    MessageContentsList parameters = new MessageContentsList();
    StaxUtils.nextEvent(xmlReader);
    boolean hasNext = true;
    Iterator<MessagePartInfo> itr = msg.getMessageParts().iterator();
    while (itr.hasNext()) {
        MessagePartInfo part = itr.next();
        if (hasNext) {
            hasNext = StaxUtils.toNextElement(xmlReader);
        }
        if (hasNext) {
            QName qn = xmlReader.getName();
            if (qn.equals(SOAP12_RESULT)) {
                // just ignore this.   The parts should work correctly.
                try {
                    while (xmlReader.getEventType() != XMLStreamConstants.END_ELEMENT) {
                        xmlReader.next();
                    }
                    xmlReader.next();
                } catch (XMLStreamException e) {
                // ignore
                }
                StaxUtils.toNextElement(xmlReader);
                qn = xmlReader.getName();
            }
            // WSI-BP states that RPC/Lit part accessors should be completely unqualified
            // However, older toolkits (Axis 1.x) are qualifying them.   We'll go
            // ahead and just match on the localpart.   The RPCOutInterceptor
            // will always generate WSI-BP compliant messages so it's unknown if
            // the non-WSI-BP toolkits will be able to understand the CXF
            // generated messages if they are expecting it to be qualified.
            Iterator<MessagePartInfo> partItr = msg.getMessageParts().iterator();
            while (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart()) && partItr.hasNext()) {
                part = partItr.next();
            }
            // only check the localpart as explained above
            if (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart())) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("UNKNOWN_RPC_LIT_PART", LOG, qn));
            }
            try {
                parameters.put(part, dr.read(part, xmlReader));
            } catch (Fault f) {
                if (!isRequestor(message)) {
                    f.setFaultCode(Fault.FAULT_CODE_CLIENT);
                }
                throw f;
            }
        }
    }
    message.setContent(List.class, parameters);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessageContentsList(org.apache.cxf.message.MessageContentsList) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) XMLStreamException(javax.xml.stream.XMLStreamException) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)163 QName (javax.xml.namespace.QName)99 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)46 MessageInfo (org.apache.cxf.service.model.MessageInfo)38 Test (org.junit.Test)38 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)29 Fault (org.apache.cxf.interceptor.Fault)21 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)19 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)13 Method (java.lang.reflect.Method)12