aoqi@0: /*
aoqi@0: * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0: *
aoqi@0: * This code is free software; you can redistribute it and/or modify it
aoqi@0: * under the terms of the GNU General Public License version 2 only, as
aoqi@0: * published by the Free Software Foundation. Oracle designates this
aoqi@0: * particular file as subject to the "Classpath" exception as provided
aoqi@0: * by Oracle in the LICENSE file that accompanied this code.
aoqi@0: *
aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0: * accompanied this code).
aoqi@0: *
aoqi@0: * You should have received a copy of the GNU General Public License version
aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0: *
aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0: * or visit www.oracle.com if you need additional information or have any
aoqi@0: * questions.
aoqi@0: */
aoqi@0:
aoqi@0: package javax.xml.soap;
aoqi@0:
aoqi@0:
aoqi@0: import java.io.IOException;
aoqi@0: import java.io.InputStream;
aoqi@0:
aoqi@0: /**
aoqi@0: * A factory for creating SOAPMessage
objects.
aoqi@0: *
aoqi@0: * A SAAJ client can create a MessageFactory
object
aoqi@0: * using the method newInstance
, as shown in the following
aoqi@0: * lines of code.
aoqi@0: *
aoqi@0: * MessageFactory mf = MessageFactory.newInstance(); aoqi@0: * MessageFactory mf12 = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); aoqi@0: *aoqi@0: *
aoqi@0: * All MessageFactory
objects, regardless of how they are
aoqi@0: * created, will produce SOAPMessage
objects that
aoqi@0: * have the following elements by default:
aoqi@0: *
SOAPPart
object
aoqi@0: * SOAPEnvelope
object
aoqi@0: * SOAPBody
object
aoqi@0: * SOAPHeader
object
aoqi@0: * SOAPHeader
object and the
aoqi@0: * SOAPBody
object.
aoqi@0: * The content of a new SOAPMessage
object depends on which of the two
aoqi@0: * MessageFactory
methods is used to create it.
aoqi@0: * createMessage()
createMessage(MimeHeaders, java.io.InputStream)
-- message has
aoqi@0: * content from the InputStream
object and headers from the
aoqi@0: * MimeHeaders
object MessageFactory
object that is an instance
aoqi@0: * of the default implementation (SOAP 1.1),
aoqi@0: *
aoqi@0: * This method uses the following ordered lookup procedure to determine the MessageFactory implementation class to load:
aoqi@0: * MessageFactory
aoqi@0: *
aoqi@0: * @exception SOAPException if there was an error in creating the
aoqi@0: * default implementation of the
aoqi@0: * MessageFactory
.
aoqi@0: * @see SAAJMetaFactory
aoqi@0: */
aoqi@0:
aoqi@0: public static MessageFactory newInstance() throws SOAPException {
aoqi@0:
aoqi@0:
aoqi@0: try {
aoqi@0: MessageFactory factory = (MessageFactory) FactoryFinder.find(
aoqi@0: MESSAGE_FACTORY_PROPERTY,
aoqi@0: DEFAULT_MESSAGE_FACTORY,
aoqi@0: false);
aoqi@0:
aoqi@0: if (factory != null) {
aoqi@0: return factory;
aoqi@0: }
aoqi@0: return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
aoqi@0:
aoqi@0: } catch (Exception ex) {
aoqi@0: throw new SOAPException(
aoqi@0: "Unable to create message factory for SOAP: "
aoqi@0: +ex.getMessage());
aoqi@0: }
aoqi@0:
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Creates a new MessageFactory
object that is an instance
aoqi@0: * of the specified implementation. May be a dynamic message factory,
aoqi@0: * a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
aoqi@0: * message factory creates messages based on the MIME headers specified
aoqi@0: * as arguments to the createMessage
method.
aoqi@0: *
aoqi@0: * This method uses the SAAJMetaFactory to locate the implementation class
aoqi@0: * and create the MessageFactory instance.
aoqi@0: *
aoqi@0: * @return a new instance of a MessageFactory
aoqi@0: *
aoqi@0: * @param protocol a string constant representing the class of the
aoqi@0: * specified message factory implementation. May be
aoqi@0: * either DYNAMIC_SOAP_PROTOCOL
,
aoqi@0: * DEFAULT_SOAP_PROTOCOL
(which is the same
aoqi@0: * as) SOAP_1_1_PROTOCOL
, or
aoqi@0: * SOAP_1_2_PROTOCOL
.
aoqi@0: *
aoqi@0: * @exception SOAPException if there was an error in creating the
aoqi@0: * specified implementation of MessageFactory
.
aoqi@0: * @see SAAJMetaFactory
aoqi@0: * @since SAAJ 1.3
aoqi@0: */
aoqi@0: public static MessageFactory newInstance(String protocol) throws SOAPException {
aoqi@0: return SAAJMetaFactory.getInstance().newMessageFactory(protocol);
aoqi@0: }
aoqi@0:
aoqi@0: /**
aoqi@0: * Creates a new SOAPMessage
object with the default
aoqi@0: * SOAPPart
, SOAPEnvelope
, SOAPBody
,
aoqi@0: * and SOAPHeader
objects. Profile-specific message factories
aoqi@0: * can choose to prepopulate the SOAPMessage
object with
aoqi@0: * profile-specific headers.
aoqi@0: *
aoqi@0: * Content can be added to this message's SOAPPart
object, and
aoqi@0: * the message can be sent "as is" when a message containing only a SOAP part
aoqi@0: * is sufficient. Otherwise, the SOAPMessage
object needs
aoqi@0: * to create one or more AttachmentPart
objects and
aoqi@0: * add them to itself. Any content that is not in XML format must be
aoqi@0: * in an AttachmentPart
object.
aoqi@0: *
aoqi@0: * @return a new SOAPMessage
object
aoqi@0: * @exception SOAPException if a SOAP error occurs
aoqi@0: * @exception UnsupportedOperationException if the protocol of this
aoqi@0: * MessageFactory
instance is DYNAMIC_SOAP_PROTOCOL
aoqi@0: */
aoqi@0: public abstract SOAPMessage createMessage()
aoqi@0: throws SOAPException;
aoqi@0:
aoqi@0: /**
aoqi@0: * Internalizes the contents of the given InputStream
object into a
aoqi@0: * new SOAPMessage
object and returns the SOAPMessage
aoqi@0: * object.
aoqi@0: *
aoqi@0: * @param in the InputStream
object that contains the data
aoqi@0: * for a message
aoqi@0: * @param headers the transport-specific headers passed to the
aoqi@0: * message in a transport-independent fashion for creation of the
aoqi@0: * message
aoqi@0: * @return a new SOAPMessage
object containing the data from
aoqi@0: * the given InputStream
object
aoqi@0: *
aoqi@0: * @exception IOException if there is a problem in reading data from
aoqi@0: * the input stream
aoqi@0: *
aoqi@0: * @exception SOAPException may be thrown if the message is invalid
aoqi@0: *
aoqi@0: * @exception IllegalArgumentException if the MessageFactory
aoqi@0: * requires one or more MIME headers to be present in the
aoqi@0: * headers
parameter and they are missing.
aoqi@0: * MessageFactory
implementations for
aoqi@0: * SOAP_1_1_PROTOCOL
or
aoqi@0: * SOAP_1_2_PROTOCOL
must not throw
aoqi@0: * IllegalArgumentException
for this reason.
aoqi@0: */
aoqi@0: public abstract SOAPMessage createMessage(MimeHeaders headers,
aoqi@0: InputStream in)
aoqi@0: throws IOException, SOAPException;
aoqi@0: }