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.keybox.manage.util.KeyStoreUtil.java

/**
 * set secret in keystore// w ww. j  a v a 2s. c o m
 *
 * @param alias  keystore secret alias
 * @param secret keystore entry
 */
public static void setSecret(String alias, byte[] secret) {

    KeyStore.ProtectionParameter protectionParameter = new KeyStore.PasswordProtection(KEYSTORE_PASS);
    try {
        SecretKeySpec secretKey = new SecretKeySpec(secret, 0, secret.length, "AES");
        KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(secretKey);
        keyStore.setEntry(alias, secretKeyEntry, protectionParameter);
    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }
}

From source file:com.keybox.manage.util.KeyStoreUtil.java

/**
 * delete existing and create new keystore
 *///w  w w  .  jav  a  2s . c o  m
public static void resetKeyStore() {
    File file = new File(keyStoreFile);
    try {
        if (file.exists()) {
            FileUtils.forceDelete(file);
        }
    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }
    //create new keystore
    initializeKeyStore();
}

From source file:com.melchor629.musicote.Utils.java

/**
 * HostTest/*w  w w .j  a va 2  s  .c om*/
 * Sirve para comprobar si est encendido el PC
 * Nothing to see here...
 *
 * @param host HOST IP
 * @return int response
 */
public static int HostTest(String host) {
    int response = 0;

    try {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        URL urlhttp = new URL("http://" + host);
        HttpURLConnection http = (HttpURLConnection) urlhttp.openConnection();
        http.setReadTimeout(1000);
        response = http.getResponseCode();
        http.disconnect();
    } catch (Exception e) {
        Log.e("Comprobando", "Excepcin HTTPURL: " + e.toString() + " " + host);
    }

    return response;
}

From source file:App.classes.BD_Connection.java

/**
 * public Connection AbrirConexion() {//w  ww  .  ja  va2s  .  c o m
 *
 * Connection con = null; try { Class.forName("com.mysql.jdbc.Driver");
 * String urlOdbc = "jdbc:mysql://127.0.0.1:3306/db_admin"; con =
 * (java.sql.DriverManager.getConnection(urlOdbc, "root", ""));
 *
 * } catch (Exception e) {
 *
 *
 * //e.printStackTrace(); JOptionPane.showMessageDialog(null, "Ha sido
 * imposible establecer la conexion!"); } return con; }
 *
 * /**
 * cerramos la conexion en la bd
 *
 * @param con
 */
/*
        
        
public void CerrarConexion(Connection con) {
try {
    if (con != null) {
        con.close();
    }
} catch (SQLException e) {
        
    JOptionPane.showMessageDialog(null, "Ha sido imposible cerrar la conexion!");
}
}
        
 */
public static void initialize_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
     */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://localhost:3306/mysql");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "5000");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "10000");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        //propiedades.load(new FileInputStream("src/config/datasource_config.properties"));
        Singleton_App.dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:application.bbdd.pool.java

public static void inicializa_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*/*from w  w  w.  ja v a2 s  .  co  m*/
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
    */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://127.0.0.1:3306/application");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "500");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "1234");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "100");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        //propiedades.load(new FileInputStream("src/config/datasource_config.properties"));
        dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:application.bbdd.pool.java

public static void realizaConsulta2() {
    Connection conexion = null;/*w w w.ja v  a2 s .  c o m*/
    Statement sentencia = null;
    ResultSet rs = null;

    try {
        conexion = getConexion();
        sentencia = conexion.createStatement();
        rs = sentencia.executeQuery("select count(*) from db");
        rs.next();
        JOptionPane.showMessageDialog(null, "El numero de bd es: " + rs.getInt(1));
        logStatistics();

    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    } finally {
        try {
            rs.close();
            sentencia.close();
            liberaConexion(conexion);
        } catch (Exception fe) {
            JOptionPane.showMessageDialog(null, fe.toString());
        }
    }
}

From source file:application.bbdd.pool.java

public static void realizaConsulta1() {
    Connection conexion = null;//from  ww w.  ja v a 2  s .  com
    Statement sentencia = null;
    ResultSet rs = null;

    try {
        // BasicDataSource nos reserva una conexion y nos la devuelve
        conexion = getConexion();
        sentencia = conexion.createStatement();
        rs = sentencia.executeQuery("select count(*) from user");
        rs.next();
        JOptionPane.showMessageDialog(null, "El numero de usuarios es: " + rs.getInt(1));
        logStatistics();

    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.toString());
    } finally {
        try {
            rs.close();
            sentencia.close();
            liberaConexion(conexion);
        } catch (Exception fe) {
            JOptionPane.showMessageDialog(null, fe.toString());
        }
    }
}

From source file:Main.java

public static Map<String, Object> getProperties(Element paramElement) {
    HashMap<String, Object> localHashMap = new HashMap<String, Object>();
    Element[] arrayOfElement = getChildrenByName(paramElement, "property");
    for (int i = 0; i < arrayOfElement.length; ++i) {
        String str1 = arrayOfElement[i].getAttribute("name");
        String str2 = arrayOfElement[i].getAttribute("type");
        String str3 = getText(arrayOfElement[i]);
        try {//w  w  w  .  j a  va 2 s .c o  m
            Class<?> localClass = Class.forName(str2);
            Constructor<?> localConstructor = localClass.getConstructor(new Class[] { String.class });
            Object localObject = localConstructor.newInstance(new Object[] { str3 });
            localHashMap.put(str1, localObject);
        } catch (Exception localException) {
            System.err.println(
                    "Unable to parse property '" + str1 + "'='" + str3 + "': " + localException.toString());
        }
    }
    return localHashMap;
}

From source file:Main.java

public static void storeBuildPropertyBatched(Context c, String propArgument) {
    StringBuilder propName = new StringBuilder("");
    StringBuilder propValue = new StringBuilder("");
    StringBuilder commandLine = new StringBuilder("");
    boolean isValue = false;
    for (int i = 0; i < propArgument.length(); i++) {
        char ch = propArgument.charAt(i);
        if (ch == '=' && isValue == false) {
            isValue = true;/*www  . j av a2  s  .  c o  m*/
        } else if (ch == ';') {
            // Store the build property
            if (isBuildPropertyAvaliable(c, propName.toString())) {
                // Change build property manually.
                commandLine.append("busybox sed -i \"s/" + propName.toString() + "=.*/" + propName.toString()
                        + "=" + propValue.toString() + "/g\" /system/build.prop ; ");
            } else {
                // Write new build property manually.
                commandLine.append("echo " + propName.toString() + "=" + propValue.toString()
                        + " >> /system/build.prop ; ");
            }

            // Clear the value
            isValue = false;
            propName = new StringBuilder("");
            propValue = new StringBuilder("");
        } else {
            if (isValue)
                propValue.append(ch);
            else
                propName.append(ch);
        }
    }

    // Execute the process
    Process p = null;
    try {
        remountSystem(c);

        p = runSuCommandAsync(c, commandLine.toString());
        p.waitFor();
    } catch (Exception d) {
        Log.e("Helper", "Failed to batch store build.prop. errcode:" + d.toString());
    }
}

From source file:com.msbmsb.gogogeocode.GoGoGeocode.java

/**
 * Given the string of an address, return a Coordinates object that contains
 * the coordinate information extracted from the API response
 * @param address the string representation of a physical address
 * @return Coordinates object containing coordinate information from response
 *//*  w w w.java 2  s.c om*/
public static Coordinates geocode(String address) {
    Coordinates coords = new Coordinates();

    String requestUrl = "";
    try {
        requestUrl = buildURL(address);
    } catch (UnsupportedEncodingException uee) {
        uee.printStackTrace();
    }

    GetMethod getMethod = new GetMethod(requestUrl);
    getMethod.setFollowRedirects(true);

    try {
        httpClient.executeMethod(getMethod);

        // build the response object
        GoogleGeocodeResponse response = new GoogleGeocodeResponse(
                IOUtils.toString(getMethod.getResponseBodyAsStream(), getMethod.getRequestCharSet()));
        /**
         * Parsing can be done via Dom Document as well: 
         * GoogleGeocodeResponse response = new GoogleGeocodeResponse(getMethod.getResponseBodyAsStream());
         */

        // only change coordinates from default if request successful
        if (response.successful()) {
            coords = response.getCoords();
        }
    } catch (Exception e) {
        System.out.println("Geocode exception: " + e.toString());
    } finally {
        getMethod.abort();
        getMethod.releaseConnection();
    }

    return coords;
}