Example usage for java.security NoSuchAlgorithmException printStackTrace

List of usage examples for java.security NoSuchAlgorithmException printStackTrace

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:it.cnr.isti.thematrix.scripting.modules.MatrixFileInput.java

/**
 * Download CSV data from the DBMS in case a valid CSV file is not found but we have a DB mapping for that
 * filename. //  www.  j  ava2 s  .c  o  m
 * 
 * TODO Maybe a file that is not downloadable should not reach here at all.
 * 
 * @param fileMapper class providing mapping information for DM-downloadable files
 * 
 * @return true if the file was successfully downloaded.
 */
private boolean openFileDownloadFromDB(MappingManager fileMapper) {

    //      If we get here, we know the CSV file is not found or invalid
    boolean fileOK = false; // true if we were able to download the CSV, it becomes the return value
    Collection<String> mappedFileNames = null; // the list of names defined in the mapping.xml config
    boolean workDone = false; // true only after successful creation

    /************** new code -- interaction with the Database ******************/

    try { // check if the file belongs in those defined by our mapping
        mappedFileNames = MappingSingleton.getInstance().mapping.getDatasetNames();
    } catch (Exception e1) {
        LogST.logP(0, "MatrixFileInput.openFile() - ERROR - exception while reading the mapping file "
                + e1.toString());
        e1.printStackTrace();
    }

    if (mappedFileNames == null || !mappedFileNames.contains(baseName)) {
        LogST.logP(0,
                "MatrixFileInput.openFileDownLoadFromDB() - ERROR - file " + baseName + " has no mapping");
        throw new Error("MatrixFileInput.openFileDownLoadFromDB() No mapping for file");
        //         System.exit(0); // FIXME we should throw exception
    }

    // if it is there, start routine to retrieve it
    try {
        // when retrieving, encode the values with the recoding tables // NOT YET
        // and dump to the CSV
        fileMapper.createDataset(new ArrayList<String>(Arrays.asList(baseName)));
        workDone = true;
    }
    /*************** Real work ends here *******************/
    catch (NoSuchAlgorithmException e) {
        LogST.logP(0, "MatrixFileInput.openFile() - MD5 encoding algorithm not found");
        e.printStackTrace();
    } catch (JAXBException e) {
        LogST.logP(0, "MatrixFileInput.openFile() - JAXB error");
        e.printStackTrace();
    } catch (IOException e) {
        LogST.logP(0, "MatrixFileInput.openFile() - file not found");
        e.printStackTrace();
    } catch (SyntaxErrorInMappingException e) {
        LogST.logP(0, "MatrixFileInput.openFile() - malformed file mapping");
        e.printStackTrace();
    } catch (SQLException e) {
        LogST.logP(0, "MatrixFileInput.openFile() - SQL error");
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        LogST.logP(0, "MatrixFileInput.openFile() - JDBC driver not found");
        e.printStackTrace();
    } catch (JDBCConnectionException e) {
        LogST.logP(0, "MatrixFileInput.openFile() - can't open JDBC connection");
        e.printStackTrace();
    } catch (UnsupportedDatabaseDriverException e) {
        LogST.logP(0, "MatrixFileInput.openFile() - JDB driver needed is not supported");
        e.printStackTrace();
    }

    if (workDone) { // only if we did not get any exception check for the CSV

        /**
         * TODO refactor, the Mapping Manager should return this information; for now we check again
         */
        try {
            fileOK = fileMapper.checkCSVFileExistence(baseName);
        } catch (Exception e) {
            LogST.logP(0, "MatrixFileInput, exception " + e.toString() + " for file " + baseName
                    + " in setup() not dowloaded");
        }
        ;

        LogST.logP(0, "MatrixFileInput.openFile() - DBMS download done for file" + baseName + " at time "
                + new java.util.Date().toString());

        /**************
         * END of interaction with the Database ***********************
         * 
         * now if we really got the data, we are fine; but if a query for manual execution was produced instead, no
         * file to open --> the script execution cannot continue; we should gracefully generate any more required
         * data and exit;
         * 
         * in the future, this can be implemented by launching an internal exception, caught in the interpreter, or
         * floated to the outermost eval(), whose catch will scan all the modules in the script, triggering the
         * openFile() of all FileInput modules
         */
    }

    // 3 possible cases: a) csv downloaded from DB b) csv not downloaded, query generated c) error occurred
    // let the user know in case b) he has to run the query manually
    if (!fileOK && Dynamic.ignoreDBConnection) {
        LogST.logP(0, "MatrixFileInput - no DBMS connection - query dumped to text file\n"
                + "Please execute the query, place the result in the directory of IAD files, validate the files.");
    }
    // case a) returns true, b) c) return false.
    return fileOK;
}

From source file:com.manzdagratiano.gobbledygook.Gobbledygook.java

/**
 * @brief   //from ww w  . ja  va2 s .  c  o  m
 * @return  
 */
private byte[] getSeedSHA(View view) {
    EditText password = (EditText) findViewById(R.id.password);
    byte[] seedSHA = null;
    MessageDigest hash = null;
    try {
        hash = MessageDigest.getInstance(Env.SHA256);
        seedSHA = hash.digest(password.getText().toString().getBytes());
    } catch (NoSuchAlgorithmException e) {
        Log.e(Env.LOG_CATEGORY, "ERROR: Caught " + e);
        e.printStackTrace();
    }

    return seedSHA;
}

From source file:edu.mit.mobile.android.locast.data.MediaSync.java

public MediaSync() {
    super();/*from   w  ww .j  av a 2s  . c  om*/

    try {
        mDigest = MessageDigest.getInstance("SHA-1");
    } catch (final NoSuchAlgorithmException e) {
        e.printStackTrace();
        mDigest = null;
    }
}

From source file:cvut.fel.mobilevoting.murinrad.communications.Connection.java

/**
 * Initializes the HTTPs connection/*from   w  ww.ja  v a 2 s . com*/
 * 
 * @param sslPort
 *            the number of the port the server should be listening for
 *            SSL/TLS connections
 */
public void InitializeSecure(int sslPort) {
    if (sslPort != -1) {
        SSLSocketFactory sslf = null;
        SSLSocket s = null;
        port = sslPort;
        try {
            // notifyOfProggress(false);
            KeyStore trusted = KeyStore.getInstance(KeyStore.getDefaultType());
            trusted.load(null, null);

            sslf = new MySSLSocketFactory(trusted);
            Log.w("Android mobile voting", "1");
            sslf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            Log.w("Android mobile voting", "2");
            BasicHttpParams params = new BasicHttpParams();
            Log.w("Android mobile voting", "3");
            HttpConnectionParams.setConnectionTimeout(params, 500);
            Log.w("Android mobile voting", "4");
            s = (SSLSocket) sslf.connectSocket(sslf.createSocket(), server.getAddress(), sslPort, null, 0,
                    params);
            if (exc) {
                SSLSession ssls = null;
                ssls = s.getSession();
                final javax.security.cert.X509Certificate[] x = ssls.getPeerCertificateChain();

                for (int i = 0; i < x.length; i++) {

                    parent.mHandler.post(new Runnable() {

                        @Override
                        public void run() {

                            try {
                                parent.askForTrust(getThumbPrint(x[0]), instance);
                            } catch (NoSuchAlgorithmException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (CertificateEncodingException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (final Exception ex) {
                                parent.mHandler.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        parent.showToast(ex.toString());

                                    }

                                });
                                Log.w("Android Mobile Voting", "400 Error");
                                parent.finish();
                            }

                        }
                    });

                }

            }

            s.startHandshake();

            Scheme https = new Scheme("https", sslf, sslPort);

            schemeRegistry.register(https);
            usingScheme = "https";
            port = sslPort;
            if (!exc)
                retrieveQuestions();
        } catch (final Exception ex) {
            parent.mHandler.post(new Runnable() {

                @Override
                public void run() {
                    parent.showToast(ex.toString());

                }

            });
            // Log.w("Android Mobile Voting", "400 Error");
            parent.finish();

        }
    } else {
        parent.mHandler.post(new Runnable() {

            @Override
            public void run() {
                parent.showNoSSLDialog(instance);

            }

        });
    }

}

From source file:com.ibm.caas.CaaSResource.java

/**
 * Pass throughout CERTs [workaround]//from   ww  w  .  j  av a 2 s . c  o m
 */
public void relaxHostChecking() {

    // Override SSL Trust manager without certificate chains validation
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        public void checkClientTrusted(X509Certificate[] certs, String authType) {
        }

        public void checkServerTrusted(X509Certificate[] certs, String authType) {
        }

    } };

    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        // Hostname verification. 
        HostnameVerifier allHostsValid = new HostnameVerifier() {
            /**
             * Verify that the host name is an acceptable match with the server's authentication scheme.
             * @hostname - the host name
             * @session - SSLSession used on the connection to host
             * @return true if the host name is acceptable
             */
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
        // Sets the default HostnameVerifier by all-trusting host verifier.
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (KeyManagementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.apache.openaz.xacml.pdp.test.custom.TestCustom.java

/**
 * This function generates the public/private key pair. Should never have to call this again, this was
 * called once to generate the keys. They were saved into the testsets/custom/datatype-function
 * sub-directory./*from w w w  .  j av a  2s. com*/
 */
public void generateKeyPair() {
    //
    // Generate a RSA private/public key pair
    //
    KeyPairGenerator keyGen;
    try {
        keyGen = KeyPairGenerator.getInstance(ALGORITHM);
    } catch (NoSuchAlgorithmException e) {
        logger.error("failed to generate keypair: " + e);
        return;
    }
    keyGen.initialize(1024);
    final KeyPair key = keyGen.generateKeyPair();
    //
    // Save the keys to disk
    //
    Path file = Paths.get(this.directory, PRIVATEKEY_FILE);
    try (ObjectOutputStream os = new ObjectOutputStream(Files.newOutputStream(file))) {
        os.writeObject(key.getPrivate());
    } catch (IOException e) {
        e.printStackTrace();
    }
    file = Paths.get(this.directory, PUBLICKEY_FILE);
    try (ObjectOutputStream os = new ObjectOutputStream(Files.newOutputStream(file))) {
        os.writeObject(key.getPublic());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.connectsdk.service.AirPlayService.java

String digestAuthentication(String md5) {
    try {/*from  w  w  w.  j av a 2  s  . c o  m*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digest = md.digest(md5.getBytes());
        StringBuffer sb = new StringBuffer();
        for (byte b : digest) {
            sb.append(String.format("%02x", b & 0xFF));
        }
        return sb.toString();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:edu.mit.mobile.android.locast.sync.MediaSync.java

/**
 * Creates a new Media Sync engine./*from w  ww.j  a  v  a  2s.c o  m*/
 */
public MediaSync() {
    super();

    try {
        mDigest = MessageDigest.getInstance("SHA-1");
    } catch (final NoSuchAlgorithmException e) {
        e.printStackTrace();
        mDigest = null;
    }
}

From source file:org.kawanfw.commons.client.http.HttpTransferOne.java

/**
 * If called, self signed SSL certificates will be accepted
 *//*  www  . ja v  a 2  s  .  c o  m*/
private void acceptSelfSignedSslCert() {
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        public void checkClientTrusted(X509Certificate[] certs, String authType) {
        }

        public void checkServerTrusted(X509Certificate[] certs, String authType) {
        }
    } };

    // Install the all-trusting trust manager
    SSLContext sc = null;
    try {
        sc = SSLContext.getInstance("SSL");

        sc.init(null, trustAllCerts, new java.security.SecureRandom());

        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

        // Create all-trusting host name verifier
        HostnameVerifier allHostsValid = new HostnameVerifier() {
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };

        // Install the all-trusting host verifier
        HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }

}