struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Lenart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4209) struts.xml not found when using tomcat Virtual webapp
Date Sat, 08 Mar 2014 16:56:43 GMT

    [ https://issues.apache.org/jira/browse/WW-4209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13924921#comment-13924921
] 

Lukasz Lenart commented on WW-4209:
-----------------------------------

[~ghuber] I think you can apply the patch yourself ;-)

> 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
>             Fix For: 2.3.17
>
>         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)

Mime
View raw message