Hi,


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("http://127.0.0.1:8080/manager"; + 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 =
(sun.misc.BASE64Encoder)
Class.forName("sun.misc.BASE64Encoder").newInstance();
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);
           con.setDoInput(true);
           con.setUseCaches(false);
           con.connect();

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


BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));

           // 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) {
               result.addWebAppDescriptor(line);
           }


} 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 "http://127.0.0.1:8080/manager";. 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to