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:org.openflamingo.uploader.util.ResourceUtils.java

/**
 *  ? ? . ?    ? ?  ? ? ? ?  ?  ? ? ? <tt>null</tt>?? ? ? 
 * ? ? .//from   w w  w  . j  av a2  s. co  m
 *
 * @return ? ?
 */
private static ClassLoader getDefaultClassLoader() {
    ClassLoader cl = null;
    try {
        cl = Thread.currentThread().getContextClassLoader();
    } catch (Throwable e) {
        e.printStackTrace();
        System.out.println(
                "? ? ? ??   .  ? ? .");
    }
    if (cl == null) {
        //  ? ? ? ? -> ? ?? ? ?  
        cl = ResourceUtils.class.getClassLoader();
    }
    return cl;
}

From source file:fm.last.hadoop.tools.ReplicationPolicyFixer.java

public static int verifyBlockPlacement(LocatedBlock lBlk, short replication, NetworkTopology cluster) {
    try {//  ww  w .ja  va2s  . co  m
        Class<?> replicationTargetChooserClass = Class
                .forName("org.apache.hadoop.hdfs.server.namenode.ReplicationTargetChooser");
        Method verifyBlockPlacementMethod = replicationTargetChooserClass.getDeclaredMethod(
                "verifyBlockPlacement", LocatedBlock.class, Short.TYPE, NetworkTopology.class);
        verifyBlockPlacementMethod.setAccessible(true);

        return (Integer) verifyBlockPlacementMethod.invoke(null, lBlk, new Short(replication), cluster);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof RuntimeException) {
            cause.printStackTrace();
            throw (RuntimeException) cause;
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:br.com.artesuzana.app.DataGenerator.java

public static void generate() {

    try {/*from w  w  w  .  j ava  2s. c  om*/
        new HibernateUtil().iniciarSessionFactory();

        // if (true) return;
        final IProductRepository prdRepo = ApplicationContext.get().getBean(IProductRepository.class);
        final ICategoryRepository catRepo = ApplicationContext.get().getBean(ICategoryRepository.class);
        final IUserRepository userRepo = ApplicationContext.get().getBean(IUserRepository.class);

        if (catRepo.list().isEmpty()) {

            final Category madeira = new Category("Madeira");
            final Category bolsa = new Category("Bolsa");
            final Category sabonete = new Category("Sabonete");
            final Category bisquit = new Category("Bisquit");
            final Category tecido = new Category("Tecido");
            final Category especial = new Category("Especial");
            final Category roupa = new Category("Roupa");
            final Category toalha = new Category("Toalha");

            catRepo.save(madeira);
            catRepo.save(bolsa);
            catRepo.save(sabonete);
            catRepo.save(bisquit);
            catRepo.save(tecido);
            catRepo.save(especial);
            catRepo.save(roupa);
            catRepo.save(toalha);

            final Product portaBijuteria = new Product();
            portaBijuteria.setName("Porta Bijuteria Aveludado");
            portaBijuteria.setPrice(new BigDecimal(30));
            portaBijuteria.setDescription("Porta bijuterias com divisrias com fundos e lados aveludados");
            portaBijuteria.setCategory(madeira);

            final Transacao transacao = new Transacao();
            transacao.begin();

            final ProductImage imgPortaBijuteria = new ProductImage();
            imgPortaBijuteria.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/porta-bijuteria.jpeg")));

            final ProductImage imgPortaBijuteria2 = new ProductImage();
            imgPortaBijuteria2.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/porta-bijuteria2.jpeg")));

            final ProductImage imgPortaBijuteria3 = new ProductImage();
            imgPortaBijuteria3.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/porta-bijuteria3.jpeg")));

            final Product bolsaDiagonal = new Product();
            bolsaDiagonal.setName("Bolsa Diagonal");
            bolsaDiagonal.setPrice(new BigDecimal(55));
            bolsaDiagonal
                    .setDescription("Bolsa feita em tecido de qualidade com faixa diagonal em grande estilo");
            bolsaDiagonal.setCategory(bolsa);

            final ProductImage imgBolsaDiagonal = new ProductImage();
            imgBolsaDiagonal.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/bolsa-diagonal.jpeg")));

            final Product bolsaPrimavera = new Product();
            bolsaPrimavera.setName("Bolsa Primavera");
            bolsaPrimavera.setPrice(new BigDecimal(65));
            bolsaPrimavera.setDescription(
                    "Bolsa que deixar qualquer mulher mais atraente em qualquer poca do ano, inclusive na Primavera");
            bolsaPrimavera.setCategory(bolsa);

            final ProductImage imgBolsaPrimavera = new ProductImage();
            imgBolsaPrimavera.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/bolsa-primavera.jpeg")));

            final Product portaBolachas = new Product();
            portaBolachas.setName("Porta Bolachas com Biscuit");
            portaBolachas.setPrice(new BigDecimal(20));
            portaBolachas.setDescription("Porta bolachas de vidro com tampa detalhada em biscuit ");
            portaBolachas.setCategory(bisquit);

            final ProductImage imgPortaBolachas = new ProductImage();
            imgPortaBolachas.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/porta-oculos.jpeg")));

            final Product arvoreNatal = new Product();
            arvoreNatal.setName("?rvore de Natal");
            arvoreNatal.setPrice(new BigDecimal(25));
            arvoreNatal.setDescription("?rvore de natal feita de tecido");
            arvoreNatal.setCategory(especial);

            final ProductImage imgArvoreNatal = new ProductImage();
            imgArvoreNatal.setImage(IOUtils.toByteArray(ArteSuzana.class.getClassLoader()
                    .getResourceAsStream("images/products/arvore-natal.jpeg")));

            bolsaPrimavera.addToImages(imgBolsaPrimavera);
            portaBijuteria.addToImages(imgPortaBijuteria);
            portaBijuteria.addToImages(imgPortaBijuteria2);
            portaBijuteria.addToImages(imgPortaBijuteria3);
            bolsaDiagonal.addToImages(imgBolsaDiagonal);
            portaBolachas.addToImages(imgPortaBolachas);
            arvoreNatal.addToImages(imgArvoreNatal);

            prdRepo.save(portaBijuteria);
            prdRepo.save(bolsaDiagonal);
            prdRepo.save(bolsaPrimavera);
            prdRepo.save(portaBolachas);
            prdRepo.save(arvoreNatal);

            transacao.commit();

            final User chico = new User();
            chico.setUsername("chico");
            chico.setName("Francisco");
            chico.setEmail("fsilva1992@gmail.com");
            chico.setPassword(CriptografiaUtil.crypt("12345"));

            final User douglas = new User();
            douglas.setUsername("douglas");
            douglas.setName("Douglas Lucio");
            douglas.setEmail("dlucio10@gmail.com");
            douglas.setPassword(CriptografiaUtil.crypt("12345"));

            final User vitor = new User();
            vitor.setUsername("vitinho");
            vitor.setName("Vitor Orsolini");
            vitor.setEmail("orsolini.vitor@gmail.com");
            vitor.setPassword(CriptografiaUtil.crypt("12345"));

            userRepo.save(chico);
            userRepo.save(vitor);
            userRepo.save(douglas);

            final Post post = new Post();
            post.setAuthor(chico);
            post.setTitle("Produto muito bom!");
            post.setText("Este produto  fantastic!! recomendo a todos.");
            post.setPage(bolsaPrimavera.getPage());

            final Post post2 = new Post();
            post2.setAuthor(douglas);
            post2.setTitle("Minha me que faz!");
            post2.setText("Gente essa bolsa  minha me quem faz..  demais.. eu uso ela todos os dias!!");
            post2.setPage(bolsaPrimavera.getPage());

            ApplicationContext.get().getBean(IPostRepository.class).save(post);
            ApplicationContext.get().getBean(IPostRepository.class).save(post2);
        }
    } catch (final Throwable e) {
        e.printStackTrace();
    }

}

From source file:com.plugin.gcm.OneSignalPush.java

private static void callbackSuccess(CallbackContext callbackContext, JSONObject jsonObject) {
    if (jsonObject == null) { // in case there are no data
        jsonObject = new JSONObject();
    }/*from  www .j  a  va  2s . com*/

    if (jsonObject.has("payload")) {
        try {
            JSONObject payload = jsonObject.getJSONObject("payload");
            if (payload.has("additionalData")) {
                payload.put("additionalData", new JSONObject(payload.getString("additionalData")));
                jsonObject.put("payload", payload);
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, jsonObject);
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
}

From source file:de.mpg.escidoc.util.Util.java

public static void loadProperties() {
    ClassLoader loader = null;/*from  w w  w . j a  v  a  2  s. co m*/
    InputStream in = null;
    try {
        if (loader == null) {
            loader = Util.class.getClassLoader();
        }
        InputStream is = loader.getResourceAsStream(PROPERTIES_FILE);
        if (is != null) {
            properties = new Properties();
            properties.load(is);
        }
    } catch (Exception e) {
        properties = null;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (Throwable ignore) {
                ignore.printStackTrace();
            }
        }
    }
}

From source file:ru.tiis.library.service.impl.GDriveService.java

public static String uploadNewBook(java.io.File bookPdf, String clientHost) {

    try {/*from   www .ja va  2 s .  com*/
        init();
        // authorization
        log.info("http transport and data store factory initialized.");
        log.info("Authorizing application");
        Credential credential = authorize(clientHost);
        log.info("Authorization passed");
        // set up the global Drive instance
        drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME)
                .build();
        log.info("Drive instance set");

        // run commands
        log.info("Starting Simple Media Upload");
        boolean useDirectUpload = true;
        File uploadedFile = uploadFile(useDirectUpload, bookPdf);

        log.info("Setting up permissions");
        createPermissions(uploadedFile.getId());

        String fileId = uploadedFile.getId();
        File bookFile = drive.files().get(fileId)
                .setFields("id,name,webContentLink,shared,mimeType,webViewLink").execute();
        log.info("File name : " + bookFile.getName());
        log.info("File mime type : " + bookFile.getMimeType());
        log.info("File web content link : " + bookFile.getWebContentLink());
        log.info("File web view link : " + bookFile.getWebViewLink());
        log.info("File is shared : " + bookFile.getShared());

        log.info("Success!");
        return bookFile.getWebViewLink();
    } catch (IOException e) {
        log.error(e.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {

    }

    return StringPool.BLANK;
}

From source file:com.ebay.erl.mobius.core.MobiusJobRunner.java

/**
 * Submit the <code>tool</code> with the specified <code>conf</code> and <code>args</code>.
 * <p>/*from   w  ww .  j  av  a2s  . c  o m*/
 * 
 * <code>tool</code> can be {@link MobiusJob} or any instance of {@link org.apache.hadoop.util.Tool}.
 * If <code>tool</code> is an instance of {@link MobiusJob}, it will be submitted using
 * {@link JobControl}.  If it's not an instance of {@link MobiusJob}, then it will be submitted
 * using <code>ToolRunner.run(conf, tool, args)</code> directly.
 * 
 */
public static int run(Configuration conf, Tool tool, String[] args) throws Exception {
    if (tool instanceof MobiusJob) {
        MobiusJob mobiusJob = (MobiusJob) tool;

        int exit;
        try {
            exit = ToolRunner.run(conf, tool, args);
        } catch (Throwable t) {
            t.printStackTrace();
            exit = 1;
        }

        if (exit == 0) {
            // setup correctly

            JobControl control = new JobControl("Mobius Job [" + tool.getClass().getCanonicalName() + "]");

            Collection<Job> allJobs = mobiusJob.jobTopology.values();
            control.addJobs(allJobs);

            LOGGER.info(allJobs.size() + " Hadoop job(s) to run.");

            Thread t = new Thread(control);
            t.start();

            StatusCheckingThread statusChecking = new StatusCheckingThread(tool, allJobs, control);
            statusChecking.start();

            statusChecking.join();
            LOGGER.info(" All job(s) done.");

            statusChecking.complete();

            int exitCode = control.getFailedJobs().size() == 0 ? 0 : 1;

            mobiusJob.deleteTempFiles();
            return exitCode;
        } else {
            mobiusJob.deleteTempFiles();
            return exit;
        }

    } else {
        return ToolRunner.run(conf, tool, args);
    }
}

From source file:com.aw.support.reflection.MethodInvoker.java

public static Method getMethod(Object target, String methodName) throws Throwable {
    Class cls = target.getClass();
    try {/*from  ww w .  j  a  v a2  s.co m*/
        return cls.getMethod(methodName);
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:com.future.pos.util.SystemInitializer.java

private static void initializeLicenses() {
    try {//  ww w  .jav  a 2  s . c  o  m
        if (License.isValid() && configVarsInitialized) {
            mapObjects();
            mapDatabaseColumns();
        } else {
            System.out.println("FATAL ERROR: License is not valid.");
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:org.wso2.developerstudio.appcloud.utils.client.HttpsJaggeryClient.java

@SuppressWarnings("deprecation")
public static HttpClient wrapClient(HttpClient base, String urlStr) {
    try {/*from  w  ww .j  a va 2s  .co m*/
        SSLContext ctx = SSLContext.getInstance("TLS");
        X509TrustManager tm = new X509TrustManager() {

            public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
            }

            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        };
        ctx.init(null, new TrustManager[] { tm }, null);
        SSLSocketFactory ssf = new SSLSocketFactory(ctx);
        ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        ClientConnectionManager ccm = new ThreadSafeClientConnManager();
        SchemeRegistry sr = ccm.getSchemeRegistry();
        URL url = new URL(urlStr);
        int port = url.getPort();
        if (port == -1) {
            port = 443;
        }
        String protocol = url.getProtocol();
        if ("https".equals(protocol)) {
            if (port == -1) {
                port = 443;
            }
        } else if ("http".equals(protocol)) {
            if (port == -1) {
                port = 80;
            }
        }
        sr.register(new Scheme(protocol, ssf, port));

        return new DefaultHttpClient(ccm, base.getParams());
    } catch (Throwable ex) {
        ex.printStackTrace();
        log.error("Trust Manager Error", ex);
        return null;
    }
}