use of j.http.JHttp in project JFramework by gugumall.
the class RouterAgent method monitor.
/**
* 监视关联路由节点状态,并报告RouterManager
* @throws RemoteException
*/
private void monitor() throws RemoteException {
boolean available = true;
if (this.routerConfig.getRmi() != null) {
// 监测rmi接口状态
try {
synchronized (Constants.GLOBAL_LOCK) {
initialNamingContext = new InitialContext(this.routerConfig.getRmi().getConfig());
}
} catch (Exception e) {
available = false;
initialNamingContext = null;
log.log(e, Logger.LEVEL_DEBUG_ADV);
}
if (available) {
try {
servant = (JRouter) initialNamingContext.lookup(this.routerConfig.getUuid());
String heartbeat = servant.heartbeat();
if (!heartbeat.startsWith(Constants.STATUS_OK)) {
throw new Exception("心跳不正常");
} else {
long upd = Long.parseLong(heartbeat.substring(heartbeat.indexOf(":") + 1));
if (upd > update) {
cache.clear();
update = upd;
}
}
} catch (Exception e) {
available = false;
servant = null;
log.log(e, Logger.LEVEL_DEBUG_ADV);
}
}
} else {
available = false;
servant = null;
}
routerRmiAvailable = available;
available = true;
if (this.routerConfig.getHttp() != null) {
// 监测http接口状态
String url = this.routerConfig.getHttp().getEntrance();
if (url.indexOf("?") > 0)
url += "&request=heartbeat";
else
url += "?request=heartbeat";
JHttp jhttp = JHttp.getInstance();
JHttpContext context = null;
try {
context = jhttp.get(null, null, url);
} catch (Exception e) {
available = false;
log.log(e, Logger.LEVEL_DEBUG);
}
if (context == null || context.getStatus() != 200 || !context.getResponseText().startsWith(Constants.STATUS_OK)) {
available = false;
} else {
String heartbeat = context.getResponseText();
long upd = Long.parseLong(heartbeat.substring(heartbeat.indexOf(":") + 1));
if (upd > update) {
cache.clear();
update = upd;
}
}
} else {
available = false;
}
routerHttpAvailable = available;
log.log("rmi of router " + routerConfig.getUuid() + "," + routerConfig.getName() + " is " + (routerRmiAvailable ? "available" : "unavailable") + ".", Logger.LEVEL_DEBUG);
log.log("http of router " + routerConfig.getUuid() + "," + routerConfig.getName() + " is " + (routerHttpAvailable ? "available" : "unavailable") + ".", Logger.LEVEL_DEBUG);
if (routerRmiAvailable) {
RouterManager.setAvailableRmi(this.routerConfig.getUuid(), true);
} else {
RouterManager.setAvailableRmi(this.routerConfig.getUuid(), false);
}
if (routerHttpAvailable) {
RouterManager.setAvailableHttp(this.routerConfig.getUuid(), true);
} else {
RouterManager.setAvailableHttp(this.routerConfig.getUuid(), false);
}
}
use of j.http.JHttp in project JFramework by gugumall.
the class Apple method main.
public static void main(String[] args) throws Exception {
JHttp http = JHttp.getInstance();
HttpClient client = http.createClient();
JHttpContext context = new JHttpContext();
String s1 = http.getResponse(context, client, "http://www.apple.com/cn/", "UTF-8");
System.out.println(s1);
context.addRequestHeader("Referer", "http://www.apple.com/cn/");
String s2 = http.getResponse(context, client, "https://idmsa.apple.com/IDMSWebAuth/login.html?appIdKey=990d5c9e38720f4e832a8009a0fe4cad7dd151f99111dbea0df5e2934f267ec8&language=CN-zh&segment=R479&grpcode=g001¶mcode=h006&path=%2Fgeniusbar%2FR479%2Fsignin%2Fack&path2=%2Fgeniusbar%2FR479%2Fsignin%2Fack", "UTF-8");
System.out.println(s2);
}
Aggregations