Search in sources :

Example 1 with AbstractAppDirective

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);
    }
}
Also used : AbstractAppDirective(com.publiccms.common.base.AbstractAppDirective) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AbstractAppDirective

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);
    }
}
Also used : HashMap(java.util.HashMap) AbstractAppDirective(com.publiccms.common.base.AbstractAppDirective) Autowired(org.springframework.beans.factory.annotation.Autowired)

Aggregations

AbstractAppDirective (com.publiccms.common.base.AbstractAppDirective)2 HttpParameterHandler (com.publiccms.common.handler.HttpParameterHandler)1 HashMap (java.util.HashMap)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1