List of usage examples for java.lang Throwable printStackTrace
public void printStackTrace()
From source file:com.simiacryptus.util.lang.CodeUtil.java
/** * Gets javadoc.//from w w w. j a v a 2s . co m * * @param clazz the clazz * @return the javadoc */ public static String getJavadoc(@Nullable final Class<?> clazz) { try { if (null == clazz) return null; @Nullable final File source = com.simiacryptus.util.lang.CodeUtil.findFile(clazz); if (null == source) return clazz.getName() + " not found"; final List<String> lines = IOUtils.readLines(new FileInputStream(source), Charset.forName("UTF-8")); final int classDeclarationLine = IntStream.range(0, lines.size()) .filter(i -> lines.get(i).contains("class " + clazz.getSimpleName())).findFirst().getAsInt(); final int firstLine = IntStream.rangeClosed(1, classDeclarationLine).map(i -> classDeclarationLine - i) .filter(i -> !lines.get(i).matches("\\s*[/\\*@].*")).findFirst().orElse(-1) + 1; final String javadoc = lines.subList(firstLine, classDeclarationLine).stream() .filter(s -> s.matches("\\s*[/\\*].*")).map(s -> s.replaceFirst("^[ \t]*[/\\*]+", "").trim()) .filter(x -> !x.isEmpty()).reduce((a, b) -> a + "\n" + b).orElse(""); return javadoc.replaceAll("<p>", "\n"); } catch (@javax.annotation.Nonnull final Throwable e) { e.printStackTrace(); return ""; } }
From source file:org.wso2.carbon.integration.test.client.PizzaOrderClient.java
public static void sendPizzaOrder(String url) { KeyStoreUtil.setTrustStoreParams();/* w ww . j a va2s. com*/ HttpClient httpClient = new SystemDefaultHttpClient(); try { HttpPost method = new HttpPost(url); String[] xmlElements = new String[] { "<mypizza:PizzaOrderStream xmlns:mypizza=\"http://samples.wso2.org/\">\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0023</mypizza:OrderNo>\n" + " <mypizza:Type>PEPPERONI</mypizza:Type>\n" + " <mypizza:Size>L</mypizza:Size>\n" + " <mypizza:Quantity>2</mypizza:Quantity>\n" + " <mypizza:Contact>James Mark</mypizza:Contact>\n" + " <mypizza:Address>29BX Finchwood Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + "</mypizza:PizzaOrderStream>", "<mypizza:PizzaOrderStream xmlns:mypizza=\"http://samples.wso2.org/\">\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0024</mypizza:OrderNo>\n" + " <mypizza:Type>CHEESE</mypizza:Type>\n" + " <mypizza:Size>M</mypizza:Size>\n" + " <mypizza:Quantity>1</mypizza:Quantity>\n" + " <mypizza:Contact>Henry Clock</mypizza:Contact>\n" + " <mypizza:Address>2CYL Morris Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + "</mypizza:PizzaOrderStream>", "<mypizza:PizzaOrderStream xmlns:mypizza=\"http://samples.wso2.org/\">\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0025</mypizza:OrderNo>\n" + " <mypizza:Type>SEAFOOD</mypizza:Type>\n" + " <mypizza:Size>S</mypizza:Size>\n" + " <mypizza:Quantity>4</mypizza:Quantity>\n" + " <mypizza:Contact>James Mark</mypizza:Contact>\n" + " <mypizza:Address>22RE Robinwood Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + "</mypizza:PizzaOrderStream>", "<mypizza:PizzaOrderStream xmlns:mypizza=\"http://samples.wso2.org/\">\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0026</mypizza:OrderNo>\n" + " <mypizza:Type>CHICKEN</mypizza:Type>\n" + " <mypizza:Size>L</mypizza:Size>\n" + " <mypizza:Contact>Alis Miranda</mypizza:Contact>\n" + " <mypizza:Address>779 Burl Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + "</mypizza:PizzaOrderStream>", "<mypizza:PizzaOrderStream xmlns:mypizza=\"http://samples.wso2.org/\">\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0026</mypizza:OrderNo>\n" + " <mypizza:Type>VEGGIE</mypizza:Type>\n" + " <mypizza:Size>L</mypizza:Size>\n" + " <mypizza:Quantity>1</mypizza:Quantity>\n" + " <mypizza:Contact>James Mark</mypizza:Contact>\n" + " <mypizza:Address>29BX Finchwood Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + "</mypizza:PizzaOrderStream>" }; String[] batchedXmlElements = new String[] { "<mypizza:PizzaOrderStream xmlns:mypizza=\"http://samples.wso2.org/\">\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0023</mypizza:OrderNo>\n" + " <mypizza:Type>PEPPERONI</mypizza:Type>\n" + " <mypizza:Size>L</mypizza:Size>\n" + " <mypizza:Quantity>2</mypizza:Quantity>\n" + " <mypizza:Contact>James Mark</mypizza:Contact>\n" + " <mypizza:Address>29BX Finchwood Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0024</mypizza:OrderNo>\n" + " <mypizza:Type>CHEESE</mypizza:Type>\n" + " <mypizza:Size>M</mypizza:Size>\n" + " <mypizza:Quantity>1</mypizza:Quantity>\n" + " <mypizza:Contact>Henry Clock</mypizza:Contact>\n" + " <mypizza:Address>2CYL Morris Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0025</mypizza:OrderNo>\n" + " <mypizza:Type>SEAFOOD</mypizza:Type>\n" + " <mypizza:Size>S</mypizza:Size>\n" + " <mypizza:Quantity>4</mypizza:Quantity>\n" + " <mypizza:Contact>James Mark</mypizza:Contact>\n" + " <mypizza:Address>22RE Robinwood Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + "</mypizza:PizzaOrderStream>", "<mypizza:PizzaOrderStream xmlns:mypizza=\"http://samples.wso2.org/\">\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0026</mypizza:OrderNo>\n" + " <mypizza:Type>CHICKEN</mypizza:Type>\n" + " <mypizza:Size>L</mypizza:Size>\n" + " <mypizza:Quantity>1</mypizza:Quantity>\n" + " <mypizza:Contact>Alis Miranda</mypizza:Contact>\n" + " <mypizza:Address>779 Burl Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + " <mypizza:PizzaOrder>\n" + " <mypizza:OrderNo>0026</mypizza:OrderNo>\n" + " <mypizza:Type>VEGGIE</mypizza:Type>\n" + " <mypizza:Size>L</mypizza:Size>\n" + " <mypizza:Quantity>1</mypizza:Quantity>\n" + " <mypizza:Contact>James Mark</mypizza:Contact>\n" + " <mypizza:Address>29BX Finchwood Ave, Clovis, CA 93611</mypizza:Address>\n" + " </mypizza:PizzaOrder>\n" + "</mypizza:PizzaOrderStream>" }; int i = 0; for (String xmlElement : xmlElements) { StringEntity entity = new StringEntity(xmlElement); method.setEntity(entity); httpClient.execute(method).getEntity().getContent().close(); System.out.println("Sent event no :" + i++); } Thread.sleep(500); // We need to wait some time for the message to be sent } catch (Throwable t) { t.printStackTrace(); Assert.fail("Exception: " + t.getMessage()); } }
From source file:com.alibaba.rocketmq.broker.BrokerStartup.java
public static BrokerController start(BrokerController controller) { try {//from w w w.java 2 s. co m // ?? controller.start(); String tip = "The broker[" + controller.getBrokerConfig().getBrokerName() + ", " + controller.getBrokerAddr() + "] boot success."; if (null != controller.getBrokerConfig().getNamesrvAddr()) { tip += " and name server is " + controller.getBrokerConfig().getNamesrvAddr(); } log.info(tip); System.out.println(tip); return controller; } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } return null; }
From source file:com.ict.dtube.filtersrv.FiltersrvStartup.java
public static FiltersrvController main0(String[] args) { System.setProperty(RemotingCommand.RemotingVersionKey, Integer.toString(MQVersion.CurrentVersion)); // Socket???/*w w w .ja va 2s . c om*/ if (null == System.getProperty(NettySystemConfig.SystemPropertySocketSndbufSize)) { NettySystemConfig.SocketSndbufSize = 65535; } // Socket? if (null == System.getProperty(NettySystemConfig.SystemPropertySocketRcvbufSize)) { NettySystemConfig.SocketRcvbufSize = 1024; } try { // ? Options options = ServerUtil.buildCommandlineOptions(new Options()); final CommandLine commandLine = ServerUtil.parseCmdLine("mqfiltersrv", args, buildCommandlineOptions(options), new PosixParser()); if (null == commandLine) { System.exit(-1); return null; } // ?? final FiltersrvConfig filtersrvConfig = new FiltersrvConfig(); final NettyServerConfig nettyServerConfig = new NettyServerConfig(); if (commandLine.hasOption('c')) { String file = commandLine.getOptionValue('c'); if (file != null) { InputStream in = new BufferedInputStream(new FileInputStream(file)); Properties properties = new Properties(); properties.load(in); MixAll.properties2Object(properties, filtersrvConfig); System.out.println("load config properties file OK, " + file); in.close(); String port = properties.getProperty("listenPort"); if (port != null) { filtersrvConfig.setConnectWhichBroker(String.format("127.0.0.1:%s", port)); } } } // 0??? nettyServerConfig.setListenPort(0); nettyServerConfig.setServerAsyncSemaphoreValue(filtersrvConfig.getFsServerAsyncSemaphoreValue()); nettyServerConfig .setServerCallbackExecutorThreads(filtersrvConfig.getFsServerCallbackExecutorThreads()); nettyServerConfig.setServerWorkerThreads(filtersrvConfig.getFsServerWorkerThreads()); // ?? if (commandLine.hasOption('p')) { MixAll.printObjectProperties(null, filtersrvConfig); MixAll.printObjectProperties(null, nettyServerConfig); System.exit(0); } MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), filtersrvConfig); if (null == filtersrvConfig.getDtubeHome()) { System.out.println("Please set the " + MixAll.DTUBE_HOME_ENV + " variable in your environment to match the location of the Dtube installation"); System.exit(-2); } // ?Logback LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(filtersrvConfig.getDtubeHome() + "/conf/logback_filtersrv.xml"); final Logger log = LoggerFactory.getLogger(LoggerName.FiltersrvLoggerName); // ?? final FiltersrvController controller = new FiltersrvController(filtersrvConfig, nettyServerConfig); boolean initResult = controller.initialize(); if (!initResult) { controller.shutdown(); System.exit(-3); } Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { private volatile boolean hasShutdown = false; private AtomicInteger shutdownTimes = new AtomicInteger(0); @Override public void run() { synchronized (this) { log.info("shutdown hook was invoked, " + this.shutdownTimes.incrementAndGet()); if (!this.hasShutdown) { this.hasShutdown = true; long begineTime = System.currentTimeMillis(); controller.shutdown(); long consumingTimeTotal = System.currentTimeMillis() - begineTime; log.info("shutdown hook over, consuming time total(ms): " + consumingTimeTotal); } } } }, "ShutdownHook")); // ?? controller.start(); String tip = "The Filter Server boot success, " + controller.localAddr(); log.info(tip); System.out.println(tip); return controller; } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } return null; }
From source file:ch.bender.evacuate.RunnerCheckDirectoriesTest.java
/** * Executed at loading of this class (static inizalizer). * <p>/* w w w . ja v a 2 s . c o m*/ * @throws Throwable * On any problem */ @BeforeClass public static final void doBeforeClass() throws Throwable { System.out.println("doBeforeClass() entering..."); try { if (Files.exists(Testconstants.ROOT_DIR)) { Helper.deleteDirRecursive(Testconstants.ROOT_DIR); } Files.createDirectory(Testconstants.ROOT_DIR); Path orig = Testconstants.createNewFolder(Testconstants.ROOT_DIR, "orig"); Path origSub1 = Testconstants.createNewFolder(orig, "sub1"); Path origSub2 = Testconstants.createNewFolder(orig, "sub2"); Path file1 = Testconstants.createNewFile(orig, "file1.txt"); Path fileSub1 = Testconstants.createNewFile(origSub1, "fileSub1.txt"); Path fileSub2 = Testconstants.createNewFile(origSub2, "fileSub2.txt"); Path backup = Testconstants.createNewFolder(Testconstants.ROOT_DIR, "backup"); FileUtils.copyDirectoryToDirectory(origSub1.toFile(), backup.toFile()); FileUtils.copyDirectoryToDirectory(origSub2.toFile(), backup.toFile()); } catch (Throwable e) { System.err.println("Throwable caught in doBeforeClass()"); e.printStackTrace(); throw e; } System.out.println("doBeforeClass() leaving..."); }
From source file:com.alibaba.rocketmq.filtersrv.FiltersrvStartup.java
public static FiltersrvController createController(String[] args) { System.setProperty(RemotingCommand.RemotingVersionKey, Integer.toString(MQVersion.CurrentVersion)); // Socket???// ww w . j a va 2 s .com if (null == System.getProperty(NettySystemConfig.SystemPropertySocketSndbufSize)) { NettySystemConfig.SocketSndbufSize = 65535; } // Socket? if (null == System.getProperty(NettySystemConfig.SystemPropertySocketRcvbufSize)) { NettySystemConfig.SocketRcvbufSize = 1024; } try { // ? Options options = ServerUtil.buildCommandlineOptions(new Options()); final CommandLine commandLine = ServerUtil.parseCmdLine("mqfiltersrv", args, buildCommandlineOptions(options), new PosixParser()); if (null == commandLine) { System.exit(-1); return null; } // ?? final FiltersrvConfig filtersrvConfig = new FiltersrvConfig(); final NettyServerConfig nettyServerConfig = new NettyServerConfig(); if (commandLine.hasOption('c')) { String file = commandLine.getOptionValue('c'); if (file != null) { InputStream in = new BufferedInputStream(new FileInputStream(file)); Properties properties = new Properties(); properties.load(in); MixAll.properties2Object(properties, filtersrvConfig); System.out.println("load config properties file OK, " + file); in.close(); String port = properties.getProperty("listenPort"); if (port != null) { filtersrvConfig.setConnectWhichBroker(String.format("127.0.0.1:%s", port)); } } } // 0??? nettyServerConfig.setListenPort(0); nettyServerConfig.setServerAsyncSemaphoreValue(filtersrvConfig.getFsServerAsyncSemaphoreValue()); nettyServerConfig .setServerCallbackExecutorThreads(filtersrvConfig.getFsServerCallbackExecutorThreads()); nettyServerConfig.setServerWorkerThreads(filtersrvConfig.getFsServerWorkerThreads()); // ?? if (commandLine.hasOption('p')) { MixAll.printObjectProperties(null, filtersrvConfig); MixAll.printObjectProperties(null, nettyServerConfig); System.exit(0); } MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), filtersrvConfig); if (null == filtersrvConfig.getRocketmqHome()) { System.out.println("Please set the " + MixAll.ROCKETMQ_HOME_ENV + " variable in your environment to match the location of the RocketMQ installation"); System.exit(-2); } // ?Logback LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(filtersrvConfig.getRocketmqHome() + "/conf/logback_filtersrv.xml"); log = LoggerFactory.getLogger(LoggerName.FiltersrvLoggerName); // ?? final FiltersrvController controller = new FiltersrvController(filtersrvConfig, nettyServerConfig); boolean initResult = controller.initialize(); if (!initResult) { controller.shutdown(); System.exit(-3); } Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { private volatile boolean hasShutdown = false; private AtomicInteger shutdownTimes = new AtomicInteger(0); @Override public void run() { synchronized (this) { log.info("shutdown hook was invoked, " + this.shutdownTimes.incrementAndGet()); if (!this.hasShutdown) { this.hasShutdown = true; long begineTime = System.currentTimeMillis(); controller.shutdown(); long consumingTimeTotal = System.currentTimeMillis() - begineTime; log.info("shutdown hook over, consuming time total(ms): " + consumingTimeTotal); } } } }, "ShutdownHook")); return controller; } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } return null; }
From source file:com.moss.appkeep.tools.cache.AppkeepComponentCache.java
private static final void copyAndClose(InputStream in, OutputStream out) throws IOException { Throwable rootError = null;/*w ww . ja va 2 s . com*/ List<Throwable> cleanupErrors = new LinkedList<Throwable>(); try { byte[] buffer = new byte[100 * 1024]; for (int x = in.read(buffer); x != -1; x = in.read(buffer)) { out.write(buffer, 0, x); } } catch (Throwable t) { rootError = t; } finally { try { in.close(); } catch (Exception e) { cleanupErrors.add(e); } try { out.close(); } catch (Exception e) { cleanupErrors.add(e); } } if (rootError != null || cleanupErrors.size() > 0) { if (rootError != null) { throw new RuntimeException("Error", rootError); } else { String message = "Error"; if (cleanupErrors.size() > 0) { message += " (Cleanup errors too - see logs)"; for (Throwable next : cleanupErrors) { next.printStackTrace(); } } throw new RuntimeException(message, rootError); } } }
From source file:com.pispower.video.sdk.net.SimpleSSLSocketFactory.java
/** * Returns a SSlSocketFactory which trusts all certificates * //from w ww.ja va 2 s. c o m * @return SSLSocketFactory */ public static SSLSocketFactory getFixedSocketFactory() { SSLSocketFactory socketFactory; try { socketFactory = new SimpleSSLSocketFactory(getKeystore()); socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (Throwable t) { t.printStackTrace(); socketFactory = SSLSocketFactory.getSocketFactory(); } return socketFactory; }
From source file:gov.nih.nci.cadsrapi.dao.orm.CleanerDAO.java
private static void setFactory() { try {//from w w w. ja v a 2 s. com // Create the SessionFactory from hibernate.cfg.xml sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed ex.printStackTrace(); log.error("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
From source file:Main.java
/** Write the text provided to a File. * /*from w w w . ja v a2 s . c o m*/ * @param file the file to write to. * @param text the text to write. * @throws IOException */ public static void write(File file, String text) throws IOException { FileOutputStream out = null; try { file.getParentFile().mkdirs(); file.delete(); file.createNewFile(); out = new FileOutputStream(file); OutputStreamWriter writer = new OutputStreamWriter(out); writer.write(text); writer.flush(); } finally { try { out.close(); } catch (Throwable t) { t.printStackTrace(); } } }