1/*2 * Copyright 2013 The Apache Software Foundation.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package org.apache.juddi.v3.migration.tool;
1718import java.util.Random;
19import org.apache.commons.cli.BasicParser;
20import org.apache.commons.cli.CommandLine;
21import org.apache.commons.cli.CommandLineParser;
22import org.apache.commons.cli.HelpFormatter;
23import org.apache.commons.cli.Options;
24import org.apache.commons.cli.ParseException;
2526/**27 * Main entry point for the UDDI migration tool28 *29 * @author Alex O'Ree30 * @since 3.231 *32 */33publicclassApp {
3435publicstaticvoid main(String[] args) throws ParseException, Exception {
36 System.out.println("This tool is used to export and import UDDI data from a UDDI v3 registry");
37 System.out.println("Random TIP: " + RandomTip());
38 System.out.println();
3940 Options options = new Options();
41 options.addOption("import", false, "Imports data into a UDDIv3 registry");
42 options.addOption("export", false, "Exports data into a UDDIv3 registry");
43 options.addOption("user", true, "Username, if not defined, those is uddi.xml will be used");
44 options.addOption("pass", true, "Password, if not defined, those is uddi.xml will be used");
45//options.addOption("safeMode", false, "Prevents overriding existing entities, saves items one at a time");46 options.addOption("config", true, "Use an alternate config file default is 'uddi.xml'");
47 options.addOption("node", true, "The node 'name' in the config, default is 'default'");
48 options.addOption("isJuddi", false, "Is this a jUDDI registry? If so we can in/export more stuff");
49 options.addOption("tmodel", true, "Im/Export for tmodels, file to store tmodel data, default is 'tmodel-export.xml'");
50 options.addOption("business", true, "Im/Export option, file to store the business data, default is 'business-export.xml'");
51 options.addOption("mappings", true, "Im/Export option, file that maps keys to owners, default is 'entityusermappings.properties'");
52 options.addOption("publishers", true, "jUDDI only - In/Export option, file to store publishers, default is 'publishers-export.xml'");
53 options.addOption("myItemsOnly", false, "Export option, Only export items owned by yourself");
54 options.addOption("preserveOwnership", false, "Im/Export option, saves owership data to the 'mappings' file");
55 options.addOption("credFile", true, "Import option with -preserveOwnership, this is a properties file mapping with user=pass");
56 options.addOption("stripSignatures", false, "Im/Export option, removes digital signatures from all signed items, default is false");
575859// create the parser60 CommandLineParser parser = new BasicParser();
61 CommandLine line = null;
62try {
63// parse the command line arguments64 line = parser.parse(options, args);
6566if (line.hasOption("import") && line.hasOption("export")) {
67 ShowHelp(options);
68return;
69 }
70if (!line.hasOption("import") && !line.hasOption("export")) {
71 ShowHelp(options);
72return;
73 }
74 String config = line.getOptionValue("config", "uddi.xml");
75boolean stripSig = line.hasOption("stripSignatures");
76 String node = line.getOptionValue("node", "default");
7778 String pass = line.getOptionValue("pass", null);
79 String user = line.getOptionValue("user", null);
8081 String tmodel = line.getOptionValue("tmodel", "tmodel-export.xml");
82 String business = line.getOptionValue("business", "business-export.xml");
83 String publishers = line.getOptionValue("publishers", "publishers-export.xml");
84//username to password85 String credFile = line.getOptionValue("credFile", "credentials.properties");
86//key to username87 String mappings = line.getOptionValue("mappings", "entityusermappings.properties");
88boolean preserveOwnership = line.hasOption("preserveOwnership");
89boolean juddi = line.hasOption("isJuddi");
90boolean myItemsOnly = line.hasOption("myItemsOnly");
91boolean safe = true;//line.hasOption("safeMode");92if (line.hasOption("export")) //CommandLine cmd = parser.parse(options, args);93 {
94 System.out.println("Exporting...");
95newExport().Execute(config, node, user, pass, tmodel, business, juddi, safe, publishers, myItemsOnly, mappings, preserveOwnership, credFile,stripSig);
96 System.out.println();
97if (preserveOwnership) {
98 System.out.println("Next step(s), Edit the " + credFile + " and make any adjustments that are necessary.");
99 System.out.println("TIP: if you're using juddi, you can temporarily switch to the 'JuddiAuthenticator' which doesn't validate passwords.");
100 }
101 System.out.println("Next step(s), Edit " + config + " to point to the next registry. Then try -import. You can also specify a different node.");
102 }
103if (line.hasOption("import")) //CommandLine cmd = parser.parse(options, args);104 {
105 System.out.println("Importing...");
106newImport().Execute(config, node, user, pass, tmodel, business, juddi, safe, publishers, preserveOwnership, mappings, credFile,stripSig);
107 }
108109110 } catch (Exception exp) {
111// oops, something went wrong112 ShowHelp(options);
113 System.err.println("Failed!");
114 exp.printStackTrace();
115 }
116117118 }
119120privatestaticvoid ShowHelp(Options options) {
121 HelpFormatter formatter = new HelpFormatter();
122 formatter.printHelp("java -jar juddi-migration-tool-(VERSION)-jar-with-dependencies.jar", options);
123 }
124125privatestatic String RandomTip() {
126 String[] tips = new String[]{
127"You can use setup custom SSL trust/key stores using -Djavax.net.ssl.keyStore=file -javax.net.ssl.keyStorePassword=pwd -Djavax.net.ssl.trustStore=file "128 + "-Djavax.net.ssl.trustStorePassword=pwd",
129"You can easily script the UDDI migration tool and use it as a backup mechanism.",
130"You can protect credentials by storing them in uddi client config file.",
131"This tool can only work with UDDI v3 registries.",
132"With the preserveOwnership flag, you can maintain entity ownership.",
133"Without the preserveOwnership flag, all imported data will be owned by the username that imported it."134 };
135 Random r = new Random();
136return tips[r.nextInt(tips.length)];
137 }
138 }