⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soapmessageconverter.java

📁 bpel执行引擎用来执行bpel业务流程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            return toFaultDetail(faultName, message);        // For faults, there will be exactly one part.        Part p = (Part)f.getMessage().getParts().values().iterator().next();        if (p == null)            return toFaultDetail(faultName, message);        Element partEl= DOMUtils.findChildByName(message,new QName(null,p.getName()));        if (partEl == null)            return toFaultDetail(faultName, message);        Element detail = DOMUtils.findChildByName(partEl, p.getElementName());        if (detail == null)            return toFaultDetail(faultName, message);        return OMUtils.toOM(detail, _soapFactory);   }    private OMElement toFaultDetail(QName fault, Element message) {        if (message == null) return null;        Element firstPart = DOMUtils.getFirstChildElement(message);        if (firstPart == null) return null;        Element detail = DOMUtils.getFirstChildElement(firstPart);        if (detail == null) return OMUtils.toOM(firstPart, _soapFactory);        return OMUtils.toOM(detail, _soapFactory);    }    public void parseSoapRequest(org.apache.ode.bpel.iapi.Message odeMessage, SOAPEnvelope envelope, Operation op) throws AxisFault {        BindingOperation bop = _binding.getBindingOperation(op.getName(), null, null);        if (bop == null)            throw new OdeFault(__msgs.msgBindingOperationNotFound(_serviceName, _portName, op.getName()));        BindingInput bi = bop.getBindingInput();        if (bi == null)            throw new OdeFault(__msgs.msgBindingInputNotFound(_serviceName, _portName, op.getName()));        SOAPBody soapBody = getSOAPBody(bi);        if (soapBody != null)            extractSoapBodyParts(odeMessage, envelope.getBody(), soapBody, op.getInput().getMessage(), op.getName());        if (envelope.getHeader() != null)            extractSoapHeaderParts(odeMessage, envelope.getHeader(), getSOAPHeaders(bi), op.getInput().getMessage());    }    public void parseSoapResponse(org.apache.ode.bpel.iapi.Message odeMessage,                                  SOAPEnvelope envelope, Operation op) throws AxisFault {        BindingOperation bop = _binding.getBindingOperation(op.getName(), null, null);        if (bop == null)            throw new OdeFault(__msgs.msgBindingOperationNotFound(_serviceName, _portName, op.getName()));        BindingOutput bo = bop.getBindingOutput();        if (bo == null)            throw new OdeFault(__msgs.msgBindingInputNotFound(_serviceName, _portName, op.getName()));        SOAPBody soapBody = getSOAPBody(bo);        if (soapBody != null)            extractSoapBodyParts(odeMessage, envelope.getBody(), soapBody, op.getOutput().getMessage(), op.getName() + "Response");        if (envelope.getHeader() != null)            extractSoapHeaderParts(odeMessage, envelope.getHeader(), getSOAPHeaders(bo), op.getOutput().getMessage());    }    @SuppressWarnings("unchecked")    public void createSoapBody(org.apache.axiom.soap.SOAPBody sb, SOAPBody soapBody, Message msgDef,                               Element message, String rpcWrapper) throws AxisFault {        OMElement partHolder = _isRPC ? _soapFactory                .createOMElement(new QName(soapBody.getNamespaceURI(), rpcWrapper, "odens"), sb) : sb;        List<Part> parts = msgDef.getOrderedParts(soapBody.getParts());        for (Part part : parts) {            Element srcPartEl = DOMUtils.findChildByName(message, new QName(null, part.getName()));            if (srcPartEl == null)                throw new OdeFault(__msgs.msgOdeMessageMissingRequiredPart(part.getName()));            OMElement omPart = OMUtils.toOM(srcPartEl, _soapFactory);            if (_isRPC) partHolder.addChild(omPart);            else for (Iterator<OMNode> i = omPart.getChildren(); i.hasNext();) partHolder.addChild(i.next());        }    }    // public Element createODEMessage(SOAPEnvelope soapEnv,Operation op) throws AxisFault {    // }    @SuppressWarnings("unchecked")    public void extractSoapBodyParts(org.apache.ode.bpel.iapi.Message message, org.apache.axiom.soap.SOAPBody soapBody,                                     SOAPBody bodyDef, Message msg,String rpcWrapper) throws AxisFault {        List<Part> bodyParts = msg.getOrderedParts(bodyDef.getParts());        if (_isRPC) {            QName rpcWrapQName = new QName(bodyDef.getNamespaceURI(), rpcWrapper);            OMElement partWrapper = soapBody.getFirstChildWithName(rpcWrapQName);            if (partWrapper == null)                throw new OdeFault(__msgs.msgSoapBodyDoesNotContainExpectedPartWrapper(_serviceName,_portName,rpcWrapQName));            // In RPC the body element is the operation name, wrapping parts. Order doesn't really matter as far as            // we're concerned. All we need to do is copy the soap:body children, since doc-lit rpc looks the same            // in ode and soap.            for (Part pdef : bodyParts) {                OMElement srcPart = partWrapper.getFirstChildWithName(new QName(null, pdef.getName()));                if (srcPart == null)                    throw new OdeFault(__msgs.msgSOAPBodyDoesNotContainRequiredPart(pdef.getName()));                message.setPart(srcPart.getLocalName(), OMUtils.toDOM(srcPart));            }        } 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> srcParts = soapBody.getChildElements();            for (Part partDef : bodyParts) {                if (!srcParts.hasNext())                    throw new OdeFault(__msgs.msgSOAPBodyDoesNotContainRequiredPart(partDef.getName()));                OMElement srcPart = srcParts.next();                if (partDef.getElementName() == null)                    throw new OdeFault(__msgs.msgBindingDefinesNonElementDocListParts());                if (!srcPart.getQName().equals(partDef.getElementName()))                    throw new OdeFault(__msgs.msgUnexpectedElementInSOAPBody(srcPart.getQName(), partDef.getElementName()));                Document doc = DOMUtils.newDocument();                Element destPart = doc.createElementNS(null, partDef.getName());                destPart.appendChild(doc.importNode(OMUtils.toDOM(srcPart), true));                message.setPart(partDef.getName(), destPart);            }        }    }    public void extractSoapHeaderParts(org.apache.ode.bpel.iapi.Message message,                                       org.apache.axiom.soap.SOAPHeader soapHeader,                                       List<SOAPHeader> headerDefs, Message msg) throws AxisFault {        // Checking that the definitions we have are at least there        for (SOAPHeader headerDef : headerDefs)            handleSoapHeaderPartDef(message, soapHeader, headerDef, msg);        // Extracting whatever header elements we find in the message, binding and abstract parts        // aren't reliable enough given what people do out there.        Iterator headersIter = soapHeader.getChildElements();        while (headersIter.hasNext()) {            OMElement header = (OMElement) headersIter.next();            String partName = findHeaderPartName(headerDefs, header.getQName());            message.setHeaderPart(partName, OMUtils.toDOM(header));        }    }    private void handleSoapHeaderPartDef(org.apache.ode.bpel.iapi.Message odeMessage, org.apache.axiom.soap.SOAPHeader header, SOAPHeader headerdef,            Message msgType) throws AxisFault {        // 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 OdeFault(__msgs.msgSoapHeaderMissingRequiredElement(headerdef.getElementType()));        if (header == null)            return;        Message hdrMsg = _def.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 OdeFault(__msgs.msgSoapHeaderMissingRequiredElement(headerdef.getElementType()));        if (headerEl == null) return;        odeMessage.setHeaderPart(p.getName(), OMUtils.toDOM(headerEl));    }    private String findHeaderPartName(List<SOAPHeader> headerDefs, QName elmtName) {        for (SOAPHeader headerDef : headerDefs) {            Message hdrMsg = _def.getMessage(headerDef.getMessage());            for (Object o : hdrMsg.getParts().values()) {                Part p = (Part) o;                if (p.getElementName().equals(elmtName)) return p.getName();            }        }        return elmtName.getLocalPart();    }    public static SOAPBody getSOAPBody(ElementExtensible ee) {        return getFirstExtensibilityElement(ee, SOAPBody.class);    }    @SuppressWarnings("unchecked")    public static List<SOAPHeader> getSOAPHeaders(ElementExtensible eee) {        return CollectionsX.filter(new ArrayList<SOAPHeader>(), (Collection<Object>) eee.getExtensibilityElements(),                SOAPHeader.class);    }    public static <T> T getFirstExtensibilityElement(ElementExtensible parent, Class<T> cls) {        Collection<T> ee = CollectionsX.filter(parent.getExtensibilityElements(), cls);        return ee.isEmpty() ? null : ee.iterator().next();    }        /**     * Attempts to extract the WS-Addressing "Action" attribute value from the operation definition.     * When WS-Addressing is being used by a service provider, the "Action" is specified in the      * portType->operation instead of the SOAP binding->operation.       *      * @param operation The name of the operation to extract the SOAP Action from     * @return the SOAPAction value if one is specified, otherwise empty string     */    public String getWSAInputAction(String operation) {      BindingOperation bop = _binding.getBindingOperation(operation, null, null);      if (bop == null) return "";      Input input = bop.getOperation().getInput();      if (input != null) {        Object actionQName = input.getExtensionAttribute(new QName(Namespaces.WS_ADDRESSING_NS, "Action"));        if (actionQName != null && actionQName instanceof QName)          return ((QName)actionQName).getLocalPart();      }      return "";    }    /**     * Attempts to extract the SOAP Action is defined in the WSDL document.     *     * @param operation The name of the operation to extract the SOAP Action from     * @return the SOAPAction value if one is specified, otherwise empty string     */    public String getSoapAction(String operation) {        BindingOperation bop = _binding.getBindingOperation(operation, null, null);        if (bop == null)            return "";        for (SOAPOperation soapOp : CollectionsX.filter(bop.getExtensibilityElements(), SOAPOperation.class))            return soapOp.getSoapActionURI();        return "";    }        public QName parseSoapFault(Element odeMsgEl, SOAPEnvelope envelope, Operation operation) throws AxisFault {        SOAPFault flt = envelope.getBody().getFault();        SOAPFaultDetail detail = flt.getDetail();        Fault fdef = inferFault(operation, flt);        if (fdef == null)            return null;        Part pdef = (Part)fdef.getMessage().getParts().values().iterator().next();        Element partel = odeMsgEl.getOwnerDocument().createElementNS(null,pdef.getName());        odeMsgEl.appendChild(partel);        if (detail.getFirstChildWithName(pdef.getElementName()) != null) {            partel.appendChild(odeMsgEl.getOwnerDocument().importNode(                    OMUtils.toDOM(detail.getFirstChildWithName(pdef.getElementName())), true));        } else {            partel.appendChild(odeMsgEl.getOwnerDocument().importNode(OMUtils.toDOM(detail),true));        }        return new QName(_def.getTargetNamespace(), fdef.getName());    }    @SuppressWarnings("unchecked")    private Fault inferFault(Operation operation, SOAPFault flt) {        if (flt.getDetail() == null || flt.getDetail().getFirstElement() == null)            return null;        // The detail is a dummy <detail> node containing the interesting fault element        QName elName = flt.getDetail().getFirstElement().getQName();        return WsdlUtils.inferFault(operation, elName);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -