Search in sources :

Example 11 with SoapBody

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBody in project cxf by apache.

the class WSIBPValidator method checkR2201Input.

private boolean checkR2201Input(final Operation operation, final BindingOperation bop) {
    List<Part> partsList = wsdlHelper.getInMessageParts(operation);
    int inmessagePartsCount = partsList.size();
    SoapBody soapBody = SOAPBindingUtil.getBindingInputSOAPBody(bop);
    if (soapBody != null) {
        List<?> parts = soapBody.getParts();
        int boundPartSize = parts == null ? inmessagePartsCount : parts.size();
        SoapHeader soapHeader = SOAPBindingUtil.getBindingInputSOAPHeader(bop);
        boundPartSize = soapHeader != null && soapHeader.getMessage().equals(operation.getInput().getMessage().getQName()) ? boundPartSize - 1 : boundPartSize;
        if (parts != null) {
            Iterator<?> partsIte = parts.iterator();
            while (partsIte.hasNext()) {
                String partName = (String) partsIte.next();
                boolean isDefined = false;
                for (Part part : partsList) {
                    if (partName.equalsIgnoreCase(part.getName())) {
                        isDefined = true;
                        break;
                    }
                }
                if (!isDefined) {
                    addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2201") + "Operation '" + operation.getName() + "' soapBody parts : " + partName + " not found in the message, wrong WSDL");
                    return false;
                }
            }
        } else {
            if (partsList.size() > 1) {
                addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2210") + "Operation '" + operation.getName() + "' more than one part bound to body");
                return false;
            }
        }
        if (boundPartSize > 1) {
            addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2201") + "Operation '" + operation.getName() + "' more than one part bound to body");
            return false;
        }
    }
    return true;
}
Also used : Part(javax.wsdl.Part) MIMEPart(javax.wsdl.extensions.mime.MIMEPart) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)

Example 12 with SoapBody

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBody in project cxf by apache.

the class RPCInInterceptor method getOperation.

private BindingOperationInfo getOperation(Message message, QName opName) {
    BindingOperationInfo bop = ServiceModelUtil.getOperation(message.getExchange(), opName);
    if (bop == null) {
        Endpoint ep = message.getExchange().getEndpoint();
        if (ep == null) {
            return null;
        }
        BindingInfo service = ep.getEndpointInfo().getBinding();
        boolean output = !isRequestor(message);
        for (BindingOperationInfo info : service.getOperations()) {
            if (info.getName().getLocalPart().equals(opName.getLocalPart())) {
                SoapBody body = null;
                if (output) {
                    body = info.getOutput().getExtensor(SoapBody.class);
                } else {
                    body = info.getInput().getExtensor(SoapBody.class);
                }
                if (body != null && opName.getNamespaceURI().equals(body.getNamespaceURI())) {
                    return info;
                }
            }
        }
    }
    return bop;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)

Example 13 with SoapBody

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBody in project cxf by apache.

the class RPCOutInterceptor method addOperationNode.

protected String addOperationNode(NSStack nsStack, Message message, XMLStreamWriter xmlWriter, boolean output, BindingOperationInfo boi) throws XMLStreamException {
    String ns = boi.getName().getNamespaceURI();
    SoapBody body = null;
    if (output) {
        body = boi.getOutput().getExtensor(SoapBody.class);
    } else {
        body = boi.getInput().getExtensor(SoapBody.class);
    }
    if (body != null) {
        // do it once, as it might internally use reflection...
        final String nsUri = body.getNamespaceURI();
        if (!StringUtils.isEmpty(nsUri)) {
            ns = nsUri;
        }
    }
    nsStack.add(ns);
    String prefix = nsStack.getPrefix(ns);
    String name = output ? boi.getName().getLocalPart() + "Response" : boi.getName().getLocalPart();
    StaxUtils.writeStartElement(xmlWriter, prefix, name, ns);
    return ns;
}
Also used : SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)

Example 14 with SoapBody

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBody in project cxf by apache.

the class SoapBindingFactory method handleMimePart.

private List<MessagePartInfo> handleMimePart(MIMEPart mpart, List<MessagePartInfo> attParts, MessageInfo msg, BindingMessageInfo bmsg, List<MessagePartInfo> bodyParts, List<MessagePartInfo> messageParts) {
    if (mpart.getExtensibilityElements().size() < 1) {
        throw new RuntimeException("MIMEPart should at least contain one element!");
    }
    String partName = null;
    for (Object content : mpart.getExtensibilityElements()) {
        if (content instanceof MIMEContent) {
            MIMEContent mc = (MIMEContent) content;
            partName = mc.getPart();
            if (attParts == null) {
                attParts = new LinkedList<MessagePartInfo>();
            }
            if (StringUtils.isEmpty(partName)) {
                throw new RuntimeException("Problem with WSDL: mime content element in operation " + bmsg.getBindingOperation().getName().getLocalPart() + " does not specify a part.");
            }
            MessagePartInfo mpi = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), partName));
            mpi.setProperty(Message.CONTENT_TYPE, mc.getType());
            attParts.add(mpi);
            // Attachments shouldn't be part of the body message
            bmsg.getMessageParts().remove(mpi);
        } else if (SOAPBindingUtil.isSOAPBody(content)) {
            SoapBody sb = SOAPBindingUtil.getSoapBody(content);
            if (sb.getParts() != null && sb.getParts().size() == 1) {
                partName = (String) sb.getParts().get(0);
            }
            // We can have a list of empty part names here.
            if (partName != null) {
                addSoapBodyPart(msg, bodyParts, partName);
            }
        } else if (SOAPBindingUtil.isSOAPHeader(content)) {
            SoapHeader header = SOAPBindingUtil.getSoapHeader(content);
            SoapHeaderInfo headerInfo = new SoapHeaderInfo();
            headerInfo.setUse(header.getUse());
            if (StringUtils.isEmpty(header.getPart())) {
                throw new RuntimeException("Problem with WSDL: soap:header element in operation " + bmsg.getBindingOperation().getName().getLocalPart() + " does not specify a part.");
            }
            MessagePartInfo mpi = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), header.getPart()));
            if (mpi != null && header.getMessage() != null && !mpi.getMessageInfo().getName().equals(header.getMessage())) {
                mpi = null;
                // out of band, let's find it
                for (MessagePartInfo mpi2 : msg.getOutOfBandParts()) {
                    if (mpi2.getName().getLocalPart().equals(header.getPart()) && mpi2.getMessageInfo().getName().equals(header.getMessage())) {
                        mpi = mpi2;
                    }
                }
            }
            if (mpi != null) {
                headerInfo.setPart(mpi);
                messageParts.remove(mpi);
                bmsg.getMessageParts().remove(mpi);
                bmsg.addExtensor(headerInfo);
            }
        }
    }
    return attParts;
}
Also used : MIMEContent(javax.wsdl.extensions.mime.MIMEContent) QName(javax.xml.namespace.QName) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 15 with SoapBody

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapBody in project cxf by apache.

the class SoapBindingFactory method initializeMessage.

private void initializeMessage(SoapBindingInfo bi, BindingOperationInfo boi, BindingMessageInfo bmsg) {
    MessageInfo msg = bmsg.getMessageInfo();
    List<MessagePartInfo> messageParts = new ArrayList<>();
    messageParts.addAll(msg.getMessageParts());
    List<SoapHeader> headers = SOAPBindingUtil.getSoapHeaders(bmsg.getExtensors(ExtensibilityElement.class));
    if (headers != null) {
        for (SoapHeader header : headers) {
            SoapHeaderInfo headerInfo = new SoapHeaderInfo();
            headerInfo.setUse(header.getUse());
            if (StringUtils.isEmpty(header.getPart())) {
                throw new RuntimeException("Problem with WSDL: soap:header element in operation " + boi.getName().getLocalPart() + " does not specify a part.");
            }
            MessagePartInfo part = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), header.getPart()));
            if (part != null && header.getMessage() != null && !part.getMessageInfo().getName().equals(header.getMessage())) {
                part = null;
                // out of band, let's find it
                for (MessagePartInfo mpi : msg.getOutOfBandParts()) {
                    if (mpi.getName().getLocalPart().equals(header.getPart()) && mpi.getMessageInfo().getName().equals(header.getMessage())) {
                        part = mpi;
                    }
                }
            }
            if (part != null) {
                headerInfo.setPart(part);
                messageParts.remove(part);
                bmsg.addExtensor(headerInfo);
            }
        }
        // Exclude the header parts from the message part list.
        bmsg.setMessageParts(messageParts);
    }
    SoapBodyInfo bodyInfo = new SoapBodyInfo();
    SoapBody soapBody = SOAPBindingUtil.getSoapBody(bmsg.getExtensors(ExtensibilityElement.class));
    List<?> parts = null;
    if (soapBody == null) {
        MIMEMultipartRelated mmr = bmsg.getExtensor(MIMEMultipartRelated.class);
        if (mmr != null) {
            parts = mmr.getMIMEParts();
        }
    } else {
        bmsg.addExtensor(soapBody);
        bodyInfo.setUse(soapBody.getUse());
        parts = soapBody.getParts();
    }
    // Initialize the body parts.
    List<MessagePartInfo> attParts = null;
    if (parts != null) {
        List<MessagePartInfo> bodyParts = new ArrayList<>();
        for (Iterator<?> itr = parts.iterator(); itr.hasNext(); ) {
            Object part = itr.next();
            if (part instanceof MIMEPart) {
                MIMEPart mpart = (MIMEPart) part;
                attParts = handleMimePart(mpart, attParts, msg, bmsg, bodyParts, messageParts);
            } else {
                addSoapBodyPart(msg, bodyParts, (String) part);
            }
        }
        bodyInfo.setParts(bodyParts);
        bodyInfo.setAttachments(attParts);
    } else {
        bodyInfo.setParts(messageParts);
    }
    bmsg.addExtensor(bodyInfo);
}
Also used : SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) QName(javax.xml.namespace.QName) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) ArrayList(java.util.ArrayList) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) MIMEMultipartRelated(javax.wsdl.extensions.mime.MIMEMultipartRelated) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) MIMEPart(javax.wsdl.extensions.mime.MIMEPart)

Aggregations

SoapBody (org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)15 SoapHeader (org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)8 QName (javax.xml.namespace.QName)7 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)5 SoapOperation (org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation)5 ToolException (org.apache.cxf.tools.common.ToolException)5 File (java.io.File)4 Binding (javax.wsdl.Binding)4 BindingInput (javax.wsdl.BindingInput)4 BindingOperation (javax.wsdl.BindingOperation)4 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)4 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)4 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)4 Test (org.junit.Test)4 MIMEPart (javax.wsdl.extensions.mime.MIMEPart)3 SoapHeaderInfo (org.apache.cxf.binding.soap.model.SoapHeaderInfo)3 SoapFault (org.apache.cxf.binding.soap.wsdl.extensions.SoapFault)3 Part (javax.wsdl.Part)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 MIMEMultipartRelated (javax.wsdl.extensions.mime.MIMEMultipartRelated)2