Return-Path: X-Original-To: apmail-struts-issues-archive@minotaur.apache.org Delivered-To: apmail-struts-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ABCCA10759 for ; Mon, 30 Sep 2013 05:24:26 +0000 (UTC) Received: (qmail 24756 invoked by uid 500); 30 Sep 2013 05:24:25 -0000 Delivered-To: apmail-struts-issues-archive@struts.apache.org Received: (qmail 24711 invoked by uid 500); 30 Sep 2013 05:24:24 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 24703 invoked by uid 99); 30 Sep 2013 05:24:24 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Sep 2013 05:24:24 +0000 Date: Mon, 30 Sep 2013 05:24:24 +0000 (UTC) From: "Lukasz Lenart (JIRA)" To: issues@struts.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (WW-4209) struts.xml not found when using tomcat Virtual webapp MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ 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: 2.3.17 > 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.1#6144)