- Javax.xml.bind classes
- Home
- Binder
- DatatypeConverter
- JAXB
- JAXBContext
- JAXBElement
- JAXBElement.GlobalScope
- JAXBIntrospector
- Marshaller.Listener
- SchemaOutputResolver
- Unmarshaller.Listener
- Javax.xml.bind.util classes
- JAXBResult
- JAXBSource
- ValidationEventCollector
- Javax.xml.parsers classes
- DocumentBuilder
- DocumentBuilderFactory
- SAXParser
- SAXParserFactory
- Javax.xml.soap classes
- AttachmentPart
- MessageFactory
- MimeHeader
- MimeHeaders
- SAAJMetaFactory
- SOAPConnection
- SOAPConnectionFactory
- SOAPFactory
- SOAPMessage
- SOAPPart
- Javax.xml.validation classes
- Schema
- SchemaFactory
- TypeInfoProvider
- Validator
- ValidatorHandler
- Javax.xml.xpath classes
- XPathConstants
- XPathFactory
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
MessageFactory newInstance(String protocol) Method
Description
The javax.xml.soap.MessageFactory.newInstance(String protocol) method creates a new MessageFactory object that is an instance of the specified implementation.
Declaration
Following is the declaration for javax.xml.soap.MessageFactory.newInstance(String protocol) method
static MessageFactory newInstance(String protocol)
Parameters
protocol − a string constant representing the class of the specified message factory implementation. May be either DYNAMIC_SOAP_PROTOCOL, DEFAULT_SOAP_PROTOCOL (which is the same as) SOAP_1_1_PROTOCOL, or SOAP_1_2_PROTOCOL.
Return Value
a new MessageFactory object
Exception
SOAPException − if there was an error in creating the specified implementation of the MessageFactory.
Example
The following example shows the usage of javax.xml.soap.MessageFactory.newInstance() method.
package com.tutorialspoint; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPConstants; import javax.xml.soap.SOAPMessage; public class MessageFactoryDemo { public static void main(String[] args) { try { //create a default message factory MessageFactory messageFactory = MessageFactory.newInstance( SOAPConstants.SOAP_1_2_PROTOCOL); // create a new SOAPMessage SOAPMessage message = messageFactory.createMessage(); //print the SOAPMessage on the console message.writeTo(System.out); } catch (Exception ex) { ex.printStackTrace(); } } }
If we compile the code and execute it, this will produce the following result −
<env:Envelope xmlns:env = "http://www.w3.org/2003/05/soap-envelope"> <env:Header/> <env:Body/> </env:Envelope>
To Continue Learning Please Login
Login with Google