diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java b/platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java index f55f37e..3464bf1 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java @@ -6,13 +6,18 @@ import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.lang.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StopWatch; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class LoginUtil { - + private static Logger logger = LoggerFactory.getLogger("DAL-MONITOR"); public static LoginContext register(String phone, String token, String typeId) { + StopWatch stopWatch = new StopWatch("register"); + stopWatch.start("init http client"); HttpClient client = new HttpClient(); PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/register.action"); NameValuePair[] data = { @@ -21,22 +26,31 @@ public class LoginUtil { }; post.setRequestBody(data); post.setRequestHeader("Authorization", token); + stopWatch.stop(); try { + stopWatch.start("excuteMethod"); client.executeMethod(post); int statusCode = post.getStatusCode(); String result = new String(post.getResponseBodyAsString()); post.releaseConnection(); + stopWatch.stop(); if (200 == statusCode) { + stopWatch.start("parse json"); LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); + stopWatch.stop(); return loginState; } } catch (Exception e) { e.printStackTrace(); + }finally { + logger.info(stopWatch.toString()); } return null; } public static Integer aouHospitalUser(String account, String pwd, String typeId, String token) { + StopWatch stopWatch = new StopWatch("aouHospitalUser"); + stopWatch.start("init http client"); HttpClient client = new HttpClient(); PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/checkUser.action"); NameValuePair[] data = { @@ -46,25 +60,34 @@ public class LoginUtil { }; post.setRequestBody(data); post.setRequestHeader("Authorization", token); + stopWatch.stop(); try { + stopWatch.start("excuteMethod"); client.executeMethod(post); int statusCode = post.getStatusCode(); String result = new String(post.getResponseBodyAsString()); post.releaseConnection(); + stopWatch.stop(); if (200 == statusCode) { + stopWatch.start("parse json"); LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); + stopWatch.stop(); if (0 == loginState.getErrorcode()) { return loginState.getId(); } } } catch (Exception e) { e.printStackTrace(); + }finally { + logger.info(stopWatch.toString()); } return null; } public static LoginContext loginHospitalUser(String account, String pwd, String typeId, String token) { + StopWatch stopWatch = new StopWatch("loginHospitalUser"); + stopWatch.start("init http client"); HttpClient client = new HttpClient(); PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/userLogin.action"); NameValuePair[] data = { @@ -74,24 +97,33 @@ public class LoginUtil { }; post.setRequestBody(data); post.setRequestHeader("Authorization", token); + stopWatch.stop(); try { + stopWatch.start("excuteMethod"); client.executeMethod(post); int statusCode = post.getStatusCode(); String result = new String(post.getResponseBodyAsString()); post.releaseConnection(); + stopWatch.stop(); LoginContext loginState = new LoginContext(); if (200 == statusCode) { + stopWatch.start("parse json"); loginState = JsonUtil.str2Obj(result, LoginContext.class); + stopWatch.stop(); return loginState; } } catch (Exception e) { e.printStackTrace(); + }finally { + logger.info(stopWatch.toString()); } return null; } public static LoginContext login(String phone, String varCode, String typeId, String token) { + StopWatch stopWatch = new StopWatch("login"); + stopWatch.start("init http client"); HttpClient client = new HttpClient(); PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/login.action"); NameValuePair[] data = { @@ -101,19 +133,26 @@ public class LoginUtil { }; post.setRequestBody(data); post.setRequestHeader("Authorization", token); + stopWatch.stop(); try { + stopWatch.start("excuteMethod"); client.executeMethod(post); int statusCode = post.getStatusCode(); String result = new String(post.getResponseBodyAsString()); - post.releaseConnection(); + post.releaseConnection();stopWatch.stop(); + LoginContext loginState = new LoginContext(); if (200 == statusCode) { + stopWatch.start("parse json"); loginState = JsonUtil.str2Obj(result, LoginContext.class); + stopWatch.stop(); return loginState; } } catch (Exception e) { e.printStackTrace(); + }finally { + logger.info(stopWatch.toString()); } return null; } @@ -130,44 +169,62 @@ public class LoginUtil { } public static LoginContext sendVerCode(String phone, String typeId, String token) { + StopWatch stopWatch = new StopWatch("sendVerCode"); + stopWatch.start("init http client"); HttpClient client = new HttpClient(); String query = "?phone=" + phone + "&typeId=" + typeId + "&token=" + token + "&userType=2"; GetMethod get = new MessageUtil.UTF8GetMethod("http://passport.healthbaby.com.cn/v1/vercode.action" + query); get.setRequestHeader("Authorization", token); + stopWatch.stop(); try { + stopWatch.start("excuteMethod"); client.executeMethod(get); int statusCode = get.getStatusCode(); String result = new String(get.getResponseBodyAsString()); get.releaseConnection(); + stopWatch.stop(); if (200 == statusCode) { + stopWatch.start("parse json"); LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); + stopWatch.stop(); return loginState; } } catch (Exception e) { e.printStackTrace(); + }finally { + logger.info(stopWatch.toString()); } return null; } public static LoginContext checkLoginState(String token) { + StopWatch stopWatch = new StopWatch("checkLoginState"); + stopWatch.start("init http client"); LoginContext loginState = new LoginContext(); HttpClient client = new HttpClient(); String query = "?token=" + token; GetMethod get = new MessageUtil.UTF8GetMethod("http://passport.healthbaby.com.cn/v1/check.action" + query); get.setRequestHeader("Authorization", token); + stopWatch.stop(); try { + stopWatch.start("excuteMethod"); client.executeMethod(get); int statusCode = get.getStatusCode(); String result = new String(get.getResponseBodyAsString()); get.releaseConnection(); + stopWatch.stop(); if (200 == statusCode) { + stopWatch.start("parse json"); loginState = JsonUtil.str2Obj(result, LoginContext.class); + stopWatch.stop(); return loginState; } } catch (Exception e) { e.printStackTrace(); + }finally { + logger.info(stopWatch.toString()); } return loginState; }