protected abstract MessageFactory newMessageFactory(String protocol) Method



Description

The javax.xml.soap.SAAJMetaFactory.newMessageFactory(String protocol) method creates a MessageFactory object for the given String protocol.

Declaration

Following is the declaration for javax.xml.soap.SAAJMetaFactory.newMessageFactory(String protocol) method

protected abstract MessageFactory newMessageFactory(String protocol)

Parameters

protocol − a String indicating the protocol.

Exception

SOAPException − if there is an error in creating the MessageFactory.

Example

The following example shows the usage of javax.xml.soap.SAAJMetaFactory.newMessageFactory(String protocol) method.

package com.tutorialspoint;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPMessage;

public class SAAJMetaFactoryDemo {
   public static void main(String[] args) {
      try {
    	 //create a default message factory using MessageFactory implementation of 
		 //SAAJMetaFactory.newMessageFactory(String protocol)
    	 MessageFactory messageFactory = MessageFactory.newInstance(
    			 SOAPConstants.SOAP_1_2_PROTOCOL);
    	  
         // create a new SOAPMessage
         SOAPMessage message = MessageFactory
            .newInstance()
            .createMessage();
         
         message.writeTo(System.out);
         
      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

If we compile the code and execute it, this will produce the following result −

<SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body/>
</SOAP-ENV:Envelope>
javax_xml_soap_saajmetafactory.htm
Advertisements