Search in sources :

Example 6 with SoapHeaderInfo

use of org.apache.cxf.binding.soap.model.SoapHeaderInfo 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<>();
            }
            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 7 with SoapHeaderInfo

use of org.apache.cxf.binding.soap.model.SoapHeaderInfo 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

SoapHeaderInfo (org.apache.cxf.binding.soap.model.SoapHeaderInfo)7 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)6 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)4 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)4 SoapBody (org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)3 SoapHeader (org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)3 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)2 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)2 Exchange (org.apache.cxf.message.Exchange)2 MessageContentsList (org.apache.cxf.message.MessageContentsList)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 ExtensionRegistry (javax.wsdl.extensions.ExtensionRegistry)1 MIMEContent (javax.wsdl.extensions.mime.MIMEContent)1 MIMEMultipartRelated (javax.wsdl.extensions.mime.MIMEMultipartRelated)1 MIMEPart (javax.wsdl.extensions.mime.MIMEPart)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 Schema (javax.xml.validation.Schema)1