private void writeLogInfo(MsgObject msgObject, String result, String message, int iRetries) { Util.logger.info( this.getClass().getName() + ".getMessages() - " + "Respone Code: [" + result + "]. " + message + ", Details: MO_ID: [" + msgObject.getMo_id() + "] UserID: [" + msgObject.getUserid() + "] ServiceID: [" + msgObject.getServiceid() + "] Keyword: [" + msgObject.getKeyword() + "] RequestID: [" + msgObject.getRequestid() + "] CommandCode: [" + msgObject.getKeyword() + "] RequestTime: [" + SOAPConstants.convertTimestampToString(msgObject.getTTimes(), SOAPConstants.DATE_TIME) + "] Online Retry countdown: " + iRetries); }
protected Collection getMessages(MsgObject msgObject, Keyword keyword) throws Exception { int iRetries = 3; int iTimeout = SOAPConstants.RETRIES_TIME; Collection messages = new ArrayList(); String result = ""; if (!isOKConfig()) { msgObject.setUsertext(Constants._prop.getProperty("MESSAGE_SYSTEM_OVERLOAD")); msgObject.setMsgtype(CHARGE_BACK); messages.add(new MsgObject(msgObject)); return messages; } if (!isAllowOperator(msgObject.getMobileoperator())) { msgObject.setUsertext( Constants._prop .getProperty( "ADS_ONLY_SUPPORT_FOR_OPERATOR", "Hien tai he thong chi ho tro cho thue bao Mobifone") .trim()); msgObject.setMsgtype(CHARGE_BACK); messages.add(new MsgObject(msgObject)); return messages; } if (!msgObject.getKeyword().equalsIgnoreCase(msgObject.getUsertext().split(" ")[0].trim())) { msgObject.setUsertext(INVALID_SYNTAX); msgObject.setMsgtype(CHARGE_BACK); messages.add(new MsgObject(msgObject)); return messages; } KeywordWhiteList keywordWhiteList = WSConfigLoader.getInstance() .getKeywordWhiteListByKeywordServiceID(keyword.getKeyword() + msgObject.getServiceid()); if (keywordWhiteList != null && !inWhiteList(keywordWhiteList.getWhiteList(), msgObject.getUserid())) { msgObject.setUsertext(keywordWhiteList.getMsgReturn()); msgObject.setMsgtype(keywordWhiteList.getMsgType()); messages.add(new MsgObject(msgObject)); return messages; } else { keywordWhiteList = WSConfigLoader.getInstance() .getKeywordWhiteListByKeywordServiceID( keyword.getKeyword() + msgObject.getServiceid() + msgObject.getMobileoperator()); if (keywordWhiteList != null && !inWhiteList(keywordWhiteList.getWhiteList(), msgObject.getUserid())) { msgObject.setUsertext(keywordWhiteList.getMsgReturn()); msgObject.setMsgtype(keywordWhiteList.getMsgType()); messages.add(new MsgObject(msgObject)); return messages; } } WSConfig wsConfig = WSConfigLoader.getInstance().getWSConfigByCpCode(FIDOL_CP_CODE); if (wsConfig == null) { Util.logger.warn( this.getClass().getName() + ".getMessages(): URL WebService for CPCODE:[" + FIDOL_CP_CODE + "] Not Found"); msgObject.setUsertext(Constants._prop.getProperty("MESSAGE_SYSTEM_OVERLOAD")); msgObject.setMsgtype(CHARGE_BACK); messages.add(new MsgObject(msgObject)); return messages; } while (iRetries > 0) { try { result = sendMessageMO(msgObject, wsConfig); // 1 transaction OK! if ("1".equals(result)) { writeLogInfo(msgObject, result, "Send OK!", iRetries); return null; } else if ("-7".equals(result)) { writeLogError(msgObject, result, "Username & Password does not match", iRetries); msgObject.setMsgNotes( "Respone Code: [" + result + "]. Username & Password does not match"); add2SMSSendFailed(msgObject); msgObject.setUsertext(Constants._prop.getProperty("MESSAGE_SYSTEM_OVERLOAD")); msgObject.setMsgtype(CHARGE_BACK); messages.add(new MsgObject(msgObject)); return messages; } else if ("-6".equals(result)) { writeLogError(msgObject, result, "System Busy", iRetries); msgObject.setMsgNotes("Respone Code: [" + result + "]. System Busy"); add2SMSSendFailed(msgObject); msgObject.setUsertext(Constants._prop.getProperty("MESSAGE_SYSTEM_OVERLOAD")); msgObject.setMsgtype(CHARGE_BACK); messages.add(new MsgObject(msgObject)); return messages; } else { writeLogError(msgObject, result, "Going For Retry, Sleeping", iRetries); msgObject.setMsgNotes("Respone Code: [" + result + "]. Going For Retry, Sleeping"); iRetries--; Thread.sleep(iTimeout * 1000); continue; } } catch (Exception e) { String message = ""; message = (e != null) ? e.getMessage() : "NULL"; Util.logger.error( this.getClass().getName() + ".getMessages()@" + "ERROR!: " + message + ". Got Respone Code: [" + result + "], Going For Retry, Sleeping,Details: MO_ID: [" + msgObject.getMo_id() + "] UserID: [" + msgObject.getUserid() + "] ServiceID: [" + msgObject.getServiceid() + "] Keyword: [" + msgObject.getKeyword() + "] RequestID: [" + msgObject.getRequestid() + "] CommandCode: [" + msgObject.getKeyword() + "] RequestTime: [" + SOAPConstants.convertTimestampToString( msgObject.getTTimes(), SOAPConstants.DATE_TIME) + "] Online Retry countdown: " + iRetries); msgObject.setMsgNotes("Respone Code: [" + result + "]. " + message); iRetries--; Thread.sleep(iTimeout * 1000); continue; } } add2SMSSendFailed(msgObject); String returnMessage = Constants._prop.getProperty("MESSAGE_SYSTEM_OVERLOAD"); msgObject.setUsertext(returnMessage); msgObject.setMsgtype(CHARGE_BACK); messages.add(msgObject); return messages; }
private static BigDecimal add2SMSSendFailed(MsgObject msgObject) { BigDecimal result = msgObject.getRequestid(); Util.logger.info( className + ".add2SMSSendFailed():" + msgObject.getUserid() + "@" + msgObject.getUsertext()); String tablename = "sms_receive_error"; String sSQLInsert = "insert into " + tablename + "(REQUEST_ID,USER_ID,SERVICE_ID,MOBILE_OPERATOR,COMMAND_CODE,INFO,RECEIVE_DATE,RESPONDED,CPID, NOTES)" + " values(?,?,?,?,?,?,?,?,?,?)"; Connection connection = null; PreparedStatement ps = null; DBPool dbpool = new DBPool(); try { connection = dbpool.getConnectionGateway(); ps = connection.prepareStatement(sSQLInsert); // ps.setBigDecimal(1, msgObject.getRequestid()); ps.setBigDecimal(1, new BigDecimal(msgObject.getMo_id())); ps.setString(2, msgObject.getUserid()); ps.setString(3, msgObject.getServiceid()); ps.setString(4, msgObject.getMobileoperator()); ps.setString(5, msgObject.getKeyword()); ps.setString(6, msgObject.getUsertext()); ps.setTimestamp(7, msgObject.getTTimes()); ps.setInt(8, 0); ps.setInt(9, msgObject.getCpid()); String notes = msgObject.getMsgnotes(); if (notes != null && notes.length() > 255) { notes = notes.substring(0, 254); } ps.setString(10, notes); if (ps.executeUpdate() != 1) { Util.logger.error( className + ".add2SMSSendFailed():" + msgObject.getUserid() + ":" + msgObject.getUsertext() + ":ps.executeUpdate failed"); result = new BigDecimal(-1); } ps.close(); } catch (SQLException e) { Util.logger.error( className + ".add2SMSSendFailed():" + msgObject.getUserid() + ":" + msgObject.getUsertext() + ":Error add row from sms receive error:" + e.toString()); result = new BigDecimal(-1); } catch (Exception e) { Util.logger.error( className + ".add2SMSSendFailed():" + msgObject.getUserid() + ":" + msgObject.getUsertext() + ":Error add row from sms receive error:" + e.toString()); result = new BigDecimal(-1); } finally { dbpool.cleanup(connection); } return result; }