List of usage examples for java.lang Exception getMessage
public String getMessage()
From source file:com.manning.blogapps.chapter11.PlanetTool.java
public static void main(String[] args) { String success = "Planet complete!"; String error = null;/*from w w w . ja v a 2 s . c om*/ Exception traceWorthy = null; String fileName = "planet-config.xml"; if (args.length == 1) { fileName = args[0]; } try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new FileInputStream(fileName)); PlanetTool planet = new PlanetTool(doc); planet.refreshEntries(); planet.generatePlanet(); System.out.println(success); System.exit(0); } catch (FileNotFoundException fnfe) { error = "Configuration file [" + fileName + "] not found"; } catch (JDOMException jde) { error = "Error parsing configuration file [" + fileName + "]"; traceWorthy = jde; } catch (IOException ioe) { error = "IO error. Using configuration file [" + fileName + "]"; traceWorthy = ioe; } catch (Exception re) { error = re.getMessage(); } if (error != null) { System.out.println(error); if (traceWorthy != null) traceWorthy.printStackTrace(); System.exit(-1); } }
From source file:ldbc.snb.datagen.generator.LDBCDatagen.java
public static void main(String[] args) throws Exception { try {/*from ww w .java2 s. c o m*/ Configuration conf = ConfigParser.initialize(); ConfigParser.readConfig(conf, args[0]); ConfigParser.readConfig(conf, LDBCDatagen.class.getResourceAsStream("/params.ini")); LDBCDatagen.prepareConfiguration(conf); LDBCDatagen.initializeContext(conf); LDBCDatagen datagen = new LDBCDatagen(); datagen.runGenerateJob(conf); } catch (Exception e) { System.err.println("Error during execution"); System.err.println(e.getMessage()); e.printStackTrace(); throw e; } }
From source file:de.codecentric.elasticsearch.plugin.kerberosrealm.support.EmbeddedKRBServer.java
public static void main(final String[] args) throws Exception { final File workDir = new File("."); final EmbeddedKRBServer eks = new EmbeddedKRBServer(); eks.realm = "DUMMY.COM"; eks.start(workDir);//w w w. ja va 2 s. c o m eks.getSimpleKdcServer().createPrincipal("kirk/admin@DUMMY.COM", "kirkpwd"); eks.getSimpleKdcServer().createPrincipal("uhura@DUMMY.COM", "uhurapwd"); eks.getSimpleKdcServer().createPrincipal("service/1@DUMMY.COM", "service1pwd"); eks.getSimpleKdcServer().createPrincipal("service/2@DUMMY.COM", "service2pwd"); eks.getSimpleKdcServer().exportPrincipal("service/1@DUMMY.COM", new File(workDir, "service1.keytab")); //server, acceptor eks.getSimpleKdcServer().exportPrincipal("service/2@DUMMY.COM", new File(workDir, "service2.keytab")); //server, acceptor eks.getSimpleKdcServer().createPrincipal("HTTP/localhost@DUMMY.COM", "httplocpwd"); eks.getSimpleKdcServer().exportPrincipal("HTTP/localhost@DUMMY.COM", new File(workDir, "httploc.keytab")); //server, acceptor eks.getSimpleKdcServer().createPrincipal("HTTP/localhost@DUMMY.COM", "httpcpwd"); eks.getSimpleKdcServer().exportPrincipal("HTTP/localhost@DUMMY.COM", new File(workDir, "http.keytab")); //server, acceptor final TgtTicket tgt = eks.getSimpleKdcServer().getKrbClient().requestTgtWithPassword("kirk/admin@DUMMY.COM", "kirkpwd"); eks.getSimpleKdcServer().getKrbClient().storeTicket(tgt, new File(workDir, "kirk.cc")); try { try { FileUtils.copyFile(new File("/etc/krb5.conf"), new File("/etc/krb5.conf.bak")); } catch (final Exception e) { //ignore } FileUtils.copyFileToDirectory(new File(workDir, "krb5.conf"), new File("/etc/")); System.out.println("Generated krb5.conf copied to /etc"); } catch (final Exception e) { System.out.println("Unable to copy generated krb5.conf to /etc die to " + e.getMessage()); } }
From source file:de.prozesskraft.pkraft.Createmap.java
public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException { // try// www. ja va 2 s . c om // { // if (args.length != 3) // { // System.out.println("Please specify processdefinition file (xml) and an outputfilename"); // } // // } // catch (ArrayIndexOutOfBoundsException e) // { // System.out.println("***ArrayIndexOutOfBoundsException: Please specify processdefinition.xml, openoffice_template.od*, newfile_for_processdefinitions.odt\n" + e.toString()); // } /*---------------------------- get options from ini-file ----------------------------*/ File inifile = new java.io.File( WhereAmI.getInstallDirectoryAbsolutePath(Createmap.class) + "/" + "../etc/pkraft-createmap.ini"); if (inifile.exists()) { try { ini = new Ini(inifile); } catch (InvalidFileFormatException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { System.err.println("ini file does not exist: " + inifile.getAbsolutePath()); System.exit(1); } /*---------------------------- create boolean options ----------------------------*/ Option ohelp = new Option("help", "print this message"); /*---------------------------- create argument options ----------------------------*/ Option ooutput = OptionBuilder.withArgName("FILE").hasArg() .withDescription("[mandatory; default: process.dot] file for generated map.") // .isRequired() .create("output"); Option odefinition = OptionBuilder.withArgName("FILE").hasArg() .withDescription("[mandatory] process definition file.") // .isRequired() .create("definition"); /*---------------------------- create options object ----------------------------*/ Options options = new Options(); options.addOption(ohelp); options.addOption(ooutput); options.addOption(odefinition); /*---------------------------- create the parser ----------------------------*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments commandline = parser.parse(options, args); } catch (Exception exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); exiter(); } /*---------------------------- usage/help ----------------------------*/ if (commandline.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("createmap", options); System.out.println(""); System.out.println("author: " + author + " | version: " + version + " | date: " + date); System.exit(0); } /*---------------------------- ueberpruefen ob eine schlechte kombination von parametern angegeben wurde ----------------------------*/ if (!(commandline.hasOption("definition"))) { System.err.println("option -definition is mandatory."); exiter(); } if (!(commandline.hasOption("output"))) { System.err.println("option -output is mandatory."); exiter(); } /*---------------------------- die lizenz ueberpruefen und ggf abbrechen ----------------------------*/ // check for valid license ArrayList<String> allPortAtHost = new ArrayList<String>(); allPortAtHost.add(ini.get("license-server", "license-server-1")); allPortAtHost.add(ini.get("license-server", "license-server-2")); allPortAtHost.add(ini.get("license-server", "license-server-3")); MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1"); // lizenz-logging ausgeben for (String actLine : (ArrayList<String>) lic.getLog()) { System.err.println(actLine); } // abbruch, wenn lizenz nicht valide if (!lic.isValid()) { System.exit(1); } /*---------------------------- die eigentliche business logic ----------------------------*/ Process p1 = new Process(); java.io.File output = new java.io.File(commandline.getOptionValue("output")); if (output.exists()) { System.err.println("warn: already exists: " + output.getCanonicalPath()); exiter(); } p1.setInfilexml(commandline.getOptionValue("definition")); System.err.println("info: reading process definition " + commandline.getOptionValue("definition")); // dummy process Process p2 = null; try { p2 = p1.readXml(); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); System.err.println("error"); exiter(); } // den wrapper process generieren ArrayList<String> dot = p2.getProcessAsDotGraph(); // dot file rausschreiben writeFile.writeFile(output, dot); }
From source file:com.obidea.semantika.cli.Main.java
public static void main(String[] args) { @SuppressWarnings("unchecked") List<Logger> loggers = Collections.list(LogManager.getCurrentLoggers()); loggers.add(LogManager.getRootLogger()); normal(loggers);// w w w. j ava2s . c o m try { CommandLineParser parser = new GnuParser(); CommandLine optionLine = parser.parse(sOptions, args); if (optionLine.hasOption(Environment.VERSION)) { printVersion(); System.exit(0); } if (optionLine.hasOption(Environment.HELP)) { printUsage(); System.exit(0); } String operation = determineOperation(args); if (StringUtils.isEmpty(operation)) { printUsage(); } else { setupLoggers(optionLine, loggers); executeOperation(operation, optionLine); } } catch (Exception e) { System.err.println("Unexpected exception:" + e.getMessage()); //$NON-NLS-1$ System.exit(1); } }
From source file:net.modelbased.proasense.storage.reader.StorageReaderScrapRateTestClient.java
public static void main(String[] args) { // Get client properties from properties file // StorageReaderMongoServiceTestClient client = new StorageReaderMongoServiceTestClient(); // client.loadClientProperties(); // Hardcoded client properties (simple test client) String STORAGE_READER_SERVICE_URL = "http://192.168.84.34:8080/storage-reader"; String QUERY_SIMPLE_SENSORID = "1000692"; String QUERY_SIMPLE_STARTTIME = "1387565891068"; String QUERY_SIMPLE_ENDTIME = "1387565996633"; String QUERY_SIMPLE_PROPERTYKEY = "value"; // Default HTTP client and common properties for requests HttpClient client = new DefaultHttpClient(); StringBuilder requestUrl = null; List<NameValuePair> params = null; String queryString = null;// w ww . ja v a2 s . co m // Default HTTP response and common properties for responses HttpResponse response = null; ResponseHandler<String> handler = null; int status = 0; String body = null; // Default query for simple events requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL); requestUrl.append("/query/simple/default"); params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_SENSORID)); params.add(new BasicNameValuePair("startTime", QUERY_SIMPLE_STARTTIME)); params.add(new BasicNameValuePair("endTime", QUERY_SIMPLE_ENDTIME)); queryString = URLEncodedUtils.format(params, "utf-8"); requestUrl.append("?"); requestUrl.append(queryString); try { HttpGet query11 = new HttpGet(requestUrl.toString()); query11.setHeader("Content-type", "application/json"); response = client.execute(query11); // Check status code status = response.getStatusLine().getStatusCode(); if (status != 200) { throw new RuntimeException("Failed! HTTP error code: " + status); } // Get body handler = new BasicResponseHandler(); body = handler.handleResponse(response); System.out.println("SIMPLE.DEFAULT: " + body); // The result is an array of simple events serialized as JSON using Apache Thrift. // The simple events can be deserialized into Java objects using Apache Thrift. ObjectMapper mapper = new ObjectMapper(); JsonNode nodeArray = mapper.readTree(body); for (JsonNode node : nodeArray) { byte[] bytes = node.toString().getBytes(); TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory()); SimpleEvent event = new SimpleEvent(); deserializer.deserialize(event, bytes); System.out.println(event.toString()); } } catch (Exception e) { System.out.println(e.getClass().getName() + ": " + e.getMessage()); } // Average query for simple events requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL); requestUrl.append("/query/simple/average"); params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_SENSORID)); params.add(new BasicNameValuePair("startTime", QUERY_SIMPLE_STARTTIME)); params.add(new BasicNameValuePair("endTime", QUERY_SIMPLE_ENDTIME)); params.add(new BasicNameValuePair("propertyKey", QUERY_SIMPLE_PROPERTYKEY)); queryString = URLEncodedUtils.format(params, "utf-8"); requestUrl.append("?"); requestUrl.append(queryString); try { HttpGet query12 = new HttpGet(requestUrl.toString()); query12.setHeader("Content-type", "application/json"); response = client.execute(query12); // Get status code status = response.getStatusLine().getStatusCode(); if (status == 200) { // Get body handler = new BasicResponseHandler(); body = handler.handleResponse(response); System.out.println("SIMPLE.AVERAGE: " + body); } else System.out.println("Error code: " + status); } catch (Exception e) { System.out.println(e.getClass().getName() + ": " + e.getMessage()); } // Maximum query for simple events requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL); requestUrl.append("/query/simple/maximum"); params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_SENSORID)); params.add(new BasicNameValuePair("startTime", QUERY_SIMPLE_STARTTIME)); params.add(new BasicNameValuePair("endTime", QUERY_SIMPLE_ENDTIME)); params.add(new BasicNameValuePair("propertyKey", QUERY_SIMPLE_PROPERTYKEY)); queryString = URLEncodedUtils.format(params, "utf-8"); requestUrl.append("?"); requestUrl.append(queryString); try { HttpGet query13 = new HttpGet(requestUrl.toString()); query13.setHeader("Content-type", "application/json"); response = client.execute(query13); // Get status code if (status == 200) { // Get body handler = new BasicResponseHandler(); body = handler.handleResponse(response); System.out.println("SIMPLE.MAXIMUM: " + body); } else System.out.println("Error code: " + status); } catch (Exception e) { System.out.println(e.getClass().getName() + ": " + e.getMessage()); } // Minimum query for simple events requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL); requestUrl.append("/query/simple/minimum"); params = new LinkedList<NameValuePair>(); params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_SENSORID)); params.add(new BasicNameValuePair("startTime", QUERY_SIMPLE_STARTTIME)); params.add(new BasicNameValuePair("endTime", QUERY_SIMPLE_ENDTIME)); params.add(new BasicNameValuePair("propertyKey", QUERY_SIMPLE_PROPERTYKEY)); queryString = URLEncodedUtils.format(params, "utf-8"); requestUrl.append("?"); requestUrl.append(queryString); try { HttpGet query14 = new HttpGet(requestUrl.toString()); query14.setHeader("Content-type", "application/json"); response = client.execute(query14); // Get status code if (status == 200) { // Get body handler = new BasicResponseHandler(); body = handler.handleResponse(response); System.out.println("SIMPLE.MINIMUM: " + body); } else System.out.println("Error code: " + status); } catch (Exception e) { System.out.println(e.getClass().getName() + ": " + e.getMessage()); } }
From source file:gov.nih.nci.caintegrator.application.download.carray23.CaArrayFileDownloader.java
/** * Application is called as: java CaArrayFileDownloader -u <url to carray> * -x <experiment>// w ww. java 2s .c om * * with optional arguments: * * -n <username> -p <password> -t <type> -e <extension> * * If -u is specified, then -p must also be specified * * Possible values for -t are "raw" or "derived" * * -e is the extension for the files. The default is "CEL" * * @param args * @throws ServerConnectionException * @throws ServerConnectionException */ public static void main(String[] args) { CaArrayFileDownloader importer = null; try { importer = new CaArrayFileDownloader(args[0], args[1], args[3]); } catch (Exception e) { reportError(e.getMessage(), null); e.printStackTrace(System.err); System.exit(1); } // try { // importer.downloadExperiment(); // } catch (ServerConnectionException e) { // System.exit(2); // } catch (IllegalArgumentException e) { // System.exit(3); // } catch (IOException e) { // System.exit(4); // } catch (LoginException e) { // System.exit(5); // } // System.exit(0); }
From source file:com.clustercontrol.util.KeyCheck.java
/** * ????????/*from ww w . j av a 2 s .c o m*/ * * @param args */ public static void main(String[] args) { PrivateKey privateKey = null; PublicKey publicKey = null; /// ??????? true /// ???????? false (?) boolean flag = false; if (flag) { try { // ? privateKey = getPrivateKey( "???????privateKey.txt??"); // ? publicKey = getPublicKey("???????"); // publicKey = getPublicKey(publicKeyStr); } catch (Exception e) { System.out.println("hoge" + e.getMessage()); } } else { KeyPairGenerator generator; try { generator = KeyPairGenerator.getInstance(ALGORITHM); SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); // ?? 1024 generator.initialize(1024, random); KeyPair keyPair = generator.generateKeyPair(); privateKey = keyPair.getPrivate(); publicKey = keyPair.getPublic(); } catch (NoSuchAlgorithmException ex) { System.out.println(ex.getMessage()); } } // // ? System.out.println("?"); System.out.println(byte2String(privateKey.getEncoded())); System.out.println("?"); System.out.println(byte2String(publicKey.getEncoded())); // ??????? String string = "20140701_nttdata"; byte[] src = string.getBytes(); System.out.println("??String"); System.out.println(string); System.out.println("??byte"); System.out.println(byte2String(src)); // ? try { String encStr = encrypt(string, privateKey); System.out.println("?"); System.out.println(encStr); // ? String decStr = decrypt(encStr, publicKey); System.out.println("?"); System.out.println(decStr); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:com.genentech.retrival.SDFExport.SDFExporter.java
public static void main(String[] args) throws ParseException, JDOMException, IOException { // create command line Options object Options options = new Options(); Option opt = new Option("sqlFile", true, "sql-xml file"); opt.setRequired(true);/*from www. j av a 2 s. c om*/ options.addOption(opt); opt = new Option("sqlName", true, "name of SQL element in xml file"); opt.setRequired(true); options.addOption(opt); opt = new Option("molSqlName", true, "name of SQL element in xml file returning molfile for first column in sqlName"); opt.setRequired(false); options.addOption(opt); opt = new Option("removeSalt", false, "remove any known salts from structure."); opt.setRequired(false); options.addOption(opt); opt = new Option("o", "out", true, "output file"); opt.setRequired(false); options.addOption(opt); opt = new Option("i", "in", true, "input file, tab separated, each line executes the query once. Use '.tab' to read from stdin"); opt.setRequired(false); options.addOption(opt); opt = new Option("newLineReplacement", true, "If given newlines in fields will be replaced by this string."); options.addOption(opt); opt = new Option("ignoreMismatches", false, "If not given each input must return at least one hit hits."); options.addOption(opt); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } String outFile = cmd.getOptionValue("o"); String inFile = cmd.getOptionValue("i"); String sqlFile = cmd.getOptionValue("sqlFile"); String sqlName = cmd.getOptionValue("sqlName"); String molSqlName = cmd.getOptionValue("molSqlName"); String newLineReplacement = cmd.getOptionValue("newLineReplacement"); boolean removeSalt = cmd.hasOption("removeSalt"); boolean ignoreMismatches = cmd.hasOption("ignoreMismatches"); SDFExporter exporter = null; try { exporter = new SDFExporter(sqlFile, sqlName, molSqlName, outFile, newLineReplacement, removeSalt, ignoreMismatches); } catch (Exception e) { e.printStackTrace(); System.err.println(); exitWithHelp(options); } args = cmd.getArgs(); if (inFile != null && args.length > 0) { System.err.println("inFile and arguments may not be mixed!\n"); exitWithHelp(options); } if (inFile == null) { if (exporter.getParamTypes().length != args.length) { System.err.printf("sql statement (%s) needs %d parameters but got only %d.\n", sqlName, exporter.getParamTypes().length, args.length); exitWithHelp(options); } exporter.export(args); } else { BufferedReader in; if (".tab".equalsIgnoreCase(inFile)) in = new BufferedReader(new InputStreamReader(System.in)); else in = new BufferedReader(new FileReader(inFile)); exporter.export(in); in.close(); } exporter.close(); }
From source file:com.threeglav.sh.bauk.main.StreamHorizonEngine.java
public static void main(final String[] args) throws Exception { printRuntimeInfo();/*from ww w . ja v a 2 s.co m*/ final long start = System.currentTimeMillis(); LOG.info("To run in test mode set system parameter {}=true", BaukEngineConfigurationConstants.IDEMPOTENT_FEED_PROCESSING_PARAM_NAME); Runtime.getRuntime().addShutdownHook(new ShutdownHook()); final BaukConfiguration conf = findConfiguration(); if (conf != null) { ConfigurationProperties.setBaukProperties(conf.getProperties()); final ConfigurationValidator configValidator = new ConfigurationValidator(conf); try { configValidator.validate(); } catch (final Exception exc) { BaukUtil.logEngineMessageSync("Error while validating configuration: " + exc.getMessage()); LOG.error("", exc); System.exit(-1); } remotingHandler = new RemotingServer(); remotingHandler.start(); createProcessingRoutes(conf); final boolean throughputTestingMode = ConfigurationProperties .getSystemProperty(BaukEngineConfigurationConstants.THROUGHPUT_TESTING_MODE_PARAM_NAME, false); if (throughputTestingMode) { BaukUtil.logEngineMessageSync( "ENGINE IS RUNNING IN THROUGHPUT TESTING MODE! ONE INPUT FEED FILE PER THREAD WILL BE CACHED AND PROCESSED REPEATEDLY!!!"); } instanceStartTime = System.currentTimeMillis(); final boolean isMultiInstance = ConfigurationProperties.isConfiguredPartitionedMultipleInstances(); if (isMultiInstance) { final int totalPartitionsCount = ConfigurationProperties.getSystemProperty( BaukEngineConfigurationConstants.MULTI_INSTANCE_PARTITION_COUNT_PARAM_NAME, -1); final String myUniqueIdentifier = ConfigurationProperties.getBaukInstanceIdentifier(); BaukUtil.logEngineMessageSync("Configured to run in multi-instance mode of " + totalPartitionsCount + " instances in total. My unique identifier is " + myUniqueIdentifier); } BaukUtil.logEngineMessageSync("Finished initialization! Started counting uptime"); startProcessing(); final long total = System.currentTimeMillis() - start; final long totalSec = total / 1000; final boolean detectBaukInstances = ConfigurationProperties .getSystemProperty(BaukEngineConfigurationConstants.DETECT_OTHER_BAUK_INSTANCES, false); if (detectBaukInstances) { final int numberOfInstances = HazelcastCacheInstanceManager.getNumberOfBaukInstances(); BaukUtil.logEngineMessage( "Total number of detected running engine instances is " + numberOfInstances); } BaukUtil.logEngineMessage("Engine started successfully in " + total + "ms (" + totalSec + " seconds). Waiting for feed files...\n\n"); } else { LOG.error( "Unable to find valid configuration file! Check your startup scripts and make sure system property {} points to valid feed configuration file. Aborting!", CONFIG_FILE_PROP_NAME); BaukUtil.logEngineMessage( "Unable to find valid configuration file! Check your startup scripts and make sure system property " + CONFIG_FILE_PROP_NAME + " points to valid feed configuration file. Aborting!"); System.exit(-1); } // sleep forever while (!BaukUtil.shutdownStarted()) { Thread.sleep(10000); } }