FileDocCategorySizeDatePackage
EnvelopeBuilder.javaAPI DocApache Axis 1.47753Sat Apr 22 18:57:28 BST 2006org.apache.axis.message

EnvelopeBuilder

public class EnvelopeBuilder extends SOAPHandler
The EnvelopeBuilder is responsible for parsing the top-level SOAP envelope stuff (Envelope, Body, Header), and spawning off HeaderBuilder and BodyBuilders.
author
Glen Daniels (gdaniels@allaire.com)
author
Andras Avar (andras.avar@nokia.com)

Fields Summary
private SOAPEnvelope
envelope
private org.apache.axis.soap.SOAPConstants
soapConstants
private boolean
gotHeader
private boolean
gotBody
Constructors Summary
public EnvelopeBuilder(String messageType, org.apache.axis.soap.SOAPConstants soapConstants)


        
    
        envelope = new SOAPEnvelope(false, soapConstants);
        envelope.setMessageType(messageType);
        myElement = envelope;
    
public EnvelopeBuilder(SOAPEnvelope env, String messageType)

        envelope = env ;
        envelope.setMessageType(messageType);
        myElement = envelope;
    
Methods Summary
public voidendElement(java.lang.String namespace, java.lang.String localName, org.apache.axis.encoding.DeserializationContext context)

        // Envelope isn't dirty yet by default...
        envelope.setDirty(false);
        envelope.setRecorded(true);
        envelope.reset();
    
public SOAPEnvelopegetEnvelope()

        return envelope;
    
public voidonEndChild(java.lang.String namespace, java.lang.String localName, org.apache.axis.encoding.DeserializationContext context)

    
public SOAPHandleronStartChild(java.lang.String namespace, java.lang.String localName, java.lang.String prefix, org.xml.sax.Attributes attributes, org.apache.axis.encoding.DeserializationContext context)

        QName thisQName = new QName(namespace, localName);
        if (thisQName.equals(soapConstants.getHeaderQName())) {
            if (gotHeader)
                throw new SAXException(Messages.getMessage("only1Header00"));

            gotHeader = true;
            return new HeaderBuilder(envelope);
        }

        if (thisQName.equals(soapConstants.getBodyQName())) {
            if (gotBody)
                throw new SAXException(Messages.getMessage("only1Body00"));

            gotBody = true;
            return new BodyBuilder(envelope);
        }

        if (!gotBody)
            throw new SAXException(Messages.getMessage("noCustomElems00"));

        if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) {
            throw new SAXException(Messages.getMessage("noElemAfterBody12"));
        }

        try {
            MessageElement element = new MessageElement(namespace, localName, prefix,
                                         attributes, context);

            if (element.getFixupDeserializer() != null)
                return (SOAPHandler)element.getFixupDeserializer();
        } catch (AxisFault axisFault) {
            throw new SAXException(axisFault);
        }

        return null;
    
public voidstartElement(java.lang.String namespace, java.lang.String localName, java.lang.String prefix, org.xml.sax.Attributes attributes, org.apache.axis.encoding.DeserializationContext context)

        if (!localName.equals(Constants.ELEM_ENVELOPE))
            throw new SAXException(
                    Messages.getMessage("badTag00", localName));

        // See if we're only supporting a single SOAP version at this endpoint
        MessageContext msgContext = context.getMessageContext();
        SOAPConstants singleVersion = null;
        if (msgContext != null) {
            singleVersion = (SOAPConstants)msgContext.getProperty(
                                            Constants.MC_SINGLE_SOAP_VERSION);
        }

        if (namespace.equals(Constants.URI_SOAP11_ENV)) {
            // SOAP 1.1
            soapConstants = SOAPConstants.SOAP11_CONSTANTS;
        } else if (namespace.equals(Constants.URI_SOAP12_ENV)) {
            // SOAP 1.2
            soapConstants = SOAPConstants.SOAP12_CONSTANTS;
        } else {
            soapConstants = null;
        }

        if ((soapConstants == null) ||
                (singleVersion != null && soapConstants != singleVersion)) {
            // Mismatch of some sort, either an unknown namespace or not
            // the one we want.  Send back an appropriate fault.

            // Right now we only send back SOAP 1.1 faults for this case.  Do
            // we want to send SOAP 1.2 faults back to SOAP 1.2 endpoints?
            soapConstants = SOAPConstants.SOAP11_CONSTANTS;
            if (singleVersion == null) singleVersion = soapConstants;

            try {
                AxisFault fault = new AxisFault(soapConstants.getVerMismatchFaultCodeQName(),
                    null, Messages.getMessage("versionMissmatch00"), null, null, null);

                SOAPHeaderElement newHeader = new
                                SOAPHeaderElement(soapConstants.getEnvelopeURI(),
                                                  Constants.ELEM_UPGRADE);

                // TODO: insert soap 1.1 upgrade header in case of soap 1.2 response if
                // axis supports both simultaneously
                MessageElement innerHeader = new
                                MessageElement(soapConstants.getEnvelopeURI(),
                                                  Constants.ELEM_SUPPORTEDENVELOPE);
                innerHeader.addAttribute(null, Constants.ATTR_QNAME,
                    new QName(singleVersion.getEnvelopeURI(), Constants.ELEM_ENVELOPE));

                newHeader.addChildElement(innerHeader);
                fault.addHeader(newHeader);

                throw new SAXException(fault);

            } catch (javax.xml.soap.SOAPException e) {
                throw new SAXException(e);
            }
        }

        // Indicate what version of SOAP we're using to anyone else involved
        // in processing this message.
        if(context.getMessageContext() != null)
            context.getMessageContext().setSOAPConstants(soapConstants);

        if (soapConstants == SOAPConstants.SOAP12_CONSTANTS &&
            attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) {

            AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER,
                null, Messages.getMessage("noEncodingStyleAttrAppear", "Envelope"), null, null, null);

            throw new SAXException(fault);
        }

        envelope.setPrefix(prefix);
        envelope.setNamespaceURI(namespace);
        envelope.setNSMappings(context.getCurrentNSMappings());
        envelope.setSoapConstants(soapConstants);
        context.pushNewElement(envelope);