FileDocCategorySizeDatePackage
EmptyMessageClient.javaAPI DocExample2619Fri Jul 19 22:26:34 BST 2002ora.jwsnut.chapter3.client

EmptyMessageClient

public class EmptyMessageClient extends Object
Client that sends an empty SOAP message to a service and prints the reply that it receives.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        
        if (args.length != 1) {
            usage();
        }

        try {
            // Build the message
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage message = messageFactory.createMessage();

            // Print the message.
            printMessage(message);
           
            // Get a SOAPConnection        
            SOAPConnectionFactory connFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection conn = connFactory.createConnection();
            
            // Send the message
            SOAPMessage reply = conn.call(message, args[0]);
            
            // Display the reply
            printMessage(reply);
            
            // Close the connection
            conn.close();
        } catch (Exception ex) {
            System.out.println(ex);
        }
    
private static voidprintHeaders(javax.xml.soap.MimeHeaders headers)

        printHeaders(headers.getAllHeaders());
    
private static voidprintHeaders(java.util.Iterator iter)

        while (iter.hasNext()) {
            MimeHeader header = (MimeHeader)iter.next();
            System.out.println("\t" + header.getName() + ": " + header.getValue());
        }
    
private static voidprintMessage(javax.xml.soap.SOAPMessage message)

        if (message != null) {
            // Get the MIME headers and print them
            System.out.println("Headers:");
            if (message.saveRequired()) {
                message.saveChanges();
            }
            MimeHeaders headers = message.getMimeHeaders();
            printHeaders(headers);
            
            // Print the message itself
            System.out.println("\nMessage:");
            message.writeTo(System.out);
            System.out.println();
        }
    
public static voidusage()

        System.err.println("Usage: java EmptyMessageClient address");
        System.exit(1);