List of usage examples for java.lang Exception toString
public String toString()
From source file:de.itomig.itoplib.GetItopData.java
public static XmlResult getDataFromItopServer(String selectExpression) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder;// ww w. j a v a2 s . com XmlResult x = new XmlResult(); try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e1) { x.error = "error: " + e1.getMessage(); return x; } AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); try { HttpPost request = new HttpPost(); String req = createUrlWithCredentials(selectExpression); // do not log password, log only search expression if (debug) Log.i(TAG, "expr.=" + selectExpression); request.setURI(new URI(req)); HttpResponse response = client.execute(request); String status = response.getStatusLine().toString(); if (debug) Log.i(TAG, "status: " + status); if (status.contains("200") && status.contains("OK")) { // request worked fine, retrieved some data InputStream instream = response.getEntity().getContent(); x.doc = builder.parse(instream); x.error = ""; } else // some error in http response { Log.e(TAG, "Get data - http-ERROR: " + status); x.error = "http-error, status " + status; } } catch (Exception e) { // Toast does not work in background task Log.e(TAG, "Get data - " + e.toString()); x.error = "Get data - " + e.toString(); } finally { client.close(); // needs to be done for androidhttpclient if (debug) Log.i(TAG, "...finally.. get data finished"); } return x; }
From source file:com.keybox.manage.db.SessionAuditDB.java
/** * returns terminal logs for user session for host system * * @param con DB connection//from w ww . j a va 2s. c o m * @param sessionId session id * @return session output for session */ public static List<HostSystem> getHostSystemsForSession(Connection con, Long sessionId) { List<HostSystem> hostSystemList = new ArrayList<>(); try { PreparedStatement stmt = con.prepareStatement( "select distinct instance_id, system_id from terminal_log where session_id=?"); stmt.setLong(1, sessionId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("system_id")); hostSystem.setInstanceId(rs.getInt("instance_id")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception ex) { log.error(ex.toString(), ex); } return hostSystemList; }
From source file:com.tethrnet.manage.db.UserDB.java
/** * returns users based on sort order defined * @param sortedSet object that defines sort order * @return sorted user list//from w w w.ja v a 2s . c o m */ public static SortedSet getUserSet(SortedSet sortedSet) { ArrayList<User> userList = new ArrayList<User>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from users where enabled=true " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { User user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setAuthType(rs.getString("auth_type")); user.setUserType(rs.getString("user_type")); userList.add(user); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(userList); return sortedSet; }
From source file:gdt.data.grain.Support.java
/** * Copy the icon file from the class path into the target directory. * @param handler the class/* w ww . ja v a 2 s . c om*/ * @param icon$ the name of the icon file. * @param directory$ the icons directory path . */ public static void addHandlerIcon(Class<?> handler, String icon$, String directory$) { try { File iconFile = new File(directory$ + "/" + icon$); if (iconFile.exists()) return; iconFile.createNewFile(); InputStream is = handler.getResourceAsStream(icon$); FileOutputStream fos = new FileOutputStream(iconFile); byte[] b = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(b)) != -1) { fos.write(b, 0, bytesRead); } is.close(); fos.close(); } catch (Exception e) { Logger.getLogger(gdt.data.grain.Support.class.getName()).severe(e.toString()); } }
From source file:org.arasthel.almeribus.utils.LoadFromWeb.java
public static ResultTiempo calcularTiempo(Context context, int parada, int linea) { ResultTiempo result = new ResultTiempo(); if (!isConnectionEnabled(context)) { Log.d("AlmeriBus", "No hay conexin"); result.setTiempo(ERROR_IO);/*from w w w . j a va 2 s . c o m*/ } try { loadCookie(); URL url = new URL(QUERY_ADDRESS_TIEMPO_PARADA + linea + "/" + parada + "/" + "3B5579C8FFD6"); URLConnection connection = url.openConnection(); connection.setConnectTimeout(10000); connection.setReadTimeout(15000); connection.setRequestProperty("REFERER", "http://m.surbus.com/tiempo-espera/"); connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); connection.setRequestProperty("X-Requested-With", "XMLHttpRequest"); connection.setRequestProperty("Cookie", "ASP.NET_SessionId=" + cookie); Scanner scan = new Scanner(connection.getInputStream()); StringBuilder strBuilder = new StringBuilder(); while (scan.hasNextLine()) { strBuilder.append(scan.nextLine()); } scan.close(); Log.d("Almeribus", strBuilder.toString()); JSONObject json = new JSONObject(strBuilder.toString()); boolean isSuccessful = json.getBoolean("success"); int type = json.getInt("waitTimeType"); if (isSuccessful && type > 0) { int time = json.getInt("waitTime"); if (time == Integer.MAX_VALUE) { time = NO_DATOS; } if (time <= 0) { time = 0; } result.setTiempo(time); result.setTiempoTexto(json.getString("waitTimeString")); } else { result.setTiempo(NO_DATOS); } } catch (Exception e) { Log.d("Almeribus", e.toString()); result.setTiempo(ERROR_IO); return result; } return result; }
From source file:com.keybox.manage.db.SessionAuditDB.java
/** * deletes audit history for users if after time set in properties file * * @param con DB connection//from w w w . j a v a 2 s. c om */ public static void deleteAuditHistory(Connection con) { try { //delete logs with no terminal entries PreparedStatement stmt = con.prepareStatement( "delete from session_log where id not in (select session_id from terminal_log)"); stmt.execute(); //take today's date and subtract how many days to keep history Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, (-1 * Integer.parseInt(AppConfig.getProperty("deleteAuditLogAfter")))); //subtract java.sql.Date date = new java.sql.Date(cal.getTimeInMillis()); stmt = con.prepareStatement("delete from session_log where session_tm < ?"); stmt.setDate(1, date); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:com.tethrnet.manage.db.UserDB.java
/** * returns all admin users based on sort order defined * @param sortedSet object that defines sort order * @return sorted user list/*from w ww . jav a 2s . c om*/ */ public static SortedSet getAdminUserSet(SortedSet sortedSet) { ArrayList<User> userList = new ArrayList<User>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from users where enabled=true and user_type like '" + User.ADMINISTRATOR + "' " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { User user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setAuthType(rs.getString("auth_type")); user.setUserType(rs.getString("user_type")); userList.add(user); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(userList); return sortedSet; }
From source file:com.keybox.manage.db.AuthDB.java
/** * updates password for admin using auth token */// w w w . j a v a 2 s .co m public static boolean updatePassword(Auth auth) { boolean success = false; Connection con = null; try { con = DBUtils.getConn(); String prevSalt = getSaltByAuthToken(con, auth.getAuthToken()); PreparedStatement stmt = con .prepareStatement("select * from users where auth_token like ? and password like ?"); stmt.setString(1, auth.getAuthToken()); stmt.setString(2, EncryptionUtil.hash(auth.getPrevPassword() + prevSalt)); ResultSet rs = stmt.executeQuery(); if (rs.next()) { String salt = EncryptionUtil.generateSalt(); stmt = con.prepareStatement("update users set password=?, salt=? where auth_token like ?"); stmt.setString(1, EncryptionUtil.hash(auth.getPassword() + salt)); stmt.setString(2, salt); stmt.setString(3, auth.getAuthToken()); stmt.execute(); success = true; } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return success; }
From source file:com.keybox.manage.db.UserDB.java
/** * updates existing user//from w ww . j a v a2 s. c o m * @param user user object */ public static void updateUserNoCredentials(User user) { Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "update users set first_nm=?, last_nm=?, email=?, username=?, user_type=? where id=?"); stmt.setString(1, user.getFirstNm()); stmt.setString(2, user.getLastNm()); stmt.setString(3, user.getEmail()); stmt.setString(4, user.getUsername()); stmt.setString(5, user.getUserType()); stmt.setLong(6, user.getId()); stmt.execute(); DBUtils.closeStmt(stmt); if (User.ADMINISTRATOR.equals(user.getUserType())) { PublicKeyDB.deleteUnassignedKeysByUser(con, user.getId()); } } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); }
From source file:com.tethrnet.manage.db.SessionAuditDB.java
/** * returns a list of terminal sessions for session id * * @param sessionId session id/*from w ww .j av a2 s. c o m*/ * @return terminal sessions with host information */ public static SessionAudit getSessionsTerminals(Long sessionId) { //get db connection Connection con = null; SessionAudit sessionAudit = new SessionAudit(); String sql = "select * from session_log, users where users.id= session_log.user_id and session_log.id = ? "; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); stmt.setLong(1, sessionId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { sessionAudit.setId(rs.getLong("session_log.id")); sessionAudit.setSessionTm(rs.getTimestamp("session_tm")); sessionAudit.setUser(UserDB.getUser(con, rs.getLong("user_id"))); sessionAudit.setHostSystemList(getHostSystemsForSession(con, sessionId)); } DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } //close db connection DBUtils.closeConn(con); return sessionAudit; }