Search in sources :

Example 1 with BPELFault

use of org.wso2.carbon.bpel.core.ode.integration.BPELFault in project carbon-business-process by wso2.

the class SOAPUtils method handleSoapHeaderPartDef.

private static void handleSoapHeaderPartDef(org.apache.ode.bpel.iapi.Message odeMessage, Definition wsdl, SOAPHeader header, javax.wsdl.extensions.soap.SOAPHeader headerdef, Message msgType) throws BPELFault {
    // Is this header part of the "payload" messsage?
    boolean payloadMessageHeader = headerdef.getMessage() == null || headerdef.getMessage().equals(msgType.getQName());
    boolean requiredHeader = payloadMessageHeader || (headerdef.getRequired() != null && headerdef.getRequired());
    if (requiredHeader && header == null) {
        throw new BPELFault("SOAP Header missing required element.");
    }
    if (header == null) {
        return;
    }
    Message hdrMsg = wsdl.getMessage(headerdef.getMessage());
    if (hdrMsg == null) {
        return;
    }
    Part p = hdrMsg.getPart(headerdef.getPart());
    if (p == null || p.getElementName() == null) {
        return;
    }
    OMElement headerEl = header.getFirstChildWithName(p.getElementName());
    if (requiredHeader && headerEl == null) {
        throw new BPELFault("SOAP Header missing required element: " + p.getElementName());
    }
    if (headerEl == null) {
        return;
    }
    odeMessage.setHeaderPart(p.getName(), OMUtils.toDOM(headerEl));
}
Also used : BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) Message(javax.wsdl.Message) Part(javax.wsdl.Part) OMElement(org.apache.axiom.om.OMElement)

Example 2 with BPELFault

use of org.wso2.carbon.bpel.core.ode.integration.BPELFault in project carbon-business-process by wso2.

the class SOAPUtils method extractSOAPBodyParts.

private static void extractSOAPBodyParts(MessageExchange partnerRoleMessageExchange, org.apache.ode.bpel.iapi.Message messageToODE, SOAPBody omSOAPBody, List parts, String namespace, boolean isRPC) throws BPELFault {
    List<Part> messageBodyParts = partnerRoleMessageExchange.getOperation().getOutput().getMessage().getOrderedParts(parts);
    if (isRPC) {
        String rpcWrapperElementName = partnerRoleMessageExchange.getOperationName() + "Response";
        OMElement rpcWrapperElement = omSOAPBody.getFirstChildWithName(new QName(namespace, rpcWrapperElementName));
        if (rpcWrapperElement == null) {
            throw new BPELFault("Message body doesn't contain expected part wrapper: " + new QName(namespace, rpcWrapperElementName));
        }
        // children, since doc-lit rpc looks the same in ode and soap.
        for (Part partDef : messageBodyParts) {
            OMElement omPartElement = rpcWrapperElement.getFirstChildWithName(new QName(null, partDef.getName()));
            if (omPartElement == null) {
                throw new BPELFault("SOAP body doesn't contain required part: " + new QName(null, partDef.getName()));
            }
            messageToODE.setPart(omPartElement.getLocalName(), OMUtils.toDOM(omPartElement));
        }
    } else {
        // In doc-literal style, we expect the elements in the body to correspond (in order)
        // to the parts defined in the binding. All the parts should be element-typed,
        // otherwise it is a mess.
        Iterator<OMElement> omParts = omSOAPBody.getChildElements();
        for (Part partDef : messageBodyParts) {
            if (!omParts.hasNext()) {
                throw new BPELFault("SOAP body doesn't contain required part.");
            }
            OMElement omPart = omParts.next();
            if (partDef.getElementName() == null) {
                throw new BPELFault("Binding defines non element document list parts.");
            }
            if (!omPart.getQName().equals(partDef.getElementName())) {
                throw new BPELFault("Unexpected element in SOAP body: " + omPart.getQName());
            }
            Document doc = DOMUtils.newDocument();
            Element domPart = doc.createElementNS(null, partDef.getName());
            domPart.appendChild(doc.importNode(OMUtils.toDOM(omPart), true));
            messageToODE.setPart(partDef.getName(), domPart);
        }
    }
}
Also used : BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) Part(javax.wsdl.Part) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) Document(org.w3c.dom.Document)

Example 3 with BPELFault

use of org.wso2.carbon.bpel.core.ode.integration.BPELFault in project carbon-business-process by wso2.

the class SOAPUtils method handleSOAPHeaderElementsInBindingOperation.

@SuppressWarnings("unchecked")
private static void handleSOAPHeaderElementsInBindingOperation(SOAPEnvelope soapEnvelope, SOAPFactory soapFactory, org.apache.ode.bpel.iapi.Message messageFromOde, Operation wsdlOperation, final javax.wsdl.extensions.soap.SOAPHeader soapHeaderElementDefinition) throws BPELFault {
    Map<String, Node> headerParts = messageFromOde.getHeaderParts();
    Message responseMessageDefinition = wsdlOperation.getOutput() != null ? wsdlOperation.getOutput().getMessage() : null;
    // If there isn't a message attribute in header element definition or if the
    // message attribute value is equal to the response message QName, then this
    // header element is part of the actual payload.
    // Refer SOAP Binding specification at http://www.w3.org/TR/wsdl#_soap-b.
    final boolean isHeaderElementAPartOfPayload = soapHeaderElementDefinition.getMessage() == null || ((wsdlOperation.getStyle() != OperationType.ONE_WAY) && soapHeaderElementDefinition.getMessage().equals(responseMessageDefinition.getQName()));
    if (soapHeaderElementDefinition.getPart() == null) {
        // Part information not found. Ignoring this header definition.
        return;
    }
    if (isHeaderElementAPartOfPayload && (responseMessageDefinition != null && responseMessageDefinition.getPart(soapHeaderElementDefinition.getPart()) == null)) {
        // we should throw a exception.
        throw new BPELFault("SOAP Header Element Definition refer unknown part.");
    }
    Element partElement = null;
    if (headerParts.size() > 0 && isHeaderElementAPartOfPayload) {
        try {
            partElement = (Element) headerParts.get(soapHeaderElementDefinition.getPart());
        } catch (ClassCastException e) {
            throw new BPELFault("SOAP Header must be a DOM Element.", e);
        }
    }
    // message payload. This is because, some headers will provided by SOAP engine.
    if (partElement == null && isHeaderElementAPartOfPayload) {
        if (messageFromOde.getPart(soapHeaderElementDefinition.getPart()) != null) {
            partElement = messageFromOde.getPart(soapHeaderElementDefinition.getPart());
        } else {
            throw new BPELFault("Missing Required part in response message.");
        }
    }
    // and can be found and extracted from the odeMessage object
    if (partElement == null && messageFromOde.getParts().size() > 0 && !isHeaderElementAPartOfPayload) {
        try {
            partElement = (Element) messageFromOde.getPart(soapHeaderElementDefinition.getPart());
        } catch (ClassCastException e) {
            throw new BPELFault("Soap header must be an element" + messageFromOde.getPart(soapHeaderElementDefinition.getPart()));
        }
    }
    // just ignore this case.
    if (partElement == null) {
        return;
    }
    org.apache.axiom.soap.SOAPHeader soapHeader = soapEnvelope.getHeader();
    if (soapHeader == null) {
        soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
    }
    OMElement omPart = OMUtils.toOM(partElement, soapFactory);
    for (Iterator<OMNode> i = omPart.getChildren(); i.hasNext(); ) {
        soapHeader.addChild(i.next());
    }
}
Also used : Message(javax.wsdl.Message) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) OMNode(org.apache.axiom.om.OMNode) Node(org.w3c.dom.Node) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) SOAPHeader(org.apache.axiom.soap.SOAPHeader) OMNode(org.apache.axiom.om.OMNode)

Example 4 with BPELFault

use of org.wso2.carbon.bpel.core.ode.integration.BPELFault in project carbon-business-process by wso2.

the class SOAPUtils method populateSOAPBody.

@SuppressWarnings("unchecked")
private static void populateSOAPBody(SOAPEnvelope soapEnvelope, ElementExtensible bindingInput, boolean soap12, SOAPFactory soapFactory, Operation operation, Message messageDefinition, org.apache.ode.bpel.iapi.Message messageFromODE, boolean isRPC, boolean isRequest) throws BPELFault {
    if (soap12) {
        SOAP12Body soapBodyDefinition = getSOAP12Body(bindingInput);
        if (soapBodyDefinition != null) {
            SOAPBody soapBody;
            if (soapEnvelope.getBody() != null) {
                soapBody = soapEnvelope.getBody();
            } else {
                soapBody = soapFactory.createSOAPBody(soapEnvelope);
            }
            OMElement partHolder;
            if (isRPC) {
                String rpcWrapperElementName;
                if (isRequest) {
                    rpcWrapperElementName = operation.getName();
                } else {
                    rpcWrapperElementName = operation.getName() + "Response";
                }
                partHolder = createRPCWrapperElement(soapBody, soapFactory, new QName(soapBodyDefinition.getNamespaceURI(), rpcWrapperElementName));
            } else {
                partHolder = soapBody;
            }
            List<Part> parts = messageDefinition.getOrderedParts(soapBodyDefinition.getParts());
            for (Part p : parts) {
                Element partContent = DOMUtils.findChildByName(messageFromODE.getMessage(), new QName(null, p.getName()));
                if (partContent == null) {
                    throw new BPELFault("Missing required part in ODE Message: " + new QName(null, p.getName()));
                }
                OMElement omPartContent = OMUtils.toOM(partContent, soapFactory);
                if (isRPC) {
                    partHolder.addChild(omPartContent);
                } else {
                    for (Iterator<OMNode> i = omPartContent.getChildren(); i.hasNext(); ) {
                        partHolder.addChild(i.next());
                    }
                }
            }
        }
    } else {
        javax.wsdl.extensions.soap.SOAPBody soapBodyDefinition = getSOAP11Body(bindingInput);
        if (soapBodyDefinition != null) {
            SOAPBody soapBody;
            if (soapEnvelope.getBody() != null) {
                soapBody = soapEnvelope.getBody();
            } else {
                soapBody = soapFactory.createSOAPBody(soapEnvelope);
            }
            OMElement partHolder;
            if (isRPC) {
                String rpcWrapperElementName;
                if (isRequest) {
                    rpcWrapperElementName = operation.getName();
                } else {
                    rpcWrapperElementName = operation.getName() + "Response";
                }
                partHolder = createRPCWrapperElement(soapBody, soapFactory, new QName(soapBodyDefinition.getNamespaceURI(), rpcWrapperElementName));
            } else {
                partHolder = soapBody;
            }
            List<Part> parts = messageDefinition.getOrderedParts(soapBodyDefinition.getParts());
            for (Part p : parts) {
                Element partContent = DOMUtils.findChildByName(messageFromODE.getMessage(), new QName(null, p.getName()));
                if (partContent == null) {
                    throw new BPELFault("Missing required part in ODE Message: " + new QName(null, p.getName()));
                }
                OMElement omPartContent = OMUtils.toOM(partContent, soapFactory);
                if (isRPC) {
                    partHolder.addChild(omPartContent);
                } else {
                    for (Iterator<OMNode> i = omPartContent.getChildren(); i.hasNext(); ) {
                        partHolder.addChild(i.next());
                    }
                }
            }
        }
    }
}
Also used : SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) OMNode(org.apache.axiom.om.OMNode) SOAPBody(org.apache.axiom.soap.SOAPBody) Part(javax.wsdl.Part)

Example 5 with BPELFault

use of org.wso2.carbon.bpel.core.ode.integration.BPELFault in project carbon-business-process by wso2.

the class SOAPUtils method parseSOAPResponseFromPartner.

public static org.apache.ode.bpel.iapi.Message parseSOAPResponseFromPartner(BPELMessageContext partnerInvocationContext, MessageExchange partnerRoleMessageExchange) throws BPELFault {
    org.apache.ode.bpel.iapi.Message messageToODE = partnerRoleMessageExchange.createMessage(partnerRoleMessageExchange.getOperation().getOutput().getMessage().getQName());
    BindingOperation bindingOp = getBindingOperation(partnerInvocationContext, partnerRoleMessageExchange.getOperationName());
    BindingOutput bindingOutPut = getBindingOutPut(bindingOp);
    SOAPEnvelope responseFromPartnerService = partnerInvocationContext.getOutMessageContext().getEnvelope();
    if (partnerInvocationContext.isSoap12()) {
        javax.wsdl.extensions.soap12.SOAP12Body soapBodyDefinition = getSOAP12Body(bindingOutPut);
        if (soapBodyDefinition != null) {
            if (responseFromPartnerService.getBody() != null) {
                extractSOAPBodyParts(partnerRoleMessageExchange, messageToODE, responseFromPartnerService.getBody(), soapBodyDefinition.getParts(), soapBodyDefinition.getNamespaceURI(), partnerInvocationContext.isRPCStyleOperation());
            } else {
                throw new BPELFault("SOAP Body cannot be null for WSDL operation which " + "requires SOAP Body.");
            }
        }
    } else {
        javax.wsdl.extensions.soap.SOAPBody soapBodyDefinition = getSOAP11Body(bindingOutPut);
        if (soapBodyDefinition != null) {
            if (responseFromPartnerService.getBody() != null) {
                extractSOAPBodyParts(partnerRoleMessageExchange, messageToODE, responseFromPartnerService.getBody(), soapBodyDefinition.getParts(), soapBodyDefinition.getNamespaceURI(), partnerInvocationContext.isRPCStyleOperation());
            } else {
                throw new BPELFault("SOAP Body cannot be null for WSDL operation which " + "requires SOAP Body.");
            }
        }
    }
    if (getSOAPHeaders(bindingOutPut) != null && responseFromPartnerService.getHeader() != null) {
        extractSoapHeaderParts(messageToODE, partnerInvocationContext.getBpelServiceWSDLDefinition(), responseFromPartnerService.getHeader(), getSOAPHeaders(bindingOutPut), partnerRoleMessageExchange.getOperation().getOutput().getMessage());
    }
    return messageToODE;
}
Also used : BindingOutput(javax.wsdl.BindingOutput) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) OMNode(org.apache.axiom.om.OMNode) Node(org.w3c.dom.Node) BindingOperation(javax.wsdl.BindingOperation) SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body)

Aggregations

BPELFault (org.wso2.carbon.bpel.core.ode.integration.BPELFault)5 OMElement (org.apache.axiom.om.OMElement)4 Part (javax.wsdl.Part)3 OMNode (org.apache.axiom.om.OMNode)3 Element (org.w3c.dom.Element)3 Message (javax.wsdl.Message)2 SOAP12Body (javax.wsdl.extensions.soap12.SOAP12Body)2 QName (javax.xml.namespace.QName)2 Node (org.w3c.dom.Node)2 BindingOperation (javax.wsdl.BindingOperation)1 BindingOutput (javax.wsdl.BindingOutput)1 SOAPBody (org.apache.axiom.soap.SOAPBody)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)1 SOAPHeader (org.apache.axiom.soap.SOAPHeader)1 Document (org.w3c.dom.Document)1