addressingouthandler.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 546 行 · 第 1/2 页

JAVA
546
字号
                    }
                }
            }
        }

        private void processFaultsInfoIfPresent() {
            OMElement detailElement = AddressingFaultsHelper
                    .getDetailElementForAddressingFault(messageContext, addressingNamespaceObject);
            if (detailElement != null) {
                //The difference between SOAP 1.1 and SOAP 1.2 fault messages is explained in the WS-Addressing Specs.
                if (isFinalAddressingNamespace && messageContext.isSOAP11()) {
                    // Add detail as a wsa:FaultDetail header
                    if (!isAddressingHeaderAlreadyAvailable(Final.FAULT_HEADER_DETAIL, false)) {
                        SOAPHeaderBlock faultDetail = header.addHeaderBlock(
                                Final.FAULT_HEADER_DETAIL, addressingNamespaceObject);
                        faultDetail.addChild(ElementHelper.importOMElement(detailElement, factory));
                    }
                } else if (!messageContext.isSOAP11()) {
                    // Add detail to the Fault in the SOAP Body
                    SOAPFault fault = envelope.getBody().getFault();
                    if (fault != null && fault.getDetail() != null) {
                        fault.getDetail().addDetailEntry(
                                ElementHelper.importOMElement(detailElement, factory));
                    }
                }
            }
        }

        private void processRelatesTo() {
            if (!isAddressingHeaderAlreadyAvailable(WSA_RELATES_TO, true)) {
                RelatesTo[] relatesTo = messageContextOptions.getRelationships();

                if (relatesTo != null) {
                    for (int i = 0, length = relatesTo.length; i < length; i++) {
                        OMElement relatesToHeader = processStringInfo(relatesTo[i].getValue(),
                                                                      WSA_RELATES_TO);
                        String relationshipType = relatesTo[i].getRelationshipType();

                        if (relatesToHeader != null) {
                            if (relatesTo[i].getExtensibilityAttributes() != null) {
                                Iterator attributes =
                                        relatesTo[i].getExtensibilityAttributes().iterator();
                                while (attributes.hasNext()) {
                                    OMAttribute oma = (OMAttribute)attributes.next();
                                    AttributeHelper.importOMAttribute(oma, relatesToHeader);
                                }
                            }

                            if (Final.WSA_DEFAULT_RELATIONSHIP_TYPE.equals(relationshipType) ||
                                    Submission.WSA_DEFAULT_RELATIONSHIP_TYPE
                                            .equals(relationshipType)) {
                                if (includeOptionalHeaders) {
                                    relationshipType = isFinalAddressingNamespace ?
                                            Final.WSA_DEFAULT_RELATIONSHIP_TYPE :
                                            Submission.WSA_DEFAULT_RELATIONSHIP_TYPE;
                                    relatesTo[i].setRelationshipType(relationshipType);
                                } else {
                                    continue; //Omit the relationship type
                                }
                            }

                            relatesToHeader.addAttribute(WSA_RELATES_TO_RELATIONSHIP_TYPE,
                                                         relationshipType,
                                                         null);
                        }
                    }
                }
            }
        }

        private void processFaultToEPR() throws AxisFault {
            EndpointReference epr = messageContextOptions.getFaultTo();
            String headerName = AddressingConstants.WSA_FAULT_TO;

            //Omit the header if the epr is null.
            if (epr != null && !isAddressingHeaderAlreadyAvailable(headerName, false)) {
                addToSOAPHeader(epr, headerName);
            }
        }

        private void processFromEPR() throws AxisFault {
            EndpointReference epr = messageContextOptions.getFrom();
            String headerName = AddressingConstants.WSA_FROM;

            //Omit the header if the epr is null.
            if (epr != null && !isAddressingHeaderAlreadyAvailable(headerName, false)) {
                addToSOAPHeader(epr, headerName);
            }
        }

        private void processReplyTo() throws AxisFault {
            EndpointReference epr = messageContextOptions.getReplyTo();
            String headerName = AddressingConstants.WSA_REPLY_TO;

            //Don't check epr for null here as addToSOAPHeader() will provide an appropriate default.
            //This default is especially useful for client side outbound processing.
            if (!isAddressingHeaderAlreadyAvailable(headerName, false)) {
                addToSOAPHeader(epr, headerName);
            }
        }

        private void processToEPR() {
            EndpointReference epr = messageContextOptions.getTo();
            if (epr != null && !isAddressingHeaderAlreadyAvailable(WSA_TO, false)) {
                Map referenceParameters = epr.getAllReferenceParameters();
                String address = epr.getAddress();

                if (!"".equals(address) && address != null) {
                    if (!includeOptionalHeaders && isFinalAddressingNamespace &&
                            (Final.WSA_ANONYMOUS_URL.equals(address) ||
                                    //Don't use epr.hasAnonymousAddress() here as it may
                                    Submission.WSA_ANONYMOUS_URL.equals(address)))
                    { //recognize none WS-Addressing anonymous values.
                        return; //Omit the header.
                    }

                    SOAPHeaderBlock toHeaderBlock =
                            header.addHeaderBlock(WSA_TO, addressingNamespaceObject);
                    toHeaderBlock.setText(address);
                    if (epr.getAddressAttributes() != null) {
                        Iterator addressAttributes = epr.getAddressAttributes().iterator();
                        while (addressAttributes.hasNext()) {
                            OMAttribute attr = (OMAttribute)addressAttributes.next();
                            AttributeHelper.importOMAttribute(attr, toHeaderBlock);
                        }
                    }
                }
                processToEPRReferenceInformation(referenceParameters, header);
            }
        }

        private OMElement processStringInfo(String value, String headerName) {
            if (log.isTraceEnabled()) {
                log.trace("processStringInfo: value=" + value + " headerName=" + headerName);
            }
            if (!"".equals(value) && value != null) {
                SOAPHeaderBlock soapHeaderBlock =
                        header.addHeaderBlock(headerName, addressingNamespaceObject);
                soapHeaderBlock.addChild(factory.createOMText(value));
                return soapHeaderBlock;
            }
            return null;
        }

        private void addToSOAPHeader(EndpointReference epr, String headerName) throws AxisFault {
            String prefix = addressingNamespaceObject.getPrefix();
            String anonymous = isFinalAddressingNamespace ?
                    Final.WSA_ANONYMOUS_URL : Submission.WSA_ANONYMOUS_URL;

            if (log.isTraceEnabled()) {
                log.trace("addToSOAPHeader: epr=" + epr + " headerName=" + headerName);
            }

            if (epr == null) {
                if (!includeOptionalHeaders && isFinalAddressingNamespace &&
                        AddressingConstants.WSA_REPLY_TO.equals(headerName)) {
                    return; //Omit the header.
                } else {
                    epr = new EndpointReference(anonymous);
                }
            } else if (!isFinalAddressingNamespace && epr.hasNoneAddress()) {
                return; //Omit the header.
            } else if (Final.WSA_ANONYMOUS_URL.equals(epr.getAddress()) ||
                    //Don't use epr.hasAnonymousAddress() here as it may
                    Submission.WSA_ANONYMOUS_URL.equals(epr.getAddress()))
            { //recognize none WS-Addressing anonymous values.

                if (!includeOptionalHeaders && isFinalAddressingNamespace &&
                        AddressingConstants.WSA_REPLY_TO.equals(headerName)) {
                    return; //Omit the header.
                } else {
                    epr.setAddress(anonymous);
                }
            }

            OMElement soapHeaderBlock = EndpointReferenceHelper.toOM(factory,
                                                                     epr,
                                                                     new QName(addressingNamespace,
                                                                               headerName, prefix),
                                                                     addressingNamespace);
            header.addChild(soapHeaderBlock);
        }

        /**
         * This will add reference parameters and/or reference properties in to the message
         *
         * @param referenceInformation a Map from QName -> OMElement
         * @param parent               is the element to which the referenceparameters should be
         *                             attached
         */
        private void processToEPRReferenceInformation(Map referenceInformation, OMElement parent) {
            if (referenceInformation != null && parent != null) {
                Iterator iterator = referenceInformation.values().iterator();
                while (iterator.hasNext()) {
                    OMElement omElement = (OMElement)iterator.next();
                    parent.addChild(
                            ElementHelper.importOMElement(omElement, parent.getOMFactory()));
                    if (isFinalAddressingNamespace) {
                        omElement.addAttribute(Final.WSA_IS_REFERENCE_PARAMETER_ATTRIBUTE,
                                               Final.WSA_TYPE_ATTRIBUTE_VALUE,
                                               addressingNamespaceObject);
                    }
                }
            }
        }

        /**
         * This will check for the existence of message information headers already in the message.
         * If there are already headers, then replacing them or not depends on the replaceHeaders
         * property.
         *
         * @param name            - Name of the message information header
         * @param multipleHeaders - determines whether to search for multiple headers, or not.
         * @return false - if one can add new headers (always the case if multipleHeaders is true),
         *         true - if new headers can't be added.
         */
        private boolean isAddressingHeaderAlreadyAvailable(String name, boolean multipleHeaders) {
            QName qname = new QName(addressingNamespaceObject.getNamespaceURI(), name,
                                    addressingNamespaceObject.getPrefix());
            boolean status = false;

            if (multipleHeaders) {
                if (replaceHeaders) {
                    Iterator iterator = header.getChildrenWithName(qname);
                    while (iterator.hasNext()) {
                        OMElement addressingHeader = (OMElement)iterator.next();
                        addressingHeader.detach();
                    }
                }
            } else {
                OMElement addressingHeader = header.getFirstChildWithName(qname);

                if (addressingHeader != null && replaceHeaders) {
                    if (log.isTraceEnabled()) {
                        log.trace("isAddressingHeaderAlreadyAvailable: Removing existing header:" +
                                addressingHeader.getLocalName());
                    }
                    addressingHeader.detach();
                } else {
                    status = addressingHeader != null;
                }
            }

            if (log.isTraceEnabled()) {
                log.trace("isAddressingHeaderAlreadyAvailable: name=" + name + " status=" + status);
            }
            return status;
        }

        /**
         * Sets a mustUnderstand attribute on all headers that are found with the appropriate
         * addressing namespace.
         */
        private void processMustUnderstandProperty() {
            if (addMustUnderstandAttribute) {
                List headers = header.getHeaderBlocksWithNSURI(addressingNamespace);

                for (int i = 0, size = headers.size(); i < size; i++) {
                    SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock)headers.get(i);
                    soapHeaderBlock.setMustUnderstand(true);
                    if (log.isTraceEnabled()) {
                        log.trace(
                                "processMustUnderstandProperty: Setting mustUnderstand=true on: " +
                                        soapHeaderBlock.getLocalName());
                    }
                }
            }
        }
    }

}

⌨️ 快捷键说明

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