SOAPConstants.SOAP_1_2_PROTOCOL

This section provides a tutorial example on how to create a SOAPMessage object for SOAP 1.2 protocol - MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).

Are you ready to see how SAAJ support SOAP 1.2? Here is my first test program:

/**
 * SOAPMessage12Test.java
 * Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
 * All rights reserved
 */
import java.io.*;
import javax.xml.soap.*;
public class SOAPMessage12Test {
   public static void main(String[] args) {
      PrintStream out = System.out;

// Checking command line arguments
      if (args.length < 1) {
         out.println("Usage:");
         out.println("java SOAPMessage12Test url");
         return;
      }
      String sURL = args[0];

      try {
// Building the request document
         SOAPMessage reqMsg = MessageFactory.newInstance(
      	    SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
         SOAPEnvelope envelope = reqMsg.getSOAPPart().getEnvelope();
         SOAPBody body = envelope.getBody();
         body.addBodyElement(envelope.createName("Hello"));

// Connecting and calling
	 SOAPConnection con 
	    = SOAPConnectionFactory.newInstance().createConnection();
         SOAPMessage resMsg = con.call(reqMsg, sURL);
         con.close();

// Showing output
         out.println("\n\nRequest:");
         reqMsg.writeTo(out);
         out.println("\n\nResponse:");
         resMsg.writeTo(out);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

To help my socket server test program to test SOAP 1.2 messages, I created this SOAP 1.2 HTTP response file, soap_1_2_server.res:

HTTP/1.1 200 OK
Connection: close
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 303

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <HelloRes>Hello Herong!</HelloRes>
  </soap:Body>
</soap:Envelope>

In the server command window:

\herong>java SocketRequestResponseServer soap_1_2_server.res
   server.req

Listening at 8888

In the client command window:

\herong>java SOAPMessage12Test http://localhost:8888

Request:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <env:Header/>
  <env:Body><Hello/></env:Body>
</env:Envelope>

Response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <HelloRes>Hello Herong!</HelloRes>
  </soap:Body>
</soap:Envelope>

Back in the client command window:

Connection received from /127.0.0.1
Request length: 414
Response length: 401

\herong>type server.req
POST / HTTP/1.1
Accept: application/soap+xml, text/html, image/gif, image/jpeg, *;...
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 123
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0_06
Host: localhost:8888
Connection: keep-alive


  
  




Result looks very good:

Last update: 2009.

Table of Contents

 About This Book

 Introduction to Web Service

 Introduction to SOAP (Simple Object Access Protocol)

 SOAP Message Structure

 SOAP Message Transmission and Processing

 SOAP Data Model

 SOAP Encoding

 SOAP RPC Presentation

 SOAP Properties Model

 SOAP Message Exchange Patterns

 SOAP HTTP Binding

 SOAP Perl Implementations

 SOAP PHP Implementations

 SOAP Java Implementations

 Perl SOAP::Lite - SOAP Server-Client Communication Module

 Perl Socket Test Program for HTTP and SOAP

 Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service

 Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services

 Perl SOAP::Lite 0.710 for WSDL

 PHP SOAP Extension Client Programs

 PHP SOAP Extension Server Programs

 Java Socket and HttpURLConnection for SOAP

SAAJ - SOAP with Attachments API for Java

 SAAJ API 1.3 Classes and Interfaces Overview

 SAAJ API and Default Implementation in JDK 1.6.0

 SAAJ API Reference Implementation 1.3.4

 First SOAPConnection Test Program

 Creating SOAPConnection and SOAPMessage Objects

 SAAJ SOAPMessage Structure and Classes/Interfaces

 Populating the SOAP Body with Request XML Elements

 Don't Use xml* as namespace Prefix

 addHeader() - Setting SOAPAction Header Line

 Calling GetSpeech SOAP 1.1 with SAAJ

SOAPConstants.SOAP_1_2_PROTOCOL

 Calling GetSpeech SOAP 1.2 with SAAJ

 SoapUI - SOAP Web Service Testing Tool

 WS-Security - SOAP Message Security Extension

 WS-Security X.509 Certificate Token

 Web Services and SOAP Terminology

 References

 PDF Printing Version