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();
}
}
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();
}
}
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) {
}
}
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);
}
}
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);
}
}
Aggregations