Search in sources :

Example 1 with MIMEContent

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

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

use of javax.wsdl.extensions.mime.MIMEContent 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 4 with MIMEContent

use of javax.wsdl.extensions.mime.MIMEContent 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 5 with MIMEContent

use of javax.wsdl.extensions.mime.MIMEContent in project carbon-business-process by wso2.

the class SOAPUtils method parseResponseFromRESTService.

public static org.apache.ode.bpel.iapi.Message parseResponseFromRESTService(BPELMessageContext partnerInvocationContext, PartnerRoleMessageExchange odePartnerMex) {
    org.apache.ode.bpel.iapi.Message messageToODE = odePartnerMex.createMessage(odePartnerMex.getOperation().getOutput().getMessage().getQName());
    BindingOperation bindingOp = getBindingOperation(partnerInvocationContext, odePartnerMex.getOperationName());
    BindingOutput bindingOutPut = getBindingOutPut(bindingOp);
    javax.wsdl.extensions.mime.MIMEContent mimeContent = getFirstExtensibilityElement(bindingOutPut, MIMEContent.class);
    if (mimeContent != null) {
        SOAPEnvelope soapEnv = partnerInvocationContext.getOutMessageContext().getEnvelope();
        Iterator childElementsItr = soapEnv.getBody().getChildElements();
        while (childElementsItr.hasNext()) {
            OMNode child = (OMNode) childElementsItr.next();
            if (child.getType() == OMNode.ELEMENT_NODE) {
                Document doc = DOMUtils.newDocument();
                Element domPart = doc.createElementNS(null, mimeContent.getPart());
                domPart.appendChild(doc.importNode(OMUtils.toDOM((OMElement) child), true));
                messageToODE.setPart(mimeContent.getPart(), domPart);
                return messageToODE;
            }
        }
    }
    throw new IllegalArgumentException("WSO2 BPS only support HTTP binding with mime output.");
}
Also used : BindingOutput(javax.wsdl.BindingOutput) MIMEContent(javax.wsdl.extensions.mime.MIMEContent) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) Document(org.w3c.dom.Document) SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) OMNode(org.apache.axiom.om.OMNode) Node(org.w3c.dom.Node) OMNode(org.apache.axiom.om.OMNode) BindingOperation(javax.wsdl.BindingOperation) Iterator(java.util.Iterator)

Aggregations

MIMEContent (javax.wsdl.extensions.mime.MIMEContent)5 MIMEPart (javax.wsdl.extensions.mime.MIMEPart)3 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 BindingOperation (javax.wsdl.BindingOperation)1 BindingOutput (javax.wsdl.BindingOutput)1 MIMEMultipartRelated (javax.wsdl.extensions.mime.MIMEMultipartRelated)1 SOAPHeader (javax.wsdl.extensions.soap.SOAPHeader)1 QName (javax.xml.namespace.QName)1 OMElement (org.apache.axiom.om.OMElement)1 OMNode (org.apache.axiom.om.OMNode)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)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 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 ToolException (org.apache.cxf.tools.common.ToolException)1