Capturing HTTP Request Generated by the HttpURLConnection Class

This section provides a tutorial example on how to capture the HTTP request generated by a HttpURLConnection program to call the GetSpeech SOAP 1.1 Web service provided by xmlme.com.

To use HttpURLConnectionGetSpeech11.java, I need a SOAP 1.1 request XML message. Here is one example, soap_1_1_GetSpeech_req.xml:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetSpeech xmlns="http://xmlme.com/WebServices">
      <Request>To be, or not to be</Request>
    </GetSpeech>
  </soap:Body>
</soap:Envelope>

The first test was performed locally with my SocketRequestResponseServer.java program running in a command line window:

\herong>java SocketServerTest http_1_0_server.res server.req

Listening at 8888

In another command line window, HttpURLConnectionGetSpeech11.java was executed:

\herong>java HttpURLConnectionGetSpeech11
   soap_1_1_GetSpeech_req.xml res.xml
    
Request length: 384
Response length: 1942

Back to the server window:

...
Connection received from /127.0.0.1
Request length: 650
Response length: 170

\herong>type server.req

POST / HTTP/1.1
Content-type: text/xml; charset=utf-8
SOAPAction: http://xmlme.com/WebServices/GetSpeech
User-Agent: Java/1.6.0_06
Host: localhost:8888
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 384

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetSpeech xmlns="http://xmlme.com/WebServices">
      <Request>To be, or not to be</Request>
    </GetSpeech>
  </soap:Body>
</soap:Envelope>

The HTTP request generated by HttpURLConnectionGetSpeech11.java looks very good. The Content-Type and SOAPAction header lines were created correctly.

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

 SocketRequestResponse.java - Socket Client Testing Program

 SocketRequestResponseServer.java - Socket Server Testing Program

 Capturing the HTTP Request from a Browser

 "read(byteBuf) = -1" Not Working

 Using java.net.HttpURLConnection to Send SOAP Messages

 Using HttpURLConnection to Call GetSpeech SOAP 1.1

Capturing HTTP Request Generated by the HttpURLConnection Class

 Calling GetSpeech SOAP 1.1 Web Service

 Using HttpURLConnection to Call GetSpeech SOAP 1.2

 Calling GetSpeech SOAP 1.2 Web Service

 SAAJ - SOAP with Attachments API for Java

 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