code: public void tryLogin(String protocol,
                           String host,
                           int port,
                           String context,
                           String user,
                           String pass) throws Exception {
  
          try {
              logger.info("Logging in...");
              // get a FedoraClient
              String baseURL = protocol + "://" + host + ":" + port + "/" + context;
              FedoraClient fc = new FedoraClient(baseURL, user, pass);
  
              // attempt to connect via REST
              String serverVersion = fc.getServerVersion();
  
              // ensure client is compatible with server, warn if not
              List<String> compatibleVersions =
                      FedoraClient.getCompatibleServerVersions();
              if (!compatibleVersions.contains(serverVersion)) {
                  StringBuffer endText = new StringBuffer();
                  if (compatibleVersions.size() == 1) {
                      // version A
                      endText.append("version " + compatibleVersions.get(0));
                  } else {
                      // versions A and B
                      // versions A, B, and C
                      endText.append("versions ");
                      for (int i = 0; i < compatibleVersions.size(); i++) {
                          if (i > 0) {
                              if (i == compatibleVersions.size() - 1) {
                                  if (i > 1) {
                                      endText.append(",");
                                  }
                                  endText.append(" and ");
                              } else {
                                  endText.append(", ");
                              }
                          }
                          endText.append(compatibleVersions.get(i));
                      }
                  }
                  System.err.println("WARNING: Server version is "
                          + serverVersion + ".  This client is "
                          + "only designed to work with " + endText.toString());
              }
  
              // set SOAP stubs for Administrator
              Administrator.APIA = fc.getAPIAMTOM();
              Administrator.APIM = fc.getAPIMMTOM();
  
          } catch (Exception e) {
              if (e.getMessage().indexOf("Unauthorized") != -1
                      || e.getMessage().indexOf("Unrecognized") != -1) {
                  throw new IOException("Bad username or password.");
              } else {
                  if (e.getMessage() != null) {
                      throw new IOException(e.getClass().getName() + ": "
                              + e.getMessage());
                  } else {
                      throw new IOException(e.getClass().getName());
                  }
              }
          }
      }
docs: sets Administrator.APIA/M if success, throws Exception if fails.