Example usage for java.lang Exception toString

List of usage examples for java.lang Exception toString

Introduction

In this page you can find the example usage for java.lang Exception toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.owncloud.android.authenticator.EasySSLSocketFactory.java

private static SSLContext createEasySSLContext() {
    Log.d(TAG, "Creating Easy SSL Context");
    try {/* w  w  w .ja  v  a2 s . c  om*/
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
        return context;
    } catch (Exception er) {
        Log.e(TAG, er.getMessage() + "");
        throw new HttpClientError(er.toString());
    }
}

From source file:com.priocept.jcr.server.UploadServlet.java

public static void writeToFile(String fileName, InputStream iStream, boolean createDir, String servletRealPath)
        throws IOException {
    String me = "FileUtils.WriteToFile";
    if (fileName == null) {
        throw new IOException(me + ": filename is null");
    }/*from   w w  w .  ja  v  a  2s.c o  m*/
    if (iStream == null) {
        throw new IOException(me + ": InputStream is null");
    }

    File theFile = new File(servletRealPath + "temp_files/" + fileName);

    // Check if a file exists.
    if (theFile.exists()) {
        String msg = theFile.isDirectory() ? "directory" : (!theFile.canWrite() ? "not writable" : null);
        if (msg != null) {
            throw new IOException(me + ": file '" + fileName + "' is " + msg);
        }
    }

    // Create directory for the file, if requested.
    if (createDir && theFile.getParentFile() != null) {
        theFile.getParentFile().mkdirs();
    }

    // Save InputStream to the file.
    BufferedOutputStream fOut = null;
    try {
        fOut = new BufferedOutputStream(new FileOutputStream(theFile));
        byte[] buffer = new byte[32 * 1024];
        int bytesRead = 0;
        while ((bytesRead = iStream.read(buffer)) != -1) {
            fOut.write(buffer, 0, bytesRead);
        }
    } catch (Exception e) {
        throw new IOException(me + " failed, got: " + e.toString());
    } finally {
        close(iStream, fOut);
    }
}

From source file:com.pinterest.terrapin.controller.TerrapinControllerServiceImpl.java

private static Exception getException(Exception e) {
    if (e instanceof ControllerException) {
        return e;
    } else {//  w w  w.  ja  v  a  2  s. com
        return new ControllerException(e.toString(), ControllerErrorCode.OTHER);
    }
}

From source file:msuresh.raftdistdb.TestAtomix.java

public static void createCluster(String test, int nodesInCluster)
        throws InterruptedException, ExecutionException {
    InitPortNumber();//from  w ww  . j  a  v a  2  s  .c o m
    try {
        List<Address> members = new ArrayList<>();
        for (int i = 0; i < nodesInCluster; i++) {
            Address addr = new Address("localhost", portId++);
            members.add(addr);
        }
        CompletableFuture<Integer> future = new CompletableFuture<>();
        Map atomixList;
        atomixList = new HashMap();
        for (Address a : members) {
            ServerSetup s = new ServerSetup(members, a, atomixList, future);
            s.start();
        }
        future.get();
        UpdatePortNumber();

        if (test.compareTo("leaderFailure") == 0) {
            for (Object s : atomixList.keySet()) {
                LeaderReelection l = new LeaderReelection((Address) s, (CopycatServer) atomixList.get(s), true);
                l.start();
            }
            Thread.sleep(20000);
            //                for(Object s : atomixList.keySet()){
            //                    CopycatServer cs = (CopycatServer)atomixList.get(s);
            //                    while(cs.isOpen())
            //                        Thread.sleep(1000);
            //                    System.out.println("printing" + cs.toString());
            //                }
            System.out.println(
                    "Leader Reelection test is done. Program might not close properly due to a bug in Atomix. Follow manual instructions to close the process and sockets.");
        } else if (test.compareTo("replicationTest") == 0) {
            CopycatClient client = CopycatClient.builder(members).withTransport(new NettyTransport()).build();
            client.open().join();
            System.out.println("Adding a testkey with testval to the cluster ..");
            client.submit(new PutCommand("testkey1", "testval")).get();
            List<LeaderReelection> reelectionList = new ArrayList<>();
            System.out.println("Crashing leader to trigger a reelection .. ");
            for (Object s : atomixList.keySet()) {

                LeaderReelection l = new LeaderReelection((Address) s, (CopycatServer) atomixList.get(s),
                        false);
                l.start();
                reelectionList.add(l);
            }

            //                for(LeaderReelection l : reelectionList){
            //                    l.future.get();
            //                    
            //                }
            //                client = CopycatClient.builder(members)
            //                        .withTransport(new NettyTransport())
            //                        .build();
            //                client.open().join();
            System.out.println(" Polling the cluster for testkey ..");
            Object str = client.submit(new GetQuery("testkey1")).get();
            System.out.println("The cluster returned (which should be 'testval'):" + (String) str);
            System.out.println("closing open servers..");
            for (Object s : atomixList.keySet()) {
                CopycatServer cs = (CopycatServer) atomixList.get(s);

                if (cs.isOpen())
                    cs.close();

            }
        }
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }

}

From source file:com.app.mvc.http.ext.EasySSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {//from w  w w . j a  v  a 2 s  . c  o  m
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new X509TrustManager() {

            @Override
            public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
                    throws CertificateException {

            }

            @Override
            public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
                    throws CertificateException {

            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        } }, null);
        return context;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new HttpClientError(e.toString());
    }
}

From source file:eionet.gdem.dcm.business.WorkqueueManager.java

/**
 * Reset active jobs on startup.//w  w  w. j av  a2 s . c  om
 */
public static void resetActiveJobs() {
    try {
        jobDao.changeJobStatusByStatus(Constants.XQ_DOWNLOADING_SRC, Constants.XQ_RECEIVED);
        jobDao.changeJobStatusByStatus(Constants.XQ_PROCESSING, Constants.XQ_RECEIVED);
    } catch (Exception e) {
        LOGGER.error("Error reseting active jobs: " + e.toString());
    }

}

From source file:net.sf.jabref.sql.SQLUtil.java

/**
 * Return a message raised from a SQLException
 *
 * @param ex The SQLException raised//  w ww.j a va 2  s  .c  o  m
 */
public static String getExceptionMessage(Exception ex) {
    String msg;
    if (ex.getMessage() == null) {
        msg = ex.toString();
    } else {
        msg = ex.getMessage();
    }
    return msg;
}

From source file:controllers.Onto.java

public static Result getLastReport(String database) {
    authorizeCrossRequests();/*  www.ja va  2s  .c  o  m*/
    try {
        DB db = mongoConnect(database);
        DBCollection reportColl = db.getCollection("report");
        String response = reportColl.findOne().toString();
        mongoClose();
        return ok(response);
    } catch (Exception e) {
        return ok(e.toString());
    }
}

From source file:flex.messaging.services.http.httpclient.EasySSLProtocolSocketFactory.java

private static SSLContext createEasySSLContext() {
    try {//from ww w  .  jav a2  s  .  c  o m
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
        return context;
    } catch (Exception e) {
        if (Trace.ssl) {
            Trace.trace(e.getMessage());
        }
        throw new HttpClientError(e.toString());
    }
}

From source file:bala.padio.Settings.java

public static ArrayList<ChannelModel> GetChannelList() {
    // update channel list
    String defaultLanguage = getConfig(ConfDefaultLanguage, null);
    SharedPreferences preference = MainActivity.AppContext.getSharedPreferences(defaultLanguage,
            Context.MODE_PRIVATE);
    Map<String, ?> channelList = preference.getAll();
    ArrayList<ChannelModel> list = new ArrayList<>();
    for (Map.Entry<String, ?> channel : channelList.entrySet()) {
        try {//from  w  w w.jav a 2s  .c  o  m
            ChannelModel cm = new ChannelModel(channel.getValue().toString());
            if (cm.id != null) {
                list.add(cm);
            }
        } catch (Exception ex) {
            Log.e(TAG, ex.toString());
        }
    }
    return list;
}