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

📄 message.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;import org.apache.axis.attachments.Attachments;import org.apache.axis.components.logger.LogFactory;import org.apache.axis.message.SOAPEnvelope;import org.apache.axis.message.MimeHeaders;import org.apache.axis.soap.SOAPConstants;import org.apache.axis.transport.http.HTTPConstants;import org.apache.axis.utils.ClassUtils;import org.apache.axis.utils.Messages;import org.apache.axis.utils.XMLUtils;import org.apache.commons.logging.Log;import javax.xml.soap.AttachmentPart;import javax.xml.soap.SOAPException;import javax.xml.soap.SOAPBody;import javax.xml.soap.SOAPHeader;import javax.xml.soap.SOAPMessage;import java.io.IOException;import java.lang.reflect.Constructor;import java.lang.reflect.InvocationTargetException;import java.util.Iterator;import java.util.Collections;/** * A complete SOAP (and/or XML-RPC, eventually) message. * Includes both the root part (as a SOAPPart), and zero or * more MIME attachments (as AttachmentParts). * <p> * Eventually should be refactored to generalize SOAPPart * for multiple protocols (XML-RPC?). * * @author Rob Jellinghaus (robj@unrealities.com) * @author Doug Davis (dug@us.ibm.com) * @author Glen Daniels (gdaniels@allaire.com) * @author Rick Rineholt * @author Heejune Ahn (cityboy@tmax.co.kr) */public class Message extends javax.xml.soap.SOAPMessage    implements java.io.Serializable {    /**     * The <code>Log</code> that this class uses for logging all messages.     */    protected static Log log =        LogFactory.getLog(Message.class.getName());    /** Message is a request. */    public static final String REQUEST = "request";    /** Message is a a response. */    public static final String RESPONSE = "response";    /** MIME parts defined for messages. */    public static final String MIME_MULTIPART_RELATED = "multipart/related";    /** DIME parts defined for messages. */    public static final String MIME_APPLICATION_DIME = "application/dime";    /** Content Type for MTOM/XOP */    public static final String CONTENT_TYPE_MTOM = "application/xop+xml";    /** Default Attachments Implementation class. */    public static final String DEFAULT_ATTACHMNET_IMPL="org.apache.axis.attachments.AttachmentsImpl";    /** Current Attachment implementation. */    private static String mAttachmentsImplClassName=DEFAULT_ATTACHMNET_IMPL;    /** Look at the input stream to find the headers to decide the mime type. */    public static final String MIME_UNKNOWN = "  ";    // fixme: is this constrained to two values - request/response (e.g.    //  REQUEST and RESPONSE)? If so, this needs documenting in the get/set    //  methods and/or converting into a type-safe e-num. Potentially get/set    //  methods should check these values & throw IllegalArgumentException    /**     * The messageType indicates whether this is request or response.     */    private String messageType;    /**     * This Message's SOAPPart.  Will always be here.     */    private SOAPPart mSOAPPart;    /**     * This Message's Attachments object, which manages the attachments     * contained in this Message.     */    private Attachments mAttachments = null;    private MimeHeaders headers;    private boolean saveRequired = true;    /**     * Returns the name of the class prividing Attachment Implementation.     *     * @return class name     */    public static String getAttachmentImplClassName(){        return mAttachmentsImplClassName;    }    private MessageContext msgContext;    /**     * Get the message type.     *     * @return the message type <code>String</code>     */    public String getMessageType() {        return messageType;    }    /**     *  Set the message type.     *     * @param messageType the message type <code>String</code>     */    public void setMessageType(String messageType) {        this.messageType = messageType;    }    /**     * Get the context associated with this message.     *     * @return  the message context for this message     */    public MessageContext getMessageContext() {        return msgContext;    }    /**     * Set the context associated with this message.     *     * @param msgContext  the message context for this message     */    public void setMessageContext(MessageContext msgContext) {        this.msgContext = msgContext;    }    /**     * Construct a Message, using the provided initialContents as the     * contents of the Message's SOAPPart.     * <p>     * Eventually, genericize this to     * return the RootPart instead, which will have some kind of     * EnvelopeFactory to enable support for things other than SOAP.     * But that all will come later, with lots of additional refactoring.     *     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,     *                        or AxisFault.     * @param bodyInStream is true if initialContents is an InputStream     *                     containing just the SOAP body (no SOAP-ENV).     */    public Message(Object initialContents, boolean bodyInStream) {        setup(initialContents, bodyInStream, null, null, null);    }    /**     * Construct a Message, using the provided initialContents as the     * contents of the Message's SOAPPart.     * <p>     * Eventually, genericize this to     * return the RootPart instead, which will have some kind of     * EnvelopeFactory to enable support for things other than SOAP.     * But that all will come later, with lots of additional refactoring.     *     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,     *                        or AxisFault.     * @param bodyInStream is true if initialContents is an InputStream     *                     containing just the SOAP body (no SOAP-ENV).     * @param headers Mime Headers.     */    public Message(Object initialContents, boolean bodyInStream, javax.xml.soap.MimeHeaders headers) {        setup(initialContents, bodyInStream, null, null, headers);    }    /**     * Construct a Message, using the provided initialContents as the     * contents of the Message's SOAPPart.     * <p>     * Eventually, genericize this to     * return the RootPart instead, which will have some kind of     * EnvelopeFactory to enable support for things other than SOAP.     * But that all will come later, with lots of additional refactoring.     *     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,     *                        or AxisFault.     * @param headers Mime Headers.     */    public Message(Object initialContents, MimeHeaders headers) {        setup(initialContents, true, null, null, headers);    }    /**     * Construct a Message, using the provided initialContents as the     * contents of the Message's SOAPPart.     * <p>     * Eventually, genericize this to     * return the RootPart instead, which will have some kind of     * EnvelopeFactory to enable support for things other than SOAP.     * But that all will come later, with lots of additional refactoring.     *     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,     *                        or AxisFault     * @param bodyInStream is true if initialContents is an InputStream     *                     containing just the SOAP body (no SOAP-ENV)     * @param contentType this if the contentType has been already determined     *                   (as in the case of servlets)     * @param contentLocation the location of the content     */    public Message(Object initialContents,                   boolean bodyInStream,                   String contentType,                   String contentLocation) {        setup(initialContents, bodyInStream, contentType, contentLocation, null);    }    /**     * Construct a Message.  An overload of Message(Object, boolean),     * defaulting bodyInStream to false.     *     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,     *                        or AxisFault     */    public Message(Object initialContents) {        setup(initialContents, false, null, null, null);    }    private static Class attachImpl = null;    //aviod testing and possibly failing everytime.    private static boolean checkForAttachmentSupport = true;    private static boolean attachmentSupportEnabled = false;    private static synchronized boolean isAttachmentSupportEnabled(MessageContext mc) {        if (checkForAttachmentSupport) {            //aviod testing and possibly failing everytime.            checkForAttachmentSupport = false;            try {                // Get the default setting from AxisProperties                String attachImpName = AxisProperties.getProperty(AxisEngine.PROP_ATTACHMENT_IMPLEMENTATION,                        AxisEngine.DEFAULT_ATTACHMENT_IMPL);                // override the default with any changes specified in the engine configuration                if (null != mc) {                    AxisEngine ae = mc.getAxisEngine();                    if (null != ae) {                        attachImpName = (String) ae.getOption(                                AxisEngine.PROP_ATTACHMENT_IMPLEMENTATION);                    }                }                /**                 * Attempt to resolve class name, verify that these are present...                 */                ClassUtils.forName("javax.activation.DataHandler");                ClassUtils.forName("javax.mail.internet.MimeMultipart");                attachImpl = ClassUtils.forName(attachImpName);                attachmentSupportEnabled = true;            } catch (ClassNotFoundException ex) {                // no support for it, leave mAttachments null.            } catch (java.lang.NoClassDefFoundError ex) {                // no support for it, leave mAttachments null.            } catch (java.lang.SecurityException ex) {                // no support for it, leave mAttachments null.            }            log.debug(Messages.getMessage("attachEnabled") + "  " +                    attachmentSupportEnabled);        }        return attachmentSupportEnabled;    }    /**     * Do the work of construction.     *     * @param initialContents may be String, byte[], InputStream, SOAPEnvelope,     *                        or AxisFault     * @param bodyInStream is true if initialContents is an InputStream     *                     containing just the SOAP body (no SOAP-ENV)     * @param contentType this if the contentType has been already determined     *                   (as in the case of servlets)     * @param contentLocation the location of the content     * @param mimeHeaders  mime headers for attachments     */    private void setup(Object initialContents, boolean bodyInStream,                       String contentType, String contentLocation,                       javax.xml.soap.MimeHeaders mimeHeaders) {        if(contentType == null && mimeHeaders != null) {            String contentTypes[] = mimeHeaders.getHeader("Content-Type");            contentType = (contentTypes != null)? contentTypes[0] : null;        }        if(contentLocation == null && mimeHeaders != null) {            String contentLocations[] = mimeHeaders.getHeader("Content-Location");            contentLocation = (contentLocations != null)? contentLocations[0] : null;        }        if (contentType != null) {            int delimiterIndex = contentType.lastIndexOf("charset");            if (delimiterIndex > 0) {                String charsetPart = contentType.substring(delimiterIndex);                int delimiterIndex2 = charsetPart.indexOf(';');                if(delimiterIndex2 != -1){                    charsetPart = charsetPart.substring(0, delimiterIndex2);                }                int charsetIndex = charsetPart.indexOf('=');                String charset = charsetPart.substring(charsetIndex + 1).trim();                if ((charset.startsWith("\"") || charset.startsWith("\'"))) {                    charset = charset.substring(1, charset.length());                }                if ((charset.endsWith("\"") || charset.endsWith("\'"))) {                    charset = charset.substring(0, charset.length()-1);                }                try {                    setProperty(SOAPMessage.CHARACTER_SET_ENCODING, charset);                } catch (SOAPException e) {                }            }        }        // Try to construct an AttachmentsImpl object for attachment        // functionality.        // If there is no org.apache.axis.attachments.AttachmentsImpl class,        // it must mean activation.jar is not present and attachments are not        // supported.        if (isAttachmentSupportEnabled(getMessageContext())) {            // Construct one, and cast to Attachments.            // There must be exactly one constructor of AttachmentsImpl, which            // must take an org.apache.axis.Message!            Constructor attachImplConstr = attachImpl.getConstructors()[0];            try {                mAttachments = (Attachments) attachImplConstr.newInstance(                        new Object[] { initialContents,                                       contentType, contentLocation});                //If it can't support it, it wont have a root part.                mSOAPPart = (SOAPPart) mAttachments.getRootPart();            } catch (InvocationTargetException ex) {                log.fatal(Messages.getMessage("invocationTargetException00"),                          ex);                throw new RuntimeException(ex.getMessage());            } catch (InstantiationException ex) {                log.fatal(Messages.getMessage("instantiationException00"),                          ex);                throw new RuntimeException(ex.getMessage());            } catch (IllegalAccessException ex) {                log.fatal(Messages.getMessage("illegalAccessException00"),                          ex);                throw new RuntimeException(ex.getMessage());            }        } else if (contentType != null && contentType.startsWith("multipart")){            throw new RuntimeException(Messages.getMessage("noAttachments"));        }        // text/xml        if (null == mSOAPPart) {            mSOAPPart = new SOAPPart(this, initialContents, bodyInStream);        }        else          mSOAPPart.setMessage(this);        // The stream was not determined by a more complex type so default to

⌨️ 快捷键说明

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