src/share/jaxws_classes/javax/xml/soap/MessageFactory.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/javax/xml/soap/MessageFactory.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,200 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.xml.soap;
    1.30 +
    1.31 +
    1.32 +import java.io.IOException;
    1.33 +import java.io.InputStream;
    1.34 +
    1.35 +/**
    1.36 + * A factory for creating <code>SOAPMessage</code> objects.
    1.37 + * <P>
    1.38 + * A SAAJ client can create a <code>MessageFactory</code> object
    1.39 + * using the method <code>newInstance</code>, as shown in the following
    1.40 + * lines of code.
    1.41 + * <PRE>
    1.42 + *       MessageFactory mf = MessageFactory.newInstance();
    1.43 + *       MessageFactory mf12 = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    1.44 + * </PRE>
    1.45 + * <P>
    1.46 + * All <code>MessageFactory</code> objects, regardless of how they are
    1.47 + * created, will produce <code>SOAPMessage</code> objects that
    1.48 + * have the following elements by default:
    1.49 + * <UL>
    1.50 + *  <LI>A <code>SOAPPart</code> object
    1.51 + *  <LI>A <code>SOAPEnvelope</code> object
    1.52 + *  <LI>A <code>SOAPBody</code> object
    1.53 + *  <LI>A <code>SOAPHeader</code> object
    1.54 + * </UL>
    1.55 + * In some cases, specialized MessageFactory objects may be obtained that produce messages
    1.56 + * prepopulated with additional entries in the <code>SOAPHeader</code> object and the
    1.57 + * <code>SOAPBody</code> object.
    1.58 + * The content of a new <code>SOAPMessage</code> object depends on which of the two
    1.59 + * <code>MessageFactory</code> methods is used to create it.
    1.60 + * <UL>
    1.61 + *  <LI><code>createMessage()</code> <BR>
    1.62 + *      This is the method clients would normally use to create a request message.
    1.63 + *  <LI><code>createMessage(MimeHeaders, java.io.InputStream)</code> -- message has
    1.64 + *       content from the <code>InputStream</code> object and headers from the
    1.65 + *       <code>MimeHeaders</code> object <BR>
    1.66 + *        This method can be used internally by a service implementation to
    1.67 + *        create a message that is a response to a request.
    1.68 + * </UL>
    1.69 + */
    1.70 +public abstract class MessageFactory {
    1.71 +
    1.72 +    static final String DEFAULT_MESSAGE_FACTORY
    1.73 +        = "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl";
    1.74 +
    1.75 +    static private final String MESSAGE_FACTORY_PROPERTY
    1.76 +        = "javax.xml.soap.MessageFactory";
    1.77 +
    1.78 +    /**
    1.79 +     * Creates a new <code>MessageFactory</code> object that is an instance
    1.80 +     * of the default implementation (SOAP 1.1),
    1.81 +     *
    1.82 +     * This method uses the following ordered lookup procedure to determine the MessageFactory implementation class to load:
    1.83 +     * <UL>
    1.84 +     *  <LI> Use the javax.xml.soap.MessageFactory system property.
    1.85 +     *  <LI> Use the properties file "lib/jaxm.properties" in the JRE directory. This configuration file is in standard
    1.86 +     * java.util.Properties format and contains the fully qualified name of the implementation class with the key being the
    1.87 +     * system property defined above.
    1.88 +     *  <LI> Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API
    1.89 +     * will look for a classname in the file META-INF/services/javax.xml.soap.MessageFactory in jars available to the runtime.
    1.90 +     *  <LI> Use the SAAJMetaFactory instance to locate the MessageFactory implementation class.
    1.91 +     * </UL>
    1.92 +
    1.93 +     *
    1.94 +     * @return a new instance of a <code>MessageFactory</code>
    1.95 +     *
    1.96 +     * @exception SOAPException if there was an error in creating the
    1.97 +     *            default implementation of the
    1.98 +     *            <code>MessageFactory</code>.
    1.99 +     * @see SAAJMetaFactory
   1.100 +     */
   1.101 +
   1.102 +    public static MessageFactory newInstance() throws SOAPException {
   1.103 +
   1.104 +
   1.105 +        try {
   1.106 +            MessageFactory factory = (MessageFactory) FactoryFinder.find(
   1.107 +                    MESSAGE_FACTORY_PROPERTY,
   1.108 +                    DEFAULT_MESSAGE_FACTORY,
   1.109 +                    false);
   1.110 +
   1.111 +            if (factory != null) {
   1.112 +                return factory;
   1.113 +            }
   1.114 +            return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
   1.115 +
   1.116 +        } catch (Exception ex) {
   1.117 +            throw new SOAPException(
   1.118 +                    "Unable to create message factory for SOAP: "
   1.119 +                                    +ex.getMessage());
   1.120 +        }
   1.121 +
   1.122 +    }
   1.123 +
   1.124 +    /**
   1.125 +     * Creates a new <code>MessageFactory</code> object that is an instance
   1.126 +     * of the specified implementation.  May be a dynamic message factory,
   1.127 +     * a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
   1.128 +     * message factory creates messages based on the MIME headers specified
   1.129 +     * as arguments to the <code>createMessage</code> method.
   1.130 +     *
   1.131 +     * This method uses the SAAJMetaFactory to locate the implementation class
   1.132 +     * and create the MessageFactory instance.
   1.133 +     *
   1.134 +     * @return a new instance of a <code>MessageFactory</code>
   1.135 +     *
   1.136 +     * @param protocol  a string constant representing the class of the
   1.137 +     *                   specified message factory implementation. May be
   1.138 +     *                   either <code>DYNAMIC_SOAP_PROTOCOL</code>,
   1.139 +     *                   <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
   1.140 +     *                   as) <code>SOAP_1_1_PROTOCOL</code>, or
   1.141 +     *                   <code>SOAP_1_2_PROTOCOL</code>.
   1.142 +     *
   1.143 +     * @exception SOAPException if there was an error in creating the
   1.144 +     *            specified implementation of  <code>MessageFactory</code>.
   1.145 +     * @see SAAJMetaFactory
   1.146 +     * @since SAAJ 1.3
   1.147 +     */
   1.148 +    public static MessageFactory newInstance(String protocol) throws SOAPException {
   1.149 +        return SAAJMetaFactory.getInstance().newMessageFactory(protocol);
   1.150 +    }
   1.151 +
   1.152 +    /**
   1.153 +     * Creates a new <code>SOAPMessage</code> object with the default
   1.154 +     * <code>SOAPPart</code>, <code>SOAPEnvelope</code>, <code>SOAPBody</code>,
   1.155 +     * and <code>SOAPHeader</code> objects. Profile-specific message factories
   1.156 +     * can choose to prepopulate the <code>SOAPMessage</code> object with
   1.157 +     * profile-specific headers.
   1.158 +     * <P>
   1.159 +     * Content can be added to this message's <code>SOAPPart</code> object, and
   1.160 +     * the message can be sent "as is" when a message containing only a SOAP part
   1.161 +     * is sufficient. Otherwise, the <code>SOAPMessage</code> object needs
   1.162 +     * to create one or more <code>AttachmentPart</code> objects and
   1.163 +     * add them to itself. Any content that is not in XML format must be
   1.164 +     * in an <code>AttachmentPart</code> object.
   1.165 +     *
   1.166 +     * @return a new <code>SOAPMessage</code> object
   1.167 +     * @exception SOAPException if a SOAP error occurs
   1.168 +     * @exception UnsupportedOperationException if the protocol of this
   1.169 +     *      <code>MessageFactory</code> instance is <code>DYNAMIC_SOAP_PROTOCOL</code>
   1.170 +     */
   1.171 +    public abstract SOAPMessage createMessage()
   1.172 +        throws SOAPException;
   1.173 +
   1.174 +    /**
   1.175 +     * Internalizes the contents of the given <code>InputStream</code> object into a
   1.176 +     * new <code>SOAPMessage</code> object and returns the <code>SOAPMessage</code>
   1.177 +     * object.
   1.178 +     *
   1.179 +     * @param in the <code>InputStream</code> object that contains the data
   1.180 +     *           for a message
   1.181 +     * @param headers the transport-specific headers passed to the
   1.182 +     *        message in a transport-independent fashion for creation of the
   1.183 +     *        message
   1.184 +     * @return a new <code>SOAPMessage</code> object containing the data from
   1.185 +     *         the given <code>InputStream</code> object
   1.186 +     *
   1.187 +     * @exception IOException if there is a problem in reading data from
   1.188 +     *            the input stream
   1.189 +     *
   1.190 +     * @exception SOAPException may be thrown if the message is invalid
   1.191 +     *
   1.192 +     * @exception IllegalArgumentException if the <code>MessageFactory</code>
   1.193 +     *      requires one or more MIME headers to be present in the
   1.194 +     *      <code>headers</code> parameter and they are missing.
   1.195 +     *      <code>MessageFactory</code> implementations for
   1.196 +     *      <code>SOAP_1_1_PROTOCOL</code> or
   1.197 +     *      <code>SOAP_1_2_PROTOCOL</code> must not throw
   1.198 +     *      <code>IllegalArgumentException</code> for this reason.
   1.199 +     */
   1.200 +    public abstract SOAPMessage createMessage(MimeHeaders headers,
   1.201 +                                              InputStream in)
   1.202 +        throws IOException, SOAPException;
   1.203 +}

mercurial