Bladeren bron

httpjobhandler optimize

xuxueli 6 jaren geleden
bovenliggende
commit
573facc050

+ 2 - 2
xxl-job-admin/src/main/resources/templates/jobgroup/jobgroup.index.ftl Bestand weergeven

@@ -121,7 +121,7 @@
121 121
                         <div class="form-group">
122 122
                             <label for="lastname" class="col-sm-2 control-label">${I18n.jobgroup_field_registryList}<font color="red">*</font></label>
123 123
                             <div class="col-sm-10">
124
-                                <textarea class="textarea" name="addressList" maxlength="512" placeholder="${I18n.jobgroup_field_registryList_placeholder}" readonly="readonly" style="background-color:#eee; width: 100%; height: 100px; font-size: 14px; line-height: 10px; border: 1px solid #dddddd; padding: 10px;"></textarea>
124
+                                <textarea class="textarea" name="addressList" maxlength="512" placeholder="${I18n.jobgroup_field_registryList_placeholder}" readonly="readonly" style="background-color:#eee; width: 100%; height: 100px; font-size: 14px; line-height: 15px; border: 1px solid #dddddd; padding: 5px;"></textarea>
125 125
                             </div>
126 126
                         </div>
127 127
                         <hr>
@@ -169,7 +169,7 @@
169 169
                         <div class="form-group">
170 170
                             <label for="lastname" class="col-sm-2 control-label">${I18n.jobgroup_field_registryList}<font color="red">*</font></label>
171 171
                             <div class="col-sm-10">
172
-                                <textarea class="textarea" name="addressList" maxlength="512" placeholder="${I18n.jobgroup_field_registryList_placeholder}" readonly="readonly" style="background-color:#eee; width: 100%; height: 100px; font-size: 14px; line-height: 10px; border: 1px solid #dddddd; padding: 10px;"></textarea>
172
+                                <textarea class="textarea" name="addressList" maxlength="512" placeholder="${I18n.jobgroup_field_registryList_placeholder}" readonly="readonly" style="background-color:#eee; width: 100%; height: 100px; font-size: 14px; line-height: 15px; border: 1px solid #dddddd; padding: 5px;"></textarea>
173 173
                             </div>
174 174
                         </div>
175 175
                         <hr>

+ 49 - 25
xxl-job-executor-samples/xxl-job-executor-sample-frameless/src/main/java/com/xuxueli/executor/sample/frameless/jobhandler/HttpJobHandler.java Bestand weergeven

@@ -3,13 +3,11 @@ package com.xuxueli.executor.sample.frameless.jobhandler;
3 3
 import com.xxl.job.core.biz.model.ReturnT;
4 4
 import com.xxl.job.core.handler.IJobHandler;
5 5
 import com.xxl.job.core.log.XxlJobLogger;
6
-import org.eclipse.jetty.client.HttpClient;
7
-import org.eclipse.jetty.client.api.ContentResponse;
8
-import org.eclipse.jetty.client.api.Request;
9
-import org.eclipse.jetty.http.HttpMethod;
10
-import org.eclipse.jetty.http.HttpStatus;
11 6
 
12
-import java.util.concurrent.TimeUnit;
7
+import java.io.BufferedReader;
8
+import java.io.InputStreamReader;
9
+import java.net.HttpURLConnection;
10
+import java.net.URL;
13 11
 
14 12
 /**
15 13
  * 跨平台Http任务
@@ -27,34 +25,60 @@ public class HttpJobHandler extends IJobHandler {
27 25
 			return FAIL;
28 26
 		}
29 27
 
30
-		// httpclient
31
-		HttpClient httpClient = null;
28
+		// request
29
+		HttpURLConnection connection = null;
30
+		BufferedReader bufferedReader = null;
32 31
 		try {
33
-			httpClient = new HttpClient();
34
-			httpClient.setFollowRedirects(false);	// Configure HttpClient, for example:
35
-			httpClient.start();						// Start HttpClient
36
-
37
-			// request
38
-			Request request = httpClient.newRequest(param);
39
-			request.method(HttpMethod.GET);
40
-			request.timeout(5000, TimeUnit.MILLISECONDS);
41
-
42
-			// invoke
43
-			ContentResponse response = request.send();
44
-			if (response.getStatus() != HttpStatus.OK_200) {
45
-				XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus());
46
-				return FAIL;
32
+			// connection
33
+			URL realUrl = new URL(param);
34
+			connection = (HttpURLConnection) realUrl.openConnection();
35
+
36
+			// connection setting
37
+			connection.setRequestMethod("GET");
38
+			connection.setDoOutput(true);
39
+			connection.setDoInput(true);
40
+			connection.setUseCaches(false);
41
+			connection.setReadTimeout(5 * 1000);
42
+			connection.setConnectTimeout(3 * 1000);
43
+			connection.setRequestProperty("connection", "Keep-Alive");
44
+			connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
45
+			connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
46
+
47
+			// do connection
48
+			connection.connect();
49
+
50
+			//Map<String, List<String>> map = connection.getHeaderFields();
51
+
52
+			// valid StatusCode
53
+			int statusCode = connection.getResponseCode();
54
+			if (statusCode != 200) {
55
+				throw new RuntimeException("Http Request StatusCode("+ statusCode +") Invalid.");
56
+			}
57
+
58
+			// result
59
+			bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
60
+			StringBuilder result = new StringBuilder();
61
+			String line;
62
+			while ((line = bufferedReader.readLine()) != null) {
63
+				result.append(line);
47 64
 			}
65
+			String responseMsg = result.toString();
48 66
 
49
-			String responseMsg = response.getContentAsString();
50 67
 			XxlJobLogger.log(responseMsg);
51 68
 			return SUCCESS;
52 69
 		} catch (Exception e) {
53 70
 			XxlJobLogger.log(e);
54 71
 			return FAIL;
55 72
 		} finally {
56
-			if (httpClient != null) {
57
-				httpClient.stop();
73
+			try {
74
+				if (bufferedReader != null) {
75
+					bufferedReader.close();
76
+				}
77
+				if (connection != null) {
78
+					connection.disconnect();
79
+				}
80
+			} catch (Exception e2) {
81
+				XxlJobLogger.log(e2);
58 82
 			}
59 83
 		}
60 84
 

+ 65 - 47
xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java Bestand weergeven

@@ -3,13 +3,11 @@ package com.xuxueli.executor.sample.jfinal.jobhandler;
3 3
 import com.xxl.job.core.biz.model.ReturnT;
4 4
 import com.xxl.job.core.handler.IJobHandler;
5 5
 import com.xxl.job.core.log.XxlJobLogger;
6
-import org.eclipse.jetty.client.HttpClient;
7
-import org.eclipse.jetty.client.api.ContentResponse;
8
-import org.eclipse.jetty.client.api.Request;
9
-import org.eclipse.jetty.http.HttpMethod;
10
-import org.eclipse.jetty.http.HttpStatus;
11 6
 
12
-import java.util.concurrent.TimeUnit;
7
+import java.io.BufferedReader;
8
+import java.io.InputStreamReader;
9
+import java.net.HttpURLConnection;
10
+import java.net.URL;
13 11
 
14 12
 /**
15 13
  * 跨平台Http任务
@@ -18,46 +16,66 @@ import java.util.concurrent.TimeUnit;
18 16
  */
19 17
 public class HttpJobHandler extends IJobHandler {
20 18
 
21
-	@Override
22
-	public ReturnT<String> execute(String param) throws Exception {
23
-
24
-		// valid
25
-		if (param==null || param.trim().length()==0) {
26
-			XxlJobLogger.log("URL Empty");
27
-			return FAIL;
28
-		}
29
-
30
-		// httpclient
31
-		HttpClient httpClient = null;
32
-		try {
33
-			httpClient = new HttpClient();
34
-			httpClient.setFollowRedirects(false);	// Configure HttpClient, for example:
35
-			httpClient.start();						// Start HttpClient
36
-
37
-			// request
38
-			Request request = httpClient.newRequest(param);
39
-			request.method(HttpMethod.GET);
40
-			request.timeout(5000, TimeUnit.MILLISECONDS);
41
-
42
-			// invoke
43
-			ContentResponse response = request.send();
44
-			if (response.getStatus() != HttpStatus.OK_200) {
45
-				XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus());
46
-				return FAIL;
47
-			}
48
-
49
-			String responseMsg = response.getContentAsString();
50
-			XxlJobLogger.log(responseMsg);
51
-			return SUCCESS;
52
-		} catch (Exception e) {
53
-			XxlJobLogger.log(e);
54
-			return FAIL;
55
-		} finally {
56
-			if (httpClient != null) {
57
-				httpClient.stop();
58
-			}
59
-		}
60
-
61
-	}
19
+    @Override
20
+    public ReturnT<String> execute(String param) throws Exception {
21
+
22
+        // request
23
+        HttpURLConnection connection = null;
24
+        BufferedReader bufferedReader = null;
25
+        try {
26
+            // connection
27
+            URL realUrl = new URL(param);
28
+            connection = (HttpURLConnection) realUrl.openConnection();
29
+
30
+            // connection setting
31
+            connection.setRequestMethod("GET");
32
+            connection.setDoOutput(true);
33
+            connection.setDoInput(true);
34
+            connection.setUseCaches(false);
35
+            connection.setReadTimeout(5 * 1000);
36
+            connection.setConnectTimeout(3 * 1000);
37
+            connection.setRequestProperty("connection", "Keep-Alive");
38
+            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
39
+            connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
40
+
41
+            // do connection
42
+            connection.connect();
43
+
44
+            //Map<String, List<String>> map = connection.getHeaderFields();
45
+
46
+            // valid StatusCode
47
+            int statusCode = connection.getResponseCode();
48
+            if (statusCode != 200) {
49
+                throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid.");
50
+            }
51
+
52
+            // result
53
+            bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
54
+            StringBuilder result = new StringBuilder();
55
+            String line;
56
+            while ((line = bufferedReader.readLine()) != null) {
57
+                result.append(line);
58
+            }
59
+            String responseMsg = result.toString();
60
+
61
+            XxlJobLogger.log(responseMsg);
62
+            return SUCCESS;
63
+        } catch (Exception e) {
64
+            XxlJobLogger.log(e);
65
+            return FAIL;
66
+        } finally {
67
+            try {
68
+                if (bufferedReader != null) {
69
+                    bufferedReader.close();
70
+                }
71
+                if (connection != null) {
72
+                    connection.disconnect();
73
+                }
74
+            } catch (Exception e2) {
75
+                XxlJobLogger.log(e2);
76
+            }
77
+        }
78
+
79
+    }
62 80
 
63 81
 }

+ 60 - 42
xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java Bestand weergeven

@@ -4,64 +4,82 @@ import com.xxl.job.core.biz.model.ReturnT;
4 4
 import com.xxl.job.core.handler.IJobHandler;
5 5
 import com.xxl.job.core.handler.annotation.JobHandler;
6 6
 import com.xxl.job.core.log.XxlJobLogger;
7
-import org.eclipse.jetty.client.HttpClient;
8
-import org.eclipse.jetty.client.api.ContentResponse;
9
-import org.eclipse.jetty.client.api.Request;
10
-import org.eclipse.jetty.http.HttpMethod;
11
-import org.eclipse.jetty.http.HttpStatus;
12 7
 import org.nutz.ioc.loader.annotation.IocBean;
13 8
 
14
-import java.util.concurrent.TimeUnit;
9
+import java.io.BufferedReader;
10
+import java.io.InputStreamReader;
11
+import java.net.HttpURLConnection;
12
+import java.net.URL;
15 13
 
16 14
 /**
17 15
  * 跨平台Http任务
18 16
  *
19 17
  * @author xuxueli 2018-09-16 03:48:34
20 18
  */
21
-@JobHandler(value="httpJobHandler")
19
+@JobHandler(value = "httpJobHandler")
22 20
 @IocBean
23 21
 public class HttpJobHandler extends IJobHandler {
24 22
 
25
-	@Override
26
-	public ReturnT<String> execute(String param) throws Exception {
23
+    @Override
24
+    public ReturnT<String> execute(String param) throws Exception {
27 25
 
28
-		// valid
29
-		if (param==null || param.trim().length()==0) {
30
-			XxlJobLogger.log("URL Empty");
31
-			return FAIL;
32
-		}
26
+        // request
27
+        HttpURLConnection connection = null;
28
+        BufferedReader bufferedReader = null;
29
+        try {
30
+            // connection
31
+            URL realUrl = new URL(param);
32
+            connection = (HttpURLConnection) realUrl.openConnection();
33 33
 
34
-		// httpclient
35
-		HttpClient httpClient = null;
36
-		try {
37
-			httpClient = new HttpClient();
38
-			httpClient.setFollowRedirects(false);	// Configure HttpClient, for example:
39
-			httpClient.start();						// Start HttpClient
34
+            // connection setting
35
+            connection.setRequestMethod("GET");
36
+            connection.setDoOutput(true);
37
+            connection.setDoInput(true);
38
+            connection.setUseCaches(false);
39
+            connection.setReadTimeout(5 * 1000);
40
+            connection.setConnectTimeout(3 * 1000);
41
+            connection.setRequestProperty("connection", "Keep-Alive");
42
+            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
43
+            connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
40 44
 
41
-			// request
42
-			Request request = httpClient.newRequest(param);
43
-			request.method(HttpMethod.GET);
44
-			request.timeout(5000, TimeUnit.MILLISECONDS);
45
+            // do connection
46
+            connection.connect();
45 47
 
46
-			// invoke
47
-			ContentResponse response = request.send();
48
-			if (response.getStatus() != HttpStatus.OK_200) {
49
-				XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus());
50
-				return FAIL;
51
-			}
48
+            //Map<String, List<String>> map = connection.getHeaderFields();
52 49
 
53
-			String responseMsg = response.getContentAsString();
54
-			XxlJobLogger.log(responseMsg);
55
-			return SUCCESS;
56
-		} catch (Exception e) {
57
-			XxlJobLogger.log(e);
58
-			return FAIL;
59
-		} finally {
60
-			if (httpClient != null) {
61
-				httpClient.stop();
62
-			}
63
-		}
50
+            // valid StatusCode
51
+            int statusCode = connection.getResponseCode();
52
+            if (statusCode != 200) {
53
+                throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid.");
54
+            }
64 55
 
65
-	}
56
+            // result
57
+            bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
58
+            StringBuilder result = new StringBuilder();
59
+            String line;
60
+            while ((line = bufferedReader.readLine()) != null) {
61
+                result.append(line);
62
+            }
63
+            String responseMsg = result.toString();
64
+
65
+            XxlJobLogger.log(responseMsg);
66
+            return SUCCESS;
67
+        } catch (Exception e) {
68
+            XxlJobLogger.log(e);
69
+            return FAIL;
70
+        } finally {
71
+            try {
72
+                if (bufferedReader != null) {
73
+                    bufferedReader.close();
74
+                }
75
+                if (connection != null) {
76
+                    connection.disconnect();
77
+                }
78
+            } catch (Exception e2) {
79
+                XxlJobLogger.log(e2);
80
+            }
81
+        }
82
+
83
+    }
66 84
 
67 85
 }

+ 60 - 42
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java Bestand weergeven

@@ -4,64 +4,82 @@ import com.xxl.job.core.biz.model.ReturnT;
4 4
 import com.xxl.job.core.handler.IJobHandler;
5 5
 import com.xxl.job.core.handler.annotation.JobHandler;
6 6
 import com.xxl.job.core.log.XxlJobLogger;
7
-import org.eclipse.jetty.client.HttpClient;
8
-import org.eclipse.jetty.client.api.ContentResponse;
9
-import org.eclipse.jetty.client.api.Request;
10
-import org.eclipse.jetty.http.HttpMethod;
11
-import org.eclipse.jetty.http.HttpStatus;
12 7
 import org.springframework.stereotype.Component;
13 8
 
14
-import java.util.concurrent.TimeUnit;
9
+import java.io.BufferedReader;
10
+import java.io.InputStreamReader;
11
+import java.net.HttpURLConnection;
12
+import java.net.URL;
15 13
 
16 14
 /**
17 15
  * 跨平台Http任务
18 16
  *
19 17
  * @author xuxueli 2018-09-16 03:48:34
20 18
  */
21
-@JobHandler(value="httpJobHandler")
19
+@JobHandler(value = "httpJobHandler")
22 20
 @Component
23 21
 public class HttpJobHandler extends IJobHandler {
24 22
 
25
-	@Override
26
-	public ReturnT<String> execute(String param) throws Exception {
23
+    @Override
24
+    public ReturnT<String> execute(String param) throws Exception {
27 25
 
28
-		// valid
29
-		if (param==null || param.trim().length()==0) {
30
-			XxlJobLogger.log("URL Empty");
31
-			return FAIL;
32
-		}
26
+        // request
27
+        HttpURLConnection connection = null;
28
+        BufferedReader bufferedReader = null;
29
+        try {
30
+            // connection
31
+            URL realUrl = new URL(param);
32
+            connection = (HttpURLConnection) realUrl.openConnection();
33 33
 
34
-		// httpclient
35
-		HttpClient httpClient = null;
36
-		try {
37
-			httpClient = new HttpClient();
38
-			httpClient.setFollowRedirects(false);	// Configure HttpClient, for example:
39
-			httpClient.start();						// Start HttpClient
34
+            // connection setting
35
+            connection.setRequestMethod("GET");
36
+            connection.setDoOutput(true);
37
+            connection.setDoInput(true);
38
+            connection.setUseCaches(false);
39
+            connection.setReadTimeout(5 * 1000);
40
+            connection.setConnectTimeout(3 * 1000);
41
+            connection.setRequestProperty("connection", "Keep-Alive");
42
+            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
43
+            connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
40 44
 
41
-			// request
42
-			Request request = httpClient.newRequest(param);
43
-			request.method(HttpMethod.GET);
44
-			request.timeout(5000, TimeUnit.MILLISECONDS);
45
+            // do connection
46
+            connection.connect();
45 47
 
46
-			// invoke
47
-			ContentResponse response = request.send();
48
-			if (response.getStatus() != HttpStatus.OK_200) {
49
-				XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus());
50
-				return FAIL;
51
-			}
48
+            //Map<String, List<String>> map = connection.getHeaderFields();
52 49
 
53
-			String responseMsg = response.getContentAsString();
54
-			XxlJobLogger.log(responseMsg);
55
-			return SUCCESS;
56
-		} catch (Exception e) {
57
-			XxlJobLogger.log(e);
58
-			return FAIL;
59
-		} finally {
60
-			if (httpClient != null) {
61
-				httpClient.stop();
62
-			}
63
-		}
50
+            // valid StatusCode
51
+            int statusCode = connection.getResponseCode();
52
+            if (statusCode != 200) {
53
+                throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid.");
54
+            }
64 55
 
65
-	}
56
+            // result
57
+            bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
58
+            StringBuilder result = new StringBuilder();
59
+            String line;
60
+            while ((line = bufferedReader.readLine()) != null) {
61
+                result.append(line);
62
+            }
63
+            String responseMsg = result.toString();
64
+
65
+            XxlJobLogger.log(responseMsg);
66
+            return SUCCESS;
67
+        } catch (Exception e) {
68
+            XxlJobLogger.log(e);
69
+            return FAIL;
70
+        } finally {
71
+            try {
72
+                if (bufferedReader != null) {
73
+                    bufferedReader.close();
74
+                }
75
+                if (connection != null) {
76
+                    connection.disconnect();
77
+                }
78
+            } catch (Exception e2) {
79
+                XxlJobLogger.log(e2);
80
+            }
81
+        }
82
+
83
+    }
66 84
 
67 85
 }

+ 60 - 42
xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java Bestand weergeven

@@ -4,64 +4,82 @@ import com.xxl.job.core.biz.model.ReturnT;
4 4
 import com.xxl.job.core.handler.IJobHandler;
5 5
 import com.xxl.job.core.handler.annotation.JobHandler;
6 6
 import com.xxl.job.core.log.XxlJobLogger;
7
-import org.eclipse.jetty.client.HttpClient;
8
-import org.eclipse.jetty.client.api.ContentResponse;
9
-import org.eclipse.jetty.client.api.Request;
10
-import org.eclipse.jetty.http.HttpMethod;
11
-import org.eclipse.jetty.http.HttpStatus;
12 7
 import org.springframework.stereotype.Component;
13 8
 
14
-import java.util.concurrent.TimeUnit;
9
+import java.io.BufferedReader;
10
+import java.io.InputStreamReader;
11
+import java.net.HttpURLConnection;
12
+import java.net.URL;
15 13
 
16 14
 /**
17 15
  * 跨平台Http任务
18 16
  *
19 17
  * @author xuxueli 2018-09-16 03:48:34
20 18
  */
21
-@JobHandler(value="httpJobHandler")
19
+@JobHandler(value = "httpJobHandler")
22 20
 @Component
23 21
 public class HttpJobHandler extends IJobHandler {
24 22
 
25
-	@Override
26
-	public ReturnT<String> execute(String param) throws Exception {
23
+    @Override
24
+    public ReturnT<String> execute(String param) throws Exception {
27 25
 
28
-		// valid
29
-		if (param==null || param.trim().length()==0) {
30
-			XxlJobLogger.log("URL Empty");
31
-			return FAIL;
32
-		}
26
+        // request
27
+        HttpURLConnection connection = null;
28
+        BufferedReader bufferedReader = null;
29
+        try {
30
+            // connection
31
+            URL realUrl = new URL(param);
32
+            connection = (HttpURLConnection) realUrl.openConnection();
33 33
 
34
-		// httpclient
35
-		HttpClient httpClient = null;
36
-		try {
37
-			httpClient = new HttpClient();
38
-			httpClient.setFollowRedirects(false);	// Configure HttpClient, for example:
39
-			httpClient.start();						// Start HttpClient
34
+            // connection setting
35
+            connection.setRequestMethod("GET");
36
+            connection.setDoOutput(true);
37
+            connection.setDoInput(true);
38
+            connection.setUseCaches(false);
39
+            connection.setReadTimeout(5 * 1000);
40
+            connection.setConnectTimeout(3 * 1000);
41
+            connection.setRequestProperty("connection", "Keep-Alive");
42
+            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
43
+            connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
40 44
 
41
-			// request
42
-			Request request = httpClient.newRequest(param);
43
-			request.method(HttpMethod.GET);
44
-			request.timeout(5000, TimeUnit.MILLISECONDS);
45
+            // do connection
46
+            connection.connect();
45 47
 
46
-			// invoke
47
-			ContentResponse response = request.send();
48
-			if (response.getStatus() != HttpStatus.OK_200) {
49
-				XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus());
50
-				return FAIL;
51
-			}
48
+            //Map<String, List<String>> map = connection.getHeaderFields();
52 49
 
53
-			String responseMsg = response.getContentAsString();
54
-			XxlJobLogger.log(responseMsg);
55
-			return SUCCESS;
56
-		} catch (Exception e) {
57
-			XxlJobLogger.log(e);
58
-			return FAIL;
59
-		} finally {
60
-			if (httpClient != null) {
61
-				httpClient.stop();
62
-			}
63
-		}
50
+            // valid StatusCode
51
+            int statusCode = connection.getResponseCode();
52
+            if (statusCode != 200) {
53
+                throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid.");
54
+            }
64 55
 
65
-	}
56
+            // result
57
+            bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
58
+            StringBuilder result = new StringBuilder();
59
+            String line;
60
+            while ((line = bufferedReader.readLine()) != null) {
61
+                result.append(line);
62
+            }
63
+            String responseMsg = result.toString();
64
+
65
+            XxlJobLogger.log(responseMsg);
66
+            return SUCCESS;
67
+        } catch (Exception e) {
68
+            XxlJobLogger.log(e);
69
+            return FAIL;
70
+        } finally {
71
+            try {
72
+                if (bufferedReader != null) {
73
+                    bufferedReader.close();
74
+                }
75
+                if (connection != null) {
76
+                    connection.disconnect();
77
+                }
78
+            } catch (Exception e2) {
79
+                XxlJobLogger.log(e2);
80
+            }
81
+        }
82
+
83
+    }
66 84
 
67 85
 }