|
@@ -17,6 +17,7 @@
|
|
|
package org.apache.dolphinscheduler.server.worker.task.http;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.commons.io.Charsets;
|
|
|
import org.apache.dolphinscheduler.common.Constants;
|
|
@@ -26,6 +27,7 @@ import org.apache.dolphinscheduler.common.process.HttpProperty;
|
|
|
import org.apache.dolphinscheduler.common.process.Property;
|
|
|
import org.apache.dolphinscheduler.common.task.AbstractParameters;
|
|
|
import org.apache.dolphinscheduler.common.task.http.HttpParameters;
|
|
|
+import org.apache.dolphinscheduler.common.utils.CollectionUtils;
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
|
|
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
|
|
|
import org.apache.dolphinscheduler.common.utils.StringUtils;
|
|
@@ -51,6 +53,7 @@ import org.slf4j.Logger;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -98,7 +101,7 @@ public class HttpTask extends AbstractTask {
|
|
|
@Override
|
|
|
public void init() {
|
|
|
logger.info("http task params {}", taskProps.getTaskParams());
|
|
|
- this.httpParameters = JSONObject.parseObject(taskProps.getTaskParams(), HttpParameters.class);
|
|
|
+ this.httpParameters = JSON.parseObject(taskProps.getTaskParams(), HttpParameters.class);
|
|
|
|
|
|
if (!httpParameters.checkParameters()) {
|
|
|
throw new RuntimeException("http task params is not valid");
|
|
@@ -146,12 +149,12 @@ public class HttpTask extends AbstractTask {
|
|
|
processInstance.getCmdTypeIfComplement(),
|
|
|
processInstance.getScheduleTime());
|
|
|
List<HttpProperty> httpPropertyList = new ArrayList<>();
|
|
|
- if(httpParameters.getHttpParams() != null && httpParameters.getHttpParams().size() > 0){
|
|
|
+ if(CollectionUtils.isNotEmpty(httpParameters.getHttpParams() )){
|
|
|
for (HttpProperty httpProperty: httpParameters.getHttpParams()) {
|
|
|
- String jsonObject = JSONObject.toJSONString(httpProperty);
|
|
|
+ String jsonObject = JSON.toJSONString(httpProperty);
|
|
|
String params = ParameterUtils.convertParameterPlaceholders(jsonObject,ParamUtils.convert(paramsMap));
|
|
|
logger.info("http request params:{}",params);
|
|
|
- httpPropertyList.add(JSONObject.parseObject(params,HttpProperty.class));
|
|
|
+ httpPropertyList.add(JSON.parseObject(params,HttpProperty.class));
|
|
|
}
|
|
|
}
|
|
|
addRequestParams(builder,httpPropertyList);
|
|
@@ -176,8 +179,7 @@ public class HttpTask extends AbstractTask {
|
|
|
if (entity == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- String webPage = EntityUtils.toString(entity, StandardCharsets.UTF_8.name());
|
|
|
- return webPage;
|
|
|
+ return EntityUtils.toString(entity, StandardCharsets.UTF_8.name());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -186,8 +188,7 @@ public class HttpTask extends AbstractTask {
|
|
|
* @return status code
|
|
|
*/
|
|
|
protected int getStatusCode(CloseableHttpResponse httpResponse) {
|
|
|
- int status = httpResponse.getStatusLine().getStatusCode();
|
|
|
- return status;
|
|
|
+ return httpResponse.getStatusLine().getStatusCode();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -252,7 +253,7 @@ public class HttpTask extends AbstractTask {
|
|
|
* @param httpPropertyList http property list
|
|
|
*/
|
|
|
protected void addRequestParams(RequestBuilder builder,List<HttpProperty> httpPropertyList) {
|
|
|
- if(httpPropertyList != null && httpPropertyList.size() > 0){
|
|
|
+ if(CollectionUtils.isNotEmpty(httpPropertyList)){
|
|
|
JSONObject jsonParam = new JSONObject();
|
|
|
for (HttpProperty property: httpPropertyList){
|
|
|
if(property.getHttpParametersType() != null){
|
|
@@ -276,12 +277,10 @@ public class HttpTask extends AbstractTask {
|
|
|
* @param httpPropertyList http property list
|
|
|
*/
|
|
|
protected void setHeaders(HttpUriRequest request,List<HttpProperty> httpPropertyList) {
|
|
|
- if(httpPropertyList != null && httpPropertyList.size() > 0){
|
|
|
- for (HttpProperty property: httpPropertyList){
|
|
|
- if(property.getHttpParametersType() != null) {
|
|
|
- if (property.getHttpParametersType().equals(HttpParametersType.HEADERS)) {
|
|
|
- request.addHeader(property.getProp(), property.getValue());
|
|
|
- }
|
|
|
+ if(CollectionUtils.isNotEmpty(httpPropertyList)){
|
|
|
+ for (HttpProperty property: httpPropertyList) {
|
|
|
+ if (HttpParametersType.HEADERS.equals(property.getHttpParametersType())) {
|
|
|
+ request.addHeader(property.getProp(), property.getValue());
|
|
|
}
|
|
|
}
|
|
|
}
|