Changeset 709306c for axis/Create.java


Ignore:
Timestamp:
Mar 31, 2011 11:01:51 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
1294d29
Parents:
9f8dbc1
Message:

Commented and working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • axis/Create.java

    r9f8dbc1 r709306c  
     1// Java I/O
     2import java.io.*;
     3
     4// The WSDL generated types for messages and components of messages.
    15import edu.isi.www.fedd_types.*;
    26import edu.isi.www.fedd_wsdl.*;
    3 import java.net.URL;
    4 import net.deterlab.isi.XTrustProvider;
    5 import java.io.*;
    6 import java.util.*;
    77
     8// The fault thrown by failed commands
    89import org.apache.axis.AxisFault;
    910
    10 import javax.net.*;
    11 import javax.net.ssl.*;
     11// The ABAC commands throw this
    1212import java.security.GeneralSecurityException;
    1313
     14// ABAC classes.  http://abac.deterlab.net
    1415import net.deterlab.abac.*;
    1516
    1617class Create extends FeddCommand {
    1718
     19    /**
     20     * Read a file into a byte array; used to load the topology file.
     21     * @param f the File to read
     22     * @throws IOException if there is an error reading the file.
     23     */
    1824    static public byte[] readNsFile(File f) throws IOException {
     25        // This is tedious but straightforward
    1926        final int bsize = 4096;
    2027        byte[] buf = new byte[bsize];
     
    3340    }
    3441
     42    /**
     43     * Create an ABAC credential indicating the the given destination acts for
     44     * the given Identity, and attach a certificate to it.
     45     * @param id the Identity delegating authority
     46     * @param dest the destination
     47     * @throws IOException an I/O problem, very unlikely
     48     * @throws GeneralSecurityException crypto or identity misconfiguration.
     49     */
    3550    static public Credential delegate(Identity id, String dest)
    3651            throws IOException,GeneralSecurityException {
     
    4257
    4358    /**
    44      * Dummy program to test an AXIS fedd implementation generated from the
    45      * WSDL and run by axis.
    46      * It just calls terminate with a dummy id as a local name (which can be
    47      * supplied on the command line and reprints the localname that the server
    48      * replies with.  A client certificate muct exist in the local keystore
    49      * file with the given password.
     59     * Create an experiment with the given mnemonic name, from the given tcl
     60     * topology file using the given identity certificate, on the given fedd.
     61     * Reads the identity and topology into memory and constructs a New request
     62     * for an empty experiment and a Create request to actually start it.  The
     63     * start is asynchronous, so this returns when the creation begins, not
     64     * when it completes.
    5065     */
    5166    public static void main(String args[]) throws
    5267            javax.xml.rpc.ServiceException, java.net.MalformedURLException,
    5368            java.rmi.RemoteException {
     69
     70        // Parse out the args
     71        String exptName = "test";
     72        String tclFile = "./deter-only.tcl";
     73        String certFile = "./emulab.pem";
     74        String urlString = "https://users.isi.deterlab.net:23235";
     75
     76        if (args.length > 0) exptName = args[0];
     77        if (args.length > 1) tclFile = args[1];
     78        if (args.length > 2) certFile = args[2];
     79        if (args.length > 3) urlString = args[3];
    5480       
    5581        /*
    56          * Boilerplate web services access stuff.
     82         * Get the Web Service for users and read the identity and topology
    5783         */
    58         FeddPortType port = getPort("https://users.isi.deterlab.net:23235");
     84        FeddPortType port = getPort(urlString);
    5985        Identity AbacID = null;
    6086        byte[] nsContents = null;
    6187        try {
    6288            nsContents = readNsFile(new File(args[1]));
     89            AbacID = new Identity(new File("./emulab.pem"));
     90        }
     91        catch (GeneralSecurityException e) {
     92            System.err.println("Error reading ABAC identity " + e);
     93            System.exit(20);
    6394        }
    6495        catch (IOException e) {
    65             System.err.println("Cannot read " + args[1] + ": " + e);
     96            System.err.println("Cannot load file " + e);
    6697            System.exit(20);
    6798        }
    6899
    69100        /*
    70          * The various parts of the MultiInfo message and response
     101         * Build and send a NewRequestType Message
    71102         */
    72103
    73104        NewRequestType newReq = new NewRequestType(null,
    74                 new IDType(null, null, null, args[0], null),
     105                new IDType(null, null, null, exptName, null),
    75106                null);
    76107        NewResponseType newResp = null;
    77 
    78 
    79108        try {
    80             // Build the message and make the call
    81109            newResp = port._new(newReq);
    82110        }
    83         catch (Exception f) {
     111        catch (AxisFault f) {
    84112            System.err.println("Error in New: " + f);
    85113            System.exit(20);
    86114        }
     115
     116        // Parse out the name of the new empty experiment, and start building
     117        // the CreateRequestType message.
    87118        ExperimentLabels newLabels =
    88119            new ExperimentLabels(newResp.getExperimentID());
    89         System.out.println("New success: " + newLabels.getLocalname() + "(" +
    90             newLabels.getFedid() + ")");
    91120
    92121        CreateRequestType createReq = new CreateRequestType(null,
    93122                new ExperimentDescriptionType(nsContents, null),
    94123                null,
    95                 //new IDType(null, null, null, newLabels.getLocalname(), null),
    96                 new IDType(null, null, null, args[0], null),
     124                new IDType(null, null, null, newLabels.getLocalname(), null),
    97125                null);
    98126        CreateResponseType createResp = null;
     127
     128        // Reloading the port clears cached SSL connections.
    99129        port = getPort("https://users.isi.deterlab.net:23235");
    100130
    101         Credential c = null;
    102         byte[][] ca = new byte[1][];
     131        // This block creates an ABAC credential telling the fedd that the
     132        // experiment we brought to life with the New call above can act with
     133        // our authority.  We could keep the certificate around for other
     134        // commands to use, but once we tell fedd about it, fedd remembers it.
    103135        try {
    104             AbacID = new Identity(new File("./emulab.pem"));
     136            Credential c = null;
     137            byte[][] ca = new byte[1][];
     138
    105139            c = delegate(AbacID, newLabels.getFedid());
    106140            ca[0] = c.cert().getEncoded();
    107141            createReq.setCredential(ca);
    108             System.err.println(AbacID);
    109             System.err.println(c);
    110142        }
    111         catch (GeneralSecurityException e) { System.err.println(e); }
    112         catch (IOException e) { System.err.println("IOException?!!" +e); }
     143        catch (GeneralSecurityException e) {
     144            System.err.println("Failed to delegate authority: " + e);
     145            System.exit(20);
     146        }
     147        catch (IOException e) {
     148            System.err.println("Failed to delegate authority: ?!!" +e);
     149            System.exit(20);
     150        }
    113151
     152        // The create call
    114153        try {
    115             /* Build the message and make the call */
    116154            createResp = port.create(createReq);
    117155        }
    118156        catch (AxisFault f) {
    119             System.err.println(f.getClass().getName());
    120             System.err.println("AxisFault Error in Create: " + f);
    121             System.exit(20);
    122         }
    123         catch (Exception f) {
    124             System.err.println(f.getClass().getName());
    125157            System.err.println("Error in Create: " + f);
    126158            System.exit(20);
    127159        }
     160
     161        // Tell the user we're underway
    128162        ExperimentLabels createLabels =
    129163            new ExperimentLabels(createResp.getExperimentID());
    130         System.out.println("New success: " + createLabels.getLocalname()
    131                 + "(" + createLabels.getFedid() + ") "
     164        System.out.println("Success: " + createLabels.getLocalname()
     165                + " (" + createLabels.getFedid() + ") "
    132166                + createResp.getExperimentStatus().getValue());
    133167    }
Note: See TracChangeset for help on using the changeset viewer.