I am using Struts 2 with the XML based validation and it is throwing the
following exception:

info: CORE3282: stdout: ERROR - ValidatorFactory.parseValidators(335) |
Unable to load file:C:/Projects/test/webapps/default/WEB-INF/classes
info: CORE3282: stdout: java.lang.IllegalArgumentException: URI is not
hierarchical
info: CORE3282: stdout:         at java.io.File.<init>(File.java:335)
info: CORE3282: stdout:         at
com.opensymphony.xwork2.validator.ValidatorFactory.parseValidators(ValidatorFactory.java:332)
info: CORE3282: stdout:         at
com.opensymphony.xwork2.validator.ValidatorFactory.<clinit>(ValidatorFactory.java:234)
info: CORE3282: stdout:         at
com.opensymphony.xwork2.validator.ValidatorFileParser.addValidatorConfigs(ValidatorFileParser.java:205)
info: CORE3282: stdout:         at
com.opensymphony.xwork2.validator.ValidatorFileParser.parseActionValidatorConfigs(ValidatorFileParser.java:85)
info: CORE3282: stdout:         at
com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.loadFile(AnnotationActionValidatorManager.java:361)
info: CORE3282: stdout:         at
com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.buildClassValidatorConfigs(AnnotationActionValidatorManage
r.java:252)
........ (continues listing Struts classes without any further error
messages)

I examined the code of ValidatorFactory.parseValidators and line 326 seems
to be throwing the exception:

318             List<File> files = new ArrayList<File>();
319             try {
320                 Iterator<URL> urls = ClassLoaderUtil.getResources("",
ValidatorFactory.class, false);
321                 while (urls.hasNext()) {
322                     URL u = urls.next();
323                     try {
324                         URI uri = new URI(u.toExternalForm().replaceAll("
", "%20"));
325                         if ("file".equalsIgnoreCase(uri.getScheme())) {
326                             File f = new File(uri);
327                             FilenameFilter filter = new FilenameFilter() {
328                                 public boolean accept(File file, String
fileName) {
329                                     return
fileName.contains("-validators.xml");
330                                 }
331                             };
332                            
files.addAll(Arrays.asList(f.listFiles(filter)));
333                         }
334                     } catch (Exception ex) {
335                         LOG.error("Unable to load " + u.toString(), ex);

Code Located at:
http://svn.opensymphony.com/fisheye/browse/xwork/branches/2.0/src/java/com/opensymphony/xwork2/validator/ValidatorFactory.java?r=1850

Does anyone have any suggestions about what I can do to make the URL
hierarchial so that the validator doesn't throw this exception? The path
provided in the stack trace does point to the location where my Java class
files and my Form-validation.xml file is located. Any suggestions would be
appreciated.

Thanks!!

Note: I also included my struts config files below in case there is anything
useful in them.

My Form-validation.xml file (located in
C:/Projects/test/webapps/default/WEB-INF/classes/org/web):

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator
1.0.2//EN" 
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd";>

<validators>
    <field name="name">
        <field-validator type="required">
            <message>The user name field is required!</message>
        </field-validator>
    </field>
</validators>

My form.jsp page:

<%@ page language="java" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<body>
<form action="Form" theme="simple">
<p>
Please enter your name: <input type="text" name="name" /><br />
<s:fielderror />
<s:actionerror />
<input type="submit" value="submit" />
</p>
</form>
</body>
</html>

My Struts action code:

package org.web;
import com.opensymphony.xwork2.ActionSupport;
public class Form extends ActionSupport {

public String name;

public String execute() {
return "success";
}

public getName() {
return name;
}

public setName(String name) {
this.name = name;
}

My Struts.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd";>

<struts>
    <package name="default" namespace="/" extends="struts-default">
    <action name="Form" class="org.web.Form">
          <result name="success">success.jsp</result>
          <result name="input">form.jsp</result>
    </action>
</struts>
-- 
View this message in context: 
http://www.nabble.com/Validation-throwing-IllegalArgumentException-tp20957607p20957607.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to