Search in sources :

Example 1 with HttpParameterHandler

use of com.publiccms.common.handler.HttpParameterHandler in project PublicCMS-preview by sanluan.

the class AbstractTemplateDirective method execute.

@Override
public void execute(HttpMessageConverter<Object> httpMessageConverter, MediaType mediaType, HttpServletRequest request, String callback, HttpServletResponse response) throws IOException, Exception {
    HttpParameterHandler handler = new HttpParameterHandler(httpMessageConverter, mediaType, request, callback, response);
    SysApp app = null;
    if (needAppToken() && (null == (app = getApp(handler)) || CommonUtils.empty(app.getAuthorizedApis()) || !ArrayUtils.contains(StringUtils.split(app.getAuthorizedApis(), COMMA_DELIMITED), getName()))) {
        if (null == app) {
            handler.put("error", ApiController.NEED_APP_TOKEN).render();
        } else {
            handler.put("error", ApiController.UN_AUTHORIZED).render();
        }
    } else if (needUserToken() && null == getUser(handler)) {
        handler.put("error", ApiController.NEED_LOGIN).render();
    } else {
        execute(handler);
        handler.render();
    }
}
Also used : SysApp(com.publiccms.entities.sys.SysApp) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler)

Example 2 with HttpParameterHandler

use of com.publiccms.common.handler.HttpParameterHandler in project PublicCMS-preview by sanluan.

the class LotteryController method check.

/**
 * @param callback
 * @param request
 * @param session
 * @param response
 */
@RequestMapping("status")
public void check(String callback, HttpServletRequest request, HttpSession session, HttpServletResponse response) {
    try {
        HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
        SysUser user = getUserFromSession(session);
        if (null != user) {
            lotteryStatusDirective.execute(handler, null, user);
        }
        handler.render();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with HttpParameterHandler

use of com.publiccms.common.handler.HttpParameterHandler in project PublicCMS-preview by sanluan.

the class VoteController method lottery.

/**
 * @param callback
 * @param request
 * @param session
 * @param response
 */
@RequestMapping("vote")
public void lottery(String callback, HttpServletRequest request, HttpSession session, HttpServletResponse response) {
    try {
        HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
        SysUser user = getUserFromSession(session);
        if (null != user) {
            voteDirective.execute(handler, null, user);
        }
        handler.render();
    } catch (Exception e) {
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with HttpParameterHandler

use of com.publiccms.common.handler.HttpParameterHandler 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 5 with HttpParameterHandler

use of com.publiccms.common.handler.HttpParameterHandler in project PublicCMS-preview by sanluan.

the class DirectiveController method directive.

/**
 * 接口指令统一分发
 *
 * @param action
 * @param callback
 * @param request
 * @param response
 */
@RequestMapping("directive/{action}")
public void directive(@PathVariable String action, String callback, HttpServletRequest request, HttpServletResponse response) {
    try {
        HttpDirective directive = actionMap.get(action);
        if (null != directive) {
            request.setAttribute(AbstractFreemarkerView.CONTEXT_SITE, getSite(request));
            directive.execute(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
        } else {
            HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
            handler.put(ERROR, ApiController.INTERFACE_NOT_FOUND).render();
        }
    } catch (Exception e) {
        HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
        try {
            handler.put(ERROR, ApiController.EXCEPTION).render();
        } catch (Exception renderException) {
            log.error(renderException.getMessage());
        }
        log.error(e.getMessage(), e);
    }
}
Also used : HttpDirective(com.publiccms.common.directive.HttpDirective) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

HttpParameterHandler (com.publiccms.common.handler.HttpParameterHandler)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 SysUser (com.publiccms.entities.sys.SysUser)3 SysApp (com.publiccms.entities.sys.SysApp)2 AbstractAppDirective (com.publiccms.common.base.AbstractAppDirective)1 HttpDirective (com.publiccms.common.directive.HttpDirective)1