|
|
|
@ -2,7 +2,6 @@ package com.xxl.job.admin.controller;
|
|
|
|
|
|
|
|
|
|
import com.xxl.job.admin.controller.annotation.PermissionLimit;
|
|
|
|
|
import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
|
|
|
|
import com.xxl.job.admin.core.exception.XxlJobException;
|
|
|
|
|
import com.xxl.job.core.biz.AdminBiz;
|
|
|
|
|
import com.xxl.job.core.biz.model.HandleCallbackParam;
|
|
|
|
|
import com.xxl.job.core.biz.model.RegistryParam;
|
|
|
|
@ -10,6 +9,7 @@ import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
|
import com.xxl.job.core.util.GsonTool;
|
|
|
|
|
import com.xxl.job.core.util.XxlJobRemotingUtil;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
@ -28,116 +28,45 @@ public class JobApiController {
|
|
|
|
|
@Resource
|
|
|
|
|
private AdminBiz adminBiz;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------- base ----------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* valid access token
|
|
|
|
|
*/
|
|
|
|
|
private void validAccessToken(HttpServletRequest request){
|
|
|
|
|
if (XxlJobAdminConfig.getAdminConfig().getAccessToken()!=null
|
|
|
|
|
&& XxlJobAdminConfig.getAdminConfig().getAccessToken().trim().length()>0
|
|
|
|
|
&& !XxlJobAdminConfig.getAdminConfig().getAccessToken().equals(request.getHeader(XxlJobRemotingUtil.XXL_JOB_ACCESS_TOKEN))) {
|
|
|
|
|
throw new XxlJobException("The access token is wrong.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* parse Param
|
|
|
|
|
*/
|
|
|
|
|
private Object parseParam(String data, Class<?> parametrized, Class<?> parameterClasses){
|
|
|
|
|
Object param = null;
|
|
|
|
|
try {
|
|
|
|
|
if (parameterClasses != null) {
|
|
|
|
|
param = GsonTool.fromJson(data, parametrized, parameterClasses);
|
|
|
|
|
} else {
|
|
|
|
|
param = GsonTool.fromJson(data, parametrized);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) { }
|
|
|
|
|
if (param==null) {
|
|
|
|
|
throw new XxlJobException("The request data invalid.");
|
|
|
|
|
}
|
|
|
|
|
return param;
|
|
|
|
|
}
|
|
|
|
|
/*private Object parseParam(String data, Class<?> parametrized, Class<?>... parameterClasses){
|
|
|
|
|
Object param = null;
|
|
|
|
|
try {
|
|
|
|
|
if (parameterClasses!=null && parameterClasses.length>0) {
|
|
|
|
|
param = JacksonUtil.readValue(data, parametrized, parameterClasses);
|
|
|
|
|
} else {
|
|
|
|
|
param = JacksonUtil.readValue(data, parametrized);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) { }
|
|
|
|
|
if (param==null) {
|
|
|
|
|
throw new XxlJobException("The request data invalid.");
|
|
|
|
|
}
|
|
|
|
|
return param;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
// ---------------------- admin biz ----------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* callback
|
|
|
|
|
*
|
|
|
|
|
* @param data
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/callback")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
@PermissionLimit(limit=false)
|
|
|
|
|
public ReturnT<String> callback(HttpServletRequest request, @RequestBody(required = false) String data) {
|
|
|
|
|
// valid
|
|
|
|
|
validAccessToken(request);
|
|
|
|
|
|
|
|
|
|
// param
|
|
|
|
|
List<HandleCallbackParam> callbackParamList = (List<HandleCallbackParam>) parseParam(data, List.class, HandleCallbackParam.class);
|
|
|
|
|
|
|
|
|
|
// invoke
|
|
|
|
|
return adminBiz.callback(callbackParamList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* registry
|
|
|
|
|
* api
|
|
|
|
|
*
|
|
|
|
|
* @param uri
|
|
|
|
|
* @param data
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/registry")
|
|
|
|
|
@RequestMapping("/{uri}")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
@PermissionLimit(limit=false)
|
|
|
|
|
public ReturnT<String> registry(HttpServletRequest request, @RequestBody(required = false) String data) {
|
|
|
|
|
// valid
|
|
|
|
|
validAccessToken(request);
|
|
|
|
|
public ReturnT<String> api(HttpServletRequest request, @PathVariable("uri") String uri, @RequestBody(required = false) String data) {
|
|
|
|
|
|
|
|
|
|
// param
|
|
|
|
|
RegistryParam registryParam = (RegistryParam) parseParam(data, RegistryParam.class, null);
|
|
|
|
|
|
|
|
|
|
// invoke
|
|
|
|
|
return adminBiz.registry(registryParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* registry remove
|
|
|
|
|
*
|
|
|
|
|
* @param data
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/registryRemove")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
@PermissionLimit(limit=false)
|
|
|
|
|
public ReturnT<String> registryRemove(HttpServletRequest request, @RequestBody(required = false) String data) {
|
|
|
|
|
// valid
|
|
|
|
|
validAccessToken(request);
|
|
|
|
|
if (!"POST".equalsIgnoreCase(request.getMethod())) {
|
|
|
|
|
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, HttpMethod not support.");
|
|
|
|
|
}
|
|
|
|
|
if (uri==null || uri.trim().length()==0) {
|
|
|
|
|
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, uri-mapping empty.");
|
|
|
|
|
}
|
|
|
|
|
if (XxlJobAdminConfig.getAdminConfig().getAccessToken()!=null
|
|
|
|
|
&& XxlJobAdminConfig.getAdminConfig().getAccessToken().trim().length()>0
|
|
|
|
|
&& !XxlJobAdminConfig.getAdminConfig().getAccessToken().equals(request.getHeader(XxlJobRemotingUtil.XXL_JOB_ACCESS_TOKEN))) {
|
|
|
|
|
return new ReturnT<String>(ReturnT.FAIL_CODE, "The access token is wrong.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// param
|
|
|
|
|
RegistryParam registryParam = (RegistryParam) parseParam(data, RegistryParam.class, null);
|
|
|
|
|
// services mapping
|
|
|
|
|
if ("callback".equals(uri)) {
|
|
|
|
|
List<HandleCallbackParam> callbackParamList = GsonTool.fromJson(data, List.class, HandleCallbackParam.class);
|
|
|
|
|
return adminBiz.callback(callbackParamList);
|
|
|
|
|
} else if ("registry".equals(uri)) {
|
|
|
|
|
RegistryParam registryParam = GsonTool.fromJson(data, RegistryParam.class);
|
|
|
|
|
return adminBiz.registry(registryParam);
|
|
|
|
|
} else if ("registryRemove".equals(uri)) {
|
|
|
|
|
RegistryParam registryParam = GsonTool.fromJson(data, RegistryParam.class);
|
|
|
|
|
return adminBiz.registryRemove(registryParam);
|
|
|
|
|
} else {
|
|
|
|
|
return new ReturnT<String>(ReturnT.FAIL_CODE, "invalid request, uri-mapping("+ uri +") not found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// invoke
|
|
|
|
|
return adminBiz.registryRemove(registryParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------- job biz ----------------------
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|