private static String getOrCreateSession(int connectorId) { String sessionId = getConnectorSession(connectorId); if (null != sessionId) { return sessionId; // we're using the key to the session table rec as the session ID } String sql = "insert into " + TABLE_SESSION + "(" + "SESSION_PKEY," + COL_DATE_CREATE + ",CONNECTOR_KEY," + COL_DATE_EXPIRE + ") values (?,?,?,?)"; sessionId = Util.getGuid(); Timestamp now = new Timestamp(Gmt.getGmtDate().getTime()); ResourceFactory rf = Context.rf.get(); Sql.sqlExe( sql, new Object[] {sessionId, now, connectorId, getExpireDt(now)}, new int[] {Types.VARCHAR, Types.TIMESTAMP, Types.INTEGER, Types.TIMESTAMP}, rf); System.out.println(new Date() + ": Created new connector session -- " + sessionId); return sessionId; // we're using the key to the session table rec as the session ID }
@Override public void logWs(LogLevel severity, WsRequest req, String logText) { if (!isInit) { init(); } String sql = "insert into " + TABLE_LOG_WS + "( date, severity, machine_name, entity_code, action, description, request, millis ) " + "values ( getutcdate(),?,?,?,?,?,?,? )"; long millis = System.currentTimeMillis() - req.getStartTime(); Sql.sqlExe( sql, new Object[] { severity.toString(), Util.getHostName(), req.getCompId(), req.getVerb(), Str.truncate(logText, 2048), null == req.getXmlRequest() ? "" : Str.truncate(req.getXmlRequest(), 4096), millis }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER }, Context.rf.get().getLogRF()); }
@Override public void log(LogEntry le) { if (!isInit) { init(); } ResourceFactory rf = Context.rf.get(); if (le.level.ordinal() < rf.getLoggingLevel().ordinal()) { return; } prepLogEntry(le, rf); final LogContext lc = Log.logContext.get(); if (alreadyCalled.get() == 0) { try { alreadyCalled.set(1); String sql = "INSERT INTO " + TABLE_LOG + "(" + COL_SYSTEM + "," + COL_ENTITY_CODE + "," + COL_DATE + "," + COL_SEVERITY + "," + COL_MACHINE_NAME + "," + COL_THREAD_ID + "," + COL_KEY + "," + COL_DESC + ")" + "VALUES(?,?,getutcdate(),?,?,?,?,?)"; Sql.sqlExe( sql, new Object[] { le.serviceName, le.compId, le.level.toString(), Util.getHostName(), le.threadId, le.transKey == -1 ? null : le.transKey, le.desc.length() > MAX_LOG_DESC ? le.desc.substring(0, MAX_LOG_DESC) : le.desc }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR }, rf); } catch (Throwable t) { handleNonLoggableError( LogLevel.ERROR, le.serviceName, getClass(), "log", "Log to database was unsuccessful. " + buildNonLoggableDesc(le)); } finally { alreadyCalled.set(0); } } else { handleNonLoggableError( LogLevel.ERROR, le.serviceName, getClass(), "logImageProcessing", "Recursive logging call cannot log. Log data: " + buildNonLoggableDesc(le)); } }