View Javadoc

1   /*
2    * AbstractWebCommand.java
3    *
4    * Created on November 4, 2004, 10:07 AM
5    */
6   package gov.bnl.gums.admin;
7   
8   
9   import gov.bnl.gums.command.AbstractCommand;
10  import gov.bnl.gums.command.Configuration;
11  import java.util.Iterator;
12  import org.apache.axis.AxisFault;
13  import org.apache.axis.client.Stub;
14  
15  import org.apache.commons.cli.*;
16  import org.apache.commons.logging.Log;
17  import org.apache.commons.logging.LogFactory;
18  
19  import java.net.ConnectException;
20  import java.net.URL;
21  
22  import java.util.logging.Logger;
23  
24  /**
25   * @author carcassi
26   */
27  public abstract class RemoteCommand extends AbstractCommand {
28      private Log log = LogFactory.getLog(RemoteCommand.class);
29  
30      private GUMSAPI clientStub;
31  
32      protected GUMSAPI getGums(String gumsUrlStr) {
33          log.trace("Retrieving GUMS stub");
34          if (clientStub != null) return clientStub;        
35          try {
36              GUMSAPIService service = new GUMSAPIServiceLocator();
37              if (Configuration.getInstance().isDirect()) {
38                  log.info("Accessing direct implementation.");
39                  return new GUMSAPIImpl();
40              } else {
41              	URL gumsUrl = gumsUrlStr!=null ? new URL(gumsUrlStr) : Configuration.getInstance().getGUMSLocation();;
42  
43                  log.info("Accessing GUMS implementation at " + gumsUrl + ".");
44                  clientStub = service.getadmin(gumsUrl);
45                  Stub axisStub = (Stub) clientStub;
46                  axisStub.setMaintainSession(true);
47                  Iterator iter = axisStub._getPropertyNames();
48                  while (iter.hasNext()) {
49                      String name = (String) iter.next();
50                      log.trace("Client stub property '" + name + "' value '" + axisStub._getProperty(name));
51                  }
52                  return clientStub;
53              }
54          } catch (Exception e) {
55              System.out.println("Couldn't initialize GUMS client:" + e.getMessage());
56              log.fatal("Couldn't initialize GUMS client", e);
57              System.exit(-1);
58  
59              return null;
60          }
61      }
62      
63      protected GUMSAPI getGums() {
64      	return getGums(null);
65      }
66  }