通用HTTP任务Handler(httpJobHandler)优化:修复 "setDoOutput(true)" 导致任务请求GetMethod失效问题;

pull/22/MERGE
xuxueli 5 years ago
parent 16ba18eafc
commit 17b416ca07

@ -51,6 +51,7 @@ public class HttpJobHandler extends IJobHandler {
XxlJobLogger.log("method["+ method +"] invalid.");
return ReturnT.FAIL;
}
boolean isPostMethod = method.equals("POST");
// request
HttpURLConnection connection = null;
@ -62,7 +63,7 @@ public class HttpJobHandler extends IJobHandler {
// connection setting
connection.setRequestMethod(method);
connection.setDoOutput(true);
connection.setDoOutput(isPostMethod);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setReadTimeout(5 * 1000);
@ -75,7 +76,7 @@ public class HttpJobHandler extends IJobHandler {
connection.connect();
// data
if (data!=null && data.trim().length()>0) {
if (isPostMethod && data!=null && data.trim().length()>0) {
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.write(data.getBytes("UTF-8"));
dataOutputStream.flush();

@ -51,8 +51,9 @@ public class HttpJobHandler extends IJobHandler {
XxlJobLogger.log("method["+ method +"] invalid.");
return ReturnT.FAIL;
}
boolean isPostMethod = method.equals("POST");
// request
// request
HttpURLConnection connection = null;
BufferedReader bufferedReader = null;
try {
@ -62,7 +63,7 @@ public class HttpJobHandler extends IJobHandler {
// connection setting
connection.setRequestMethod(method);
connection.setDoOutput(true);
connection.setDoOutput(isPostMethod);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setReadTimeout(5 * 1000);
@ -75,7 +76,7 @@ public class HttpJobHandler extends IJobHandler {
connection.connect();
// data
if (data!=null && data.trim().length()>0) {
if (isPostMethod && data!=null && data.trim().length()>0) {
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.write(data.getBytes("UTF-8"));
dataOutputStream.flush();

@ -51,6 +51,7 @@ public class HttpJobHandler extends IJobHandler {
XxlJobLogger.log("method["+ method +"] invalid.");
return ReturnT.FAIL;
}
boolean isPostMethod = method.equals("POST");
// request
HttpURLConnection connection = null;
@ -62,7 +63,7 @@ public class HttpJobHandler extends IJobHandler {
// connection setting
connection.setRequestMethod(method);
connection.setDoOutput(true);
connection.setDoOutput(isPostMethod);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setReadTimeout(5 * 1000);
@ -75,7 +76,7 @@ public class HttpJobHandler extends IJobHandler {
connection.connect();
// data
if (data!=null && data.trim().length()>0) {
if (isPostMethod && data!=null && data.trim().length()>0) {
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.write(data.getBytes("UTF-8"));
dataOutputStream.flush();

@ -51,6 +51,7 @@ public class HttpJobHandler extends IJobHandler {
XxlJobLogger.log("method["+ method +"] invalid.");
return ReturnT.FAIL;
}
boolean isPostMethod = method.equals("POST");
// request
HttpURLConnection connection = null;
@ -62,7 +63,7 @@ public class HttpJobHandler extends IJobHandler {
// connection setting
connection.setRequestMethod(method);
connection.setDoOutput(true);
connection.setDoOutput(isPostMethod);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setReadTimeout(5 * 1000);
@ -75,7 +76,7 @@ public class HttpJobHandler extends IJobHandler {
connection.connect();
// data
if (data!=null && data.trim().length()>0) {
if (isPostMethod && data!=null && data.trim().length()>0) {
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.write(data.getBytes("UTF-8"));
dataOutputStream.flush();

@ -151,6 +151,7 @@ public class SampleXxlJob {
XxlJobLogger.log("method["+ method +"] invalid.");
return ReturnT.FAIL;
}
boolean isPostMethod = method.equals("POST");
// request
HttpURLConnection connection = null;
@ -162,7 +163,7 @@ public class SampleXxlJob {
// connection setting
connection.setRequestMethod(method);
connection.setDoOutput(true);
connection.setDoOutput(isPostMethod);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setReadTimeout(5 * 1000);
@ -175,7 +176,7 @@ public class SampleXxlJob {
connection.connect();
// data
if (data!=null && data.trim().length()>0) {
if (isPostMethod && data!=null && data.trim().length()>0) {
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.write(data.getBytes("UTF-8"));
dataOutputStream.flush();

@ -151,6 +151,7 @@ public class SampleXxlJob {
XxlJobLogger.log("method["+ method +"] invalid.");
return ReturnT.FAIL;
}
boolean isPostMethod = method.equals("POST");
// request
HttpURLConnection connection = null;
@ -162,7 +163,7 @@ public class SampleXxlJob {
// connection setting
connection.setRequestMethod(method);
connection.setDoOutput(true);
connection.setDoOutput(isPostMethod);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setReadTimeout(5 * 1000);
@ -175,7 +176,7 @@ public class SampleXxlJob {
connection.connect();
// data
if (data!=null && data.trim().length()>0) {
if (isPostMethod && data!=null && data.trim().length()>0) {
DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream());
dataOutputStream.write(data.getBytes("UTF-8"));
dataOutputStream.flush();

Loading…
Cancel
Save