From ce673741c08d9c56da57dbf6a864b6543742b9c9 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Sun, 28 Oct 2018 04:49:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0RM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xxl-job-admin/Dockerfile | 2 +- .../jfinal/jobhandler/HttpJobHandler.java | 43 ++++++++++++------- .../nutz/jobhandler/HttpJobHandler.java | 43 ++++++++++++------- .../service/jobhandler/HttpJobHandler.java | 43 ++++++++++++------- .../service/jobhandler/HttpJobHandler.java | 43 ++++++++++++------- .../src/main/resources/logback.xml | 8 ---- 6 files changed, 109 insertions(+), 73 deletions(-) diff --git a/xxl-job-admin/Dockerfile b/xxl-job-admin/Dockerfile index 336db09e..be431040 100644 --- a/xxl-job-admin/Dockerfile +++ b/xxl-job-admin/Dockerfile @@ -3,6 +3,6 @@ MAINTAINER xuxueli ENV PARAMS="" -ADD target/xxl-conf-admin-*.jar /app.jar +ADD target/xxl-job-admin-*.jar /app.jar ENTRYPOINT ["sh","-c","java -jar /app.jar $PARAMS"] \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java index 88b36cf4..a4fa6b97 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-jfinal/src/main/java/com/xuxueli/executor/sample/jfinal/jobhandler/HttpJobHandler.java @@ -28,25 +28,36 @@ public class HttpJobHandler extends IJobHandler { } // httpclient - HttpClient httpClient = new HttpClient(); - httpClient.setFollowRedirects(false); // Configure HttpClient, for example: - httpClient.start(); // Start HttpClient - - // request - Request request = httpClient.newRequest(param); - request.method(HttpMethod.GET); - request.timeout(5000, TimeUnit.MILLISECONDS); - - // invoke - ContentResponse response = request.send(); - if (response.getStatus() != HttpStatus.OK_200) { - XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus()); + HttpClient httpClient = null; + try { + httpClient = new HttpClient(); + httpClient.setFollowRedirects(false); // Configure HttpClient, for example: + httpClient.start(); // Start HttpClient + + // request + Request request = httpClient.newRequest(param); + request.method(HttpMethod.GET); + request.timeout(5000, TimeUnit.MILLISECONDS); + + // invoke + ContentResponse response = request.send(); + if (response.getStatus() != HttpStatus.OK_200) { + XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus()); + return FAIL; + } + + String responseMsg = response.getContentAsString(); + XxlJobLogger.log(responseMsg); + return SUCCESS; + } catch (Exception e) { + XxlJobLogger.log(e); return FAIL; + } finally { + if (httpClient != null) { + httpClient.stop(); + } } - String responseMsg = response.getContentAsString(); - XxlJobLogger.log(responseMsg); - return SUCCESS; } } diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java index 45d2268e..615bbd88 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-nutz/src/main/java/com/xuxueli/executor/sample/nutz/jobhandler/HttpJobHandler.java @@ -32,25 +32,36 @@ public class HttpJobHandler extends IJobHandler { } // httpclient - HttpClient httpClient = new HttpClient(); - httpClient.setFollowRedirects(false); // Configure HttpClient, for example: - httpClient.start(); // Start HttpClient - - // request - Request request = httpClient.newRequest(param); - request.method(HttpMethod.GET); - request.timeout(5000, TimeUnit.MILLISECONDS); - - // invoke - ContentResponse response = request.send(); - if (response.getStatus() != HttpStatus.OK_200) { - XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus()); + HttpClient httpClient = null; + try { + httpClient = new HttpClient(); + httpClient.setFollowRedirects(false); // Configure HttpClient, for example: + httpClient.start(); // Start HttpClient + + // request + Request request = httpClient.newRequest(param); + request.method(HttpMethod.GET); + request.timeout(5000, TimeUnit.MILLISECONDS); + + // invoke + ContentResponse response = request.send(); + if (response.getStatus() != HttpStatus.OK_200) { + XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus()); + return FAIL; + } + + String responseMsg = response.getContentAsString(); + XxlJobLogger.log(responseMsg); + return SUCCESS; + } catch (Exception e) { + XxlJobLogger.log(e); return FAIL; + } finally { + if (httpClient != null) { + httpClient.stop(); + } } - String responseMsg = response.getContentAsString(); - XxlJobLogger.log(responseMsg); - return SUCCESS; } } diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java index ea68d749..61dbab1c 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java @@ -32,25 +32,36 @@ public class HttpJobHandler extends IJobHandler { } // httpclient - HttpClient httpClient = new HttpClient(); - httpClient.setFollowRedirects(false); // Configure HttpClient, for example: - httpClient.start(); // Start HttpClient - - // request - Request request = httpClient.newRequest(param); - request.method(HttpMethod.GET); - request.timeout(5000, TimeUnit.MILLISECONDS); - - // invoke - ContentResponse response = request.send(); - if (response.getStatus() != HttpStatus.OK_200) { - XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus()); + HttpClient httpClient = null; + try { + httpClient = new HttpClient(); + httpClient.setFollowRedirects(false); // Configure HttpClient, for example: + httpClient.start(); // Start HttpClient + + // request + Request request = httpClient.newRequest(param); + request.method(HttpMethod.GET); + request.timeout(5000, TimeUnit.MILLISECONDS); + + // invoke + ContentResponse response = request.send(); + if (response.getStatus() != HttpStatus.OK_200) { + XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus()); + return FAIL; + } + + String responseMsg = response.getContentAsString(); + XxlJobLogger.log(responseMsg); + return SUCCESS; + } catch (Exception e) { + XxlJobLogger.log(e); return FAIL; + } finally { + if (httpClient != null) { + httpClient.stop(); + } } - String responseMsg = response.getContentAsString(); - XxlJobLogger.log(responseMsg); - return SUCCESS; } } diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java index ea68d749..61dbab1c 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java +++ b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/service/jobhandler/HttpJobHandler.java @@ -32,25 +32,36 @@ public class HttpJobHandler extends IJobHandler { } // httpclient - HttpClient httpClient = new HttpClient(); - httpClient.setFollowRedirects(false); // Configure HttpClient, for example: - httpClient.start(); // Start HttpClient - - // request - Request request = httpClient.newRequest(param); - request.method(HttpMethod.GET); - request.timeout(5000, TimeUnit.MILLISECONDS); - - // invoke - ContentResponse response = request.send(); - if (response.getStatus() != HttpStatus.OK_200) { - XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus()); + HttpClient httpClient = null; + try { + httpClient = new HttpClient(); + httpClient.setFollowRedirects(false); // Configure HttpClient, for example: + httpClient.start(); // Start HttpClient + + // request + Request request = httpClient.newRequest(param); + request.method(HttpMethod.GET); + request.timeout(5000, TimeUnit.MILLISECONDS); + + // invoke + ContentResponse response = request.send(); + if (response.getStatus() != HttpStatus.OK_200) { + XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus()); + return FAIL; + } + + String responseMsg = response.getContentAsString(); + XxlJobLogger.log(responseMsg); + return SUCCESS; + } catch (Exception e) { + XxlJobLogger.log(e); return FAIL; + } finally { + if (httpClient != null) { + httpClient.stop(); + } } - String responseMsg = response.getContentAsString(); - XxlJobLogger.log(responseMsg); - return SUCCESS; } } diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/logback.xml b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/logback.xml index bbea067c..d5a0d2ca 100644 --- a/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/logback.xml +++ b/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/logback.xml @@ -5,9 +5,6 @@ - %d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n @@ -29,9 +26,4 @@ - - \ No newline at end of file