home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wsgatsam.zip / GetDayOfTheWeek.java < prev    next >
Encoding:
Java Source  |  2003-02-24  |  2.3 KB  |  89 lines

  1. /**
  2.  * %wsgw_sample_start%
  3.  * Licensed Materials - Property of IBM  
  4.  *    
  5.  * (c) Copyright IBM Corp. 2001, 2002 All Rights Reserved.  
  6.  *    
  7.  * US Government Users Restricted Rights - Use, duplication or   
  8.  * disclosure restricted by GSA ADP Schedule Contract with   
  9.  * IBM Corp.  
  10.  * %wsgw_sample_end%
  11.  */
  12.  
  13. package services.calendar;
  14.                        
  15. import java.io.*;
  16. import java.net.*;
  17. import java.util.*;
  18. import org.apache.soap.*;
  19. import org.apache.soap.rpc.*;
  20. import org.apache.soap.transport.*;
  21. import org.apache.soap.transport.http.*;
  22.  
  23. /**
  24.  * See README for info.
  25.  *
  26.  * @author William A. Nagy (nagy@watson.ibm.com)
  27.  */
  28. public class GetDayOfTheWeek
  29. {
  30.   public static void main (String[] args)
  31.     throws Exception
  32.   {
  33.     if ((args.length != 6) && (args.length != 8))
  34.     {
  35.       System.err.println ("Usage: java " + GetDayOfTheWeek.class.getName () +
  36.                           " SOAP-router-URL method-namespace-uri" +
  37.                           " action-uri month date year [username password]");
  38.       System.exit (1);
  39.     }
  40.  
  41.     URL url = new URL(args[0]);
  42.     String id = args[1];
  43.     String actionURI = args[2];
  44.     Integer month = new Integer(args[3]);
  45.     Integer date = new Integer(args[4]);
  46.     Integer year = new Integer(args[5]);
  47.     String userName = null;
  48.     String password = null;
  49.     if (args.length == 8)
  50.     {
  51.       userName = args[6];
  52.       password = args[7];
  53.     }
  54.     
  55.     /*Build the call.*/
  56.     Call call = new Call();
  57.     call.setTargetObjectURI(id);
  58.     call.setMethodName("dayOfTheWeekOp");
  59.     call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
  60.     Vector params = new Vector();
  61.     params.addElement(new Parameter("month", int.class, month, null));
  62.     params.addElement(new Parameter("date", int.class, date, null));
  63.     params.addElement(new Parameter("year", int.class, year, null));
  64.     call.setParams(params);
  65.  
  66.     if (userName != null)
  67.     {
  68.       SOAPHTTPConnection shc = new SOAPHTTPConnection();
  69.       shc.setUserName(userName);
  70.       shc.setPassword(password);
  71.       call.setSOAPTransport(shc);
  72.     }
  73.  
  74.     Response resp = call.invoke(url, actionURI);
  75.  
  76.     // Check the response.
  77.     if (resp.generatedFault())
  78.     {
  79.       Fault fault = resp.getFault();
  80.       System.out.println ("Ouch, the call failed: " + fault);
  81.     }
  82.     else
  83.     {
  84.       Parameter result = resp.getReturnValue();
  85.       System.out.println(result.getValue());
  86.     }
  87.   }
  88. }
  89.