home *** CD-ROM | disk | FTP | other *** search
Java Source | 2003-02-24 | 2.7 KB | 93 lines |
- /**
- * %wsgw_sample_start%
- * Licensed Materials - Property of IBM
- *
- * (c) Copyright IBM Corp. 2001, 2002 All Rights Reserved.
- *
- * US Government Users Restricted Rights - Use, duplication or
- * disclosure restricted by GSA ADP Schedule Contract with
- * IBM Corp.
- * %wsgw_sample_end%
- */
- package services.addressbook;
-
- import java.io.*;
- import java.util.*;
- import java.net.*;
- import org.w3c.dom.*;
- import org.apache.soap.util.xml.*;
- import org.apache.soap.*;
- import org.apache.soap.encoding.*;
- import org.apache.soap.encoding.soapenc.*;
- import org.apache.soap.rpc.*;
- import org.apache.soap.transport.*;
- import org.apache.soap.transport.http.*;
-
- import com.ibm.www.namespace.wsif.samples.ab.types.*;
-
- /**
- * @author Matthew J. Duftler (duftler@us.ibm.com)
- */
- public class GetAddress
- {
- public static void main(String[] args) throws Exception
- {
- if ((args.length != 4) && (args.length != 6)) {
- System.err.println ("Usage: java " + GetAddress.class.getName () +
- " SOAP-router-URL method-namespace-uri" +
- " action-uri name [username password]");
- System.exit (1);
- }
-
- URL url = new URL (args[0]);
- String id = args[1];
- String actionURI = args[2];
- String name = args[3];
- String userName = null;
- String password = null;
- if (args.length == 6) {
- userName = args[4];
- password = args[5];
- }
-
- SOAPMappingRegistry smr = new SOAPMappingRegistry();
- BeanSerializer beanSer = new BeanSerializer();
-
- // Map the types.
- smr.mapTypes(Constants.NS_URI_SOAP_ENC,
- new QName("http://www.ibm.com/namespace/wsif/samples/ab/types", "address"),
- Address.class, beanSer, beanSer);
- smr.mapTypes(Constants.NS_URI_SOAP_ENC,
- new QName("http://www.ibm.com/namespace/wsif/samples/ab/types", "phone"),
- Phone.class, beanSer, beanSer);
-
- // Build the call.
- Call call = new Call();
-
- call.setSOAPMappingRegistry(smr);
- call.setTargetObjectURI(id);
- call.setMethodName("getAddressFromName");
- call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
- Vector params = new Vector();
- params.addElement(new Parameter("name", String.class, name, null));
- call.setParams(params);
- if (userName != null) {
- SOAPHTTPConnection shc = new SOAPHTTPConnection ();
- shc.setUserName (userName);
- shc.setPassword (password);
- call.setSOAPTransport (shc);
- }
-
- Response resp = call.invoke(url, actionURI);
-
- // Check the response.
- if (resp.generatedFault ()) {
- Fault fault = resp.getFault ();
- System.out.println ("Ouch, the call failed: " + fault);
- } else {
- Parameter result = resp.getReturnValue ();
- System.out.println (result.getValue ());
- }
- }
- }
-