use of com.qlangtech.tis.runtime.module.action.BasicModule in project tis by qlangtech.
the class AuthorityCheckAdvice method doIntercept.
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
BasicModule action = (BasicModule) invocation.getAction();
ActionProxy proxy = invocation.getProxy();
String namespace = proxy.getNamespace();
final Method method = action.getExecuteMethod();
Func func = method.getAnnotation(Func.class);
final Rundata rundata = BasicModule.getRundataInstance();
// }
final IUser user = UserUtils.getUser(ServletActionContext.getRequest(), daoContextGetter.get());
if (!user.hasLogin() && !(action instanceof LoginAction || StringUtils.startsWith(namespace, "/config"))) {
rundata.redirectTo("/runtime/login.htm");
return Action.NONE;
}
action.setAuthtoken(user);
if (func == null) {
log.debug("target:" + proxy.getActionName() + ",method:" + method.getName() + " has not set FUNC");
return invocation.invoke();
}
// }
return invocation.invoke();
}
use of com.qlangtech.tis.runtime.module.action.BasicModule in project tis by qlangtech.
the class CoreAction method pushConfig2Engine.
public static void pushConfig2Engine(BasicModule module, Context context, DocCollection collection, int snapshotId, boolean needReload) throws Exception {
// module.errorsPageShow(context);
if (traverseCollectionReplic(collection, false, /* collection */
new ReplicaCallback() {
@Override
public boolean process(boolean isLeader, final Replica replica) throws Exception {
try {
URL url = new URL(replica.getStr(BASE_URL_PROP) + "/admin/cores?action=CREATEALIAS&" + ICoreAdminAction.EXEC_ACTION + "=" + ICoreAdminAction.ACTION_UPDATE_CONFIG + "&core=" + replica.getStr(CORE_NAME_PROP) + "&" + ZkStateReader.COLLECTION_PROP + "=" + collection.getName() + "&needReload=" + needReload + "&" + ICoreAdminAction.TARGET_SNAPSHOT_ID + "=" + snapshotId);
return HttpUtils.processContent(url, new StreamProcess<Boolean>() {
@Override
public Boolean p(int status, InputStream stream, Map<String, List<String>> headerFields) {
ProcessResponse result = null;
if ((result = ProcessResponse.processResponse(stream, (err) -> module.addErrorMessage(context, replica.getName() + "," + err))).success) {
// addActionMessage(context, "成功触发了创建索引集群" + groupNum + "组,组内" + repliationCount + "个副本");
// return true;
}
return true;
}
});
} catch (MalformedURLException e) {
// e.printStackTrace();
log.error(collection.getName(), e);
module.addErrorMessage(context, e.getMessage());
}
return true;
}
})) {
// module.addActionMessage(context, "已经更新全部服务器配置文件");
}
}
use of com.qlangtech.tis.runtime.module.action.BasicModule in project tis by qlangtech.
the class OperationLogInterceptor method doIntercept.
@Override
protected String doIntercept(ActionInvocation invocation) throws Exception {
BasicModule action = (BasicModule) invocation.getAction();
final Method method = action.getExecuteMethod();
final String result = invocation.invoke();
Func func = method.getAnnotation(Func.class);
if (func != null && !func.sideEffect()) {
return result;
}
AppDomainInfo appDomain = CheckAppDomainExistValve.getAppDomain(daoContext);
OperationLog log = new OperationLog();
log.setOpType(BasicModule.parseMehtodName());
if (StringUtils.startsWith(log.getOpType(), "doGet")) {
return result;
}
log.setCreateTime(new Date());
if (!(appDomain instanceof Nullable)) {
log.setAppName(appDomain.getAppName());
}
ActionProxy proxy = invocation.getProxy();
// log.setOpType(proxy.getMethod());
HttpServletRequest request = ServletActionContext.getRequest();
if (StringUtils.indexOf(request.getClass().getSimpleName(), "Mock") > -1) {
// 当前是测试流程的话就不需要记录日志了
return result;
}
IUser user = UserUtils.getUser(request, daoContext);
if (user == null) {
throw new IllegalStateException("user can not be null");
}
StringBuffer jsonObject = new StringBuffer();
JSONObject params = null;
Map<String, String[]> paramsMap = null;
String url = request.getRequestURL().toString();
jsonObject.append("request:");
jsonObject.append(url).append("\n");
String requestBody = null;
if (!ConfigFileContext.HTTPMethod.GET.name().equals(request.getMethod())) {
paramsMap = request.getParameterMap();
if (paramsMap.size() > 0) {
params = new JSONObject();
for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) {
if (entry.getValue().length == 1) {
params.put(entry.getKey(), entry.getValue()[0]);
} else {
params.put(entry.getKey(), entry.getValue());
}
}
jsonObject.append("params:").append("\n");
jsonObject.append(params.toString(1)).append("\n");
}
try (ServletInputStream input = request.getInputStream()) {
if (!input.isFinished()) {
requestBody = IOUtils.toString(input, TisUTF8.get());
jsonObject.append("body:").append("\n");
jsonObject.append(requestBody).append("\n");
}
}
}
Context context = new MockContext();
jsonObject.append("\n=================================");
jsonObject.append("response:").append("\n");
jsonObject.append(AjaxValve.buildResultStruct(context));
log.setTabName(proxy.getActionName());
log.setUsrId(user.getId());
log.setUsrName(user.getName());
log.setOpDesc(jsonObject.toString());
operationLogDAO.insertSelective(log);
return result;
}
Aggregations