处理XMLfile XStream API时的ConversionException
问题描述:
我在使用OVAL验证框架处理XML文件时收到异常。我正在使用OVAL验证框架进行验证。我遵循这个用户指南在现场记录。 http://oval.sourceforge.net/userguide.html处理XMLfile XStream API时的ConversionException
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.thoughtworks.xstream.converters.ConversionException:
---- Debugging information ----
cause-exception : java.lang.RuntimeException
cause-message : null
class : java.util.regex.Pattern
required-type : java.util.regex.Pattern
converter-type : com.thoughtworks.xstream.converters.extended.RegexPatternConverter
path : /oval/class/field/matchPattern/pattern
line number : 13
class[1] : net.sf.oval.constraint.MatchPatternCheck
converter-type[1] : net.sf.oval.configuration.xml.XMLConfigurer$1
class[2] : net.sf.oval.configuration.pojo.elements.FieldConfiguration
class[3] : net.sf.oval.configuration.pojo.elements.ClassConfiguration
class[4] : net.sf.oval.configuration.pojo.POJOConfigurer
version : 1.4.9
-------------------------------
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
com.thoughtworks.xstream.converters.ConversionException:
---- Debugging information ----
cause-exception : java.lang.RuntimeException
cause-message : null
class : java.util.regex.Pattern
required-type : java.util.regex.Pattern
converter-type : com.thoughtworks.xstream.converters.extended.RegexPatternConverter
path : /oval/class/field/matchPattern/pattern
line number : 13
class[1] : net.sf.oval.constraint.MatchPatternCheck
converter-type[1] : net.sf.oval.configuration.xml.XMLConfigurer$1
class[2] : net.sf.oval.configuration.pojo.elements.FieldConfiguration
class[3] : net.sf.oval.configuration.pojo.elements.ClassConfiguration
class[4] : net.sf.oval.configuration.pojo.POJOConfigurer
version : 1.4.9
-------------------------------
com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)
com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:70)
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
我的XML是
<?xml version="1.0" ?>
<oval xmlns="http://oval.sf.net/oval-configuration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://oval.sf.net/oval-configuration http://oval.sourceforge.net/oval-configuration.xsd">
<!-- define checks for the acme.model.User class -->
<!-- overwrite=false means already defined checks for this class will not
be removed -->
<class type="org.rbac.form.ConfigurationLoginForm" overwrite="false">
<field name="password">
<notNull message="password.can.not.be null"></notNull>
<notEmpty message="password.can.not.be.empty"></notEmpty>
<length min="4" max="20" message="password.length.must.be.between.min.max"></length>
<matchPattern matchAll="true">
<pattern pattern="^[a-z0-9]{8}$" flags="0" />
</matchPattern>
</field>
</class>
</oval>
这是一个验证对象对XML
XMLConfigurer xmlConfigurer = new XMLConfigurer(FormValidator.class.getResourceAsStream("/validation/login_configuration.xml"));
Guard guard = new Guard(xmlConfigurer);
Validator validator = new Validator(guard.getConfigurers());
ResourceBundleMessageResolver messageResolver = new ResourceBundleMessageResolver();
messageResolver.addMessageBundle(resourceBundle);
Validator.setMessageResolver(messageResolver);
Validator.setContextRenderer(new ResourceBundleValidationContextRenderer());
List<ConstraintViolation> LS = validator.validate(formObject);
return LS;
如果我删除模式然后正常工作的方法。任何建议。
答
的XStream的RegExPatternConverter预计正常XML元素作为孩子,而不是属性:
<pattern>
<pattern>^[a-z0-9]$</pattern>
<flags>0</flags>
</pattern>
请也添加一些Java代码。 –
你最终能解决这个问题吗? – javabeats