Greg Huber created WW-4209:
------------------------------
Summary: 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
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 file
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