use of org.springframework.context.NoSuchMessageException in project disconf by knightliao.
the class ParamValidateUtils method getParamErrors.
/**
* 从bindException中获取到参数错误类型,参数错误
*/
public static ModelAndView getParamErrors(BindException be) {
// 构造error的映射
Map<String, String> paramErrors = new HashMap<String, String>();
Map<String, Object[]> paramArgusErrors = new HashMap<String, Object[]>();
for (Object error : be.getAllErrors()) {
if (error instanceof FieldError) {
FieldError fe = (FieldError) error;
String field = fe.getField();
// 默认的message
String message = fe.getDefaultMessage();
try {
contextReader.getMessage(message, fe.getArguments());
} catch (NoSuchMessageException e) {
// 如果有code,则从前往后遍历Code(特殊到一般),修改message为code所对应
for (int i = fe.getCodes().length - 1; i >= 0; i--) {
try {
String code = fe.getCodes()[i];
String info = contextReader.getMessage(code, fe.getArguments());
LOG.debug(code + "\t" + info);
message = code;
} catch (NoSuchMessageException e2) {
LOG.debug("");
}
}
}
// 最终的消息
paramErrors.put(field, message);
paramArgusErrors.put(field, fe.getArguments());
}
}
return ParamValidateUtils.paramError(paramErrors, paramArgusErrors, ErrorCode.FIELD_ERROR);
}
use of org.springframework.context.NoSuchMessageException in project head by mifos.
the class FieldConfigurationHelper method getLocalSpecificFieldNames.
public static String getLocalSpecificFieldNames(String fieldName, UserContext userContext) {
try {
String configuredLabel = getConfiguredFieldName(fieldName, userContext);
if (configuredLabel != null) {
return configuredLabel;
}
Locale locale = ApplicationContextProvider.getBean(PersonnelServiceFacade.class).getUserPreferredLocale();
return ApplicationContextProvider.getBean(MessageSource.class).getMessage(fieldName, null, locale);
} catch (NoSuchMessageException e) {
/*
* I think the theory here is that it is better to show the user
* something, than just make it an internal error. Not sure whether
* that is what is going on for sure, though.
*/
return fieldName;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.springframework.context.NoSuchMessageException in project spring-framework by spring-projects.
the class XmlWebApplicationContextTests method withoutMessageSource.
@Test
@SuppressWarnings("resource")
public void withoutMessageSource() throws Exception {
MockServletContext sc = new MockServletContext("");
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setParent(root);
wac.setServletContext(sc);
wac.setNamespace("testNamespace");
wac.setConfigLocations(new String[] { "/org/springframework/web/context/WEB-INF/test-servlet.xml" });
wac.refresh();
try {
wac.getMessage("someMessage", null, Locale.getDefault());
fail("Should have thrown NoSuchMessageException");
} catch (NoSuchMessageException ex) {
// expected;
}
String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
assertTrue("Default message returned", "default".equals(msg));
}
use of org.springframework.context.NoSuchMessageException in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method readNeedDeep.
/**
* This request URL should be protected by WebID filter because the result
* contains events data - which is data with restricted access. See
* filterChainProxy in node-context.xml.
*
* @param request
* @param identifier
* @return
*/
@RequestMapping(value = "${uri.path.data.need}/{identifier}/deep", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads" })
public ResponseEntity<Dataset> readNeedDeep(HttpServletRequest request, @PathVariable(value = "identifier") String identifier, @RequestParam(value = "layer-size", required = false) Integer layerSize) {
logger.debug("readNeed() called");
URI needUri = URI.create(this.needResourceURIPrefix + "/" + identifier);
try {
Dataset dataset = linkedDataService.getNeedDataset(needUri, true, layerSize);
// TODO: need information does change over time. The immutable need information
// should never expire, the mutable should
HttpHeaders headers = new HttpHeaders();
addCORSHeader(headers);
return new ResponseEntity<>(dataset, headers, HttpStatus.OK);
} catch (NoSuchNeedException | NoSuchConnectionException | NoSuchMessageException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
use of org.springframework.context.NoSuchMessageException in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method showDeepNeedPage.
/**
* This request URL should be protected by WebID filter because the result
* contains events data - which is data with restricted access. See
* filterChainProxy in node-context.xml.
*
* @param identifier
* @param model
* @param response
* @return
*/
// webmvc controller method
@RequestMapping("${uri.path.page.need}/{identifier}/deep")
public String showDeepNeedPage(@PathVariable String identifier, Model model, HttpServletResponse response, @RequestParam(value = "layer-size", required = false) Integer layerSize) {
try {
URI needURI = uriService.createNeedURIForId(identifier);
Dataset rdfDataset = linkedDataService.getNeedDataset(needURI, true, layerSize);
model.addAttribute("rdfDataset", rdfDataset);
model.addAttribute("resourceURI", needURI.toString());
model.addAttribute("dataURI", uriService.toDataURIIfPossible(needURI).toString());
return "rdfDatasetView";
} catch (NoSuchNeedException | NoSuchConnectionException | NoSuchMessageException e) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return "notFoundView";
}
}
Aggregations