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

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 384
8f2986ff0235
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

ohair@286 1 /*
mkos@384 2 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package javax.xml.soap;
ohair@286 27
ohair@286 28
ohair@286 29 import java.io.IOException;
ohair@286 30 import java.io.InputStream;
ohair@286 31
ohair@286 32 /**
ohair@286 33 * A factory for creating <code>SOAPMessage</code> objects.
ohair@286 34 * <P>
ohair@286 35 * A SAAJ client can create a <code>MessageFactory</code> object
ohair@286 36 * using the method <code>newInstance</code>, as shown in the following
ohair@286 37 * lines of code.
ohair@286 38 * <PRE>
ohair@286 39 * MessageFactory mf = MessageFactory.newInstance();
ohair@286 40 * MessageFactory mf12 = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
ohair@286 41 * </PRE>
ohair@286 42 * <P>
ohair@286 43 * All <code>MessageFactory</code> objects, regardless of how they are
ohair@286 44 * created, will produce <code>SOAPMessage</code> objects that
ohair@286 45 * have the following elements by default:
ohair@286 46 * <UL>
ohair@286 47 * <LI>A <code>SOAPPart</code> object
ohair@286 48 * <LI>A <code>SOAPEnvelope</code> object
ohair@286 49 * <LI>A <code>SOAPBody</code> object
ohair@286 50 * <LI>A <code>SOAPHeader</code> object
ohair@286 51 * </UL>
ohair@286 52 * In some cases, specialized MessageFactory objects may be obtained that produce messages
ohair@286 53 * prepopulated with additional entries in the <code>SOAPHeader</code> object and the
ohair@286 54 * <code>SOAPBody</code> object.
ohair@286 55 * The content of a new <code>SOAPMessage</code> object depends on which of the two
ohair@286 56 * <code>MessageFactory</code> methods is used to create it.
ohair@286 57 * <UL>
ohair@286 58 * <LI><code>createMessage()</code> <BR>
ohair@286 59 * This is the method clients would normally use to create a request message.
ohair@286 60 * <LI><code>createMessage(MimeHeaders, java.io.InputStream)</code> -- message has
ohair@286 61 * content from the <code>InputStream</code> object and headers from the
ohair@286 62 * <code>MimeHeaders</code> object <BR>
ohair@286 63 * This method can be used internally by a service implementation to
ohair@286 64 * create a message that is a response to a request.
ohair@286 65 * </UL>
ohair@286 66 */
ohair@286 67 public abstract class MessageFactory {
ohair@286 68
mkos@384 69 static final String DEFAULT_MESSAGE_FACTORY
ohair@286 70 = "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl";
ohair@286 71
ohair@286 72 static private final String MESSAGE_FACTORY_PROPERTY
ohair@286 73 = "javax.xml.soap.MessageFactory";
ohair@286 74
ohair@286 75 /**
ohair@286 76 * Creates a new <code>MessageFactory</code> object that is an instance
ohair@286 77 * of the default implementation (SOAP 1.1),
ohair@286 78 *
ohair@286 79 * This method uses the following ordered lookup procedure to determine the MessageFactory implementation class to load:
ohair@286 80 * <UL>
ohair@286 81 * <LI> Use the javax.xml.soap.MessageFactory system property.
ohair@286 82 * <LI> Use the properties file "lib/jaxm.properties" in the JRE directory. This configuration file is in standard
ohair@286 83 * java.util.Properties format and contains the fully qualified name of the implementation class with the key being the
ohair@286 84 * system property defined above.
ohair@286 85 * <LI> Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API
ohair@286 86 * will look for a classname in the file META-INF/services/javax.xml.soap.MessageFactory in jars available to the runtime.
ohair@286 87 * <LI> Use the SAAJMetaFactory instance to locate the MessageFactory implementation class.
ohair@286 88 * </UL>
ohair@286 89
ohair@286 90 *
ohair@286 91 * @return a new instance of a <code>MessageFactory</code>
ohair@286 92 *
ohair@286 93 * @exception SOAPException if there was an error in creating the
ohair@286 94 * default implementation of the
ohair@286 95 * <code>MessageFactory</code>.
ohair@286 96 * @see SAAJMetaFactory
ohair@286 97 */
ohair@286 98
mkos@384 99 public static MessageFactory newInstance() throws SOAPException {
mkos@384 100
mkos@384 101
ohair@286 102 try {
mkos@384 103 MessageFactory factory = (MessageFactory) FactoryFinder.find(
mkos@384 104 MESSAGE_FACTORY_PROPERTY,
mkos@384 105 DEFAULT_MESSAGE_FACTORY,
mkos@384 106 false);
ohair@286 107
mkos@384 108 if (factory != null) {
ohair@286 109 return factory;
mkos@384 110 }
ohair@286 111 return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
mkos@384 112
ohair@286 113 } catch (Exception ex) {
ohair@286 114 throw new SOAPException(
ohair@286 115 "Unable to create message factory for SOAP: "
ohair@286 116 +ex.getMessage());
ohair@286 117 }
ohair@286 118
ohair@286 119 }
ohair@286 120
ohair@286 121 /**
ohair@286 122 * Creates a new <code>MessageFactory</code> object that is an instance
ohair@286 123 * of the specified implementation. May be a dynamic message factory,
ohair@286 124 * a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
ohair@286 125 * message factory creates messages based on the MIME headers specified
ohair@286 126 * as arguments to the <code>createMessage</code> method.
ohair@286 127 *
ohair@286 128 * This method uses the SAAJMetaFactory to locate the implementation class
ohair@286 129 * and create the MessageFactory instance.
ohair@286 130 *
ohair@286 131 * @return a new instance of a <code>MessageFactory</code>
ohair@286 132 *
ohair@286 133 * @param protocol a string constant representing the class of the
ohair@286 134 * specified message factory implementation. May be
ohair@286 135 * either <code>DYNAMIC_SOAP_PROTOCOL</code>,
ohair@286 136 * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
ohair@286 137 * as) <code>SOAP_1_1_PROTOCOL</code>, or
ohair@286 138 * <code>SOAP_1_2_PROTOCOL</code>.
ohair@286 139 *
ohair@286 140 * @exception SOAPException if there was an error in creating the
ohair@286 141 * specified implementation of <code>MessageFactory</code>.
ohair@286 142 * @see SAAJMetaFactory
ohair@286 143 * @since SAAJ 1.3
ohair@286 144 */
ohair@286 145 public static MessageFactory newInstance(String protocol) throws SOAPException {
ohair@286 146 return SAAJMetaFactory.getInstance().newMessageFactory(protocol);
ohair@286 147 }
ohair@286 148
ohair@286 149 /**
ohair@286 150 * Creates a new <code>SOAPMessage</code> object with the default
ohair@286 151 * <code>SOAPPart</code>, <code>SOAPEnvelope</code>, <code>SOAPBody</code>,
ohair@286 152 * and <code>SOAPHeader</code> objects. Profile-specific message factories
ohair@286 153 * can choose to prepopulate the <code>SOAPMessage</code> object with
ohair@286 154 * profile-specific headers.
ohair@286 155 * <P>
ohair@286 156 * Content can be added to this message's <code>SOAPPart</code> object, and
ohair@286 157 * the message can be sent "as is" when a message containing only a SOAP part
ohair@286 158 * is sufficient. Otherwise, the <code>SOAPMessage</code> object needs
ohair@286 159 * to create one or more <code>AttachmentPart</code> objects and
ohair@286 160 * add them to itself. Any content that is not in XML format must be
ohair@286 161 * in an <code>AttachmentPart</code> object.
ohair@286 162 *
ohair@286 163 * @return a new <code>SOAPMessage</code> object
ohair@286 164 * @exception SOAPException if a SOAP error occurs
ohair@286 165 * @exception UnsupportedOperationException if the protocol of this
ohair@286 166 * <code>MessageFactory</code> instance is <code>DYNAMIC_SOAP_PROTOCOL</code>
ohair@286 167 */
ohair@286 168 public abstract SOAPMessage createMessage()
ohair@286 169 throws SOAPException;
ohair@286 170
ohair@286 171 /**
ohair@286 172 * Internalizes the contents of the given <code>InputStream</code> object into a
ohair@286 173 * new <code>SOAPMessage</code> object and returns the <code>SOAPMessage</code>
ohair@286 174 * object.
ohair@286 175 *
ohair@286 176 * @param in the <code>InputStream</code> object that contains the data
ohair@286 177 * for a message
ohair@286 178 * @param headers the transport-specific headers passed to the
ohair@286 179 * message in a transport-independent fashion for creation of the
ohair@286 180 * message
ohair@286 181 * @return a new <code>SOAPMessage</code> object containing the data from
ohair@286 182 * the given <code>InputStream</code> object
ohair@286 183 *
ohair@286 184 * @exception IOException if there is a problem in reading data from
ohair@286 185 * the input stream
ohair@286 186 *
ohair@286 187 * @exception SOAPException may be thrown if the message is invalid
ohair@286 188 *
ohair@286 189 * @exception IllegalArgumentException if the <code>MessageFactory</code>
ohair@286 190 * requires one or more MIME headers to be present in the
ohair@286 191 * <code>headers</code> parameter and they are missing.
ohair@286 192 * <code>MessageFactory</code> implementations for
ohair@286 193 * <code>SOAP_1_1_PROTOCOL</code> or
ohair@286 194 * <code>SOAP_1_2_PROTOCOL</code> must not throw
ohair@286 195 * <code>IllegalArgumentException</code> for this reason.
ohair@286 196 */
ohair@286 197 public abstract SOAPMessage createMessage(MimeHeaders headers,
ohair@286 198 InputStream in)
ohair@286 199 throws IOException, SOAPException;
ohair@286 200 }

mercurial