Deploy packed WAR. Note: It is expected that the caller has successfully added the app to servicedSet before calling this method. @param cn The context name @param war The WAR file
(ContextName cn, File war)
| 781 | * @param war The WAR file |
| 782 | */ |
| 783 | protected void deployWAR(ContextName cn, File war) { |
| 784 | |
| 785 | // Check for WARs with /../ /./ or similar sequences in the name |
| 786 | if (!cn.isPathValid()) { |
| 787 | log.error(sm.getString("hostConfig.illegalWarName", war.getName())); |
| 788 | invalidWars.add(war.getName()); |
| 789 | return; |
| 790 | } |
| 791 | |
| 792 | File xml = new File(host.getAppBaseFile(), cn.getBaseName() + "/" + Constants.ApplicationContextXml); |
| 793 | |
| 794 | File warTracker = new File(host.getAppBaseFile(), cn.getBaseName() + Constants.WarTracker); |
| 795 | |
| 796 | boolean xmlInWar = false; |
| 797 | try (JarFile jar = new JarFile(war)) { |
| 798 | JarEntry entry = jar.getJarEntry(Constants.ApplicationContextXml); |
| 799 | if (entry != null) { |
| 800 | xmlInWar = true; |
| 801 | } |
| 802 | } catch (IOException ignore) { |
| 803 | // Ignore |
| 804 | } |
| 805 | |
| 806 | // If there is an expanded directory then any xml in that directory |
| 807 | // should only be used if the directory is not out of date and |
| 808 | // unpackWARs is true. Note the code below may apply further limits |
| 809 | boolean useXml = |
| 810 | xml.exists() && unpackWARs && (!warTracker.exists() || warTracker.lastModified() == war.lastModified()); |
| 811 | // If the xml file exists then expandedDir must exist so no need to |
| 812 | // test that here |
| 813 | |
| 814 | Context context = null; |
| 815 | boolean deployThisXML = this.deployXML; |
| 816 | |
| 817 | try { |
| 818 | if (deployThisXML && useXml && !copyXML) { |
| 819 | synchronized (digesterLock) { |
| 820 | try { |
| 821 | context = (Context) digester.parse(xml); |
| 822 | } catch (Exception e) { |
| 823 | log.error(sm.getString("hostConfig.deployDescriptor.error", war.getAbsolutePath()), e); |
| 824 | } finally { |
| 825 | digester.reset(); |
| 826 | if (context == null) { |
| 827 | context = new FailedContext(); |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | context.setConfigFile(xml.toURI().toURL()); |
| 832 | } else if (deployThisXML && xmlInWar) { |
| 833 | synchronized (digesterLock) { |
| 834 | try (JarFile jar = new JarFile(war)) { |
| 835 | JarEntry entry = jar.getJarEntry(Constants.ApplicationContextXml); |
| 836 | try (InputStream istream = jar.getInputStream(entry)) { |
| 837 | context = (Context) digester.parse(istream); |
| 838 | } |
| 839 | } catch (Exception e) { |
| 840 | log.error(sm.getString("hostConfig.deployDescriptor.error", war.getAbsolutePath()), e); |
no test coverage detected