List of usage examples for java.lang Exception getStackTrace
public StackTraceElement[] getStackTrace()
From source file:lab.home.spring.redis.test.SpringRedisTest.java
public static void main(String argv[]) { ApplicationContext ctx = new AnnotationConfigApplicationContext(RedisTestConfig.class); DictionaryDao ddao = ctx.getBean(DictionaryDao.class); try {/*from w ww . ja v a 2s .c o m*/ System.out.println("ddao.setValue(\"key1\", \"value1\")"); ddao.setValue("key1", "value1"); System.out.println("ddao.setValue(\"testkey\", \"testvalue\")"); ddao.setValue("testkey", "testvalue"); System.out.println("getting value for key1 = " + ddao.getValue("key1")); System.out.println("getting value for testkey = " + ddao.getValue("testkey")); } catch (Exception e) { System.out.println(e); System.out.println(e.fillInStackTrace()); System.out.println(e.getCause()); System.out.println(e.getClass()); System.out.println(e.getStackTrace()); e.printStackTrace(); } }
From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.ModelImporter.java
/** * Usage: <code>'Path to config' Collection PATH [PATH2 [PATH3] ...]]</code> * </br></br>/* www . ja va2s .c o m*/ * <code>Path to config</code> is a path in file system to the configuration file being used * for import. It can be given relative to the PromniCAT folder.</br> * If an empty string is provided, the default file 'PromniCAT/configuration.properties' is used.</br></br> * <code>Collection</code> is the process model collection and can be one of * 'BPMN', 'NPB', 'SAP_RM' or 'AOK' </br></br> * <code>PATH</code> is a path in file system to a directory containing the models that should be imported. */ public static void main(String[] args) { // wrong number of parameter? if (args.length < 3) { printHelpMessage(); return; } try { //read configuration file IPersistenceApi persistenceApi = new ConfigurationParser(args[0]) .getDbInstance(Constants.DATABASE_TYPES.ORIENT_DB); //import models // BPMAI model? if (args[1].toUpperCase().equals(Constants.ORIGIN_BPMAI)) { startImport(new BpmaiImporter(persistenceApi), args); return; } // NPB model? if (args[1].toUpperCase().equals(Constants.ORIGIN_NPB)) { startImport(new NPBImporter(persistenceApi), args); return; } // SAP_RM model? if (args[1].toUpperCase().equals(Constants.ORIGIN_SAP_RM)) { startImport(new SapReferenceModelImporter(persistenceApi), args); return; } // AOK model? if (args[1].toUpperCase().equals(Constants.ORIGIN_AOK)) { startImport(new AokModelImporter(persistenceApi), args); return; } // wrong argument value printHelpMessage(); throw new IllegalArgumentException(WRONG_USAGE_MESSAGE); } catch (Exception e) { logger.severe(e.getMessage()); String stackTraceString = ""; for (StackTraceElement ste : e.getStackTrace()) { stackTraceString = stackTraceString.concat(ste.toString() + "\n"); } logger.severe(stackTraceString); } }
From source file:se.berazy.api.examples.App.java
/** * Operation examples.// www .ja va 2 s . c om * @param args */ public static void main(String[] args) { Scanner scanner = null; try { client = new BookkeepingClient(); System.out.println("Choose operation to invoke:\n"); System.out.println("1. Create invoice"); System.out.println("2. Credit invoice"); scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String line = scanner.nextLine(); line = (line != null) ? line.trim().toLowerCase() : ""; if (line.equals("1")) { outPutResponse(createInvoice()); } else if (line.equals("2")) { outPutResponse(creditInvoice()); } else if (line.equals("q") || line.equals("quit") || line.equals("exit")) { System.exit(0); } else { System.out.println("\nPlease choose an operation from 1-7."); } } scanner.close(); } catch (Exception ex) { System.out.println(String.format( "\nAn exception occured, press CTRL+C to exit or enter 'q', 'quit' or 'exit'.\n\nException: %s %s", ex.getMessage(), ex.getStackTrace())); } finally { if (scanner != null) { scanner.close(); } } }
From source file:com.ibm.replication.iidr.warehouse.CollectCDCStats.java
public static void main(String[] args) { // Only set arguments when testing if (args.length == 1 && args[0].equalsIgnoreCase("*Testing*")) { // args = "-d -ds CDC_DB2".split(" "); args = "-d -ds CDC_DB2 -s CDC_BD,CDC_BS".split(" "); // args = "-d".split(" "); }//from w w w . j a va 2 s. com // First check parameters CollectCDCStatsParms parms = null; try { // Get and check parameters parms = new CollectCDCStatsParms(args); } catch (CollectCDCStatsParmsException cpe) { Logger logger = LogManager.getLogger(); logger.error("Error while validating parameters: " + cpe.getMessage()); } // Set Log4j properties and get logger System.setProperty("log4j.configurationFile", System.getProperty("user.dir") + File.separatorChar + "conf" + File.separatorChar + parms.loggingConfigurationFile); Logger logger = LogManager.getLogger(); // Collect the statistics try { new CollectCDCStats(parms); } catch (Exception e) { // Report the full stack trace for debugging logger.error(Arrays.toString(e.getStackTrace())); logger.error("Error while collecting statistics from CDC: " + e.getMessage()); } }
From source file:com.ln.gui.Main.java
public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { createandshowgui();//from www . j a v a 2s .c om } catch (Exception e) { //Kill&print on errors e.printStackTrace(); JOptionPane.showMessageDialog(null, e.getStackTrace(), "Error", JOptionPane.WARNING_MESSAGE); } } }); }
From source file:com.aliasi.lingmed.medline.DownloadMedline.java
/** * Main method to be called from the command-line. * * @param args Command-line arguments.//from w w w .java 2 s. co m */ public static void main(String[] args) throws Exception { DownloadMedline downloader = new DownloadMedline(args); while (true) { try { // Logger.getLogger(DownloadMedline.class).info("Run downloader"); downloader.run(); // Logger.getLogger(DownloadMedline.class).info("Run completed"); } catch (Exception e) { String msg = "Unexpected exception=" + e; // Logger.getLogger(DownloadMedline.class).warn(msg); IllegalStateException e2 = new IllegalStateException(msg); e2.setStackTrace(e.getStackTrace()); throw e2; } if (downloader.sleepMins() < 1) break; Thread.sleep(downloader.sleepMins() * MINUTE); } }
From source file:de.prozesskraft.pkraft.Manager.java
public static void main(String[] args) throws org.apache.commons.cli.ParseException, CloneNotSupportedException { // try/*from w ww .j a va 2 s. com*/ // { // if (args.length != 1) // { // System.out.println("Please specify Inputfile and Outputfile (prozessinstanz.lri)"); // } // // } // catch (ArrayIndexOutOfBoundsException e) // { // System.out.println("***ArrayIndexOutOfBoundsException: Please specify procesdefinition.lrd and processinstance.lri\n" + e.toString()); // } /*---------------------------- get options from ini-file ----------------------------*/ File inifile = new java.io.File( WhereAmI.getInstallDirectoryAbsolutePath(Manager.class) + "/" + "../etc/pkraft-manager.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); exit = true; } /*---------------------------- create boolean options ----------------------------*/ Option help = new Option("help", "print this message"); Option v = new Option("v", "prints version and build-date"); /*---------------------------- create argument options ----------------------------*/ Option instance = OptionBuilder.withArgName("instance").hasArg() .withDescription("[mandatory] process instance file") // .isRequired() .create("instance"); Option stop = OptionBuilder.withArgName("stop") // .hasArg() .withDescription("[optional] stops a running manager for given instance") // .isRequired() .create("stop"); Option kill = OptionBuilder.withArgName("kill") // .hasArg() .withDescription("[optional] kills all applications that have been started by steps") // .isRequired() .create("kill"); /*---------------------------- create options object ----------------------------*/ Options options = new Options(); options.addOption(help); options.addOption(v); options.addOption(instance); options.addOption(stop); options.addOption(kill); /*---------------------------- create the parser ----------------------------*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments line = parser.parse(options, args); } // catch ( ParseException exp ) catch (Exception exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); exiter(); } /*---------------------------- usage/help ----------------------------*/ if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("manager", options); exit = true; System.exit(0); } else if (line.hasOption("v")) { System.out.println("author: info@prozesskraft.de"); System.out.println("version: [% version %]"); System.out.println("date: [% date %]"); exit = true; System.exit(0); } else if (!(line.hasOption("instance"))) { 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()) { exit = true; System.exit(1); } /*---------------------------- business logic ----------------------------*/ Process actualProcess = null; try { Process p1 = new Process(); // die dauer des loops festlegen. Dies soll kein standardwert sein, da sonst bei vielen subprozessen die Prozessorlast stark oszilliert // zwischen 12 und 17 sekunden // Random rand = new Random(System.currentTimeMillis()); // int loop_period_seconds = rand.nextInt((17 - 12) + 1) + 12; // System.err.println("loop period is randomly set to: "+loop_period_seconds); fileBinary = new java.io.File(line.getOptionValue("instance")); String pathBinary = ""; if (fileBinary.exists()) { pathBinary = fileBinary.getAbsolutePath(); System.err.println("file does exist: " + pathBinary); } else { System.err.println("file does not exist: " + fileBinary.getAbsolutePath()); exiter(); } if (line.hasOption("stop") || line.hasOption("kill")) { p1.setInfilebinary(pathBinary); Process p2 = p1.readBinary(); p2.log("debug", "setting new manager-Id (0) to signal actual manager (" + p2.getManagerid() + ") that he is no longer in charge "); System.err.println("info: stopping instance"); System.err.println("debug: setting new manager-Id (0) to signal actual manager (" + p2.getManagerid() + ") that he is no longer in charge "); p2.setManagerid(0); p2.run = false; p2.setOutfilebinary(pathBinary); p2.writeBinary(); if (line.hasOption("kill")) { System.err.println("info: killing all steps of instance"); String returnStringOfKills = p2.kill(); System.err.println("info: killing returns: " + returnStringOfKills); } boolean pradar = (!(p2.isWrapper())); // pradar checkout if (pradar) { pradarAttend(p2.getRootdir() + "/process.pmb"); // pradarCheckout(p2.getId(), p2.getName(), "0"); } exit = true; System.exit(0); } startZyklischerThread(0); // prozessinstanz einlesen p1.setInfilebinary(pathBinary); managerid = p1.genManagerid(); Process p2; p2 = p1.readBinary(); // beim aufruf des programms wird erstmal die instanz occupiert p2.setManagerid(managerid); System.err.println("debug: manager " + managerid + ": occupying instance."); p2.log("info", "manager " + managerid + ": occupying instance."); p2.log("debug", "manager " + managerid + ": setting new manager-id to signal other running managers that they are not longer needed."); p2.log("debug", "manager " + managerid + ": setting binary file for input to: " + pathBinary); // System.out.println("setting binary file for input to: "+line.getOptionValue("instance")); p2.log("debug", "manager " + managerid + ": reading binary file: " + pathBinary); p2.setInfilebinary(pathBinary); p2.setOutfilebinary(pathBinary); p2.log("debug", "manager " + managerid + ": setting binary file for output: " + pathBinary); // instanz auf platte schreiben (um anderen managern zu signalisieren, dass sie nicht mehr gebraucht werden // System.out.println("setting manager-id to: "+managerid); p2.log("debug", "manager " + managerid + ": writing process to binary file to occupy instance."); // wenn es kein wrapper-prozess ist, dann soll die komunikation mit pradar vom manager uebernommen werden boolean pradar = (!(p2.isWrapper())); System.err.println("debug: setting instance to run"); p2.run = true; // pradar checkin if (pradar && p2.run && p2.touchInMillis == 0) { pradarAttend(p2.getRootdir() + "/process.pmb"); // p2.log("debug", "pradar-checkin id="+p2.getId()+", process="+p2.getName()+", processversion="+p2.getVersion()+", id2="+p2.getId2()+", parentid="+p2.getParentid()+", resource="+p2.getRootdir()+"/process.pmb"); // pradarCheckin(p2.getId(), p2.getName(), p2.getVersion(), p2.getId2(), p2.getParentid(), getPid(), p2.getRootdir()+"/process.pmb"); } System.err.println("debug: writing binary"); p2.writeBinary(); // process weiter schubsen pushProcessAsFarAsPossible(pathBinary, false); // try // { // // der thread soll so lange schlafen, wie die periode lang ist. die schlafdauer wird mit der anzahl multipliziert, wie oft das loadAverage zu hoch war (max 5) // int faktorForPeriod = Math.min(10, p2.counterLoadAverageTooHigh + 1); // // int secondsToSleep = loop_period_seconds * faktorForPeriod; // System.err.println("debug: sleeping for " + secondsToSleep + " seconds"); // // int millisecondsToSleep = secondsToSleep*1000; // System.err.println("debug: sleeping for " + millisecondsToSleep + " milliseconds"); // // Thread.sleep(millisecondsToSleep); // } // catch (InterruptedException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // // // ausgabe in das debugLogFile // exiterException(actualProcess.getOutfilebinary(), e); // } } catch (Exception e) { if (actualProcess != null) { actualProcess.log("fatal", e.getMessage() + "\n" + Arrays.toString(e.getStackTrace())); updateFile(actualProcess); e.printStackTrace(); // ausgabe in das debugLogFile exiterException(actualProcess.getOutfilebinary(), e); } exit = true; System.exit(10); } }
From source file:cli.Main.java
public static void main(String[] args) { // Workaround for BKS truststore Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1); Namespace ns = parseArgs(args); if (ns == null) { System.exit(1);//from ww w .ja v a2 s . c o m } final String username = ns.getString("username"); final Manager m = new Manager(username); if (m.userExists()) { try { m.load(); } catch (Exception e) { System.err.println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage()); System.exit(2); } } switch (ns.getString("command")) { case "register": if (!m.userHasKeys()) { m.createNewIdentity(); } try { m.register(ns.getBoolean("voice")); } catch (IOException e) { System.err.println("Request verify error: " + e.getMessage()); System.exit(3); } break; case "verify": if (!m.userHasKeys()) { System.err.println("User has no keys, first call register."); System.exit(1); } if (m.isRegistered()) { System.err.println("User registration is already verified"); System.exit(1); } try { m.verifyAccount(ns.getString("verificationCode")); } catch (IOException e) { System.err.println("Verify error: " + e.getMessage()); System.exit(3); } break; case "send": if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } String messageText = ns.getString("message"); if (messageText == null) { try { messageText = IOUtils.toString(System.in); } catch (IOException e) { System.err.println("Failed to read message from stdin: " + e.getMessage()); System.exit(1); } } final List<String> attachments = ns.getList("attachment"); List<TextSecureAttachment> textSecureAttachments = null; if (attachments != null) { textSecureAttachments = new ArrayList<>(attachments.size()); for (String attachment : attachments) { try { File attachmentFile = new File(attachment); InputStream attachmentStream = new FileInputStream(attachmentFile); final long attachmentSize = attachmentFile.length(); String mime = Files.probeContentType(Paths.get(attachment)); textSecureAttachments .add(new TextSecureAttachmentStream(attachmentStream, mime, attachmentSize, null)); } catch (IOException e) { System.err.println("Failed to add attachment \"" + attachment + "\": " + e.getMessage()); System.err.println("Aborting sending."); System.exit(1); } } } List<TextSecureAddress> recipients = new ArrayList<>(ns.<String>getList("recipient").size()); for (String recipient : ns.<String>getList("recipient")) { try { recipients.add(m.getPushAddress(recipient)); } catch (InvalidNumberException e) { System.err.println("Failed to add recipient \"" + recipient + "\": " + e.getMessage()); System.err.println("Aborting sending."); System.exit(1); } } sendMessage(m, messageText, textSecureAttachments, recipients); break; case "receive": if (!m.isRegistered()) { System.err.println("User is not registered."); System.exit(1); } try { m.receiveMessages(5, true, new ReceiveMessageHandler(m)); } catch (IOException e) { System.err.println("Error while receiving message: " + e.getMessage()); System.exit(3); } catch (AssertionError e) { System.err.println("Failed to receive message (Assertion): " + e.getMessage()); System.err.println(e.getStackTrace()); System.err.println( "If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README"); System.exit(1); } break; } m.save(); System.exit(0); }
From source file:Main.java
public static boolean checkInternetConnection(Context context) { boolean haveConnectedWifi = false; boolean haveConnectedMobile = false; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); try {//from w ww . j av a 2 s.com NetworkInfo[] netInfo = cm.getAllNetworkInfo(); for (NetworkInfo ni : netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true; if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) haveConnectedMobile = true; } } catch (Exception e) { e.getStackTrace(); } return haveConnectedWifi || haveConnectedMobile; }
From source file:Main.java
public static int getMonthDays(int year, int month) { if (month > 12) { month = 1;//w ww .java 2 s.c o m year += 1; } else if (month < 1) { month = 12; year -= 1; } int[] arr = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int days = 0; if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { arr[1] = 29; } try { days = arr[month - 1]; } catch (Exception e) { e.getStackTrace(); } return days; }