You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lukasz Lenart (JIRA)" <ji...@apache.org> on 2014/03/27 22:16:23 UTC

[jira] [Updated] (WW-4209) struts.xml not found when using tomcat Virtual webapp

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

Lukasz Lenart updated WW-4209:
------------------------------

    Fix Version/s:     (was: 2.3.17)
                   2.3.x

> 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
>            Assignee: Greg Huber
>            Priority: Minor
>             Fix For: 2.3.x
>
>         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 
> {noformat}
> project/target/classes
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider
> {noformat}
> {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 was sent by Atlassian JIRA
(v6.2#6252)