use of org.summerb.approaches.springmvc.model.PageMessage in project summerb by skarpushin.
the class ControllerExceptionHandlerStrategyLegacyImpl method buildHtmlError.
protected ModelAndView buildHtmlError(Throwable ex) {
if (securityContextResolver != null && (ex instanceof AccessDeniedException && !securityContextResolver.hasRole(Roles.ROLE_USER))) {
throw new IllegalArgumentException("Exception will not be handled by default exception handler: " + ex);
}
log.error("Exception occured", ex);
ModelAndView ret = new ModelAndView(Views.ERROR_UNEXPECTED_CLARIFIED);
String msg = exceptionTranslator.buildUserMessage(ex, LocaleContextHolder.getLocale());
ControllerBase.addPageMessage(ret.getModel(), new PageMessage(msg, MessageSeverity.Danger));
ret.getModel().put(ControllerBase.ATTR_EXCEPTION, ex);
ret.getModel().put(ControllerBase.ATTR_EXCEPTION_STACKTRACE, ExceptionUtils.getThrowableStackTraceAsString(ex));
return ret;
}
use of org.summerb.approaches.springmvc.model.PageMessage in project summerb by skarpushin.
the class ArticleController method get.
@RequestMapping(method = RequestMethod.GET, value = "/articles/{articleKey}")
public String get(Model model, @PathVariable("articleKey") String articleKey, HttpServletResponse respons, Locale locale) {
try {
RenderedArticle article = articleRenderer.renderArticle(articleKey, locale);
model.addAttribute(ATTR_ARTICLE, article);
} catch (Throwable t) {
log.debug("Failed to get article", t);
String msg = exceptionTranslator.buildUserMessage(t, CurrentRequestUtils.getLocale());
addPageMessage(model.asMap(), new PageMessage(msg, MessageSeverity.Danger));
}
return viewNameArticle;
}
use of org.summerb.approaches.springmvc.model.PageMessage in project summerb by skarpushin.
the class ArticlesAuthoringController method createAttachment.
// NOTE: File upload example:
// http://www.ioncannon.net/programming/975/spring-3-file-upload-example/
@RequestMapping(method = RequestMethod.POST, value = "/{articleId}/addAttachment")
public String createAttachment(@ModelAttribute(ATTR_ARTICLE_ATTACHMENT) ArticleAttachmentVm articleAttachmentVm, Model model, @PathVariable("articleId") long articleId) throws Exception {
try {
Preconditions.checkArgument(articleAttachmentVm.getFile() != null && articleAttachmentVm.getFile().getFileItem() != null, "File required");
Article article = articleService.findById(articleId);
Preconditions.checkArgument(article != null, "Article not found");
Attachment att = articleAttachmentVm.getAttachment();
att.setArticleId(articleId);
FileItem fileItem = articleAttachmentVm.getFile().getFileItem();
att.setSize(fileItem.getSize());
String fileName = fileItem.getName();
att.setName(fileName);
att.setContents(articleAttachmentVm.getFile().getInputStream());
articleService.addArticleAttachment(att);
return Views.redirect(String.format("article-authoring/%s", article.getArticleKey()));
} catch (Throwable t) {
log.error("Failed to create attachment", t);
String msg = exceptionTranslator.buildUserMessage(t, CurrentRequestUtils.getLocale());
addPageMessage(model.asMap(), new PageMessage(msg, MessageSeverity.Danger));
// TODO: Navigate to article authoring instead!
return viewNameArticleAuthoring;
}
}
Aggregations