FileDocCategorySizeDatePackage
CDOrderer.javaAPI DocExample4925Wed Sep 19 09:44:22 BST 2001javaxml2

CDOrderer

public class CDOrderer extends Object

CDOrderer is a web services client. It uses SOAP messaging to send a message to the cd-order-service.

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

Provide a static entry point.

        if (args.length != 1) {
            System.out.println("Usage: java javaxml2.CDOrderer " +
                "[XML Message Filename]");
            return;
        }

        try {
            URL serviceURL = 
                new URL("http://localhost:8080/soap/servlet/messagerouter");

            CDOrderer orderer = new CDOrderer();
            orderer.order(serviceURL, args[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    
public voidorder(java.net.URL serviceURL, java.lang.String msgFilename)

This will take a SOAP message, and send it to the cd-order-service which should reside at the supplied URL.

param
serviceURL the URL the web service is running on.
param
msgFilename the file to read the SOAP message from.
throws
IOException - when file access errors occur.
throws
SAXException - when file parsing errors occur.
throws
SOAPException - when errors occuring in accessing the SOAP service.


        // Parse the XML message
        FileReader reader = new FileReader(msgFilename);
        DocumentBuilder builder = XMLParserUtils.getXMLDocBuilder();
        Document doc = builder.parse(new InputSource(reader));
        if (doc == null) {
            throw new SOAPException(Constants.FAULT_CODE_CLIENT, 
                "Error parsing XML message.");
        }

        // Create the message envelope
        Envelope msgEnvelope = Envelope.unmarshall(doc.getDocumentElement());

        // Send the message
        Message msg = new Message();
        msg.send(serviceURL, "urn:cd-order-service", msgEnvelope);

        // Handle the response
        SOAPTransport transport = msg.getSOAPTransport();
        BufferedReader resReader = transport.receive();

        String line;
        while ((line = resReader.readLine()) != null) {
            System.out.println(line);
        }