List of usage examples for java.lang Exception toString
public String toString()
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * inserts into the status table to keep track of key placement status * * @param con DB connection object * @param hostSystem systems for authorized_keys replacement * @param userId user id/* ww w. j a va 2 s. co m*/ */ private static void insertSystemStatus(Connection con, HostSystem hostSystem, Long userId) { try { PreparedStatement stmt = con .prepareStatement("insert into status (id, status_cd, user_id) values (?,?,?)"); stmt.setLong(1, hostSystem.getId()); stmt.setString(2, hostSystem.getStatusCd()); stmt.setLong(3, userId); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:com.cprassoc.solr.auth.SolrAuthActionController.java
public static String doSavePropertiesAction(Properties props) { String result = "SUCCESS"; try {// ww w . j ava2 s . co m File f = new File(SolrAuthManager.SOLR_AUTH_PROPERTIES); OutputStream out = new FileOutputStream(f); props.store(out, "SolrAuthManager Properties"); } catch (Exception e) { result = "FAILURE: " + e.toString(); e.printStackTrace(); } return (result); }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * returns all key placement statuses// w w w . j a v a 2s . co m * * @param con DB connection object * @param userId user id */ private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) { List<HostSystem> hostSystemList = new ArrayList<HostSystem>(); try { PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystemList; }
From source file:com.gtwm.pb.servlets.ServletUtilMethods.java
/** * Return a string for logging purposes, of an exception's 'cause stack', * i.e. the original exception(s) thrown and stack trace, i.e. the methods * that the exception was thrown through. * // www. j a v a2 s .c o m * Called by logException */ private static String getExceptionCauses(Exception ex) { String errorMessage = ex.toString() + "\r\n"; if (ex.getCause() != null) { // Recursively find causes of exception errorMessage += " - Error was due to..."; Exception exceptionCause = ex; String causeIndent = " - "; errorMessage += causeIndent + ex.toString() + "\r\n"; while (exceptionCause.getCause() != null) { if (exceptionCause.getCause() instanceof Exception) { exceptionCause = (Exception) exceptionCause.getCause(); causeIndent += " - "; errorMessage += causeIndent + getExceptionCauses(exceptionCause); } } } // Include out relevant parts of the stack trace StackTraceElement[] stackTrace = ex.getStackTrace(); if (stackTrace.length > 0) { errorMessage += " - Stack trace:\r\n"; int nonGtwmClassesLogged = 0; for (StackTraceElement stackTraceElement : stackTrace) { if (!stackTraceElement.getClassName().startsWith("com.gtwm.")) { nonGtwmClassesLogged++; } // Only trace our own classes + a few more, stop shortly after // we get to java language or 3rd party classes if (nonGtwmClassesLogged < 15) { errorMessage += " " + stackTraceElement.toString() + "\r\n"; } } } return errorMessage; }
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * returns all key placement statuses/* ww w . ja va2 s . c o m*/ * * @param con DB connection object * @param userId user id */ private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) { List<HostSystem> hostSystemList = new ArrayList<>(); try { PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString(STATUS_CD)); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystemList; }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * returns key placement status of system * * @param systemId system id/* w w w. j a va2 s. c o m*/ * @param userId user id */ public static HostSystem getSystemStatus(Long systemId, Long userId) { Connection con = null; HostSystem hostSystem = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("select * from status where id=? and user_id=?"); stmt.setLong(1, systemId); stmt.setLong(2, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return hostSystem; }
From source file:com.airbop.library.simple.AirBopImageDownloader.java
static public Bitmap downloadBitmap(String url, Context context) { final AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); final HttpGet getRequest = new HttpGet(url); try {/*from w w w.j a v a 2 s . c om*/ HttpResponse response = client.execute(getRequest); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { displayMessage(context, "Error " + statusCode + " while retrieving bitmap from " + url); return null; } final HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = null; try { inputStream = entity.getContent(); final Bitmap bitmap = BitmapFactory.decodeStream(new FlushedInputStream(inputStream)); return bitmap; } finally { if (inputStream != null) { inputStream.close(); } entity.consumeContent(); } } } catch (Exception e) { // Could provide a more explicit error message for IOException or IllegalStateException getRequest.abort(); displayMessage(context, "Error while retrieving bitmap from " + url + e.toString()); } finally { if (client != null) { client.close(); } } return null; }
From source file:com.swingtech.commons.testing.JavaBeanTester.java
/** * Tests the get/set methods of the specified class. * /*from w w w . j a va 2 s .com*/ * @param <T> the type parameter associated with the class under test * @param clazz the Class under test * @param skipThese the names of any properties that should not be tested * @throws IntrospectionException thrown if the Introspector.getBeanInfo() method throws this exception * for the class under test */ public static <T> void test(final Class<T> clazz, final String... skipThese) throws IntrospectionException { final PropertyDescriptor[] props = Introspector.getBeanInfo(clazz).getPropertyDescriptors(); nextProp: for (PropertyDescriptor prop : props) { // Check the list of properties that we don't want to test for (String skipThis : skipThese) { if (skipThis.equals(prop.getName())) { continue nextProp; } } final Method getter = prop.getReadMethod(); final Method setter = prop.getWriteMethod(); if (getter != null && setter != null) { // We have both a get and set method for this property final Class<?> returnType = getter.getReturnType(); final Class<?>[] params = setter.getParameterTypes(); if (params.length == 1 && params[0] == returnType) { // The set method has 1 argument, which is of the same type as the return type of the get method, so we can test this property try { // Build a value of the correct type to be passed to the set method Object value = buildValue(returnType); // Build an instance of the bean that we are testing (each property test gets a new instance) T bean = clazz.newInstance(); // Call the set method, then check the same value comes back out of the get method setter.invoke(bean, value); final Object expectedValue = value; final Object actualValue = getter.invoke(bean); assertEquals(String.format("Failed while testing property %s", prop.getName()), expectedValue, actualValue); } catch (Exception ex) { fail(String.format("An exception was thrown while testing the property %s: %s", prop.getName(), ex.toString())); } } } } }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * set the initial status for selected systems * * @param systemSelectIds systems ids to set initial status * @param userId user id/*from ww w . j a v a 2s. c o m*/ * @param userType user type */ public static void setInitialSystemStatus(List<Long> systemSelectIds, Long userId, String userType) { Connection con = null; try { con = DBUtils.getConn(); //checks perms if to see if in assigned profiles // if (!Auth.MANAGER.equals(userType)) { // systemSelectIds = SystemDB.checkSystemPerms(con, systemSelectIds, userId); // } //deletes all old systems deleteAllSystemStatus(con, userId); for (Long hostSystemId : systemSelectIds) { HostSystem hostSystem = new HostSystem(); hostSystem.setId(hostSystemId); hostSystem.setStatusCd(HostSystem.INITIAL_STATUS); //insert new status insertSystemStatus(con, hostSystem, userId); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.tethrnet.manage.db.SystemStatusDB.java
/** * returns the first system that authorized keys has not been tried * * @param userId user id/* w w w .j a v a 2s .c o m*/ * @return hostSystem systems for authorized_keys replacement */ public static HostSystem getNextPendingSystem(Long userId) { HostSystem hostSystem = null; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from status where (status_cd like ? or status_cd like ? or status_cd like ?) and user_id=? order by id asc"); stmt.setString(1, HostSystem.INITIAL_STATUS); stmt.setString(2, HostSystem.AUTH_FAIL_STATUS); stmt.setString(3, HostSystem.PUBLIC_KEY_FAIL_STATUS); stmt.setLong(4, userId); ResultSet rs = stmt.executeQuery(); if (rs.next()) { hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return hostSystem; }