1 17 18 19 package org.apache.catalina.ant; 20 21 22 import java.io.BufferedInputStream ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 import java.io.UnsupportedEncodingException ; 26 import java.net.URL ; 27 import java.net.URLConnection ; 28 import java.net.URLEncoder ; 29 30 import org.apache.tools.ant.BuildException; 31 32 33 41 public class DeployTask extends AbstractCatalinaTask { 42 43 44 46 47 50 protected String config = null; 51 52 public String getConfig() { 53 return (this.config); 54 } 55 56 public void setConfig(String config) { 57 this.config = config; 58 } 59 60 61 65 protected String localWar = null; 66 67 public String getLocalWar() { 68 return (this.localWar); 69 } 70 71 public void setLocalWar(String localWar) { 72 this.localWar = localWar; 73 } 74 75 76 79 protected String path = null; 80 81 public String getPath() { 82 return (this.path); 83 } 84 85 public void setPath(String path) { 86 this.path = path; 87 } 88 89 90 93 protected String tag = null; 94 95 public String getTag() { 96 return (this.tag); 97 } 98 99 public void setTag(String tag) { 100 this.tag = tag; 101 } 102 103 104 107 protected boolean update = false; 108 109 public boolean getUpdate() { 110 return (this.update); 111 } 112 113 public void setUpdate(boolean update) { 114 this.update = update; 115 } 116 117 118 121 protected String war = null; 122 123 public String getWar() { 124 return (this.war); 125 } 126 127 public void setWar(String war) { 128 this.war = war; 129 } 130 131 132 134 135 140 public void execute() throws BuildException { 141 142 super.execute(); 143 if (path == null) { 144 throw new BuildException 145 ("Must specify 'path' attribute"); 146 } 147 if ((war == null) && (localWar == null) && (config == null) && (tag == null)) { 148 throw new BuildException 149 ("Must specify either 'war', 'localWar', 'config', or 'tag' attribute"); 150 } 151 152 BufferedInputStream stream = null; 154 String contentType = null; 155 int contentLength = -1; 156 if (war != null) { 157 if (war.startsWith("file:")) { 158 try { 159 URL url = new URL (war); 160 URLConnection conn = url.openConnection(); 161 contentLength = conn.getContentLength(); 162 stream = new BufferedInputStream 163 (conn.getInputStream(), 1024); 164 } catch (IOException e) { 165 throw new BuildException(e); 166 } 167 } else { 168 try { 169 stream = new BufferedInputStream 170 (new FileInputStream (war), 1024); 171 } catch (IOException e) { 172 throw new BuildException(e); 173 } 174 } 175 contentType = "application/octet-stream"; 176 } 177 178 StringBuffer sb = new StringBuffer ("/deploy?path="); 180 try { 181 sb.append(URLEncoder.encode(this.path, getCharset())); 182 if ((war == null) && (config != null)) { 183 sb.append("&config="); 184 sb.append(URLEncoder.encode(config, getCharset())); 185 } 186 if ((war == null) && (localWar != null)) { 187 sb.append("&war="); 188 sb.append(URLEncoder.encode(localWar, getCharset())); 189 } 190 if (update) { 191 sb.append("&update=true"); 192 } 193 if (tag != null) { 194 sb.append("&tag="); 195 sb.append(URLEncoder.encode(tag, getCharset())); 196 } 197 } catch (UnsupportedEncodingException e) { 198 throw new BuildException("Invalid 'charset' attribute: " + getCharset()); 199 } 200 201 execute(sb.toString(), stream, contentType, contentLength); 202 203 } 204 205 206 } 207 | Popular Tags |