64 lines
2.1 KiB
64 lines
2.1 KiB
/* |
|
* Copyright (C), 2018-2021 |
|
* Project: starter |
|
* FileName: AbstractDataOutput |
|
* Author: xx |
|
* Date: 2021/4/12 15:13 |
|
*/ |
|
package com.fr.plugin.ajchk.action; |
|
|
|
import com.fanruan.api.i18n.I18nKit; |
|
import com.fanruan.api.util.StringKit; |
|
import com.fr.schedule.feature.output.OutputActionHandler; |
|
|
|
import java.util.HashMap; |
|
import java.util.Map; |
|
|
|
/** |
|
* <Function Description><br> |
|
* <AbstractDataOutput> |
|
* |
|
* @author xx |
|
* @since 1.0.0 |
|
*/ |
|
public abstract class AbstractDataOutput extends OutputActionHandler<OutputHttp> { |
|
@Override |
|
public void doAction(OutputHttp outputHttp, Map<String, Object> taskParams) throws Exception { |
|
this.checkOutputHttp(outputHttp); |
|
Map<String, String> bodyParams = getHttpParams(outputHttp.getBodyParameters()); |
|
if (bodyParams.isEmpty()) { |
|
return; |
|
} |
|
Map<String, String> headers = getHttpParams(outputHttp.getHeaders()); |
|
checkHeader(headers); |
|
operation(outputHttp, taskParams, bodyParams, headers); |
|
} |
|
|
|
/** |
|
* 根据参数名在定时调度任务参数结果中,提取参数值信息 |
|
* |
|
* @return |
|
* @throws Exception |
|
*/ |
|
private Map<String, String> getHttpParams(String paramsStr) { |
|
String[] params = paramsStr.split(";"); |
|
String[] keyAndValue; |
|
Map<String, String> result = new HashMap<>(); |
|
for (String content : params) { |
|
keyAndValue = content.split("="); |
|
result.put(keyAndValue[0], keyAndValue[1]); |
|
} |
|
return result; |
|
} |
|
|
|
public void checkOutputHttp(OutputHttp outputHttp) throws Exception { |
|
if (outputHttp == null || StringKit.isBlank(outputHttp.getApiUrl())) { |
|
throw new Exception(I18nKit.getLocText("Plugin-httpaction_Link_Valid")); |
|
} |
|
} |
|
|
|
public void checkHeader(Map<String, String> headers) throws Exception { |
|
} |
|
|
|
public abstract void operation(OutputHttp outputHttp, Map<String, Object> taskParams, Map<String, String> bodyParams, Map<String, String> headers) throws Exception; |
|
} |