You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bval.apache.org by "Romain Manni-Bucau (JIRA)" <ji...@apache.org> on 2011/08/24 17:26:29 UTC

[jira] [Created] (BVAL-97) More than one META-INF/validation.xml in tomcat webapp

More than one META-INF/validation.xml in tomcat webapp
------------------------------------------------------

                 Key: BVAL-97
                 URL: https://issues.apache.org/jira/browse/BVAL-97
             Project: BeanValidation
          Issue Type: Bug
    Affects Versions: 0.3-incubating
         Environment: Tomcat 7.0.16 + OpenEJB 4.0.0-SNAPSHOT
            Reporter: Romain Manni-Bucau


To be spec compliant bval check there is only one validation.xml in the classloader.

However in tomcat WEB-INF/classes/META-INF/validation.xml is returned twice so it fails because of the following code in ValidationParser:

{code}
           if ( path.equals("META-INF/validation.xml") ) {
                Enumeration<URL> urls = loader.getResources(path);
                if ( urls.hasMoreElements() && (urls.nextElement() != null) && urls.hasMoreElements() ) {
                    throw new ValidationException("More than one " + path + " is found in the classpath");
                }
            }
{code}

To fix it urls should be check to see if they are all equals or loader.findResources(path) could be used instead of loader.getResources(path).



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (BVAL-97) More than one META-INF/validation.xml in tomcat webapp

Posted by "Romain Manni-Bucau (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/BVAL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13091118#comment-13091118 ] 

Romain Manni-Bucau commented on BVAL-97:
----------------------------------------

perfect, thanks :)

> More than one META-INF/validation.xml in tomcat webapp
> ------------------------------------------------------
>
>                 Key: BVAL-97
>                 URL: https://issues.apache.org/jira/browse/BVAL-97
>             Project: BeanValidation
>          Issue Type: Bug
>    Affects Versions: 0.3-incubating
>         Environment: Tomcat 7.0.16 + OpenEJB 4.0.0-SNAPSHOT
>            Reporter: Romain Manni-Bucau
>            Assignee: Roman Stumm
>
> To be spec compliant bval check there is only one validation.xml in the classloader.
> However in tomcat WEB-INF/classes/META-INF/validation.xml is returned twice so it fails because of the following code in ValidationParser:
> {code}
>            if ( path.equals("META-INF/validation.xml") ) {
>                 Enumeration<URL> urls = loader.getResources(path);
>                 if ( urls.hasMoreElements() && (urls.nextElement() != null) && urls.hasMoreElements() ) {
>                     throw new ValidationException("More than one " + path + " is found in the classpath");
>                 }
>             }
> {code}
> To fix it urls should be check to see if they are all equals or loader.findResources(path) could be used instead of loader.getResources(path).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (BVAL-97) More than one META-INF/validation.xml in tomcat webapp

Posted by "Romain Manni-Bucau (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/BVAL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13090375#comment-13090375 ] 

Romain Manni-Bucau commented on BVAL-97:
----------------------------------------

replacing ValidationParser.getInputStream() with:

{code}
private InputStream getInputStream(String path) throws IOException {
        ClassLoader loader = PrivilegedActions.getClassLoader(getClass());
        InputStream inputStream = loader.getResourceAsStream( path );

        if ( inputStream != null ) {
            // spec says: If more than one META-INF/validation.xml file
            // is found in the classpath, a ValidationException is raised.
            if ( path.equals("META-INF/validation.xml") ) {
                Enumeration<URL> urls = loader.getResources(path);
                Set<String> uniqueUrls = new HashSet<String>();
                while (urls.hasMoreElements()) {
                    uniqueUrls.add(urls.nextElement().toString());
                }
                if (uniqueUrls.size() > 1) {
                    throw new ValidationException("More than one " + path + " is found in the classpath"
                            + uniqueUrls);
                }
            }
        }

        return inputStream;
    }
{code}

works.

> More than one META-INF/validation.xml in tomcat webapp
> ------------------------------------------------------
>
>                 Key: BVAL-97
>                 URL: https://issues.apache.org/jira/browse/BVAL-97
>             Project: BeanValidation
>          Issue Type: Bug
>    Affects Versions: 0.3-incubating
>         Environment: Tomcat 7.0.16 + OpenEJB 4.0.0-SNAPSHOT
>            Reporter: Romain Manni-Bucau
>
> To be spec compliant bval check there is only one validation.xml in the classloader.
> However in tomcat WEB-INF/classes/META-INF/validation.xml is returned twice so it fails because of the following code in ValidationParser:
> {code}
>            if ( path.equals("META-INF/validation.xml") ) {
>                 Enumeration<URL> urls = loader.getResources(path);
>                 if ( urls.hasMoreElements() && (urls.nextElement() != null) && urls.hasMoreElements() ) {
>                     throw new ValidationException("More than one " + path + " is found in the classpath");
>                 }
>             }
> {code}
> To fix it urls should be check to see if they are all equals or loader.findResources(path) could be used instead of loader.getResources(path).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Assigned] (BVAL-97) More than one META-INF/validation.xml in tomcat webapp

Posted by "Roman Stumm (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/BVAL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Roman Stumm reassigned BVAL-97:
-------------------------------

    Assignee: Roman Stumm

> More than one META-INF/validation.xml in tomcat webapp
> ------------------------------------------------------
>
>                 Key: BVAL-97
>                 URL: https://issues.apache.org/jira/browse/BVAL-97
>             Project: BeanValidation
>          Issue Type: Bug
>    Affects Versions: 0.3-incubating
>         Environment: Tomcat 7.0.16 + OpenEJB 4.0.0-SNAPSHOT
>            Reporter: Romain Manni-Bucau
>            Assignee: Roman Stumm
>
> To be spec compliant bval check there is only one validation.xml in the classloader.
> However in tomcat WEB-INF/classes/META-INF/validation.xml is returned twice so it fails because of the following code in ValidationParser:
> {code}
>            if ( path.equals("META-INF/validation.xml") ) {
>                 Enumeration<URL> urls = loader.getResources(path);
>                 if ( urls.hasMoreElements() && (urls.nextElement() != null) && urls.hasMoreElements() ) {
>                     throw new ValidationException("More than one " + path + " is found in the classpath");
>                 }
>             }
> {code}
> To fix it urls should be check to see if they are all equals or loader.findResources(path) could be used instead of loader.getResources(path).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Issue Comment Edited] (BVAL-97) More than one META-INF/validation.xml in tomcat webapp

Posted by "Roman Stumm (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/BVAL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13091083#comment-13091083 ] 

Roman Stumm edited comment on BVAL-97 at 8/25/11 3:58 PM:
----------------------------------------------------------

This is the version I committed:

      protected InputStream getInputStream(String path) throws IOException {
        ClassLoader loader = PrivilegedActions.getClassLoader(getClass());
        InputStream inputStream = loader.getResourceAsStream(path);

        if (inputStream != null) {
            // spec says: If more than one META-INF/validation.xml file
            // is found in the classpath, a ValidationException is raised.
            Enumeration<URL> urls = loader.getResources(path);
            if (urls.hasMoreElements()) {
                String url = urls.nextElement().toString();
                while (urls.hasMoreElements()) {
                    if (!url.equals(urls.nextElement().toString())) { // complain when first duplicate found
                        throw new ValidationException("More than one " + path + " is found in the classpath");
                    }
                }
            }
        }

        return inputStream;
    }

      was (Author: romanstumm):
    This is the version I committed:

    protected InputStream getInputStream(String path) throws IOException {
        ClassLoader loader = PrivilegedActions.getClassLoader(getClass());
        InputStream inputStream = loader.getResourceAsStream(path);

        if (inputStream != null) {
            // spec says: If more than one META-INF/validation.xml file
            // is found in the classpath, a ValidationException is raised.
            Enumeration<URL> urls = loader.getResources(path);
            Set<String> uniqueUrls = new HashSet<String>(2);
            while (urls.hasMoreElements()) {
                uniqueUrls.add(urls.nextElement().toString());
                if (uniqueUrls.size() > 1){ // complain when first duplicate found
                    throw new ValidationException("More than one " + path + " is found in the classpath"
                            + uniqueUrls);
                }
            }
        }

        return inputStream;
    }
  
> More than one META-INF/validation.xml in tomcat webapp
> ------------------------------------------------------
>
>                 Key: BVAL-97
>                 URL: https://issues.apache.org/jira/browse/BVAL-97
>             Project: BeanValidation
>          Issue Type: Bug
>    Affects Versions: 0.3-incubating
>         Environment: Tomcat 7.0.16 + OpenEJB 4.0.0-SNAPSHOT
>            Reporter: Romain Manni-Bucau
>            Assignee: Roman Stumm
>
> To be spec compliant bval check there is only one validation.xml in the classloader.
> However in tomcat WEB-INF/classes/META-INF/validation.xml is returned twice so it fails because of the following code in ValidationParser:
> {code}
>            if ( path.equals("META-INF/validation.xml") ) {
>                 Enumeration<URL> urls = loader.getResources(path);
>                 if ( urls.hasMoreElements() && (urls.nextElement() != null) && urls.hasMoreElements() ) {
>                     throw new ValidationException("More than one " + path + " is found in the classpath");
>                 }
>             }
> {code}
> To fix it urls should be check to see if they are all equals or loader.findResources(path) could be used instead of loader.getResources(path).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (BVAL-97) More than one META-INF/validation.xml in tomcat webapp

Posted by "Roman Stumm (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/BVAL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Roman Stumm resolved BVAL-97.
-----------------------------

    Resolution: Fixed

used the patch in a slightly modified form in 0.4-incubating-SNAPSHOT:

Revision #1161606 Committed by romanstumm at 25.08.11 17:35:57 

Changed the duplication-check for "More than one META-INF/validation.xml in tomcat webapp" based on the patch from Romain Manni-Bucau, but removed the hard-coded resource name "META-INF/validation.xml", because I think the spec means that the validationXmlFile must be a unique resource, regardless of its concrete name.

> More than one META-INF/validation.xml in tomcat webapp
> ------------------------------------------------------
>
>                 Key: BVAL-97
>                 URL: https://issues.apache.org/jira/browse/BVAL-97
>             Project: BeanValidation
>          Issue Type: Bug
>    Affects Versions: 0.3-incubating
>         Environment: Tomcat 7.0.16 + OpenEJB 4.0.0-SNAPSHOT
>            Reporter: Romain Manni-Bucau
>            Assignee: Roman Stumm
>
> To be spec compliant bval check there is only one validation.xml in the classloader.
> However in tomcat WEB-INF/classes/META-INF/validation.xml is returned twice so it fails because of the following code in ValidationParser:
> {code}
>            if ( path.equals("META-INF/validation.xml") ) {
>                 Enumeration<URL> urls = loader.getResources(path);
>                 if ( urls.hasMoreElements() && (urls.nextElement() != null) && urls.hasMoreElements() ) {
>                     throw new ValidationException("More than one " + path + " is found in the classpath");
>                 }
>             }
> {code}
> To fix it urls should be check to see if they are all equals or loader.findResources(path) could be used instead of loader.getResources(path).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (BVAL-97) More than one META-INF/validation.xml in tomcat webapp

Posted by "Roman Stumm (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/BVAL-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13091083#comment-13091083 ] 

Roman Stumm commented on BVAL-97:
---------------------------------

This is the version I committed:

    protected InputStream getInputStream(String path) throws IOException {
        ClassLoader loader = PrivilegedActions.getClassLoader(getClass());
        InputStream inputStream = loader.getResourceAsStream(path);

        if (inputStream != null) {
            // spec says: If more than one META-INF/validation.xml file
            // is found in the classpath, a ValidationException is raised.
            Enumeration<URL> urls = loader.getResources(path);
            Set<String> uniqueUrls = new HashSet<String>(2);
            while (urls.hasMoreElements()) {
                uniqueUrls.add(urls.nextElement().toString());
                if (uniqueUrls.size() > 1){ // complain when first duplicate found
                    throw new ValidationException("More than one " + path + " is found in the classpath"
                            + uniqueUrls);
                }
            }
        }

        return inputStream;
    }

> More than one META-INF/validation.xml in tomcat webapp
> ------------------------------------------------------
>
>                 Key: BVAL-97
>                 URL: https://issues.apache.org/jira/browse/BVAL-97
>             Project: BeanValidation
>          Issue Type: Bug
>    Affects Versions: 0.3-incubating
>         Environment: Tomcat 7.0.16 + OpenEJB 4.0.0-SNAPSHOT
>            Reporter: Romain Manni-Bucau
>            Assignee: Roman Stumm
>
> To be spec compliant bval check there is only one validation.xml in the classloader.
> However in tomcat WEB-INF/classes/META-INF/validation.xml is returned twice so it fails because of the following code in ValidationParser:
> {code}
>            if ( path.equals("META-INF/validation.xml") ) {
>                 Enumeration<URL> urls = loader.getResources(path);
>                 if ( urls.hasMoreElements() && (urls.nextElement() != null) && urls.hasMoreElements() ) {
>                     throw new ValidationException("More than one " + path + " is found in the classpath");
>                 }
>             }
> {code}
> To fix it urls should be check to see if they are all equals or loader.findResources(path) could be used instead of loader.getResources(path).

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira