KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > ant > SessionsTask


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.catalina.ant;
20
21
22 import java.io.UnsupportedEncodingException JavaDoc;
23 import java.net.URLEncoder JavaDoc;
24
25 import org.apache.tools.ant.BuildException;
26
27
28 /**
29  * Ant task that implements the <code>/sessions</code> command
30  * supported by the Tomcat manager application.
31  *
32  * @author Vivek Chopra
33  * @version $Revision: 467222 $
34  */

35 public class SessionsTask extends AbstractCatalinaTask {
36
37     // Properties
38

39     /**
40      * The context path of the web application we are managing.
41      */

42     protected String JavaDoc path = null;
43
44     public String JavaDoc getPath() {
45         return (this.path);
46     }
47
48     public void setPath(String JavaDoc path) {
49         this.path = path;
50     }
51
52     // Public Methods
53

54     /**
55      * Execute the requested operation.
56      *
57      * @exception BuildException if an error occurs
58      */

59     public void execute() throws BuildException {
60
61         super.execute();
62         if (path == null) {
63             throw new BuildException
64                 ("Must specify 'path' attribute");
65         }
66         
67         try {
68             execute("/sessions?path=" + URLEncoder.encode(this.path, getCharset()));
69         } catch (UnsupportedEncodingException JavaDoc e) {
70             throw new BuildException
71                 ("Invalid 'charset' attribute: " + getCharset());
72         }
73         
74     }
75
76 }
77
Popular Tags