List of usage examples for java.lang RuntimeException printStackTrace
public void printStackTrace(PrintStream s)
From source file:net.udidb.cli.driver.UdidbDriver.java
/** * Entry point for udidb launched from the command line * * @param args command line arguments (see help message) *//*from ww w . j a v a2 s . c o m*/ public static void main(String[] args) { try { UdidbDriver driver = new UdidbDriver(args); System.exit(driver.execute() ? EXIT_SUCCESS : EXIT_FAILURE); } catch (RuntimeException e) { e.printStackTrace(System.err); System.exit(EXIT_FAILURE); } }
From source file:net.siegmar.japtproxy.JaptProxyServer.java
/** * Starts the JaptProxyServer with the given parameters. * * @param args command line args.//from ww w.j av a 2 s .co m */ public static void main(final String[] args) { if (checkRequiredOptions()) { System.exit(1); } String configFile = System.getProperty(OPT_CONFIG); String contextPath = System.getProperty(OPT_CONTEXT_PATH); String logConfig = System.getProperty(OPT_LOG_CONFIG); final String host = System.getProperty(OPT_HOST); String port = System.getProperty(OPT_PORT); // Check settings if (configFile == null) { configFile = OPT_CONFIG_DEFAULT; } if (contextPath == null) { contextPath = OPT_CONTEXT_PATH_DEFAULT; } if (logConfig == null) { logConfig = OPT_LOG_CONFIG_DEFAULT; } if (port == null) { port = OPT_PORT_DEFAULT; } if (!new File(configFile).exists()) { System.err.println("Config file '" + configFile + "' doesn't exist"); System.exit(1); } try { initializeLogging(logConfig); } catch (final RuntimeException e) { System.err.println("Couldn't initialize logging"); e.printStackTrace(System.err); System.exit(1); } final Logger log = LoggerFactory.getLogger(JaptProxyServer.class); // Remove PID_FILE if specified final String pidFile = System.getenv("PID_FILE"); if (pidFile != null) { log.debug("Will try to delete PID_FILE {} on exit", pidFile); new File(pidFile).deleteOnExit(); } try { final int portNumber = Integer.parseInt(port); startServer(host, portNumber, StringUtils.stripEnd(contextPath, "/")); } catch (final NumberFormatException e) { log.error("The specified port number {} is not a number", port); System.exit(1); } catch (final RuntimeException e) { log.error("Error while starting server", e); System.exit(1); } }
From source file:org.archive.io.warc.WARCReader.java
/** * Command-line interface to WARCReader. * * Here is the command-line interface:/*from w w w . jav a2 s. c o m*/ * <pre> * usage: java org.archive.io.arc.WARCReader [--offset=#] ARCFILE * -h,--help Prints this message and exits. * -o,--offset Outputs record at this offset into arc file.</pre> * * <p>Outputs using a pseudo-CDX format as described here: * <a href="http://www.archive.org/web/researcher/cdx_legend.php">CDX * Legent</a> and here * <a href="http://www.archive.org/web/researcher/example_cdx.php">Example</a>. * Legend used in below is: 'CDX b e a m s c V (or v if uncompressed) n g'. * Hash is hard-coded straight SHA-1 hash of content. * * @param args Command-line arguments. * @throws ParseException Failed parse of the command line. * @throws IOException * @throws java.text.ParseException */ public static void main(String[] args) throws ParseException, IOException, java.text.ParseException { Options options = getOptions(); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); @SuppressWarnings("unchecked") List<String> cmdlineArgs = cmdline.getArgList(); Option[] cmdlineOptions = cmdline.getOptions(); HelpFormatter formatter = new HelpFormatter(); // If no args, print help. if (cmdlineArgs.size() <= 0) { usage(formatter, options, 0); } // Now look at options passed. long offset = -1; boolean digest = false; boolean strict = false; String format = CDX; for (int i = 0; i < cmdlineOptions.length; i++) { switch (cmdlineOptions[i].getId()) { case 'h': usage(formatter, options, 0); break; case 'o': offset = Long.parseLong(cmdlineOptions[i].getValue()); break; case 's': strict = true; break; case 'd': digest = getTrueOrFalse(cmdlineOptions[i].getValue()); break; case 'f': format = cmdlineOptions[i].getValue().toLowerCase(); boolean match = false; // List of supported formats. final String[] supportedFormats = { CDX, DUMP, GZIP_DUMP, CDX_FILE }; for (int ii = 0; ii < supportedFormats.length; ii++) { if (supportedFormats[ii].equals(format)) { match = true; break; } } if (!match) { usage(formatter, options, 1); } break; default: throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId()); } } if (offset >= 0) { if (cmdlineArgs.size() != 1) { System.out.println("Error: Pass one arcfile only."); usage(formatter, options, 1); } WARCReader r = WARCReaderFactory.get(new File((String) cmdlineArgs.get(0)), offset); r.setStrict(strict); outputRecord(r, format); } else { for (Iterator<String> i = cmdlineArgs.iterator(); i.hasNext();) { String urlOrPath = (String) i.next(); try { WARCReader r = WARCReaderFactory.get(urlOrPath); r.setStrict(strict); r.setDigest(digest); output(r, format); } catch (RuntimeException e) { // Write out name of file we failed on to help with // debugging. Then print stack trace and try to keep // going. We do this for case where we're being fed // a bunch of ARCs; just note the bad one and move // on to the next. System.err.println("Exception processing " + urlOrPath + ": " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } } } }
From source file:com.cyberway.issue.io.warc.WARCReader.java
/** * Command-line interface to WARCReader. * * Here is the command-line interface:/* w w w.j av a2 s .c o m*/ * <pre> * usage: java com.cyberway.issue.io.arc.WARCReader [--offset=#] ARCFILE * -h,--help Prints this message and exits. * -o,--offset Outputs record at this offset into arc file.</pre> * * <p>Outputs using a pseudo-CDX format as described here: * <a href="http://www.archive.org/web/researcher/cdx_legend.php">CDX * Legent</a> and here * <a href="http://www.archive.org/web/researcher/example_cdx.php">Example</a>. * Legend used in below is: 'CDX b e a m s c V (or v if uncompressed) n g'. * Hash is hard-coded straight SHA-1 hash of content. * * @param args Command-line arguments. * @throws ParseException Failed parse of the command line. * @throws IOException * @throws java.text.ParseException */ public static void main(String[] args) throws ParseException, IOException, java.text.ParseException { Options options = getOptions(); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); List cmdlineArgs = cmdline.getArgList(); Option[] cmdlineOptions = cmdline.getOptions(); HelpFormatter formatter = new HelpFormatter(); // If no args, print help. if (cmdlineArgs.size() <= 0) { usage(formatter, options, 0); } // Now look at options passed. long offset = -1; boolean digest = false; boolean strict = false; String format = CDX; for (int i = 0; i < cmdlineOptions.length; i++) { switch (cmdlineOptions[i].getId()) { case 'h': usage(formatter, options, 0); break; case 'o': offset = Long.parseLong(cmdlineOptions[i].getValue()); break; case 's': strict = true; break; case 'd': digest = getTrueOrFalse(cmdlineOptions[i].getValue()); break; case 'f': format = cmdlineOptions[i].getValue().toLowerCase(); boolean match = false; // List of supported formats. final String[] supportedFormats = { CDX, DUMP, GZIP_DUMP, CDX_FILE }; for (int ii = 0; ii < supportedFormats.length; ii++) { if (supportedFormats[ii].equals(format)) { match = true; break; } } if (!match) { usage(formatter, options, 1); } break; default: throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId()); } } if (offset >= 0) { if (cmdlineArgs.size() != 1) { System.out.println("Error: Pass one arcfile only."); usage(formatter, options, 1); } WARCReader r = WARCReaderFactory.get(new File((String) cmdlineArgs.get(0)), offset); r.setStrict(strict); outputRecord(r, format); } else { for (Iterator i = cmdlineArgs.iterator(); i.hasNext();) { String urlOrPath = (String) i.next(); try { WARCReader r = WARCReaderFactory.get(urlOrPath); r.setStrict(strict); r.setDigest(digest); output(r, format); } catch (RuntimeException e) { // Write out name of file we failed on to help with // debugging. Then print stack trace and try to keep // going. We do this for case where we're being fed // a bunch of ARCs; just note the bad one and move // on to the next. System.err.println("Exception processing " + urlOrPath + ": " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } } } }
From source file:org.archive.io.arc.ARCReader.java
/** * Command-line interface to ARCReader./*from ww w . ja v a2 s.c o m*/ * * Here is the command-line interface: * <pre> * usage: java org.archive.io.arc.ARCReader [--offset=#] ARCFILE * -h,--help Prints this message and exits. * -o,--offset Outputs record at this offset into arc file.</pre> * * <p>See in <code>$HERITRIX_HOME/bin/arcreader</code> for a script that'll * take care of classpaths and the calling of ARCReader. * * <p>Outputs using a pseudo-CDX format as described here: * <a href="http://www.archive.org/web/researcher/cdx_legend.php">CDX * Legent</a> and here * <a href="http://www.archive.org/web/researcher/example_cdx.php">Example</a>. * Legend used in below is: 'CDX b e a m s c V (or v if uncompressed) n g'. * Hash is hard-coded straight SHA-1 hash of content. * * @param args Command-line arguments. * @throws ParseException Failed parse of the command line. * @throws IOException * @throws java.text.ParseException */ @SuppressWarnings("unchecked") public static void main(String[] args) throws ParseException, IOException, java.text.ParseException { Options options = getOptions(); options.addOption(new Option("p", "parse", false, "Parse headers.")); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); List<String> cmdlineArgs = cmdline.getArgList(); Option[] cmdlineOptions = cmdline.getOptions(); HelpFormatter formatter = new HelpFormatter(); // If no args, print help. if (cmdlineArgs.size() <= 0) { usage(formatter, options, 0); } // Now look at options passed. long offset = -1; boolean digest = false; boolean strict = false; boolean parse = false; String format = CDX; for (int i = 0; i < cmdlineOptions.length; i++) { switch (cmdlineOptions[i].getId()) { case 'h': usage(formatter, options, 0); break; case 'o': offset = Long.parseLong(cmdlineOptions[i].getValue()); break; case 's': strict = true; break; case 'p': parse = true; break; case 'd': digest = getTrueOrFalse(cmdlineOptions[i].getValue()); break; case 'f': format = cmdlineOptions[i].getValue().toLowerCase(); boolean match = false; // List of supported formats. final String[] supportedFormats = { CDX, DUMP, GZIP_DUMP, HEADER, NOHEAD, CDX_FILE }; for (int ii = 0; ii < supportedFormats.length; ii++) { if (supportedFormats[ii].equals(format)) { match = true; break; } } if (!match) { usage(formatter, options, 1); } break; default: throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId()); } } if (offset >= 0) { if (cmdlineArgs.size() != 1) { System.out.println("Error: Pass one arcfile only."); usage(formatter, options, 1); } ARCReader arc = ARCReaderFactory.get((String) cmdlineArgs.get(0), offset); arc.setStrict(strict); // We must parse headers if we need to skip them. if (format.equals(NOHEAD) || format.equals(HEADER)) { parse = true; } arc.setParseHttpHeaders(parse); outputRecord(arc, format); } else { for (String urlOrPath : cmdlineArgs) { try { ARCReader r = ARCReaderFactory.get(urlOrPath); r.setStrict(strict); r.setParseHttpHeaders(parse); r.setDigest(digest); output(r, format); } catch (RuntimeException e) { // Write out name of file we failed on to help with // debugging. Then print stack trace and try to keep // going. We do this for case where we're being fed // a bunch of ARCs; just note the bad one and move // on to the next. System.err.println("Exception processing " + urlOrPath + ": " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } } } }
From source file:org.grouplens.lenskit.diffusion.MainTester.java
public static void main(String[] args) { MainTester hello = new MainTester(args); System.out.println("Hellooo"); try {//from w w w . j a va 2 s .c o m //runsingle(); hello.run(); } catch (RuntimeException e) { System.err.println(e.toString()); e.printStackTrace(System.err); System.exit(1); } }
From source file:com.cyberway.issue.io.arc.ARCReader.java
/** * Command-line interface to ARCReader.//w w w. j a v a2 s. c o m * * Here is the command-line interface: * <pre> * usage: java com.cyberway.issue.io.arc.ARCReader [--offset=#] ARCFILE * -h,--help Prints this message and exits. * -o,--offset Outputs record at this offset into arc file.</pre> * * <p>See in <code>$HERITRIX_HOME/bin/arcreader</code> for a script that'll * take care of classpaths and the calling of ARCReader. * * <p>Outputs using a pseudo-CDX format as described here: * <a href="http://www.archive.org/web/researcher/cdx_legend.php">CDX * Legent</a> and here * <a href="http://www.archive.org/web/researcher/example_cdx.php">Example</a>. * Legend used in below is: 'CDX b e a m s c V (or v if uncompressed) n g'. * Hash is hard-coded straight SHA-1 hash of content. * * @param args Command-line arguments. * @throws ParseException Failed parse of the command line. * @throws IOException * @throws java.text.ParseException */ public static void main(String[] args) throws ParseException, IOException, java.text.ParseException { Options options = getOptions(); options.addOption(new Option("p", "parse", false, "Parse headers.")); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); List cmdlineArgs = cmdline.getArgList(); Option[] cmdlineOptions = cmdline.getOptions(); HelpFormatter formatter = new HelpFormatter(); // If no args, print help. if (cmdlineArgs.size() <= 0) { usage(formatter, options, 0); } // Now look at options passed. long offset = -1; boolean digest = false; boolean strict = false; boolean parse = false; String format = CDX; for (int i = 0; i < cmdlineOptions.length; i++) { switch (cmdlineOptions[i].getId()) { case 'h': usage(formatter, options, 0); break; case 'o': offset = Long.parseLong(cmdlineOptions[i].getValue()); break; case 's': strict = true; break; case 'p': parse = true; break; case 'd': digest = getTrueOrFalse(cmdlineOptions[i].getValue()); break; case 'f': format = cmdlineOptions[i].getValue().toLowerCase(); boolean match = false; // List of supported formats. final String[] supportedFormats = { CDX, DUMP, GZIP_DUMP, HEADER, NOHEAD, CDX_FILE }; for (int ii = 0; ii < supportedFormats.length; ii++) { if (supportedFormats[ii].equals(format)) { match = true; break; } } if (!match) { usage(formatter, options, 1); } break; default: throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId()); } } if (offset >= 0) { if (cmdlineArgs.size() != 1) { System.out.println("Error: Pass one arcfile only."); usage(formatter, options, 1); } ARCReader arc = ARCReaderFactory.get((String) cmdlineArgs.get(0), offset); arc.setStrict(strict); // We must parse headers if we need to skip them. if (format.equals(NOHEAD) || format.equals(HEADER)) { parse = true; } arc.setParseHttpHeaders(parse); outputRecord(arc, format); } else { for (Iterator i = cmdlineArgs.iterator(); i.hasNext();) { String urlOrPath = (String) i.next(); try { ARCReader r = ARCReaderFactory.get(urlOrPath); r.setStrict(strict); r.setParseHttpHeaders(parse); r.setDigest(digest); output(r, format); } catch (RuntimeException e) { // Write out name of file we failed on to help with // debugging. Then print stack trace and try to keep // going. We do this for case where we're being fed // a bunch of ARCs; just note the bad one and move // on to the next. System.err.println("Exception processing " + urlOrPath + ": " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } } } }
From source file:org.jug.bg.rest.hateoas.spring.common.resource.AbstractResource.java
/** * Auxiliary method for handling exceptions. * * @param exception Exception to be handled. * @param errMsg Error message./*from w ww. j a v a 2s .c om*/ */ private void handleError(RuntimeException exception, String errMsg) { System.err.println(errMsg); exception.printStackTrace(System.err); }
From source file:org.apache.oozie.action.hadoop.PigMain.java
private void printScript(String name, String type) { FileInputStream fin = null;/*w w w . j a v a2 s. c o m*/ InputStreamReader inReader = null; BufferedReader bufReader = null; try { File script = new File(name); if (!script.exists()) { return; } System.out.println("-----------------------------------------------------------"); System.out.println(type + " Pig script [" + name + "] content: "); System.out.println("-----------------------------------------------------------"); fin = new FileInputStream(script); inReader = new InputStreamReader(fin, "UTF-8"); bufReader = new BufferedReader(inReader); String line = bufReader.readLine(); while (line != null) { System.out.println(line); line = bufReader.readLine(); } bufReader.close(); } catch (RuntimeException e) { throw e; } catch (Exception e) { System.out.println("Unable to read " + name); e.printStackTrace(System.out); } finally { IOUtils.closeQuietly(fin); IOUtils.closeQuietly(inReader); IOUtils.closeQuietly(bufReader); } System.out.println(); System.out.flush(); System.out.println("-----------------------------------------------------------"); System.out.println(); }
From source file:eumetsat.pn.common.AbstractApp.java
public void run() { if (servletContainer) { log.info("Running in servlet container, not configuring port, webapp path is {}", this.path); } else {/*from w w w . jav a 2 s. co m*/ log.info("Running standalone, configuring port to {}", this.port); Spark.staticFileLocation(PUBLIC_ROUTE); Spark.port(this.port); } TemplateEngine engine = new FreeMarkerTemplateEngine(cfg); Spark.get(searchRoute, new TemplateViewRoute() { @Override public ModelAndView handle(Request request, Response response) { log.trace("Handle search request..."); setHeaders(response); ModelAndView mav = null; Map<String, Object> attributes = new HashMap<>(); addGlobalAttributes(attributes); try { mav = new ModelAndView(attributes, "/templates/search_page.ftl"); } catch (RuntimeException e) { log.error("Error serving request", e); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); String str = errors.toString(); Spark.halt(401, "Error while accessing page search_page. error = " + str); } return mav; } }, engine); Spark.get(searchResultsRoute, new TemplateViewRoute() { @Override public ModelAndView handle(Request request, Response response) { log.trace("Handle search request: {}", request.raw().getRequestURL()); setHeaders(response); ModelAndView mav = null; Map<String, Object> attributes = new HashMap<>(); attributes = addGlobalAttributes(attributes); try { String searchTerms = request.queryParams("search-terms"); String filterTerms = request.queryParams("filter-terms"); int from = -1; int size = -1; try { from = Integer.parseInt(request.queryParams("from")); } catch (Exception e) { log.error("Parameter 'from' cannot be converted to int. default to -1.", e); } try { size = Integer.parseInt(request.queryParams("size")); } catch (Exception e) { log.error("Parameter 'size' cannot be converted to int. default to -1.", e); } log.trace("Search terms: {} | Filter terms: {} | From: {} | Size: {}", searchTerms, filterTerms, from, size); Map<String, Object> data = search(searchTerms, filterTerms, from, size); attributes.putAll(data); mav = new ModelAndView(attributes, "/templates/search_results.ftl"); } catch (RuntimeException e) { log.error("Error handling search/results", e); StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); String str = errors.toString(); Spark.halt(401, "Error while returning responses: \n\n" + str); } return mav; } }, engine); Spark.get(productDescriptionRoute, new TemplateViewRoute() { @Override public ModelAndView handle(Request request, Response response) { log.trace("Handle product description request: ", request.raw().getRequestURL().toString()); String id = request.queryParams("id"); Map<String, Object> attributes = new HashMap<>(); attributes = addGlobalAttributes(attributes); setHeaders(response); try { //get product description info and return them as the input for the template Map<String, Object> data = describeProduct(id); attributes.putAll(data); } catch (RuntimeException | MalformedURLException | ParseException e) { log.error("Error during product description page.", e); // errorResponse(e); attributes = addMessage(attributes, MessageLevel.danger, "Error: " + response.toString()); } ModelAndView mav = new ModelAndView(attributes, "/templates/product_description.ftl"); return mav; } }, engine); Spark.get("/", new Route() { @Override public Object handle(Request request, Response response) { String destination = servletContainer ? "/" + path + searchRoute : searchRoute; log.trace("Handle base request > redirect to {}!", destination); response.redirect(destination); return null; } }); Spark.get("/feed", new Route() { @Override public Object handle(Request request, Response response) { log.info("Starting feeding!"); try { String config = request.queryMap("config").value(); if (config != null && !config.isEmpty()) { config = URLDecoder.decode(config, "UTF-8"); log.debug("Decoded parameter 'config': {}", config); Path p = Paths.get(config); feed(p); } else { feed(); } } catch (IOException e) { log.error("Error during feeding", e); errorResponse(e); } log.info("Done with feeding."); response.redirect(servletContainer ? "/" + path : ""); return null; } }); }