tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Novotny <>
Subject using manager webapp in a portlet
Date Mon, 15 Dec 2003 14:07:49 GMT


    I'm trying to create a portlet using our GridSphere framework that 
would essentially use the functionality of the tomcat manager webapp to 
allow dynamic webapp reloading, etc. This all worked by doing the 
following :

try {
            URL u = new URL("" + command);
            URLConnection con = u.openConnection();

            String up = USERNAME + ":" + PASSWORD;
            String encoding = null;
            // check to see if sun's Base64 encoder is available.
            try {

                sun.misc.BASE64Encoder encoder =
                encoding = encoder.encode(up.getBytes());
            } catch (Exception ex) { // sun's base64 encoder isn't available
                throw new TomcatManagerException("No 
sun.misc.BASE64Encoder availoable in JDK!");

            con.setRequestProperty("Authorization", "Basic " + encoding);

            if (con instanceof HttpURLConnection) {
                HttpURLConnection httpConnection = (HttpURLConnection) con;
                // test for 401 result (HTTP only)
                if (httpConnection.getResponseCode() == 
                    throw new TomcatManagerException("HTTP Authorization 

            BufferedReader reader = new BufferedReader(new 

            // get first line
            // should be something like:
            // OK - some information text
            String line = null;

            line = reader.readLine();
            StringTokenizer tokenizer = new StringTokenizer(line, "-");
            if (tokenizer.countTokens() == 2) {
                String rc = tokenizer.nextToken();
                String description = tokenizer.nextToken();
                result = new TomcatWebAppResult(rc, description);

            while ((line = reader.readLine()) != null) {

        } catch (IOException e) {
            throw new TomcatManagerException("Unable to perform command: 
", e);

    As you see, I basically just parse the result from using the 
URLConnection class and make it available in my portlet. So far so good.

    Now,,, as someone pointed out, it's not very portable since I have 
the URL hardcoded in my code "". I don't 
mind hardcoding "manager" but the port is no good since this no longer 
works if someone runs Tomcat on some other port besides 8080.

    Any suggestions or ideas are greatly appreciated-- I sure would 
appreciate the manager webservice or something a bit more portable....

    Thanks a lot, Jason

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message