// WSDL generated types and port import edu.isi.www.fedd_types.*; import edu.isi.www.fedd_wsdl.*; // The usual suspects import java.net.*; import java.util.*; // The Fedid and XTrustManager classes import net.deterlab.isi.*; // SSL manipulations and a couple Exceptions import javax.net.ssl.*; import javax.xml.rpc.*; /** * Base class that all the example programs are derived from. It holds * routines that several classes use, including some key routines to massage * java's security model closer to fedd's. */ public class FeddCommand { // SetUpSecurity is defined below. This is necessary stuff, and putting it // here guarantees that it's always called before main. static { setUpSecurity(); } /** * Parse out an experiment name from a return value. Several fedd * responses identify the experiment that was operated on (or created) by * both a human-readable name and a fedid. This class scans through the * array of IDTypes returned and keeps the fedid and localname (mnemonic * name) returned. */ static class ExperimentLabels { /** The fedid */ protected String fedid; /** The localname */ protected String localname; /** * Construct the class - i.e., parse the array * @param experimentID an array of IDTypes holding the synonymous names */ public ExperimentLabels(IDType[] experimentID) { fedid = null; localname = null; for (IDType id: experimentID) { if (id.getLocalname() != null) localname = id.getLocalname(); if (id.getFedid() != null) { byte[] rawFedid = id.getFedid(); if (rawFedid != null) { Fedid f = new Fedid(rawFedid); if ( f != null) fedid = f.toString().substring(6); } } } } /** * Return the fedid * @return the fedid */ String getFedid() { return fedid; } /** * Return the localname * @return the localname */ String getLocalname() { return localname; } } /** * This magic convinces the SSL routines to accept self-signed certificates * from the server (fedd) and points the SSL routines at the local * keystore. Other applications may move the keystore assignment, but the * XTrustProvider call is always necessary. */ public static void setUpSecurity() { /* This magic turns off certificate chain checking. */ XTrustProvider.install(); /* This tells the SSL system where to find client certificate * information. */ String keyStore = "./keystore"; String keyStorePassword = "importkey"; System.setProperty("javax.net.ssl.keyStore", keyStore); System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword); } /** * Clear the SSL session cache. Java aggressively reuses SSL sessions, and * it confuses fedd greatly - connections drop. This routine invalidates * all the existing sessions. Necessary when you will make more than one * call. This is also called by getPort, so getting a new port before each * new call will also atomize the sessions. */ static public void clearSSLSessionCache() { try { SSLContext sctxt = SSLContext.getDefault(); SSLSessionContext ssctxt = sctxt.getClientSessionContext(); Enumeration e = ssctxt.getIds(); while (e.hasMoreElements()) { SSLSession s = ssctxt.getSession(e.nextElement()); s.invalidate(); } } catch (Exception e) { System.err.println(e); } } /** * Get a new FeddPortType on which requests can be made. The server to * contact is passed as a string. * @param server a String containing the server URL * @return a FeddPortType to talk to. * @throws ServiceException if the services/server can't be found * @throws MalformedURLException if the URL is bad */ public static FeddPortType getPort(String server) throws ServiceException, MalformedURLException { /* * Boilerplate web services access stuff. */ clearSSLSessionCache(); FeddServiceLocator service = new FeddServiceLocator(); FeddPortType port = service.getfeddPort(new URL(server)); return port; } }