Example usage for java.lang Throwable printStackTrace

List of usage examples for java.lang Throwable printStackTrace

Introduction

In this page you can find the example usage for java.lang Throwable printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.couragelabs.logging.LogAppenderTestFixture.java

/**
 * Use this method to test the appender. Run this first, then run
 * GlobalContextSocketAppender::main/*from   ww  w . ja  va 2 s .co  m*/
 *
 * @param args Program arguments. None are needed.
 * @throws java.lang.Exception if things go wrong
 */
@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
    ServerSocket serverSocket = new ServerSocket(PORT);

    System.out.println("Starting listen loop.");
    while (true) {
        try {
            final Socket clientSocket = serverSocket.accept();
            System.out.println("Received client connection.");
            new Thread() {
                @Override
                public void run() {
                    ObjectInputStream i = null;
                    try {
                        i = new ObjectInputStream(clientSocket.getInputStream());
                        while (true) {
                            Object received = i.readObject();
                            System.out.println(ToStringBuilder.reflectionToString(received,
                                    ToStringStyle.SHORT_PREFIX_STYLE));
                            Thread.sleep(1000);
                        }
                    } catch (EOFException e) {
                        System.out.println("Client closed connection.");
                    } catch (Throwable t) {
                        t.printStackTrace();
                    } finally {
                        if (i != null) {
                            try {
                                i.close();
                            } catch (Throwable t) {
                                t.printStackTrace();
                            }
                        }
                    }
                }
            }.start();
            Thread.sleep(1000);
        } catch (Throwable t) {
            t.printStackTrace();
        }
        System.out.println("Next...");
    }

}

From source file:coral.CoralStart.java

public static void main(String[] args) {

    loadSwtJar(null);/*  w w  w .j  av  a  2s . co m*/

    if (args.length == 0) {
        args = new String[] { "coral.properties" };
    }

    try {
        CoralHead.build(args);
    } catch (Throwable e) {
        lastresort("Problem starting Coral:", e);
        e.printStackTrace();
    }
}

From source file:disko.PDFDocument.java

public static void main(String[] args) {
    File dir = new File("/var/tmp/muriloq/mdc/selected");

    File[] pdfFiles = dir.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".pdf");
        }//ww  w . j  a v a  2 s. c om
    });

    for (File f : pdfFiles) {
        try {
            System.out.println(f.getName());
            PDFDocument pdf = new PDFDocument(f);
            pdf.getFullText();
            System.out.println(pdf.getFullText());
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}

From source file:com.daon.identityx.utils.GenerateAndroidFacet.java

public static void main(String[] args) {

    String androidKeystoreLocation = System.getProperty("ANDROID_KEYSTORE_LOCATION",
            DEFAULT_ANDROID_KEYSTORE_LOCATION);
    String androidKeystorePassword = System.getProperty("ANDROID_KEYSTORE_PASSWORD",
            DEFAULT_ANDROID_KEYSTORE_PASSWORD);
    String androidKeystoreCert = System.getProperty("ANDROID_KEYSTORE_CERT_NAME",
            DEFAULT_ANDROID_KEYSTORE_CERT_NAME);
    String hashingAlgorithm = System.getProperty("HASHING_ALGORITHM", DEFAULT_HASHING_ALGORITHM);

    try {/*from   w  ww .j  av a  2  s . c o m*/
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        File filePath = new File(androidKeystoreLocation);
        if (!filePath.exists()) {
            System.err.println(
                    "The filepath to the debug keystore could not be located at: " + androidKeystoreCert);
            System.exit(1);
        } else {
            System.out.println("Found the Android Studio keystore at: " + androidKeystoreLocation);
        }

        keyStore.load(new FileInputStream(filePath), androidKeystorePassword.toCharArray());
        System.out.println("Keystore loaded - password and location were OK");

        Certificate cert = keyStore.getCertificate(androidKeystoreCert);
        if (cert == null) {
            System.err.println(
                    "Could not location the certification in the store with the name: " + androidKeystoreCert);
            System.exit(1);
        } else {
            System.out.println("Certificate found in the store with name: " + androidKeystoreCert);
        }

        byte[] certBytes = cert.getEncoded();

        MessageDigest digest = MessageDigest.getInstance(hashingAlgorithm);
        System.out.println("Hashing algorithm: " + hashingAlgorithm + " found.");
        byte[] hashedCert = digest.digest(certBytes);
        String base64HashedCert = Base64.getEncoder().encodeToString(hashedCert);
        System.out.println("Base64 encoded SHA-1 hash of the certificate: " + base64HashedCert);
        String base64HashedCertRemoveTrailing = StringUtils.deleteAny(base64HashedCert, "=");
        System.out.println(
                "Add the following facet to the Facets file in order for the debug app to be trusted by the FIDO client");
        System.out.println("\"android:apk-key-hash:" + base64HashedCertRemoveTrailing + "\"");

    } catch (Throwable ex) {
        ex.printStackTrace();
    }

}

From source file:$.ServiceApplication.java

public static void main(String[] args) throws Exception {
        DateTimeZone.setDefault(DateTimeZone.UTC);

        ServiceApplication serviceApplication = new ServiceApplication(new GuiceBundleProvider());

        try {//from  w w  w  .ja va2s. c  o m
            serviceApplication.run(args);
        } catch (Throwable ex) {
            ex.printStackTrace();

            System.exit(1);
        }
    }

From source file:org.wso2.carbon.sample.pizzadelivery.client.PizzaDeliveryClient.java

public static void main(String[] args) {

    KeyStoreUtil.setTrustStoreParams();/*from  w  w  w  .j  a va2 s .c  o m*/
    String url = args[0];
    String username = args[1];
    String password = args[2];

    HttpClient httpClient = new SystemDefaultHttpClient();

    try {
        HttpPost method = new HttpPost(url);

        if (httpClient != null) {
            String[] xmlElements = new String[] {
                    "<mypizza:PizzaDeliveryStream xmlns:mypizza=\"http://samples.wso2.org/\">\n"
                            + "        <mypizza:PizzaDelivery>\n"
                            + "              <mypizza:OrderNo>0023</mypizza:OrderNo>\n"
                            + "              <mypizza:PaymentType>Card</mypizza:PaymentType>\n"
                            + "              <mypizza:Address>29BX Finchwood Ave, Clovis, CA 93611</mypizza:Address>\n"
                            + "        </mypizza:PizzaDelivery>\n" + "</mypizza:PizzaDeliveryStream>",
                    "<mypizza:PizzaDeliveryStream xmlns:mypizza=\"http://samples.wso2.org/\">\n"
                            + "        <mypizza:PizzaDelivery>\n"
                            + "              <mypizza:OrderNo>0024</mypizza:OrderNo>\n"
                            + "              <mypizza:PaymentType>Card</mypizza:PaymentType>\n"
                            + "              <mypizza:Address>2CYL Morris Ave, Clovis, CA 93611</mypizza:Address>\n"
                            + "        </mypizza:PizzaDelivery>\n" + "</mypizza:PizzaDeliveryStream>",
                    "<mypizza:PizzaDeliveryStream xmlns:mypizza=\"http://samples.wso2.org/\">\n"
                            + "        <mypizza:PizzaDelivery>\n"
                            + "              <mypizza:OrderNo>0025</mypizza:OrderNo>\n"
                            + "              <mypizza:PaymentType>Cash</mypizza:PaymentType>\n"
                            + "              <mypizza:Address>22RE Robinwood Ave, Clovis, CA 93611</mypizza:Address>\n"
                            + "        </mypizza:PizzaDelivery>\n" + "</mypizza:PizzaDeliveryStream>",
                    "<mypizza:PizzaDeliveryStream xmlns:mypizza=\"http://samples.wso2.org/\">\n"
                            + "        <mypizza:PizzaDelivery>\n"
                            + "              <mypizza:OrderNo>0026</mypizza:OrderNo>\n"
                            + "              <mypizza:PaymentType>Card</mypizza:PaymentType>\n"
                            + "              <mypizza:Address>29BX Finchwood Ave, Clovis, CA 93611</mypizza:Address>\n"
                            + "        </mypizza:PizzaDelivery>\n" + "</mypizza:PizzaDeliveryStream>" };

            try {
                for (String xmlElement : xmlElements) {
                    StringEntity entity = new StringEntity(xmlElement);
                    method.setEntity(entity);
                    if (url.startsWith("https")) {
                        processAuthentication(method, username, password);
                    }
                    httpClient.execute(method).getEntity().getContent().close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            Thread.sleep(500); // We need to wait some time for the message to be sent

        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:org.wso2.carbon.sample.atmstats.ATMTransactionStatsClient.java

public static void main(String[] args) throws XMLStreamException {
    System.out.println(xmlMsgs.get(1));
    System.out.println(xmlMsgs.get(2));
    System.out.println(xmlMsgs.get(3));
    KeyStoreUtil.setTrustStoreParams();//  ww  w.  j  ava 2s .  co  m
    String url = args[0];
    String username = args[1];
    String password = args[2];

    HttpClient httpClient = new SystemDefaultHttpClient();

    try {
        HttpPost method = new HttpPost(url);

        for (String xmlElement : xmlMsgs) {
            StringEntity entity = new StringEntity(xmlElement);
            method.setEntity(entity);
            if (url.startsWith("https")) {
                processAuthentication(method, username, password);
            }
            httpClient.execute(method).getEntity().getContent().close();
        }
        Thread.sleep(500); // We need to wait some time for the message to be sent

    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.haulmont.mp2xls.MessagePropertiesProcessor.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption(READ_OPT, "read", false, "read messages from project and save to XLS");
    options.addOption(WRITE_OPT, "write", false, "load messages from XLS and write to project");
    options.addOption(OVERWRITE_OPT, "overwrite", false,
            "overwrite existing messages by changed messages from XLS file");
    options.addOption(PROJECT_DIR_OPT, "projectDir", true, "project root directory");
    options.addOption(XLS_FILE_OPT, "xlsFile", true, "XLS file with translations");
    options.addOption(LOG_FILE_OPT, "logFile", true, "log file");
    options.addOption(LANGUAGES_OPT, "languages", true,
            "list of locales separated by comma, for example: 'de,fr'");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;/* w w w.  java  2 s . c  o m*/
    try {
        cmd = parser.parse(options, args);
        if ((!cmd.hasOption(READ_OPT) && !cmd.hasOption(WRITE_OPT)) || !cmd.hasOption(PROJECT_DIR_OPT)
                || !cmd.hasOption(XLS_FILE_OPT) || !cmd.hasOption(LANGUAGES_OPT)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Messages To/From XLS Convertor", options);
            System.exit(-1);
        }
        if (cmd.hasOption(READ_OPT) && cmd.hasOption(WRITE_OPT)) {
            System.out.println("Please provide either 'read' or 'write' option");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Messages To/From XLS Convertor", options);
            System.exit(-1);
        }

        Set<String> languages = getLanguages(cmd.getOptionValue(LANGUAGES_OPT));

        if (cmd.hasOption(READ_OPT)) {
            LocalizationsBatch localizationsBatch = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT));
            localizationsBatch.setScanLocalizationIds(languages);

            LocalizationBatchExcelWriter.exportToXls(localizationsBatch, cmd.getOptionValue(XLS_FILE_OPT));

        } else if (cmd.hasOption(WRITE_OPT)) {
            LocalizationsBatch sourceLocalization = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT));
            sourceLocalization.setScanLocalizationIds(languages);

            LocalizationsBatch fileLocalization = new LocalizationsBatch(cmd.getOptionValue(XLS_FILE_OPT),
                    cmd.getOptionValue(PROJECT_DIR_OPT));
            fileLocalization.setScanLocalizationIds(languages);

            LocalizationBatchFileWriter fileWriter = new LocalizationBatchFileWriter(sourceLocalization,
                    fileLocalization);
            String logFile = StringUtils.isNotEmpty(cmd.getOptionValue(LOG_FILE_OPT))
                    ? cmd.getOptionValue(LOG_FILE_OPT)
                    : "log.xls";
            fileWriter.process(logFile, cmd.hasOption(OVERWRITE_OPT));
        }
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:Test.java

public static void main(String[] args) throws Exception {
    AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(Paths.get("/asynchronous.txt"),
            StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
    CompletionHandler<Integer, Object> handler = new CompletionHandler<Integer, Object>() {

        @Override/*w ww.j  a  v  a  2s  .c om*/
        public void completed(Integer result, Object attachment) {
            System.out.println("Attachment: " + attachment + " " + result + " bytes written");
            System.out.println("CompletionHandler Thread ID: " + Thread.currentThread().getId());
        }

        @Override
        public void failed(Throwable e, Object attachment) {
            System.err.println("Attachment: " + attachment + " failed with:");
            e.printStackTrace();
        }
    };

    System.out.println("Main Thread ID: " + Thread.currentThread().getId());
    fileChannel.write(ByteBuffer.wrap("Sample".getBytes()), 0, "First Write", handler);
    fileChannel.write(ByteBuffer.wrap("Box".getBytes()), 0, "Second Write", handler);

}

From source file:alluxio.master.backcompat.BackwardsCompatibilityJournalGenerator.java

/**
 * Generates journal files to be used by the backwards compatibility test. The files are named
 * based on the current version defined in ProjectConstants.VERSION. Run this with each release,
 * and commit the created journal and snapshot into the git repository.
 *
 * @param args no args expected//from ww  w  .j  av a 2  s.c  o  m
 */
public static void main(String[] args) throws Exception {
    BackwardsCompatibilityJournalGenerator generator = new BackwardsCompatibilityJournalGenerator();
    new JCommander(generator, args);
    if (!LoginUser.get().getName().equals("root")) {
        System.err.printf("Journals must be generated as root so that they can be replayed by root%n");
        System.exit(-1);
    }
    File journalDst = new File(generator.getOutputDirectory(),
            String.format("journal-%s", ProjectConstants.VERSION));
    if (journalDst.exists()) {
        System.err.printf("%s already exists, delete it first%n", journalDst.getAbsolutePath());
        System.exit(-1);
    }
    File backupDst = new File(generator.getOutputDirectory(),
            String.format("backup-%s", ProjectConstants.VERSION));
    if (backupDst.exists()) {
        System.err.printf("%s already exists, delete it first%n", backupDst.getAbsolutePath());
        System.exit(-1);
    }
    MultiProcessCluster cluster = MultiProcessCluster.newBuilder(PortCoordination.BACKWARDS_COMPATIBILITY)
            .setClusterName("BackwardsCompatibility").setNumMasters(1).setNumWorkers(1).build();
    try {
        cluster.start();
        cluster.notifySuccess();
        cluster.waitForAllNodesRegistered(10 * Constants.SECOND_MS);
        for (TestOp op : OPS) {
            op.apply(cluster.getClients());
        }
        AlluxioURI backup = cluster.getMetaMasterClient()
                .backup(new File(generator.getOutputDirectory()).getAbsolutePath(), true).getBackupUri();
        FileUtils.moveFile(new File(backup.getPath()), backupDst);
        cluster.stopMasters();
        FileUtils.copyDirectory(new File(cluster.getJournalDir()), journalDst);
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        cluster.destroy();
    }
    System.out.printf("Artifacts successfully generated at %s and %s%n", journalDst.getAbsolutePath(),
            backupDst.getAbsolutePath());
}