FileDocCategorySizeDatePackage
CDLister.javaAPI DocExample5546Wed Sep 19 09:29:10 BST 2001javaxml2

CDLister

public class CDLister extends Object

CDLister is a web services client. It connects to the cd-catalog-demo service and lists the currently available CDs.

Fields Summary
Constructors Summary
Methods Summary
public voidlist(java.net.URL url)

This will connect to the provided URL and attempt to use the cd-catalog-demo web service to get a listing of currently available CDs. It then outputs that list to System.out.

param
url URL where web service is running.
throws
SOAPException - when errors in accessing the web service occur.

        System.out.println("Listing current CD catalog.");

        // Map the CD type so SOAP can use it
        SOAPMappingRegistry registry = new SOAPMappingRegistry();
        BeanSerializer serializer = new BeanSerializer();
        registry.mapTypes(Constants.NS_URI_SOAP_ENC,
            new QName("urn:cd-catalog-demo", "cd"),
            CD.class, serializer, serializer);   

        // Build the Call object
        Call call = new Call();
        call.setSOAPMappingRegistry(registry);
        call.setTargetObjectURI("urn:cd-catalog");
        call.setMethodName("list");
        call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

        // No parameters needed

        // Invoke the call
        Response response;
        response = call.invoke(url, "");

        if (!response.generatedFault()) {
            Parameter returnValue = response.getReturnValue();
            Hashtable catalog = (Hashtable)returnValue.getValue();
            Enumeration e = catalog.keys();
            while (e.hasMoreElements()) {
                String title = (String)e.nextElement();
                CD cd = (CD)catalog.get(title);
                System.out.println("  '" + cd.getTitle() + "' by " + cd.getArtist() +
                    " on the label " + cd.getLabel());
            }
        } else {
            Fault fault = response.getFault();
            System.out.println("Error encountered: " + fault.getFaultString());

            Vector entries = fault.getDetailEntries();
            for (Iterator i = entries.iterator(); i.hasNext(); ) {
                org.w3c.dom.Element entry = (org.w3c.dom.Element)i.next();
                System.out.println(entry.getFirstChild().getNodeValue());
            }
        }
    
public static voidmain(java.lang.String[] args)

Provide a static entry point.

        if (args.length != 1) {
            System.out.println("Usage: java javaxml2.CDAdder [SOAP server URL]");
            return;
        }

        try {
            // URL for SOAP server to connect to
            URL url = new URL(args[0]);

            // List the current CDs
            CDLister lister = new CDLister();
            lister.list(url);
        } catch (Exception e) {
            e.printStackTrace();
        }