use of com.publiccms.common.base.AbstractAppDirective in project PublicCMS-preview by sanluan.
the class ApiController method api.
/**
* 接口指令统一分发
*
* @param api
* @param callback
* @param request
* @param response
*/
@RequestMapping("{api}")
public void api(@PathVariable String api, String callback, HttpServletRequest request, HttpServletResponse response) {
try {
AbstractAppDirective directive = appDirectiveMap.get(api);
if (null != directive) {
directive.execute(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
} else {
HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
handler.put(ERROR, INTERFACE_NOT_FOUND).render();
}
} catch (Exception e) {
HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
try {
handler.put(ERROR, EXCEPTION).render();
} catch (Exception renderException) {
log.error(renderException.getMessage());
}
log.error(e.getMessage(), e);
}
}
use of com.publiccms.common.base.AbstractAppDirective in project PublicCMS-preview by sanluan.
the class ApiController method init.
/**
* 接口初始化
*
* @param directiveComponent
* @param directiveList
*/
@Autowired(required = false)
public void init(DirectiveComponent directiveComponent, List<AbstractAppDirective> directiveList) {
for (AbstractAppDirective appDirective : directiveList) {
if (null == appDirective.getName()) {
appDirective.setName(directiveComponent.getDirectiveName(appDirective.getClass().getSimpleName()));
}
appDirectiveMap.put(appDirective.getName(), appDirective);
Map<String, String> map = new HashMap<>();
map.put("name", appDirective.getName());
map.put("needAppToken", String.valueOf(appDirective.needAppToken()));
map.put("needUserToken", String.valueOf(appDirective.needUserToken()));
appList.add(map);
}
}
Aggregations