Changeset 709306c for axis/Create.java
- Timestamp:
- Mar 31, 2011 11:01:51 PM (13 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master
- Children:
- 1294d29
- Parents:
- 9f8dbc1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
axis/Create.java
r9f8dbc1 r709306c 1 // Java I/O 2 import java.io.*; 3 4 // The WSDL generated types for messages and components of messages. 1 5 import edu.isi.www.fedd_types.*; 2 6 import edu.isi.www.fedd_wsdl.*; 3 import java.net.URL;4 import net.deterlab.isi.XTrustProvider;5 import java.io.*;6 import java.util.*;7 7 8 // The fault thrown by failed commands 8 9 import org.apache.axis.AxisFault; 9 10 10 import javax.net.*; 11 import javax.net.ssl.*; 11 // The ABAC commands throw this 12 12 import java.security.GeneralSecurityException; 13 13 14 // ABAC classes. http://abac.deterlab.net 14 15 import net.deterlab.abac.*; 15 16 16 17 class Create extends FeddCommand { 17 18 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 */ 18 24 static public byte[] readNsFile(File f) throws IOException { 25 // This is tedious but straightforward 19 26 final int bsize = 4096; 20 27 byte[] buf = new byte[bsize]; … … 33 40 } 34 41 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 */ 35 50 static public Credential delegate(Identity id, String dest) 36 51 throws IOException,GeneralSecurityException { … … 42 57 43 58 /** 44 * Dummy program to test an AXIS fedd implementation generated from the45 * WSDL and run by axis.46 * It just calls terminate with a dummy id as a local name (which can be47 * supplied on the command line and reprints the localname that the server48 * replies with. A client certificate muct exist in the local keystore49 * 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. 50 65 */ 51 66 public static void main(String args[]) throws 52 67 javax.xml.rpc.ServiceException, java.net.MalformedURLException, 53 68 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]; 54 80 55 81 /* 56 * Boilerplate web services access stuff.82 * Get the Web Service for users and read the identity and topology 57 83 */ 58 FeddPortType port = getPort( "https://users.isi.deterlab.net:23235");84 FeddPortType port = getPort(urlString); 59 85 Identity AbacID = null; 60 86 byte[] nsContents = null; 61 87 try { 62 88 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); 63 94 } 64 95 catch (IOException e) { 65 System.err.println("Cannot read " + args[1] + ":" + e);96 System.err.println("Cannot load file " + e); 66 97 System.exit(20); 67 98 } 68 99 69 100 /* 70 * The various parts of the MultiInfo message and response101 * Build and send a NewRequestType Message 71 102 */ 72 103 73 104 NewRequestType newReq = new NewRequestType(null, 74 new IDType(null, null, null, args[0], null),105 new IDType(null, null, null, exptName, null), 75 106 null); 76 107 NewResponseType newResp = null; 77 78 79 108 try { 80 // Build the message and make the call81 109 newResp = port._new(newReq); 82 110 } 83 catch ( Exceptionf) {111 catch (AxisFault f) { 84 112 System.err.println("Error in New: " + f); 85 113 System.exit(20); 86 114 } 115 116 // Parse out the name of the new empty experiment, and start building 117 // the CreateRequestType message. 87 118 ExperimentLabels newLabels = 88 119 new ExperimentLabels(newResp.getExperimentID()); 89 System.out.println("New success: " + newLabels.getLocalname() + "(" +90 newLabels.getFedid() + ")");91 120 92 121 CreateRequestType createReq = new CreateRequestType(null, 93 122 new ExperimentDescriptionType(nsContents, null), 94 123 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), 97 125 null); 98 126 CreateResponseType createResp = null; 127 128 // Reloading the port clears cached SSL connections. 99 129 port = getPort("https://users.isi.deterlab.net:23235"); 100 130 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. 103 135 try { 104 AbacID = new Identity(new File("./emulab.pem")); 136 Credential c = null; 137 byte[][] ca = new byte[1][]; 138 105 139 c = delegate(AbacID, newLabels.getFedid()); 106 140 ca[0] = c.cert().getEncoded(); 107 141 createReq.setCredential(ca); 108 System.err.println(AbacID);109 System.err.println(c);110 142 } 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 } 113 151 152 // The create call 114 153 try { 115 /* Build the message and make the call */116 154 createResp = port.create(createReq); 117 155 } 118 156 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());125 157 System.err.println("Error in Create: " + f); 126 158 System.exit(20); 127 159 } 160 161 // Tell the user we're underway 128 162 ExperimentLabels createLabels = 129 163 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() + ") " 132 166 + createResp.getExperimentStatus().getValue()); 133 167 }
Note: See TracChangeset
for help on using the changeset viewer.