Author: violetagg Date: Wed Jul 8 09:14:53 2015 New Revision: 1689825 URL: http://svn.apache.org/r1689825 Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58086 Rework the change made with r1688563. When the war location points to a local path the FileInputStream will be used otherwise URLConnection will be used.
Added: tomcat/trunk/test/deployment/context.jar (with props) tomcat/trunk/test/deployment/dir with spaces/ (with props) tomcat/trunk/test/deployment/dir with spaces/context.jar (with props) tomcat/trunk/test/deployment/dir with spaces/context.war (with props) tomcat/trunk/test/org/apache/catalina/ant/ (with props) tomcat/trunk/test/org/apache/catalina/ant/TestDeployTask.java (with props) Modified: tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java Modified: tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java?rev=1689825&r1=1689824&r2=1689825&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java (original) +++ tomcat/trunk/java/org/apache/catalina/ant/DeployTask.java Wed Jul 8 09:14:53 2015 @@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingExcept import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; +import java.util.regex.Pattern; import org.apache.tools.ant.BuildException; @@ -38,6 +39,7 @@ import org.apache.tools.ant.BuildExcepti * @since 4.1 */ public class DeployTask extends AbstractCatalinaCommandTask { + private static final Pattern PROTOCOL_PATTERN = Pattern.compile("\\w{3,5}\\:"); // ------------------------------------------------------------- Properties @@ -140,7 +142,7 @@ public class DeployTask extends Abstract String contentType = null; int contentLength = -1; if (war != null) { - if (!war.startsWith("file:")) { + if (PROTOCOL_PATTERN.matcher(war).lookingAt()) { try { URL url = new URL(war); URLConnection conn = url.openConnection(); @@ -151,8 +153,9 @@ public class DeployTask extends Abstract throw new BuildException(e); } } else { + FileInputStream fsInput = null; try { - FileInputStream fsInput = new FileInputStream(war); + fsInput = new FileInputStream(war); long size = fsInput.getChannel().size(); if (size > Integer.MAX_VALUE) @@ -164,6 +167,13 @@ public class DeployTask extends Abstract stream = new BufferedInputStream(fsInput, 1024); } catch (IOException e) { + if (fsInput != null) { + try { + fsInput.close(); + } catch (IOException ioe) { + // Ignore + } + } throw new BuildException(e); } } Added: tomcat/trunk/test/deployment/context.jar URL: http://svn.apache.org/viewvc/tomcat/trunk/test/deployment/context.jar?rev=1689825&view=auto ============================================================================== Binary file - no diff available. Propchange: tomcat/trunk/test/deployment/context.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Propchange: tomcat/trunk/test/deployment/dir with spaces/ ------------------------------------------------------------------------------ bugtraq:append = false Propchange: tomcat/trunk/test/deployment/dir with spaces/ ------------------------------------------------------------------------------ bugtraq:label = Bugzilla ID (optional) Propchange: tomcat/trunk/test/deployment/dir with spaces/ ------------------------------------------------------------------------------ --- bugtraq:logregex (added) +++ bugtraq:logregex Wed Jul 8 09:14:53 2015 @@ -0,0 +1,2 @@ +(https?\://(bz|issues)\.apache\.org/bugzilla/show_bug.cgi\?id=\d+|BZ\s?\d+) +(\d+) Propchange: tomcat/trunk/test/deployment/dir with spaces/ ------------------------------------------------------------------------------ bugtraq:message = Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=%BUGID% Propchange: tomcat/trunk/test/deployment/dir with spaces/ ------------------------------------------------------------------------------ bugtraq:url = https://bz.apache.org/bugzilla/show_bug.cgi?id=%BUGID% Added: tomcat/trunk/test/deployment/dir with spaces/context.jar URL: http://svn.apache.org/viewvc/tomcat/trunk/test/deployment/dir%20with%20spaces/context.jar?rev=1689825&view=auto ============================================================================== Binary file - no diff available. Propchange: tomcat/trunk/test/deployment/dir with spaces/context.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: tomcat/trunk/test/deployment/dir with spaces/context.war URL: http://svn.apache.org/viewvc/tomcat/trunk/test/deployment/dir%20with%20spaces/context.war?rev=1689825&view=auto ============================================================================== Binary file - no diff available. Propchange: tomcat/trunk/test/deployment/dir with spaces/context.war ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Propchange: tomcat/trunk/test/org/apache/catalina/ant/ ------------------------------------------------------------------------------ bugtraq:append = false Propchange: tomcat/trunk/test/org/apache/catalina/ant/ ------------------------------------------------------------------------------ bugtraq:label = Bugzilla ID (optional) Propchange: tomcat/trunk/test/org/apache/catalina/ant/ ------------------------------------------------------------------------------ --- bugtraq:logregex (added) +++ bugtraq:logregex Wed Jul 8 09:14:53 2015 @@ -0,0 +1,2 @@ +(https?\://(bz|issues)\.apache\.org/bugzilla/show_bug.cgi\?id=\d+|BZ\s?\d+) +(\d+) Propchange: tomcat/trunk/test/org/apache/catalina/ant/ ------------------------------------------------------------------------------ bugtraq:message = Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=%BUGID% Propchange: tomcat/trunk/test/org/apache/catalina/ant/ ------------------------------------------------------------------------------ bugtraq:url = https://bz.apache.org/bugzilla/show_bug.cgi?id=%BUGID% Added: tomcat/trunk/test/org/apache/catalina/ant/TestDeployTask.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/ant/TestDeployTask.java?rev=1689825&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/catalina/ant/TestDeployTask.java (added) +++ tomcat/trunk/test/org/apache/catalina/ant/TestDeployTask.java Wed Jul 8 09:14:53 2015 @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.ant; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tools.ant.BuildException; + +public class TestDeployTask extends TomcatBaseTest { + + @Test + public void bug58086a() { + DeployTask deployTask = new DeployTask() { + + @Override + public void execute(String command, InputStream istream, String contentType, int contentLength) + throws BuildException { + assertEquals("/deploy?path=somepath", command); + assertEquals("application/octet-stream", contentType); + try { + istream.close(); + } catch (IOException e) { + } + } + + }; + + setDefaults(deployTask); + + testExecute(deployTask, "file:./test/deployment/context.war"); + testExecute(deployTask, "file:.\\test\\deployment\\context.war"); + testExecute(deployTask, new File("test/deployment/context.war").toURI().toString()); + testExecute(deployTask, new File("test/deployment/context.war").getAbsolutePath()); + testExecute(deployTask, "jar:" + new File("test/deployment/context.jar").toURI().toString() + "!/context.war"); + testExecute(deployTask, "file:./test/deployment/dir with spaces/context.war"); + testExecute(deployTask, "file:.\\test\\deployment\\dir with spaces\\context.war"); + testExecute(deployTask, new File("test/deployment/dir with spaces/context.war").toURI().toString()); + testExecute(deployTask, new File("test/deployment/dir with spaces/context.war").getAbsolutePath()); + testExecute(deployTask, "jar:" + new File("test/deployment/dir with spaces/context.jar").toURI().toString() + + "!/context.war"); + testExecute(deployTask, "file:./test/deployment/dir%20with%20spaces/context.war"); + testExecute(deployTask, "file:.\\test\\deployment\\dir%20with%20spaces\\context.war"); + } + + @Test(expected = BuildException.class) + public void bug58086b() { + DeployTask deployTask = new DeployTask(); + setDefaults(deployTask); + testExecute(deployTask, "scheme:./test/deployment/context.war"); + } + + @Test(expected = BuildException.class) + public void bug58086c() { + DeployTask deployTask = new DeployTask(); + setDefaults(deployTask); + testExecute(deployTask, "sc:./test/deployment/context.war"); + } + + @Test + public void bug58086d() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File root = new File("test/deployment"); + tomcat.addWebapp("", root.getAbsolutePath()); + + tomcat.start(); + + DeployTask deployTask = new DeployTask() { + + @Override + public void execute(String command, InputStream istream, String contentType, int contentLength) + throws BuildException { + assertEquals("/deploy?path=somepath", command); + assertEquals("application/octet-stream", contentType); + try { + istream.close(); + } catch (IOException e) { + } + } + + }; + + setDefaults(deployTask); + + testExecute(deployTask, "http://localhost:" + getPort() + "/context.war"); + } + + private void setDefaults(DeployTask deployTask) { + deployTask.setUrl("someurl"); + deployTask.setUsername("someuser"); + deployTask.setPassword("somepassword"); + deployTask.setPath("somepath"); + } + + private void testExecute(DeployTask deployTask, String war) { + deployTask.setWar(war); + deployTask.execute(); + } +} Propchange: tomcat/trunk/test/org/apache/catalina/ant/TestDeployTask.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org