Commit 1c6147534c1d4462de0db81213d94c9660f6c4e1
1 parent
3d6f8f3241
Exists in
master
and in
8 other branches
增加监控
Showing 1 changed file with 59 additions and 2 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java
View file @
1c61475
... | ... | @@ -6,13 +6,18 @@ |
6 | 6 | import org.apache.commons.httpclient.methods.GetMethod; |
7 | 7 | import org.apache.commons.httpclient.methods.PostMethod; |
8 | 8 | import org.apache.commons.lang.*; |
9 | +import org.slf4j.Logger; | |
10 | +import org.slf4j.LoggerFactory; | |
11 | +import org.springframework.util.StopWatch; | |
9 | 12 | |
10 | 13 | import java.security.MessageDigest; |
11 | 14 | import java.security.NoSuchAlgorithmException; |
12 | 15 | |
13 | 16 | public class LoginUtil { |
14 | - | |
17 | + private static Logger logger = LoggerFactory.getLogger("DAL-MONITOR"); | |
15 | 18 | public static LoginContext register(String phone, String token, String typeId) { |
19 | + StopWatch stopWatch = new StopWatch("register"); | |
20 | + stopWatch.start("init http client"); | |
16 | 21 | HttpClient client = new HttpClient(); |
17 | 22 | PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/register.action"); |
18 | 23 | NameValuePair[] data = { |
19 | 24 | |
20 | 25 | |
21 | 26 | |
22 | 27 | |
23 | 28 | |
24 | 29 | |
... | ... | @@ -21,22 +26,31 @@ |
21 | 26 | }; |
22 | 27 | post.setRequestBody(data); |
23 | 28 | post.setRequestHeader("Authorization", token); |
29 | + stopWatch.stop(); | |
24 | 30 | try { |
31 | + stopWatch.start("excuteMethod"); | |
25 | 32 | client.executeMethod(post); |
26 | 33 | int statusCode = post.getStatusCode(); |
27 | 34 | String result = new String(post.getResponseBodyAsString()); |
28 | 35 | post.releaseConnection(); |
36 | + stopWatch.stop(); | |
29 | 37 | if (200 == statusCode) { |
38 | + stopWatch.start("parse json"); | |
30 | 39 | LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); |
40 | + stopWatch.stop(); | |
31 | 41 | return loginState; |
32 | 42 | } |
33 | 43 | } catch (Exception e) { |
34 | 44 | e.printStackTrace(); |
45 | + }finally { | |
46 | + logger.info(stopWatch.toString()); | |
35 | 47 | } |
36 | 48 | return null; |
37 | 49 | } |
38 | 50 | |
39 | 51 | public static Integer aouHospitalUser(String account, String pwd, String typeId, String token) { |
52 | + StopWatch stopWatch = new StopWatch("aouHospitalUser"); | |
53 | + stopWatch.start("init http client"); | |
40 | 54 | HttpClient client = new HttpClient(); |
41 | 55 | PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/checkUser.action"); |
42 | 56 | NameValuePair[] data = { |
43 | 57 | |
44 | 58 | |
45 | 59 | |
46 | 60 | |
47 | 61 | |
48 | 62 | |
... | ... | @@ -46,25 +60,34 @@ |
46 | 60 | }; |
47 | 61 | post.setRequestBody(data); |
48 | 62 | post.setRequestHeader("Authorization", token); |
63 | + stopWatch.stop(); | |
49 | 64 | try { |
65 | + stopWatch.start("excuteMethod"); | |
50 | 66 | client.executeMethod(post); |
51 | 67 | int statusCode = post.getStatusCode(); |
52 | 68 | String result = new String(post.getResponseBodyAsString()); |
53 | 69 | |
54 | 70 | post.releaseConnection(); |
71 | + stopWatch.stop(); | |
55 | 72 | if (200 == statusCode) { |
73 | + stopWatch.start("parse json"); | |
56 | 74 | LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); |
75 | + stopWatch.stop(); | |
57 | 76 | if (0 == loginState.getErrorcode()) { |
58 | 77 | return loginState.getId(); |
59 | 78 | } |
60 | 79 | } |
61 | 80 | } catch (Exception e) { |
62 | 81 | e.printStackTrace(); |
82 | + }finally { | |
83 | + logger.info(stopWatch.toString()); | |
63 | 84 | } |
64 | 85 | return null; |
65 | 86 | } |
66 | 87 | |
67 | 88 | public static LoginContext loginHospitalUser(String account, String pwd, String typeId, String token) { |
89 | + StopWatch stopWatch = new StopWatch("loginHospitalUser"); | |
90 | + stopWatch.start("init http client"); | |
68 | 91 | HttpClient client = new HttpClient(); |
69 | 92 | PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/userLogin.action"); |
70 | 93 | NameValuePair[] data = { |
71 | 94 | |
72 | 95 | |
73 | 96 | |
74 | 97 | |
75 | 98 | |
76 | 99 | |
... | ... | @@ -74,24 +97,33 @@ |
74 | 97 | }; |
75 | 98 | post.setRequestBody(data); |
76 | 99 | post.setRequestHeader("Authorization", token); |
100 | + stopWatch.stop(); | |
77 | 101 | try { |
102 | + stopWatch.start("excuteMethod"); | |
78 | 103 | client.executeMethod(post); |
79 | 104 | int statusCode = post.getStatusCode(); |
80 | 105 | String result = new String(post.getResponseBodyAsString()); |
81 | 106 | |
82 | 107 | post.releaseConnection(); |
108 | + stopWatch.stop(); | |
83 | 109 | LoginContext loginState = new LoginContext(); |
84 | 110 | if (200 == statusCode) { |
111 | + stopWatch.start("parse json"); | |
85 | 112 | loginState = JsonUtil.str2Obj(result, LoginContext.class); |
113 | + stopWatch.stop(); | |
86 | 114 | return loginState; |
87 | 115 | } |
88 | 116 | } catch (Exception e) { |
89 | 117 | e.printStackTrace(); |
118 | + }finally { | |
119 | + logger.info(stopWatch.toString()); | |
90 | 120 | } |
91 | 121 | return null; |
92 | 122 | } |
93 | 123 | |
94 | 124 | public static LoginContext login(String phone, String varCode, String typeId, String token) { |
125 | + StopWatch stopWatch = new StopWatch("login"); | |
126 | + stopWatch.start("init http client"); | |
95 | 127 | HttpClient client = new HttpClient(); |
96 | 128 | PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/login.action"); |
97 | 129 | NameValuePair[] data = { |
98 | 130 | |
99 | 131 | |
100 | 132 | |
101 | 133 | |
102 | 134 | |
... | ... | @@ -101,19 +133,26 @@ |
101 | 133 | }; |
102 | 134 | post.setRequestBody(data); |
103 | 135 | post.setRequestHeader("Authorization", token); |
136 | + stopWatch.stop(); | |
104 | 137 | try { |
138 | + stopWatch.start("excuteMethod"); | |
105 | 139 | client.executeMethod(post); |
106 | 140 | int statusCode = post.getStatusCode(); |
107 | 141 | String result = new String(post.getResponseBodyAsString()); |
108 | 142 | |
109 | - post.releaseConnection(); | |
143 | + post.releaseConnection();stopWatch.stop(); | |
144 | + | |
110 | 145 | LoginContext loginState = new LoginContext(); |
111 | 146 | if (200 == statusCode) { |
147 | + stopWatch.start("parse json"); | |
112 | 148 | loginState = JsonUtil.str2Obj(result, LoginContext.class); |
149 | + stopWatch.stop(); | |
113 | 150 | return loginState; |
114 | 151 | } |
115 | 152 | } catch (Exception e) { |
116 | 153 | e.printStackTrace(); |
154 | + }finally { | |
155 | + logger.info(stopWatch.toString()); | |
117 | 156 | } |
118 | 157 | return null; |
119 | 158 | } |
120 | 159 | |
121 | 160 | |
122 | 161 | |
123 | 162 | |
124 | 163 | |
125 | 164 | |
126 | 165 | |
127 | 166 | |
128 | 167 | |
129 | 168 | |
130 | 169 | |
131 | 170 | |
132 | 171 | |
... | ... | @@ -130,44 +169,62 @@ |
130 | 169 | } |
131 | 170 | |
132 | 171 | public static LoginContext sendVerCode(String phone, String typeId, String token) { |
172 | + StopWatch stopWatch = new StopWatch("sendVerCode"); | |
173 | + stopWatch.start("init http client"); | |
133 | 174 | HttpClient client = new HttpClient(); |
134 | 175 | String query = "?phone=" + phone + "&typeId=" + typeId + "&token=" + token + "&userType=2"; |
135 | 176 | GetMethod get = new MessageUtil.UTF8GetMethod("http://passport.healthbaby.com.cn/v1/vercode.action" + query); |
136 | 177 | |
137 | 178 | get.setRequestHeader("Authorization", token); |
179 | + stopWatch.stop(); | |
138 | 180 | try { |
181 | + stopWatch.start("excuteMethod"); | |
139 | 182 | client.executeMethod(get); |
140 | 183 | int statusCode = get.getStatusCode(); |
141 | 184 | String result = new String(get.getResponseBodyAsString()); |
142 | 185 | get.releaseConnection(); |
186 | + stopWatch.stop(); | |
143 | 187 | if (200 == statusCode) { |
188 | + stopWatch.start("parse json"); | |
144 | 189 | LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); |
190 | + stopWatch.stop(); | |
145 | 191 | return loginState; |
146 | 192 | } |
147 | 193 | } catch (Exception e) { |
148 | 194 | e.printStackTrace(); |
195 | + }finally { | |
196 | + logger.info(stopWatch.toString()); | |
149 | 197 | } |
150 | 198 | return null; |
151 | 199 | } |
152 | 200 | |
153 | 201 | |
154 | 202 | public static LoginContext checkLoginState(String token) { |
203 | + StopWatch stopWatch = new StopWatch("checkLoginState"); | |
204 | + stopWatch.start("init http client"); | |
155 | 205 | LoginContext loginState = new LoginContext(); |
156 | 206 | HttpClient client = new HttpClient(); |
157 | 207 | String query = "?token=" + token; |
158 | 208 | GetMethod get = new MessageUtil.UTF8GetMethod("http://passport.healthbaby.com.cn/v1/check.action" + query); |
159 | 209 | get.setRequestHeader("Authorization", token); |
210 | + stopWatch.stop(); | |
160 | 211 | try { |
212 | + stopWatch.start("excuteMethod"); | |
161 | 213 | client.executeMethod(get); |
162 | 214 | int statusCode = get.getStatusCode(); |
163 | 215 | String result = new String(get.getResponseBodyAsString()); |
164 | 216 | get.releaseConnection(); |
217 | + stopWatch.stop(); | |
165 | 218 | if (200 == statusCode) { |
219 | + stopWatch.start("parse json"); | |
166 | 220 | loginState = JsonUtil.str2Obj(result, LoginContext.class); |
221 | + stopWatch.stop(); | |
167 | 222 | return loginState; |
168 | 223 | } |
169 | 224 | } catch (Exception e) { |
170 | 225 | e.printStackTrace(); |
226 | + }finally { | |
227 | + logger.info(stopWatch.toString()); | |
171 | 228 | } |
172 | 229 | return loginState; |
173 | 230 | } |