本文整理汇总了Java中javax.validation.ValidatorFactory.getMessageInterpolator方法的典型用法代码示例。如果您正苦于以下问题:Java ValidatorFactory.getMessageInterpolator方法的具体用法?Java ValidatorFactory.getMessageInterpolator怎么用?Java ValidatorFactory.getMessageInterpolator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.validation.ValidatorFactory
的用法示例。
在下文中一共展示了ValidatorFactory.getMessageInterpolator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parsePolicyEnable
import javax.validation.ValidatorFactory; //导入方法依赖的package包/类
public static JsonNode parsePolicyEnable(String jsonString, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
PolicyEnbale policyEnable = new_mapper.readValue(jsonString, PolicyEnbale.class);
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<PolicyEnbale>> set = validator.validate(policyEnable);
if (set.size() > 0 ){
for (ConstraintViolation<PolicyEnbale> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
//additional data manipulation
String new_json = policyEnable.transformInput();
result.put("valid", true);
result.put("new_json", new_json);
return result;
}
示例2: parseScalingHistory
import javax.validation.ValidatorFactory; //导入方法依赖的package包/类
public static JsonNode parseScalingHistory(String jsonString, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
JavaType javaType = getCollectionType(ArrayList.class, ArrayList.class, HistoryData.class);
new_mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
List<HistoryData> scalinghistory = (List<HistoryData>)new_mapper.readValue(jsonString, javaType);
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<List<HistoryData>>> set = validator.validate(scalinghistory);
if (set.size() > 0 ){
for (ConstraintViolation<List<HistoryData>> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
//additional data manipulation
String new_json = transformHistory(scalinghistory);
result.put("valid", true);
result.put("new_json", new_json);
return result;
}
示例3: parsePolicy
import javax.validation.ValidatorFactory; //导入方法依赖的package包/类
public static JsonNode parsePolicy(String jsonString, Map<String, String> service_info, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
logger.info("received policy : " + jsonString); //debug
new_mapper.readValue(jsonString, Policy.class); //for syntax error check
String transfered_json = TransferedPolicy.packServiceInfo(jsonString, service_info);
logger.info("transfered policy after update with service_information : " + transfered_json); //debug
TransferedPolicy policy = new_mapper.readValue(transfered_json, TransferedPolicy.class);
logger.info("we get policy as " + (Obj2Map(policy)).toString());//debug
//additional data manipulation and check again
policy = policy.setMaxInstCount();
HibernateValidatorConfiguration config = BeanValidation.getPolicyRange();
ValidatorFactory vf = config.buildValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<TransferedPolicy>> set = validator.validate(policy);
if (set.size() > 0 ){
for (ConstraintViolation<TransferedPolicy> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
String new_json = policy.transformInput();
logger.info("policy before trigger back : " + new_json); //debug
new_json = TransferedPolicy.unpackServiceInfo(new_json, service_info);
result.put("valid", true);
logger.info("send out policy: " + new_json); //debug
result.put("new_json", new_json);
return result;
}
示例4: parsePolicyOutput
import javax.validation.ValidatorFactory; //导入方法依赖的package包/类
public static JsonNode parsePolicyOutput(String jsonString, Map<String, String> supplyment, Map<String, String> service_info, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
logger.info("received json: " + jsonString);
String transfered_json = TransferedPolicy.packServiceInfo(jsonString, service_info);
logger.info("transfered policy after update with service_information : " + transfered_json); //debug
TransferedPolicy policy = new_mapper.readValue(transfered_json, TransferedPolicy.class);
logger.info("we get policy as " + (Obj2Map(policy)).toString());//debug
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<TransferedPolicy>> set = validator.validate(policy);
if (set.size() > 0 ){
for (ConstraintViolation<TransferedPolicy> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
//additional data manipulation
policy = policy.transformSchedules();
String new_json = policy.transformOutput(supplyment, service_info);
result.put("valid", true);
result.put("new_json", new_json);
return result;
}
示例5: parseMetrics
import javax.validation.ValidatorFactory; //导入方法依赖的package包/类
public static JsonNode parseMetrics(String jsonString, HttpServletRequest httpServletRequest) throws JsonParseException, JsonMappingException, IOException{
List<String> violation_message = new ArrayList<String>();
ObjectNode result = new_mapper.createObjectNode();
result.put("valid", false);
//JavaType javaType = getCollectionType(ArrayList.class, HistoryData.class);
//new_mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
logger.info("Received metrics: " + jsonString);
Metrics metrics = new_mapper.readValue(jsonString, Metrics.class);
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Locale locale = LocaleUtil.getLocale(httpServletRequest);
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(vf.getMessageInterpolator(), locale);
Validator validator = vf.usingContext().messageInterpolator(interpolator).getValidator();
Set<ConstraintViolation<Metrics>> set = validator.validate(metrics);
if (set.size() > 0 ){
for (ConstraintViolation<Metrics> constraintViolation : set) {
violation_message.add(constraintViolation.getMessage());
}
result.set("violation_message", new_mapper.valueToTree(violation_message));
return result;
}
//additional data manipulation
String new_json = metrics.transformOutput();
result.put("valid", true);
result.put("new_json", new_json);
return result;
}