Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 2012, 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 | |
ohair@286 | 69 | static private 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 | |
ohair@286 | 99 | public static MessageFactory newInstance() |
ohair@286 | 100 | throws SOAPException { |
ohair@286 | 101 | try { |
ohair@286 | 102 | MessageFactory factory = (MessageFactory) |
alanb@368 | 103 | FactoryFinder.find(MESSAGE_FACTORY_PROPERTY, |
alanb@368 | 104 | DEFAULT_MESSAGE_FACTORY, false); |
ohair@286 | 105 | |
ohair@286 | 106 | if (factory != null) |
ohair@286 | 107 | return factory; |
ohair@286 | 108 | return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); |
ohair@286 | 109 | } catch (Exception ex) { |
ohair@286 | 110 | throw new SOAPException( |
ohair@286 | 111 | "Unable to create message factory for SOAP: " |
ohair@286 | 112 | +ex.getMessage()); |
ohair@286 | 113 | } |
ohair@286 | 114 | |
ohair@286 | 115 | } |
ohair@286 | 116 | |
ohair@286 | 117 | /** |
ohair@286 | 118 | * Creates a new <code>MessageFactory</code> object that is an instance |
ohair@286 | 119 | * of the specified implementation. May be a dynamic message factory, |
ohair@286 | 120 | * a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic |
ohair@286 | 121 | * message factory creates messages based on the MIME headers specified |
ohair@286 | 122 | * as arguments to the <code>createMessage</code> method. |
ohair@286 | 123 | * |
ohair@286 | 124 | * This method uses the SAAJMetaFactory to locate the implementation class |
ohair@286 | 125 | * and create the MessageFactory instance. |
ohair@286 | 126 | * |
ohair@286 | 127 | * @return a new instance of a <code>MessageFactory</code> |
ohair@286 | 128 | * |
ohair@286 | 129 | * @param protocol a string constant representing the class of the |
ohair@286 | 130 | * specified message factory implementation. May be |
ohair@286 | 131 | * either <code>DYNAMIC_SOAP_PROTOCOL</code>, |
ohair@286 | 132 | * <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same |
ohair@286 | 133 | * as) <code>SOAP_1_1_PROTOCOL</code>, or |
ohair@286 | 134 | * <code>SOAP_1_2_PROTOCOL</code>. |
ohair@286 | 135 | * |
ohair@286 | 136 | * @exception SOAPException if there was an error in creating the |
ohair@286 | 137 | * specified implementation of <code>MessageFactory</code>. |
ohair@286 | 138 | * @see SAAJMetaFactory |
ohair@286 | 139 | * @since SAAJ 1.3 |
ohair@286 | 140 | */ |
ohair@286 | 141 | public static MessageFactory newInstance(String protocol) throws SOAPException { |
ohair@286 | 142 | return SAAJMetaFactory.getInstance().newMessageFactory(protocol); |
ohair@286 | 143 | } |
ohair@286 | 144 | |
ohair@286 | 145 | /** |
ohair@286 | 146 | * Creates a new <code>SOAPMessage</code> object with the default |
ohair@286 | 147 | * <code>SOAPPart</code>, <code>SOAPEnvelope</code>, <code>SOAPBody</code>, |
ohair@286 | 148 | * and <code>SOAPHeader</code> objects. Profile-specific message factories |
ohair@286 | 149 | * can choose to prepopulate the <code>SOAPMessage</code> object with |
ohair@286 | 150 | * profile-specific headers. |
ohair@286 | 151 | * <P> |
ohair@286 | 152 | * Content can be added to this message's <code>SOAPPart</code> object, and |
ohair@286 | 153 | * the message can be sent "as is" when a message containing only a SOAP part |
ohair@286 | 154 | * is sufficient. Otherwise, the <code>SOAPMessage</code> object needs |
ohair@286 | 155 | * to create one or more <code>AttachmentPart</code> objects and |
ohair@286 | 156 | * add them to itself. Any content that is not in XML format must be |
ohair@286 | 157 | * in an <code>AttachmentPart</code> object. |
ohair@286 | 158 | * |
ohair@286 | 159 | * @return a new <code>SOAPMessage</code> object |
ohair@286 | 160 | * @exception SOAPException if a SOAP error occurs |
ohair@286 | 161 | * @exception UnsupportedOperationException if the protocol of this |
ohair@286 | 162 | * <code>MessageFactory</code> instance is <code>DYNAMIC_SOAP_PROTOCOL</code> |
ohair@286 | 163 | */ |
ohair@286 | 164 | public abstract SOAPMessage createMessage() |
ohair@286 | 165 | throws SOAPException; |
ohair@286 | 166 | |
ohair@286 | 167 | /** |
ohair@286 | 168 | * Internalizes the contents of the given <code>InputStream</code> object into a |
ohair@286 | 169 | * new <code>SOAPMessage</code> object and returns the <code>SOAPMessage</code> |
ohair@286 | 170 | * object. |
ohair@286 | 171 | * |
ohair@286 | 172 | * @param in the <code>InputStream</code> object that contains the data |
ohair@286 | 173 | * for a message |
ohair@286 | 174 | * @param headers the transport-specific headers passed to the |
ohair@286 | 175 | * message in a transport-independent fashion for creation of the |
ohair@286 | 176 | * message |
ohair@286 | 177 | * @return a new <code>SOAPMessage</code> object containing the data from |
ohair@286 | 178 | * the given <code>InputStream</code> object |
ohair@286 | 179 | * |
ohair@286 | 180 | * @exception IOException if there is a problem in reading data from |
ohair@286 | 181 | * the input stream |
ohair@286 | 182 | * |
ohair@286 | 183 | * @exception SOAPException may be thrown if the message is invalid |
ohair@286 | 184 | * |
ohair@286 | 185 | * @exception IllegalArgumentException if the <code>MessageFactory</code> |
ohair@286 | 186 | * requires one or more MIME headers to be present in the |
ohair@286 | 187 | * <code>headers</code> parameter and they are missing. |
ohair@286 | 188 | * <code>MessageFactory</code> implementations for |
ohair@286 | 189 | * <code>SOAP_1_1_PROTOCOL</code> or |
ohair@286 | 190 | * <code>SOAP_1_2_PROTOCOL</code> must not throw |
ohair@286 | 191 | * <code>IllegalArgumentException</code> for this reason. |
ohair@286 | 192 | */ |
ohair@286 | 193 | public abstract SOAPMessage createMessage(MimeHeaders headers, |
ohair@286 | 194 | InputStream in) |
ohair@286 | 195 | throws IOException, SOAPException; |
ohair@286 | 196 | } |