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

📄 soapenvelope.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.axis.message;import org.apache.axis.AxisFault;import org.apache.axis.Constants;import org.apache.axis.Message;import org.apache.axis.MessageContext;import org.apache.axis.client.AxisClient;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.configuration.NullProvider;import org.apache.axis.encoding.DeserializationContext;import org.apache.axis.encoding.SerializationContext;import org.apache.axis.schema.SchemaVersion;import org.apache.axis.soap.SOAPConstants;import org.apache.axis.utils.Mapping;import org.apache.axis.utils.Messages;import org.apache.commons.logging.Log;import org.w3c.dom.DOMException;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.InputSource;import org.xml.sax.SAXException;import javax.xml.namespace.QName;import javax.xml.soap.SOAPException;import java.io.InputStream;import java.util.ArrayList;import java.util.Enumeration;import java.util.Iterator;import java.util.Vector;import java.util.List;/** * Implementation of a SOAP Envelope */ public class SOAPEnvelope extends MessageElement    implements javax.xml.soap.SOAPEnvelope{    protected static Log log =        LogFactory.getLog(SOAPEnvelope.class.getName());    private SOAPHeader header;    private SOAPBody body;    public Vector trailers = new Vector();    private SOAPConstants soapConstants;    private SchemaVersion schemaVersion = SchemaVersion.SCHEMA_2001;    // This is a hint to any service description to tell it what    // "type" of message we are.  This might be "request", "response",    // or anything else your particular service descripton requires.    //    // This gets passed back into the service description during    // deserialization    public String messageType;    private boolean recorded;    public SOAPEnvelope()    {        this(true, SOAPConstants.SOAP11_CONSTANTS);    }    public SOAPEnvelope(SOAPConstants soapConstants)    {        this(true, soapConstants);    }    public SOAPEnvelope(SOAPConstants soapConstants,                        SchemaVersion schemaVersion)    {        this(true, soapConstants, schemaVersion);    }    public SOAPEnvelope(boolean registerPrefixes, SOAPConstants soapConstants)    {        this (registerPrefixes, soapConstants, SchemaVersion.SCHEMA_2001);    }        public SOAPEnvelope(boolean registerPrefixes,                        SOAPConstants soapConstants,                        SchemaVersion schemaVersion)    {            // FIX BUG http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18108        super(Constants.ELEM_ENVELOPE,               Constants.NS_PREFIX_SOAP_ENV,               (soapConstants != null) ? soapConstants.getEnvelopeURI() : Constants.DEFAULT_SOAP_VERSION.getEnvelopeURI());        if (soapConstants == null)          soapConstants = Constants.DEFAULT_SOAP_VERSION;        // FIX BUG http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18108                        this.soapConstants = soapConstants;        this.schemaVersion = schemaVersion;        header = new SOAPHeader(this, soapConstants);        body = new SOAPBody(this, soapConstants);        if (registerPrefixes) {            if (namespaces == null)                namespaces = new ArrayList();            namespaces.add(new Mapping(soapConstants.getEnvelopeURI(),                                       Constants.NS_PREFIX_SOAP_ENV));            namespaces.add(new Mapping(schemaVersion.getXsdURI(),                                       Constants.NS_PREFIX_SCHEMA_XSD));            namespaces.add(new Mapping(schemaVersion.getXsiURI(),                                       Constants.NS_PREFIX_SCHEMA_XSI));        }        setDirty();    }        public SOAPEnvelope(InputStream input) throws SAXException {        InputSource is = new InputSource(input);        // FIX BUG http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18108        //header = new SOAPHeader(this, soapConstants); // soapConstants = null!        header = new SOAPHeader(this, Constants.DEFAULT_SOAP_VERSION); // soapConstants = null!        // FIX BUG http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18108        DeserializationContext dser = null ;        AxisClient     tmpEngine = new AxisClient(new NullProvider());        MessageContext msgContext = new MessageContext(tmpEngine);        dser = new DeserializationContext(is, msgContext,                                          Message.REQUEST, this );        dser.parse();    }    /**     * Get the Message Type (REQUEST/RESPONSE)     * @return message type     */     public String getMessageType()    {        return messageType;    }    /**     * Set the Message Type (REQUEST/RESPONSE)     * @param messageType     */     public void setMessageType(String messageType)    {        this.messageType = messageType;    }    /**     * Get all the BodyElement's in the soap body     * @return vector with body elements     * @throws AxisFault     */     public Vector getBodyElements() throws AxisFault    {        if (body != null) {            return body.getBodyElements();        } else {            return new Vector();        }    }    /**     * Return trailers     * @return vector of some type     */     public Vector getTrailers()    {        return trailers;    }    /**     * Get the first BodyElement in the SOAP Body     * @return first Body Element     * @throws AxisFault     */     public SOAPBodyElement getFirstBody() throws AxisFault    {        if (body == null) {            return null;        } else {            return body.getFirstBody();        }    }    /**     * Get Headers     * @return Vector containing Header's     * @throws AxisFault     */     public Vector getHeaders() throws AxisFault    {        if (header != null) {            return header.getHeaders();        } else {            return new Vector();        }    }    /**     * Get all the headers targeted at a list of actors.     */    public Vector getHeadersByActor(ArrayList actors)    {        if (header != null) {            return header.getHeadersByActor(actors);        } else {            return new Vector();        }    }    /**     * Add a HeaderElement     * @param hdr     */     public void addHeader(SOAPHeaderElement hdr)    {        if (header == null) {            header = new SOAPHeader(this, soapConstants);        }        hdr.setEnvelope(this);        header.addHeader(hdr);        _isDirty = true;    }    /**     * Add a SOAP Body Element     * @param element     */     public void addBodyElement(SOAPBodyElement element)    {        if (body == null) {            body = new SOAPBody(this, soapConstants);        }        element.setEnvelope(this);        body.addBodyElement(element);        _isDirty = true;    }    /**     * Remove all headers     */     public void removeHeaders() {        if (header != null) {            removeChild(header);        }        header = null;    }    /**     * Set the SOAP Header     * @param hdr     */     public void setHeader(SOAPHeader hdr) {        if(this.header != null) {            removeChild(this.header);        }        header = hdr;        try {            header.setParentElement(this);        } catch (SOAPException ex) {            // class cast should never fail when parent is a SOAPEnvelope            log.fatal(Messages.getMessage("exception00"), ex);        }    }    /**     * Remove a Header Element from SOAP Header     * @param hdr     */     public void removeHeader(SOAPHeaderElement hdr)    {        if (header != null) {            header.removeHeader(hdr);            _isDirty = true;        }    }    /**     * Remove the SOAP Body     */     public void removeBody() {        if (body != null) {            removeChild(body);        }        body = null;    }    /**     * Set the soap body     * @param body     */     public void setBody(SOAPBody body) {        if(this.body != null) {            removeChild(this.body);        }        this.body = body;        try {            body.setParentElement(this);        } catch (SOAPException ex) {            // class cast should never fail when parent is a SOAPEnvelope            log.fatal(Messages.getMessage("exception00"), ex);        }    }    /**     * Remove a Body Element from the soap body     * @param element     */     public void removeBodyElement(SOAPBodyElement element)    {        if (body != null) {            body.removeBodyElement(element);            _isDirty = true;        }    }    /**     * Remove an element from the trailer     * @param element     */     public void removeTrailer(MessageElement element)    {        if (log.isDebugEnabled())            log.debug(Messages.getMessage("removeTrailer00"));        trailers.removeElement(element);        _isDirty = true;    }    /**     * clear the elements in the soap body     */     public void clearBody()    {        if (body != null) {            body.clearBody();            _isDirty = true;

⌨️ 快捷键说明

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