Search in sources :

Example 1 with MIMEPart

use of javax.wsdl.extensions.mime.MIMEPart in project cxf by apache.

the class MIMEBindingValidator method doValidate.

private boolean doValidate(MIMEMultipartRelated mimeExt, String operationName) {
    boolean gotRootPart = false;
    List<MIMEPart> parts = CastUtils.cast(mimeExt.getMIMEParts());
    for (MIMEPart mPart : parts) {
        List<MIMEContent> mimeContents = new ArrayList<>();
        List<ExtensibilityElement> extns = CastUtils.cast(mPart.getExtensibilityElements());
        for (ExtensibilityElement extElement : extns) {
            if (SOAPBindingUtil.isSOAPBody(extElement)) {
                if (gotRootPart) {
                    addErrorMessage("Operation(" + operationName + "): There's more than one soap body mime part" + " in its binding input");
                    return false;
                }
                gotRootPart = true;
            } else if (extElement instanceof MIMEContent) {
                mimeContents.add((MIMEContent) extElement);
            }
        }
        if (!doValidateMimeContentPartNames(mimeContents, operationName)) {
            return false;
        }
    }
    if (!gotRootPart) {
        addErrorMessage("Operation(" + operationName + "): There's no soap body in mime part" + " in its binding input");
        return false;
    }
    return true;
}
Also used : MIMEContent(javax.wsdl.extensions.mime.MIMEContent) ArrayList(java.util.ArrayList) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) MIMEPart(javax.wsdl.extensions.mime.MIMEPart)

Example 2 with MIMEPart

use of javax.wsdl.extensions.mime.MIMEPart in project cxf by apache.

the class WSIBPValidator method getIgnorableParts.

private static Set<String> getIgnorableParts(WSDLElement ext) {
    Set<String> parts = null;
    if (ext != null && ext.getExtensibilityElements() != null && ext.getExtensibilityElements().size() > 0 && ext.getExtensibilityElements().get(0) instanceof MIMEMultipartRelated) {
        MIMEMultipartRelated mpr = (MIMEMultipartRelated) ext.getExtensibilityElements().get(0);
        List<MIMEPart> mps = CastUtils.cast(mpr.getMIMEParts());
        parts = new HashSet<>(mps.size());
        for (Iterator<MIMEPart> it = mps.iterator(); it.hasNext(); ) {
            MIMEPart mp = it.next();
            if (mp.getExtensibilityElements() != null && mp.getExtensibilityElements().size() > 0 && mp.getExtensibilityElements().get(0) instanceof MIMEContent) {
                parts.add(((MIMEContent) mp.getExtensibilityElements().get(0)).getPart());
            }
        }
    }
    return parts;
}
Also used : MIMEContent(javax.wsdl.extensions.mime.MIMEContent) MIMEMultipartRelated(javax.wsdl.extensions.mime.MIMEMultipartRelated) MIMEPart(javax.wsdl.extensions.mime.MIMEPart)

Example 3 with MIMEPart

use of javax.wsdl.extensions.mime.MIMEPart in project cxf by apache.

the class ServiceProcessor method processMultipart.

public void processMultipart(JavaMethod jm, BindingOperationInfo operation, MIMEMultipartRelated ext, JavaType.Style style) throws ToolException {
    List<MIMEPart> mimeParts = CastUtils.cast(ext.getMIMEParts());
    for (MIMEPart mPart : mimeParts) {
        List<ExtensibilityElement> extns = CastUtils.cast(mPart.getExtensibilityElements());
        for (ExtensibilityElement extElement : extns) {
            if (extElement instanceof MIMEContent) {
                MIMEContent mimeContent = (MIMEContent) extElement;
                String mimeJavaType = getJavaTypeForMimeType(mPart);
                if (JavaType.Style.IN.equals(style)) {
                    String paramName = ProcessorUtil.mangleNameToVariableName(mimeContent.getPart());
                    JavaParameter jp = jm.getParameter(paramName);
                    if (jp == null) {
                        Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
                        throw new ToolException(message);
                    }
                    if (!jp.getClassName().equals(mimeJavaType)) {
                        // jp.setType(mimeJavaType);
                        jp.setClassName(mimeJavaType);
                    }
                } else if (JavaType.Style.OUT.equals(style)) {
                    JavaType jp = null;
                    if (!"void".equals(jm.getReturn().getType()) && mimeContent.getPart().equals(jm.getReturn().getName())) {
                        jp = jm.getReturn();
                        jp.setClassName(mimeJavaType);
                    }
                    if (jp == null) {
                        for (JavaParameter para : jm.getParameters()) {
                            if (mimeContent.getPart().equals(para.getPartName())) {
                                jp = para;
                            }
                        }
                        if (jp != null) {
                            ((JavaParameter) jp).setClassName(mimeJavaType);
                        }
                    }
                    if (jp == null) {
                        Message message = new Message("MIMEPART_CANNOT_MAP", LOG, mimeContent.getPart());
                        throw new ToolException(message);
                    }
                }
            } else if (extElement instanceof SOAPHeader) {
                processSoapHeader(jm, operation, extElement);
            }
        }
    }
}
Also used : JavaType(org.apache.cxf.tools.common.model.JavaType) MIMEContent(javax.wsdl.extensions.mime.MIMEContent) Message(org.apache.cxf.common.i18n.Message) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) ToolException(org.apache.cxf.tools.common.ToolException) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) SOAPHeader(javax.wsdl.extensions.soap.SOAPHeader) MIMEPart(javax.wsdl.extensions.mime.MIMEPart)

Example 4 with MIMEPart

use of javax.wsdl.extensions.mime.MIMEPart 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

MIMEPart (javax.wsdl.extensions.mime.MIMEPart)4 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)3 MIMEContent (javax.wsdl.extensions.mime.MIMEContent)3 ArrayList (java.util.ArrayList)2 MIMEMultipartRelated (javax.wsdl.extensions.mime.MIMEMultipartRelated)2 SOAPHeader (javax.wsdl.extensions.soap.SOAPHeader)1 QName (javax.xml.namespace.QName)1 SoapBodyInfo (org.apache.cxf.binding.soap.model.SoapBodyInfo)1 SoapHeaderInfo (org.apache.cxf.binding.soap.model.SoapHeaderInfo)1 SoapBody (org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)1 SoapHeader (org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)1 Message (org.apache.cxf.common.i18n.Message)1 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)1 MessageInfo (org.apache.cxf.service.model.MessageInfo)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 ToolException (org.apache.cxf.tools.common.ToolException)1 JavaParameter (org.apache.cxf.tools.common.model.JavaParameter)1 JavaType (org.apache.cxf.tools.common.model.JavaType)1