struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Huber (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (WW-4209) struts.xml not found when using tomcat Virtual webapp
Date Wed, 25 Sep 2013 14:48:04 GMT

     [ https://issues.apache.org/jira/browse/WW-4209?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Greg Huber updated WW-4209:
---------------------------

    Description: 
Hello, 
I would like to use tomcats virtual webapp functionality (http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Virtual_webapp)
in my mavenised struts application but there is an issue where it cannot find the struts.xml
file.  Basically using the virtual webbapp its adds alternative class folders where stuff
comes from.

ie project/src/main/webapp and project/target/classes;

Basically its throwing a IllegalArgumentException com.opensymphony.xwork2.util.fs.DefaultFileManager
when it cannot find the struts.xml file in project/src/main/webapp/WEB-INF/classes.

<code>
private InputStream openFile(URL fileUrl) {
        try {
            InputStream is = fileUrl.openStream();
            if (is == null) {
                throw new IllegalArgumentException("No file '" + fileUrl + "' found as a resource");
            }
            return is;
        } catch (IOException e) {
            throw new IllegalArgumentException("No file '" + fileUrl + "' found as a resource");
        }
    }
</code>

and then not checking the rest of the found resources in 

project/target/classes

com.opensymphony.xwork2.config.providers.XmlConfigurationProvider

<code>
URL url = null;
            while (urls.hasNext()) {
                try {
                    url = urls.next();
                    is = fileManager.loadFile(url);

                    InputSource in = new InputSource(is);

                    in.setSystemId(url.toString());

                    docs.add(DomHelper.parse(in, dtdMappings));
                } catch (XWorkException e) {
                    if (includeElement != null) {
                        throw new ConfigurationException("Unable to load " + url, e, includeElement);
                    } else {
                        throw new ConfigurationException("Unable to load " + url, e);
                    }
                } catch (Exception e) {
                    throw new ConfigurationException("Caught exception while loading file
" + fileName, e, includeElement);
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (IOException e) {
                            LOG.error("Unable to close input stream", e);
                        }
                    }
                }
            }
</code>

To make it work I modified above to:

<code>
// Catch the exception
            ConfigurationException theException = null;

            URL url = null;
            while (urls.hasNext()) {
                try {
                    url = urls.next();
                    is = fileManager.loadFile(url);

                    InputSource in = new InputSource(is);

                    in.setSystemId(url.toString());

                    docs.add(DomHelper.parse(in, dtdMappings));
                    
                    theException = null;
                    
                } catch (XWorkException e) {
                    if (includeElement != null) {
                        //throw new ConfigurationException("Unable to load " + url, e, includeElement);
                        theException = new ConfigurationException("Unable to load " + url,
e, includeElement);
                    } else {
                        //throw new ConfigurationException("Unable to load " + url, e);
                        theException = new ConfigurationException("Unable to load " + url,
e);
                    }
                } catch (Exception e) {
                    //throw new ConfigurationException("Caught exception while loading file
" + fileName, e, includeElement);
                    theException = new ConfigurationException("Caught exception while loading
file " + fileName, e, includeElement);
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (IOException e) {
                            LOG.error("Unable to close input stream", e);
                        }
                    }
                }
            }
            
            // OK bail out as resource not found
            if ( theException != null) {
				throw theException;
			}
</code>

ie try the rest of the files and then if not found give up and throw the exception.

Cheers Greg


  was:
Hello, 
I would like to use tomcats virtual webapp functionality (http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Virtual_webapp)
in my mavenised struts application but there is an issue where it cannot find the struts.xml
file.  Basically using the virtual webbapp its adds alternative class folders where stuff
comes from.

ie project/src/main/webapp and project/target/classes;

Basically its throwing a IllegalArgumentException com.opensymphony.xwork2.util.fs.DefaultFileManager
when it cannot find the struts.xml file in project/src/main/webapp/WEB-INF/classes.

<code>
private InputStream openFile(URL fileUrl) {
        try {
            InputStream is = fileUrl.openStream();
            if (is == null) {
                throw new IllegalArgumentException("No file '" + fileUrl + "' found as a resource");
            }
            return is;
        } catch (IOException e) {
            throw new IllegalArgumentException("No file '" + fileUrl + "' found as a resource");
        }
    }
</code>

and then not checking the rest of the found resources in 

project/target/classes

com.opensymphony.xwork2.config.providers.XmlConfigurationProvider

<code>
URL url = null;
            while (urls.hasNext()) {
                try {
                    url = urls.next();
                    is = fileManager.loadFile(url);

                    InputSource in = new InputSource(is);

                    in.setSystemId(url.toString());

                    docs.add(DomHelper.parse(in, dtdMappings));
                } catch (XWorkException e) {
                    if (includeElement != null) {
                        throw new ConfigurationException("Unable to load " + url, e, includeElement);
                    } else {
                        throw new ConfigurationException("Unable to load " + url, e);
                    }
                } catch (Exception e) {
                    throw new ConfigurationException("Caught exception while loading file
" + fileName, e, includeElement);
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (IOException e) {
                            LOG.error("Unable to close input stream", e);
                        }
                    }
                }
            }
<code>

To make it work I modified above to:

<code>
// Catch the exception
            ConfigurationException theException = null;

            URL url = null;
            while (urls.hasNext()) {
                try {
                    url = urls.next();
                    is = fileManager.loadFile(url);

                    InputSource in = new InputSource(is);

                    in.setSystemId(url.toString());

                    docs.add(DomHelper.parse(in, dtdMappings));
                    
                    theException = null;
                    
                } catch (XWorkException e) {
                    if (includeElement != null) {
                        //throw new ConfigurationException("Unable to load " + url, e, includeElement);
                        theException = new ConfigurationException("Unable to load " + url,
e, includeElement);
                    } else {
                        //throw new ConfigurationException("Unable to load " + url, e);
                        theException = new ConfigurationException("Unable to load " + url,
e);
                    }
                } catch (Exception e) {
                    //throw new ConfigurationException("Caught exception while loading file
" + fileName, e, includeElement);
                    theException = new ConfigurationException("Caught exception while loading
file " + fileName, e, includeElement);
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (IOException e) {
                            LOG.error("Unable to close input stream", e);
                        }
                    }
                }
            }
            
            // OK bail out as resource not found
            if ( theException != null) {
				throw theException;
			}
</code>

ie try the rest of the files and then if not found give up and throw the exception.

Cheers Greg


    
> struts.xml not found when using tomcat Virtual webapp
> -----------------------------------------------------
>
>                 Key: WW-4209
>                 URL: https://issues.apache.org/jira/browse/WW-4209
>             Project: Struts 2
>          Issue Type: Improvement
>    Affects Versions: 2.3.15.1
>         Environment: Tomcat 7/Centos 6.4
>            Reporter: Greg Huber
>            Priority: Minor
>         Attachments: patch.txt
>
>
> Hello, 
> I would like to use tomcats virtual webapp functionality (http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Virtual_webapp)
in my mavenised struts application but there is an issue where it cannot find the struts.xml
file.  Basically using the virtual webbapp its adds alternative class folders where stuff
comes from.
> ie project/src/main/webapp and project/target/classes;
> Basically its throwing a IllegalArgumentException com.opensymphony.xwork2.util.fs.DefaultFileManager
when it cannot find the struts.xml file in project/src/main/webapp/WEB-INF/classes.
> <code>
> private InputStream openFile(URL fileUrl) {
>         try {
>             InputStream is = fileUrl.openStream();
>             if (is == null) {
>                 throw new IllegalArgumentException("No file '" + fileUrl + "' found as
a resource");
>             }
>             return is;
>         } catch (IOException e) {
>             throw new IllegalArgumentException("No file '" + fileUrl + "' found as a
resource");
>         }
>     }
> </code>
> and then not checking the rest of the found resources in 
> project/target/classes
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider
> <code>
> URL url = null;
>             while (urls.hasNext()) {
>                 try {
>                     url = urls.next();
>                     is = fileManager.loadFile(url);
>                     InputSource in = new InputSource(is);
>                     in.setSystemId(url.toString());
>                     docs.add(DomHelper.parse(in, dtdMappings));
>                 } catch (XWorkException e) {
>                     if (includeElement != null) {
>                         throw new ConfigurationException("Unable to load " + url, e,
includeElement);
>                     } else {
>                         throw new ConfigurationException("Unable to load " + url, e);
>                     }
>                 } catch (Exception e) {
>                     throw new ConfigurationException("Caught exception while loading
file " + fileName, e, includeElement);
>                 } finally {
>                     if (is != null) {
>                         try {
>                             is.close();
>                         } catch (IOException e) {
>                             LOG.error("Unable to close input stream", e);
>                         }
>                     }
>                 }
>             }
> </code>
> To make it work I modified above to:
> <code>
> // Catch the exception
>             ConfigurationException theException = null;
>             URL url = null;
>             while (urls.hasNext()) {
>                 try {
>                     url = urls.next();
>                     is = fileManager.loadFile(url);
>                     InputSource in = new InputSource(is);
>                     in.setSystemId(url.toString());
>                     docs.add(DomHelper.parse(in, dtdMappings));
>                     
>                     theException = null;
>                     
>                 } catch (XWorkException e) {
>                     if (includeElement != null) {
>                         //throw new ConfigurationException("Unable to load " + url, e,
includeElement);
>                         theException = new ConfigurationException("Unable to load " +
url, e, includeElement);
>                     } else {
>                         //throw new ConfigurationException("Unable to load " + url, e);
>                         theException = new ConfigurationException("Unable to load " +
url, e);
>                     }
>                 } catch (Exception e) {
>                     //throw new ConfigurationException("Caught exception while loading
file " + fileName, e, includeElement);
>                     theException = new ConfigurationException("Caught exception while
loading file " + fileName, e, includeElement);
>                 } finally {
>                     if (is != null) {
>                         try {
>                             is.close();
>                         } catch (IOException e) {
>                             LOG.error("Unable to close input stream", e);
>                         }
>                     }
>                 }
>             }
>             
>             // OK bail out as resource not found
>             if ( theException != null) {
> 				throw theException;
> 			}
> </code>
> ie try the rest of the files and then if not found give up and throw the exception.
> Cheers Greg

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message