View | Details | Raw Unified | Return to bug 28852
Collapse All | Expand All

(-)ant/AbstractCatalinaTask.java (-34 / +39 lines)
Lines 66-71 Link Here
66
import java.io.BufferedOutputStream;
66
import java.io.BufferedOutputStream;
67
import java.io.InputStream;
67
import java.io.InputStream;
68
import java.io.InputStreamReader;
68
import java.io.InputStreamReader;
69
import java.io.BufferedReader;
69
import java.net.HttpURLConnection;
70
import java.net.HttpURLConnection;
70
import java.net.URL;
71
import java.net.URL;
71
import java.net.URLConnection;
72
import java.net.URLConnection;
Lines 135-144 Link Here
135
        this.username = username;
136
        this.username = username;
136
    }
137
    }
137
138
139
    protected boolean failonerror = true;
140
141
    public boolean getFailOnError(){
142
        return this.failonerror;
143
    }
144
145
    public void setFailOnError(boolean failonerror){
146
        this.failonerror = failonerror;
147
    }
148
149
138
150
139
    // --------------------------------------------------------- Public Methods
151
    // --------------------------------------------------------- Public Methods
140
152
141
153
154
    protected void validate() throws BuildException  {
155
        if ((username == null) || (password == null) || (url == null)) {
156
            throw new BuildException
157
                ("Must specify all of 'username', 'password', and 'url'");
158
        }
159
    }
160
142
    /**
161
    /**
143
     * Execute the specified command.  This logic only performs the common
162
     * Execute the specified command.  This logic only performs the common
144
     * attribute validation required by all subclasses; it does not perform
163
     * attribute validation required by all subclasses; it does not perform
Lines 147-164 Link Here
147
     * @exception BuildException if a validation error occurs
166
     * @exception BuildException if a validation error occurs
148
     */
167
     */
149
    public void execute() throws BuildException {
168
    public void execute() throws BuildException {
150
169
        validate();
151
        if ((username == null) || (password == null) || (url == null)) {
170
        try {
152
            throw new BuildException
171
            executeProtected();
153
                ("Must specify all of 'username', 'password', and 'url'");
172
        } catch (BuildException e){
173
            if (failonerror){
174
                throw e;
175
            }
176
            log(e.getMessage(), Project.MSG_WARN);
154
        }
177
        }
155
156
    }
178
    }
157
179
158
159
    // ------------------------------------------------------ Protected Methods
180
    // ------------------------------------------------------ Protected Methods
160
181
161
182
183
    protected abstract void executeProtected() throws BuildException;
184
162
    /**
185
    /**
163
     * Execute the specified command, based on the configured properties.
186
     * Execute the specified command, based on the configured properties.
164
     *
187
     *
Lines 190-196 Link Here
190
        throws BuildException {
213
        throws BuildException {
191
214
192
        URLConnection conn = null;
215
        URLConnection conn = null;
193
        InputStreamReader reader = null;
216
        BufferedReader reader = null;
194
        try {
217
        try {
195
218
196
            // Create a connection for this command
219
            // Create a connection for this command
Lines 245-279 Link Here
245
            }
268
            }
246
269
247
            // Process the response message
270
            // Process the response message
248
            reader = new InputStreamReader(hconn.getInputStream());
271
            reader = new BufferedReader(new InputStreamReader(hconn.getInputStream()));
249
            StringBuffer buff = new StringBuffer();
272
            String line = reader.readLine();
250
            String error = null;
273
            if (!line.startsWith("OK -")) {
251
            boolean first = true;
274
                throw new BuildException(line);
252
            while (true) {
253
                int ch = reader.read();
254
                if (ch < 0) {
255
                    break;
256
                } else if ((ch == '\r') || (ch == '\n')) {
257
                    String line = buff.toString();
258
                    buff.setLength(0);
259
                    log(line, Project.MSG_INFO);
260
                    if (first) {
261
                        if (!line.startsWith("OK -")) {
262
                            error = line;
263
                        }
264
                        first = false;
265
                    }
266
                } else {
267
                    buff.append((char) ch);
268
                }
269
            }
270
            if (buff.length() > 0) {
271
                log(buff.toString(), Project.MSG_INFO);
272
            }
275
            }
273
            if (error != null) {
276
            log(line, Project.MSG_INFO);
274
                throw new BuildException(error);
277
            while ( (line = reader.readLine()) != null) {
278
                log(line, Project.MSG_INFO);
275
            }
279
            }
276
280
        } catch (BuildException e){
281
            throw e;
277
        } catch (Throwable t) {
282
        } catch (Throwable t) {
278
            throw new BuildException(t);
283
            throw new BuildException(t);
279
        } finally {
284
        } finally {
(-)ant/DeployTask.java (-9 / +10 lines)
Lines 116-130 Link Here
116
116
117
    // --------------------------------------------------------- Public Methods
117
    // --------------------------------------------------------- Public Methods
118
118
119
119
    protected void validate() throws BuildException {
120
    /**
120
        super.validate();
121
     * Execute the requested operation.
122
     *
123
     * @exception BuildException if an error occurs
124
     */
125
    public void execute() throws BuildException {
126
127
        super.execute();
128
        if (path == null) {
121
        if (path == null) {
129
            throw new BuildException
122
            throw new BuildException
130
                ("Must specify 'path' attribute");
123
                ("Must specify 'path' attribute");
Lines 133-138 Link Here
133
            throw new BuildException
126
            throw new BuildException
134
                ("Must specify 'war' attribute");
127
                ("Must specify 'war' attribute");
135
        }
128
        }
129
    }
130
131
    /**
132
     * Execute the requested operation.
133
     *
134
     * @exception BuildException if an error occurs
135
     */
136
    public void executeProtected() throws BuildException {
136
        BufferedInputStream stream = null;
137
        BufferedInputStream stream = null;
137
        int contentLength = -1;
138
        int contentLength = -1;
138
        try {
139
        try {
(-)ant/InstallTask.java (-9 / +10 lines)
Lines 127-141 Link Here
127
127
128
    // --------------------------------------------------------- Public Methods
128
    // --------------------------------------------------------- Public Methods
129
129
130
130
    protected void validate() throws BuildException {
131
    /**
131
        super.validate();
132
     * Execute the requested operation.
133
     *
134
     * @exception BuildException if an error occurs
135
     */
136
    public void execute() throws BuildException {
137
138
        super.execute();
139
        if (path == null) {
132
        if (path == null) {
140
            throw new BuildException
133
            throw new BuildException
141
                ("Must specify 'path' attribute");
134
                ("Must specify 'path' attribute");
Lines 144-149 Link Here
144
            throw new BuildException
137
            throw new BuildException
145
                ("Must specify at least one of 'config' and 'war'");
138
                ("Must specify at least one of 'config' and 'war'");
146
        }
139
        }
140
    }
141
142
    /**
143
     * Execute the requested operation.
144
     *
145
     * @exception BuildException if an error occurs
146
     */
147
    public void executeProtected() throws BuildException {
147
        StringBuffer sb = new StringBuffer("/install?path=");
148
        StringBuffer sb = new StringBuffer("/install?path=");
148
        sb.append(URLEncoder.encode(this.path));
149
        sb.append(URLEncoder.encode(this.path));
149
        if (config != null) {
150
        if (config != null) {
(-)ant/ListTask.java (-3 / +1 lines)
Lines 89-97 Link Here
89
     *
89
     *
90
     * @exception BuildException if an error occurs
90
     * @exception BuildException if an error occurs
91
     */
91
     */
92
    public void execute() throws BuildException {
92
    public void executeProtected() throws BuildException {
93
94
        super.execute();
95
        execute("/list");
93
        execute("/list");
96
94
97
    }
95
    }
(-)ant/ReloadTask.java (-7 / +8 lines)
Lines 98-116 Link Here
98
98
99
    // --------------------------------------------------------- Public Methods
99
    // --------------------------------------------------------- Public Methods
100
100
101
    protected void validate() throws BuildException {
102
        super.validate();
103
        if (path == null) {
104
            throw new BuildException
105
                ("Must specify 'path' attribute");
106
        }
107
    }
101
108
102
    /**
109
    /**
103
     * Execute the requested operation.
110
     * Execute the requested operation.
104
     *
111
     *
105
     * @exception BuildException if an error occurs
112
     * @exception BuildException if an error occurs
106
     */
113
     */
107
    public void execute() throws BuildException {
114
    public void executeProtected() throws BuildException {
108
109
        super.execute();
110
        if (path == null) {
111
            throw new BuildException
112
                ("Must specify 'path' attribute");
113
        }
114
        execute("/reload?path=" + URLEncoder.encode(this.path));
115
        execute("/reload?path=" + URLEncoder.encode(this.path));
115
116
116
    }
117
    }
(-)ant/RemoveTask.java (-7 / +8 lines)
Lines 97-115 Link Here
97
97
98
    // --------------------------------------------------------- Public Methods
98
    // --------------------------------------------------------- Public Methods
99
99
100
    protected void validate() throws BuildException {
101
        super.validate();
102
        if (path == null) {
103
            throw new BuildException
104
                ("Must specify 'path' attribute");
105
        }
106
    }
100
107
101
    /**
108
    /**
102
     * Execute the requested operation.
109
     * Execute the requested operation.
103
     *
110
     *
104
     * @exception BuildException if an error occurs
111
     * @exception BuildException if an error occurs
105
     */
112
     */
106
    public void execute() throws BuildException {
113
    public void executeProtected() throws BuildException {
107
108
        super.execute();
109
        if (path == null) {
110
            throw new BuildException
111
                ("Must specify 'path' attribute");
112
        }
113
        execute("/remove?path=" + URLEncoder.encode(this.path));
114
        execute("/remove?path=" + URLEncoder.encode(this.path));
114
115
115
    }
116
    }
(-)ant/ResourcesTask.java (-4 / +4 lines)
Lines 63-68 Link Here
63
package org.apache.catalina.ant;
63
package org.apache.catalina.ant;
64
64
65
65
66
import java.net.URLEncoder;
67
66
import org.apache.tools.ant.BuildException;
68
import org.apache.tools.ant.BuildException;
67
import org.apache.tools.ant.Task;
69
import org.apache.tools.ant.Task;
68
70
Lines 104-114 Link Here
104
     *
106
     *
105
     * @exception BuildException if an error occurs
107
     * @exception BuildException if an error occurs
106
     */
108
     */
107
    public void execute() throws BuildException {
109
    public void executeProtected() throws BuildException {
108
109
        super.execute();
110
        if (type != null) {
110
        if (type != null) {
111
            execute("/resources?type=" + type);
111
            execute("/resources?type=" + URLEncoder.encode(type));
112
        } else {
112
        } else {
113
            execute("/resources");
113
            execute("/resources");
114
        }
114
        }
(-)ant/RolesTask.java (-4 / +1 lines)
Lines 89-99 Link Here
89
     *
89
     *
90
     * @exception BuildException if an error occurs
90
     * @exception BuildException if an error occurs
91
     */
91
     */
92
    public void execute() throws BuildException {
92
    public void executeProtected() throws BuildException {
93
94
        super.execute();
95
        execute("/roles");
93
        execute("/roles");
96
97
    }
94
    }
98
95
99
96
(-)ant/StartTask.java (-8 / +8 lines)
Lines 98-118 Link Here
98
98
99
    // --------------------------------------------------------- Public Methods
99
    // --------------------------------------------------------- Public Methods
100
100
101
    protected void validate() throws BuildException {
102
        super.validate();
103
        if (path == null) {
104
            throw new BuildException
105
                ("Must specify 'path' attribute");
106
        }
107
    }
101
108
102
    /**
109
    /**
103
     * Execute the requested operation.
110
     * Execute the requested operation.
104
     *
111
     *
105
     * @exception BuildException if an error occurs
112
     * @exception BuildException if an error occurs
106
     */
113
     */
107
    public void execute() throws BuildException {
114
    public void executeProtected() throws BuildException {
108
109
        super.execute();
110
        if (path == null) {
111
            throw new BuildException
112
                ("Must specify 'path' attribute");
113
        }
114
        execute("/start?path=" + URLEncoder.encode(this.path));
115
        execute("/start?path=" + URLEncoder.encode(this.path));
115
116
    }
116
    }
117
117
118
118
(-)ant/StopTask.java (-8 / +8 lines)
Lines 98-118 Link Here
98
98
99
    // --------------------------------------------------------- Public Methods
99
    // --------------------------------------------------------- Public Methods
100
100
101
    protected void validate() throws BuildException {
102
        super.validate();
103
        if (path == null) {
104
            throw new BuildException
105
                ("Must specify 'path' attribute");
106
        }
107
    }
101
108
102
    /**
109
    /**
103
     * Execute the requested operation.
110
     * Execute the requested operation.
104
     *
111
     *
105
     * @exception BuildException if an error occurs
112
     * @exception BuildException if an error occurs
106
     */
113
     */
107
    public void execute() throws BuildException {
114
    public void executeProtected() throws BuildException {
108
109
        super.execute();
110
        if (path == null) {
111
            throw new BuildException
112
                ("Must specify 'path' attribute");
113
        }
114
        execute("/stop?path=" + URLEncoder.encode(this.path));
115
        execute("/stop?path=" + URLEncoder.encode(this.path));
115
116
    }
116
    }
117
117
118
118
(-)ant/UndeployTask.java (-8 / +11 lines)
Lines 63-68 Link Here
63
package org.apache.catalina.ant;
63
package org.apache.catalina.ant;
64
64
65
65
66
import java.net.URLEncoder;
67
66
import org.apache.tools.ant.BuildException;
68
import org.apache.tools.ant.BuildException;
67
import org.apache.tools.ant.Task;
69
import org.apache.tools.ant.Task;
68
70
Lines 97-116 Link Here
97
99
98
    // --------------------------------------------------------- Public Methods
100
    // --------------------------------------------------------- Public Methods
99
101
102
    protected void validate() throws BuildException {
103
        super.validate();
104
        if (path == null) {
105
            throw new BuildException
106
                ("Must specify 'path' attribute");
107
        }
108
    }
100
109
101
    /**
110
    /**
102
     * Execute the requested operation.
111
     * Execute the requested operation.
103
     *
112
     *
104
     * @exception BuildException if an error occurs
113
     * @exception BuildException if an error occurs
105
     */
114
     */
106
    public void execute() throws BuildException {
115
    public void executeProtected() throws BuildException {
107
116
        execute("/undeploy?path=" + URLEncoder.encode(this.path));
108
        super.execute();
109
        if (path == null) {
110
            throw new BuildException
111
                ("Must specify 'path' attribute");
112
        }
113
        execute("/undeploy?path=" + this.path);
114
117
115
    }
118
    }
116
119

Return to bug 28852