use of j.http.JHttpContext in project JFramework by gugumall.
the class SSONotifier method logout.
/**
* 通知注销
* @param client
* @param globalSessionId
* @param userId
* @param userIp
*/
public void logout(Client client, String globalSessionId, String userId, String userIp) {
long now = SysUtil.getNow();
String md5 = JUtilMD5.MD5EncodeToHex(client.getPassport() + now + globalSessionId + userId + userIp);
String url = client.getUrlDefault() + client.getLogoutInterface();
if (url.indexOf("?") > 0) {
url += "&" + Constants.SSO_MD5_STRING + "=" + md5;
} else {
url += "?" + Constants.SSO_MD5_STRING + "=" + md5;
}
url += "&" + Constants.SSO_TIME + "=" + now;
url += "&" + Constants.SSO_GLOBAL_SESSION_ID + "=" + globalSessionId;
url += "&" + Constants.SSO_USER_ID + "=" + userId;
url += "&" + Constants.SSO_USER_IP + "=" + userIp;
url += "&" + Constants.SSO_PASSPORT + "=" + Permission.getSSOPassport();
int loop = 0;
while (loop < 3) {
// 最多尝试3次
loop++;
try {
JHttpContext context = http.get(null, httpClient, url);
if (context.getStatus() == 200) {
String response = context.getResponseText();
context.finalize();
context = null;
// log.log("notify "+url+",client response:"+response,-1);
break;
}
} catch (Exception e) {
log.log("failed to notify " + url, Logger.LEVEL_ERROR);
log.log(e, Logger.LEVEL_ERROR);
}
}
}
use of j.http.JHttpContext in project JFramework by gugumall.
the class DB method setUpdatable.
/**
* @param dbname
* @param mirrorUuid
* @param updatable
* @throws Exception
*/
public static void setUpdatable(String dbname, String mirrorUuid, boolean updatable) throws Exception {
Database db = DB.database(dbname);
DBMirror mirror = db.mirror(mirrorUuid);
String url = mirror.monitor;
if (url.indexOf("?") > 0)
url += "&request=setUpdatable";
else
url += "?request=setUpdatable";
url += "&db_name=" + dbname;
url += "&mirror_uuid=" + mirrorUuid;
url += "&updatable=" + updatable;
// System.out.println(url);
JHttpContext context = jhttp.get(null, jclient, url, SysConfig.sysEncoding);
if (context == null || context.getStatus() != 200 || Constants.AUTH_FAILED.equals(context.getResponseText()) || Constants.INVOKING_FAILED.equals(context.getResponseText())) {
if (context != null) {
context.finalize();
context = null;
}
throw new Exception("failed to setUpdatable of - " + dbname + "," + mirrorUuid + "," + updatable + " on " + url);
}
context.finalize();
context = null;
}
use of j.http.JHttpContext in project JFramework by gugumall.
the class DB method setInsertable.
/**
* @param dbname
* @param mirrorUuid
* @param insertable
* @throws Exception
*/
public static void setInsertable(String dbname, String mirrorUuid, boolean insertable) throws Exception {
Database db = DB.database(dbname);
DBMirror mirror = db.mirror(mirrorUuid);
String url = mirror.monitor;
if (url.indexOf("?") > 0)
url += "&request=setInsertable";
else
url += "?request=setInsertable";
url += "&db_name=" + dbname;
url += "&mirror_uuid=" + mirrorUuid;
url += "&insertable=" + insertable;
// System.out.println(url);
JHttpContext context = jhttp.get(null, jclient, url, SysConfig.sysEncoding);
if (context == null || context.getStatus() != 200 || Constants.AUTH_FAILED.equals(context.getResponseText()) || Constants.INVOKING_FAILED.equals(context.getResponseText())) {
if (context != null) {
context.finalize();
context = null;
}
throw new Exception("failed to setInsertable of - " + dbname + "," + mirrorUuid + "," + insertable + " on " + url);
}
context.finalize();
context = null;
}
use of j.http.JHttpContext in project JFramework by gugumall.
the class DB method setAvail.
/**
* @param dbname
* @param mirrorUuid
* @param avail
* @throws Exception
*/
public static void setAvail(String dbname, String mirrorUuid, boolean avail) throws Exception {
Database db = DB.database(dbname);
DBMirror mirror = db.mirror(mirrorUuid);
Client client = SSOConfig.getSsoClientByIdOrUrl(SysConfig.getSysId());
String url = mirror.monitor;
if (url == null || url.equals("")) {
url = client.getUrlDefault() + "DataSource.service";
} else if (!url.matches(JUtilString.RegExpHttpUrl)) {
if (url.startsWith("/")) {
url = client.getUrlDefault() + url.substring(1);
} else {
url = client.getUrlDefault() + url;
}
}
if (url.indexOf("?") > 0)
url += "&request=setAvail";
else
url += "?request=setAvail";
url += "&db_name=" + dbname;
url += "&mirror_uuid=" + mirrorUuid;
url += "&avail=" + avail;
// System.out.println(url);
JHttpContext context = jhttp.get(null, jclient, url, SysConfig.sysEncoding);
if (context == null || context.getStatus() != 200 || Constants.AUTH_FAILED.equals(context.getResponseText()) || Constants.INVOKING_FAILED.equals(context.getResponseText())) {
if (context != null) {
context.finalize();
context = null;
}
throw new Exception("failed to setAvail of - " + dbname + "," + mirrorUuid + "," + avail + " on " + url);
}
context.finalize();
context = null;
}
use of j.http.JHttpContext in project JFramework by gugumall.
the class DBMirror method available.
/**
* @return
*/
boolean available() {
if (shutdown) {
status = DBMirror.STATUS_UNAVAILABLE;
return false;
}
if (!avail) {
status = DBMirror.STATUS_UNAVAILABLE;
return false;
}
if (!isMonitor && (monitor != null && monitor.matches(JUtilString.RegExpHttpUrl))) {
synchronized (this) {
String url = monitor;
if (url.indexOf("?") > 0)
url += "&request=isAvail";
else
url += "?request=isAvail";
url += "&db_name=" + dbname;
url += "&mirror_uuid=" + uuid;
JHttpContext context = null;
int loop = 0;
while ((context == null || context.getStatus() != 200) && loop < 10) {
try {
context = jhttp.get(null, jclient, url, SysConfig.sysEncoding);
loop++;
} catch (Exception e) {
log.log(e, Logger.LEVEL_ERROR);
try {
Thread.sleep(6000);
} catch (Exception ex) {
}
}
}
String result = context == null ? "false" : context.getResponseText();
// log.log("status from monitor - "+url+","+result, Logger.LEVEL_INFO);
context.finalize();
context = null;
if ("true".equalsIgnoreCase(result)) {
status = DBMirror.STATUS_AVAILABLE;
} else {
status = DBMirror.STATUS_UNAVAILABLE;
}
return "true".equalsIgnoreCase(result);
}
} else {
synchronized (this) {
if (factory == null) {
try {
factory = DAOFactory.getInstance(dbname, config);
factory.resetIgnoreColsWhileUpdating();
ConcurrentList cols = db.getIgnoreColsWhileUpdateViaBean();
for (int i = 0; i < cols.size(); i++) {
String col = (String) cols.get(i);
factory.ignoreColWhileUpdating(col.substring(0, col.indexOf(",")).trim(), col.substring(col.indexOf(",") + 1).trim());
}
} catch (Exception e) {
log.log(e, Logger.LEVEL_ERROR);
return false;
}
}
}
}
DAO dao = null;
try {
dao = factory.createDAO(DBMirror.class, this);
dao.close();
status = DBMirror.STATUS_AVAILABLE;
return true;
} catch (Exception e) {
status = DBMirror.STATUS_UNAVAILABLE;
log.log(e, Logger.LEVEL_INFO);
if (dao != null) {
try {
dao.close();
dao = null;
} catch (Exception ex) {
}
}
return false;
}
}
Aggregations