Search in sources :

Example 11 with NoSuchMessageException

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);
}
Also used : NoSuchMessageException(org.springframework.context.NoSuchMessageException) HashMap(java.util.HashMap) FieldError(org.springframework.validation.FieldError)

Example 12 with NoSuchMessageException

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);
    }
}
Also used : Locale(java.util.Locale) NoSuchMessageException(org.springframework.context.NoSuchMessageException) MessageSource(org.springframework.context.MessageSource) PersonnelServiceFacade(org.mifos.application.admin.servicefacade.PersonnelServiceFacade) NoSuchMessageException(org.springframework.context.NoSuchMessageException) ConfigurationException(org.mifos.config.exceptions.ConfigurationException)

Example 13 with NoSuchMessageException

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));
}
Also used : XmlWebApplicationContext(org.springframework.web.context.support.XmlWebApplicationContext) NoSuchMessageException(org.springframework.context.NoSuchMessageException) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 14 with NoSuchMessageException

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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) NoSuchMessageException(org.springframework.context.NoSuchMessageException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) Dataset(org.apache.jena.query.Dataset) NoSuchNeedException(won.protocol.exception.NoSuchNeedException) URI(java.net.URI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with NoSuchMessageException

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";
    }
}
Also used : NoSuchMessageException(org.springframework.context.NoSuchMessageException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) Dataset(org.apache.jena.query.Dataset) NoSuchNeedException(won.protocol.exception.NoSuchNeedException) URI(java.net.URI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NoSuchMessageException (org.springframework.context.NoSuchMessageException)18 Locale (java.util.Locale)5 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 URI (java.net.URI)4 HashMap (java.util.HashMap)4 Dataset (org.apache.jena.query.Dataset)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 NoSuchConnectionException (won.protocol.exception.NoSuchConnectionException)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 Properties (java.util.Properties)2 Set (java.util.Set)2 Pair (org.apache.commons.lang3.tuple.Pair)2 OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)2 ApplicationSummary (org.orcid.pojo.ApplicationSummary)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 NoSuchAtomException (won.protocol.exception.NoSuchAtomException)2