2017-12-19 14:55:52 +08:00
|
|
|
|
package com.nis.web.controller.restful;
|
|
|
|
|
|
|
2018-06-02 13:01:27 +08:00
|
|
|
|
import java.io.File;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import java.io.IOException;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
2018-07-19 10:19:57 +08:00
|
|
|
|
import com.nis.web.service.AuditLogThread;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
|
|
|
|
|
import com.nis.domain.restful.ConfigCompile;
|
|
|
|
|
|
import com.nis.domain.restful.ConfigSource;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.nis.domain.restful.FileDesc;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.restful.RestBusinessCode;
|
|
|
|
|
|
import com.nis.restful.RestServiceException;
|
2018-08-03 18:08:46 +08:00
|
|
|
|
import com.nis.restful.ServiceRuntimeException;
|
2018-07-04 17:03:04 +08:00
|
|
|
|
import com.nis.util.CompileVal;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.util.Constants;
|
2018-06-07 18:37:30 +08:00
|
|
|
|
import com.nis.util.FileUtils;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.util.OracleErrorCodeUtil;
|
|
|
|
|
|
import com.nis.util.StringUtil;
|
|
|
|
|
|
import com.nis.util.StringUtils;
|
|
|
|
|
|
import com.nis.web.controller.BaseRestController;
|
|
|
|
|
|
import com.nis.web.service.ServicesRequestLogService;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.nis.web.service.fdfs.FastDFSFile;
|
|
|
|
|
|
import com.nis.web.service.fdfs.FileManager;
|
2018-05-19 18:35:24 +08:00
|
|
|
|
import com.nis.web.service.restful.ConfigRedisService;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.web.service.restful.ConfigSourcesService;
|
|
|
|
|
|
import com.wordnik.swagger.annotations.Api;
|
|
|
|
|
|
import com.wordnik.swagger.annotations.ApiOperation;
|
|
|
|
|
|
import com.wordnik.swagger.annotations.ApiParam;
|
|
|
|
|
|
|
2018-07-18 11:05:54 +08:00
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @ClassName: ConfigSourcesController
|
|
|
|
|
|
* @Description: 配置存储服务
|
|
|
|
|
|
* @author (zx)
|
|
|
|
|
|
* @date 2016年9月5日 下午6:20:33
|
|
|
|
|
|
* @version V1.0
|
|
|
|
|
|
*/
|
2018-05-31 10:09:29 +08:00
|
|
|
|
// @Scope("prototype")
|
2017-12-19 14:55:52 +08:00
|
|
|
|
@RestController
|
|
|
|
|
|
@RequestMapping("${servicePath}")
|
2018-07-19 10:19:57 +08:00
|
|
|
|
@Api(value = "ConfigSourcesController", description = "配置规则服务,主要对MAAT规则和回调规则做解析、存储与更新操作")
|
2017-12-19 14:55:52 +08:00
|
|
|
|
public class ConfigSourcesController extends BaseRestController {
|
2018-07-17 18:16:49 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
protected ConfigSourcesService configSourcesService;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
protected ServicesRequestLogService servicesRequestLogService;
|
|
|
|
|
|
|
2018-05-17 14:53:57 +08:00
|
|
|
|
@Autowired
|
2018-05-21 19:06:19 +08:00
|
|
|
|
ConfigRedisService configRedisService;
|
2018-05-17 14:53:57 +08:00
|
|
|
|
|
2018-06-01 10:27:03 +08:00
|
|
|
|
|
2018-05-23 19:54:35 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.POST)
|
2018-07-19 10:19:57 +08:00
|
|
|
|
@ApiOperation(value = "MAAT规则存储接口", httpMethod = "POST", response = Map.class, notes = "接收MAAT规则数据,存储到流量处理平台配置线中")
|
|
|
|
|
|
@ApiParam(value = "MAAT规则对象", name = "configSource", required = true)
|
|
|
|
|
|
public Map createMaatConfigSource(@RequestBody ConfigSource configSource, HttpServletRequest request,
|
2017-12-19 14:55:52 +08:00
|
|
|
|
HttpServletResponse response) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
CompileVal.setBusinessCode(null);
|
2017-12-19 14:55:52 +08:00
|
|
|
|
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
2018-07-19 10:19:57 +08:00
|
|
|
|
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
|
2017-12-19 14:55:52 +08:00
|
|
|
|
configSource);
|
2018-07-19 10:19:57 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
|
|
if (null != configSource && null != configSource.getConfigCompileList()
|
|
|
|
|
|
&& configSource.getConfigCompileList().size() > 0) {
|
2018-07-19 10:19:57 +08:00
|
|
|
|
checkOpAction(thread, System.currentTimeMillis() - start, configSource.getOpAction(), Constants.OPACTION_POST);
|
2017-12-19 14:55:52 +08:00
|
|
|
|
// 验证配置编译数据
|
|
|
|
|
|
validateConfigSource(thread, start, configSource);
|
2018-06-11 15:06:47 +08:00
|
|
|
|
String msg = configSourcesService.saveMaatConfig(thread, start, configSource.getConfigCompileList(), sb);
|
2018-07-19 10:19:57 +08:00
|
|
|
|
|
|
|
|
|
|
if ("error".equals(msg)) {
|
2018-06-11 15:06:47 +08:00
|
|
|
|
Exception exception = ConfigSourcesService.getMsgList().get(0);
|
2018-08-03 18:08:46 +08:00
|
|
|
|
if (exception instanceof RestServiceException) {
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"Maat 规则存储异常:" + exception.getMessage(), CompileVal.getBusinessCode());
|
|
|
|
|
|
}else{
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"Maat 规则存储异常:" + exception.getMessage(), CompileVal.getBusinessCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-11 15:06:47 +08:00
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
} else {
|
2018-07-19 10:19:57 +08:00
|
|
|
|
thread.setExceptionInfo("Maat规则不能为空");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "Maat规则不能为空",
|
2017-12-19 14:55:52 +08:00
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
|
2018-07-19 10:19:57 +08:00
|
|
|
|
"Maat规则下发成功" + sb.toString(), Constants.IS_DEBUG ? configSource : null);
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.PUT)
|
2018-07-19 10:19:57 +08:00
|
|
|
|
@ApiOperation(value = "MAAT规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收Maat规则,对其状态置为失效")
|
|
|
|
|
|
@ApiParam(value = "MAAT规则对象", name = "configSource", required = true)
|
2017-12-19 14:55:52 +08:00
|
|
|
|
public Map updateConfigSource(@RequestBody ConfigSource configSource, HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
CompileVal.setBusinessCode(null);
|
2017-12-19 14:55:52 +08:00
|
|
|
|
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
2018-07-19 10:19:57 +08:00
|
|
|
|
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
|
2017-12-19 14:55:52 +08:00
|
|
|
|
configSource);
|
|
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
|
|
if (null == configSource.getOpTime()) {
|
|
|
|
|
|
configSource.setOpTime(new Date());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (null != configSource && null != configSource.getConfigCompileList()
|
|
|
|
|
|
&& configSource.getConfigCompileList().size() > 0) {
|
|
|
|
|
|
int opAction = configSource.getOpAction();
|
|
|
|
|
|
checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
|
|
|
|
|
|
String msg = "";
|
|
|
|
|
|
ConfigCompile compile = configSource.getConfigCompileList().get(0);
|
2018-06-04 10:18:31 +08:00
|
|
|
|
// zdx 20180528改为调用rkg接口取消配置
|
2018-06-02 13:01:27 +08:00
|
|
|
|
msg = configSourcesService.updateConfigSources(thread, start, configSource.getConfigCompileList(),
|
2018-06-01 10:27:03 +08:00
|
|
|
|
configSource.getOpTime(), sb);
|
2018-05-17 14:53:57 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (msg.equals("error")) {
|
|
|
|
|
|
Exception exception = ConfigSourcesService.getMsgList().get(0);
|
2018-08-03 18:08:46 +08:00
|
|
|
|
if (exception instanceof RestServiceException) {
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"MAAT规则状态更新时出现异常:" + exception.getMessage(),CompileVal.getBusinessCode());
|
|
|
|
|
|
}else {
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"MAAT规则状态更新时出现异常:" + exception.getMessage(),CompileVal.getBusinessCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
// configSourcesService.updateConfigSource(thread, start,
|
|
|
|
|
|
// configSource.getConfigCompileList(),
|
|
|
|
|
|
// configSource.getOpTime(), sb);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
2018-07-19 10:19:57 +08:00
|
|
|
|
thread.setExceptionInfo("Maat规则不能为空");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "Maat规则不能为空" + sb.toString(),
|
2017-12-19 14:55:52 +08:00
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
|
2018-07-19 10:19:57 +08:00
|
|
|
|
"Maat规则状态更新成功" + sb.toString(), Constants.IS_DEBUG ? configSource : null);
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/cfg/v1/configModifySources", method = RequestMethod.PUT)
|
2018-07-19 10:19:57 +08:00
|
|
|
|
@ApiOperation(value = "MAAT规则修改接口", httpMethod = "PUT", response = Map.class, notes = "接收Maat规则,对其规则内容进行修改")
|
|
|
|
|
|
@ApiParam(value = "MAAT规则对象", name = "configSource", required = true)
|
2017-12-19 14:55:52 +08:00
|
|
|
|
public Map configModifySources(@RequestBody ConfigSource configSource, HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) {
|
|
|
|
|
|
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
2018-07-19 10:19:57 +08:00
|
|
|
|
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
|
2017-12-19 14:55:52 +08:00
|
|
|
|
configSource);
|
|
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
|
|
if (null != configSource && null != configSource.getConfigCompileList()
|
|
|
|
|
|
&& configSource.getConfigCompileList().size() > 0) {
|
|
|
|
|
|
int opAction = configSource.getOpAction();
|
|
|
|
|
|
checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
|
|
|
|
|
|
// 验证配置编译数据
|
|
|
|
|
|
validateConfigSource(thread, start, configSource);
|
|
|
|
|
|
try {
|
|
|
|
|
|
List<ConfigCompile> configCompileList = configSource.getConfigCompileList();
|
|
|
|
|
|
if (null != configCompileList && configCompileList.size() > 0) {
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
for (ConfigCompile configCompile : configCompileList) {
|
|
|
|
|
|
Long compileId = configCompile.getCompileId();
|
|
|
|
|
|
if (null == compileId) {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置id不能为空");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
2018-06-04 10:18:31 +08:00
|
|
|
|
// if ((configCompile.getActiveSys() != null) ||
|
|
|
|
|
|
// (configCompile.getEffectiveRange() != null
|
|
|
|
|
|
// && !configCompile.getEffectiveRange().equals(""))) {
|
|
|
|
|
|
// count++;
|
|
|
|
|
|
// configSourcesService.setCompileInvalid(configCompile);
|
|
|
|
|
|
// }
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
|
Thread.sleep(14000);
|
|
|
|
|
|
}
|
|
|
|
|
|
String str = configSourcesService.configModifySources(configCompileList);
|
|
|
|
|
|
if (str.equals("idIsNull")) {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置id不能为空");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置数据不能为空");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据不能为空",
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
List<ConfigCompile> configCompileList = configSource.getConfigCompileList();
|
|
|
|
|
|
if (null != configCompileList && configCompileList.size() > 0) {
|
|
|
|
|
|
for (ConfigCompile configCompile : configCompileList) {
|
|
|
|
|
|
Long compileId = configCompile.getCompileId();
|
|
|
|
|
|
if (null == compileId) {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置id不能为空");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
2018-06-04 10:18:31 +08:00
|
|
|
|
// if ((configCompile.getActiveSys() != null) ||
|
|
|
|
|
|
// (configCompile.getEffectiveRange() != null
|
|
|
|
|
|
// && !configCompile.getEffectiveRange().equals(""))) {
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// configSourcesService.setCompileValid(configCompile);
|
|
|
|
|
|
// } catch (Exception e1) {
|
|
|
|
|
|
// String errorCode = "";
|
|
|
|
|
|
// String message = e.getMessage();
|
|
|
|
|
|
// if (null != message && message.length() > 0) {
|
|
|
|
|
|
// int index = message.toUpperCase().indexOf("ORA-");
|
|
|
|
|
|
// if (index != -1) {
|
|
|
|
|
|
// errorCode = message.substring(index + 4, index + 9);
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil
|
|
|
|
|
|
// .throwExceptionInfo(errorCode);
|
|
|
|
|
|
// for (int errorNum : throwExceptionInfo.keySet()) {
|
|
|
|
|
|
// if (errorNum == 998) {
|
|
|
|
|
|
// thread.setExceptionInfo(e.toString());
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// thread.setExceptionInfo(throwExceptionInfo.get(errorNum));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
// throwExceptionInfo.get(errorNum), errorNum);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String errorCode = "";
|
|
|
|
|
|
String message = e.getMessage();
|
|
|
|
|
|
if (null != message && message.length() > 0) {
|
|
|
|
|
|
int index = message.toUpperCase().indexOf("ORA-");
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
|
errorCode = message.substring(index + 4, index + 9);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil.throwExceptionInfo(errorCode);
|
|
|
|
|
|
for (int errorNum : throwExceptionInfo.keySet()) {
|
|
|
|
|
|
if (errorNum == 998) {
|
|
|
|
|
|
thread.setExceptionInfo(e.toString());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo(throwExceptionInfo.get(errorNum));
|
|
|
|
|
|
}
|
2018-08-03 18:08:46 +08:00
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
2017-12-19 14:55:52 +08:00
|
|
|
|
throwExceptionInfo.get(errorNum), errorNum);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
thread.setExceptionInfo("编译配置数据不能为空");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置数据不能为空",
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
|
2018-05-19 18:35:24 +08:00
|
|
|
|
"修改编译配置数据成功" + sb.toString(), Constants.IS_DEBUG ? configSource : null);
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-19 10:19:57 +08:00
|
|
|
|
private void validateConfigSource(AuditLogThread thread, long start, ConfigSource configSource) {
|
2017-12-19 14:55:52 +08:00
|
|
|
|
String errorInfo = "";
|
|
|
|
|
|
|
|
|
|
|
|
List<ConfigCompile> configCompileList = configSource.getConfigCompileList();
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(configSource.getOperator())) {
|
|
|
|
|
|
errorInfo = "get operator is Empty";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(configSource.getVersion())) {
|
|
|
|
|
|
errorInfo = "get version is Empty";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isBlank(configSource.getOpTime())) {
|
|
|
|
|
|
errorInfo = "get OpTime is Empty";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (configCompileList.size() <= 0) {
|
2018-07-19 10:19:57 +08:00
|
|
|
|
errorInfo = "Maat规则不能为空";
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (!errorInfo.equals("")) {
|
|
|
|
|
|
thread.setExceptionInfo(errorInfo);
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorInfo,
|
|
|
|
|
|
RestBusinessCode.missing_args.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-05-31 10:09:29 +08:00
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.POST, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
|
2018-07-19 10:19:57 +08:00
|
|
|
|
@ApiOperation(value = "回调(通用)规则存储接口", httpMethod = "POST", response = Map.class, notes = "接收回调规则数据,格式为结构化行列式JSON,存储到流量处理平台配置线中")
|
2018-05-31 10:09:29 +08:00
|
|
|
|
public Map createCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
|
2018-05-24 17:22:38 +08:00
|
|
|
|
HttpServletResponse response) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
CompileVal.setBusinessCode(null);
|
2018-05-24 17:22:38 +08:00
|
|
|
|
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
2018-07-19 10:19:57 +08:00
|
|
|
|
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
|
2018-05-31 10:09:29 +08:00
|
|
|
|
null);
|
2018-07-19 10:19:57 +08:00
|
|
|
|
|
|
|
|
|
|
String msg = configSourcesService.saveCommonSources(thread, start, jsonString);
|
2018-06-11 15:06:47 +08:00
|
|
|
|
if (msg.equals("error")) {
|
|
|
|
|
|
Exception exception = ConfigSourcesService.getMsgList().get(0);
|
2018-08-03 18:08:46 +08:00
|
|
|
|
if (exception instanceof RestServiceException) {
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"回调规则存储异常:" + exception.getMessage(), CompileVal.getBusinessCode());
|
|
|
|
|
|
}else {
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"回调规则存储异常:" + exception.getMessage(), CompileVal.getBusinessCode());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-06-11 15:06:47 +08:00
|
|
|
|
}
|
2018-07-19 10:19:57 +08:00
|
|
|
|
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则下发成功",
|
2018-05-31 10:09:29 +08:00
|
|
|
|
Constants.IS_DEBUG ? jsonString : null);
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-06-04 10:18:31 +08:00
|
|
|
|
|
2018-07-19 10:19:57 +08:00
|
|
|
|
|
2018-06-02 13:01:27 +08:00
|
|
|
|
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT)
|
2018-08-03 18:08:46 +08:00
|
|
|
|
@ApiOperation(value = "回调(通用)规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收回调规则,对其状态置为失效")
|
2018-06-04 15:14:52 +08:00
|
|
|
|
public Map updateCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
CompileVal.setBusinessCode(null);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
2018-07-19 10:19:57 +08:00
|
|
|
|
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
|
2018-06-07 18:37:30 +08:00
|
|
|
|
jsonString);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
StringBuffer sb = new StringBuffer();
|
2018-06-11 15:06:47 +08:00
|
|
|
|
String msg = configSourcesService.updateCommonSources(thread, start, jsonString, new Date(), sb);
|
|
|
|
|
|
if (msg.equals("error")) {
|
|
|
|
|
|
Exception exception = ConfigSourcesService.getMsgList().get(0);
|
2018-08-03 18:08:46 +08:00
|
|
|
|
if (exception instanceof RestServiceException) {
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"回调规则状态更新异常:" + exception.getMessage(), CompileVal.getBusinessCode());
|
|
|
|
|
|
}else {
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
"回调规则状态更新异常:" + exception.getMessage(), CompileVal.getBusinessCode());
|
|
|
|
|
|
}
|
2018-06-11 15:06:47 +08:00
|
|
|
|
}
|
2018-07-19 10:19:57 +08:00
|
|
|
|
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则状态更新成功",
|
2018-06-07 18:37:30 +08:00
|
|
|
|
Constants.IS_DEBUG ? jsonString : null);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
2018-06-04 10:18:31 +08:00
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
@RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST)
|
2018-07-19 10:19:57 +08:00
|
|
|
|
@ApiOperation(value = "样例文件上传服务接口", httpMethod = "POST", response = Map.class, notes = "样例文件上传服务")
|
2018-05-24 17:22:38 +08:00
|
|
|
|
@ApiParam(value = "样例文件上传服务", name = "MultipartFile", required = true)
|
|
|
|
|
|
public Map fileUploadSource(@RequestBody MultipartFile file, HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) {
|
|
|
|
|
|
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
2018-07-19 10:19:57 +08:00
|
|
|
|
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
|
2018-06-04 10:18:31 +08:00
|
|
|
|
null);
|
|
|
|
|
|
String filePath = "";
|
2018-05-24 17:22:38 +08:00
|
|
|
|
try {
|
2018-06-04 10:18:31 +08:00
|
|
|
|
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),
|
|
|
|
|
|
FileDesc.class);
|
|
|
|
|
|
if (null == file) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
thread.setExceptionInfo("请选择上传文件到file参数");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请选择上传文件到file参数",
|
2018-07-04 17:03:04 +08:00
|
|
|
|
RestBusinessCode.FileIsNull.getValue());
|
2018-06-04 10:18:31 +08:00
|
|
|
|
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
2018-05-24 17:22:38 +08:00
|
|
|
|
if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
|
2018-06-04 10:18:31 +08:00
|
|
|
|
// 验证Md5
|
|
|
|
|
|
String md5 = DigestUtils.md5Hex(file.getInputStream());
|
2018-06-07 18:37:30 +08:00
|
|
|
|
// String md5 = DigestUtils.md5Hex(file.getBytes());
|
2018-06-04 10:18:31 +08:00
|
|
|
|
System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
if (!md5.equals(fileDesc.getChecksum())) {
|
|
|
|
|
|
thread.setExceptionInfo("checksum与文件MD5值不一致");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致",
|
2018-07-04 17:03:04 +08:00
|
|
|
|
RestBusinessCode.CheckSumIsWrong.getValue());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
|
2018-06-04 10:18:31 +08:00
|
|
|
|
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext);
|
|
|
|
|
|
// NameValuePair[] meta_list = new NameValuePair[5];
|
|
|
|
|
|
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
|
|
|
|
|
|
// meta_list[1] = new NameValuePair("fileLength",
|
|
|
|
|
|
// String.valueOf(file.getSize()));
|
|
|
|
|
|
// meta_list[2] = new NameValuePair("fileExt", ext);
|
|
|
|
|
|
// meta_list[3] = new NameValuePair("fileAuthor", "rkg");
|
|
|
|
|
|
// meta_list[4] = new NameValuePair("fileMd5", md5);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger.info("-----------------调用接口上传文件---------------");
|
2018-05-24 17:22:38 +08:00
|
|
|
|
filePath = FileManager.upload(fdsfile, null);
|
|
|
|
|
|
}
|
2018-07-18 13:15:29 +08:00
|
|
|
|
}catch (IOException e) {
|
2018-05-24 17:22:38 +08:00
|
|
|
|
// TODO Auto-generated catch block
|
2018-08-03 18:08:46 +08:00
|
|
|
|
logger.error(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+e.getMessage());
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
RestBusinessCode.FileUploadFailure.getErrorReason()+":"+ e.getMessage(), RestBusinessCode.FileUploadFailure.getValue());
|
2018-07-18 13:15:29 +08:00
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
|
// TODO: handle exception
|
|
|
|
|
|
logger.error(e.getMessage());
|
2018-08-03 18:08:46 +08:00
|
|
|
|
if (e instanceof RestServiceException) {
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
e.getMessage(), ((RestServiceException) e).getErrorCode());
|
|
|
|
|
|
}else if (e instanceof ServiceRuntimeException) {
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
|
|
|
|
|
|
}else {
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
e.getMessage(), RestBusinessCode.FileUploadFailure.getValue());
|
2018-07-18 13:15:29 +08:00
|
|
|
|
}
|
2018-08-03 18:08:46 +08:00
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
JSONObject jsonObj = new JSONObject();
|
2018-06-07 18:37:30 +08:00
|
|
|
|
// jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
|
2018-06-22 10:48:53 +08:00
|
|
|
|
jsonObj.put("accessUrl", filePath);
|
2018-06-04 10:18:31 +08:00
|
|
|
|
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "文件上传成功", jsonObj);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
2018-06-04 10:18:31 +08:00
|
|
|
|
|
2018-06-01 10:27:03 +08:00
|
|
|
|
@RequestMapping(value = "/cfg/v1/fileDigestSources", method = RequestMethod.POST)
|
2018-07-19 10:19:57 +08:00
|
|
|
|
@ApiOperation(value = "文件摘要获取接口", httpMethod = "POST", response = Map.class, notes = "文件摘要获取")
|
2018-06-01 10:27:03 +08:00
|
|
|
|
@ApiParam(value = "摘要文件", name = "MultipartFile", required = true)
|
2018-06-07 18:37:30 +08:00
|
|
|
|
public Map fileDigestSources(@RequestBody MultipartFile file, HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
long start = System.currentTimeMillis();
|
2018-07-19 10:19:57 +08:00
|
|
|
|
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
|
2018-06-04 10:18:31 +08:00
|
|
|
|
file, null);
|
|
|
|
|
|
if (file == null) {
|
2018-06-01 10:27:03 +08:00
|
|
|
|
thread.setExceptionInfo("请上传获取摘要的文件到file");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请上传获取摘要的文件到file参数",
|
2018-07-04 17:03:04 +08:00
|
|
|
|
RestBusinessCode.FileIsNull.getValue());
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
JSONObject resultObject = new JSONObject();
|
2018-06-04 10:18:31 +08:00
|
|
|
|
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),
|
|
|
|
|
|
FileDesc.class);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
try {
|
|
|
|
|
|
if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
|
2018-06-04 10:18:31 +08:00
|
|
|
|
// 验证Md5
|
2018-06-07 18:37:30 +08:00
|
|
|
|
|
2018-06-04 10:18:31 +08:00
|
|
|
|
String md5 = DigestUtils.md5Hex(file.getInputStream());
|
|
|
|
|
|
System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'");
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (!md5.equals(fileDesc.getChecksum())) {
|
|
|
|
|
|
thread.setExceptionInfo("checksum与文件MD5值不一致");
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致",
|
2018-07-04 17:03:04 +08:00
|
|
|
|
RestBusinessCode.CheckSumIsWrong.getValue());
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
|
2018-06-04 10:18:31 +08:00
|
|
|
|
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext);
|
|
|
|
|
|
// NameValuePair[] meta_list = new NameValuePair[5];
|
|
|
|
|
|
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
|
|
|
|
|
|
// meta_list[1] = new NameValuePair("fileLength",
|
|
|
|
|
|
// String.valueOf(file.getSize()));
|
|
|
|
|
|
// meta_list[2] = new NameValuePair("fileExt", ext);
|
|
|
|
|
|
// meta_list[3] = new NameValuePair("fileAuthor", "rkg");
|
|
|
|
|
|
// meta_list[4] = new NameValuePair("fileMd5", md5);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
logger.info("-----------------调用接口上传文件---------------");
|
|
|
|
|
|
String filePath = FileManager.upload(fdsfile, null);
|
2018-06-07 18:37:30 +08:00
|
|
|
|
// resultObject.put("path", filePath.substring(filePath.indexOf("group")));
|
2018-07-01 11:47:30 +08:00
|
|
|
|
resultObject.put("accessUrl", filePath);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
2018-08-03 18:08:46 +08:00
|
|
|
|
}catch (IOException e) {
|
2018-06-22 10:48:53 +08:00
|
|
|
|
// TODO Auto-generated catch block
|
2018-08-03 18:08:46 +08:00
|
|
|
|
logger.error(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+e.getMessage());
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
RestBusinessCode.FileUploadFailure.getErrorReason()+":"+ e.getMessage(), RestBusinessCode.FileUploadFailure.getValue());
|
2018-07-18 13:15:29 +08:00
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
|
// TODO: handle exception
|
|
|
|
|
|
logger.error(e.getMessage());
|
2018-08-03 18:08:46 +08:00
|
|
|
|
if (e instanceof RestServiceException) {
|
|
|
|
|
|
throw new RestServiceException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
e.getMessage(), ((RestServiceException) e).getErrorCode());
|
|
|
|
|
|
}else if (e instanceof ServiceRuntimeException) {
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
|
|
|
|
|
|
}else {
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
|
|
|
|
|
|
e.getMessage(), RestBusinessCode.FileUploadFailure.getValue());
|
2018-07-18 13:15:29 +08:00
|
|
|
|
}
|
2018-08-03 18:08:46 +08:00
|
|
|
|
|
2018-06-22 10:48:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
try {
|
2018-06-07 18:37:30 +08:00
|
|
|
|
String tempFilePath = request.getRealPath(File.separator) + "upload" + File.separator
|
|
|
|
|
|
+ (new Date()).getTime() + file.getOriginalFilename();
|
|
|
|
|
|
file.transferTo(new File(tempFilePath));
|
2018-06-22 10:48:53 +08:00
|
|
|
|
//System.out.println("------------" + tempFilePath);
|
|
|
|
|
|
System.out.println("摘要获取开始:---------------");
|
2018-06-04 10:18:31 +08:00
|
|
|
|
String digestStr = configSourcesService.getDigestGen(request.getRealPath(File.separator), tempFilePath);
|
2018-06-22 10:48:53 +08:00
|
|
|
|
System.out.println("摘要获取结束:---------------:"+digestStr);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
resultObject.put("digest", digestStr);
|
|
|
|
|
|
resultObject.put("rawLen", file.getSize());
|
2018-06-07 18:37:30 +08:00
|
|
|
|
FileUtils.deleteFile(tempFilePath);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
e.printStackTrace();
|
2018-08-03 18:08:46 +08:00
|
|
|
|
logger.error(RestBusinessCode.GetFileDigestFailure.getValue()+":"+e.getMessage()+",请检查摘要获取工具是否安装成功");
|
|
|
|
|
|
// thread.setExceptionInfo("摘要获取过程中出现异常");
|
|
|
|
|
|
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, RestBusinessCode.GetFileDigestFailure.getValue()+":"+e.getMessage()+",请检查摘要获取工具是否安装成功",
|
|
|
|
|
|
RestBusinessCode.GetFileDigestFailure.getValue());
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
2018-06-04 10:18:31 +08:00
|
|
|
|
return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "摘要获取成功", resultObject);
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-06-04 10:18:31 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
private boolean isBlank(Date datetime) {
|
|
|
|
|
|
if (null != datetime) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|