From 1c6147534c1d4462de0db81213d94c9660f6c4e1 Mon Sep 17 00:00:00 2001 From: jiangjiazhi Date: Fri, 27 May 2016 11:04:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lyms/platform/common/utils/LoginUtil.java | 61 +++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) 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; } -- 1.8.3.1